fix(port_self): 增加一个线程,防止卡住

This commit is contained in:
chenyf 2024-11-24 20:43:16 +08:00
parent 45aa9278fe
commit 03ea55fdc9
5 changed files with 17 additions and 3 deletions

Binary file not shown.

Binary file not shown.

View File

@ -187,6 +187,7 @@ u32 erpc_send_base(erpc_hw_cfg_t *hw_cfg, u8 dest_id, u16 port, u8 package_type,
{ {
if (wait_time == 0) if (wait_time == 0)
{ {
printf("send timeout,state:%d\n", hw_cfg->send_cache[cache_ord].state);
ret = ERPC_ERR_SEND_TIMEOUT; ret = ERPC_ERR_SEND_TIMEOUT;
break; break;
} }

View File

@ -32,6 +32,8 @@ u32 hello_cat(u8 hw, u8 src_id, u8 dest_id, u16 port, u8 *data, u16 len)
return 0; return 0;
} }
u32 hello_dog(u8 hw, u8 src_id, u8 dest_id, u16 port, u8 *data, u16 len) u32 hello_dog(u8 hw, u8 src_id, u8 dest_id, u16 port, u8 *data, u16 len)
{ {
ERPC_DEBUG("Hello Dog!\n"); ERPC_DEBUG("Hello Dog!\n");
@ -136,8 +138,16 @@ DWORD WINAPI test_task(LPVOID lpParam)
ERPC_DEBUG("[test_task]send ret:%d\n", ret); ERPC_DEBUG("[test_task]send ret:%d\n", ret);
ret = erpc_send(self_hw_cfg.ord, self_hw_cfg.local_id, 0x02, NULL, 0); ret = erpc_send(self_hw_cfg.ord, self_hw_cfg.local_id, 0x02, NULL, 0);
ERPC_DEBUG("[test_task]send ret:%d\n", ret); ERPC_DEBUG("[test_task]send ret:%d\n", ret);
ret = erpc_send_wait_reply(self_hw_cfg.ord, self_hw_cfg.local_id, 0x03, NULL, 0, data, NULL, 1000); u16 reply_len = 30;
u8 data[reply_len];
ret = erpc_send_wait_reply(self_hw_cfg.ord, self_hw_cfg.local_id, 0x03, NULL, 0, data, &reply_len, 1000);
ERPC_DEBUG("[test_task]send ret:%d\n", ret); ERPC_DEBUG("[test_task]send ret:%d\n", ret);
for (int i = 0; i < reply_len; i++)
{
ERPC_DEBUG("%c", data[i]);
}
ERPC_DEBUG("\n");
UNUSED(ret); UNUSED(ret);
sys_sleep(1000); sys_sleep(1000);
} }
@ -156,7 +166,7 @@ int main(int argc, char *argv[])
ERPC_DEBUG("erpc_cmd_config ret:%d\n", ret); ERPC_DEBUG("erpc_cmd_config ret:%d\n", ret);
erpc_sleep_tick = sys_sleep; erpc_sleep_tick = sys_sleep;
HANDLE threadHandle[3]; HANDLE threadHandle[4];
deal_lock = CreateMutex(NULL, FALSE, NULL); deal_lock = CreateMutex(NULL, FALSE, NULL);
if (deal_lock == NULL) if (deal_lock == NULL)
{ {
@ -171,13 +181,16 @@ int main(int argc, char *argv[])
} }
threadHandle[0] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)send_task, NULL, 0, NULL); threadHandle[0] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)send_task, NULL, 0, NULL);
threadHandle[1] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)rev_task, NULL, 0, NULL); threadHandle[1] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)rev_task, NULL, 0, NULL);
threadHandle[2] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)test_task, NULL, 0, NULL); threadHandle[3] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)rev_task, NULL, 0, NULL);
threadHandle[4] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)test_task, NULL, 0, NULL);
WaitForSingleObject(threadHandle[0], INFINITE); WaitForSingleObject(threadHandle[0], INFINITE);
WaitForSingleObject(threadHandle[1], INFINITE); WaitForSingleObject(threadHandle[1], INFINITE);
WaitForSingleObject(threadHandle[2], INFINITE); WaitForSingleObject(threadHandle[2], INFINITE);
WaitForSingleObject(threadHandle[3], INFINITE);
CloseHandle(threadHandle[0]); CloseHandle(threadHandle[0]);
CloseHandle(threadHandle[1]); CloseHandle(threadHandle[1]);
CloseHandle(threadHandle[2]); CloseHandle(threadHandle[2]);
CloseHandle(threadHandle[3]);
return 0; return 0;
} }

Binary file not shown.