summaryrefslogtreecommitdiff
path: root/nuttx/examples
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2009-06-16 22:08:59 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2009-06-16 22:08:59 +0000
commit731994d0383c636e43644c3dc91b91b15745b345 (patch)
tree34e83135dc0e7f8f211822a1350250000701c7cb /nuttx/examples
parent50b481d7aad72088a44da871bb7df4865e5afeb9 (diff)
downloadpx4-nuttx-731994d0383c636e43644c3dc91b91b15745b345.tar.gz
px4-nuttx-731994d0383c636e43644c3dc91b91b15745b345.tar.bz2
px4-nuttx-731994d0383c636e43644c3dc91b91b15745b345.zip
Added NXFLAT a bit at a time
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1889 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/examples')
-rw-r--r--nuttx/examples/nxflat/nxflat.ld172
-rw-r--r--nuttx/examples/nxflat/tests/Make.defs45
-rw-r--r--nuttx/examples/nxflat/tests/Makefile55
-rw-r--r--nuttx/examples/nxflat/tests/errno/Makefile58
-rw-r--r--nuttx/examples/nxflat/tests/errno/errno.c83
-rw-r--r--nuttx/examples/nxflat/tests/errno/errno.obin0 -> 3708 bytes
-rw-r--r--nuttx/examples/nxflat/tests/hello++/Makefile114
-rw-r--r--nuttx/examples/nxflat/tests/hello++/hello++1.cpp60
-rw-r--r--nuttx/examples/nxflat/tests/hello++/hello++2.cpp123
-rw-r--r--nuttx/examples/nxflat/tests/hello++/hello++3.cpp132
-rw-r--r--nuttx/examples/nxflat/tests/hello++/hello++4.cpp150
-rw-r--r--nuttx/examples/nxflat/tests/hello/Makefile58
-rw-r--r--nuttx/examples/nxflat/tests/hello/hello.c89
-rw-r--r--nuttx/examples/nxflat/tests/hello/hello.obin0 -> 3456 bytes
-rw-r--r--nuttx/examples/nxflat/tests/longjmp/Makefile58
-rw-r--r--nuttx/examples/nxflat/tests/longjmp/longjmp.c128
-rw-r--r--nuttx/examples/nxflat/tests/mutex/Makefile58
-rw-r--r--nuttx/examples/nxflat/tests/mutex/mutex.c135
-rw-r--r--nuttx/examples/nxflat/tests/pthread/Makefile58
-rw-r--r--nuttx/examples/nxflat/tests/pthread/pthread.c136
-rw-r--r--nuttx/examples/nxflat/tests/signal/Makefile58
-rw-r--r--nuttx/examples/nxflat/tests/signal/signal.c296
-rw-r--r--nuttx/examples/nxflat/tests/task/Makefile59
-rw-r--r--nuttx/examples/nxflat/tests/task/task.c124
24 files changed, 2249 insertions, 0 deletions
diff --git a/nuttx/examples/nxflat/nxflat.ld b/nuttx/examples/nxflat/nxflat.ld
new file mode 100644
index 000000000..9a59c0ec0
--- /dev/null
+++ b/nuttx/examples/nxflat/nxflat.ld
@@ -0,0 +1,172 @@
+/****************************************************************************
+ * examples/nxflat/nxflat.ld
+ *
+ * Copyright (C) 2009 Gregory Nutt. All rights reserved.
+ * Author: 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.
+ *
+ ****************************************************************************/
+
+MEMORY
+{
+ ISPACE : ORIGIN = 0x0, LENGTH = 2097152
+ DSPACE : ORIGIN = 0x0, LENGTH = 2097152
+}
+
+/****************************************************************************
+ * The XFLAT program image is divided into two segments:
+ *
+ * (1) ISpace (Instruction Space). This is the segment that contains
+ * code (.text). Everything in the segment should be fetch-able
+ * machine PC instructions (jump, branch, call, etc.).
+ * (2) DSpace (Data Space). This is the segment that contains both
+ * read-write data (.data, .bss) as well as read-only data (.rodata).
+ * Everything in this segment should be access-able with machine
+ * with machine load and store instructions.
+ ****************************************************************************/
+
+SECTIONS
+{
+ .text 0x00000000 :
+ {
+ /* ISpace is located at address 0. Every (unrelocated) ISpace
+ * address is an offset from the begining of this segment.
+ */
+
+ text_start = . ;
+
+ *(.text)
+ *(.text.*)
+ *(.gnu.warning)
+ *(.stub)
+ *(.glue_7)
+ *(.glue_7t)
+ *(.jcr)
+
+ /* C++ support: The .init and .fini sections contain XFLAT-
+ * specific logic to manage static constructors and destructors.
+ */
+
+ *(.gnu.linkonce.t.*)
+ *(.init)
+ *(.fini)
+
+ /* This is special code area at the end of the normal
+ text section. It contains a small lookup table at
+ the start followed by the code pointed to by entries
+ in the lookup table. */
+
+ . = ALIGN (4) ;
+ PROVIDE(__ctbp = .);
+ *(.call_table_data)
+ *(.call_table_text)
+
+ _etext = . ;
+
+ } > ISPACE
+
+ /* DSpace is also located at address 0. Every (unrelocated) DSpace
+ * address is an offset from the begining of this segment.
+ */
+
+ .data 0x00000000 :
+ {
+ __data_start = . ;
+ *(.rodata)
+ *(.rodata1)
+ *(.rodata.*)
+ *(.gnu.linkonce.r*)
+ *(.data)
+ *(.data1)
+ *(.data.*)
+ *(.gnu.linkonce.d*)
+ *(.data1)
+ *(.eh_frame)
+ *(.gcc_except_table)
+
+ *(.gnu.linkonce.s.*)
+ *(__libc_atexit)
+ *(__libc_subinit)
+ *(__libc_subfreeres)
+ *(.note.ABI-tag)
+
+ /* C++ support. For each global and static local C++ object,
+ * GCC creates a small subroutine to construct the object. Pointers
+ * to these routines (not the routines themselves) are stored as
+ * simple, linear arrays in the .ctors section of the object file.
+ * Similarly, pointers to global/static destructor routines are
+ * stored in .dtors.
+ */
+
+ *(.gnu.linkonce.d.*)
+
+ _ctors_start = . ;
+ *(.ctors)
+ _ctors_end = . ;
+ _dtors_start = . ;
+ *(.dtors)
+ _dtors_end = . ;
+
+ _edata = . ;
+ edata = ALIGN( 0x10 ) ;
+ } > DSPACE
+
+ .bss :
+ {
+ __bss_start = _edata ;
+ *(.dynsbss)
+ *(.sbss)
+ *(.sbss.*)
+ *(.scommon)
+ *(.dynbss)
+ *(.bss)
+ *(.bss.*)
+ *(.bss*)
+ *(.gnu.linkonce.b*)
+ *(COMMON)
+ end = ALIGN( 0x10 ) ;
+ _end = ALIGN( 0x10 ) ;
+ } > DSPACE
+
+ .got 0 : { *(.got.plt) *(.got) }
+ .junk 0 : { *(.rel*) *(.rela*) }
+ /* Stabs debugging sections. */
+ .stab 0 : { *(.stab) }
+ .stabstr 0 : { *(.stabstr) }
+ .stab.excl 0 : { *(.stab.excl) }
+ .stab.exclstr 0 : { *(.stab.exclstr) }
+ .stab.index 0 : { *(.stab.index) }
+ .stab.indexstr 0 : { *(.stab.indexstr) }
+ .comment 0 : { *(.comment) }
+ .debug_abbrev 0 : { *(.debug_abbrev) }
+ .debug_info 0 : { *(.debug_info) }
+ .debug_line 0 : { *(.debug_line) }
+ .debug_pubnames 0 : { *(.debug_pubnames) }
+ .debug_aranges 0 : { *(.debug_aranges) }
+}
diff --git a/nuttx/examples/nxflat/tests/Make.defs b/nuttx/examples/nxflat/tests/Make.defs
new file mode 100644
index 000000000..c4ec82c52
--- /dev/null
+++ b/nuttx/examples/nxflat/tests/Make.defs
@@ -0,0 +1,45 @@
+############################################################################
+# examples/nxflat/Make.defs
+#
+# Copyright (C) 2009 Gregory Nutt. All rights reserved.
+# Author: 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.
+#
+############################################################################
+
+NXFLATCC = $(CC)
+NXFLATCFLAGS = $(CFLAGS)
+NXFLATCXX = $(CXX)
+NXFLATCXXFLAGS = $(CXXFLAGS)
+NXFLATCC = $(CC)
+NXFLATCFLAGS = $(CFLAGS)
+
+NXFLATLD = $(LD)
+NXFLATLDFLAGS =
+
diff --git a/nuttx/examples/nxflat/tests/Makefile b/nuttx/examples/nxflat/tests/Makefile
new file mode 100644
index 000000000..003c187f3
--- /dev/null
+++ b/nuttx/examples/nxflat/tests/Makefile
@@ -0,0 +1,55 @@
+############################################################################
+# examples/nxflat/Makefile
+#
+# Copyright (C) 2009 Gregory Nutt. All rights reserved.
+# Author: 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.
+#
+############################################################################
+
+TESTDIRS := errno hello hello++ longjmp mutex pthread signal task
+
+define TEST_template
+$(1)_$(2):
+ $(MAKE) -C $(1) $(3)
+endef
+
+$(foreach TEST, $(TESTDIRS), $(eval $(call TEST_template,$(TEST),build, all)))
+$(foreach TEST, $(TESTDIRS), $(eval $(call TEST_template,$(TEST),clean,clean)))
+$(foreach TEST, $(TESTDIRS), $(eval $(call TEST_template,$(TEST),install,install)))
+
+all: build
+.PHONY: all build clean user_install root_install
+
+build: $(foreach TEST, $(TESTDIRS), $(TEST)_build)
+
+clean: $(foreach TEST, $(TESTDIRS), $(TEST)_clean)
+
+install: $(foreach TEST, $(TESTDIRS), $(TEST)_install)
+
diff --git a/nuttx/examples/nxflat/tests/errno/Makefile b/nuttx/examples/nxflat/tests/errno/Makefile
new file mode 100644
index 000000000..4c1ce8180
--- /dev/null
+++ b/nuttx/examples/nxflat/tests/errno/Makefile
@@ -0,0 +1,58 @@
+############################################################################
+# examples/nxflat/tests/hello/Makefile
+#
+# Copyright (C) 2009 Gregory Nutt. All rights reserved.
+# Author: 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)/.config # Current configuration
+-include $(TOPDIR)/Make.defs # Basic make info
+include ../Make.defs # NXFLAT make info
+
+BIN = errno
+
+SRCS = $(BIN).c
+OBJS = $(SRCS:.c=.o)
+
+all: $(BIN)
+
+$(OBJS): %.o: %.c
+ $(NXFLATCC) -c $(NXFLATCFLAGS) $< -o $@
+
+$(BIN): $(OBJS)
+ $(NXFLATLD) $(NXFLATLDFLAGS) -o $@ $(OBJS)
+
+clean:
+ rm -f $(BIN) *.o core
+
+install:
+ install -D $(BIN) $(ROMFS_DIR)/$(BIN)
+
diff --git a/nuttx/examples/nxflat/tests/errno/errno.c b/nuttx/examples/nxflat/tests/errno/errno.c
new file mode 100644
index 000000000..3c54de7be
--- /dev/null
+++ b/nuttx/examples/nxflat/tests/errno/errno.c
@@ -0,0 +1,83 @@
+/****************************************************************************
+ * examples/nxflat/tests/errno/errno.c
+ *
+ * Copyright (C) 2009 Gregory Nutt. All rights reserved.
+ * Author: 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+static const char g_nonexistent[] = "aflav-sautga-ay";
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+int main(int argc, char **argv, char **envp)
+{
+ FILE *test_stream;
+
+ /* Try using stdout and stderr explicitly. These are global variables
+ * exported from the base code.
+ */
+
+ fprintf(stdout, "Hello, World on stdout\n");
+ fprintf(stderr, "Hello, World on stderr\n");
+
+ /* Try opening a non-existent file using buffered IO. */
+
+ test_stream = fopen(g_nonexistent, "r");
+ if (test_stream)
+ {
+ fprintf(stderr, "Hmm... Delete \"%s\" and try this again\n",
+ g_nonexistent);
+ exit(1);
+ }
+
+ /* Now print the errno on stderr. Errno is also a global
+ * variable exported by the base code.
+ */
+
+ fprintf(stderr, "We failed to open \"%s!\" errno is %d\n",
+ g_nonexistent, errno);
+
+ return 0;
+}
diff --git a/nuttx/examples/nxflat/tests/errno/errno.o b/nuttx/examples/nxflat/tests/errno/errno.o
new file mode 100644
index 000000000..eada97cdb
--- /dev/null
+++ b/nuttx/examples/nxflat/tests/errno/errno.o
Binary files differ
diff --git a/nuttx/examples/nxflat/tests/hello++/Makefile b/nuttx/examples/nxflat/tests/hello++/Makefile
new file mode 100644
index 000000000..dc2693219
--- /dev/null
+++ b/nuttx/examples/nxflat/tests/hello++/Makefile
@@ -0,0 +1,114 @@
+############################################################################
+# examples/nxflat/tests/hello/Makefile
+#
+# Copyright (C) 2009 Gregory Nutt. All rights reserved.
+# Author: 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)/.config # Current configuration
+-include $(TOPDIR)/Make.defs # Basic make info
+include ../Make.defs # NXFLAT make info
+
+BIN1 = hello++1
+BIN2 = hello++2
+BIN3 = hello++3
+#BIN4 = hello++4
+
+SRCS1 = $(BIN1).c
+OBJS1 = $(SRCS1:.c=.o)
+
+SRCS2 = $(BIN2).c
+OBJS2 = $(SRCS2:.c=.o)
+
+SRCS3 = $(BIN3).c
+OBJS3 = $(SRCS3:.c=.o)
+
+#SRCS4 = $(BIN4).c
+#OBJS4 = $(SRCS4:.c=.o)
+
+CXXOBJS = $(OBJS1) $(OBJS2) $(OBJS3) # $(OBJS4)
+
+LIBSTDC_STUBS_DIR = $(TOPDIR)/libxx
+LIBSTDC_STUBS_LIB = $(LIBSTDC_STUBS_DIR)/liblibxx.a
+
+all: $(BIN1) $(BIN2) $(BIN3) # $(BIN4)
+
+$(CXXOBJS): %.o: %.cpp
+ $(NXFLATCXX) -c $(NXFLATCXXFLAGS) $< -o $@
+
+# This contains libstdc++ stubs to that you can build C++ code
+# without actually have libstdc++
+
+$(LIBSTDC_STUBS_LIB):
+ $(MAKE) -C $(LIBSTDC_STUBS_DIR)
+
+# BIN1 and BIN2 link just like C code because they contain no
+# static constructors. BIN1 is equivalent to a C hello world;
+# BIN2 contains a class that implements hello world, but it is
+# not statically initialized.
+
+$(BIN1): $(OBJS1)
+ $(XFLATLD) -o $@ $^
+
+$(BIN2): $(OBJS2) $(LIBSTDC_STUBS_LIB)
+ $(XFLATLD) -o $@ $^
+
+# BIN3 and BIN4 require that we include --cxx in the xflat-ld command.
+# This will instruct xflat-ld that we want it to put togethe the correct
+# startup files to handle the C++ static initializers.
+#
+# BIN3 is equivalent to BIN2 except that is uses static initializers
+
+$(BIN3): $(OBJS3) $(LIBSTDC_STUBS_LIB)
+ $(XFLATLD) --cxx -o $@ $^
+
+# BIN4 is similar to BIN3 except that it uses the streams code from libstdc++
+#
+# NOTE: libstdc++ is not available for XFLAT as of this writing
+#
+#$(BIN4): $(OBJS4) $(LIBSTDC_STUBS_LIB)
+# $(XFLATLD) --cxx -o $@ $^
+
+clean:
+ rm -f $(BIN1) $(BIN2) $(BIN3) $(BIN4) *.o *~ core
+
+user_install: $(BIN1) $(BIN2) $(BIN3) # $(BIN4)
+ install -D $(BIN1) $(ROMFS_DIR)/$(BIN1)
+ install -D $(BIN2) $(ROMFS_DIR)/$(BIN2)
+ install -D $(BIN3) $(ROMFS_DIR)/$(BIN3)
+# install -D $(BIN4) $(ROMFS_DIR)/$(BIN4)
+
+
+
+
+
+
+
diff --git a/nuttx/examples/nxflat/tests/hello++/hello++1.cpp b/nuttx/examples/nxflat/tests/hello++/hello++1.cpp
new file mode 100644
index 000000000..a8881422c
--- /dev/null
+++ b/nuttx/examples/nxflat/tests/hello++/hello++1.cpp
@@ -0,0 +1,60 @@
+/////////////////////////////////////////////////////////////////////////////
+// examples/nxflat/tests/hello++/hello++1.c
+//
+// Copyright (C) 2009 Gregory Nutt. All rights reserved.
+// Author: 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.
+//
+/////////////////////////////////////////////////////////////////////////////
+//
+// This is an trivial version of "Hello, World" program. It illustrates
+// that we can build C programs using the C++ compiler.
+//
+// - Building a C++ program to use the C library
+// - No class creation
+// - NO Streams
+// - NO Static constructor and destructors
+//
+/////////////////////////////////////////////////////////////////////////////
+
+/////////////////////////////////////////////////////////////////////////////
+// Included Files
+/////////////////////////////////////////////////////////////////////////////
+
+#include <cstdio>
+
+/////////////////////////////////////////////////////////////////////////////
+// Public Functions
+/////////////////////////////////////////////////////////////////////////////
+
+int main(int argc, char **argv, char **envp)
+{
+ printf("Hello, World!\n");
+ return 0;
+}
diff --git a/nuttx/examples/nxflat/tests/hello++/hello++2.cpp b/nuttx/examples/nxflat/tests/hello++/hello++2.cpp
new file mode 100644
index 000000000..4f189699e
--- /dev/null
+++ b/nuttx/examples/nxflat/tests/hello++/hello++2.cpp
@@ -0,0 +1,123 @@
+/////////////////////////////////////////////////////////////////////////////
+// examples/nxflat/tests/hello++/hello++2.c
+//
+// Copyright (C) 2009 Gregory Nutt. All rights reserved.
+// Author: 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.
+//
+/////////////////////////////////////////////////////////////////////////////
+//
+// This is an another trivial version of "Hello, World" design. It illustrates
+//
+// - Building a C++ program to use the C library
+// - Basic class creation
+// - NO Streams
+// - NO Static constructor and destructors
+//
+/////////////////////////////////////////////////////////////////////////////
+
+/////////////////////////////////////////////////////////////////////////////
+// Included Files
+/////////////////////////////////////////////////////////////////////////////
+
+#include <cstdio>
+
+/////////////////////////////////////////////////////////////////////////////
+// Classes
+/////////////////////////////////////////////////////////////////////////////
+
+class CThingSayer
+{
+ const char *szWhatToSay;
+public:
+ CThingSayer(void)
+ {
+ printf("CThingSayer::CThingSayer: I am!\n");
+ szWhatToSay = NULL;
+ }
+
+ ~CThingSayer(void)
+ {
+ printf("CThingSayer::~CThingSayer: I cease to be\n");
+ if (szWhatToSay)
+ {
+ printf("CThingSayer::~CThingSayer: I will never say '%s' again\n",
+ szWhatToSay);
+ }
+ szWhatToSay = NULL;
+ }
+
+ void Initialize(const char *czSayThis)
+ {
+ printf("CThingSayer::Initialize: When told, I will say '%s'\n",
+ czSayThis);
+ szWhatToSay = czSayThis;
+ }
+
+ void SayThing(void)
+ {
+ printf("CThingSayer::SayThing: I am now saying '%s'\n", szWhatToSay);
+ }
+};
+
+/////////////////////////////////////////////////////////////////////////////
+// Public Functions
+/////////////////////////////////////////////////////////////////////////////
+
+int main(int argc, char **argv, char **envp)
+{
+ CThingSayer *MyThingSayer;
+
+ printf("main: Started. Creating MyThingSayer\n");
+
+ // Create an instance of the CThingSayer class
+ // We should see the message from constructor, CThingSayer::CThingSayer(),
+
+ MyThingSayer = new CThingSayer;
+ printf("main: Created MyThingSayer=0x%08lx\n", (long)MyThingSayer);
+
+ // Tell MyThingSayer that "Hello, World!" is the string to be said
+
+ printf("main: Calling MyThingSayer->Initialize\n");;
+ MyThingSayer->Initialize("Hello, World!");
+
+ // Tell MyThingSayer to say the thing we told it to say
+
+ printf("main: Calling MyThingSayer->SayThing\n");;
+ MyThingSayer->SayThing();
+
+ // We should see the message from the destructor,
+ // CThingSayer::~CThingSayer(), AFTER we see the following
+
+ printf("main: Destroying MyThingSayer\n");
+ delete MyThingSayer;
+
+ printf("main: Returning\n");;
+ return 0;
+}
diff --git a/nuttx/examples/nxflat/tests/hello++/hello++3.cpp b/nuttx/examples/nxflat/tests/hello++/hello++3.cpp
new file mode 100644
index 000000000..b41d09664
--- /dev/null
+++ b/nuttx/examples/nxflat/tests/hello++/hello++3.cpp
@@ -0,0 +1,132 @@
+/////////////////////////////////////////////////////////////////////////////
+// examples/nxflat/tests/hello++/hello++3.c
+//
+// Copyright (C) 2009 Gregory Nutt. All rights reserved.
+// Author: 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.
+//
+/////////////////////////////////////////////////////////////////////////////
+//
+// This is an another trivial version of "Hello, World" design. It illustrates
+//
+// - Building a C++ program to use the C library and stdio
+// - Basic class creation with virtual methods.
+// - Static constructor and destructors (in main program only)
+// - NO Streams
+//
+/////////////////////////////////////////////////////////////////////////////
+
+/////////////////////////////////////////////////////////////////////////////
+// Included Files
+/////////////////////////////////////////////////////////////////////////////
+
+#include <cstdio>
+
+/////////////////////////////////////////////////////////////////////////////
+// Classes
+/////////////////////////////////////////////////////////////////////////////
+
+class CThingSayer
+{
+ const char *szWhatToSay;
+public:
+ CThingSayer(void);
+ virtual ~CThingSayer(void);
+ virtual void Initialize(const char *czSayThis);
+ virtual void SayThing(void);
+};
+
+// A static instance of the CThingSayer class. This instance MUST
+// be constructed by the system BEFORE the program is started at
+// main() and must be destructed by the system AFTER the main()
+// returns to the system
+
+static CThingSayer MyThingSayer;
+
+// These are implementations of the methods of the CThingSayer class
+
+CThingSayer::CThingSayer(void)
+{
+ printf("CThingSayer::CThingSayer: I am!\n");
+ szWhatToSay = NULL;
+}
+
+CThingSayer::~CThingSayer(void)
+{
+ printf("CThingSayer::~CThingSayer: I cease to be\n");
+ if (szWhatToSay)
+ {
+ printf("CThingSayer::~CThingSayer: I will never say '%s' again\n",
+ szWhatToSay);
+ }
+ szWhatToSay = NULL;
+}
+
+void CThingSayer::Initialize(const char *czSayThis)
+{
+ printf("CThingSayer::Initialize: When told, I will say '%s'\n",
+ czSayThis);
+ szWhatToSay = czSayThis;
+}
+
+void CThingSayer::SayThing(void)
+{
+ printf("CThingSayer::SayThing: I am now saying '%s'\n", szWhatToSay);
+}
+
+/////////////////////////////////////////////////////////////////////////////
+// Public Functions
+/////////////////////////////////////////////////////////////////////////////
+
+int main(int argc, char **argv, char **envp)
+{
+ // We should see the message from constructor, CThingSayer::CThingSayer(),
+ // BEFORE we see the following messages. That is proof that the
+ // C++ static initializer is working
+
+ printf("main: Started. MyThingSayer should already exist\n");
+
+ // Tell MyThingSayer that "Hello, World!" is the string to be said
+
+ printf("main: Calling MyThingSayer.Initialize\n");;
+ MyThingSayer.Initialize("Hello, World!");
+
+ // Tell MyThingSayer to say the thing we told it to say
+
+ printf("main: Calling MyThingSayer.SayThing\n");;
+ MyThingSayer.SayThing();
+
+ // We are finished, return. We should see the message from the
+ // destructor, CThingSayer::~CThingSayer(), AFTER we see the following
+ // message. That is proof that the C++ static destructor logic
+ // is working
+
+ printf("main: Returning. MyThingSayer should be destroyed\n");;
+ return 0;
+}
diff --git a/nuttx/examples/nxflat/tests/hello++/hello++4.cpp b/nuttx/examples/nxflat/tests/hello++/hello++4.cpp
new file mode 100644
index 000000000..b6c0c488c
--- /dev/null
+++ b/nuttx/examples/nxflat/tests/hello++/hello++4.cpp
@@ -0,0 +1,150 @@
+/////////////////////////////////////////////////////////////////////////////
+// examples/nxflat/tests/hello++/hello++4.c
+//
+// Copyright (C) 2009 Gregory Nutt. All rights reserved.
+// Author: 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.
+//
+/////////////////////////////////////////////////////////////////////////////
+//
+// This is an excessively complex version of "Hello, World" design to
+// illustrate some basic properties of C++:
+//
+// - Building a C++ program
+// - Streams / statically linked libstdc++
+// - Static constructor and destructors (in main program only)
+//
+/////////////////////////////////////////////////////////////////////////////
+
+/////////////////////////////////////////////////////////////////////////////
+// Included Files
+/////////////////////////////////////////////////////////////////////////////
+
+#include <cstdio>
+#include <iostream>
+
+#ifndef NULL
+# define NULL ((void*)0L)
+#endif
+
+/////////////////////////////////////////////////////////////////////////////
+// Classes
+/////////////////////////////////////////////////////////////////////////////
+
+using namespace std;
+
+// A hello world sayer class
+
+class CThingSayer
+{
+ const char *szWhatToSay;
+public:
+ CThingSayer(void);
+ virtual ~CThingSayer(void);
+ virtual void Initialize(const char *czSayThis);
+ virtual void SayThing(void);
+};
+
+/////////////////////////////////////////////////////////////////////////////
+// Private Data
+/////////////////////////////////////////////////////////////////////////////
+
+// A static instance of the CThingSayer class. This instance MUST
+// be constructed by the system BEFORE the program is started at
+// main() and must be destructed by the system AFTER the main()
+// returns to the system
+
+static CThingSayer MyThingSayer;
+
+/////////////////////////////////////////////////////////////////////////////
+// Method Implementations
+/////////////////////////////////////////////////////////////////////////////
+
+// These are implementations of the methods of the CThingSayer class
+
+CThingSayer::CThingSayer(void)
+{
+ cout << "CThingSayer::CThingSayer: I am!" << endl;
+ szWhatToSay = (char*)NULL;
+}
+
+CThingSayer::~CThingSayer(void)
+{
+ cout << "CThingSayer::~CThingSayer: I cease to be" << endl;
+ if (szWhatToSay)
+ {
+ cout << "CThingSayer::~CThingSayer: I will never say '"
+ << szWhatToSay << "' again" << endl;
+ }
+ szWhatToSay = (char*)NULL;
+}
+
+void CThingSayer::Initialize(const char *czSayThis)
+{
+ cout << "CThingSayer::Initialize: When told, I will say '"
+ << czSayThis << "'" << endl;
+ szWhatToSay = czSayThis;
+}
+
+void CThingSayer::SayThing(void)
+{
+ cout << "CThingSayer::SayThing: I am now saying '"
+ << szWhatToSay << "'" << endl;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+// Public Functions
+/////////////////////////////////////////////////////////////////////////////
+
+int main(int argc, char **argv, char **envp)
+{
+ // We should see the message from constructor, CThingSayer::CThingSayer(),
+ // BEFORE we see the following messages. That is proof that the
+ // C++ static initializer is working
+
+ cout << "main: Started" << endl;
+
+ // Tell MyThingSayer that "Hello, World!" is the string to be said
+
+ cout << "main: Calling MyThingSayer.Initialize" << endl;
+ MyThingSayer.Initialize("Hello, World!");
+
+ // Tell MyThingSayer to say the thing we told it to say
+
+ cout << "main: Calling MyThingSayer.SayThing" << endl;
+ MyThingSayer.SayThing();
+
+ // We are finished, return. We should see the message from the
+ // destructor, CThingSayer::~CThingSayer(), AFTER we see the following
+ // message. That is proof that the C++ static destructor logic
+ // is working
+
+ cout << "main: Returning" << endl;
+ return 0;
+}
diff --git a/nuttx/examples/nxflat/tests/hello/Makefile b/nuttx/examples/nxflat/tests/hello/Makefile
new file mode 100644
index 000000000..c8cbf6112
--- /dev/null
+++ b/nuttx/examples/nxflat/tests/hello/Makefile
@@ -0,0 +1,58 @@
+############################################################################
+# examples/nxflat/tests/hello/Makefile
+#
+# Copyright (C) 2009 Gregory Nutt. All rights reserved.
+# Author: 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)/.config # Current configuration
+-include $(TOPDIR)/Make.defs # Basic make info
+include ../Make.defs # NXFLAT make info
+
+BIN = hello
+
+SRCS = $(BIN).c
+OBJS = $(SRCS:.c=.o)
+
+all: $(BIN)
+
+$(OBJS): %.o: %.c
+ $(NXFLATCC) -c $(NXFLATCFLAGS) $< -o $@
+
+$(BIN): $(OBJS)
+ $(NXFLATLD) $(NXFLATLDFLAGS) -o $@ $(OBJS)
+
+clean:
+ rm -f $(BIN) *.o core
+
+install:
+ install -D $(BIN) $(ROMFS_DIR)/$(BIN)
+
diff --git a/nuttx/examples/nxflat/tests/hello/hello.c b/nuttx/examples/nxflat/tests/hello/hello.c
new file mode 100644
index 000000000..d951d1565
--- /dev/null
+++ b/nuttx/examples/nxflat/tests/hello/hello.c
@@ -0,0 +1,89 @@
+/****************************************************************************
+ * examples/nxflat/tests/hello/hello.c
+ *
+ * Copyright (C) 2009 Gregory Nutt. All rights reserved.
+ * Author: 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+int main(int argc, char **argv, char **envp)
+{
+ int i;
+
+ /* Mandatory "Hello, world!" */
+
+ puts("Getting ready to say \"Hello, world\"\n");
+ printf("Hello, world!\n");
+ puts("It has been said.\n");
+
+ /* Print arguments */
+
+ printf("argc\t= %d\n", argc);
+ printf("argv\t= 0x%p\n", argv);
+
+ for (i = 0; i < argc; i++)
+ {
+ printf("argv[%d]\t= ", i);
+ if (argv[i])
+ {
+ printf("(0x%p) \"%s\"\n", argv[i], argv[i]);
+ }
+ else
+ {
+ printf("NULL?\n");
+ }
+ }
+
+ printf("argv[%d]\t= 0x%p\n", argc, argv[argc]);
+
+ /* Print environment variables */
+
+ printf("envp\t= 0x%p\n", envp);
+
+ for (i = 0; envp[i] != NULL; i++)
+ {
+ printf("envp[%d]\t= (0x%p) \"%s\"\n", i, envp[i], envp[i]);
+ }
+ printf("envp[%d]\t= 0x%p\n", i, envp[i]);
+
+ printf("Goodbye, world!\n");
+ return 0;
+}
diff --git a/nuttx/examples/nxflat/tests/hello/hello.o b/nuttx/examples/nxflat/tests/hello/hello.o
new file mode 100644
index 000000000..2ba7aa2ce
--- /dev/null
+++ b/nuttx/examples/nxflat/tests/hello/hello.o
Binary files differ
diff --git a/nuttx/examples/nxflat/tests/longjmp/Makefile b/nuttx/examples/nxflat/tests/longjmp/Makefile
new file mode 100644
index 000000000..80b94d5f8
--- /dev/null
+++ b/nuttx/examples/nxflat/tests/longjmp/Makefile
@@ -0,0 +1,58 @@
+############################################################################
+# examples/nxflat/tests/longjmp/Makefile
+#
+# Copyright (C) 2009 Gregory Nutt. All rights reserved.
+# Author: 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)/.config # Current configuration
+-include $(TOPDIR)/Make.defs # Basic make info
+include ../Make.defs # NXFLAT make info
+
+BIN = longjmp
+
+SRCS = $(BIN).c
+OBJS = $(SRCS:.c=.o)
+
+all: $(BIN)
+
+$(OBJS): %.o: %.c
+ $(NXFLATCC) -c $(NXFLATCFLAGS) $< -o $@
+
+$(BIN): $(OBJS)
+ $(NXFLATLD) $(NXFLATLDFLAGS) -o $@ $(OBJS)
+
+clean:
+ rm -f $(BIN) *.o core
+
+install:
+ install -D $(BIN) $(ROMFS_DIR)/$(BIN)
+
diff --git a/nuttx/examples/nxflat/tests/longjmp/longjmp.c b/nuttx/examples/nxflat/tests/longjmp/longjmp.c
new file mode 100644
index 000000000..a896fb13c
--- /dev/null
+++ b/nuttx/examples/nxflat/tests/longjmp/longjmp.c
@@ -0,0 +1,128 @@
+/****************************************************************************
+ * examples/nxflat/tests/longjmp/longjmp.c
+ *
+ * Copyright (C) 2009 Gregory Nutt. All rights reserved.
+ * Author: 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdio.h>
+#include <setjmp.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MAIN_VAL 47
+#define FUNC_VAL 92
+#define LEAF_VAL 163
+
+#define FUNCTION_ARG MAIN_VAL
+#define LEAF_ARG (FUNCTION_ARG + FUNC_VAL)
+#define SETJMP_RETURN (LEAF_ARG + LEAF_VAL)
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static jmp_buf env;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int leaf(int *some_arg)
+{
+ int some_local_variable = *some_arg + LEAF_VAL;
+
+ printf("leaf: received %d\n", *some_arg);
+
+ if (*some_arg != LEAF_ARG)
+ printf("leaf: ERROR: expected %d\n", LEAF_ARG);
+
+ printf("leaf: Calling longjmp() with %d\n", some_local_variable);
+
+ longjmp(env, some_local_variable);
+}
+
+static int function(int some_arg)
+{
+ int some_local_variable = some_arg + FUNC_VAL;
+ int retval;
+
+ printf("function: received %d\n", some_arg);
+
+ if (some_arg != FUNCTION_ARG)
+ printf("function: ERROR: expected %d\n", FUNCTION_ARG);
+
+ printf("function: Calling leaf() with %d\n", some_local_variable);
+
+ retval = leaf(&some_local_variable);
+
+ printf("function: ERROR -- leaf returned!\n");
+ return retval;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+int main(int argc, char **argv, char **envp)
+{
+ int value;
+
+ printf("main: Calling setjmp\n");
+ value = setjmp(env);
+ printf("main: setjmp returned %d\n", value);
+
+ if (value == 0)
+ {
+ printf("main: Normal setjmp return\n");
+ printf("main: Calling function with %d\n", MAIN_VAL);
+ function(MAIN_VAL);
+ printf("main: ERROR -- function returned!\n");
+ return 1;
+ }
+ else if (value != SETJMP_RETURN)
+ {
+ printf("main: ERROR: Expected %d\n", SETJMP_RETURN);
+ return 1;
+ }
+ else
+ {
+ printf("main: SUCCESS: setjmp return from longjmp call\n");
+ return 0;
+ }
+}
+
diff --git a/nuttx/examples/nxflat/tests/mutex/Makefile b/nuttx/examples/nxflat/tests/mutex/Makefile
new file mode 100644
index 000000000..6ba0b6736
--- /dev/null
+++ b/nuttx/examples/nxflat/tests/mutex/Makefile
@@ -0,0 +1,58 @@
+############################################################################
+# examples/nxflat/tests/mutex/Makefile
+#
+# Copyright (C) 2009 Gregory Nutt. All rights reserved.
+# Author: 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)/.config # Current configuration
+-include $(TOPDIR)/Make.defs # Basic make info
+include ../Make.defs # NXFLAT make info
+
+BIN = mutex
+
+SRCS = $(BIN).c
+OBJS = $(SRCS:.c=.o)
+
+all: $(BIN)
+
+$(OBJS): %.o: %.c
+ $(NXFLATCC) -c $(NXFLATCFLAGS) $< -o $@
+
+$(BIN): $OBJS)
+ $(NXFLATLD) $(NXFLATLDFLAGS) -o $@ $(OBJS)
+
+clean:
+ rm -f $(BIN) *.o core
+
+install:
+ install -D $(BIN) $(ROMFS_DIR)/$(BIN)
+
diff --git a/nuttx/examples/nxflat/tests/mutex/mutex.c b/nuttx/examples/nxflat/tests/mutex/mutex.c
new file mode 100644
index 000000000..5fdbdac5d
--- /dev/null
+++ b/nuttx/examples/nxflat/tests/mutex/mutex.c
@@ -0,0 +1,135 @@
+/****************************************************************************
+ * examples/nxflat/tests/mutex/mutex.c
+ *
+ * Copyright (C) 2009 Gregory Nutt. All rights reserved.
+ * Author: 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdio.h>
+#include <pthread.h>
+#include <signal.h>
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static pthread_mutex_t mut;
+static volatile int my_mutex = 0;
+static unsigned long nloops[2] = {0, 0};
+static unsigned long nerrors[2] = {0, 0};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static void thread_func(void *parameter)
+{
+ int my_id = (int)parameter;
+ int my_ndx = my_id - 1;
+ volatile int i;
+
+ for (;;)
+ {
+ if ((pthread_mutex_lock(&mut)) != 0)
+ {
+ printf("ERROR thread %d: pthread_mutex_lock failed\n", my_id);
+ }
+
+ if (my_mutex == 1)
+ {
+ printf("ERROR thread=%d: "
+ "my_mutex should be zero, instead my_mutex=%d\n",
+ my_id, my_mutex);
+ nerrors[my_ndx]++;
+ }
+
+ my_mutex = 1;
+ for (i = 0; i < 1000; i++);
+ my_mutex = 0;
+
+ if ((pthread_mutex_unlock(&mut)) != 0)
+ {
+ printf("ERROR thread %d: pthread_mutex_unlock failed\n", my_id);
+ }
+
+ nloops[my_ndx]++;
+ }
+}
+
+static void signal_handler(int signo)
+{
+ printf("\tThread1\tThread2\n");
+ printf("Loops\t%ld\t%ld\n", nloops[0], nloops[1]);
+ printf("Errors\t%ld\t%ld\n", nerrors[0], nerrors[1]);
+ exit(0);
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+int main(int argc, char **argv, char **envp)
+{
+ pthread_t thread1, thread2;
+
+ printf("Starting threads\n");
+
+ /* Set up to catch control-C interrupt */
+
+ (void)signal(SIGINT, signal_handler);
+
+ /* Initialize the mutex */
+
+ pthread_mutex_init(&mut, NULL);
+
+ /* Start two thread instances */
+
+ if ((pthread_create(&thread1, NULL, (void*)&thread_func, (void*)1)) != 0)
+ {
+ fprintf(stderr, "Error in thread#1 creation\n");
+ }
+
+ if ((pthread_create(&thread2, NULL, (void*)&thread_func, (void*)2)) != 0)
+ {
+ fprintf(stderr, "Error in thread#2 creation\n");
+ }
+
+ printf("Press control-C to terminate the example\n");
+
+ pthread_join(thread1, NULL);
+ pthread_join(thread2, NULL);
+ return 0;
+}
+
diff --git a/nuttx/examples/nxflat/tests/pthread/Makefile b/nuttx/examples/nxflat/tests/pthread/Makefile
new file mode 100644
index 000000000..eadba85ab
--- /dev/null
+++ b/nuttx/examples/nxflat/tests/pthread/Makefile
@@ -0,0 +1,58 @@
+############################################################################
+# examples/nxflat/tests/pthread/Makefile
+#
+# Copyright (C) 2009 Gregory Nutt. All rights reserved.
+# Author: 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)/.config # Current configuration
+-include $(TOPDIR)/Make.defs # Basic make info
+include ../Make.defs # NXFLAT make info
+
+BIN = pthread
+
+SRCS = $(BIN).c
+OBJS = $(SRCS:.c=.o)
+
+all: $(BIN)
+
+$(OBJS): %.o: %.c
+ $(NXFLATCC) -c $(NXFLATCFLAGS) $< -o $@
+
+$(BIN): $OBJS)
+ $(NXFLATLD) $(NXFLATLDFLAGS) -o $@ $(OBJS)
+
+clean:
+ rm -f $(BIN) *.o core
+
+install:
+ install -D $(BIN) $(ROMFS_DIR)/$(BIN)
+
diff --git a/nuttx/examples/nxflat/tests/pthread/pthread.c b/nuttx/examples/nxflat/tests/pthread/pthread.c
new file mode 100644
index 000000000..89b489302
--- /dev/null
+++ b/nuttx/examples/nxflat/tests/pthread/pthread.c
@@ -0,0 +1,136 @@
+/****************************************************************************
+ * examples/nxflat/tests/pthread/pthread.c
+ *
+ * Copyright (C) 2009 Gregory Nutt. All rights reserved.
+ * Author: 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdlib.h>
+#include <pthread.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define CHILD_ARG ((void*)0x12345678)
+#define CHILD_RET ((void*)0x87654321)
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+enum exit_values_e
+{
+ TESTRESULT_SUCCESS = 0,
+ TESTRESULT_PTHREAD_ATTR_INIT_FAIL,
+ TESTRESULT_PTHREAD_CREATE_FAIL,
+ TESTRESULT_PTHREAD_JOIN_FAIL,
+ TESTRESULT_CHILD_ARG_FAIL,
+ TESTRESULT_CHILD_RETVAL_FAIL,
+};
+
+/****************************************************************************
+ * External Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static void *child_start_routine(void *arg)
+{
+ printf("CHILD: started with arg=%d\n", (int)arg);
+
+ if (arg != CHILD_ARG)
+ {
+ printf("CHILD: expected arg=%d\n", (int)CHILD_ARG);
+ return (void*)TESTRESULT_CHILD_ARG_FAIL;
+ }
+ sleep(2);
+
+ printf("CHILD: returning %d\n", (int)CHILD_RET);
+ pthread_exit(CHILD_RET);
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+int main(int argc, char **argv, char **envp)
+{
+ pthread_attr_t attr;
+ pthread_t thread;
+ void *retval;
+ int status;
+
+ puts("PARENT: started\n");
+
+ status = pthread_attr_init(&attr);
+ if (status != 0)
+ {
+ printf("PARENT: pthread_attr_init() returned %d\n", status);
+ exit(TESTRESULT_PTHREAD_ATTR_INIT_FAIL);
+ }
+
+ printf("PARENT: calling pthread_start with arg=%d\n", (int)CHILD_ARG);
+ status = pthread_create(&thread, &attr, child_start_routine, CHILD_ARG);
+ if (status != 0)
+ {
+ printf("PARENT: pthread_create() returned %d\n", status);
+ exit(TESTRESULT_PTHREAD_CREATE_FAIL);
+ }
+
+ status = pthread_join(thread, &retval);
+ if (status != 0)
+ {
+ printf("PARENT pthread_join() returned %d\n", status);
+
+ exit(TESTRESULT_PTHREAD_JOIN_FAIL);
+ }
+
+ printf("PARENT child exitted with %d\n", (int)retval);
+ if (retval != CHILD_RET)
+ {
+ printf("PARENT child thread did not exit with %d\n", (int)CHILD_RET);
+ exit(TESTRESULT_CHILD_RETVAL_FAIL);
+ }
+
+ puts("PARENT returning success\n");
+ return TESTRESULT_SUCCESS;
+}
diff --git a/nuttx/examples/nxflat/tests/signal/Makefile b/nuttx/examples/nxflat/tests/signal/Makefile
new file mode 100644
index 000000000..e1632aa8f
--- /dev/null
+++ b/nuttx/examples/nxflat/tests/signal/Makefile
@@ -0,0 +1,58 @@
+############################################################################
+# examples/nxflat/tests/signal/Makefile
+#
+# Copyright (C) 2009 Gregory Nutt. All rights reserved.
+# Author: 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)/.config # Current configuration
+-include $(TOPDIR)/Make.defs # Basic make info
+include ../Make.defs # NXFLAT make info
+
+BIN = signal
+
+SRCS = $(BIN).c
+OBJS = $(SRCS:.c=.o)
+
+all: $(BIN)
+
+$(OBJS): %.o: %.c
+ $(NXFLATCC) -c $(NXFLATCFLAGS) $< -o $@
+
+$(BIN): $(OBJS)
+ $(NXFLATLD) $(NXFLATLDFLAGS) -o $@ $(OBJS)
+
+clean:
+ rm -f $(BIN) *.o core
+
+install:
+ install -D $(BIN) $(ROMFS_DIR)/$(BIN)
+
diff --git a/nuttx/examples/nxflat/tests/signal/signal.c b/nuttx/examples/nxflat/tests/signal/signal.c
new file mode 100644
index 000000000..68d96702e
--- /dev/null
+++ b/nuttx/examples/nxflat/tests/signal/signal.c
@@ -0,0 +1,296 @@
+/****************************************************************************
+ * examples/nxflat/tests/signal/signal.c
+ *
+ * Copyright (C) 2009 Gregory Nutt. All rights reserved.
+ * Author: 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdio.h> /* For printf(), fprintf(), etc. */
+#include <signal.h> /* For signal(), sigaction(), etc. */
+#include <unistd.h> /* For usleep() */
+#include <errno.h> /* For errno */
+#include <sys/types.h> /* (needed by getpid()) */
+
+/****************************************************************************
+ * Definitions
+ ****************************************************************************/
+
+#define USEC_PER_MSEC 1000
+#define MSEC_PER_SEC 1000
+#define USEC_PER_SEC (USEC_PER_MSEC * MSEC_PER_SEC)
+#define SHORT_DELAY (USEC_PER_SEC / 3)
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static int sigusr1_rcvd = 0;
+static int sigusr2_rcvd = 0;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sigusr1_sighandler
+ ****************************************************************************/
+
+static void sigusr1_sighandler(int signo)
+{
+ printf("sigusr1_sighandler: Received SIGUSR1, signo=%d\n", signo);
+ sigusr1_rcvd = 1;
+}
+
+/****************************************************************************
+ * Name: sigusr2_sigaction
+ ***************************************************************************/
+
+#ifdef __USE_POSIX199309
+static void sigusr2_sigaction(int signo, siginfo_t *siginfo, void *arg)
+{
+ printf("sigusr2_sigaction: Received SIGUSR2, signo=%d siginfo=%p arg=%p\n",
+ signo, siginfo, arg);
+
+#ifdef HAVE_SIGQUEUE
+ if (siginfo)
+ {
+ printf(" si_signo = %d\n", siginfo->si_signo);
+ printf(" si_errno = %d\n", siginfo->si_errno);
+ printf(" si_code = %d\n", siginfo->si_code);
+ printf(" si_pid = %d\n", siginfo->si_pid);
+ printf(" si_uid = %d\n", siginfo->si_uid);
+ printf(" si_status = %d\n", siginfo->si_status);
+ printf(" si_utime = %ld\n", (long)siginfo->si_utime);
+ printf(" si_stime = %ld\n", (long)siginfo->si_stime);
+ printf(" si_value = %d\n", siginfo->si_value.sival_int);
+ printf(" si_int = %d\n", siginfo->si_int);
+ printf(" si_ptr = %p\n", siginfo->si_ptr);
+ printf(" si_addr = %p\n", siginfo->si_addr);
+ printf(" si_band = %ld\n", siginfo->si_band);
+ printf(" si_fd = %d\n", siginfo->si_fd);
+ }
+#endif
+ sigusr2_rcvd = 1;
+}
+#else
+static void sigusr2_sigaction(int signo)
+{
+ printf("sigusr2_sigaction: Received SIGUSR2, signo=%d\n", signo);
+ sigusr2_rcvd = 1;
+}
+
+#endif
+
+/****************************************************************************
+ * Name: sigusr2_sighandler
+ ****************************************************************************/
+
+static void sigusr2_sighandler(int signo)
+{
+ printf("sigusr2_sighandler: Received SIGUSR2, signo=%d\n", signo);
+ sigusr2_rcvd = 1;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: main
+ ****************************************************************************/
+
+int main(int argc, char **argv, char **envp)
+{
+ struct sigaction act;
+ struct sigaction oact;
+ void (*old_sigusr1_sighandler)(int signo);
+ void (*old_sigusr2_sighandler)(int signo);
+ pid_t mypid = getpid();
+#if defined(__USE_POSIX199309) && defined(HAVE_SIGQUEUE)
+ sigval_t sigval;
+#endif
+ int status;
+
+ printf("Setting up signal handlers from pid=%d\n", mypid);
+
+ /* Set up so that sigusr1_sighandler will respond to SIGUSR1 */
+
+ old_sigusr1_sighandler = signal(SIGUSR1, sigusr1_sighandler);
+ if (old_sigusr1_sighandler == SIG_ERR)
+ {
+ fprintf(stderr, "Failed to install SIGUSR1 handler, errno=%d\n",
+ errno);
+ exit(1);
+ }
+
+ printf("Old SIGUSR1 sighandler at %p\n", old_sigusr1_sighandler);
+ printf("New SIGUSR1 sighandler at %p\n", sigusr1_sighandler);
+
+ /* Set up so that sigusr2_sigaction will respond to SIGUSR2 */
+
+ memset(&act, 0, sizeof(struct sigaction));
+ act.sa_sigaction = sigusr2_sigaction;
+ act.sa_flags = SA_SIGINFO;
+
+ (void)sigemptyset(&act.sa_mask);
+
+ status = sigaction(SIGUSR2, &act, &oact);
+ if (status != 0)
+ {
+ fprintf(stderr, "Failed to install SIGUSR2 handler, errno=%d\n",
+ errno);
+ exit(2);
+ }
+
+ printf("Old SIGUSR2 sighandler at %p\n", oact.sa_handler);
+ printf("New SIGUSR2 sighandler at %p\n", sigusr2_sigaction);
+ printf("Raising SIGUSR1 from pid=%d\n", mypid);
+
+ fflush(stdout); usleep(SHORT_DELAY);
+
+ /* Send SIGUSR1 to ourselves via raise() */
+
+ status = raise(SIGUSR1);
+ if (status != 0)
+ {
+ fprintf(stderr, "Failed to raise SIGUSR1, errno=%d\n", errno);
+ exit(3);
+ }
+
+ usleep(SHORT_DELAY);
+ printf("SIGUSR1 raised from pid=%d\n", mypid);
+
+ /* Verify that we received SIGUSR1 */
+
+ if (sigusr1_rcvd == 0)
+ {
+ fprintf(stderr, "SIGUSR1 not received\n");
+ exit(4);
+ }
+ sigusr1_rcvd = 0;
+
+ /* Send SIGUSR2 to ourselves */
+
+ printf("Killing SIGUSR2 from pid=%d\n", mypid);
+ fflush(stdout); usleep(SHORT_DELAY);
+
+#if defined(__USE_POSIX199309) && defined(HAVE_SIGQUEUE)
+ /* Send SIGUSR2 to ourselves via sigqueue() */
+
+ sigval.sival_int = 87;
+ status = sigqueue(mypid, SIGUSR2, sigval);
+ if (status != 0)
+ {
+ fprintf(stderr, "Failed to queue SIGUSR2, errno=%d\n", errno);
+ exit(5);
+ }
+
+ usleep(SHORT_DELAY);
+ printf("SIGUSR2 queued from pid=%d, sigval=97\n", mypid);
+#else
+ /* Send SIGUSR2 to ourselves via kill() */
+
+ status = kill(mypid, SIGUSR2);
+ if (status != 0)
+ {
+ fprintf(stderr, "Failed to kill SIGUSR2, errno=%d\n", errno);
+ exit(5);
+ }
+
+ usleep(SHORT_DELAY);
+ printf("SIGUSR2 killed from pid=%d\n", mypid);
+#endif
+ /* Verify that SIGUSR2 was received */
+
+ if (sigusr2_rcvd == 0)
+ {
+ fprintf(stderr, "SIGUSR2 not received\n");
+ exit(6);
+ }
+ sigusr2_rcvd = 0;
+
+ /* Remove the sigusr2_sigaction handler and replace the SIGUSR2
+ * handler with sigusr2_sighandler.
+ */
+
+ printf("Resetting SIGUSR2 signal handler from pid=%d\n", mypid);
+
+ old_sigusr2_sighandler = signal(SIGUSR2, sigusr2_sighandler);
+ if (old_sigusr2_sighandler == SIG_ERR)
+ {
+ fprintf(stderr, "Failed to install SIGUSR2 handler, errno=%d\n",
+ errno);
+ exit(7);
+ }
+
+ printf("Old SIGUSR2 sighandler at %p\n", old_sigusr2_sighandler);
+ printf("New SIGUSR2 sighandler at %p\n", sigusr2_sighandler);
+
+ /* Verify that the handler that was removed was sigusr2_sigaction */
+
+ if ((void*)old_sigusr2_sighandler != (void*)sigusr2_sigaction)
+ {
+ fprintf(stderr,
+ "Old SIGUSR2 signhanlder (%p) is not sigusr2_sigation (%p)\n",
+ old_sigusr2_sighandler, sigusr2_sigaction);
+ exit(8);
+ }
+
+ /* Send SIGUSR2 to ourselves via kill() */
+
+ printf("Killing SIGUSR2 from pid=%d\n", mypid);
+ fflush(stdout); usleep(SHORT_DELAY);
+
+ status = kill(mypid, SIGUSR2);
+ if (status != 0)
+ {
+ fprintf(stderr, "Failed to kill SIGUSR2, errno=%d\n", errno);
+ exit(9);
+ }
+
+ usleep(SHORT_DELAY);
+ printf("SIGUSR2 killed from pid=%d\n", mypid);
+
+ /* Verify that SIGUSR2 was received */
+
+ if (sigusr2_rcvd == 0)
+ {
+ fprintf(stderr, "SIGUSR2 not received\n");
+ exit(10);
+ }
+ sigusr2_rcvd = 0;
+
+ return 0;
+}
diff --git a/nuttx/examples/nxflat/tests/task/Makefile b/nuttx/examples/nxflat/tests/task/Makefile
new file mode 100644
index 000000000..b71d135e5
--- /dev/null
+++ b/nuttx/examples/nxflat/tests/task/Makefile
@@ -0,0 +1,59 @@
+############################################################################
+# examples/nxflat/tests/task/Makefile
+#
+# Copyright (C) 2009 Gregory Nutt. All rights reserved.
+# Author: 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)/.config # Current configuration
+-include $(TOPDIR)/Make.defs # Basic make info
+include ../Make.defs # NXFLAT make info
+
+BIN = task
+
+SRCS = $(BIN).c
+OBJS = $(SRCS:.c=.o)
+
+all: $(BIN)
+
+$(OBJS): %.o: %.c
+ $(NXFLATCC) -c $(NXFLATCFLAGS) $< -o $@
+
+$(BIN): $(OBJS)
+ $(NXFLATLD) $(NXFLATLDFLAGS) -o $@ $(OBJS)
+
+clean:
+ rm -f $(BIN) *.o core
+
+install:
+ install -D $(BIN) $(ROMFS_DIR)/$(BIN)
+
+
diff --git a/nuttx/examples/nxflat/tests/task/task.c b/nuttx/examples/nxflat/tests/task/task.c
new file mode 100644
index 000000000..28ec88d5f
--- /dev/null
+++ b/nuttx/examples/nxflat/tests/task/task.c
@@ -0,0 +1,124 @@
+/****************************************************************************
+ * examples/nxflat/tests/task/parent.c
+ *
+ * Copyright (C) 2009 Gregory Nutt. All rights reserved.
+ * Author: 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sched.h>
+#include <semaphore.h>
+#include <errno.h>
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static char child_arg[] = "Hello from your parent!";
+static sem_t g_sem;
+
+/****************************************************************************
+ * Privite Functions
+ ****************************************************************************/
+
+int child_task(int argc, char **argv, char **envp)
+{
+ printf("Child: execv was successful!\n");
+ printf("Child: argc=%d\n", argc);
+
+ if (argc != 2)
+ {
+ printf("Child: expected argc to be 2\n");
+ printf("Child: Exit-ting with status=2\n");
+ exit(2);
+ }
+
+ printf("Child: argv[0]=\"%s\"\n", argv[0]);
+
+ if (strcmp(argv[0], my_path) != 0)
+ {
+ printf("Child: expected argv[0] to be \"%s\"\n", my_path);
+ printf("Child: Exit-ting with status=3\n");
+ exit(3);
+ }
+
+ printf("Child: argv[1]=\"%s\"\n", argv[1]);
+
+ if (strcmp(argv[1], child_arg) != 0)
+ {
+ printf("Child: expected argv[1] to be \"%s\"\n", parent_arg);
+ printf("Child: Exit-ting with status=4\n");
+ exit(4);
+ }
+
+ printf("Child: Exit-ting with status=0\n");
+ sem_post(&g_sem);
+ return 0;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+int main(int argc, char **argv, char **envp)
+{
+ pid_t parent_pid = getpid();
+ char *child_argv[2];
+ int ret;
+
+ printf("Parent: Started, pid=%d\n", parent_pid);
+
+ sem_init(&g_sem, 0, 0);
+
+ printf("Parent: Calling task_create()\n");
+
+ child_argv[0] = child_arg;
+ child_argv[1] = 0;
+ ret = task_create("child", 50, 512, child_task, &child_arg);
+ if (ret != 0)
+ {
+ printf("Parent: task_create failed: %d\n", errno);
+ }
+
+ printf("Parent: Waiting for child\n");
+ sem_wait(&g_sem);
+ printf("Parent: Exiting\n");
+ sem_destroy(&g_sem);
+ return 0;
+}
+