linlib.h

Go to the documentation of this file.
1 /*
2  * Copyright 2003-2017 by KVASER AB, SWEDEN
3  * WWW: http://www.kvaser.com
4  *
5  * This software is furnished under a license and may be used and copied
6  * only in accordance with the terms of such license.
7  */
8 
26 #ifndef __LINLIB_H
27 #define __LINLIB_H
28 
29 #include <stddef.h>
30 
34 typedef int LinHandle;
35 
39 #define linINVALID_HANDLE ((LinHandle)(-1))
40 
41 
51 typedef enum {
52  linOK = 0,
53  linERR_NOMSG = -1,
54 
61 
68 
74 
80 
81 
82  linERR_PARAM = -7,
84  linERR_NOMEM = -9,
93  linERR_DRIVER = -18,
95  linERR_NOCARD = -20,
102 } LinStatus;
106 // sizeof(LinMessageInfo) should be 68 for correct alignment
107 #include <pshpack1.h>
108 
123 typedef struct {
134  unsigned long timestamp;
135 
140  unsigned long synchBreakLength;
141 
146  unsigned long frameLength;
147 
152  unsigned long bitrate;
153 
158  unsigned char checkSum;
159 
164  unsigned char idPar;
165 
166  unsigned short z;
167 
174  unsigned long synchEdgeTime[4];
175 
182  unsigned long byteTime[8];
184 
185 #include <poppack.h>
186 
187 
196 #define LIN_TX 1
197 #define LIN_RX 2
198 #define LIN_WAKEUP_FRAME 4
199 #define LIN_NODATA 8
200 #define LIN_CSUM_ERROR 16
201 #define LIN_PARITY_ERROR 32
202 #define LIN_SYNCH_ERROR 64
203 #define LIN_BIT_ERROR 128
204 
226 #define linCHANNELDATA_CARD_FIRMWARE_REV 9
227 
233 #define LINERROR(f) ((f) & (LIN_NODATA | LIN_CSUM_ERROR | LIN_SYNCH_ERROR | LIN_BIT_ERROR))
234 
235 
236 // Define LINLIBAPI unless it's done already.
237 // (linlib.c provides its own definition of LINLIBAPI before including this file.)
238 //
239 #ifndef LINLIBAPI
240 # if defined(__BORLANDC__)
241 # define LINLIBAPI __stdcall
242 # elif defined(_MSC_VER) || defined(__MWERKS__) || defined(__GNUC__)
243 # define LINLIBAPI __stdcall
244 # endif
245 #endif
246 
247 #ifdef __cplusplus
248 extern "C" {
249 #endif
250 
259 void LINLIBAPI linInitializeLibrary(void);
260 
267 void LINLIBAPI linUnloadLibrary(void);
268 
269 
305 LinStatus LINLIBAPI linGetTransceiverData(int channel, unsigned char eanNo[8],
306  unsigned char serNo[8], int *ttype);
307 
328 LinHandle LINLIBAPI linOpenChannel(int channel, int flags);
329 
330 
339 #define LIN_MASTER 1
340 #define LIN_SLAVE 2
341 
356 LinStatus LINLIBAPI linClose(LinHandle h);
357 
358 
373 LinStatus LINLIBAPI linGetVersion(int *major, int *minor, int *build);
374 
375 
412  unsigned char *bootVerMajor,
413  unsigned char *bootVerMinor,
414  unsigned char *bootVerBuild,
415  unsigned char *appVerMajor,
416  unsigned char *appVerMinor,
417  unsigned char *appVerBuild);
418 
419 
420 
441 LinStatus LINLIBAPI linGetChannelData(int channel, int item, void *buffer, size_t bufsize);
442 
459 LinStatus LINLIBAPI linSetBitrate(LinHandle h, unsigned int bps);
460 
475 LinStatus LINLIBAPI linBusOn(LinHandle h);
476 
490 LinStatus LINLIBAPI linBusOff(LinHandle h);
491 
504 unsigned long LINLIBAPI linReadTimer(LinHandle h);
505 
527 LinStatus LINLIBAPI linWriteMessage(LinHandle h, unsigned int id, const void *msg,
528  unsigned int dlc);
529 
545 LinStatus LINLIBAPI linRequestMessage(LinHandle h, unsigned int id);
546 
573 LinStatus LINLIBAPI linReadMessage(LinHandle h, unsigned int *id, void *msg,
574  unsigned int *dlc, unsigned int *flags,
575  LinMessageInfo *msgInfo);
576 
606 LinStatus LINLIBAPI linReadMessageWait(LinHandle h, unsigned int *id, void *msg,
607  unsigned int *dlc, unsigned int *flags,
608  LinMessageInfo *msgInfo, unsigned long timeout);
609 
629 LinStatus LINLIBAPI linUpdateMessage(LinHandle h, unsigned int id, const void *msg,
630  unsigned int dlc);
631 
632 
656 LinStatus LINLIBAPI linSetupIllegalMessage(LinHandle h, unsigned int id,
657  unsigned int cFlags, unsigned int delay);
658 
667 #define LIN_MSG_DISTURB_CSUM 1
668 
672 #define LIN_MSG_DISTURB_PARITY 2
673 
684 #define LIN_MSG_USE_STANDARD_PARITY 0x04
685 
688 #define LIN_MSG_USE_ENHANCED_PARITY 0x08
689 
724 LinStatus LINLIBAPI linSetupLIN(LinHandle h, unsigned int lFlags, unsigned int bps);
725 
726 
739 #define LIN_ENHANCED_CHECKSUM 1
740 
746 #define LIN_VARIABLE_DLC 2
747 
769 LinStatus LINLIBAPI linWriteWakeup(LinHandle h, unsigned int count,
770  unsigned int interval);
771 
772 
785 LinStatus LINLIBAPI linClearMessage(LinHandle h, unsigned int id);
786 
829 LinStatus LINLIBAPI linWriteSync(LinHandle h, unsigned long timeout);
830 
842 LinStatus LINLIBAPI linGetCanHandle(LinHandle h, unsigned int *canHandle);
843 
892 #ifdef __cplusplus
893 }
894 #endif
895 
896 #endif // __LINLIB_H