summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarmink <[email protected]>2018-04-23 13:28:44 +0800
committerarmink <[email protected]>2018-04-23 13:28:44 +0800
commit72ec60aaa36c9e942825fb755cb307705ce6a6bc (patch)
treee3cd56e36e0647b4d0936b0ca3b39bc3a415f61c
parent7c97e16ecf8d7f384206a324f443843ba09cf9f4 (diff)
[components][finsh] Finsh thread using heap when RT_USING_HEAP is defined.
-rw-r--r--components/finsh/shell.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/components/finsh/shell.c b/components/finsh/shell.c
index ea68a57ffa..6bdb418120 100644
--- a/components/finsh/shell.c
+++ b/components/finsh/shell.c
@@ -50,9 +50,11 @@
#endif
/* finsh thread */
+#ifndef RT_USING_HEAP
static struct rt_thread finsh_thread;
ALIGN(RT_ALIGN_SIZE)
static char finsh_thread_stack[FINSH_THREAD_STACK_SIZE];
+#endif
struct finsh_shell *shell;
#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 =
*/
int finsh_system_init(void)
{
- rt_err_t result;
+ rt_err_t result = RT_EOK;
+ rt_thread_t tid;
#ifdef FINSH_USING_SYMTAB
#ifdef __CC_ARM /* ARM C Compiler */
@@ -764,29 +767,31 @@ int finsh_system_init(void)
#endif
#endif
- /* create or set shell structure */
#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)
{
rt_kprintf("no memory for shell\n");
return -1;
}
+ tid = rt_thread_create(FINSH_THREAD_NAME,
+ finsh_thread_entry, RT_NULL,
+ FINSH_THREAD_STACK_SIZE, FINSH_THREAD_PRIORITY, 10);
#else
shell = &_shell;
-#endif
-
- memset(shell, 0, sizeof(struct finsh_shell));
-
- rt_sem_init(&(shell->rx_sem), "shrx", 0, 0);
+ tid = &finsh_thread;
result = rt_thread_init(&finsh_thread,
FINSH_THREAD_NAME,
finsh_thread_entry, RT_NULL,
&finsh_thread_stack[0], sizeof(finsh_thread_stack),
FINSH_THREAD_PRIORITY, 10);
+#endif /* RT_USING_HEAP */
+
+ rt_sem_init(&(shell->rx_sem), "shrx", 0, 0);
- if (result == RT_EOK)
- rt_thread_startup(&finsh_thread);
+ if (tid != NULL && result == RT_EOK)
+ rt_thread_startup(tid);
return 0;
}
INIT_APP_EXPORT(finsh_system_init);