diff --git a/erpc_core.c b/erpc_core.c index 570de48..2bd711c 100644 --- a/erpc_core.c +++ b/erpc_core.c @@ -173,25 +173,26 @@ u32 erpc_send(u8 hw, u8 dest_id, u16 port, u8 *data, u16 len) u32 ret = ERPC_NO_ERROR; do { - if(wait_time == 0){ - ret = ERPC_ERR_SEND_TIMEOUT; - break; - } - if(hw_cfg->send_cache[cache_ord].state == ERPC_CMD_SEND_ONCE){ - ret = ERPC_ERR_DEST_NO_RESPONSE; - break; - } - if(hw_cfg->send_cache[cache_ord].state == ERPC_CMD_SEND_REPEAT){ - ret = ERPC_ERR_DEST_NO_RESPONSE; - break; - } + if (wait_time == 0) + { + ret = ERPC_ERR_SEND_TIMEOUT; + break; + } + if (hw_cfg->send_cache[cache_ord].state == ERPC_CMD_SEND_ONCE) + { + ret = ERPC_ERR_DEST_NO_RESPONSE; + break; + } + if (hw_cfg->send_cache[cache_ord].state == ERPC_CMD_SEND_REPEAT) + { + ret = ERPC_ERR_DEST_NO_RESPONSE; + break; + } } while (0); hw_cfg->send_cache[cache_ord].state = ERPC_CMD_NO_ERROR; return ret; } - - u32 erpc_send_data(erpc_hw_cfg_t *hw) { for (int i = 0; i < MAX_SEND_CMD_CACHE_NUM; i++) @@ -367,49 +368,58 @@ void erpc_rev_deal_core() while (list != NULL) { erpc_hw_cfg_t *hw = (erpc_hw_cfg_t *)list->data; - - for (int j = 0; j < MAX_REC_CMD_CACHE_NUM; j++) - { - // 发现等待处理的数据包 - if (hw->rec_cache[j].state == ERPC_CMD_WAIT_TASK_DEAL) + { // 遍历接收缓存 + for (int j = 0; j < MAX_REC_CMD_CACHE_NUM; j++) { - // 多线程处理 - hw->deal_lock(); - if (hw->rec_cache[j].state == ERPC_CMD_WAIT_TASK_DEAL) - { - // 获取指令的处理权限 - hw->rec_cache[j].state = ERPC_CMD_WAIT_TASK_DEAL_FINISH; - } - else - { - // 已经有线程抢先执行了 - hw->deal_unlock(); - continue; - } - hw->deal_unlock(); - // 搜索指令列表 - list_t *cmd_list = &hw->cmd_list; - // 链表是空的 - if (cmd_list->data == NULL) - { - continue; - } - while (cmd_list != NULL) - { - erpc_cmd_list_t *cmd_obj = (erpc_cmd_list_t *)cmd_list->data; - erpc_cmd_def_t *cmd_def = (erpc_cmd_def_t *)hw->rec_cache[j].data; - if (cmd_obj->cmd == cmd_def->head.port) + { // 发现等待处理的数据包 + if (hw->rec_cache[j].state != ERPC_CMD_WAIT_TASK_DEAL) { - if (cmd_obj->handle != NULL) - { - // 指令调用 - cmd_obj->handle(hw->ord, cmd_def->head.src_id, cmd_def->head.dest_id, cmd_def->head.port, cmd_def->data, cmd_def->head.msg_len); - } - // 处理完成 丢弃缓存 - hw->rec_cache[j].state = ERPC_CMD_NO_ERROR; + continue; } - cmd_list = cmd_list->next; } + { // 多线程下,抢占处理权限 + hw->deal_lock(); + if (hw->rec_cache[j].state == ERPC_CMD_WAIT_TASK_DEAL) + { + // 获取指令的处理权限 + hw->rec_cache[j].state = ERPC_CMD_WAIT_TASK_DEAL_FINISH; + } + else + { + // 已经有线程抢先执行了 + hw->deal_unlock(); + continue; + } + hw->deal_unlock(); + } + { // 处理指令 + // 搜索指令列表 + list_t *cmd_list = &hw->cmd_list; + // 链表是空的 + if (cmd_list->data == NULL) + { + continue; + } + // 获取指令指针 + erpc_cmd_def_t *cmd_def = (erpc_cmd_def_t *)hw->rec_cache[j].data; + while (cmd_list != NULL) + { // 搜索指令列表 + erpc_cmd_list_t *cmd_obj = (erpc_cmd_list_t *)cmd_list->data; + if (cmd_obj->cmd == cmd_def->head.port) + { + if (cmd_obj->handle != NULL) + { + // 指令调用 + cmd_obj->handle(hw->ord, cmd_def->head.src_id, cmd_def->head.dest_id, cmd_def->head.port, cmd_def->data, cmd_def->head.msg_len); + } + + break; + } + cmd_list = cmd_list->next; + } + } + // 处理完成 丢弃缓存 , 无论是否执行指令,都需要把数据包丢弃 + hw->rec_cache[j].state = ERPC_CMD_NO_ERROR; } } list = list->next; diff --git a/erpc_core.o b/erpc_core.o index d9d50ac..f4ec436 100644 Binary files a/erpc_core.o and b/erpc_core.o differ diff --git a/port_self.c b/port_self.c index 7ccedb9..36f6f70 100644 --- a/port_self.c +++ b/port_self.c @@ -93,6 +93,7 @@ DWORD WINAPI test_task(LPVOID lpParam) { // printf("[test_task]send\n"); u32 ret = erpc_send(self_hw_cfg.ord, self_hw_cfg.local_id, 0x01, NULL, 0); + ret = erpc_send(self_hw_cfg.ord, self_hw_cfg.local_id, 0x02, NULL, 0); printf("[test_task]send ret:%d\n", ret); sys_sleep(1000); } diff --git a/port_self.exe b/port_self.exe index 0ea715d..364981f 100644 Binary files a/port_self.exe and b/port_self.exe differ diff --git a/port_self.o b/port_self.o index ed6933e..bd191e2 100644 Binary files a/port_self.o and b/port_self.o differ