mailbox.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef _MAIL_BOX_H
  2. #define _MAIL_BOX_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #define MAILBOX_DR_SUM 7 //每个邮箱的数据寄存器数量。硬件决定,勿改。
  7. #define MAILBOX_SUM 16 //邮箱总数。硬件决定,勿改。
  8. #define MAILBOX_MCU_CORE_NUM (0) // MCU 编号=0。硬件决定,勿改。
  9. #define MAILBOX_CPU_CORE_NUM (1) // CPU 编号=1。硬件决定,勿改。
  10. #define MAILBOX_MCU_CORE_ID ((1 << MAILBOX_MCU_CORE_NUM))
  11. #define MAILBOX_CPU_CORE_ID ((1 << MAILBOX_CPU_CORE_NUM))
  12. #define MAILBOX_MY_CORE_NUM (MAILBOX_CPU_CORE_NUM)
  13. #define MAILBOX_MY_CORE_ID (MAILBOX_CPU_CORE_ID)
  14. #define TX_MAILBOX_NUM 8 //MCU、CPU各8个
  15. #define TX_MAILBOX_START_ID 8 //邮箱分配:MCU:0~7,CPU:8~15
  16. #define TX_MAILBOX_MAX_ID (TX_MAILBOX_START_ID + TX_MAILBOX_NUM)
  17. #define RX_MAILBOX_NUM 8 //MCU、CPU各8个
  18. #define RX_MAILBOX_START_ID 0 //邮箱分配:MCU:8~15,CPU:0~7
  19. #define RX_MAILBOX_MAX_ID (RX_MAILBOX_START_ID + RX_MAILBOX_NUM)
  20. typedef struct {
  21. volatile uint32_t SRC;
  22. volatile uint32_t DEST;
  23. volatile uint32_t DCLR;
  24. volatile uint32_t DSTA;
  25. volatile uint32_t MODE;
  26. volatile uint32_t MSET;
  27. volatile uint32_t MCLR;
  28. volatile uint32_t MSTA;
  29. volatile uint32_t SEND;
  30. volatile uint32_t DR[MAILBOX_DR_SUM];
  31. }mailbox_t;
  32. typedef enum{
  33. mail_s_done = 0,
  34. mail_s_occ, // 邮箱被占用
  35. mail_s_mb_num_err, // 邮箱号错误
  36. mail_s_link_discontinuous, // 连接的邮箱不连续
  37. mail_s_tx_tout, // 发送超时
  38. }mail_status;
  39. typedef struct {
  40. uint32_t sender; // 源核只能一个
  41. uint32_t recipients; // 目标核可多个
  42. uint32_t data[MAILBOX_DR_SUM];
  43. uint8_t auto_acknowledge; // 自动确认(接收方仅返回确信号,不修改邮件内容,多个目标核必须开启自动确认)
  44. uint8_t auto_link; /* 1: 表示此邮箱将连接到 mailbox_id + 1。自动连接:
  45. 邮箱按顺序一个接一个发送数据,全部发送完成后,
  46. 且目标返回确认中断,则产生中断。
  47. */
  48. uint8_t mailbox_id; // 邮箱号
  49. mail_status tx_status; // 邮件发送状态(该字段仅在发送邮件时有效)
  50. TickType_t tx_tout_tick; // 发送超时时间
  51. }mail_t;
  52. typedef struct {
  53. uint32_t data[MAILBOX_DR_SUM];
  54. }reply_t;
  55. typedef reply_t (*mb_rx_cb_func_t)(mail_t mail, void *param);
  56. void mailbox_reset(void);
  57. int mailbox_init(void);
  58. int mailbox_request(int id);
  59. int mailbox_release(int id);
  60. int mailbox_register_rx_cb(int id, mb_rx_cb_func_t cb, void *param);
  61. int mailbox_send_mail(mail_t *mail, uint32_t mail_num);
  62. #ifdef __cplusplus
  63. }
  64. #endif
  65. #endif /* _MAIL_BOX_H */