00001
00017 #ifndef __LINLIB_H
00018 #define __LINLIB_H
00019
00028 typedef int LinHandle;
00029
00033 #define linINVALID_HANDLE ((LinHandle)(-1))
00034
00035 #if !WIN32
00036 # define CompilerAssert(exp) extern char _CompilerAssert[(exp) ? 1 : -1]
00037 #endif
00038
00039
00045 typedef enum {
00046 linOK = 0,
00047 linERR_NOMSG = -1,
00048 linERR_NOTRUNNING = -3,
00049 linERR_RUNNING = -4,
00050 linERR_MASTERONLY = -5,
00051 linERR_SLAVEONLY = -6,
00052 linERR_PARAM = -7,
00053 linERR_NOTFOUND = -8,
00054 linERR_NOMEM = -9,
00055 linERR_NOCHANNELS = -10,
00056 linERR_TIMEOUT = -11,
00057 linERR_NOTINITIALIZED = -12,
00058 linERR_NOHANDLES = -13,
00059 linERR_INVHANDLE = -14,
00060 linERR_CANERROR = -15,
00061 linERR_ERRRESP = -16,
00062 linERR_WRONGRESP = -17,
00063 linERR_DRIVER = -18,
00064 linERR_DRIVERFAILED = -19,
00065 linERR_NOCARD = -20,
00066 linERR_LICENSE = -21,
00067 linERR_INTERNAL = -22,
00068 linERR_NO_ACCESS = -23,
00069 linERR_VERSION = -24
00070 } LinStatus;
00074
00075 #if WIN32
00076 #include <pshpack1.h>
00077 #endif
00078
00093 typedef struct {
00104 unsigned long timestamp;
00105
00110 unsigned long synchBreakLength;
00111
00116 unsigned long frameLength;
00117
00122 unsigned long bitrate;
00123
00128 unsigned char checkSum;
00129
00134 unsigned char idPar;
00135
00136 unsigned short z;
00137
00142 unsigned long synchEdgeTime[4];
00143
00148 unsigned long byteTime[8];
00149 } LinMessageInfo;
00150
00151 #if WIN32
00152 #include <poppack.h>
00153 #endif
00154
00155
00164 #define LIN_TX 1 ///< The message was something we transmitted on the bus
00165 #define LIN_RX 2 ///< The message was something we received from the bus
00166 #define LIN_WAKEUP_FRAME 4 ///< A wake up frame was received. Id/msg/dlc are undefined
00167 #define LIN_NODATA 8 ///< No data, only a header
00168 #define LIN_CSUM_ERROR 16 ///< Checksum error
00169 #define LIN_PARITY_ERROR 32 ///< ID parity error
00170 #define LIN_SYNCH_ERROR 64 ///< A synch error
00171 #define LIN_BIT_ERROR 128 ///< Bit error when transmitting
00172
00177 #define LINERROR(f) ((f) & (LIN_NODATA | LIN_CSUM_ERROR | LIN_SYNCH_ERROR | LIN_BIT_ERROR))
00178
00179
00180
00181
00182
00183 #if WIN32
00184 #ifndef LINLIBAPI
00185 # if defined(__BORLANDC__)
00186 # define LINLIBAPI __stdcall
00187 # elif defined(_MSC_VER) || defined(__MWERKS__) || defined(__GNUC__)
00188 # define LINLIBAPI __stdcall
00189 # endif
00190 #endif
00191 #else
00192 #define LINLIBAPI
00193 #endif
00194
00195 #ifdef __cplusplus
00196 extern "C" {
00197 #endif
00198
00206 void LINLIBAPI linInitializeLibrary(void);
00207
00208
00242 LinStatus LINLIBAPI linGetTransceiverData(int channel, unsigned char eanNo[8],
00243 unsigned char serNo[8], int *ttype);
00244
00266 LinHandle LINLIBAPI linOpenChannel(int channel, int flags);
00267
00268
00273 #define LIN_MASTER 1 ///< The LIN interface will be a LIN master
00274 #define LIN_SLAVE 2 ///< The LIN interface will be a LIN slave
00275
00289 LinStatus LINLIBAPI linClose(LinHandle h);
00290
00322 LinStatus LINLIBAPI linGetFirmwareVersion(LinHandle h,
00323 unsigned char *bootVerMajor,
00324 unsigned char *bootVerMinor,
00325 unsigned char *bootVerBuild,
00326 unsigned char *appVerMajor,
00327 unsigned char *appVerMinor,
00328 unsigned char *appVerBuild);
00329
00344 LinStatus LINLIBAPI linSetBitrate(LinHandle h, unsigned int bps);
00345
00358 LinStatus LINLIBAPI linBusOn(LinHandle h);
00359
00371 LinStatus LINLIBAPI linBusOff(LinHandle h);
00372
00384 unsigned long LINLIBAPI linReadTimer(LinHandle h);
00385
00405 LinStatus LINLIBAPI linWriteMessage(LinHandle h, unsigned int id, const void *msg,
00406 unsigned int dlc);
00407
00420 LinStatus LINLIBAPI linRequestMessage(LinHandle h, unsigned int id);
00421
00447 LinStatus LINLIBAPI linReadMessage(LinHandle h, unsigned int *id, void *msg,
00448 unsigned int *dlc, unsigned int *flags,
00449 LinMessageInfo *msgInfo);
00450
00479 LinStatus LINLIBAPI linReadMessageWait(LinHandle h, unsigned int *id, void *msg,
00480 unsigned int *dlc, unsigned int *flags,
00481 LinMessageInfo *msgInfo, unsigned long timeout);
00482
00500 LinStatus LINLIBAPI linUpdateMessage(LinHandle h, unsigned int id, const void *msg,
00501 unsigned int dlc);
00502
00503
00526 LinStatus LINLIBAPI linSetupIllegalMessage(LinHandle h, unsigned int id,
00527 unsigned int cFlags, unsigned int delay);
00528
00537 #define LIN_MSG_DISTURB_CSUM 1
00538
00542 #define LIN_MSG_DISTURB_PARITY 2
00543
00554 #define LIN_MSG_USE_STANDARD_PARITY 0x04
00555
00558 #define LIN_MSG_USE_ENHANCED_PARITY 0x08
00559
00592 LinStatus LINLIBAPI linSetupLIN(LinHandle h, unsigned int lFlags, unsigned int bps);
00593
00594
00607 #define LIN_ENHANCED_CHECKSUM 1
00608
00614 #define LIN_VARIABLE_DLC 2
00615
00633 LinStatus LINLIBAPI linWriteWakeup(LinHandle h, unsigned int count,
00634 unsigned int interval);
00635
00636
00648 LinStatus LINLIBAPI linClearMessage(LinHandle h, unsigned int id);
00649
00691 LinStatus LINLIBAPI linWriteSync(LinHandle h, unsigned long timeout);
00692
00703 LinStatus LINLIBAPI linGetCanHandle(LinHandle h, unsigned int *canHandle);
00704
00705 #ifdef __cplusplus
00706 }
00707 #endif
00708
00711 #endif // __LINLIB_H