can_types.h
Go to the documentation of this file.
00001 #ifndef __CAN_TYPES_H__
00002 #define __CAN_TYPES_H__
00003 
00004 #ifdef WIN32
00005   #ifndef __WIN32__
00006     #define __WIN32__
00007   #endif
00008 #endif
00009 
00010 #ifdef __WIN32__
00011 // Windows
00012 #include <windows.h>
00013 
00014 #define int32_t __int32
00015 #define uint32_t unsigned __int32
00016 #define int16_t __int16
00017 #define uint16_t unsigned __int16
00018 #else
00019 // Linux & Mac
00020 //#include <unistd.h>
00021 //#include <stdlib.h>
00022 //#include <sys/time.h>
00023 #include <stdint.h>
00024 #endif
00025 
00026 #ifdef __cplusplus
00027   extern "C" {
00028 #endif
00029 
00030 #define INDEX_INVALID          0xFFFFFFFF
00031 
00032 #define INDEX_FIFO_PUFFER_MASK 0x0000FFFF
00033 #define INDEX_SOFT_FLAG        0x02000000
00034 #define INDEX_RXD_TXT_FLAG     0x01000000
00035 #define INDEX_CAN_KANAL_MASK   0x000F0000
00036 #define INDEX_CAN_DEVICE_MASK  0x00F00000
00037 
00038 #define INDEX_USER_MASK        0xFC000000
00039 
00040 #define INDEX_CAN_KANAL_A      0x00000000
00041 #define INDEX_CAN_KANAL_B      0x00010000
00042 
00043 /***************************************************************/
00044 /*  Typen                                                      */
00045 /***************************************************************/
00046 
00047 /******************************************/
00048 /*            CAN Message Type            */
00049 /******************************************/
00050 #define MsgFlags Flags.Long
00051 #define MsgLen Flags.Flag.Len
00052 #define MsgRTR Flags.Flag.RTR
00053 #define MsgEFF Flags.Flag.EFF
00054 #define MsgTxD Flags.Flag.TxD
00055 #define MsgErr Flags.Flag.Error
00056 #define MsgSource Flags.Flag.Source
00057 #define MsgData Data.Bytes
00058 
00059 /*
00060 Byte
00061 
00062  0 -> LEC Last Error Code 
00063         1 = Stuff Error More than 5 equal bits in a sequence have occurred in a part of a received message where this is not allowed.
00064         2 = Form Error A fixed format part of a received frame has the wrong format.
00065         3 = AckError The message this CAN Core transmitted was not acknowledged by another node.
00066         4 = Bit1Error During the transmission of a message (with the exception of the arbitration field), the device wanted to send a recessive level (bit of logical value ‘1’), but the monitored busvalue was dominant.
00067         5 = Bit0Error During the transmission of a message (or acknowledge bit or active error flag, or overload flag), the device wanted to send a dominant level (data or identifier bit logical value ‘0’), but the monitored Bus value was recessive. During busoff recovery this status is set each time a sequence of 11 recessive bits has been monitored. This enables the CPU to monitor the proceeding of the busoff recovery sequence (indicating the bus is not stuck at dominant level or continuously disturbed).
00068         6 = CRCError The CRC check sum was incorrect in the message received, the CRC received for an incoming message does not match with the calculated CRC for the received data.
00069   1 -> Bus Status
00070         0 = Ok
00071         1 = Error Warning
00072         2 = Error Passiv
00073         3 = Bus Off
00074   2 -> Receive Error Counter
00075   3 -> Transmit Error Counter               
00076 */
00077 
00078 struct TCanFlagsBits
00079   {
00080   unsigned Len:4;    // DLC -> Datenlänge 0 - 8 Byte
00081   unsigned TxD:1;    // TxD -> 1 = Tx CAN Nachricht, 0 = Rx CAN Nachricht
00082                      //        Eine Erfolgreich versendete Nachricht wird als Bestätigung
00083                      //        ins Empfangsfifo zurückgeschrieben
00084                      //        Nicht alle Module unterstützen diese Funktion u. das 
00085                      //        Feature muss aktiveirt sein
00086   unsigned Error:1;  // Error -> 1 = CAN Bus Fehler Nachricht
00087                      //        Nicht alle Module unterstützen diese Funktion u. das 
00088                      //        Feature muss aktiveirt sein
00089   unsigned RTR:1;    // Remote Transmition Request bit -> Kennzeichnet eine RTR Nachricht
00090   unsigned EFF:1;    // Extended Frame Format bit -> 1 = 29 Bit Id's, 0 = 11 Bit Id's
00091   unsigned Source:8; // Quelle der Nachricht (Device)
00092   };
00093 
00094 union TCanFlags
00095   {
00096   struct TCanFlagsBits Flag;
00097   uint32_t Long;
00098   };
00099 
00100 union TCanData
00101   {
00102   char Chars[8];
00103   unsigned char Bytes[8];
00104   uint16_t Words[4];
00105   uint32_t Longs[2];
00106   };
00107 
00108 struct TTime
00109   {
00110   uint32_t Sec;
00111   uint32_t USec;
00112   };
00113 
00114 struct TCanMsg
00115   {
00116   uint32_t Id;
00117   union TCanFlags Flags;
00118   union TCanData Data;
00119   struct TTime Time;
00120   };
00121 
00122 /******************************************/
00123 /*         CAN Message Filter Type        */
00124 /******************************************/
00125 #define FilFlags Flags.Long
00126 #define FilRTR Flags.Flag.RTR
00127 #define FilEFF Flags.Flag.EFF
00128 #define FilMode Flags.Flag.Mode
00129 #define FilIdMode Flags.Flag.IdMode
00130 #define FilEnable Flags.Flag.Enable
00131 
00132 // * = Reserviert, zur Zeit noch unbenutzt
00133 
00134 struct TMsgFilterFlagsBits
00135   {
00136   // 1. Byte
00137   unsigned Len:4;       // * Dlc
00138   unsigned Res:2;       // Reserviert
00139   unsigned RTR:1;       // Remote Transmition Request
00140   unsigned EFF:1;       // Extended Frame Format
00141   // 2. Byte
00142   unsigned IdMode:2;    // 0 = Maske & Code
00143                         // 1 = Start & Stop
00144                         // 2 = Single Id
00145   unsigned DLCCheck:1;  // *
00146   unsigned DataCheck:1; // *
00147   unsigned Res1:4;
00148   // 3. Byte
00149   unsigned Res2:8;
00150   // 4. Byte
00151   unsigned Type:4;      // 0 = Single Puffer
00152   unsigned Res3:2;
00153   unsigned Mode:1;      // 0 = Message entfernen
00154                         // 1 = Message nicht entfernen
00155   unsigned Enable:1;    // 0 = Filter sperren
00156                         // 1 = Filter freigeben
00157   };
00158 
00159 
00160 union TMsgFilterFlags
00161   {
00162   struct TMsgFilterFlagsBits Flag;
00163   uint32_t Long;
00164   };
00165 
00166 struct TMsgFilter
00167   {                     // IdMode    -> Maske & Code | Start & Stop | Single Id
00168                         // --------------------------+--------------+-----------
00169   uint32_t Maske;       // Filter-Id ->    Maske     |     Stop     |  
00170   uint32_t Code;        // Filter-Id ->    Code      |     Start    |    Id
00171   union TMsgFilterFlags Flags;
00172   union TCanData Data;  // *
00173   };
00174 
00175 struct TCanIndexSource
00176   {
00177   // 1. u. 2 Byte
00178   unsigned SubIndex:16;
00179   // 3. Byte
00180   unsigned Source:8;
00181   // 4. Byte
00182   unsigned TxD:1;
00183   unsigned Soft:1;
00184   unsigned User:6;
00185   };
00186 
00187 struct TCanIndexBits
00188   {
00189   // 1. u. 2 Byte
00190   unsigned SubIndex:16;
00191   // 3. Byte
00192   unsigned Channel:4;
00193   unsigned Device:4;
00194   // 4. Byte
00195   unsigned TxD:1;
00196   unsigned Soft:1;
00197   unsigned User:6;
00198   };
00199 
00200 union TCanIndex
00201   {
00202   struct TCanIndexBits Item;
00203   struct TCanIndexSource SrcItem;
00204   uint32_t Long;
00205   };
00206 
00207 
00208 #ifdef __cplusplus
00209   }
00210 #endif
00211 
00212 
00213 #endif


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