| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #ifndef _MAIL_BOX_H
- #define _MAIL_BOX_H
- #ifdef __cplusplus
- extern "C" {
- #endif
- #define MAILBOX_DR_SUM 7 //每个邮箱的数据寄存器数量。硬件决定,勿改。
- #define MAILBOX_SUM 16 //邮箱总数。硬件决定,勿改。
- #define MAILBOX_MCU_CORE_NUM (0) // MCU 编号=0。硬件决定,勿改。
- #define MAILBOX_CPU_CORE_NUM (1) // CPU 编号=1。硬件决定,勿改。
- #define MAILBOX_MCU_CORE_ID ((1 << MAILBOX_MCU_CORE_NUM))
- #define MAILBOX_CPU_CORE_ID ((1 << MAILBOX_CPU_CORE_NUM))
- #define MAILBOX_MY_CORE_NUM (MAILBOX_CPU_CORE_NUM)
- #define MAILBOX_MY_CORE_ID (MAILBOX_CPU_CORE_ID)
- #define TX_MAILBOX_NUM 8 //MCU、CPU各8个
- #define TX_MAILBOX_START_ID 8 //邮箱分配:MCU:0~7,CPU:8~15
- #define TX_MAILBOX_MAX_ID (TX_MAILBOX_START_ID + TX_MAILBOX_NUM)
- #define RX_MAILBOX_NUM 8 //MCU、CPU各8个
- #define RX_MAILBOX_START_ID 0 //邮箱分配:MCU:8~15,CPU:0~7
- #define RX_MAILBOX_MAX_ID (RX_MAILBOX_START_ID + RX_MAILBOX_NUM)
- typedef struct {
- volatile uint32_t SRC;
- volatile uint32_t DEST;
- volatile uint32_t DCLR;
- volatile uint32_t DSTA;
- volatile uint32_t MODE;
- volatile uint32_t MSET;
- volatile uint32_t MCLR;
- volatile uint32_t MSTA;
- volatile uint32_t SEND;
- volatile uint32_t DR[MAILBOX_DR_SUM];
- }mailbox_t;
- typedef enum{
- mail_s_done = 0,
- mail_s_occ, // 邮箱被占用
- mail_s_mb_num_err, // 邮箱号错误
- mail_s_link_discontinuous, // 连接的邮箱不连续
- mail_s_tx_tout, // 发送超时
- }mail_status;
- typedef struct {
- uint32_t sender; // 源核只能一个
- uint32_t recipients; // 目标核可多个
- uint32_t data[MAILBOX_DR_SUM];
- uint8_t auto_acknowledge; // 自动确认(接收方仅返回确信号,不修改邮件内容,多个目标核必须开启自动确认)
- uint8_t auto_link; /* 1: 表示此邮箱将连接到 mailbox_id + 1。自动连接:
- 邮箱按顺序一个接一个发送数据,全部发送完成后,
- 且目标返回确认中断,则产生中断。
- */
- uint8_t mailbox_id; // 邮箱号
- mail_status tx_status; // 邮件发送状态(该字段仅在发送邮件时有效)
- TickType_t tx_tout_tick; // 发送超时时间
- }mail_t;
- typedef struct {
- uint32_t data[MAILBOX_DR_SUM];
- }reply_t;
- typedef reply_t (*mb_rx_cb_func_t)(mail_t mail, void *param);
- void mailbox_reset(void);
- int mailbox_init(void);
- int mailbox_request(int id);
- int mailbox_release(int id);
- int mailbox_register_rx_cb(int id, mb_rx_cb_func_t cb, void *param);
- int mailbox_send_mail(mail_t *mail, uint32_t mail_num);
- #ifdef __cplusplus
- }
- #endif
- #endif /* _MAIL_BOX_H */
|