[BSP] Enable module application in simulator BSP
This commit is contained in:
parent
aa190ed5f6
commit
cdf4c7e897
|
@ -350,8 +350,67 @@ FINSH_FUNCTION_EXPORT_ALIAS(rt_module_open, exec, exec module from a file);
|
|||
|
||||
#endif
|
||||
|
||||
#define RT_MODULE_ARG_MAX 8
|
||||
static int _rt_module_split_arg(char* cmd, rt_size_t length, char* argv[])
|
||||
{
|
||||
int argc = 0;
|
||||
char *ptr = cmd;
|
||||
|
||||
while ((ptr - cmd) < length)
|
||||
{
|
||||
/* strip bank and tab */
|
||||
while ((*ptr == ' ' || *ptr == '\t') && (ptr -cmd)< length)
|
||||
*ptr++ = '\0';
|
||||
/* check whether it's the end of line */
|
||||
if ((ptr - cmd)>= length) break;
|
||||
|
||||
/* handle string with quote */
|
||||
if (*ptr == '"')
|
||||
{
|
||||
argv[argc++] = ++ptr;
|
||||
|
||||
/* skip this string */
|
||||
while (*ptr != '"' && (ptr-cmd) < length)
|
||||
if (*ptr ++ == '\\') ptr ++;
|
||||
if ((ptr - cmd) >= length) break;
|
||||
|
||||
/* skip '"' */
|
||||
*ptr ++ = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
argv[argc++] = ptr;
|
||||
while ((*ptr != ' ' && *ptr != '\t') && (ptr - cmd) < length)
|
||||
ptr ++;
|
||||
}
|
||||
|
||||
if (argc >= RT_MODULE_ARG_MAX) break;
|
||||
}
|
||||
|
||||
return argc;
|
||||
}
|
||||
|
||||
/* module main thread entry */
|
||||
static void module_main_entry(void* parameter)
|
||||
{
|
||||
int argc;
|
||||
char *argv[RT_MODULE_ARG_MAX];
|
||||
typedef int (*main_func_t)(int argc, char** argv);
|
||||
|
||||
rt_module_t module = (rt_module_t) parameter;
|
||||
if (module == RT_NULL || module->module_cmd_line == RT_NULL) return;
|
||||
|
||||
rt_memset(argv, 0x00, sizeof(argv));
|
||||
argc = _rt_module_split_arg((char*)module->module_cmd_line, module->module_cmd_size, argv);
|
||||
if (argc == 0) return ;
|
||||
|
||||
/* do the main function */
|
||||
((main_func_t)module->module_entry)(argc, argv);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will do a excutable program with main function and parameters.
|
||||
* This function will do a executable program with main function and parameters.
|
||||
*
|
||||
* @param path the full path of application module
|
||||
* @param cmd_line the command line of program
|
||||
|
@ -456,14 +515,10 @@ rt_module_t rt_module_exec_cmd(const char *path, const char* cmd_line, int line_
|
|||
#endif
|
||||
|
||||
/* create module thread */
|
||||
module->module_thread =
|
||||
rt_thread_create(name,
|
||||
(void(*)(void *))module->module_entry, RT_NULL,
|
||||
module->module_thread = rt_thread_create(name,
|
||||
module_main_entry, module,
|
||||
2048, RT_THREAD_PRIORITY_MAX - 2, 10);
|
||||
|
||||
RT_DEBUG_LOG(RT_DEBUG_MODULE, ("thread entry 0x%x\n",
|
||||
module->module_entry));
|
||||
|
||||
/* set module id */
|
||||
module->module_thread->module_id = (void *)module;
|
||||
module->parent.flag = RT_MODULE_FLAG_WITHENTRY;
|
||||
|
@ -500,4 +555,10 @@ rt_err_t rt_module_destroy(rt_module_t module)
|
|||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
rt_err_t rt_module_unload(rt_module_t module)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -98,6 +98,8 @@
|
|||
// #define RT_USING_LIBC
|
||||
// <bool name="RT_USING_PTHREADS" description="Using POSIX threads library" default="true" />
|
||||
// #define RT_USING_PTHREADS
|
||||
// <bool name="RT_USING_MODULE" description="Enable Moudle Application" default="true" />
|
||||
#define RT_USING_MODULE
|
||||
// </section>
|
||||
|
||||
// <section name="RT_USING_DFS" description="Device file system" default="true" >
|
||||
|
|
Loading…
Reference in New Issue