Subversion Repositories HomeAutomation

Rev

Rev 244 | Blame | 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.  
  9.  
  10. /*-----------------------------------------------------------------------------
  11.  * Type Definitions
  12.  *---------------------------------------------------------------------------*/
  13.  
  14.  
  15. /**
  16.  * CAN Return Type. Most CAN functions return one of these.
  17.  */
  18. typedef enum {
  19.     CAN_FAIL = -1,                  /* The function failed */
  20.     CAN_OK = 1,                     /* The function succeeded */
  21.    
  22.     CAN_MSG_AVAILABLE = 2,          /* Messsages are available */
  23.     CAN_NO_MSG_AVAILABLE = -2,      /* Messages are NOT available */
  24.    
  25.     //CAN_CTRLERROR = -4
  26. } Can_Return_t;
  27.  
  28.  
  29. /**
  30.  * CAN Message Type. Stores a complete CAN frame.
  31.  */
  32. typedef struct {
  33.     /*
  34.      * ID section. Contains either 29bit ID or 11bit ID (depending on ExtendedFlag).
  35.      */
  36.     uint32_t Id;
  37.    
  38.     /*
  39.      * DLC section. Contains the data length expressed in number of bytes. Range [0,8].
  40.      */
  41.     uint8_t DataLength;
  42.    
  43.     /**
  44.      * Extended frame flag. Set to 1 if the ID is 29bit, or 0 if it is 11bit.
  45.      */
  46.     uint8_t ExtendedFlag;
  47.    
  48.     /**
  49.      * Remote frame flag. Set to 1 if the frame is a remote frame. 0 otherwise.
  50.      */
  51.     uint8_t RemoteFlag;
  52.    
  53.     /*
  54.      * DATA section. Contains the 8 data bytes.
  55.      */
  56.     union {
  57.         /* read as 8bit unsigned data */
  58.         uint8_t bytes[8];
  59.        
  60.         /* read as 16bit unsigned data */
  61.         uint16_t words[4];
  62.        
  63.         /* read as 32bit unsigned data */
  64.         uint32_t dwords[2];
  65.     } Data;
  66. } Can_Message_t;
  67.  
  68.  
  69. /*-----------------------------------------------------------------------------
  70.  * Public Function Prototypes
  71.  *---------------------------------------------------------------------------*/
  72.  
  73. //Can_Return_t Can_Init(void);
  74. //Can_Return_t Can_Send(Can_Message_t* msg);
  75. //void Can_Service(void);
  76. //Can_Return_t Can_Receive(Can_Message_t *msg);
  77.  
  78. #endif
  79.