init支持rpc启动应用

This commit is contained in:
zhangzheng
2023-11-28 22:33:37 +08:00
parent e6ab040306
commit 2905bf4930
24 changed files with 235 additions and 26 deletions

View File

@@ -254,7 +254,8 @@
"__threading_support": "c",
"spinlock.h": "c",
"mr_api.h": "c",
"u_app_loader.h": "c"
"u_app_loader.h": "c",
"process_manager.h": "c"
},
"cortex-debug.showRTOS": false,
"cortex-debug.variableUseNaturalFormat": false,

View File

@@ -0,0 +1,3 @@
#pragma once
#define INT_MAX 0x7fffffff

View File

@@ -25,9 +25,8 @@
#include "ipc.h"
#include "err.h"
#include "slist.h"
#include <access.h>
#define INT_MAX 0x7fffffff
#include "access.h"
#include "limits.h"
#define FT_ADDR_NR 16 //!< 最多加锁的对象
@@ -70,6 +69,7 @@ typedef struct futex
kobject_t kobj;
futex_lock_t fl_list[FT_ADDR_NR]; //!< 存储加锁的地址
} futex_t;
static futex_t futex_obj;
static void futex_init(futex_t *ft);
typedef struct futex_wait_item
@@ -78,6 +78,7 @@ typedef struct futex_wait_item
thread_t *th;
mword_t sleep_times;
} futex_wait_item_t;
static slist_head_t wait_list;
/**

View File

@@ -159,9 +159,11 @@ static void task_syscall_func(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t i
tag = msg_tag_init4(0, 0, 0, -EINVAL);
break;
}
// ref_counter_inc(&tag_task->ref_cn);
kobj_del_list_init(&kobj_list);
obj_unmap(&tag_task->obj_space, vpage_create_raw(f->r[1]), &kobj_list);
kobj_del_list_to_do(&kobj_list);
// ref_counter_dec_and_release(&tag_task->ref_cn, &tag_task->kobj);
spinlock_set(&tag_task->kobj.lock, status);
tag = msg_tag_init4(0, 0, 0, 0);
}

View File

@@ -695,7 +695,11 @@ msg_tag_t thread_do_ipc(kobject_t *kobj, entry_frame_t *f, umword_t user_id)
msg_tag_t ret_msg;
ipc_timeout_t ipc_tm_out = ipc_timeout_create(f->r[3]);
thread_ipc_recv(&ret_msg, ipc_tm_out, &f->r[1]);
int ret = thread_ipc_recv(&ret_msg, ipc_tm_out, &f->r[1]);
if (ret < 0)
{
return msg_tag_init4(0, 0, 0, ret);
}
return ret_msg;
}
case IPC_SEND:

View File

@@ -1,9 +1,9 @@
#!/bin/bash
export TOOLCHAIN=/home/zhangzheng/gcc-arm-none-eabi-5_4-2016q3/bin/
export TOOLCHAIN_LIB=/home/zhangzheng/gcc-arm-none-eabi-5_4-2016q3/lib/gcc/arm-none-eabi/5.4.1/armv7-m
# export TOOLCHAIN=/Users/zhangzheng/gcc-arm-none-eabi-10.3-2021.10/bin/
# export TOOLCHAIN_LIB=/Users/zhangzheng/gcc-arm-none-eabi-10.3-2021.10/lib/gcc/arm-none-eabi/10.3.1/thumb/v7-m/nofp
# export TOOLCHAIN=/home/zhangzheng/gcc-arm-none-eabi-5_4-2016q3/bin/
# export TOOLCHAIN_LIB=/home/zhangzheng/gcc-arm-none-eabi-5_4-2016q3/lib/gcc/arm-none-eabi/5.4.1/armv7-m
export TOOLCHAIN=/Users/zhangzheng/gcc-arm-none-eabi-10.3-2021.10/bin/
export TOOLCHAIN_LIB=/Users/zhangzheng/gcc-arm-none-eabi-10.3-2021.10/lib/gcc/arm-none-eabi/10.3.1/thumb/v7-m/nofp
export KEN_OFFSET=0x2000
export INIT_OFFSET=0x10000
export BOOTFS_ADDR_OFFSET=0x20000

View File

@@ -0,0 +1,3 @@
#pragma once
int pm_run_app(const char *path, int flags);

View File

@@ -0,0 +1,21 @@
/**
* @file pm_svr.h
* @author zhangzheng (1358745329@qq.com)
* @brief
* @version 0.1
* @date 2023-11-28
*
* @copyright Copyright (c) 2023
*
*/
#pragma once
#include "u_rpc_svr.h"
typedef struct pm
{
rpc_svr_obj_t svr_obj;
} pm_t;
void pm_svr_obj_init(pm_t *pm);
int pm_rpc_run_app(const char *path);

View File

@@ -32,4 +32,7 @@
#define DRV_CLOSE ((uint16_t)3) //!< 关闭设备
#define DRV_IOCTL ((uint16_t)4) //!< 控制设备
#define META_PROT 0x0004
#define META_PROT 0x0004 //!< 元协议
#define PM_PROT 0x0005 //!< 进程管理协议
#define PM_RUN_APP ((uint16_t)0) //!< 启动应用程序

View File

@@ -34,7 +34,13 @@ RPC_GENERATION_OP3(drv_t, FS_PROT, DRV_READ, read,
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_OUT, RPC_TYPE_DATA, data,
rpc_size_t_t, rpc_size_t_t, RPC_DIR_IN, RPC_TYPE_DATA, size)
{
return dev_read(desc->data, data->data, size->data);
int ret = dev_read(desc->data, data->data, size->data);
if (ret >= 0)
{
data->len = ret;
}
return ret;
}
RPC_GENERATION_DISPATCH3(drv_t, FS_PROT, DRV_READ, read,

View File

@@ -0,0 +1,29 @@
#include "u_rpc.h"
#include "u_rpc_svr.h"
#include "rpc_prot.h"
#include "u_env.h"
#include "u_prot.h"
#include "u_hd_man.h"
#include "pm_svr.h"
#include <stdio.h>
#include <string.h>
#include <assert.h>
RPC_GENERATION_CALL2(pm_t, PM_PROT, PM_RUN_APP, run_app,
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, path,
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, flags)
int pm_run_app(const char *path, int flags)
{
rpc_ref_array_uint32_t_uint8_t_32_t rpc_path = {
.data = (uint8_t *)path,
.len = strlen(path) + 1,
};
rpc_int_t rpc_flags = {
.data = flags,
};
msg_tag_t tag = pm_t_run_app_call(u_get_global_env()->ns_hd, &rpc_path, &rpc_flags);
return msg_tag_get_val(tag);
}

View File

@@ -0,0 +1,41 @@
/**
* @file pm_svr.c
* @author zhangzheng (1358745329@qq.com)
* @brief
* @version 0.1
* @date 2023-11-28
*
* @copyright Copyright (c) 2023
*
*/
#include "rpc_prot.h"
#include "u_rpc.h"
#include "u_rpc_svr.h"
#include "u_hd_man.h"
#include "fs_svr.h"
#include "pm_svr.h"
#include <stdio.h>
/*run_app*/
RPC_GENERATION_OP2(pm_t, PM_PROT, PM_RUN_APP, run_app,
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, path,
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, flags)
{
int16_t ret = -1;
path->data[path->len - 1] = 0;
ret = pm_rpc_run_app(path->data);
return ret;
}
RPC_GENERATION_DISPATCH2(pm_t, PM_PROT, PM_RUN_APP, run_app,
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, path,
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, flags)
/*dispatch*/
RPC_DISPATCH1(pm_t, PM_PROT, typeof(PM_RUN_APP), FS_OPEN, run_app)
void pm_svr_obj_init(pm_t *pm)
{
rpc_svr_obj_init(&pm->svr_obj, rpc_pm_t_dispatch, PM_PROT);
}

View File

@@ -173,7 +173,7 @@ int app_load(const char *name, uenv_t *cur_env)
uenv->rev1 = HANDLER_INVALID;
uenv->rev2 = HANDLER_INVALID;
tag = thread_exec_regs(hd_thread, (umword_t)addr, (umword_t)sp_addr_top - sizeof(void*), ram_base, 1);
tag = thread_exec_regs(hd_thread, (umword_t)addr, (umword_t)sp_addr_top - sizeof(void *), ram_base, 1);
assert(msg_tag_get_prot(tag) >= 0);
/*启动线程运行*/
@@ -181,14 +181,14 @@ int app_load(const char *name, uenv_t *cur_env)
assert(msg_tag_get_prot(tag) >= 0);
return 0;
end_del_obj:
if (hd_task != HANDLER_INVALID)
{
task_unmap(TASK_THIS, vpage_create_raw3(KOBJ_DELETE_RIGHT, 0, hd_task));
}
if (hd_thread != HANDLER_INVALID)
{
task_unmap(TASK_THIS, vpage_create_raw3(KOBJ_DELETE_RIGHT, 0, hd_thread));
}
if (hd_task != HANDLER_INVALID)
{
task_unmap(TASK_THIS, vpage_create_raw3(KOBJ_DELETE_RIGHT, 0, hd_task));
}
// if (hd_ipc != HANDLER_INVALID)
// {
// task_unmap(TASK_THIS, vpage_create_raw3(KOBJ_DELETE_RIGHT, 0, hd_ipc));

View File

@@ -8,9 +8,9 @@ static obj_handler_t ipc_hd;
obj_handler_t drv_svr_init(void)
{
drv_init(&drv);
int ret;
printf("mr drv init...\n");
drv_init(&drv);
ret = rpc_creaite_bind_ipc(THREAD_MAIN, &drv, &ipc_hd);
assert(ret >= 0);

View File

@@ -10,8 +10,8 @@
int main(int argc, char *args[])
{
ns_register("/dev", drv_svr_init());
printf("mr drv start success...\n");
mr_auto_init();
printf("mr drv start success...\n");
drv_svr_loop();
return 0;
}

View File

@@ -3,8 +3,9 @@
#include "u_log.h"
#include "u_env.h"
#include "u_sleep.h"
#include "pm_cli.h"
#include "drv_cli.h"
#include <unistd.h>
#include <mr_api.h>
#include <assert.h>
void drv_test(void)
@@ -23,8 +24,10 @@ void drv_test(void)
int main(int argc, char *args[])
{
u_sleep_ms(100);
// printf("Hello world.\n");
printf("Hello world.\n");
usleep(100000);
// while (pm_run_app("hello", 0) < 0)
// usleep(100000);
ulog_write_str(u_get_global_env()->log_hd, "hello is runing...\n");
drv_test();
ulog_write_str(u_get_global_env()->log_hd, "Hello world.\n");

View File

@@ -1,4 +1,13 @@
/**
* @file heap_stack.c
* @author zhangzheng (1358745329@qq.com)
* @brief
* @version 0.1
* @date 2023-11-28
*
* @copyright Copyright (c) 2023
*
*/
#define HEAP_SIZE 8192
#define STACK_SIZE 1024 * 2

View File

@@ -1,4 +1,13 @@
/**
* @file main.c
* @author zhangzheng (1358745329@qq.com)
* @brief
* @version 0.1
* @date 2023-11-28
*
* @copyright Copyright (c) 2023
*
*/
#include "u_log.h"
#include "u_prot.h"
#include "u_mm.h"
@@ -11,6 +20,7 @@
#include "u_irq_sender.h"
#include "u_app_loader.h"
#include "u_rpc_svr.h"
#include "pm.h"
#include "test/test.h"
#include "u_rpc_svr.h"
@@ -54,6 +64,7 @@ int main(int argc, char *args[])
env = u_get_global_env();
rpc_meta_init(THREAD_MAIN, &env->ns_hd);
namespace_init();
pm_init();
ret = parse_cfg(DEFAULT_INIT_CFG, env);
printf("run app num is %d.\n", ret);

View File

@@ -1,4 +1,13 @@
/**
* @file namespace.c
* @author zhangzheng (1358745329@qq.com)
* @brief
* @version 0.1
* @date 2023-11-28
*
* @copyright Copyright (c) 2023
*
*/
#include <u_types.h>
#include <string.h>
#include <assert.h>

View File

@@ -1,3 +1,13 @@
/**
* @file namespace.h
* @author zhangzheng (1358745329@qq.com)
* @brief
* @version 0.1
* @date 2023-11-28
*
* @copyright Copyright (c) 2023
*
*/
#pragma once
#include "u_types.h"
#include "u_prot.h"

View File

@@ -1,4 +1,14 @@
#pragma once
/**
* @file parse_cfg.h
* @author zhangzheng (1358745329@qq.com)
* @brief
* @version 0.1
* @date 2023-11-28
*
* @copyright Copyright (c) 2023
*
*/
#include <u_env.h>

View File

@@ -0,0 +1,30 @@
/**
* @file pm.c
* @author zhangzheng (1358745329@qq.com)
* @brief
* @version 0.1
* @date 2023-11-28
*
* @copyright Copyright (c) 2023
*
*/
#include "pm_svr.h"
#include "u_app_loader.h"
#include "u_env.h"
#include "rpc_prot.h"
#include <stdio.h>
static pm_t pm;
void pm_init(void)
{
pm_svr_obj_init(&pm);
meta_reg_svr_obj(&pm.svr_obj, PM_PROT);
printf("pm runing..\n");
}
int pm_rpc_run_app(const char *path)
{
printf("pm run %s.\n", path);
return app_load(path, u_get_global_env());
}

View File

@@ -0,0 +1,13 @@
/**
* @file pm.h
* @author zhangzheng (1358745329@qq.com)
* @brief
* @version 0.1
* @date 2023-11-28
*
* @copyright Copyright (c) 2023
*
*/
#pragma once
void pm_init(void);