queue.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef __QUEUE_H
  2. #define __QUEUE_H
  3. #include "stdio.h"
  4. #define MAX_QSIZE (60u) /* 最大队列长度 */
  5. typedef unsigned long long u64;
  6. typedef struct
  7. {
  8. struct
  9. {
  10. uint8_t ide;
  11. uint8_t rtr;
  12. uint8_t dlc;
  13. } reg;
  14. union
  15. {
  16. uint32_t r;
  17. struct
  18. {
  19. uint8_t sa : 8;
  20. uint8_t ps : 8;
  21. uint8_t pf : 8;
  22. uint8_t dp : 1;
  23. uint8_t r : 1;
  24. uint8_t p : 3;
  25. } b;
  26. } id;
  27. union
  28. {
  29. uint8_t u8_buf[8];
  30. uint16_t u16_buf[4];
  31. uint32_t u32_buf[2];
  32. u64 u64_buf;
  33. } data;
  34. } pdu_tag, *p_pdu_tag;
  35. typedef struct
  36. {
  37. uint8_t buf[8];
  38. uint32_t can_id;
  39. } CanData_TypeDef;
  40. typedef struct
  41. {
  42. uint16_t head;
  43. uint16_t tail;
  44. uint16_t count;
  45. pdu_tag can_message[MAX_QSIZE];
  46. } can_queue_tag, *p_can_queue_tag;
  47. typedef enum
  48. {
  49. Q_OK,
  50. Q_ERR,
  51. Q_FULL,
  52. Q_EMPTY,
  53. } QUEUE_STATUS;
  54. extern can_queue_tag can_tx_queue;
  55. extern can_queue_tag can_rx_queue;
  56. void queue_init(p_can_queue_tag); // 初始化队列
  57. uint8_t queue_empty(p_can_queue_tag); // 查询队列是否为空
  58. uint8_t queue_full(p_can_queue_tag);
  59. uint8_t get_head(can_queue_tag *p_queue, pdu_tag *data); // 获取对头数据
  60. QUEUE_STATUS en_queue(p_can_queue_tag, pdu_tag); // 队列插入数据
  61. QUEUE_STATUS de_queue(p_can_queue_tag, p_pdu_tag);
  62. #endif