fix(simple cmd) 完成简单通讯

This commit is contained in:
chenyf 2024-11-21 00:26:15 +08:00
parent 8357f41a75
commit 70fb05c650
5 changed files with 64 additions and 53 deletions

View File

@ -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;

Binary file not shown.

View File

@ -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);
}

Binary file not shown.

Binary file not shown.