线程增加ipc能力,原ipc对象将修改为ipc代理功能

This commit is contained in:
zhangzheng
2023-11-26 00:15:32 +08:00
parent 782ef1331d
commit 5a0ad76ad0
16 changed files with 569 additions and 113 deletions

View File

@@ -2,7 +2,7 @@
#include "u_types.h"
#include "u_prot.h"
#include "u_ipc.h"
msg_tag_t thread_yield(obj_handler_t obj);
msg_tag_t thread_msg_buf_set(obj_handler_t obj, void *msg);
msg_tag_t thread_msg_buf_get(obj_handler_t obj, umword_t *msg, umword_t *len);
@@ -10,6 +10,11 @@ msg_tag_t thread_exec_regs(obj_handler_t obj, umword_t pc, umword_t sp, umword_t
msg_tag_t thread_run(obj_handler_t obj, uint8_t prio);
msg_tag_t thread_bind_task(obj_handler_t obj, obj_handler_t tk_obj);
msg_tag_t thread_ipc_wait(void);
msg_tag_t thread_ipc_reply(msg_tag_t in_tag, ipc_timeout_t timeout);
msg_tag_t thread_ipc_send(msg_tag_t in_tag, obj_handler_t target_th_obj, ipc_timeout_t timeout);
msg_tag_t thread_ipc_call(msg_tag_t in_tag, obj_handler_t target_th_obj, ipc_timeout_t timeout);
#define thread_get_cur_ipc_msg() \
( \
{ \

View File

@@ -1,6 +1,7 @@
#include "u_prot.h"
#include "u_types.h"
#include "u_thread.h"
#include "u_ipc.h"
enum thread_op
{
SET_EXEC_REGS,
@@ -9,7 +10,80 @@ enum thread_op
MSG_BUG_GET,
MSG_BUG_SET,
YIELD,
DO_IPC,
};
enum IPC_TYPE
{
IPC_CALL,
IPC_REPLY,
IPC_WAIT,
IPC_RECV,
IPC_SEND,
};
msg_tag_t thread_ipc_wait(void)
{
register volatile umword_t r0 asm("r0");
mk_syscall(syscall_prot_create4(DO_IPC, THREAD_PROT, -1, TRUE).raw,
0,
IPC_WAIT,
0,
0,
0,
0);
asm __volatile__(""
:
:
: "r0");
return msg_tag_init(r0);
}
msg_tag_t thread_ipc_reply(msg_tag_t in_tag, ipc_timeout_t timeout)
{
register volatile umword_t r0 asm("r0");
mk_syscall(syscall_prot_create4(DO_IPC, THREAD_PROT, -1, TRUE).raw,
in_tag.raw,
IPC_REPLY,
0,
timeout.raw,
0,
0);
asm __volatile__(""
:
:
: "r0");
return msg_tag_init(r0);
}
msg_tag_t thread_ipc_send(msg_tag_t in_tag, obj_handler_t target_th_obj, ipc_timeout_t timeout)
{
register volatile umword_t r0 asm("r0");
mk_syscall(syscall_prot_create4(DO_IPC, THREAD_PROT, -1, TRUE).raw,
in_tag.raw,
IPC_SEND,
target_th_obj,
timeout.raw,
0,
0);
asm __volatile__(""
:
:
: "r0");
return msg_tag_init(r0);
}
msg_tag_t thread_ipc_call(msg_tag_t in_tag, obj_handler_t target_th_obj, ipc_timeout_t timeout)
{
register volatile umword_t r0 asm("r0");
mk_syscall(syscall_prot_create4(DO_IPC, THREAD_PROT, -1, TRUE).raw,
in_tag.raw,
IPC_CALL,
target_th_obj,
timeout.raw,
0,
0);
asm __volatile__(""
:
:
: "r0");
return msg_tag_init(r0);
}
msg_tag_t thread_yield(obj_handler_t obj)
{
register volatile umword_t r0 asm("r0");

View File

@@ -35,10 +35,10 @@ int main(int argc, char *args[])
mpu_test();
thread_press_test();
kobj_create_press_test();
ipc_test();
pthread_cond_lock_test();
pthread_lock_test();
#endif
ipc_test();
uenv_t env = *u_get_global_env();
obj_handler_t ipc_hd;
int ret = rpc_creaite_bind_ipc(THREAD_MAIN, NULL, &ipc_hd);

View File

@@ -69,7 +69,7 @@ static void thread_test_func2(void)
static void hard_sleep(void)
{
for (volatile int i; i < 10000000; i++)
for (volatile int i; i < 1000000000; i++)
;
}
static void thread_test_func(void)
@@ -79,10 +79,10 @@ static void thread_test_func(void)
thread_msg_buf_get(th1_hd, (umword_t *)(&buf), NULL);
while (1)
{
ipc_wait(ipc_hd, 0);
thread_ipc_wait();
printf("srv recv:%s", buf);
hard_sleep();
ipc_reply(ipc_hd, msg_tag_init4(0, ROUND_UP(strlen(buf), WORD_BYTES), 0, 0));
thread_ipc_reply(msg_tag_init4(0, ROUND_UP(strlen(buf), WORD_BYTES), 0, 0), ipc_timeout_create2(0, 0));
}
printf("thread_test_func.\n");
task_unmap(TASK_PROT, vpage_create_raw3(KOBJ_DELETE_RIGHT, 0, th1_hd));
@@ -96,7 +96,7 @@ static void thread_test_func2(void)
while (1)
{
strcpy(buf, "I am th2.\n");
ipc_call(ipc_hd, msg_tag_init4(0, ROUND_UP(strlen(buf), WORD_BYTES), 0, 0), ipc_timeout_create2(0, 0));
thread_ipc_call(msg_tag_init4(0, ROUND_UP(strlen(buf), WORD_BYTES), 0, 0), th1_hd, ipc_timeout_create2(0, 0));
printf("th2:%s", buf);
}
printf("thread_test_func2.\n");
@@ -113,7 +113,7 @@ static void thread_test_func3(void)
while (1)
{
strcpy(buf, "I am th3.\n");
ipc_call(ipc_hd, msg_tag_init4(0, ROUND_UP(strlen(buf), WORD_BYTES), 0, 0), ipc_timeout_create2(0, 0));
thread_ipc_call(msg_tag_init4(0, ROUND_UP(strlen(buf), WORD_BYTES), 0, 0), th1_hd, ipc_timeout_create2(0, 0));
printf("th3:%s", buf);
}
printf("thread_test_func2.\n");
@@ -127,17 +127,14 @@ static void thread_test_func3(void)
*/
void ipc_test(void)
{
msg_tag_t tag;
th1_hd = handler_alloc();
assert(th1_hd != HANDLER_INVALID);
th2_hd = handler_alloc();
assert(th2_hd != HANDLER_INVALID);
th3_hd = handler_alloc();
assert(th3_hd != HANDLER_INVALID);
ipc_hd = handler_alloc();
assert(ipc_hd != HANDLER_INVALID);
msg_tag_t tag = factory_create_ipc(FACTORY_PROT, vpage_create_raw3(KOBJ_ALL_RIGHTS, 0, ipc_hd));
assert(msg_tag_get_prot(tag) >= 0);
tag = factory_create_thread(FACTORY_PROT, vpage_create_raw3(KOBJ_ALL_RIGHTS, 0, th1_hd));
assert(msg_tag_get_prot(tag) >= 0);
ipc_bind(ipc_hd, th1_hd, 0);
@@ -176,11 +173,4 @@ void ipc_test(void)
void ipc_timeout_test(void)
{
obj_handler_t hd = handler_alloc();
factory_create_ipc(FACTORY_PROT, vpage_create_raw3(KOBJ_ALL_RIGHTS, 0, hd));
printf("sleep.\n");
ipc_call(hd, msg_tag_init4(0, 0, 0, 0), ipc_timeout_create2(100, 100));
printf("sleep.\n");
ipc_call(hd, msg_tag_init4(0, 0, 0, 0), ipc_timeout_create2(100, 100));
handler_free_umap(hd);
}