ipc support call.

This commit is contained in:
zhangzheng
2023-09-01 22:01:13 +08:00
parent 5ba4cc7fb2
commit a513010c51
9 changed files with 148 additions and 155 deletions

View File

@@ -3,7 +3,8 @@
#include "u_prot.h"
#define MSG_BUG_LEN 128
#define MSG_BUF_CALL_FLAGS 0x02U //!< 是CALL
#define MSG_BUF_RECV_R_FLAGS 0x02U //!< 接收上次发送数据的接收者
#define MSG_BUF_REPLY_FLAGS 0x04U //!<
msg_tag_t ipc_recv(obj_handler_t obj);
msg_tag_t ipc_recv(obj_handler_t obj, umword_t flags);
msg_tag_t ipc_send(obj_handler_t obj, umword_t len, umword_t flags);

View File

@@ -1,16 +1,17 @@
#include "u_types.h"
#include "u_prot.h"
#include "u_ipc.h"
enum ipc_op
{
IPC_SEND, //!< 发送IPC消息
IPC_REVC, //!< 接受IPC消息
};
msg_tag_t ipc_recv(obj_handler_t obj)
msg_tag_t ipc_recv(obj_handler_t obj, umword_t flags)
{
register volatile umword_t r0 asm("r0");
syscall(obj, msg_tag_init3(IPC_REVC, 0, IPC_PROT).raw,
0,
syscall(obj, msg_tag_init3(IPC_REVC, 1, IPC_PROT).raw,
flags,
0,
0,
0,

View File

@@ -16,10 +16,10 @@ int main(int argc, char *args[])
mm_test();
ulog_test();
factory_test();
thread_test();
app_test();
mpu_test();
printf_test();
thread_test();
#endif
ipc_test();
printf("exit init.\n");

View File

@@ -66,6 +66,12 @@ static void thread_test_func2(void)
printf("Error\n");
}
#else
static void hard_sleep(void)
{
for (volatile int i; i < 10000000; i++)
;
}
static void thread_test_func(void)
{
char *buf;
@@ -73,10 +79,10 @@ static void thread_test_func(void)
thread_msg_buf_get(th1_hd, (umword_t *)(&buf), NULL);
while (1)
{
ipc_recv(ipc_hd);
printf(buf);
strcpy(buf, "thread_test_func.\n");
ipc_send(ipc_hd, strlen(buf), 0);
ipc_recv(ipc_hd, 0);
printf("srv recv:%s", buf);
hard_sleep();
ipc_send(ipc_hd, strlen(buf), MSG_BUF_REPLY_FLAGS);
}
printf("thread_test_func.\n");
task_unmap(TASK_PROT, th1_hd);
@@ -89,14 +95,16 @@ static void thread_test_func2(void)
thread_msg_buf_get(th2_hd, (umword_t *)(&buf), NULL);
while (1)
{
strcpy(buf, "thread_test_func2.\n");
ipc_send(ipc_hd, strlen(buf), MSG_BUF_CALL_FLAGS);
printf(buf);
strcpy(buf, "I am th2.");
ipc_send(ipc_hd, strlen(buf), 0);
ipc_recv(ipc_hd, MSG_BUF_RECV_R_FLAGS);
printf("th2:%s", buf);
}
printf("thread_test_func2.\n");
task_unmap(TASK_PROT, th2_hd);
printf("Error\n");
}
static void thread_test_func3(void)
{
char *buf;
@@ -104,10 +112,10 @@ static void thread_test_func3(void)
thread_msg_buf_get(th3_hd, (umword_t *)(&buf), NULL);
while (1)
{
ipc_recv(ipc_hd);
printf(buf);
strcpy(buf, "thread_test_func3.\n");
strcpy(buf, "I am th3.\n");
ipc_send(ipc_hd, strlen(buf), 0);
ipc_recv(ipc_hd, MSG_BUF_RECV_R_FLAGS);
printf("th3:%s", buf);
}
printf("thread_test_func2.\n");
task_unmap(TASK_PROT, th3_hd);
@@ -153,15 +161,15 @@ void ipc_test(void)
tag = thread_run(th2_hd);
assert(msg_tag_get_prot(tag) >= 0);
// assert(msg_tag_get_prot(tag) >= 0);
// tag = factory_create_thread(FACTORY_PROT, th3_hd);
// assert(msg_tag_get_prot(tag) >= 0);
// tag = thread_msg_buf_set(th3_hd, msg_buf2);
// assert(msg_tag_get_prot(tag) >= 0);
// tag = thread_exec_regs(th3_hd, (umword_t)thread_test_func3, (umword_t)stack2 + STACK_SIZE, RAM_BASE());
// assert(msg_tag_get_prot(tag) >= 0);
// tag = thread_bind_task(th3_hd, TASK_THIS);
// assert(msg_tag_get_prot(tag) >= 0);
// tag = thread_run(th3_hd);
// assert(msg_tag_get_prot(tag) >= 0);
assert(msg_tag_get_prot(tag) >= 0);
tag = factory_create_thread(FACTORY_PROT, th3_hd);
assert(msg_tag_get_prot(tag) >= 0);
tag = thread_msg_buf_set(th3_hd, msg_buf2);
assert(msg_tag_get_prot(tag) >= 0);
tag = thread_exec_regs(th3_hd, (umword_t)thread_test_func3, (umword_t)stack2 + STACK_SIZE, RAM_BASE());
assert(msg_tag_get_prot(tag) >= 0);
tag = thread_bind_task(th3_hd, TASK_THIS);
assert(msg_tag_get_prot(tag) >= 0);
tag = thread_run(th3_hd);
assert(msg_tag_get_prot(tag) >= 0);
}

View File

@@ -5,9 +5,12 @@
#include "u_thread.h"
#include "u_task.h"
#include "u_ipc.h"
#include "u_hd_man.h"
#include <assert.h>
#include <stdio.h>
static umword_t th1_hd = 0;
static umword_t th2_hd = 0;
static umword_t ipc_hd = 0;
static char msg_buf0[MSG_BUG_LEN];
static char msg_buf1[MSG_BUG_LEN];
#define STACK_SIZE 1024
@@ -17,32 +20,32 @@ static void thread_test_func(void)
{
char *buf;
umword_t len;
thread_msg_buf_get(11, (umword_t *)(&buf), NULL);
thread_msg_buf_get(th1_hd, (umword_t *)(&buf), NULL);
while (1)
{
msg_tag_t tag = ipc_recv(12);
msg_tag_t tag = ipc_recv(ipc_hd, 0);
if (msg_tag_get_prot(tag) > 0)
{
buf[msg_tag_get_prot(tag)] = 0;
printf("recv data is %s\n", buf);
}
strcpy(buf, "reply");
ipc_send(12, strlen("reply"), 0);
ipc_send(ipc_hd, strlen("reply"), 0);
}
printf("thread_test_func.\n");
task_unmap(TASK_PROT, 11);
task_unmap(TASK_PROT, th1_hd);
printf("Error\n");
}
static void thread_test_func2(void)
{
char *buf;
umword_t len;
thread_msg_buf_get(10, (umword_t *)(&buf), NULL);
thread_msg_buf_get(th2_hd, (umword_t *)(&buf), NULL);
while (1)
{
strcpy(buf, "1234");
ipc_send(12, strlen(buf), 0);
msg_tag_t tag = ipc_recv(12);
ipc_send(ipc_hd, strlen(buf), 0);
msg_tag_t tag = ipc_recv(ipc_hd, 0);
if (msg_tag_get_prot(tag) > 0)
{
buf[msg_tag_get_prot(tag)] = 0;
@@ -50,7 +53,7 @@ static void thread_test_func2(void)
}
}
printf("thread_test_func2.\n");
task_unmap(TASK_PROT, 10);
task_unmap(TASK_PROT, th2_hd);
printf("Error\n");
}
/**
@@ -59,27 +62,28 @@ static void thread_test_func2(void)
*/
void thread_test(void)
{
msg_tag_t tag = factory_create_ipc(FACTORY_PROT, 12);
if (msg_tag_get_prot(tag) < 0)
{
printf("factory_create_ipc no memory\n");
return;
}
tag = factory_create_thread(FACTORY_PROT, 11);
th1_hd = handler_alloc();
assert(th1_hd != HANDLER_INVALID);
th2_hd = handler_alloc();
assert(th2_hd != HANDLER_INVALID);
ipc_hd = handler_alloc();
assert(ipc_hd != HANDLER_INVALID);
if (msg_tag_get_prot(tag) < 0)
{
printf("factory_create_thread no memory\n");
return;
}
thread_msg_buf_set(11, msg_buf0);
thread_exec_regs(11, (umword_t)thread_test_func, (umword_t)stack0 + STACK_SIZE, RAM_BASE());
thread_bind_task(11, TASK_PROT);
thread_run(11);
msg_tag_t tag = factory_create_ipc(FACTORY_PROT, ipc_hd);
assert(msg_tag_get_prot(tag) >= 0);
factory_create_thread(FACTORY_PROT, 10);
thread_msg_buf_set(10, msg_buf1);
thread_exec_regs(10, (umword_t)thread_test_func2, (umword_t)stack1 + STACK_SIZE, RAM_BASE());
thread_bind_task(10, TASK_PROT);
thread_run(10);
tag = factory_create_thread(FACTORY_PROT, th1_hd);
assert(msg_tag_get_prot(tag) >= 0);
thread_msg_buf_set(th1_hd, msg_buf0);
thread_exec_regs(th1_hd, (umword_t)thread_test_func, (umword_t)stack0 + STACK_SIZE, RAM_BASE());
thread_bind_task(th1_hd, TASK_THIS);
thread_run(th1_hd);
factory_create_thread(FACTORY_PROT, th2_hd);
assert(msg_tag_get_prot(tag) >= 0);
thread_msg_buf_set(th2_hd, msg_buf1);
thread_exec_regs(th2_hd, (umword_t)thread_test_func2, (umword_t)stack1 + STACK_SIZE, RAM_BASE());
thread_bind_task(th2_hd, TASK_THIS);
thread_run(th2_hd);
}