From 6fafa11958163e847fa0ea15f870ae20ed6630d2 Mon Sep 17 00:00:00 2001 From: patacongo Date: Fri, 11 Mar 2011 12:36:30 +0000 Subject: [PATCH] apps/-related updates git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@3364 7fd9a85b-ad96-42d3-883c-3090e2eb8679 --- apps/Makefile | 4 +- apps/README | 6 +-- apps/exec_nuttapp.c | 44 ++++++++++++---- nuttx/arch/x86/src/common/up_initialize.c | 2 +- nuttx/configs/vsn/nsh/defconfig | 1 + nuttx/examples/nsh/nsh_main.c | 35 ++++++++----- nuttx/include/nuttx/nuttapp.h | 62 ++++++++++++++--------- 7 files changed, 98 insertions(+), 56 deletions(-) diff --git a/apps/Makefile b/apps/Makefile index 0deb46e9c..4ffca6343 100644 --- a/apps/Makefile +++ b/apps/Makefile @@ -97,11 +97,11 @@ $(BIN): $(OBJS) $(BUILTIN_APPS_BUILT) done ; ) .depend: Makefile $(SRCS) + @echo "/* List of application requirements, generated during make depend. */" > exec_nuttapp_list.h + @echo "/* List of application entry points, generated during make depend. */" > exec_nuttapp_proto.h @$(MKDEP) $(ROOTDEPPATH) \ $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep @touch $@ - echo "/* List of application requirements, generated during make depend. */" > exec_nuttapp_list.h - echo "/* List of application entry points, generated during make depend. */" > exec_nuttapp_proto.h @for dir in $(BUILTIN_APPS_DIR) ; do \ $(MAKE) -C $$dir TOPDIR="$(TOPDIR)" depend ; \ done diff --git a/apps/README b/apps/README index 61129e7d6..4ffee90c8 100644 --- a/apps/README +++ b/apps/README @@ -35,7 +35,7 @@ where each application can be controlled as: To include applications under the user ../apps directory: CONFIG_BUILTIN_APPS_USER=y/n -When the user defines an option: +When the user defines an option: (NOT IMPLEMENTED YET) CONFIG_BUILTIN_APP_START= then after initialization of the NuttX OS it starts this application @@ -56,7 +56,3 @@ define: 4. add enable/disable option in the top file in this directory as: ifeq CONFIG_BUILTIN_APPS_ ... - -To include user (external) application create an application under -../apps directory and steps 1. - 3. The last 4. step is not needed, as, -all applications under ../apps becomes a part of the build process. diff --git a/apps/exec_nuttapp.c b/apps/exec_nuttapp.c index 658cbf07f..4550de27e 100644 --- a/apps/exec_nuttapp.c +++ b/apps/exec_nuttapp.c @@ -91,27 +91,49 @@ static const struct nuttapp_s nuttapps[] = { * Public Functions ****************************************************************************/ + +const char * nuttapp_getname(int index) +{ + if ( index < 0 || index >= (sizeof(nuttapps)/sizeof(struct nuttapp_s)) ) + return NULL; + + return nuttapps[index].name; +} + + +int nuttapp_isavail(FAR const char *appname) +{ + int i; + + for (i=0; nuttapps[i].name; i++) + { + if ( !strcmp(nuttapps[i].name, appname) ) + return i; + } + + errno = ENOENT; + return -1; +} + + int exec_nuttapp(FAR const char *appname, FAR const char *argv[]) { - int i, ret = ERROR; + int i; // Not sure what to do with exports and nexports ... as found in exec // FAR const struct symtab_s *exports, int nexports // so they are ommited in the args list. - for (i=0; nuttapps[i].name; i++) + if ( (i = nuttapp_isavail(appname)) >= 0 ) { - if ( !strcmp(nuttapps[i].name, appname) ) - { #ifndef CONFIG_CUSTOM_STACK - ret = task_create(nuttapps[i].name, nuttapps[i].priority, - nuttapps[i].stacksize, nuttapps[i].main, &argv[1]); + i = task_create(nuttapps[i].name, nuttapps[i].priority, + nuttapps[i].stacksize, nuttapps[i].main, &argv[1]); #else - ret = task_create(nuttapps[i].name, nuttapps[i].priority, nuttapps[i].main, &argv[1]); + i = task_create(nuttapps[i].name, nuttapps[i].priority, nuttapps[i].main, &argv[1]); #endif - return ret; - } + return i; } - errno = ENOENT; - return ret; + + return i; } diff --git a/nuttx/arch/x86/src/common/up_initialize.c b/nuttx/arch/x86/src/common/up_initialize.c index 9ce9523ed..0ceeddbb6 100644 --- a/nuttx/arch/x86/src/common/up_initialize.c +++ b/nuttx/arch/x86/src/common/up_initialize.c @@ -124,7 +124,7 @@ void up_initialize(void) up_irqinitialize(); - /* Initialize the DMA subsystem if the weak function stm32_dmainitialize has been + /* Initialize the DMA subsystem if the weak function up_dmainitialize has been * brought into the build */ diff --git a/nuttx/configs/vsn/nsh/defconfig b/nuttx/configs/vsn/nsh/defconfig index 8e74c4c58..2d3e5b2b3 100755 --- a/nuttx/configs/vsn/nsh/defconfig +++ b/nuttx/configs/vsn/nsh/defconfig @@ -848,6 +848,7 @@ CONFIG_BUILTIN_APP_START= # apps from command line. See apps/README for more information. # CONFIG_EXAMPLES_NSH_BUILTIN_APPS=y +CONFIG_SCHED_WAITPID=y # ######################################################################## diff --git a/nuttx/examples/nsh/nsh_main.c b/nuttx/examples/nsh/nsh_main.c index a13c6dae0..84ef2bdfd 100644 --- a/nuttx/examples/nsh/nsh_main.c +++ b/nuttx/examples/nsh/nsh_main.c @@ -499,23 +499,23 @@ static int nsh_execute(FAR struct nsh_vtbl_s *vtbl, int argc, char *argv[]) if ((ret = exec_nuttapp(cmd, argv)) < 0) { if (errno != ENOENT) - { - return -errno; + { + return -errno; } } else { - /* Is the background mode or foreground mode desired? */ -#if 0 - if (argc > 1 && strcmp(argv[argc-1], "&") == 0) - { - } - else - { - waitpid(ret, ); - } +#ifdef CONFIG_SCHED_WAITPID + if (vtbl->np.np_bg == false) + { + waitpid(ret, NULL, 0); + } + else #endif - return ret; + { + nsh_output(vtbl, "%s [%d:%d]\n", cmd, ret, 128); // \todo get priority from new pid? + return ret; + } } } #endif @@ -1176,6 +1176,7 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline) } #endif + /* Check if the output was re-directed using > or >> */ if (argc > 2) @@ -1229,10 +1230,16 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline) nsh_output(vtbl, g_fmttoomanyargs, cmd); } - /* Handle the case where the command is executed in background */ + /* Handle the case where the command is executed in background. + * However is app is to be started as nuttapp new process will + * be created anyway, so skip this step. */ #ifndef CONFIG_EXAMPLES_NSH_DISABLEBG - if (vtbl->np.np_bg) + if (vtbl->np.np_bg +#ifdef CONFIG_EXAMPLES_NSH_BUILTIN_APPS + && nuttapp_isavail(argv[0]) < 0 +#endif + ) { struct sched_param param; struct nsh_vtbl_s *bkgvtbl; diff --git a/nuttx/include/nuttx/nuttapp.h b/nuttx/include/nuttx/nuttapp.h index a8b6e8397..1d6497283 100644 --- a/nuttx/include/nuttx/nuttapp.h +++ b/nuttx/include/nuttx/nuttapp.h @@ -72,6 +72,45 @@ extern "C" { #define EXTERN extern #endif + +/**************************************************************************** + * Name: check for availability of builtin NuttX application + * + * Description: + * Checks for availabiliy of application registerred during compile time. + * + * Input Parameter: + * filename - Name of the linked-in binary to be started. + * + * Returned Value: + * This is an end-user function, so it follows the normal convention: + * Returns index of builtin application. If it is not found then it + * returns -1 (ERROR) and sets errno appropriately. + * + ****************************************************************************/ + +EXTERN int nuttapp_isavail(FAR const char *appname); + + +/**************************************************************************** + * Name: get name of built-in application + * + * Description: + * Returns pointer to a name of built-in application pointed by the + * index. + * + * Input Parameter: + * index, from 0 and on ... + * + * Returned Value: + * Returns valid pointer pointing to the app name if index is valid. + * Otherwise NULL is returned. + * + ****************************************************************************/ + +EXTERN const char * nuttapp_getname(int index); + + /**************************************************************************** * Name: execute builtin NuttX application * @@ -88,33 +127,10 @@ extern "C" { * Returns the PID of the exec'ed module. On failure, it.returns * -1 (ERROR) and sets errno appropriately. * - * Implementation within drivers/bchsbin ****************************************************************************/ EXTERN int exec_nuttapp(FAR const char *appname, FAR const char *argv[]); -/**************************************************************************** - * Name: execute a nutt shell command - * - * Description: - * Invokes an application that is either: - * - invokes a nsh script or directly invoke: - * - system application list, registerred via XXXX - * - resides in a file system compiled/linked in NXFLAT model - * - resides in a non-executable file-system, which is loaded - * into the memory first and then executed. - * - * Input Parameter: - * Sheel command. - * - * Returned Value: - * Zero on success or -1 on error with errno set. - * - * TODO: move this command to the stdlib.h (?) and - * merge implementation with the nuttshell sh command - ****************************************************************************/ - -EXTERN FAR int system(const char *command); #undef EXTERN #if defined(__cplusplus)