2024-11-20 15:03:26 +00:00
|
|
|
|
|
|
|
// #ifndef WINDOWS
|
|
|
|
// #error "This file is for Windows only"
|
|
|
|
// #endif
|
|
|
|
|
|
|
|
#include "erpc_core.h"
|
|
|
|
#include "windows.h"
|
|
|
|
#include <stdio.h>
|
2024-11-21 13:22:33 +00:00
|
|
|
u32 hellworld(u8 hw, u8 src_id, u8 dest_id, u16 port, u8 *data, u16 len)
|
2024-11-20 15:03:26 +00:00
|
|
|
{
|
2024-11-21 13:22:33 +00:00
|
|
|
ERPC_DEBUG("Hello World:\n");
|
|
|
|
ERPC_DEBUG("len = %d, msg :%s\n", len, data);
|
|
|
|
// 防止编译警告
|
|
|
|
UNUSED(hw);
|
|
|
|
UNUSED(src_id);
|
|
|
|
UNUSED(dest_id);
|
|
|
|
UNUSED(port);
|
|
|
|
UNUSED(data);
|
|
|
|
UNUSED(len);
|
|
|
|
return 0;
|
2024-11-20 15:03:26 +00:00
|
|
|
}
|
2024-11-21 13:22:33 +00:00
|
|
|
u32 hello_cat(u8 hw, u8 src_id, u8 dest_id, u16 port, u8 *data, u16 len)
|
2024-11-20 15:03:26 +00:00
|
|
|
{
|
2024-11-21 13:22:33 +00:00
|
|
|
ERPC_DEBUG("Hello Cat!\n");
|
|
|
|
// 防止编译警告
|
|
|
|
UNUSED(hw);
|
|
|
|
UNUSED(src_id);
|
|
|
|
UNUSED(dest_id);
|
|
|
|
UNUSED(port);
|
|
|
|
UNUSED(data);
|
|
|
|
UNUSED(len);
|
|
|
|
return 0;
|
2024-11-20 15:03:26 +00:00
|
|
|
}
|
2024-11-21 08:59:31 +00:00
|
|
|
|
2024-11-21 13:22:33 +00:00
|
|
|
u32 hello_dog(u8 hw, u8 src_id, u8 dest_id, u16 port, u8 *data, u16 len)
|
2024-11-21 08:59:31 +00:00
|
|
|
{
|
2024-11-21 13:22:33 +00:00
|
|
|
ERPC_DEBUG("Hello Dog!\n");
|
|
|
|
// 防止编译警告
|
2024-11-21 08:59:31 +00:00
|
|
|
u8 data_out[10] = "12345";
|
2024-11-21 13:22:33 +00:00
|
|
|
u32 ret = erpc_replay(hw, dest_id, port, data_out, sizeof(data_out));
|
|
|
|
ERPC_DEBUG("erpc_replay ret:%d\n", ret);
|
|
|
|
// 防止编译警告
|
|
|
|
UNUSED(ret);
|
|
|
|
UNUSED(hw);
|
|
|
|
UNUSED(src_id);
|
|
|
|
UNUSED(dest_id);
|
|
|
|
UNUSED(port);
|
|
|
|
UNUSED(data);
|
|
|
|
UNUSED(len);
|
|
|
|
return 0;
|
2024-11-21 08:59:31 +00:00
|
|
|
}
|
2024-11-20 15:03:26 +00:00
|
|
|
erpc_cmd_list_t erpc_cmd_list[] = {
|
|
|
|
{.cmd = 0x01, hellworld},
|
|
|
|
{.cmd = 0x02, hello_cat},
|
2024-11-21 08:59:31 +00:00
|
|
|
{.cmd = 0x03, hello_dog},
|
2024-11-20 15:03:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
HANDLE deal_lock;
|
|
|
|
HANDLE send_lock;
|
|
|
|
|
|
|
|
static void deal_lock_h()
|
|
|
|
{
|
|
|
|
WaitForSingleObject(deal_lock, INFINITE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void deal_unlock_h()
|
|
|
|
{
|
|
|
|
ReleaseMutex(deal_lock);
|
|
|
|
}
|
|
|
|
static void send_lock_h()
|
|
|
|
{
|
|
|
|
WaitForSingleObject(send_lock, INFINITE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void send_unlock_h()
|
|
|
|
{
|
|
|
|
ReleaseMutex(send_lock);
|
|
|
|
}
|
|
|
|
u8 data[300];
|
2024-11-21 13:22:33 +00:00
|
|
|
static u8 data_write(u8 *data, u16 len)
|
2024-11-20 15:03:26 +00:00
|
|
|
{
|
|
|
|
erpc_set_rev_cahce(0, data, len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
erpc_hw_cfg_t self_hw_cfg = {
|
|
|
|
.ord = 0,
|
|
|
|
.deal_lock = deal_lock_h,
|
|
|
|
.deal_unlock = deal_unlock_h,
|
|
|
|
.send_lock = send_lock_h,
|
|
|
|
.send_unlock = send_unlock_h,
|
|
|
|
.local_id = 0x01,
|
|
|
|
.write = data_write,
|
|
|
|
};
|
|
|
|
void erpc_cmd_config()
|
|
|
|
{
|
2024-11-21 13:22:33 +00:00
|
|
|
for (int i = 0; i < (int)sizeof(erpc_cmd_list) / (int)sizeof(erpc_cmd_list[0]); i++)
|
2024-11-20 15:03:26 +00:00
|
|
|
{
|
|
|
|
erpc_add_cmd_list(&self_hw_cfg, &erpc_cmd_list[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void sys_sleep(u32 ms)
|
|
|
|
{
|
|
|
|
Sleep(ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WINAPI send_task(LPVOID lpParam)
|
|
|
|
{
|
2024-11-21 13:22:33 +00:00
|
|
|
UNUSED(lpParam);
|
2024-11-20 15:03:26 +00:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
erpc_send_deal_core();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DWORD WINAPI rev_task(LPVOID lpParam)
|
|
|
|
{
|
2024-11-21 13:22:33 +00:00
|
|
|
UNUSED(lpParam);
|
2024-11-20 15:03:26 +00:00
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2024-11-21 13:22:33 +00:00
|
|
|
// ERPC_DEBUG("rev_task\n");
|
2024-11-20 16:12:48 +00:00
|
|
|
erpc_rev_package_core();
|
2024-11-20 15:03:26 +00:00
|
|
|
erpc_rev_deal_core();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WINAPI test_task(LPVOID lpParam)
|
|
|
|
{
|
2024-11-21 13:22:33 +00:00
|
|
|
UNUSED(lpParam);
|
|
|
|
ERPC_DEBUG("test_task\n");
|
2024-11-20 15:03:26 +00:00
|
|
|
while (1)
|
|
|
|
{
|
2024-11-21 13:22:33 +00:00
|
|
|
// ERPC_DEBUG("[test_task]send\n");
|
|
|
|
char msg[] = "miao miao miao\n";
|
|
|
|
u32 ret = erpc_send(self_hw_cfg.ord, self_hw_cfg.local_id, 0x01, (u8 *)msg, sizeof(msg));
|
|
|
|
ERPC_DEBUG("[test_task]send ret:%d\n", ret);
|
2024-11-20 16:26:15 +00:00
|
|
|
ret = erpc_send(self_hw_cfg.ord, self_hw_cfg.local_id, 0x02, NULL, 0);
|
2024-11-21 13:22:33 +00:00
|
|
|
ERPC_DEBUG("[test_task]send ret:%d\n", ret);
|
2024-11-21 08:59:31 +00:00
|
|
|
ret = erpc_send_wait_reply(self_hw_cfg.ord, self_hw_cfg.local_id, 0x03, NULL, 0, data, NULL, 1000);
|
2024-11-21 13:22:33 +00:00
|
|
|
ERPC_DEBUG("[test_task]send ret:%d\n", ret);
|
|
|
|
UNUSED(ret);
|
2024-11-20 15:03:26 +00:00
|
|
|
sys_sleep(1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2024-11-21 13:22:33 +00:00
|
|
|
UNUSED(argc);
|
|
|
|
UNUSED(argv);
|
2024-11-20 15:03:26 +00:00
|
|
|
u32 ret = 0;
|
2024-11-21 13:22:33 +00:00
|
|
|
ERPC_DEBUG("erpc_port_self start\n");
|
2024-11-20 15:03:26 +00:00
|
|
|
ret = erpc_hw_add(&self_hw_cfg);
|
2024-11-21 13:22:33 +00:00
|
|
|
ERPC_DEBUG("erpc_hw_add ret:%d\n", ret);
|
2024-11-20 15:03:26 +00:00
|
|
|
CHECK_IF_ERROR(ret, 0);
|
|
|
|
erpc_cmd_config();
|
2024-11-21 13:22:33 +00:00
|
|
|
ERPC_DEBUG("erpc_cmd_config ret:%d\n", ret);
|
2024-11-20 15:03:26 +00:00
|
|
|
erpc_sleep_tick = sys_sleep;
|
|
|
|
|
|
|
|
HANDLE threadHandle[3];
|
|
|
|
deal_lock = CreateMutex(NULL, FALSE, NULL);
|
|
|
|
if (deal_lock == NULL)
|
|
|
|
{
|
2024-11-21 13:22:33 +00:00
|
|
|
ERPC_DEBUG("创建互斥锁失败\n");
|
2024-11-20 15:03:26 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
send_lock = CreateMutex(NULL, FALSE, NULL);
|
|
|
|
if (send_lock == NULL)
|
|
|
|
{
|
2024-11-21 13:22:33 +00:00
|
|
|
ERPC_DEBUG("创建互斥锁失败\n");
|
2024-11-20 15:03:26 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
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[2] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)test_task, NULL, 0, NULL);
|
|
|
|
|
|
|
|
WaitForSingleObject(threadHandle[0], INFINITE);
|
|
|
|
WaitForSingleObject(threadHandle[1], INFINITE);
|
|
|
|
WaitForSingleObject(threadHandle[2], INFINITE);
|
|
|
|
CloseHandle(threadHandle[0]);
|
|
|
|
CloseHandle(threadHandle[1]);
|
2024-11-20 16:12:48 +00:00
|
|
|
CloseHandle(threadHandle[2]);
|
2024-11-20 15:03:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|