linlib.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 by Kvaser AB, Molndal, Sweden
3  * http://www.kvaser.com
4  *
5  * This software is dual licensed under the following two licenses:
6  * BSD-new and GPLv2. You may use either one. See the included
7  * COPYING file for details.
8  *
9  * License: BSD-new
10  * ==============================================================================
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions are met:
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  * * Neither the name of the <organization> nor the
19  * names of its contributors may be used to endorse or promote products
20  * derived from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
30  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  *
35  * License: GPLv2
36  * ==============================================================================
37  * This program is free software; you can redistribute it and/or modify
38  * it under the terms of the GNU General Public License as published by
39  * the Free Software Foundation; either version 2 of the License, or
40  * (at your option) any later version.
41  *
42  * This program is distributed in the hope that it will be useful,
43  * but WITHOUT ANY WARRANTY; without even the implied warranty of
44  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45  * GNU General Public License for more details.
46  *
47  * You should have received a copy of the GNU General Public License
48  * along with this program; if not, write to the Free Software
49  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
50  *
51  *
52  * IMPORTANT NOTICE:
53  * ==============================================================================
54  * This source code is made available for free, as an open license, by Kvaser AB,
55  * for use with its applications. Kvaser AB does not accept any liability
56  * whatsoever for any third party patent or other immaterial property rights
57  * violations that may result from any usage of this source code, regardless of
58  * the combination of source code and various applications that it can be used
59  * in, or with.
60  *
61  * -----------------------------------------------------------------------------
62  */
63 
81 #ifndef __LINLIB_H
82 #define __LINLIB_H
83 
87 typedef int LinHandle;
88 
92 #define linINVALID_HANDLE ((LinHandle)(-1))
93 
94 typedef unsigned char BYTE;
95 typedef unsigned int DWORD;
96 typedef unsigned int BOOL;
97 
107 typedef enum {
108  linOK = 0,
110 
117 
124 
130 
136 
137 
158 } LinStatus;
162 // sizeof(LinMessageInfo) should be 68 for correct alignment
163 
178 typedef struct {
189  unsigned long timestamp;
190 
195  unsigned long synchBreakLength;
196 
201  unsigned long frameLength;
202 
207  unsigned long bitrate;
208 
213  unsigned char checkSum;
214 
219  unsigned char idPar;
220 
221  unsigned short z;
222 
229  unsigned long synchEdgeTime[4];
230 
237  unsigned long byteTime[8];
239 
240 
241 
250 #define LIN_TX 1
251 #define LIN_RX 2
252 #define LIN_WAKEUP_FRAME 4
253 #define LIN_NODATA 8
254 #define LIN_CSUM_ERROR 16
255 #define LIN_PARITY_ERROR 32
256 #define LIN_SYNCH_ERROR 64
257 #define LIN_BIT_ERROR 128
258 
280 #define linCHANNELDATA_CARD_FIRMWARE_REV 9
281 
287 #define LINERROR(f) ((f) & (LIN_NODATA | LIN_CSUM_ERROR | LIN_SYNCH_ERROR | LIN_BIT_ERROR))
288 
289 
290 // Define LINLIBAPI unless it's done already.
291 // (linlib.c provides its own definition of LINLIBAPI before including this file.)
292 //
293 #define LINLIBAPI
294 
295 #ifdef __cplusplus
296 extern "C" {
297 #endif
298 
308 
315 void LINLIBAPI linUnloadLibrary(void);
316 
317 
353 LinStatus LINLIBAPI linGetTransceiverData(int channel, unsigned char eanNo[8],
354  unsigned char serNo[8], int *ttype);
355 
376 LinHandle LINLIBAPI linOpenChannel(int channel, int flags);
377 
378 
387 #define LIN_MASTER 1
388 #define LIN_SLAVE 2
389 
404 LinStatus LINLIBAPI linClose(LinHandle h);
405 
406 
421 LinStatus LINLIBAPI linGetVersion(int *major, int *minor, int *build);
422 
423 
459  unsigned char *bootVerMajor,
460  unsigned char *bootVerMinor,
461  unsigned char *bootVerBuild,
462  unsigned char *appVerMajor,
463  unsigned char *appVerMinor,
464  unsigned char *appVerBuild);
465 
466 
467 
488 LinStatus LINLIBAPI linGetChannelData(int channel, int item, void *buffer, size_t bufsize);
489 
505 LinStatus LINLIBAPI linSetBitrate(LinHandle h, unsigned int bps);
506 
522 
537 
550 unsigned long LINLIBAPI linReadTimer(LinHandle h);
551 
573 LinStatus LINLIBAPI linWriteMessage(LinHandle h, unsigned int id, const void *msg,
574  unsigned int dlc);
575 
591 LinStatus LINLIBAPI linRequestMessage(LinHandle h, unsigned int id);
592 
619 LinStatus LINLIBAPI linReadMessage(LinHandle h, unsigned int *id, void *msg,
620  unsigned int *dlc, unsigned int *flags,
621  LinMessageInfo *msgInfo);
622 
652 LinStatus LINLIBAPI linReadMessageWait(LinHandle h, unsigned int *id, void *msg,
653  unsigned int *dlc, unsigned int *flags,
654  LinMessageInfo *msgInfo, unsigned long timeout);
655 
675 LinStatus LINLIBAPI linUpdateMessage(LinHandle h, unsigned int id, const void *msg,
676  unsigned int dlc);
677 
678 
703  unsigned int cFlags, unsigned int delay);
704 
713 #define LIN_MSG_DISTURB_CSUM 1
714 
718 #define LIN_MSG_DISTURB_PARITY 2
719 
730 #define LIN_MSG_USE_STANDARD_PARITY 0x04
731 
734 #define LIN_MSG_USE_ENHANCED_PARITY 0x08
735 
770 LinStatus LINLIBAPI linSetupLIN(LinHandle h, unsigned int lFlags, unsigned int bps);
771 
772 
785 #define LIN_ENHANCED_CHECKSUM 1
786 
792 #define LIN_VARIABLE_DLC 2
793 
815 LinStatus LINLIBAPI linWriteWakeup(LinHandle h, unsigned int count,
816  unsigned int interval);
817 
818 
831 LinStatus LINLIBAPI linClearMessage(LinHandle h, unsigned int id);
832 
875 LinStatus LINLIBAPI linWriteSync(LinHandle h, unsigned long timeout);
876 
889 
930 #ifdef __cplusplus
931 }
932 #endif
933 
934 #endif // __LINLIB_H
LinStatus linWriteWakeup(LinHandle h, unsigned int count, unsigned int interval)
Definition: linlib.h:178
LinStatus linRequestMessage(LinHandle h, unsigned int id)
LinStatus linSetBitrate(LinHandle h, unsigned int bps)
Definition: linlib.h:129
LinHandle linOpenChannel(int channel, int flags)
LinStatus linClearMessage(LinHandle h, unsigned int id)
unsigned int BOOL
Definition: linlib.h:96
The LIN interface response wasn&#39;t the expected one.
Definition: linlib.h:148
LinStatus linGetFirmwareVersion(LinHandle h, unsigned char *bootVerMajor, unsigned char *bootVerMinor, unsigned char *bootVerBuild, unsigned char *appVerMajor, unsigned char *appVerMinor, unsigned char *appVerBuild)
unsigned long bitrate
Definition: linlib.h:207
Internal error in the driver.
Definition: linlib.h:146
LinStatus
Definition: linlib.h:107
The card was removed or not inserted.
Definition: linlib.h:151
int canHandle
Definition: canlib.h:148
CAN driver type not supported.
Definition: linlib.h:149
LinStatus linUpdateMessage(LinHandle h, unsigned int id, const void *msg, unsigned int dlc)
LinStatus linGetChannelData(int channel, int item, void *buffer, size_t bufsize)
There was an error response from the LIN interface.
Definition: linlib.h:147
LinStatus linGetTransceiverData(int channel, unsigned char eanNo[8], unsigned char serNo[8], int *ttype)
Specified hardware not found. This error is reported when the LIN transceiver isn&#39;t powered up...
Definition: linlib.h:139
Error in parameter.
Definition: linlib.h:138
No channels avaliable.
Definition: linlib.h:141
LinStatus linBusOn(LinHandle h)
LinStatus linWriteMessage(LinHandle h, unsigned int id, const void *msg, unsigned int dlc)
Can&#39;t get handle.
Definition: linlib.h:144
The requested feature or function is not implemented in the device you are trying to use it on...
Definition: linlib.h:157
Function not supported in this version.
Definition: linlib.h:155
unsigned int DWORD
Definition: linlib.h:95
Definition: linlib.h:135
Handle is invalid.
Definition: linlib.h:145
Library not initialized.
Definition: linlib.h:143
LinStatus linWriteSync(LinHandle h, unsigned long timeout)
Definition: linlib.h:123
void linUnloadLibrary(void)
LinStatus linReadMessage(LinHandle h, unsigned int *id, void *msg, unsigned int *dlc, unsigned int *flags, LinMessageInfo *msgInfo)
DeviceIOControl failed.
Definition: linlib.h:150
LinStatus linGetCanHandle(LinHandle h, unsigned int *canHandle)
#define LINLIBAPI
Definition: linlib.h:293
LinStatus linReadMessageWait(LinHandle h, unsigned int *id, void *msg, unsigned int *dlc, unsigned int *flags, LinMessageInfo *msgInfo, unsigned long timeout)
Internal error in the driver.
Definition: linlib.h:153
Timeout occurred.
Definition: linlib.h:142
No messages available.
Definition: linlib.h:109
Out of memory.
Definition: linlib.h:140
LinStatus linSetupIllegalMessage(LinHandle h, unsigned int id, unsigned int cFlags, unsigned int delay)
unsigned long linReadTimer(LinHandle h)
LinStatus linSetupLIN(LinHandle h, unsigned int lFlags, unsigned int bps)
int LinHandle
Definition: linlib.h:87
Definition: linlib.h:116
Function not supported in this version.
Definition: linlib.h:156
Access denied.
Definition: linlib.h:154
unsigned long frameLength
Definition: linlib.h:201
OK - no error.
Definition: linlib.h:108
The license is not valid.
Definition: linlib.h:152
LinStatus linBusOff(LinHandle h)
unsigned long synchBreakLength
Definition: linlib.h:195
unsigned char BYTE
Definition: linlib.h:94
unsigned long timestamp
Definition: linlib.h:189
unsigned short z
Dummy for alignment.
Definition: linlib.h:221
void linInitializeLibrary(void)
LinStatus linGetVersion(int *major, int *minor, int *build)
unsigned char checkSum
Definition: linlib.h:213
unsigned char idPar
Definition: linlib.h:219