Subversion Repositories HomeAutomation

Rev

Rev 692 | 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.  * @brief Return values.
  16.  *
  17.  * CAN Return Type. Most CAN functions return one of these.
  18.  */
  19. typedef enum {
  20.     CAN_FAIL = -1,              /**< The function failed. */
  21.     CAN_OK = 1,                 /**< The function succeeded. */
  22.    
  23.     CAN_MSG_AVAILABLE = 2,      /**< Messsages are available. */
  24.     CAN_NO_MSG_AVAILABLE = -2/**< Messages are NOT available. */
  25.    
  26. } Can_Return_t;
  27.  
  28. /**
  29.  * @brief Message structure.
  30.  *
  31.  * CAN Message Type. Stores a complete CAN frame.
  32.  */
  33. typedef struct {
  34.     uint32_t Id;                /**< ID section. Contains either 29bit ID or 11bit ID (depending on ExtendedFlag). */
  35.     uint8_t DataLength;         /**< DLC section. Contains the data length expressed in number of bytes. Range [0,8]. */
  36.     uint8_t ExtendedFlag;       /**< Extended frame flag. Set to 1 if the ID is 29bit, or 0 if it is 11bit. */
  37.     uint8_t RemoteFlag;         /**< Remote frame flag. Set to 1 if the frame is a remote frame. 0 otherwise. */
  38.    
  39.     /**
  40.      * DATA section. Contains the 8 data bytes.
  41.      */
  42.     union {
  43.         uint8_t bytes[8];       /**< read as 8bit unsigned data */
  44.         uint16_t words[4];      /**< read as 16bit unsigned data */
  45.         uint32_t dwords[2];     /**< read as 32bit unsigned data */
  46.     } Data;
  47. } Can_Message_t;
  48.  
  49. #endif /*CAN_H_*/
  50.