137 lines
3.0 KiB
C
137 lines
3.0 KiB
C
|
|
// #ifndef WINDOWS
|
|
// #error "This file is for Windows only"
|
|
// #endif
|
|
|
|
#include "erpc_core.h"
|
|
#include "windows.h"
|
|
#include <stdio.h>
|
|
void hellworld()
|
|
{
|
|
printf("Hello World!\n");
|
|
}
|
|
void hello_cat()
|
|
{
|
|
printf("Hello Cat!\n");
|
|
}
|
|
erpc_cmd_list_t erpc_cmd_list[] = {
|
|
{.cmd = 0x01, hellworld},
|
|
{.cmd = 0x02, hello_cat},
|
|
};
|
|
|
|
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, u32 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 < sizeof(erpc_cmd_list) / 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)
|
|
{
|
|
while (1)
|
|
{
|
|
erpc_send_deal_core();
|
|
}
|
|
}
|
|
DWORD WINAPI rev_task(LPVOID lpParam)
|
|
{
|
|
|
|
while (1)
|
|
{
|
|
// printf("rev_task\n");
|
|
erpc_rev_package_core();
|
|
erpc_rev_deal_core();
|
|
}
|
|
}
|
|
|
|
DWORD WINAPI test_task(LPVOID lpParam)
|
|
{
|
|
printf("test_task\n");
|
|
while (1)
|
|
{
|
|
// 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);
|
|
}
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
u32 ret = 0;
|
|
printf("erpc_port_self start\n");
|
|
ret = erpc_hw_add(&self_hw_cfg);
|
|
printf("erpc_hw_add ret:%d\n", ret);
|
|
CHECK_IF_ERROR(ret, 0);
|
|
erpc_cmd_config();
|
|
printf("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)
|
|
{
|
|
printf("创建互斥锁失败,错误代码:%d\n", GetLastError());
|
|
return 1;
|
|
}
|
|
send_lock = CreateMutex(NULL, FALSE, NULL);
|
|
if (send_lock == NULL)
|
|
{
|
|
printf("创建互斥锁失败,错误代码:%d\n", GetLastError());
|
|
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;
|
|
} |