Kvaser CANLIB: linlib.h Source File

linlib.h

Go to the documentation of this file.
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 // sizeof(LinMessageInfo) should be 68 for correct alignment
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 // Define LINLIBAPI unless it's done already.
00181 // (linlib.c provides its own definition of LINLIBAPI before including this file.)
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 
00213 void LINLIBAPI linUnloadLibrary(void);
00214 
00215 
00249 LinStatus LINLIBAPI linGetTransceiverData(int channel, unsigned char eanNo[8],
00250                                           unsigned char serNo[8], int *ttype);
00251 
00273 LinHandle LINLIBAPI linOpenChannel(int channel, int flags);
00274 
00275 
00280 #define LIN_MASTER 1 ///< The LIN interface will be a LIN master
00281 #define LIN_SLAVE 2  ///< The LIN interface will be a LIN slave
00282 
00296 LinStatus LINLIBAPI linClose(LinHandle h);
00297 
00329 LinStatus LINLIBAPI linGetFirmwareVersion(LinHandle h,
00330                                           unsigned char *bootVerMajor,
00331                                           unsigned char *bootVerMinor,
00332                                           unsigned char *bootVerBuild,
00333                                           unsigned char *appVerMajor,
00334                                           unsigned char *appVerMinor,
00335                                           unsigned char *appVerBuild);
00336 
00351 LinStatus LINLIBAPI linSetBitrate(LinHandle h, unsigned int bps);
00352 
00365 LinStatus LINLIBAPI linBusOn(LinHandle h);
00366 
00378 LinStatus LINLIBAPI linBusOff(LinHandle h);
00379 
00391 unsigned long LINLIBAPI linReadTimer(LinHandle h);
00392 
00412 LinStatus LINLIBAPI linWriteMessage(LinHandle h, unsigned int id, const void *msg,
00413                                     unsigned int dlc);
00414 
00427 LinStatus LINLIBAPI linRequestMessage(LinHandle h, unsigned int id);
00428 
00454 LinStatus LINLIBAPI linReadMessage(LinHandle h, unsigned int *id, void *msg,
00455                                    unsigned int *dlc, unsigned int *flags,
00456                                    LinMessageInfo *msgInfo);
00457 
00486 LinStatus LINLIBAPI linReadMessageWait(LinHandle h, unsigned int *id, void *msg,
00487                                        unsigned int *dlc, unsigned int *flags,
00488                                        LinMessageInfo *msgInfo, unsigned long timeout);
00489 
00507 LinStatus LINLIBAPI linUpdateMessage(LinHandle h, unsigned int id, const void *msg,
00508                                      unsigned int dlc);
00509 
00510 
00533 LinStatus LINLIBAPI linSetupIllegalMessage(LinHandle h, unsigned int id,
00534                                            unsigned int cFlags, unsigned int delay);
00535                                            
00544 #define LIN_MSG_DISTURB_CSUM   1
00545 
00549 #define LIN_MSG_DISTURB_PARITY 2
00550 
00561 #define LIN_MSG_USE_STANDARD_PARITY 0x04
00562 
00565 #define LIN_MSG_USE_ENHANCED_PARITY 0x08 
00566 
00599 LinStatus LINLIBAPI linSetupLIN(LinHandle h, unsigned int lFlags, unsigned int bps);
00600 
00601 
00614 #define LIN_ENHANCED_CHECKSUM  1
00615 
00621 #define LIN_VARIABLE_DLC       2
00622 
00640 LinStatus LINLIBAPI linWriteWakeup(LinHandle h, unsigned int count,
00641                                    unsigned int interval);
00642 
00643 
00655 LinStatus LINLIBAPI linClearMessage(LinHandle h, unsigned int id);
00656 
00698 LinStatus LINLIBAPI linWriteSync(LinHandle h, unsigned long timeout);
00699 
00710 LinStatus LINLIBAPI linGetCanHandle(LinHandle h, unsigned int *canHandle);
00711 
00712 #ifdef __cplusplus
00713 }
00714 #endif
00715 
00718 #endif // __LINLIB_H