183 lines
4.3 KiB
C
183 lines
4.3 KiB
C
|
|
// #ifndef WINDOWS
|
|
// #error "This file is for Windows only"
|
|
// #endif
|
|
|
|
#include "erpc_core.h"
|
|
#include "windows.h"
|
|
#include <stdio.h>
|
|
u32 hellworld(u8 hw, u8 src_id, u8 dest_id, u16 port, u8 *data, u16 len)
|
|
{
|
|
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;
|
|
}
|
|
u32 hello_cat(u8 hw, u8 src_id, u8 dest_id, u16 port, u8 *data, u16 len)
|
|
{
|
|
ERPC_DEBUG("Hello Cat!\n");
|
|
// 防止编译警告
|
|
UNUSED(hw);
|
|
UNUSED(src_id);
|
|
UNUSED(dest_id);
|
|
UNUSED(port);
|
|
UNUSED(data);
|
|
UNUSED(len);
|
|
return 0;
|
|
}
|
|
|
|
u32 hello_dog(u8 hw, u8 src_id, u8 dest_id, u16 port, u8 *data, u16 len)
|
|
{
|
|
ERPC_DEBUG("Hello Dog!\n");
|
|
// 防止编译警告
|
|
u8 data_out[10] = "12345";
|
|
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;
|
|
}
|
|
erpc_cmd_list_t erpc_cmd_list[] = {
|
|
{.cmd = 0x01, hellworld},
|
|
{.cmd = 0x02, hello_cat},
|
|
{.cmd = 0x03, hello_dog},
|
|
};
|
|
|
|
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];
|
|
static u8 data_write(u8 *data, u16 len)
|
|
{
|
|
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()
|
|
{
|
|
for (int i = 0; i < (int)sizeof(erpc_cmd_list) / (int)sizeof(erpc_cmd_list[0]); i++)
|
|
{
|
|
erpc_add_cmd_list(&self_hw_cfg, &erpc_cmd_list[i]);
|
|
}
|
|
}
|
|
void sys_sleep(u32 ms)
|
|
{
|
|
Sleep(ms);
|
|
}
|
|
|
|
DWORD WINAPI send_task(LPVOID lpParam)
|
|
{
|
|
UNUSED(lpParam);
|
|
while (1)
|
|
{
|
|
erpc_send_deal_core();
|
|
}
|
|
}
|
|
DWORD WINAPI rev_task(LPVOID lpParam)
|
|
{
|
|
UNUSED(lpParam);
|
|
|
|
while (1)
|
|
{
|
|
// ERPC_DEBUG("rev_task\n");
|
|
erpc_rev_package_core();
|
|
erpc_rev_deal_core();
|
|
}
|
|
}
|
|
|
|
DWORD WINAPI test_task(LPVOID lpParam)
|
|
{
|
|
UNUSED(lpParam);
|
|
ERPC_DEBUG("test_task\n");
|
|
while (1)
|
|
{
|
|
// 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);
|
|
ret = erpc_send(self_hw_cfg.ord, self_hw_cfg.local_id, 0x02, NULL, 0);
|
|
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);
|
|
ERPC_DEBUG("[test_task]send ret:%d\n", ret);
|
|
UNUSED(ret);
|
|
sys_sleep(1000);
|
|
}
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
UNUSED(argc);
|
|
UNUSED(argv);
|
|
u32 ret = 0;
|
|
ERPC_DEBUG("erpc_port_self start\n");
|
|
ret = erpc_hw_add(&self_hw_cfg);
|
|
ERPC_DEBUG("erpc_hw_add ret:%d\n", ret);
|
|
CHECK_IF_ERROR(ret, 0);
|
|
erpc_cmd_config();
|
|
ERPC_DEBUG("erpc_cmd_config ret:%d\n", ret);
|
|
erpc_sleep_tick = sys_sleep;
|
|
|
|
HANDLE threadHandle[3];
|
|
deal_lock = CreateMutex(NULL, FALSE, NULL);
|
|
if (deal_lock == NULL)
|
|
{
|
|
ERPC_DEBUG("创建互斥锁失败\n");
|
|
return 1;
|
|
}
|
|
send_lock = CreateMutex(NULL, FALSE, NULL);
|
|
if (send_lock == NULL)
|
|
{
|
|
ERPC_DEBUG("创建互斥锁失败\n");
|
|
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]);
|
|
CloseHandle(threadHandle[2]);
|
|
return 0;
|
|
} |