summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-03-10 14:42:28 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-03-10 14:42:28 +0000
commit506452c6fa4b7d408da0d332100f43a3102168ab (patch)
treebca4f4b7d50f699ff0c88572958ed38f6d747244
parentebc734d8e40e310bc94bd8321a70ce1b8ef5d5a9 (diff)
downloadnuttx-506452c6fa4b7d408da0d332100f43a3102168ab.tar.gz
nuttx-506452c6fa4b7d408da0d332100f43a3102168ab.tar.bz2
nuttx-506452c6fa4b7d408da0d332100f43a3102168ab.zip
add apps/ dir
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3360 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r--apps/Makefile122
-rw-r--r--apps/README62
-rw-r--r--apps/exec_nuttapp.c117
-rw-r--r--apps/exec_nuttapp_list.h2
-rw-r--r--apps/exec_nuttapp_proto.h2
-rw-r--r--apps/hello/Makefile103
-rw-r--r--apps/hello/hello.c47
-rw-r--r--nuttx/Makefile22
-rwxr-xr-xnuttx/configs/vsn/nsh/defconfig36
-rw-r--r--nuttx/examples/nsh/nsh_main.c33
-rw-r--r--nuttx/include/nuttx/nuttapp.h123
-rw-r--r--nuttx/sched/sched_waitpid.c8
12 files changed, 668 insertions, 9 deletions
diff --git a/apps/Makefile b/apps/Makefile
new file mode 100644
index 000000000..4bc1f90bc
--- /dev/null
+++ b/apps/Makefile
@@ -0,0 +1,122 @@
+############################################################################
+# apps/Makefile
+#
+# Copyright (C) 2011 Uros Platise. All rights reserved.
+# Author: Uros Platise <uros.platise@isotel.eu>
+# Gregory Nutt <spudmonkey@racsa.co.cr>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# 3. Neither the name NuttX nor the names of its contributors may be
+# used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+############################################################################
+
+-include $(TOPDIR)/Make.defs
+
+ifeq ($(WINTOOL),y)
+INCDIROPT = -w
+endif
+
+# Application Directories
+
+BUILTIN_APPS_DIR =
+BUILTIN_APPS_BUILT =
+
+ifeq ($(CONFIG_BUILTIN_APPS_NUTTX),y)
+
+
+# Individual application: HELLO
+
+ifeq ($(CONFIG_BUILTIN_APPS_HELLO),y)
+
+BUILTIN_APPS_DIR += hello
+
+# we use a non-existing .built_always to guarantee that Makefile
+# always walks into the sub-directories and asks for build
+BUILTIN_APPS_BUILT += hello/.built_always
+
+hello/libhello$(LIBEXT):
+ @$(MAKE) -C hello TOPDIR="$(TOPDIR)" libhello$(LIBEXT)
+
+endif
+
+# end of application list
+
+endif
+
+
+ROOTDEPPATH = --dep-path .
+ASRCS =
+CSRCS = exec_nuttapp.c
+
+AOBJS = $(ASRCS:.S=$(OBJEXT))
+COBJS = $(CSRCS:.c=$(OBJEXT))
+
+SRCS = $(ASRCS) $(CSRCS)
+OBJS = $(AOBJS) $(COBJS)
+
+BIN = libapps$(LIBEXT)
+
+VPATH =
+
+all: $(BIN)
+
+$(AOBJS): %$(OBJEXT): %.S
+ $(call ASSEMBLE, $<, $@)
+
+$(COBJS): %$(OBJEXT): %.c
+ $(call COMPILE, $<, $@)
+
+$(BUILTIN_APPS_BUILT):
+ @for dir in $(BUILTIN_APPS_DIR) ; do \
+ $(MAKE) -C $$dir TOPDIR="$(TOPDIR)" ; \
+ done
+
+$(BIN): $(OBJS) $(BUILTIN_APPS_BUILT)
+ @( for obj in $(OBJS) ; do \
+ $(call ARCHIVE, $@, $${obj}); \
+ done ; )
+
+.depend: Makefile $(SRCS)
+ @$(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
+
+depend: .depend
+
+clean:
+ @rm -f $(BIN) *~ .*.swp *.o libapps.a
+ $(call CLEAN)
+
+distclean: clean
+ @rm -f Make.dep .depend
+
+-include Make.dep
diff --git a/apps/README b/apps/README
new file mode 100644
index 000000000..61129e7d6
--- /dev/null
+++ b/apps/README
@@ -0,0 +1,62 @@
+
+Application Folder
+==================
+
+This folder provides various applications that can be enabled in the .config
+file and further provides frame-work to include external user applications
+from the ../apps directory.
+
+Application entry points with their requirements are gathered together in
+this folder, in two files:
+ - exec_nuttapp_proto.h Entry points, prototype function
+ - exec_nuttapp_list.h Application specific information and requirements
+
+Application information is collected during the make .depend process.
+
+To execute an application function:
+ exec_nuttapp() is defined in the include/nuttx/nuttapp.h
+
+Further, builtin applications may be accessed via pseudo file-system found
+under the nuttx/drivers/sbin directory.
+
+NuttShell provides transparent method of invoking the command, when the
+following option is enabled (regardless of sbin pseudo file system):
+ CONFIG_EXAMPLES_NSH_BUILTIN_APPS=y
+
+To select which application to be included in the build process set your
+preferences the .config file as:
+
+To include applications under the nuttx apps directory:
+ CONFIG_BUILTIN_APPS_NUTTX=y/n
+
+where each application can be controlled as:
+ CONFIG_BUILTIN_APPS_<NAME>=y/n
+
+To include applications under the user ../apps directory:
+ CONFIG_BUILTIN_APPS_USER=y/n
+
+When the user defines an option:
+ CONFIG_BUILTIN_APP_START=<application name>
+
+then after initialization of the NuttX OS it starts this application
+using the exec_nuttapp() method.
+
+Application skeleton can be found under the hello sub-directory,
+which shows how an application can be added to the project. One must
+define:
+ 1. create sub-directory as: appname
+ 2. provide entry point: appname_main()
+ 3. set the requirements in the file: Makefile, specially the lines:
+ APPNAME = appname
+ PRIORITY = SCHED_PRIORITY_DEFAULT
+ STACKSIZE = 768
+ ASRCS = asm source file list as a.asm b.asm ...
+ CSRCS = C source file list as foo1.c foo2.c ..
+
+ 4. add enable/disable option in the top file in this directory as:
+ ifeq CONFIG_BUILTIN_APPS_<NAME>
+ ...
+
+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
new file mode 100644
index 000000000..658cbf07f
--- /dev/null
+++ b/apps/exec_nuttapp.c
@@ -0,0 +1,117 @@
+/****************************************************************************
+ * drivers/sbin/exec_nuttapp.c
+ *
+ * Copyright (C) 2011 Uros Platise. All rights reserved.
+ * Author: Uros Platise <uros.platise@isotel.eu>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/nuttapp.h>
+#include <sched.h>
+
+#include <string.h>
+#include <errno.h>
+
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* Load builtin function prototypes */
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+#include "exec_nuttapp_proto.h"
+
+static const struct nuttapp_s nuttapps[] = {
+# include "exec_nuttapp_list.h"
+ {.name=NULL}
+};
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+int exec_nuttapp(FAR const char *appname, FAR const char *argv[])
+{
+ int i, ret = ERROR;
+
+ // 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 ( !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]);
+#else
+ ret = task_create(nuttapps[i].name, nuttapps[i].priority, nuttapps[i].main, &argv[1]);
+#endif
+ return ret;
+ }
+ }
+ errno = ENOENT;
+ return ret;
+}
diff --git a/apps/exec_nuttapp_list.h b/apps/exec_nuttapp_list.h
new file mode 100644
index 000000000..e8e4424ad
--- /dev/null
+++ b/apps/exec_nuttapp_list.h
@@ -0,0 +1,2 @@
+/* List of application requirements, generated during make depend. */
+{ .name = "hello", .priority = SCHED_PRIORITY_DEFAULT, .stacksize = 768, .main = hello_main },
diff --git a/apps/exec_nuttapp_proto.h b/apps/exec_nuttapp_proto.h
new file mode 100644
index 000000000..2c9c65ec9
--- /dev/null
+++ b/apps/exec_nuttapp_proto.h
@@ -0,0 +1,2 @@
+/* List of application entry points, generated during make depend. */
+EXTERN int hello_main(int argc, char *argv[]);
diff --git a/apps/hello/Makefile b/apps/hello/Makefile
new file mode 100644
index 000000000..f4267cd4d
--- /dev/null
+++ b/apps/hello/Makefile
@@ -0,0 +1,103 @@
+############################################################################
+# Makefile
+#
+# Copyright (C) 2011 Uros Platise. All rights reserved.
+# Author: Uros Platise <uros.platise@isotel.eu>
+# Gregory Nutt <spudmonkey@racsa.co.cr>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# 3. Neither the name NuttX nor the names of its contributors may be
+# used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+############################################################################
+
+# TODO, this makefile should run make under the app dirs, instead of
+# sourcing the Make.defs!
+
+-include $(TOPDIR)/Make.defs
+
+ifeq ($(WINTOOL),y)
+INCDIROPT = -w
+endif
+
+# Hello Application
+# TODO: appname can be automatically extracted from the directory name
+
+APPNAME = hello
+PRIORITY = SCHED_PRIORITY_DEFAULT
+STACKSIZE = 768
+
+ASRCS =
+CSRCS = hello.c
+
+AOBJS = $(ASRCS:.S=$(OBJEXT))
+COBJS = $(CSRCS:.c=$(OBJEXT))
+
+SRCS = $(ASRCS) $(CSRCS)
+OBJS = $(AOBJS) $(COBJS)
+
+BIN = ../libapps$(LIBEXT)
+
+ROOTDEPPATH = --dep-path .
+
+# Common build
+
+VPATH =
+
+all: .built
+
+$(AOBJS): %$(OBJEXT): %.S
+ $(call ASSEMBLE, $<, $@)
+
+$(COBJS): %$(OBJEXT): %.c
+ $(call COMPILE, $<, $@)
+
+$(BIN): $(OBJS)
+ @( for obj in $(OBJS) ; do \
+ $(call ARCHIVE, $@, $${obj}); \
+ done ; )
+ @touch .built
+
+.built: $(BIN)
+
+.depend: Makefile $(SRCS)
+ @$(MKDEP) $(ROOTDEPPATH) \
+ $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
+ @touch $@
+ echo "{ .name = \""$(APPNAME)"\", .priority = "$(PRIORITY)", .stacksize = "$(STACKSIZE)", .main = "$(APPNAME)"_main }," >> ../exec_nuttapp_list.h
+ echo "EXTERN int "$(APPNAME)"_main(int argc, char *argv[]);" >> ../exec_nuttapp_proto.h
+
+# Register application
+depend: .depend
+
+clean:
+ @rm -f $(BIN) *.o *~ .*.swp .built
+ $(call CLEAN)
+
+distclean: clean
+ @rm -f Make.dep .depend
+
+-include Make.dep
diff --git a/apps/hello/hello.c b/apps/hello/hello.c
new file mode 100644
index 000000000..d7818d351
--- /dev/null
+++ b/apps/hello/hello.c
@@ -0,0 +1,47 @@
+/****************************************************************************
+ * hello/hello.c
+ *
+ * Copyright (C) 2011 Uros Platise. All rights reserved.
+ * Author: Uros Platise <uros.platise@isotel.eu>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+#include <stdio.h>
+
+
+/** Example of a standalone application
+ */
+int hello_main(int argc, char *argv[])
+{
+ int i;
+ printf("Hello Builtin Application\nFound argc=%d arguments and are as follows:\n", argc);
+ for (i=0; i<argc; i++) printf("%s\n", argv[i]);
+ return 0;
+}
diff --git a/nuttx/Makefile b/nuttx/Makefile
index 231173a21..4c44492b6 100644
--- a/nuttx/Makefile
+++ b/nuttx/Makefile
@@ -59,11 +59,16 @@ ARCH_SRC = $(ARCH_DIR)/src
ARCH_INC = $(ARCH_DIR)/include
BOARD_DIR = configs/$(CONFIG_ARCH_BOARD)
+# This can be over-ridden from the command line:
+
+APPS_LOC = ../apps
+
# Add-on directories. These may or may not be in place in the
# NuttX source tree (they must be specifically installed)
+APPS_DIR := ${shell if [ -r $(APPS_LOC)/Makefile ]; then echo "$(APPS_LOC)"; fi}
PCODE_DIR := ${shell if [ -r pcode/Makefile ]; then echo "pcode"; fi}
-ADDON_DIRS := $(PCODE_DIR) $(NX_DIR)
+ADDON_DIRS := $(PCODE_DIR) $(NX_DIR) $(APPS_DIR)
# FSDIRS depend on file descriptor support; NONFSDIRS do not
# (except for parts of FSDIRS). We will exclude FSDIRS
@@ -127,6 +132,18 @@ ifeq ($(CONFIG_HAVE_CXX),y)
LINKLIBS += libxx/liblibxx$(LIBEXT)
endif
+# Add library for application support
+# Always compile the framework which includes exec_nuttapp if users
+# or nuttX applications are to be included.
+
+ifeq ($(CONFIG_BUILTIN_APPS_NUTTX),y)
+LINKLIBS += $(APPS_DIR)/libapps$(LIBEXT)
+else
+ifeq ($(CONFIG_BUILTIN_APPS_USER),y)
+LINKLIBS += $(APPS_DIR)/libapps$(LIBEXT)
+endif
+endif
+
# Add libraries for network support
ifeq ($(CONFIG_NET),y)
@@ -249,6 +266,9 @@ fs/libfs$(LIBEXT): context
drivers/libdrivers$(LIBEXT): context
@$(MAKE) -C drivers TOPDIR="$(TOPDIR)" libdrivers$(LIBEXT)
+$(APPS_DIR)/libapps$(LIBEXT): context
+ @$(MAKE) -C $(APPS_DIR) TOPDIR="$(TOPDIR)" libapps$(LIBEXT)
+
binfmt/libbinfmt$(LIBEXT): context
@$(MAKE) -C binfmt TOPDIR="$(TOPDIR)" libbinfmt$(LIBEXT)
diff --git a/nuttx/configs/vsn/nsh/defconfig b/nuttx/configs/vsn/nsh/defconfig
index 7842e5213..8e74c4c58 100755
--- a/nuttx/configs/vsn/nsh/defconfig
+++ b/nuttx/configs/vsn/nsh/defconfig
@@ -336,7 +336,7 @@ CONFIG_MM_REGIONS=1
CONFIG_ARCH_LOWPUTC=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_INSTRUMENTATION=n
-CONFIG_TASK_NAME_SIZE=0
+CONFIG_TASK_NAME_SIZE=16
CONFIG_START_YEAR=2009
CONFIG_START_MONTH=9
CONFIG_START_DAY=21
@@ -754,6 +754,7 @@ CONFIG_EXAMPLES_NSH_FATSECTSIZE=512
CONFIG_EXAMPLES_NSH_FATNSECTORS=40
CONFIG_EXAMPLES_NSH_FATMOUNTPT=/tmp
+
#
# Architecture-specific NSH options
#
@@ -817,3 +818,36 @@ CONFIG_PTHREAD_STACK_MIN=256
CONFIG_PTHREAD_STACK_DEFAULT=2048
CONFIG_HEAP_BASE=
CONFIG_HEAP_SIZE=
+
+
+########################################################################
+#
+# Applications to be included within the NuttX binary as described
+# under the apps/README.txt
+#
+# Set this config parameter above to: CONFIG_TASK_NAME_SIZE=16
+# in order to enable argv[0]=<task name> argument. Otherwise argv[0]
+# will be noname.
+#
+# Include builtin NuttX application (disabling this option will
+# exclude all of the apps found under the nuttx/apps directory, but
+# not the apps found under the ../apps directory unless _APPS_USER=n.
+CONFIG_BUILTIN_APPS_NUTTX=y
+
+# Individual selection of built-in applications:
+CONFIG_BUILTIN_APPS_HELLO=y
+
+# Include user (external) applications located under ../apps directory?
+CONFIG_BUILTIN_APPS_USER=y
+
+# Invoke the following application after NuttX starts
+# (enter app name, as: hello)
+CONFIG_BUILTIN_APP_START=
+
+# CONFIG_EXAMPLES_NSH_BUILTIN_APPS - Support for running the builtin
+# apps from command line. See apps/README for more information.
+#
+CONFIG_EXAMPLES_NSH_BUILTIN_APPS=y
+
+#
+########################################################################
diff --git a/nuttx/examples/nsh/nsh_main.c b/nuttx/examples/nsh/nsh_main.c
index 9981ad073..a13c6dae0 100644
--- a/nuttx/examples/nsh/nsh_main.c
+++ b/nuttx/examples/nsh/nsh_main.c
@@ -55,6 +55,10 @@
# include <pthread.h>
#endif
+#ifdef CONFIG_EXAMPLES_NSH_BUILTIN_APPS
+# include <nuttx/nuttapp.h>
+#endif
+
#include "nsh.h"
/****************************************************************************
@@ -487,6 +491,35 @@ static int nsh_execute(FAR struct nsh_vtbl_s *vtbl, int argc, char *argv[])
}
}
+#ifdef CONFIG_EXAMPLES_NSH_BUILTIN_APPS
+ if (handler == cmd_unrecognized)
+ {
+ /* Try to find command within pre-built application list. */
+
+ if ((ret = exec_nuttapp(cmd, argv)) < 0)
+ {
+ if (errno != ENOENT)
+ {
+ return -errno;
+ }
+ }
+ else
+ {
+ /* Is the background mode or foreground mode desired? */
+#if 0
+ if (argc > 1 && strcmp(argv[argc-1], "&") == 0)
+ {
+ }
+ else
+ {
+ waitpid(ret, );
+ }
+#endif
+ return ret;
+ }
+ }
+#endif
+
ret = handler(vtbl, argc, argv);
return ret;
}
diff --git a/nuttx/include/nuttx/nuttapp.h b/nuttx/include/nuttx/nuttapp.h
new file mode 100644
index 000000000..a8b6e8397
--- /dev/null
+++ b/nuttx/include/nuttx/nuttapp.h
@@ -0,0 +1,123 @@
+/****************************************************************************
+ * include/nuttx/nuttapp.h
+ *
+ * Copyright(C) 2011 Uros Platise. All rights reserved.
+ * Author: Uros Platise <uros.platise@isotel.eu>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+#ifndef __NUTTX_NUTTAPP_H
+#define __NUTTX_NUTTAPP_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <sys/types.h>
+#include <stdint.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+struct nuttapp_s
+{
+ const char *name; /* Invocation name and as seen under /sbin/ */
+ int priority; /* Use: SCHED_PRIORITY_DEFAULT */
+ int stacksize; /* Desired stack size */
+ main_t main; /* Entry point: main(int argc, char *argv[]) */
+};
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Name: execute builtin NuttX application
+ *
+ * Description:
+ * Executes builtin application registerred during compile time.
+ * New application is run in a separate task context (and thread).
+ *
+ * Input Parameter:
+ * filename - Name of the linked-in binary to be started.
+ * argv - Argument list
+ *
+ * Returned Value:
+ * This is an end-user function, so it follows the normal convention:
+ * 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)
+}
+#endif
+#endif /* __NUTTX_NUTAPP_H */
diff --git a/nuttx/sched/sched_waitpid.c b/nuttx/sched/sched_waitpid.c
index 6e544f2eb..a1af343e1 100644
--- a/nuttx/sched/sched_waitpid.c
+++ b/nuttx/sched/sched_waitpid.c
@@ -195,12 +195,6 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options)
/* None of the options are supported */
#ifdef CONFIG_DEBUG
- if (stat_loc == NULL)
- {
- err = EINVAL;
- goto errout_with_errno;
- }
-
if (options != 0)
{
err = ENOSYS;
@@ -214,7 +208,7 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options)
* others?
*/
- if (tcb->stat_loc == NULL)
+ if (stat_loc != NULL && tcb->stat_loc == NULL)
{
tcb->stat_loc = stat_loc;
mystat = true;