can_drv.h
Go to the documentation of this file.
00001 #ifndef __CAN_DRV_H__
00002 #define __CAN_DRV_H__
00003 
00004 #include "can_types.h"
00005 
00006 #ifdef __WIN32__
00007 // ****** Windows
00008 #include <windows.h>
00009 //#define DRV_CALLBACK_TYPE CALLBACK
00010 #define DRV_CALLBACK_TYPE __stdcall
00011 #else
00012 #define DRV_CALLBACK_TYPE
00013 #endif
00014 
00015 #ifdef __cplusplus
00016   extern "C" {
00017 #endif
00018 
00019 /***************************************************************/
00020 /* Define Makros                                               */
00021 /***************************************************************/
00022 
00023 // CAN Übertragungsgeschwindigkeit
00024 #define CAN_10K_BIT   10    // 10 kBit/s
00025 #define CAN_20K_BIT   20    // 20 kBit/s
00026 #define CAN_50K_BIT   50    // 50 kBit/s
00027 #define CAN_100K_BIT  100   // 100 kBit/s
00028 #define CAN_125K_BIT  125   // 125 kBit/s
00029 #define CAN_250K_BIT  250   // 250 kBit/s
00030 #define CAN_500K_BIT  500   // 500 kBit/s
00031 #define CAN_800K_BIT  800   // 800 kBit/s
00032 #define CAN_1M_BIT    1000  // 1 MBit/s
00033 
00034 // Time Stamp Mode
00035 #define TIME_STAMP_OFF        0  // keine Time-Stamps
00036 #define TIME_STAMP_SOFT       1  // Software Time-Stamps
00037 #define TIME_STAMP_HW_UNIX    2  // Hardware Time-Stamps, UNIX-Format 
00038 #define TIME_STAMP_HW         3  // Hardware Time-Stamps
00039 #define TIME_STAMP_HW_SW_UNIX 4  // Hardware Time-Stamps verwenden wenn verfügbar,
00040                                  // ansonsten Software Time-Stamps 
00041                                  // Ab Treiber Version 4.08!
00042 
00043 // CAN Bus Mode
00044 #define OP_CAN_NO_CHANGE         0  // Aktuellen Zustand nicht ändern
00045 #define OP_CAN_START             1  // Startet den CAN-Bus
00046 #define OP_CAN_STOP              2  // Stopt den CAN-Bus
00047 #define OP_CAN_RESET             3  // Reset CAN Controller (BusOff löschen)
00048 #define OP_CAN_START_LOM         4  // Startet den CAN-Bus im Silent Mode (Listen Only Mode)
00049 #define OP_CAN_START_NO_RETRANS  5  // Startet den CAN-Bus im Automatic Retransmission disable Mode
00050 
00051 #define CAN_CMD_NONE                0x0000
00052 #define CAN_CMD_RXD_OVERRUN_CLEAR   0x0001
00053 #define CAN_CMD_RXD_FIFOS_CLEAR     0x0002
00054 #define CAN_CMD_TXD_OVERRUN_CLEAR   0x0004
00055 #define CAN_CMD_TXD_FIFOS_CLEAR     0x0008
00056 #define CAN_CMD_HW_FILTER_CLEAR     0x0010
00057 #define CAN_CMD_SW_FILTER_CLEAR     0x0020
00058 #define CAN_CMD_TXD_PUFFERS_CLEAR   0x0040
00059 
00060 #define CAN_CMD_ALL_CLEAR           0x0FFF
00061 
00062 
00063 // DrvStatus
00064 #define DRV_NOT_LOAD              0  // Die Treiber DLL wurde noch nicht geladen
00065 #define DRV_STATUS_NOT_INIT       1  // Treiber noch nicht Initialisiert (Funktion "CanInitDrv" noch nicht aufgerufen)
00066 #define DRV_STATUS_INIT           2  // Treiber erfolgrich Initialisiert
00067 #define DRV_STATUS_PORT_NOT_OPEN  3  // Die Schnittstelle wurde nicht geöffnet
00068 #define DRV_STATUS_PORT_OPEN      4  // Die Schnittstelle wurde geöffnet
00069 #define DRV_STATUS_DEVICE_FOUND   5  // Verbindung zur Hardware wurde Hergestellt
00070 #define DRV_STATUS_CAN_OPEN       6  // Device wurde geöffnet und erfolgreich Initialisiert
00071 #define DRV_STATUS_CAN_RUN_TX     7  // CAN Bus RUN nur Transmitter (wird nicht verwendet !)
00072 #define DRV_STATUS_CAN_RUN        8  // CAN Bus RUN
00073 
00074 // CanStatus
00075 #define CAN_STATUS_OK          0     // CAN-Controller: Ok
00076 #define CAN_STATUS_ERROR       1     // CAN-Controller: CAN Error
00077 #define CAN_STATUS_WARNING     2     // CAN-Controller: Error warning
00078 #define CAN_STATUS_PASSIV      3     // CAN-Controller: Error passiv
00079 #define CAN_STATUS_BUS_OFF     4     // CAN-Controller: Bus Off
00080 #define CAN_STATUS_UNBEKANNT   5     // CAN-Controller: Status Unbekannt
00081 
00082 // Fifo Status
00083 #define FIFO_OK                 0 // Fifo-Status: Ok
00084 #define FIFO_HW_OVERRUN         1 // Fifo-Status: Hardware Fifo Überlauf
00085 #define FIFO_SW_OVERRUN         2 // Fifo-Status: Software Fifo Überlauf
00086 #define FIFO_HW_SW_OVERRUN      3 // Fifo-Status: Hardware & Software Fifo Überlauf
00087 #define FIFO_STATUS_UNBEKANNT   4 // Fifo-Status: Unbekannt
00088 
00089 // Makros für SetEvent
00090 #define EVENT_ENABLE_PNP_CHANGE          0x0001
00091 #define EVENT_ENABLE_STATUS_CHANGE       0x0002
00092 #define EVENT_ENABLE_RX_FILTER_MESSAGES  0x0004
00093 #define EVENT_ENABLE_RX_MESSAGES         0x0008
00094 #define EVENT_ENABLE_ALL                 0x00FF
00095 
00096 #define EVENT_DISABLE_PNP_CHANGE         0x0100
00097 #define EVENT_DISABLE_STATUS_CHANGE      0x0200
00098 #define EVENT_DISABLE_RX_FILTER_MESSAGES 0x0400
00099 #define EVENT_DISABLE_RX_MESSAGES        0x0800
00100 #define EVENT_DISABLE_ALL                0xFF00
00101 
00102 
00103 /***************************************************************/
00104 /*  Typen                                                      */
00105 /***************************************************************/
00106 
00107 /******************************************/
00108 /*             Device Status              */
00109 /******************************************/
00110 struct TDeviceStatus
00111   {
00112   int32_t DrvStatus;         // Treiber Status (Device close / Device open / CAN Bus RUN)
00113   unsigned char CanStatus;   // Status des CAN Controllers (Ok / ... / Error passiv / Bus off)
00114   unsigned char FifoStatus;  // Fifo Status (Ok / ... / Hard. u. Soft. FIFO Überlauf)
00115   };
00116 
00117 
00118 #ifdef CAN_API_TRUE_FUNC
00119 
00120 int32_t CanInitDriver(char *options);
00121 void CanDownDriver(void);
00122 int32_t CanSetOptions(char *options);
00123 int32_t CanDeviceOpen(uint32_t  index, char *parameter);
00124 int32_t CanDeviceClose(uint32_t  index);
00125 
00126 int32_t CanSetMode(uint32_t  index, unsigned char can_op_mode, uint16_t  can_command);
00127 
00128 int32_t CanTransmit(uint32_t  index, struct TCanMsg *msg, int32_t count);
00129 void CanTransmitClear(uint32_t  index);
00130 uint32_t  CanTransmitGetCount(uint32_t  index);
00131 int32_t CanTransmitSet(uint32_t  index, uint16_t  cmd,
00132   uint32_t  time);
00133 int32_t CanReceive(uint32_t  index, struct TCanMsg *msg, int32_t count);
00134 void CanReceiveClear(uint32_t  index);
00135 uint32_t  CanReceiveGetCount(uint32_t  index);
00136 
00137 int32_t CanSetSpeed(uint32_t  index, uint16_t  speed);
00138 int32_t CanSetSpeedUser(uint32_t  index, uint32_t  value);
00139 char *CanDrvInfo(void);
00140 char *CanDrvHwInfo(uint32_t  index);
00141 int32_t CanSetFilter(uint32_t  index, struct TMsgFilter *msg_filter);
00142 int32_t CanGetDeviceStatus(uint32_t  index, struct TDeviceStatus *status);
00143 void CanSetPnPEventCallback(void (CALLBACK *event)(uint32_t  index, int32_t status));
00144 void CanSetStatusEventCallback(void (CALLBACK *event)
00145   (uint32_t  index, struct TDeviceStatus *device_status));
00146 void CanSetRxEventCallback(void (CALLBACK *event)(uint32_t  index,
00147   struct TCanMsg *msg, int32_t count));
00148 
00149 void CanSetEvents(uint16_t  events);
00150 uint32_t CanEventStatus(void);
00151 
00152 #endif
00153 
00154 
00155 #if !(defined(CAN_API_TRUE_FUNC)) || defined(CAN_DRV_INCLUDE)
00156 /***************************************************************/
00157 /*  Funktionstypen                                             */
00158 /***************************************************************/
00159 typedef int32_t (DRV_CALLBACK_TYPE *TCanInitDriver)(char *options);
00160 typedef void (DRV_CALLBACK_TYPE *TCanDownDriver)(void);
00161 typedef int32_t (DRV_CALLBACK_TYPE *TCanSetOptions)(char *options);
00162 typedef int32_t (DRV_CALLBACK_TYPE *TCanDeviceOpen)(uint32_t index, char *parameter);
00163 typedef int32_t (DRV_CALLBACK_TYPE *TCanDeviceClose)(uint32_t index);
00164 
00165 typedef int32_t (DRV_CALLBACK_TYPE *TCanSetMode)(uint32_t index, unsigned char can_op_mode,
00166                  uint16_t  can_command);
00167 
00168 typedef int32_t (DRV_CALLBACK_TYPE *TCanTransmit)(uint32_t index, struct TCanMsg *msg, int32_t count);
00169 typedef void (DRV_CALLBACK_TYPE *TCanTransmitClear)(uint32_t index);
00170 typedef uint32_t  (DRV_CALLBACK_TYPE *TCanTransmitGetCount)(uint32_t index);
00171 typedef int32_t (DRV_CALLBACK_TYPE *TCanTransmitSet)(uint32_t index, uint16_t cmd,
00172   uint32_t time);
00173 typedef int32_t (DRV_CALLBACK_TYPE *TCanReceive)(uint32_t index, struct TCanMsg *msg, int32_t count);
00174 typedef void (DRV_CALLBACK_TYPE *TCanReceiveClear)(uint32_t index);
00175 typedef uint32_t  (DRV_CALLBACK_TYPE *TCanReceiveGetCount)(uint32_t index);
00176 
00177 typedef int32_t (DRV_CALLBACK_TYPE *TCanSetSpeed)(uint32_t index, uint16_t speed);
00178 typedef int32_t (DRV_CALLBACK_TYPE *TCanSetSpeedUser)(uint32_t index, uint32_t value);
00179 typedef char * (DRV_CALLBACK_TYPE *TCanDrvInfo)(void);
00180 typedef char * (DRV_CALLBACK_TYPE *TCanDrvHwInfo)(uint32_t index);
00181 typedef int32_t (DRV_CALLBACK_TYPE *TCanSetFilter)(uint32_t index, struct TMsgFilter *msg_filter);
00182 
00183 typedef int32_t (DRV_CALLBACK_TYPE *TCanGetDeviceStatus)(uint32_t index, struct TDeviceStatus *status);
00184 
00185 typedef void (DRV_CALLBACK_TYPE *TCanSetPnPEventCallback)(void (DRV_CALLBACK_TYPE *event)
00186    (uint32_t index, int32_t status));
00187 typedef void (DRV_CALLBACK_TYPE *TCanSetStatusEventCallback)(void (DRV_CALLBACK_TYPE *event)
00188    (uint32_t index, struct TDeviceStatus *device_status));
00189 typedef void (DRV_CALLBACK_TYPE *TCanSetRxEventCallback)(void (DRV_CALLBACK_TYPE *event)
00190    (uint32_t index, struct TCanMsg *msg, int32_t count));
00191 
00192 typedef void (DRV_CALLBACK_TYPE *TCanSetEvents)(uint16_t events);
00193 typedef uint32_t (DRV_CALLBACK_TYPE *TCanEventStatus)(void);
00194 
00195 #endif
00196 
00197 
00198 #ifndef CAN_API_TRUE_FUNC
00199 /***************************************************************/
00200 /*  Tiny-CAN API Funktionen                                    */
00201 /***************************************************************/
00202 
00203 extern TCanInitDriver CanInitDriver;
00204 extern TCanDownDriver CanDownDriver;
00205 extern TCanSetOptions CanSetOptions;
00206 extern TCanDeviceOpen CanDeviceOpen;
00207 extern TCanDeviceClose CanDeviceClose;
00208 
00209 extern TCanSetMode CanSetMode;
00210 
00211 extern TCanTransmit CanTransmit;
00212 extern TCanTransmitClear CanTransmitClear;
00213 extern TCanTransmitGetCount CanTransmitGetCount;
00214 extern TCanTransmitSet CanTransmitSet;
00215 extern TCanReceive CanReceive;
00216 extern TCanReceiveClear CanReceiveClear;
00217 extern TCanReceiveGetCount CanReceiveGetCount;
00218 
00219 extern TCanSetSpeed CanSetSpeed;
00220 extern TCanSetSpeedUser CanSetSpeedUser;
00221 
00222 extern TCanDrvInfo CanDrvInfo;
00223 extern TCanDrvHwInfo CanDrvHwInfo;
00224 extern TCanSetFilter CanSetFilter;
00225 
00226 extern TCanGetDeviceStatus CanGetDeviceStatus;
00227 
00228 extern TCanSetPnPEventCallback CanSetPnPEventCallback;
00229 extern TCanSetStatusEventCallback CanSetStatusEventCallback;
00230 extern TCanSetRxEventCallback CanSetRxEventCallback;
00231 
00232 extern TCanSetEvents CanSetEvents;
00233 extern TCanEventStatus CanEventStatus;
00234 
00235 #endif
00236 
00237 /***************************************************************/
00238 /*  Funktionen Treiber laden/entladen                          */
00239 /***************************************************************/
00240 int32_t LoadDriver(const char *file_name);
00241 void UnloadDriver(void);
00242 
00243 #include "can_drv_ex.h"
00244 
00245 #ifdef __cplusplus
00246   }
00247 #endif
00248 
00249 #endif


tinycan
Author(s): M.Fischer
autogenerated on Thu Jun 6 2019 20:39:28