Subversion Repositories HomeAutomation

Rev

Rev 361 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. #ifndef CAN_H_
  2. #define CAN_H_
  3.  
  4. /*-----------------------------------------------------------------------------
  5.  * Includes
  6.  *---------------------------------------------------------------------------*/
  7. #include <inttypes.h>
  8. #include <drivers/can/canid.h>
  9.  
  10. /*-----------------------------------------------------------------------------
  11.  * Type Definitions
  12.  *---------------------------------------------------------------------------*/
  13.  
  14. /**
  15.  * CAN Return Type. Most CAN functions return one of these.
  16.  */
  17. typedef enum {
  18.     CAN_FAIL = -1,                  /* The function failed */
  19.     CAN_OK = 1,                     /* The function succeeded */
  20.    
  21.     CAN_MSG_AVAILABLE = 2,          /* Messsages are available */
  22.     CAN_NO_MSG_AVAILABLE = -2,      /* Messages are NOT available */
  23.    
  24.     //CAN_CTRLERROR = -4
  25. } Can_Return_t;
  26.  
  27. /**
  28.  * CAN Message Type. Stores a complete CAN frame.
  29.  */
  30. typedef struct {
  31.     /*
  32.      * ID section. Contains either 29bit ID or 11bit ID (depending on ExtendedFlag).
  33.      */
  34.     uint32_t Id;
  35.    
  36.     /*
  37.      * DLC section. Contains the data length expressed in number of bytes. Range [0,8].
  38.      */
  39.     uint8_t DataLength;
  40.    
  41.     /**
  42.      * Extended frame flag. Set to 1 if the ID is 29bit, or 0 if it is 11bit.
  43.      */
  44.     uint8_t ExtendedFlag;
  45.    
  46.     /**
  47.      * Remote frame flag. Set to 1 if the frame is a remote frame. 0 otherwise.
  48.      */
  49.     uint8_t RemoteFlag;
  50.    
  51.     /*
  52.      * DATA section. Contains the 8 data bytes.
  53.      */
  54.     union {
  55.         /* read as 8bit unsigned data */
  56.         uint8_t bytes[8];
  57.        
  58.         /* read as 16bit unsigned data */
  59.         uint16_t words[4];
  60.        
  61.         /* read as 32bit unsigned data */
  62.         uint32_t dwords[2];
  63.     } Data;
  64. } Can_Message_t;
  65.  
  66. #endif /*CAN_H_*/
  67.