修复一些bugs

This commit is contained in:
zhangzheng
2023-09-02 00:18:54 +08:00
parent 7c230e34e1
commit a9969d7762
17 changed files with 254 additions and 66 deletions

View File

@@ -9,6 +9,7 @@
#define IPC_PROT 5
#define MM_PROT 6
#define THREAD_MAIN THREAD_PROT
#define TASK_THIS TASK_PROT
typedef struct msg_tag

View File

@@ -16,15 +16,14 @@ int main(int argc, char *args[])
mm_test();
ulog_test();
factory_test();
app_test();
mpu_test();
printf_test();
thread_test();
#endif
ipc_test();
thread_exit_test();
#endif
app_test();
task_unmap(TASK_THIS, TASK_THIS);
printf("exit init.\n");
while (1)
;
// task_unmap(TASK_PROT, TASK_PROT);
return 0;
}

View File

@@ -6,8 +6,10 @@
#include "u_task.h"
#include "u_hd_man.h"
#include "u_thread.h"
#include "u_ipc.h"
#include "cpiofs.h"
#include <assert.h>
#include <string.h>
/**
* @brief 加载一个app并启动
*
@@ -19,9 +21,11 @@ void app_test(void)
assert(addr);
app_info_t *app = (app_info_t *)addr;
printf("app addr is 0x%x\n", app);
umword_t ram_base;
obj_handler_t hd_task = handler_alloc();
obj_handler_t hd_thread = handler_alloc();
obj_handler_t hd_ipc = handler_alloc();
assert(hd_task != HANDLER_INVALID);
assert(hd_thread != HANDLER_INVALID);
@@ -30,11 +34,18 @@ void app_test(void)
assert(msg_tag_get_prot(tag) >= 0);
tag = factory_create_thread(FACTORY_PROT, hd_thread);
assert(msg_tag_get_prot(tag) >= 0);
tag = factory_create_ipc(FACTORY_PROT, hd_ipc);
assert(msg_tag_get_prot(tag) >= 0);
printf("ipc hd is %d\n", hd_ipc);
tag = task_alloc_ram_base(hd_task, app->i.ram_size, &ram_base);
assert(msg_tag_get_prot(tag) >= 0);
tag = task_map(hd_task, LOG_PROT, LOG_PROT);
assert(msg_tag_get_prot(tag) >= 0);
tag = task_map(hd_task, hd_ipc, hd_ipc);
assert(msg_tag_get_prot(tag) >= 0);
tag = task_map(hd_task, hd_thread, THREAD_MAIN);
assert(msg_tag_get_prot(tag) >= 0);
void *sp_addr = (char *)ram_base + app->i.stack_offset - app->i.data_offset;
void *sp_addr_top = (char *)sp_addr + app->i.stack_size;
tag = thread_exec_regs(hd_thread, (umword_t)addr, (umword_t)sp_addr_top, ram_base);
@@ -43,4 +54,11 @@ void app_test(void)
assert(msg_tag_get_prot(tag) >= 0);
tag = thread_run(hd_thread);
assert(msg_tag_get_prot(tag) >= 0);
char *buf;
umword_t len;
thread_msg_buf_get(THREAD_MAIN, (umword_t *)(&buf), NULL);
strcpy(buf, "hello shell.\n");
ipc_send(hd_ipc, strlen(buf), 0);
printf("test ok\n");
}

View File

@@ -8,4 +8,5 @@ void thread_test(void);
void app_test(void);
void mpu_test(void);
void printf_test(void);
void ipc_test(void);
void ipc_test(void);
void thread_exit_test(void);

View File

@@ -0,0 +1,86 @@
#include "u_log.h"
#include "u_prot.h"
#include "u_mm.h"
#include "u_factory.h"
#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
static __attribute__((aligned(8))) uint8_t stack0[STACK_SIZE];
static __attribute__((aligned(8))) uint8_t stack1[STACK_SIZE];
static void hard_sleep(void)
{
for (volatile int i; i < 10000000; i++)
;
}
static void thread_test_func(void)
{
char *buf;
umword_t len;
thread_msg_buf_get(th1_hd, (umword_t *)(&buf), NULL);
printf("thread_test_func.\n");
task_unmap(TASK_PROT, th1_hd);
printf("Error\n");
}
static void thread_test_func2(void)
{
char *buf;
umword_t len;
thread_msg_buf_get(th2_hd, (umword_t *)(&buf), NULL);
printf("thread_test_func2.\n");
task_unmap(TASK_PROT, th2_hd);
printf("Error\n");
}
/**
* @brief 启动两个线程并进行ipc测试
*
*/
void thread_exit_test(void)
{
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);
msg_tag_t tag = factory_create_ipc(FACTORY_PROT, ipc_hd);
assert(msg_tag_get_prot(tag) >= 0);
tag = factory_create_thread(FACTORY_PROT, th1_hd);
assert(msg_tag_get_prot(tag) >= 0);
tag = thread_msg_buf_set(th1_hd, msg_buf0);
assert(msg_tag_get_prot(tag) >= 0);
tag = thread_exec_regs(th1_hd, (umword_t)thread_test_func, (umword_t)stack0 + STACK_SIZE, RAM_BASE());
assert(msg_tag_get_prot(tag) >= 0);
tag = thread_bind_task(th1_hd, TASK_THIS);
assert(msg_tag_get_prot(tag) >= 0);
tag = thread_run(th1_hd);
assert(msg_tag_get_prot(tag) >= 0);
tag = factory_create_thread(FACTORY_PROT, th2_hd);
assert(msg_tag_get_prot(tag) >= 0);
tag = thread_msg_buf_set(th2_hd, msg_buf1);
assert(msg_tag_get_prot(tag) >= 0);
tag = thread_exec_regs(th2_hd, (umword_t)thread_test_func2, (umword_t)stack1 + STACK_SIZE, RAM_BASE());
assert(msg_tag_get_prot(tag) >= 0);
tag = thread_bind_task(th2_hd, TASK_THIS);
assert(msg_tag_get_prot(tag) >= 0);
tag = thread_run(th2_hd);
assert(msg_tag_get_prot(tag) >= 0);
}

View File

@@ -5,12 +5,21 @@
#include "u_factory.h"
#include "u_thread.h"
#include "u_task.h"
#include "u_ipc.h"
#include <assert.h>
#include <stdio.h>
static uint8_t msg_buf[MSG_BUG_LEN];
int main(int argc, char *args[])
{
// printf("shell>\n");
ulog_write_str(LOG_PROT, "MKRTOS:\n");
while(1);
thread_msg_buf_set(THREAD_MAIN, msg_buf);
ipc_recv(12, 0);
char *buf;
umword_t len;
thread_msg_buf_get(THREAD_MAIN, (umword_t *)(&buf), NULL);
printf(buf);
task_unmap(TASK_THIS, TASK_THIS);
ulog_write_str(LOG_PROT, "Error.\n");
return 0;
}