Subversion Repositories HomeAutomation

Rev

Blame | Last modification | View Log | SVN | RSS feed

  1. #ifndef CAN_H_
  2. #define CAN_H_
  3.  
  4. #include <inttypes.h>
  5.  
  6. #define CANDEBUG   1
  7.  
  8. #define CANUSELOOP 0
  9.  
  10. #define CANSENDTIMEOUT (200) /* milliseconds */
  11.  
  12. // initial value of gCANAutoProcess
  13. #define CANAUTOPROCESS (1)
  14. #define CANAUTOON  (1)
  15. #define CANAUTOOFF (0)
  16.  
  17. #define CAN_STDID (0)
  18. #define CAN_EXTID (1)
  19.  
  20. #define CANDEFAULTIDENT    (0x55CC)
  21. #define CANDEFAULTIDENTEXT (CAN_EXTID)
  22.  
  23. #define CAN_20KBPS   (1)
  24. #define CAN_125KBPS  (CAN_20KBPS+1)
  25.  
  26. #define CAN_OK         (0)
  27. #define CAN_FAILINIT   (1)
  28. #define CAN_FAILTX     (2)
  29. #define CAN_MSGAVAIL   (3)
  30. #define CAN_NOMSG      (4)
  31. #define CAN_CTRLERROR  (5)
  32. #define CAN_FAIL       (0xff)
  33.  
  34. #define CAN_MAX_CHAR_IN_MESSAGE (8)
  35.  
  36. typedef struct {
  37.     // identifier CAN_xxxID
  38.     uint8_t  extended_identifier;
  39.     // either extended (the 29 LSB) or standard (the 11 LSB)
  40.     uint32_t identifier;
  41.     // data length:
  42.     uint8_t  dlc;
  43.     uint8_t  dta[CAN_MAX_CHAR_IN_MESSAGE];
  44.    
  45.     // used for receive only:
  46.     // Received Remote Transfer Bit
  47.     //  (0=no... 1=remote transfer request received)
  48.     uint8_t  rtr;  
  49.     // Acceptence Filter that enabled the reception
  50.     uint8_t  filhit;
  51. } CanMessage;
  52.  
  53. extern uint8_t gCANAutoProcess;
  54.  
  55. uint8_t can_init(uint8_t speedset);
  56.  
  57. void can_initMessageStruct(CanMessage* msg);
  58. uint8_t can_sendMessage(const CanMessage* msg);
  59. uint8_t can_checkReceive(void);
  60. uint8_t can_readMessage(CanMessage *msg);
  61. uint8_t can_checkError(void);
  62.  
  63. #if (CANDEBUG)
  64. void can_debug1(void);
  65. void can_dumpMessage(CanMessage *msg);
  66. uint8_t can_testTransmit(const uint8_t ext, const uint8_t data2);
  67. void can_dumpStatus(void);
  68. #endif
  69.  
  70. #endif
  71.