Subversion Repositories HomeAutomation

Rev

Rev 568 | 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. #define CAN_FLAG_EXT 0x01
  28. #define CAN_FLAG_RTR 0x80
  29.  
  30. /**
  31.  * CAN Message Type. Stores a complete CAN frame.
  32.  */
  33. typedef struct {
  34.     /*
  35.      * ID section. Contains either 29bit ID or 11bit ID (depending on ExtendedFlag).
  36.      */
  37.     uint32_t Id;
  38.    
  39.     /*
  40.      * DLC section. Contains the data length expressed in number of bytes. Range [0,8].
  41.      */
  42.     uint8_t DataLength;
  43.    
  44.     /**
  45.      * Extended frame flag. Set to 1 if the ID is 29bit, or 0 if it is 11bit.
  46.      */
  47.     uint8_t Flags;
  48.    
  49.     /*
  50.      * DATA section. Contains the 8 data bytes.
  51.      */
  52.     union {
  53.         /* read as 8bit unsigned data */
  54.         uint8_t bytes[8];
  55.        
  56.         /* read as 16bit unsigned data */
  57.         uint16_t words[4];
  58.        
  59.         /* read as 32bit unsigned data */
  60.         uint32_t dwords[2];
  61.     } Data;
  62. } Can_Message_t;
  63.  
  64. #endif /*CAN_H_*/
  65.