can_interface.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef __CAN_INTERFACE_H
  2. #define __CAN_INTERFACE_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #ifdef __CAN_INTERFACE_H_GLOBAL
  7. #define __CAN_INTERFACE_H_EXTERN
  8. #else
  9. #define __CAN_INTERFACE_H_EXTERN extern
  10. #endif
  11. /************************************************************************************************
  12. * Version *
  13. ************************************************************************************************/
  14. /************************************************************************************************
  15. * How to use *
  16. ************************************************************************************************/
  17. /************************************************************************************************
  18. * Enable config *
  19. ************************************************************************************************/
  20. /************************************************************************************************
  21. * Includes *
  22. ************************************************************************************************/
  23. #include <can.h>
  24. /************************************************************************************************
  25. * Defines *
  26. ************************************************************************************************/
  27. #define CAN_IER hcan.Instance->IER
  28. #define CAN_IT_TME_ENABLE() HAL_CAN_ActivateNotification(&hcan, CAN_IT_TX_MAILBOX_EMPTY)
  29. #define CAN_IT_TME_DISABLE() HAL_CAN_DeactivateNotification(&hcan, CAN_IT_TX_MAILBOX_EMPTY)
  30. /************************************************************************************************
  31. * Typedefs *
  32. ************************************************************************************************/
  33. typedef struct
  34. {
  35. struct
  36. {
  37. uint8_t ide;
  38. uint8_t rtr;
  39. uint8_t dlc;
  40. } reg;
  41. union
  42. {
  43. uint32_t r;
  44. struct
  45. {
  46. uint8_t sa : 8;
  47. uint8_t ps : 8;
  48. uint8_t pf : 8;
  49. uint8_t dp : 1;
  50. uint8_t r : 1;
  51. uint8_t p : 3;
  52. } b;
  53. } id;
  54. union
  55. {
  56. uint8_t u8_buf[8];
  57. uint16_t u16_buf[4];
  58. uint32_t u32_buf[2];
  59. uint64_t u64_buf;
  60. } data;
  61. } pdu_tag, *p_pdu_tag;
  62. typedef void (*pcan_tx)(void);
  63. typedef void (*pcan_rx)(CAN_RxHeaderTypeDef, uint8_t *);
  64. /************************************************************************************************
  65. * Interfaces *
  66. ************************************************************************************************/
  67. uint8_t can_write(uint32_t id, uint8_t id_type, uint8_t *p_data, uint8_t len);
  68. void can_rx_back_init(pcan_rx p_fun);
  69. void can_tx_back_init(pcan_tx p_fun);
  70. #ifdef __cplusplus
  71. };
  72. #endif
  73. #endif // __CAN_INTERFACE_H