From 1d81a3b02cd8ec6b88e12fef1bf8b79a402d639a Mon Sep 17 00:00:00 2001 From: chenyf <1343619937@qq.com> Date: Sat, 7 Dec 2024 21:06:04 +0800 Subject: [PATCH] fix:null --- erpc_core.c | 52 +++++++++++++++++++++++++++++++++++++++++++++- erpc_core.h | 7 +++++++ erpc_net.c | 3 +++ erpc_net.h | 3 +++ port_uart_master.c | 0 5 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 erpc_net.c create mode 100644 erpc_net.h create mode 100644 port_uart_master.c diff --git a/erpc_core.c b/erpc_core.c index b2e0a95..05fb2ee 100644 --- a/erpc_core.c +++ b/erpc_core.c @@ -205,6 +205,56 @@ u32 erpc_send_base(erpc_hw_cfg_t *hw_cfg, u8 dest_id, u16 port, u8 package_type, hw_cfg->send_cache[cache_ord].state = ERPC_CMD_NO_ERROR; return ret; } +u32 erpc_boardcast(u16 port, u8 *data, u16 len) +{ + list_t *list = &erpc_hw; + if (list->data == NULL) + { + return ERPC_ERR_NOFOND_HW; + } + while (list != NULL) + { + erpc_hw_cfg_t *hw_cfg = (erpc_hw_cfg_t *)list->data; + u8 cache_ord = 255; + // 查找可用的发送缓存 + for (int i = 0; i < MAX_SEND_CMD_CACHE_NUM; i++) + { + if (hw_cfg->send_cache[i].state == ERPC_CMD_NO_ERROR) + { + // ERPC_DEBUG("find send cache %d\n", i); + cache_ord = i; + break; + } + } + if (cache_ord == 255) + { + continue; + } + // 准备数据 + hw_cfg->send_cache[cache_ord].state = ERPC_CMD_DATA_DEAL; + erpc_cmd_def_t *cmd = + (erpc_cmd_def_t *)&hw_cfg->send_cache[cache_ord].data[0]; + cmd->head.dest_id = ERPC_BOARDCAST_ID; + cmd->head.port = port; + cmd->head.src_id = hw_cfg->local_id; + cmd->head.msg_len = len; + if (data == NULL) + { + cmd->head.msg_len = 0; + } + if (len > 0 && data != NULL) + { + for (int i = 0; i < len; i++) + { + cmd->data[i] = data[i]; + } + } + // 计算校验和 + cmd_cal_crc16(cmd); + hw_cfg->send_cache[cache_ord].state = ERPC_CMD_WAIT_SEND; + } +} + u32 erpc_send(u8 hw, u8 dest_id, u16 port, u8 *data, u16 len) { erpc_hw_cfg_t *hw_cfg = erpc_hw_get(hw); @@ -561,4 +611,4 @@ void erpc_rev_deal_core() { erpc_sleep_tick(1); } -} \ No newline at end of file +} diff --git a/erpc_core.h b/erpc_core.h index a8560b1..0f19aaf 100644 --- a/erpc_core.h +++ b/erpc_core.h @@ -135,4 +135,11 @@ u32 erpc_send_wait_reply(u8 hw, u8 dest_id, u16 port, u8 *data, u16 len, * 回复消息 */ u32 erpc_replay(u8 hw, u8 dest_id, u16 port, u8 *data_out, u16 len); + +/** + * 广播消息 + */ +u32 erpc_boardcast(u16 port, u8 *data, u16 len); + + #endif /* ERPC_CORE_H_ */ \ No newline at end of file diff --git a/erpc_net.c b/erpc_net.c new file mode 100644 index 0000000..3c9b91f --- /dev/null +++ b/erpc_net.c @@ -0,0 +1,3 @@ +#include "erpc_net.h" +#include "erpc_core.h" + diff --git a/erpc_net.h b/erpc_net.h new file mode 100644 index 0000000..3d38351 --- /dev/null +++ b/erpc_net.h @@ -0,0 +1,3 @@ +#include "erpc_core.h" + +u32 erpc_find_all(); \ No newline at end of file diff --git a/port_uart_master.c b/port_uart_master.c new file mode 100644 index 0000000..e69de29