Skip to content

Commit cdf4c7e

Browse files
committed
[BSP] Enable module application in simulator BSP
1 parent aa190ed commit cdf4c7e

File tree

2 files changed

+72
-9
lines changed

2 files changed

+72
-9
lines changed

bsp/simulator/drivers/module_win32.c

Lines changed: 70 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,67 @@ FINSH_FUNCTION_EXPORT_ALIAS(rt_module_open, exec, exec module from a file);
350350

351351
#endif
352352

353+
#define RT_MODULE_ARG_MAX 8
354+
static int _rt_module_split_arg(char* cmd, rt_size_t length, char* argv[])
355+
{
356+
int argc = 0;
357+
char *ptr = cmd;
358+
359+
while ((ptr - cmd) < length)
360+
{
361+
/* strip bank and tab */
362+
while ((*ptr == ' ' || *ptr == '\t') && (ptr -cmd)< length)
363+
*ptr++ = '\0';
364+
/* check whether it's the end of line */
365+
if ((ptr - cmd)>= length) break;
366+
367+
/* handle string with quote */
368+
if (*ptr == '"')
369+
{
370+
argv[argc++] = ++ptr;
371+
372+
/* skip this string */
373+
while (*ptr != '"' && (ptr-cmd) < length)
374+
if (*ptr ++ == '\\') ptr ++;
375+
if ((ptr - cmd) >= length) break;
376+
377+
/* skip '"' */
378+
*ptr ++ = '\0';
379+
}
380+
else
381+
{
382+
argv[argc++] = ptr;
383+
while ((*ptr != ' ' && *ptr != '\t') && (ptr - cmd) < length)
384+
ptr ++;
385+
}
386+
387+
if (argc >= RT_MODULE_ARG_MAX) break;
388+
}
389+
390+
return argc;
391+
}
392+
393+
/* module main thread entry */
394+
static void module_main_entry(void* parameter)
395+
{
396+
int argc;
397+
char *argv[RT_MODULE_ARG_MAX];
398+
typedef int (*main_func_t)(int argc, char** argv);
399+
400+
rt_module_t module = (rt_module_t) parameter;
401+
if (module == RT_NULL || module->module_cmd_line == RT_NULL) return;
402+
403+
rt_memset(argv, 0x00, sizeof(argv));
404+
argc = _rt_module_split_arg((char*)module->module_cmd_line, module->module_cmd_size, argv);
405+
if (argc == 0) return ;
406+
407+
/* do the main function */
408+
((main_func_t)module->module_entry)(argc, argv);
409+
return;
410+
}
411+
353412
/**
354-
* This function will do a excutable program with main function and parameters.
413+
* This function will do a executable program with main function and parameters.
355414
*
356415
* @param path the full path of application module
357416
* @param cmd_line the command line of program
@@ -455,14 +514,10 @@ rt_module_t rt_module_exec_cmd(const char *path, const char* cmd_line, int line_
455514
module->page_cnt = 0;
456515
#endif
457516

458-
/* create module thread */
459-
module->module_thread =
460-
rt_thread_create(name,
461-
(void(*)(void *))module->module_entry, RT_NULL,
462-
2048, RT_THREAD_PRIORITY_MAX - 2, 10);
463-
464-
RT_DEBUG_LOG(RT_DEBUG_MODULE, ("thread entry 0x%x\n",
465-
module->module_entry));
517+
/* create module thread */
518+
module->module_thread = rt_thread_create(name,
519+
module_main_entry, module,
520+
2048, RT_THREAD_PRIORITY_MAX - 2, 10);
466521

467522
/* set module id */
468523
module->module_thread->module_id = (void *)module;
@@ -500,4 +555,10 @@ rt_err_t rt_module_destroy(rt_module_t module)
500555
{
501556
return 0;
502557
}
558+
559+
rt_err_t rt_module_unload(rt_module_t module)
560+
{
561+
return 0;
562+
}
563+
503564
#endif

bsp/simulator/rtconfig.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@
9898
// #define RT_USING_LIBC
9999
// <bool name="RT_USING_PTHREADS" description="Using POSIX threads library" default="true" />
100100
// #define RT_USING_PTHREADS
101+
// <bool name="RT_USING_MODULE" description="Enable Moudle Application" default="true" />
102+
#define RT_USING_MODULE
101103
// </section>
102104

103105
// <section name="RT_USING_DFS" description="Device file system" default="true" >

0 commit comments

Comments
 (0)