diff --git a/components/finsh/SConscript b/components/finsh/SConscript index 3fd0961f72..80c53bfc61 100644 --- a/components/finsh/SConscript +++ b/components/finsh/SConscript @@ -2,13 +2,43 @@ Import('rtconfig') from building import * cwd = GetCurrentDir() -src = Glob('*.c') +src = Split(''' +shell.c +symbol.c +cmd.c +''') + +fsh_src = Split(''' +finsh_compiler.c +finsh_error.c +finsh_heap.c +finsh_init.c +finsh_node.c +finsh_ops.c +finsh_parser.c +finsh_var.c +finsh_vm.c +finsh_token.c +''') + +msh_src = Split(''' +msh_cmd.c +msh.c +''') + CPPPATH = [cwd] if rtconfig.CROSS_TOOL == 'keil': - LINKFLAGS = ' --keep __fsym_* --keep __vsym_* ' + LINKFLAGS = ' --keep __fsym_*' + + if not GetDepend('FINSH_USING_MSH_ONLY'): + LINKFLAGS = LINKFLAGS + ' --keep __vsym_* ' else: LINKFLAGS = '' +src = src + msh_src +if not GetDepend('FINSH_USING_MSH_ONLY'): + src = src + fsh_src + group = DefineGroup('finsh', src, depend = ['RT_USING_FINSH'], CPPPATH = CPPPATH, LINKFLAGS = LINKFLAGS) Return('group') diff --git a/components/finsh/cmd.c b/components/finsh/cmd.c index 00dc384a1e..2a8a884251 100644 --- a/components/finsh/cmd.c +++ b/components/finsh/cmd.c @@ -612,9 +612,11 @@ FINSH_FUNCTION_EXPORT(list_mod_detail, list module objects in system) long list(void) { +#ifndef FINSH_USING_MSH_ONLY struct finsh_syscall_item *syscall_item; struct finsh_sysvar_item *sysvar_item; - +#endif + rt_kprintf("--Function List:\n"); { struct finsh_syscall *index; @@ -633,6 +635,7 @@ long list(void) } } +#ifndef FINSH_USING_MSH_ONLY /* list syscall list */ syscall_item = global_syscall_list; while (syscall_item != NULL) @@ -662,11 +665,13 @@ long list(void) rt_kprintf("[l] %s\n", sysvar_item->sysvar.name); sysvar_item = sysvar_item->next; } - +#endif + return 0; } FINSH_FUNCTION_EXPORT(list, list all symbol in system) +#ifndef FINSH_USING_MSH_ONLY static int str_is_prefix(const char *prefix, const char *str) { while ((*prefix) && (*prefix == *str)) @@ -865,8 +870,9 @@ void list_prefix(char *prefix) rt_strncpy(prefix, name_ptr, min_length); } } +#endif -#ifdef FINSH_USING_SYMTAB +#if defined(FINSH_USING_SYMTAB) && !defined(FINSH_USING_MSH_ONLY) static int dummy = 0; FINSH_VAR_EXPORT(dummy, finsh_type_int, dummy variable for finsh) #endif diff --git a/components/finsh/msh.c b/components/finsh/msh.c index a100b3d60d..c8fe2dc390 100644 --- a/components/finsh/msh.c +++ b/components/finsh/msh.c @@ -35,6 +35,12 @@ typedef int (*cmd_function_t)(int argc, char** argv); #ifdef FINSH_USING_MSH +#ifdef FINSH_USING_MSH_ONLY +rt_bool_t msh_is_used(void) +{ + return RT_TRUE; +} +#else #ifdef FINSH_USING_MSH_DEFAULT static rt_bool_t __msh_state = RT_TRUE; #else @@ -61,6 +67,7 @@ static int msh_enter(void) return 0; } FINSH_FUNCTION_EXPORT_ALIAS(msh_enter, msh, use module shell); +#endif int msh_help(int argc, char** argv) { diff --git a/components/finsh/shell.c b/components/finsh/shell.c index b643702620..874ce559be 100644 --- a/components/finsh/shell.c +++ b/components/finsh/shell.c @@ -183,7 +183,6 @@ rt_uint32_t finsh_get_echo() static void shell_auto_complete(char* prefix) { - extern void list_prefix(char* prefix); rt_kprintf("\n"); #ifdef FINSH_USING_MSH @@ -194,12 +193,16 @@ static void shell_auto_complete(char* prefix) else #endif { +#ifndef FINSH_USING_MSH_ONLY + extern void list_prefix(char* prefix); list_prefix(prefix); +#endif } rt_kprintf("%s%s", FINSH_PROMPT, prefix); } +#ifndef FINSH_USING_MSH_ONLY void finsh_run_line(struct finsh_parser* parser, const char *line) { const char* err_str; @@ -242,6 +245,7 @@ void finsh_run_line(struct finsh_parser* parser, const char *line) finsh_flush(parser); } +#endif #ifdef FINSH_USING_HISTORY static rt_bool_t shell_handle_history(struct finsh_shell* shell) @@ -304,7 +308,9 @@ void finsh_thread_entry(void* parameter) /* normal is echo mode */ shell->echo_mode = 1; +#ifndef FINSH_USING_MSH_ONLY finsh_init(&shell->parser); +#endif rt_kprintf(FINSH_PROMPT); /* set console device as shell device */ @@ -480,33 +486,31 @@ void finsh_thread_entry(void* parameter) /* handle end of line, break */ if (ch == '\r' || ch == '\n') { -#ifdef FINSH_USING_MSH - if (msh_is_used() == RT_TRUE && shell->line_position != 0) + #ifdef FINSH_USING_HISTORY + shell_push_history(shell); + #endif + + #ifdef FINSH_USING_MSH + if (msh_is_used() == RT_TRUE) { rt_kprintf("\n"); - #ifdef FINSH_USING_HISTORY - shell_push_history(shell); - #endif msh_exec(shell->line, shell->line_position); } else -#endif + #endif { + #ifndef FINSH_USING_MSH_ONLY /* add ';' and run the command line */ shell->line[shell->line_position] = ';'; - #ifdef FINSH_USING_HISTORY - shell_push_history(shell); - #endif - if (shell->line_position != 0) finsh_run_line(&shell->parser, shell->line); else rt_kprintf("\n"); + #endif } rt_kprintf(FINSH_PROMPT); memset(shell->line, 0, sizeof(shell->line)); shell->line_curpos = shell->line_position = 0; - break; } @@ -605,7 +609,9 @@ int finsh_system_init(void) extern const int VSymTab$$Base; extern const int VSymTab$$Limit; finsh_system_function_init(&FSymTab$$Base, &FSymTab$$Limit); + #ifndef FINSH_USING_MSH_ONLY finsh_system_var_init(&VSymTab$$Base, &VSymTab$$Limit); + #endif #elif defined (__ICCARM__) /* for IAR Compiler */ finsh_system_function_init(__section_begin("FSymTab"), __section_end("FSymTab")); @@ -638,15 +644,17 @@ int finsh_system_init(void) /* create or set shell structure */ #ifdef RT_USING_HEAP shell = (struct finsh_shell*)rt_malloc(sizeof(struct finsh_shell)); -#else - shell = &_shell; -#endif if (shell == RT_NULL) { rt_kprintf("no memory for shell\n"); return -1; } - +#else + shell = &_shell; +#endif + + rt_kprintf("shell tcb size: %d\n", sizeof(struct finsh_shell)); + memset(shell, 0, sizeof(struct finsh_shell)); rt_sem_init(&(shell->rx_sem), "shrx", 0, 0); diff --git a/components/finsh/shell.h b/components/finsh/shell.h index 7736aa4921..9065f2f5ef 100644 --- a/components/finsh/shell.h +++ b/components/finsh/shell.h @@ -77,7 +77,9 @@ struct finsh_shell char cmd_history[FINSH_HISTORY_LINES][FINSH_CMD_SIZE]; #endif +#ifndef FINSH_USING_MSH_ONLY struct finsh_parser parser; +#endif char line[FINSH_CMD_SIZE]; rt_uint8_t line_position;