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

@@ -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);