can_message.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #ifndef _CAN_MESSAGE_H__
  2. #define _CAN_MESSAGE_H__
  3. #include <stdint.h>
  4. #include "bsp/can.h"
  5. #include "libs/node_list.h"
  6. #define can_payload_offset 2
  7. typedef struct {
  8. uint16_t key;
  9. uint8_t dest;
  10. uint8_t src;
  11. uint8_t *data;
  12. uint16_t len;
  13. uint8_t idx;
  14. uint8_t total_frame;
  15. uint8_t type;
  16. }can_message_t;
  17. #define CAN_MESSAGE_MAX_FRAMES 32
  18. #define CAN_SEND_SUCCESS 0
  19. #define CAN_SEND_TIMEOUT -1
  20. #define CAN_SEND_ERROR -2
  21. #define CAN_SEND_ACK_FAILT -3
  22. #define CAN_SEND_NO_WAIT_QUEUE -4
  23. void can_message_init(void);
  24. s32 can_send_message(uint32_t can_id, u8 *data, int len, s32 timeout);
  25. static __inline__ uint32 get_can_id(u8 dest, u8 src, u8 type, u8 retry){
  26. can_id_t id;
  27. id.id = 0;
  28. id.dest = dest;
  29. id.src = src;
  30. id.type = type;
  31. id.retry = retry;
  32. return id.id;
  33. }
  34. static __inline__ uint32 get_request_can_id(u8 dest, u8 retry){
  35. return get_can_id(dest,CAN_MY_ADDRESS, ptype_request, retry);
  36. }
  37. static __inline__ uint32 get_indicator_can_id(u8 dest){
  38. return get_can_id(dest,CAN_MY_ADDRESS, ptype_indicater, 1);
  39. }
  40. static __inline__ uint32 get_reponse_can_id(u8 dest){
  41. return get_can_id(dest,CAN_MY_ADDRESS, ptype_response, 1);
  42. }
  43. //EXPORT FUNCTIONS
  44. extern void can_send_message_ack(can_message_t *msg, uint8_t success);
  45. extern void can_send_ack(uint8_t can_addr, uint16_t key, uint8_t data);
  46. extern void can_send_response(uint8_t can_add, uint8_t *data, int len);
  47. extern void can_send_indicator(uint8_t can_add, uint8_t *data, int len);
  48. extern void can_send_request(uint8_t can_add, uint8_t *data, int len);
  49. #endif /* _CAN_MESSAGE_H__ */