未验证 提交 0ee4c74a 编写于 作者: B Bernard Xiong 提交者: GitHub

Merge pull request #1378 from armink/fix_finsh

Finsh thread using heap when RT_USING_HEAP is defined
...@@ -50,9 +50,11 @@ ...@@ -50,9 +50,11 @@
#endif #endif
/* finsh thread */ /* finsh thread */
#ifndef RT_USING_HEAP
static struct rt_thread finsh_thread; static struct rt_thread finsh_thread;
ALIGN(RT_ALIGN_SIZE) ALIGN(RT_ALIGN_SIZE)
static char finsh_thread_stack[FINSH_THREAD_STACK_SIZE]; static char finsh_thread_stack[FINSH_THREAD_STACK_SIZE];
#endif
struct finsh_shell *shell; struct finsh_shell *shell;
#if defined(FINSH_USING_MSH) || (defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR)) #if defined(FINSH_USING_MSH) || (defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR))
...@@ -721,7 +723,8 @@ __declspec(allocate("FSymTab$z")) const struct finsh_syscall __fsym_end = ...@@ -721,7 +723,8 @@ __declspec(allocate("FSymTab$z")) const struct finsh_syscall __fsym_end =
*/ */
int finsh_system_init(void) int finsh_system_init(void)
{ {
rt_err_t result; rt_err_t result = RT_EOK;
rt_thread_t tid;
#ifdef FINSH_USING_SYMTAB #ifdef FINSH_USING_SYMTAB
#ifdef __CC_ARM /* ARM C Compiler */ #ifdef __CC_ARM /* ARM C Compiler */
...@@ -764,29 +767,31 @@ int finsh_system_init(void) ...@@ -764,29 +767,31 @@ int finsh_system_init(void)
#endif #endif
#endif #endif
/* create or set shell structure */
#ifdef RT_USING_HEAP #ifdef RT_USING_HEAP
shell = (struct finsh_shell *)rt_malloc(sizeof(struct finsh_shell)); /* create or set shell structure */
shell = (struct finsh_shell *)rt_calloc(1, sizeof(struct finsh_shell));
if (shell == RT_NULL) if (shell == RT_NULL)
{ {
rt_kprintf("no memory for shell\n"); rt_kprintf("no memory for shell\n");
return -1; return -1;
} }
tid = rt_thread_create(FINSH_THREAD_NAME,
finsh_thread_entry, RT_NULL,
FINSH_THREAD_STACK_SIZE, FINSH_THREAD_PRIORITY, 10);
#else #else
shell = &_shell; shell = &_shell;
#endif tid = &finsh_thread;
memset(shell, 0, sizeof(struct finsh_shell));
rt_sem_init(&(shell->rx_sem), "shrx", 0, 0);
result = rt_thread_init(&finsh_thread, result = rt_thread_init(&finsh_thread,
FINSH_THREAD_NAME, FINSH_THREAD_NAME,
finsh_thread_entry, RT_NULL, finsh_thread_entry, RT_NULL,
&finsh_thread_stack[0], sizeof(finsh_thread_stack), &finsh_thread_stack[0], sizeof(finsh_thread_stack),
FINSH_THREAD_PRIORITY, 10); FINSH_THREAD_PRIORITY, 10);
#endif /* RT_USING_HEAP */
rt_sem_init(&(shell->rx_sem), "shrx", 0, 0);
if (result == RT_EOK) if (tid != NULL && result == RT_EOK)
rt_thread_startup(&finsh_thread); rt_thread_startup(tid);
return 0; return 0;
} }
INIT_APP_EXPORT(finsh_system_init); INIT_APP_EXPORT(finsh_system_init);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册