summaryrefslogtreecommitdiff
path: root/nuttx/include
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-02-17 23:21:28 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-02-17 23:21:28 +0000
commite3940eb2080711edac189cca3f642ee89dc215f2 (patch)
tree1c390958fae49e34dce698b175487e6d4681e540 /nuttx/include
parent2223612deb2cc6322992f8595b6d6f86fcb53ae1 (diff)
downloadpx4-nuttx-e3940eb2080711edac189cca3f642ee89dc215f2.tar.gz
px4-nuttx-e3940eb2080711edac189cca3f642ee89dc215f2.tar.bz2
px4-nuttx-e3940eb2080711edac189cca3f642ee89dc215f2.zip
NuttX RTOS
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/include')
-rw-r--r--nuttx/include/assert.h96
-rw-r--r--nuttx/include/ctype.h187
-rw-r--r--nuttx/include/debug.h103
-rw-r--r--nuttx/include/errno.h198
-rw-r--r--nuttx/include/mqueue.h120
-rw-r--r--nuttx/include/nuttx/arch.h433
-rw-r--r--nuttx/include/nuttx/compiler.h73
-rw-r--r--nuttx/include/nuttx/fs.h215
-rw-r--r--nuttx/include/nuttx/irq.h107
-rw-r--r--nuttx/include/nuttx/kmalloc.h94
-rw-r--r--nuttx/include/nuttx/lib.h79
-rw-r--r--nuttx/include/nuttx/os_external.h85
-rw-r--r--nuttx/include/pthread.h326
-rw-r--r--nuttx/include/queue.h118
-rw-r--r--nuttx/include/sched.h308
-rw-r--r--nuttx/include/semaphore.h103
-rw-r--r--nuttx/include/signal.h176
-rw-r--r--nuttx/include/stddef.h49
-rw-r--r--nuttx/include/stdio.h285
-rw-r--r--nuttx/include/stdlib.h116
-rw-r--r--nuttx/include/string.h94
-rw-r--r--nuttx/include/sys/types.h143
-rw-r--r--nuttx/include/time.h126
-rw-r--r--nuttx/include/unistd.h84
-rw-r--r--nuttx/include/wdog.h95
25 files changed, 3813 insertions, 0 deletions
diff --git a/nuttx/include/assert.h b/nuttx/include/assert.h
new file mode 100644
index 000000000..831b57485
--- /dev/null
+++ b/nuttx/include/assert.h
@@ -0,0 +1,96 @@
+/************************************************************
+ * assert.h
+ *
+ * Copyright (C) 2007 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 Gregory Nutt 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 __ASSERT_H
+#define __ASSERT_H
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+#include <sys/types.h>
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/* Macro Name: ASSERT, ASSERTCODE, et al. */
+
+#undef ASSERT
+#undef ASSERTFILE
+#undef ASSERTCODE
+#undef DEBUGASSERT
+
+#define ASSERT(f) \
+ { if (!(f)) up_assert((const ubyte *)__FILE__, (uint32)__LINE__); }
+
+#define ASSERTCODE(f, errCode) \
+ { if (!(f)) up_assert_code((const ubyte *)__FILE__, (uint32)__LINE__, errCode); }
+
+#ifdef CONFIG_DEBUG
+#define DEBUGASSERT(f) \
+ { if (!(f)) up_assert((const ubyte *)__FILE__, (uint32)__LINE__); }
+#else
+#define DEBUGASSERT(f)
+#endif /* CONFIG_DEBUG */
+
+#define PANIC(errCode) \
+ up_assert_code((const ubyte *)__FILE__, (uint32)__LINE__, ((errCode)|(0x8000)))
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+/************************************************************
+ * Global Function Prototypes
+ ************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+EXTERN void up_assert(const ubyte *fileName, uint32 lineNum);
+EXTERN void up_assert_code(const ubyte *fileName, uint32 lineNum,
+ uint16 errorCode);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __ASSERT_H */
diff --git a/nuttx/include/ctype.h b/nuttx/include/ctype.h
new file mode 100644
index 000000000..c9acca9e7
--- /dev/null
+++ b/nuttx/include/ctype.h
@@ -0,0 +1,187 @@
+/************************************************************
+ * ctype.h
+ *
+ * Copyright (C) 2007 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 Gregory Nutt 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 __CTYPE_H
+#define __CTYPE_H
+
+/* There is no consistent ctype implementation, just a
+ * smattering of functions. Individually, they are okay, but
+ * a more standard, data lookup approach would make more sense
+ * if used extensively.
+ */
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+#include <sys/types.h>
+
+/************************************************************
+ * Public Type Definitions
+ ************************************************************/
+
+/************************************************************
+ * Function: isspace
+ *
+ * Description:
+ * Checks for white-space characters. In the "C" and "POSIX"
+ * locales, these are: space, form-feed ('\f'), newline ('\n'),
+ * carriage return ('\r'), horizontal tab ('\t'), and vertical
+ * tab ('\v').
+ *
+ ************************************************************/
+
+static inline int isspace(int c)
+{
+ if (c == ' ' || c == '\t' || c == '\n' || \
+ c == '\r' || c == '\f' || c == '\v')
+ {
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+}
+
+/************************************************************
+ * Function: isdigit
+ *
+ * Description:
+ * ANSI standard isdigit implementation.
+ *
+ ************************************************************/
+
+static inline int isdigit(int c)
+{
+ return (c >= '0' && c <= '9');
+}
+
+/************************************************************
+ * Function: isascii
+ *
+ * Description:
+ * Checks whether c is a 7-bit unsigned char value that
+ * fits into the ASCII character set.
+ *
+ ************************************************************/
+
+static inline int isascii(int c)
+{
+ return (c >= 0 && c <= 0177);
+}
+
+
+/************************************************************
+ * Function: isascii
+ *
+ * Description:
+ * isxdigit() checks for a hexadecimal digits, i.e. one of
+ * {0-9,a-f,A-F}
+ *
+ ************************************************************/
+
+static inline int isxdigit(int c)
+{
+ if ((c >= '0' && c <= '9') ||
+ (c >= 'a' && c <= 'f') ||
+ (c >= 'A' && c <= 'F'))
+ {
+ return 1;
+ }
+ else
+ {
+
+ return 0;
+ }
+}
+
+/************************************************************
+ * Function: isascii
+ *
+ * Description:
+ * toupper() converts the letter c to upper case, if possible.
+ *
+ ************************************************************/
+
+static inline int toupper(int c)
+{
+ if (c >= 'a' && c <= 'z')
+ {
+ return c - 'a' + 'A';
+ }
+ else
+ {
+ return c;
+ }
+}
+
+/************************************************************
+ * Function: isascii
+ *
+ * Description:
+ * tolower() converts the letter c to lower case, if possible.
+ *
+ ************************************************************/
+
+static inline int tolower(int c)
+{
+ if (c >= 'A' && c <= 'Z')
+ {
+ return c - 'A' + 'a';
+ }
+ else
+ {
+ return c;
+ }
+}
+
+/************************************************************
+ * Public Functions
+ ************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CTYPE_H */
diff --git a/nuttx/include/debug.h b/nuttx/include/debug.h
new file mode 100644
index 000000000..db47bf6b1
--- /dev/null
+++ b/nuttx/include/debug.h
@@ -0,0 +1,103 @@
+/************************************************************
+ * debug.h
+ *
+ * Copyright (C) 2007 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 Gregory Nutt 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 __DEBUG_H
+#define __DEBUG_H
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+#include <nuttx/config.h>
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/* Debug macros to runtime filter the opsys debug messages */
+
+#ifdef CONFIG_DEBUG
+# define dbg(format, arg...) lib_rawprintf(format, ##arg)
+
+# ifdef CONFIG_ARCH_LOWPUTC
+# define lldbg(format, arg...) lib_lowprintf(format, ##arg)
+# else
+# define lldbg(x...)
+# endif
+
+# ifdef CONFIG_DEBUG_VERBOSE
+# define vdbg(format, arg...) lib_rawprintf(format, ##arg)
+# else
+# define vdbg(x...)
+# endif
+
+#else
+# define dbg(x...)
+# define lldbg(x...)
+# define vdbg(x...)
+#endif
+
+/************************************************************
+ * Public Type Declarations
+ ************************************************************/
+
+/************************************************************
+ * Public Variables
+ ************************************************************/
+
+/************************************************************
+ * Public Function Prototypes
+ ************************************************************/
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+EXTERN int lib_rawprintf(const char *format, ...);
+
+#ifdef CONFIG_ARCH_LOWPUTC
+EXTERN int lib_lowprintf(const char *format, ...);
+#endif
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __DEBUG_H */
diff --git a/nuttx/include/errno.h b/nuttx/include/errno.h
new file mode 100644
index 000000000..50fddfc9f
--- /dev/null
+++ b/nuttx/include/errno.h
@@ -0,0 +1,198 @@
+/************************************************************
+ * errno.h
+ *
+ * Copyright (C) 2007 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 Gregory Nutt 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 __ERRNO_H
+#define __ERRNO_H
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+#define EPERM 1 /* Operation not permitted */
+#define ENOENT 2 /* No such file or directory */
+#define ESRCH 3 /* No such process */
+#define EINTR 4 /* Interrupted system call */
+#define EIO 5 /* I/O error */
+#define ENXIO 6 /* No such device or address */
+#define E2BIG 7 /* Arg list too long */
+#define ENOEXEC 8 /* Exec format error */
+#define EBADF 9 /* Bad file number */
+#define ECHILD 10 /* No child processes */
+#define EAGAIN 11 /* Try again */
+#define ENOMEM 12 /* Out of memory */
+#define EACCES 13 /* Permission denied */
+#define EFAULT 14 /* Bad address */
+#define ENOTBLK 15 /* Block device required */
+#define EBUSY 16 /* Device or resource busy */
+#define EEXIST 17 /* File exists */
+#define EXDEV 18 /* Cross-device link */
+#define ENODEV 19 /* No such device */
+#define ENOTDIR 20 /* Not a directory */
+#define EISDIR 21 /* Is a directory */
+#define EINVAL 22 /* Invalid argument */
+#define ENFILE 23 /* File table overflow */
+#define EMFILE 24 /* Too many open files */
+#define ENOTTY 25 /* Not a typewriter */
+#define ETXTBSY 26 /* Text file busy */
+#define EFBIG 27 /* File too large */
+#define ENOSPC 28 /* No space left on device */
+#define ESPIPE 29 /* Illegal seek */
+#define EROFS 30 /* Read-only file system */
+#define EMLINK 31 /* Too many links */
+#define EPIPE 32 /* Broken pipe */
+#define EDOM 33 /* Math argument out of domain of func */
+#define ERANGE 34 /* Math result not representable */
+#define EDEADLK 35 /* Resource deadlock would occur */
+#define ENAMETOOLONG 36 /* File name too long */
+#define ENOLCK 37 /* No record locks available */
+#define ENOSYS 38 /* Function not implemented */
+#define ENOTEMPTY 39 /* Directory not empty */
+#define ELOOP 40 /* Too many symbolic links encountered */
+#define EWOULDBLOCK EAGAIN /* Operation would block */
+#define ENOMSG 42 /* No message of desired type */
+#define EIDRM 43 /* Identifier removed */
+#define ECHRNG 44 /* Channel number out of range */
+#define EL2NSYNC 45 /* Level 2 not synchronized */
+#define EL3HLT 46 /* Level 3 halted */
+#define EL3RST 47 /* Level 3 reset */
+#define ELNRNG 48 /* Link number out of range */
+#define EUNATCH 49 /* Protocol driver not attached */
+#define ENOCSI 50 /* No CSI structure available */
+#define EL2HLT 51 /* Level 2 halted */
+#define EBADE 52 /* Invalid exchange */
+#define EBADR 53 /* Invalid request descriptor */
+#define EXFULL 54 /* Exchange full */
+#define ENOANO 55 /* No anode */
+#define EBADRQC 56 /* Invalid request code */
+#define EBADSLT 57 /* Invalid slot */
+
+#define EDEADLOCK EDEADLK
+
+#define EBFONT 59 /* Bad font file format */
+#define ENOSTR 60 /* Device not a stream */
+#define ENODATA 61 /* No data available */
+#define ETIME 62 /* Timer expired */
+#define ENOSR 63 /* Out of streams resources */
+#define ENONET 64 /* Machine is not on the network */
+#define ENOPKG 65 /* Package not installed */
+#define EREMOTE 66 /* Object is remote */
+#define ENOLINK 67 /* Link has been severed */
+#define EADV 68 /* Advertise error */
+#define ESRMNT 69 /* Srmount error */
+#define ECOMM 70 /* Communication error on send */
+#define EPROTO 71 /* Protocol error */
+#define EMULTIHOP 72 /* Multihop attempted */
+#define EDOTDOT 73 /* RFS specific error */
+#define EBADMSG 74 /* Not a data message */
+#define EOVERFLOW 75 /* Value too large for defined data type */
+#define ENOTUNIQ 76 /* Name not unique on network */
+#define EBADFD 77 /* File descriptor in bad state */
+#define EREMCHG 78 /* Remote address changed */
+#define ELIBACC 79 /* Can not access a needed shared library */
+#define ELIBBAD 80 /* Accessing a corrupted shared library */
+#define ELIBSCN 81 /* .lib section in a.out corrupted */
+#define ELIBMAX 82 /* Attempting to link in too many shared libraries */
+#define ELIBEXEC 83 /* Cannot exec a shared library directly */
+#define EILSEQ 84 /* Illegal byte sequence */
+#define ERESTART 85 /* Interrupted system call should be restarted */
+#define ESTRPIPE 86 /* Streams pipe error */
+#define EUSERS 87 /* Too many users */
+#define ENOTSOCK 88 /* Socket operation on non-socket */
+#define EDESTADDRREQ 89 /* Destination address required */
+#define EMSGSIZE 90 /* Message too long */
+#define EPROTOTYPE 91 /* Protocol wrong type for socket */
+#define ENOPROTOOPT 92 /* Protocol not available */
+#define EPROTONOSUPPORT 93 /* Protocol not supported */
+#define ESOCKTNOSUPPORT 94 /* Socket type not supported */
+#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
+#define EPFNOSUPPORT 96 /* Protocol family not supported */
+#define EAFNOSUPPORT 97 /* Address family not supported by protocol */
+#define EADDRINUSE 98 /* Address already in use */
+#define EADDRNOTAVAIL 99 /* Cannot assign requested address */
+#define ENETDOWN 100 /* Network is down */
+#define ENETUNREACH 101 /* Network is unreachable */
+#define ENETRESET 102 /* Network dropped connection because of reset */
+#define ECONNABORTED 103 /* Software caused connection abort */
+#define ECONNRESET 104 /* Connection reset by peer */
+#define ENOBUFS 105 /* No buffer space available */
+#define EISCONN 106 /* Transport endpoint is already connected */
+#define ENOTCONN 107 /* Transport endpoint is not connected */
+#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
+#define ETOOMANYREFS 109 /* Too many references: cannot splice */
+#define ETIMEDOUT 110 /* Connection timed out */
+#define ECONNREFUSED 111 /* Connection refused */
+#define EHOSTDOWN 112 /* Host is down */
+#define EHOSTUNREACH 113 /* No route to host */
+#define EALREADY 114 /* Operation already in progress */
+#define EINPROGRESS 115 /* Operation now in progress */
+#define ESTALE 116 /* Stale NFS file handle */
+#define EUCLEAN 117 /* Structure needs cleaning */
+#define ENOTNAM 118 /* Not a XENIX named type file */
+#define ENAVAIL 119 /* No XENIX semaphores available */
+#define EISNAM 120 /* Is a named type file */
+#define EREMOTEIO 121 /* Remote I/O error */
+#define EDQUOT 122 /* Quota exceeded */
+
+#define ENOMEDIUM 123 /* No medium found */
+#define EMEDIUMTYPE 124 /* Wrong medium type */
+
+/************************************************************
+ * Type Declarations
+ ************************************************************/
+
+/************************************************************
+ * Global Function Prototypes
+ ************************************************************/
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+extern int *get_errno_ptr(void);
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __ERRNO_H */
diff --git a/nuttx/include/mqueue.h b/nuttx/include/mqueue.h
new file mode 100644
index 000000000..3e54ba6e8
--- /dev/null
+++ b/nuttx/include/mqueue.h
@@ -0,0 +1,120 @@
+/************************************************************
+ * mqueue.h
+ *
+ * Copyright (C) 2007 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 Gregory Nutt 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 __MQUEUE_H
+#define __MQUEUE_H
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+#include <sys/types.h>
+#include <signal.h>
+#include "queue.h"
+
+/************************************************************
+ * Compilations Switches
+ ************************************************************/
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/************************************************************
+ * Global Type Declarations
+ ************************************************************/
+
+/* Message queue attributes */
+
+struct mq_attr
+{
+ size_t mq_maxmsg; /* Max number of messages in queue */
+ size_t mq_msgsize; /* Max message size */
+ unsigned mq_flags; /* Queue flags */
+ size_t mq_curmsgs; /* Number of messages currently in queue */
+};
+
+/* The following is used to attach a signal to a message queue
+ * to notify a task when a message is available on a queue
+ */
+
+struct sigevent {
+ int sigev_signo;
+ union sigval sigev_value;
+ int sigev_notify;
+};
+
+/* Message queue descriptor */
+
+typedef struct mq_des *mqd_t;
+
+/************************************************************
+ * Global Variables
+ ************************************************************/
+
+/************************************************************
+ * Global Function Prototypes
+ ************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+EXTERN mqd_t mq_open(const char *mq_name,
+ int oflags, ... );
+EXTERN int mq_close(mqd_t mqdes );
+EXTERN int mq_unlink(const char *mq_name );
+EXTERN int mq_send(mqd_t mqdes, const void *msg,
+ size_t msglen, int prio );
+EXTERN int mq_receive(mqd_t mqdes, void *msg,
+ size_t msglen, int *prio );
+EXTERN int mq_notify(mqd_t mqdes,
+ const struct sigevent *notification );
+EXTERN int mq_setattr(mqd_t mqdes,
+ const struct mq_attr *mq_stat,
+ struct mq_attr *oldstat);
+EXTERN int mq_getattr(mqd_t mqdes,
+ struct mq_attr *mq_stat);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __MQUEUE_H */
+
diff --git a/nuttx/include/nuttx/arch.h b/nuttx/include/nuttx/arch.h
new file mode 100644
index 000000000..30f47029a
--- /dev/null
+++ b/nuttx/include/nuttx/arch.h
@@ -0,0 +1,433 @@
+/************************************************************
+ * arch.h
+ *
+ * Copyright (C) 2007 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 Gregory Nutt 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 __ARCH_H
+#define __ARCH_H
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+#include <nuttx/config.h>
+#include <sys/types.h>
+#include <sched.h>
+#include <arch/arch.h>
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/************************************************************
+ * Inline functions
+ ************************************************************/
+
+/************************************************************
+ * Public Types
+ ************************************************************/
+
+/************************************************************
+ * Public Variables
+ ************************************************************/
+
+typedef void (*sig_deliver_t)(_TCB *tcb);
+
+/************************************************************
+ * Public Function Prototypes
+ ************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/************************************************************
+ * These are standard interfaces that must be exported to the
+ * scheduler from architecture-specific code.
+ ************************************************************/
+
+/************************************************************
+ * Name: up_initialize
+ *
+ * Description:
+ * up_initialize will be called once during OS
+ * initialization after the basic OS services have been
+ * initialized. The architecture specific details of
+ * initializing the OS will be handled here. Such things as
+ * setting up interrupt service routines, starting the
+ * clock, and registering device drivers are some of the
+ * things that are different for each processor and hardware
+ * platform.
+ *
+ * up_initialize is called after the OS initialized but
+ * before the init process has been started and before the
+ * libraries have been initialized. OS services and driver
+ * services are available.
+ *
+ ************************************************************/
+
+EXTERN void up_initialize(void);
+
+/************************************************************
+ * Name: up_idle
+ *
+ * Description:
+ * up_idle() is the logic that will be executed
+ * when their is no other ready-to-run task. This is processor
+ * idle time and will continue until some interrupt occurs to
+ * cause a context switch from the idle task.
+ *
+ * Processing in this state may be processor-specific. e.g.,
+ * this is where power management operations might be performed.
+ *
+ ************************************************************/
+
+EXTERN void up_idle(void);
+
+/************************************************************
+ * Name: up_initial_state
+ *
+ * Description:
+ * A new thread is being started and a new TCB
+ * has been created. This function is called to initialize
+ * the processor specific portions of the new TCB.
+ *
+ * This function must setup the intial architecture registers
+ * and/or stack so that execution will begin at tcb->start
+ * on the next context switch.
+ *
+ ************************************************************/
+
+EXTERN void up_initial_state(_TCB *tcb);
+
+/************************************************************
+ * Name: up_create_stack
+ *
+ * Description:
+ * Allocate a stack for a new thread and setup
+ * up stack-related information in the TCB.
+ *
+ * The following TCB fields must be initialized:
+ * adj_stack_size: Stack size after adjustment for hardware,
+ * processor, etc. This value is retained only for debug
+ * purposes.
+ * stack_alloc_ptr: Pointer to allocated stack
+ * adj_stack_ptr: Adjusted StatckAllocPtr for HW. The
+ * initial value of the stack pointer.
+ *
+ * Inputs:
+ * tcb: The TCB of new task
+ * stack_size: The requested stack size. At least this much
+ * must be allocated.
+ ************************************************************/
+
+EXTERN STATUS up_create_stack(_TCB *tcb, uint32 stack_size);
+
+/************************************************************
+ * Name: up_use_stack
+ *
+ * Description:
+ * Setup up stack-related information in the TCB
+ * using pre-allocated stack memory
+ *
+ * The following TCB fields must be initialized:
+ * adj_stack_size: Stack size after adjustment for hardware,
+ * processor, etc. This value is retained only for debug
+ * purposes.
+ * stack_alloc_ptr: Pointer to allocated stack
+ * adj_stack_ptr: Adjusted StatckAllocPtr for HW. The
+ * initial value of the stack pointer.
+ *
+ * Inputs:
+ * tcb: The TCB of new task
+ * stack_size: The allocated stack size.
+ *
+ ************************************************************/
+
+EXTERN STATUS up_use_stack(_TCB *tcb, uint32 *stack, uint32 stack_size);
+
+/************************************************************
+ * Name: up_release_stack
+ *
+ * Description:
+ * A task has been stopped. Free all stack
+ * related resources retained int the defunct TCB.
+ *
+ ************************************************************/
+
+EXTERN void up_release_stack(_TCB *dtcb);
+
+/************************************************************
+ * Name: up_unblock_task
+ *
+ * Description:
+ * A task is currently in an inactive task list
+ * but has been prepped to execute. Move the TCB to the
+ * ready-to-run list, restore its context, and start execution.
+ *
+ * Inputs:
+ * tcb: Refers to the tcb to be unblocked. This tcb is
+ * in one of the waiting tasks lists. It must be moved to
+ * the ready-to-run list and, if it is the highest priority
+ * ready to run taks, executed.
+ *
+ ************************************************************/
+
+EXTERN void up_unblock_task(_TCB *tcb);
+
+/************************************************************
+ * Name: up_block_task
+ *
+ * Description:
+ * The currently executing task at the head of
+ * the ready to run list must be stopped. Save its context
+ * and move it to the inactive list specified by task_state.
+ *
+ * Inputs:
+ * tcb: Refers to a task in the ready-to-run list (normally
+ * the task at the the head of the list). It most be
+ * stopped, its context saved and moved into one of the
+ * waiting task lists. It it was the task at the head
+ * of the ready-to-run list, then a context to the new
+ * ready to run task must be performed.
+ * task_state: Specifies which waiting task list should be
+ * hold the blocked task TCB.
+ *
+ ************************************************************/
+
+EXTERN void up_block_task(_TCB *tcb, tstate_t task_state);
+
+/************************************************************
+ * Name: up_release_pending
+ *
+ * Description:
+ * Release and ready-to-run tasks that have
+ * collected in the pending task list. This can call a
+ * context switch if a new task is placed at the head of
+ * the ready to run list.
+ *
+ ************************************************************/
+
+EXTERN void up_release_pending(void);
+
+/************************************************************
+ * Name: up_reprioritize_rtr
+ *
+ * Description:
+ * Called when the priority of a running or
+ * ready-to-run task changes and the reprioritization will
+ * cause a context switch. Two cases:
+ *
+ * 1) The priority of the currently running task drops and the next
+ * task in the ready to run list has priority.
+ * 2) An idle, ready to run task's priority has been raised above the
+ * the priority of the current, running task and it now has the
+ * priority.
+ *
+ * Inputs:
+ * tcb: The TCB of the task that has been reprioritized
+ * priority: The new task priority
+ *
+ ************************************************************/
+
+EXTERN void up_reprioritize_rtr(_TCB *tcb, ubyte priority);
+
+/************************************************************
+ * Name: _exit
+ *
+ * Description:
+ * This function causes the currently executing task to cease
+ * to exist. This is a special case of task_delete().
+ *
+ ************************************************************/
+/* Prototype is in unistd.h */
+
+/************************************************************
+ * Name: ip_assert and up_assert_code
+ *
+ * Description:
+ * Assertions may be handled in an architecture-specific
+ * way.
+ *
+ ************************************************************/
+/* Prototype is in assert.h */
+
+/************************************************************
+ * Name: up_schedule_sigaction
+ *
+ * Description:
+ * This function is called by the OS when one or more
+ * signal handling actions have been queued for execution.
+ * The architecture specific code must configure things so
+ * that the 'igdeliver' callback is executed on the thread
+ * specified by 'tcb' as soon as possible.
+ *
+ * This function may be called from interrupt handling logic.
+ *
+ * This operation should not cause the task to be unblocked
+ * nor should it cause any immediate execution of sigdeliver.
+ * Typically, a few cases need to be considered:
+ *
+ * (1) This function may be called from an interrupt handler
+ * During interrupt processing, all xcptcontext structures
+ * should be valid for all tasks. That structure should
+ * be modified to invoke sigdeliver() either on return
+ * from (this) interrupt or on some subsequent context
+ * switch to the recipient task.
+ * (2) If not in an interrupt handler and the tcb is NOT
+ * the currently executing task, then again just modify
+ * the saved xcptcontext structure for the recipient
+ * task so it will invoke sigdeliver when that task is
+ * later resumed.
+ * (3) If not in an interrupt handler and the tcb IS the
+ * currently executing task -- just call the signal
+ * handler now.
+ *
+ ************************************************************/
+
+EXTERN void up_schedule_sigaction(_TCB *tcb, sig_deliver_t sigdeliver);
+
+/************************************************************
+ * Name: up_allocate_heap
+ *
+ * Description:
+ * The heap may be statically allocated by
+ * defining CONFIG_HEAP_BASE and CONFIG_HEAP_SIZE. If these
+ * are not defined, then this function will be called to
+ * dynamically set aside the heap region.
+ *
+ ************************************************************/
+
+#ifndef CONFIG_HEAP_BASE
+EXTERN void up_allocate_heap(void **heap_start, size_t *heap_size);
+#endif
+
+/************************************************************
+ * Name: up_interrupt_context
+ *
+ * Description:
+ * Return TRUE is we are currently executing in
+ * the interrupt handler context.
+ *
+ ************************************************************/
+
+EXTERN boolean up_interrupt_context(void);
+
+/************************************************************
+ * Name: up_disable_irq
+ *
+ * Description:
+ * Disable the IRQ specified by 'irq'
+ *
+ ************************************************************/
+
+EXTERN void up_disable_irq(int irq);
+
+/************************************************************
+ * Name: up_enable_irq
+ *
+ * Description:
+ * Enable the IRQ specified by 'irq'
+ *
+ ************************************************************/
+
+EXTERN void up_enable_irq(int irq);
+
+/************************************************************
+ * Name: up_acknowledge_irq
+ *
+ * Description:
+ * Disable the IRQ specified by 'irq'
+ *
+ ************************************************************/
+
+EXTERN void up_disable_irq(int irq);
+
+/************************************************************
+ * These are standard interfaces that are exported by the OS
+ * for use by the architecture specific logic
+ ************************************************************/
+
+/************************************************************
+ * Name: sched_process_timer
+ *
+ * Description:
+ * This function handles system timer events.
+ * The timer interrupt logic itself is implemented in the
+ * architecture specific code, but must call the following OS
+ * function periodically -- the calling interval must be
+ * MSEC_PER_TICK.
+ *
+ ************************************************************/
+
+EXTERN void sched_process_timer(void);
+
+/************************************************************
+ * Name: irq_dispatch
+ *
+ * Description:
+ * This function must be called from the achitecture-
+ * specific logic in order to dispaly an interrupt to
+ * the appropriate, registered handling logic.
+ *
+ ***********************************************************/
+
+EXTERN void irq_dispatch(int irq, struct xcptcontext *xcp);
+
+/************************************************************
+ * Debug interfaces exported by the architecture-specific
+ * logic
+ ************************************************************/
+
+/************************************************************
+ * Name: up_putc
+ *
+ * Description:
+ * Output one character on the console
+ *
+ ************************************************************/
+
+# ifdef CONFIG_ARCH_LOWPUTC
+EXTERN int up_putc(int ch);
+#endif
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __ARCH_H */
+
diff --git a/nuttx/include/nuttx/compiler.h b/nuttx/include/nuttx/compiler.h
new file mode 100644
index 000000000..6204faa7b
--- /dev/null
+++ b/nuttx/include/nuttx/compiler.h
@@ -0,0 +1,73 @@
+/************************************************************
+ * compiler.h
+ *
+ * Copyright (C) 2007 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 Gregory Nutt 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 __COMPILER_H
+#define __COMPILER_H
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+#define weak_alias(name, aliasname) \
+ extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
+#define weak_function __attribute__ ((weak))
+#define weak_const_function __attribute__ ((weak, __const__))
+
+/************************************************************
+ * Global Function Prototypes
+ ************************************************************/
+
+/************************************************************
+ * Global Function Prototypes
+ ************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __COMPILER_H */
diff --git a/nuttx/include/nuttx/fs.h b/nuttx/include/nuttx/fs.h
new file mode 100644
index 000000000..085c050ef
--- /dev/null
+++ b/nuttx/include/nuttx/fs.h
@@ -0,0 +1,215 @@
+/************************************************************
+ * fs.h
+ *
+ * Copyright (C) 2007 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 Gregory Nutt 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 __FS_H
+#define __FS_H
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+#include <sys/types.h>
+#include <semaphore.h>
+#include <nuttx/compiler.h>
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/************************************************************
+ * Type Definitions
+ ************************************************************/
+
+/* This structure is provided by filesystems when they are
+ * registered with the system. It is used to call back to
+ * perform fs/device specific operations.
+ */
+
+struct file;
+struct file_operations
+{
+ int (*open)(struct file *);
+ int (*close)(struct file *);
+// off_t (*llseek)(struct file *, off_t, int);
+ ssize_t (*read)(struct file *, char *, size_t);
+ ssize_t (*write)(struct file *, const char *, size_t);
+// unsigned int (*poll)(struct file *, struct poll_table_struct *);
+ int (*ioctl)(struct file *, int, unsigned long);
+};
+
+/* This structure represents one inode in the Nuttx psuedo-file system */
+
+struct inode
+{
+ struct inode *i_peer; /* Pointer to inode at same level */
+ struct inode *i_child; /* Pointer to inode at lower level */
+ struct file_operations *i_ops; /* Driver file operations for inode */
+ sint16 i_crefs; /* References to inode */
+ uint16 i_flags; /* flags for inode */
+#ifdef CONFIG_FILE_MODE
+ mode_t i_mode; /* Access mode flags */
+#endif
+ void *i_private; /* Driver private data */
+ char i_name[1]; /* Name of inode (variable length) */
+};
+#define FSNODE_SIZE(n) (sizeof(struct inode) + (n))
+
+/* This is the underlying representation of a ropen file.
+ * A file descriptor is an index into an array of such types.
+ * The type associates the file descriptor to the file state
+ * and to a set of inode operations.
+ */
+
+struct file
+{
+ int f_oflags; /* Open mode flags */
+ off_t f_pos; /* File position */
+ struct inode *f_inode; /* Driver interface */
+};
+
+/* This defines a list of files indexed by the file descriptor */
+
+#if CONFIG_NFILE_DESCRIPTORS > 0
+struct filelist
+{
+ sem_t fl_sem; /* Manage access to the file list */
+ sint16 fl_crefs; /* Reference count */
+ struct file fl_files[CONFIG_NFILE_DESCRIPTORS];
+};
+#endif
+
+/* This defines the list of files used for standard C I/O
+ * We can support the standard C APIs without or without buffering
+ */
+
+/* Buffered file I/O structure */
+
+#if CONFIG_NFILE_STREAMS > 0
+struct file_struct
+{
+ int fs_filedes; /* File descriptor associated with stream */
+ mode_t fs_oflags; /* Open mode flags */
+#if CONFIG_NUNGET_CHARS > 0
+ uint8 fs_nungotten; /* The number of characters buffered for ungetc */
+ unsigned char fs_ungotten[CONFIG_NUNGET_CHARS];
+#endif
+#if CONFIG_STDIO_BUFFER_SIZE > 0
+ sem_t fs_sem; /* For thread safety */
+ pid_t fs_holder; /* Holder of sem */
+ int fs_counts; /* Number of times sem is held */
+ unsigned char *fs_bufstart; /* Pointer to start of buffer */
+ unsigned char *fs_bufend; /* Pointer to 1 past end of buffer */
+ unsigned char *fs_bufpos; /* Current position in buffer */
+ unsigned char *fs_bufread; /* Pointer to 1 past last buffered read char. */
+#endif
+};
+
+struct streamlist
+{
+ int sl_crefs; /* Reference count */
+ sem_t sl_sem; /* For thread safety */
+ struct file_struct sl_streams[CONFIG_NFILE_STREAMS];
+};
+#endif /* CONFIG_NFILE_STREAMS */
+
+/************************************************************
+ * Global Function Prototypes
+ ************************************************************/
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/* fs_inode.c ***********************************************/
+
+/* These interfaces are used by drivers to register their
+ * inodes in the inode tree.
+ */
+
+EXTERN void weak_function fs_initialize(void);
+EXTERN STATUS register_inode(const char *path,
+ struct file_operations *fops,
+ mode_t mode, void *private);
+EXTERN STATUS unregister_inode(const char *path);
+
+/* fs_open.c ************************************************/
+
+EXTERN int inode_checkflags(struct inode *inode, int oflags);
+
+/* fs_files.c ***********************************************/
+
+#if CONFIG_NFILE_DESCRIPTORS >0
+EXTERN struct filelist *files_alloclist(void);
+EXTERN int files_addreflist(struct filelist *list);
+EXTERN int files_releaselist(struct filelist *list);
+EXTERN int files_dup(struct file *filep1, struct file *filep2);
+#endif
+
+/* lib_fopen.c **********************************************/
+
+/* Used by the OS to clone stdin, stdout, stderr */
+
+#if CONFIG_NFILE_STREAMS > 0
+EXTERN struct file_struct *lib_fdopen(int fd,
+ const char *mode,
+ struct filelist *flist,
+ struct streamlist *slist);
+#endif
+
+/* lib_fflush.c *********************************************/
+
+#if CONFIG_NFILE_STREAMS > 0
+EXTERN void lib_flushall(struct streamlist *list);
+#endif
+
+/* drivers **************************************************/
+
+/* Call in of these to register the corresponding default
+ * default drivers in the drivers/ subdirectory
+ */
+
+EXTERN void devnull_register(void);
+
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __FS_H */
diff --git a/nuttx/include/nuttx/irq.h b/nuttx/include/nuttx/irq.h
new file mode 100644
index 000000000..e1b1c5a65
--- /dev/null
+++ b/nuttx/include/nuttx/irq.h
@@ -0,0 +1,107 @@
+/************************************************************
+ * irq.h
+ *
+ * Copyright (C) 2007 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 Gregory Nutt 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 __IRQ_H
+#define __IRQ_H
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+#ifndef __ASSEMBLY__
+# include <sys/types.h>
+# include <assert.h>
+#endif
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+#ifndef __ASSEMBLY__
+# define irq_detach(isr) irq_attach(isr, NULL)
+#endif
+
+/************************************************************
+ * Public Types
+ ************************************************************/
+
+/* This struct defines the way the registers are stored */
+
+#ifndef __ASSEMBLY__
+struct xcptcontext; /* forward reference */
+
+typedef int (*xcpt_t)(int irq, struct xcptcontext *xcp);
+typedef int (*swint_t)(uint32 code, uint32 parm2, uint32 parm3,
+ struct xcptcontext *xcp);
+#endif
+
+/* Now include architecture-specific types */
+
+#include <arch/irq.h>
+
+/************************************************************
+ * Inline functions
+ ************************************************************/
+
+/************************************************************
+ * Public Variables
+ ************************************************************/
+
+#ifndef __ASSEMBLY__
+struct xcptcontext *current_xcp;
+#endif
+
+/************************************************************
+ * Public Function Prototypes
+ ************************************************************/
+
+#ifndef __ASSEMBLY__
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+EXTERN int irq_attach(int irq, xcpt_t isr);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+#endif
+
+#endif /* __IRQ_H */
+
diff --git a/nuttx/include/nuttx/kmalloc.h b/nuttx/include/nuttx/kmalloc.h
new file mode 100644
index 000000000..5a48f33d2
--- /dev/null
+++ b/nuttx/include/nuttx/kmalloc.h
@@ -0,0 +1,94 @@
+/************************************************************
+ * kmalloc.h
+ *
+ * Copyright (C) 2007 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 Gregory Nutt 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 __KMALLOC_H
+#define __KMALLOC_H
+
+/************************************************************
+ * Included Functions
+ ************************************************************/
+
+#include <nuttx/config.h>
+#include <sys/types.h>
+
+/************************************************************
+ * Public Types
+ ************************************************************/
+
+/************************************************************
+ * Pulblic Function Prototypes
+ ************************************************************/
+
+#undef KMALLOC_EXTERN
+#if defined(__cplusplus)
+# define KMALLOC_EXTERN extern "C"
+extern "C" {
+#else
+# define KMALLOC_EXTERN extern
+#endif
+
+#ifndef CONFIG_ARCH_KMALLOC
+# include <stdlib.h>
+# define kmalloc(s) malloc(s)
+#else
+KMALLOC_EXTERN void *kmalloc(size_t);
+#endif
+
+#ifndef CONFIG_ARCH_KZMALLOC
+# include <stdlib.h>
+# define kzmalloc(s) zalloc(s)
+#else
+KMALLOC_EXTERN void *kzalloc(size_t);
+#endif
+
+#ifndef CONFIG_ARCH_KFREE
+# include <stdlib.h>
+# define kfree(p) free(p)
+#else
+KMALLOC_EXTERN void kfree(void*);
+#endif
+
+/* Functions defined in os_list.c ***************************/
+
+/* Handles memory freed from an interrupt handler */
+
+KMALLOC_EXTERN void sched_free(void *address);
+
+#undef KMALLOC_EXTERN
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __KMALLOC_H */
diff --git a/nuttx/include/nuttx/lib.h b/nuttx/include/nuttx/lib.h
new file mode 100644
index 000000000..52f506897
--- /dev/null
+++ b/nuttx/include/nuttx/lib.h
@@ -0,0 +1,79 @@
+/************************************************************
+ * lib.h
+ *
+ * Copyright (C) 2007 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 Gregory Nutt 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 __LIB_H
+#define __LIB_H
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs.h>
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/************************************************************
+ * Global Function Prototypes
+ ************************************************************/
+
+/************************************************************
+ * Global Function Prototypes
+ ************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/* Functions contained in lib_init.c ************************/
+
+EXTERN void weak_function lib_initialize(void);
+#if CONFIG_NFILE_STREAMS > 0
+EXTERN struct streamlist *lib_alloclist(void);
+EXTERN void lib_addreflist(struct streamlist *list);
+EXTERN void lib_releaselist(struct streamlist *list);
+#endif
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __LIB_H */
diff --git a/nuttx/include/nuttx/os_external.h b/nuttx/include/nuttx/os_external.h
new file mode 100644
index 000000000..6d96b5afb
--- /dev/null
+++ b/nuttx/include/nuttx/os_external.h
@@ -0,0 +1,85 @@
+/************************************************************
+ * os_external.h
+ *
+ * Copyright (C) 2007 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 Gregory Nutt 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 __OS_EXTERNAL_H
+#define __OS_EXTERNAL_H
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+#include <nuttx/config.h>
+#include <pthread.h>
+#include <sched.h>
+#include <nuttx/compiler.h>
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/************************************************************
+ * Global Function Prototypes
+ ************************************************************/
+
+/************************************************************
+ * Global Function Prototypes
+ ************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/* These are functions that must be supplied by the application */
+
+EXTERN void weak_function user_initialize(void);
+EXTERN int user_start(int parm1, int parm2, int parm3, int parm4);
+
+/* Functions contained in os_task.c *************************/
+
+EXTERN void os_start(void); /* OS entry point called by boot logic */
+
+/* Functions contained in mm_init.c *************************/
+
+EXTERN void mm_initialize(void *heap_start, size_t heap_size);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OS_EXTERNAL_H */
diff --git a/nuttx/include/pthread.h b/nuttx/include/pthread.h
new file mode 100644
index 000000000..c15cf3e0f
--- /dev/null
+++ b/nuttx/include/pthread.h
@@ -0,0 +1,326 @@
+/************************************************************
+ * pthread.h
+ *
+ * Copyright (C) 2007 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 Gregory Nutt 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 __PTHREAD_H
+#define __PTHREAD_H
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+#include <nuttx/config.h> /* Default settings */
+#include <sys/types.h> /* Needed for general types */
+#include <semaphore.h> /* Needed for sem_t */
+#include <time.h> /* Needed for struct timespec */
+
+/************************************************************
+ * Compilation Switches
+ ************************************************************/
+
+/* Standard POSIX switches */
+
+#ifndef _POSIX_THREADS
+#define _POSIX_THREADS
+#endif
+#ifndef _POSIX_THREAD_ATTR_STACKSIZE
+#define _POSIX_THREAD_ATTR_STACKSIZE
+#endif
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+#define PTHREAD_PROCESS_PRIVATE 0
+#define PTHREAD_PROCESS_SHARED 1
+
+#define PTHREAD_STACK_MIN CONFIG_PTHREAD_STACK_MIN
+#define PTHREAD_STACK_DEFAULT CONFIG_PTHREAD_STACK_DEFAULT
+
+#define PTHREAD_INHERIT_SCHED 0
+#define PTHREAD_EXPLICIT_SCHED 1
+
+#define PTHREAD_PRIO_NONE 0
+#define PTHREAD_PRIO_INHERIT 1
+#define PTHREAD_PRIO_PROTECT 2
+
+#define PTHREAD_DEFAULT_PRIORITY 100
+
+/* Cancellation states returned by pthread_cancelstate() */
+
+#define PTHREAD_CANCEL_ENABLE (0)
+#define PTHREAD_CANCEL_DISABLE (1)
+
+/* Thread return value when a pthread is canceled */
+
+#define PTHREAD_CANCELED ((void*)-1)
+
+/************************************************************
+ * Global Type Declarations
+ ************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/*----------------------------------------------------------*
+ PTHREAD-SPECIFIC TYPES
+ *----------------------------------------------------------*/
+
+typedef int pthread_key_t;
+typedef void *pthread_addr_t;
+typedef pthread_addr_t any_t;
+
+typedef pthread_addr_t (*pthread_startroutine_t)(pthread_addr_t);
+typedef pthread_startroutine_t pthread_func_t;
+
+struct pthread_addr_s
+{
+ unsigned long stacksize; /* Size of the stack allocated for the pthead */
+ short priority; /* Priority of the pthread */
+ ubyte policy; /* Pthread scheduler policy */
+ ubyte inheritsched; /* Inherit parent prio/policy? */
+};
+typedef struct pthread_addr_s pthread_attr_t;
+
+struct pthread_s
+{
+ int pid;
+};
+typedef struct pthread_s pthread_t;
+
+typedef int pthread_condattr_t;
+
+struct pthread_cond_s
+{
+ sem_t sem;
+};
+typedef struct pthread_cond_s pthread_cond_t;
+#define PTHREAD_COND_INITIALIZER {{0, 0xffff}}
+
+struct pthread_mutexattr_s
+{
+ int pshared;
+};
+typedef struct pthread_mutexattr_s pthread_mutexattr_t;
+
+struct pthread_mutex_s
+{
+ int pid;
+ sem_t sem;
+};
+typedef struct pthread_mutex_s pthread_mutex_t;
+#define PTHREAD_MUTEX_INITIALIZER {0, {1, 0xffff}}
+
+/************************************************************
+ * Global Variables
+ ************************************************************/
+
+/************************************************************
+ * Global Function Prototypes
+ ************************************************************/
+/*----------------------------------------------------------*
+ * Initializes a thread attributes object (attr) with default
+ * values for all of the individual attributes used by a
+ * given implementation.
+ *----------------------------------------------------------*/
+
+EXTERN int pthread_attr_init(pthread_attr_t *attr);
+
+/*----------------------------------------------------------*
+ * An attributes object can be deleted when it is no longer
+ * needed.
+ *----------------------------------------------------------*/
+
+EXTERN int pthread_attr_destroy(pthread_attr_t *attr);
+
+/*----------------------------------------------------------*
+ * Set or obtain the default scheduling algorithm
+ *----------------------------------------------------------*/
+
+EXTERN int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy);
+EXTERN int pthread_attr_getschedpolicy(pthread_attr_t *attr, int *policy);
+EXTERN int pthread_attr_setschedparam(pthread_attr_t *attr,
+ const struct sched_param *param);
+EXTERN int pthread_attr_getschedparam(pthread_attr_t *attr,
+ struct sched_param *param);
+EXTERN int pthread_attr_setinheritsched(pthread_attr_t *attr,
+ int inheritsched);
+EXTERN int pthread_attr_getinheritsched(const pthread_attr_t *attr,
+ int *inheritsched);
+
+/*----------------------------------------------------------*
+ * Set or obtain the default stack size
+ *----------------------------------------------------------*/
+
+EXTERN int pthread_attr_setstacksize(pthread_attr_t *attr, long stacksize);
+EXTERN int pthread_attr_getstacksize(pthread_attr_t *attr, long *stackaddr);
+
+/*----------------------------------------------------------*
+ * To create a thread object and runnable thread, a routine
+ * must be specified as the new thread's start routine. An
+ * argument may be passed to this routine, as an untyped
+ * address; an untyped address may also be returned as the
+ * routine's value. An attributes object may be used to
+ * specify details about the kind of thread being created.
+ *----------------------------------------------------------*/
+
+EXTERN int pthread_create(pthread_t *thread, pthread_attr_t *attr,
+ pthread_startroutine_t startRoutine,
+ pthread_addr_t arg);
+
+/*----------------------------------------------------------*
+ * A thread object may be "detached" to specify that the
+ * return value and completion status will not be requested.
+ *----------------------------------------------------------*/
+
+EXTERN int pthread_detach(pthread_t thread);
+
+/*----------------------------------------------------------*
+ * A thread may terminate it's own execution or the
+ * execution of another thread.
+ *----------------------------------------------------------*/
+
+EXTERN void pthread_exit(pthread_addr_t pvValue) __attribute__ ((noreturn));
+EXTERN int pthread_cancel(pthread_t thread);
+EXTERN int pthread_setcancelstate(int state, int *oldstate);
+EXTERN void pthread_testcancel(void);
+
+/*----------------------------------------------------------*
+ * A thread can await termination of another thread and retrieve
+ * the return value of the thread.
+ *----------------------------------------------------------*/
+
+EXTERN int pthread_join(pthread_t thread, pthread_addr_t *ppvValue);
+
+/*----------------------------------------------------------*
+ * A thread may tell the scheduler that its processor can be
+ * made available.
+ *----------------------------------------------------------*/
+
+EXTERN void pthread_yield(void);
+
+/*----------------------------------------------------------*
+ * A thread may obtain a copy of its own thread handle.
+ *----------------------------------------------------------*/
+
+EXTERN pthread_t pthread_self(void);
+
+/*----------------------------------------------------------*
+ * Thread scheduling parameters
+ *----------------------------------------------------------*/
+
+EXTERN int pthread_getschedparam(pthread_t thread, int *policy,
+ struct sched_param *param);
+EXTERN int pthread_setschedparam(pthread_t thread, int policy,
+ const struct sched_param *param);
+
+/*----------------------------------------------------------*
+ * Thread-specific Data Interfaces
+ *----------------------------------------------------------*/
+
+EXTERN int pthread_key_create(pthread_key_t *key,
+ void (*destructor)(void*));
+EXTERN int pthread_setspecific(pthread_key_t key, void *value);
+EXTERN void *pthread_getspecific(pthread_key_t key);
+EXTERN int pthread_key_delete(pthread_key_t key);
+
+/*----------------------------------------------------------*
+ * Create, operate on, and destroy mutex attributes.
+ *----------------------------------------------------------*/
+
+EXTERN int pthread_mutexattr_init(pthread_mutexattr_t *attr);
+EXTERN int pthread_mutexattr_destroy(pthread_mutexattr_t *attr);
+EXTERN int pthread_mutexattr_getpshared(pthread_mutexattr_t *attr,
+ int *pshared);
+EXTERN int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr,
+ int pshared);
+
+/*----------------------------------------------------------*
+ * The following routines create, delete, lock and unlock
+ * mutexes.
+ *----------------------------------------------------------*/
+
+EXTERN int pthread_mutex_init(pthread_mutex_t *mutex,
+ pthread_mutexattr_t *attr);
+EXTERN int pthread_mutex_destroy(pthread_mutex_t *mutex);
+EXTERN int pthread_mutex_lock(pthread_mutex_t *mutex);
+EXTERN int pthread_mutex_trylock(pthread_mutex_t *mutex);
+EXTERN int pthread_mutex_unlock(pthread_mutex_t *mutex);
+
+/*----------------------------------------------------------*
+ * Operations on condition variables
+ *----------------------------------------------------------*/
+
+EXTERN int pthread_condattr_init(pthread_condattr_t *attr);
+EXTERN int pthread_condattr_destroy(pthread_condattr_t *attr);
+
+/*----------------------------------------------------------*
+ * A thread can create and delete condition variables.
+ *----------------------------------------------------------*/
+
+EXTERN int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *attr);
+EXTERN int pthread_cond_destroy(pthread_cond_t *cond);
+
+/*----------------------------------------------------------*
+ * A thread can signal to and broadcast on a condition variable.
+ *----------------------------------------------------------*/
+
+EXTERN int pthread_cond_broadcast(pthread_cond_t *cond);
+EXTERN int pthread_cond_signal(pthread_cond_t *dond);
+
+/*----------------------------------------------------------*
+ * A thread can wait for a condition variable to be signalled
+ * or broadcast.
+ *----------------------------------------------------------*/
+
+EXTERN int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
+
+/*----------------------------------------------------------*
+ * A thread can perform a timed wait on a condition variable.
+ *----------------------------------------------------------*/
+
+EXTERN int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
+ const struct timespec *abstime);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __PTHREAD_H */
+
diff --git a/nuttx/include/queue.h b/nuttx/include/queue.h
new file mode 100644
index 000000000..17f4ddec0
--- /dev/null
+++ b/nuttx/include/queue.h
@@ -0,0 +1,118 @@
+/************************************************************************
+ * queue.h
+ *
+ * Copyright (C) 2007 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 Gregory Nutt 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 __QUEUE_H
+#define __QUEUE_H
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <sys/types.h>
+
+/************************************************************************
+ * Definitions
+ ************************************************************************/
+
+#define sq_init(q) do { (q)->head = NULL; (q)->tail = NULL; } while (0)
+#define dq_init(q) do { (q)->head = NULL; (q)->tail = NULL; } while (0)
+#define sq_next(p) ((p)->flink)
+#define dq_next(p) ((p)->flink)
+#define dq_prev(p) ((p)->prev)
+
+/************************************************************************
+ * Global Type Declarations
+ ************************************************************************/
+
+struct sq_entry_s
+{
+ struct sq_entry_s *flink;
+};
+typedef struct sq_entry_s sq_entry_t;
+
+struct dq_entry_s
+{
+ struct dq_entry_s *flink, *blink;
+};
+typedef struct dq_entry_s dq_entry_t;
+
+struct sq_queue_s
+{
+ sq_entry_t *head, *tail;
+};
+typedef struct sq_queue_s sq_queue_t;
+
+struct dq_queue_s
+{
+ dq_entry_t *head, *tail;
+};
+typedef struct dq_queue_s dq_queue_t;
+
+/************************************************************************
+ * Global Function Prototypes
+ ************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+EXTERN void sq_addfirst(sq_entry_t *node, sq_queue_t *queue);
+EXTERN void dq_addfirst(dq_entry_t *node, dq_queue_t *queue);
+EXTERN void sq_addlast(sq_entry_t *node, sq_queue_t *queue);
+EXTERN void dq_addlast(dq_entry_t *node, dq_queue_t *queue);
+EXTERN void sq_addafter(sq_entry_t *prev, sq_entry_t *node,
+ sq_queue_t *queue);
+EXTERN void dq_addafter(dq_entry_t *prev, dq_entry_t *node,
+ dq_queue_t *queue);
+EXTERN void dq_addbefore(dq_entry_t *next, dq_entry_t *node,
+ dq_queue_t *queue);
+EXTERN sq_entry_t *sq_remafter(sq_entry_t *node, sq_queue_t *queue);
+EXTERN void sq_rem(sq_entry_t *node, sq_queue_t *queue);
+EXTERN void dq_rem(dq_entry_t *node, dq_queue_t *queue);
+EXTERN sq_entry_t *sq_remlast(sq_queue_t *queue);
+EXTERN dq_entry_t *dq_remlast(dq_queue_t *queue);
+EXTERN sq_entry_t *sq_remfirst(sq_queue_t *queue);
+EXTERN dq_entry_t *dq_remfirst(dq_queue_t *queue);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __QUEUE_H_ */
+
diff --git a/nuttx/include/sched.h b/nuttx/include/sched.h
new file mode 100644
index 000000000..c5d7e1163
--- /dev/null
+++ b/nuttx/include/sched.h
@@ -0,0 +1,308 @@
+/************************************************************
+ * sched.h
+ *
+ * Copyright (C) 2007 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 Gregory Nutt 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 __SCHED_H
+#define __SCHED_H
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+#include <nuttx/config.h>
+#include <queue.h>
+#include <signal.h>
+#include <semaphore.h>
+#include <pthread.h>
+#include <mqueue.h>
+#include <time.h>
+#include <nuttx/irq.h>
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/* Task Management Definitins *******************************/
+
+/* This is the number of arguments that are passed to tasks
+ * on start-up. This number was selected because this is the
+ * number of parameters that can be passed to a MIPS function
+ * in registers
+ . */
+
+#define NUM_TASK_ARGS 4
+
+/* This is the maximum number of times that a lock can be set */
+
+#define MAX_LOCK_COUNT 127
+
+/* Values for the _TCB flags flag bits */
+
+#define TCB_FLAG_PTHREAD 0x0001 /* Thread is a pthread */
+#define TCB_FLAG_NONCANCELABLE 0x0002 /* Pthread is non-cancelable */
+#define TCB_FLAG_CANCEL_PENDING 0x0004 /* Pthread cancel is pending */
+#define TCB_FLAG_ROUND_ROBIN 0x0008 /* Round robin sched enabled */
+
+/* Pthread definitions **************************************/
+
+#define PTHREAD_KEYS_MAX CONFIG_NPTHREAD_KEYS
+
+/************************************************************
+ * Global Type Definitions
+ ************************************************************/
+
+#ifndef __ASSEMBLY__
+
+/* General Task Management Types ****************************/
+
+/* This is the type of the task_state field of the TCB.
+ * NOTE: the order and content of this enumeration is
+ * critical since there are some OS tables indexed by these
+ * values.
+ */
+
+typedef enum tstate_e
+{
+ TSTATE_TASK_INVALID = 0, /* INVALID - TCB has not yet been initialized */
+
+ TSTATE_TASK_PENDING = 1, /* READY_TO_RUN - Pending preemption unlock */
+ TSTATE_TASK_READYTORUN = 2, /* READY-TO-RUN - But not running */
+ TSTATE_TASK_RUNNING = 3, /* READY_TO_RUN - Aand running */
+
+ TSTATE_TASK_INACTIVE = 4, /* BLOCKED - Initialized but not yet activated */
+ TSTATE_WAIT_SEM = 5, /* BLOCKED - Waiting for a semaphore */
+ TSTATE_WAIT_SIG = 6, /* BLOCKED - Waiting for a signal */
+ TSTATE_WAIT_MQNOTEMPTY = 7, /* BLOCKED - Waiting for a MQ to become not empty. */
+ TSTATE_WAIT_MQNOTFULL = 8 /* BLOCKED - Waiting for a MQ to become not full. */
+};
+typedef enum tstate_e tstate_t;
+
+/* The following definitions are determined by tstate_t */
+
+#define FIRST_READY_TO_RUN_STATE TSTATE_TASK_READYTORUN
+#define LAST_READY_TO_RUN_STATE TSTATE_TASK_RUNNING
+#define FIRST_BLOCKED_STATE TSTATE_TASK_INACTIVE
+#define LAST_BLOCKED_STATE TSTATE_WAIT_MQNOTFULL
+#define NUM_TASK_STATES 9
+
+/* The following is the form of a thread start-up function */
+
+typedef void (*start_t)(void);
+
+/* This is the entry point into the main thread of the task
+ * or into a created pthread within the task.
+ */
+
+union entry_u
+{
+ pthread_startroutine_t pthread;
+ main_t main;
+};
+typedef union entry_u entry_t;
+
+/* This is the type of the function that is executed with
+ * exit() is called (if registered via atexit()).
+ */
+
+typedef void (*exitfunc_t)(void);
+
+/* POSIX Message queue */
+
+typedef struct msgq_s msgq_t;
+
+/* This is the task control block (TCB) */
+
+struct _TCB
+{
+ /* Fields used to support list management ***************************/
+
+ struct _TCB *flink, *blink; /* link in DQ of TCBs */
+
+ /* Task Management Fields *******************************************/
+
+ pid_t pid; /* This is the ID of the thread */
+ start_t start; /* Thread start function */
+ entry_t entry; /* Entry Point into the thread */
+ exitfunc_t exitfunc; /* Called if exit is called. */
+ ubyte sched_priority; /* Current priority of the thread */
+ tstate_t task_state; /* Current state of the thread */
+ uint16 flags; /* Misc. general status flags */
+ sint16 lockcount; /* 0=preemptable (not-locked) */
+ void *joininfo; /* Detach-able info to support join */
+#if CONFIG_RR_INTERVAL > 0
+ int timeslice; /* RR timeslice interval remaining */
+#endif
+
+ /* Values needed to restart a task **********************************/
+
+ ubyte init_priority; /* Initial priority of the task */
+ char *argv[NUM_TASK_ARGS+1]; /* Name + start-up parameters */
+
+ /* Stack-Related Fields *********************************************/
+
+ uint32 adj_stack_size; /* Stack size after adjustment */
+ /* for hardware, processor, etc. */
+ /* (for debug purposes only) */
+ uint32 *stack_alloc_ptr; /* Pointer to allocated stack */
+ /* Need to deallocate stack */
+ uint32 *adj_stack_ptr; /* Adjusted StatckAllocPtr for HW */
+ /* The initial stack pointer value */
+
+ /* POSIX thread Specific Data ***************************************/
+
+ void *pthread_data[CONFIG_NPTHREAD_KEYS];
+
+ /* POSIX Semaphore Control Fields ***********************************/
+
+ sem_t *waitsem; /* Semaphore ID waiting on */
+
+ /* POSIX Signal Control Fields **************************************/
+
+ sigset_t sigprocmask; /* Signals that are blocked */
+ sigset_t sigwaitmask; /* Waiting for pending signals */
+ sq_queue_t sigactionq; /* List of actions for signals */
+ sq_queue_t sigpendingq; /* List of Pending Signals */
+ sq_queue_t sigpendactionq; /* List of pending signal actions */
+ sq_queue_t sigpostedq; /* List of posted signals */
+ siginfo_t sigunbinfo; /* Signal info when task unblocked */
+
+ /* POSIX Named Message Queue Fields *********************************/
+
+ sq_queue_t msgdesq; /* List of opened message queues */
+ msgq_t *msgwaitq; /* Waiting for this message queue */
+
+ /* Library related fields *******************************************/
+
+ int errno; /* Current per-thread errno */
+
+ /* File system support **********************************************/
+
+#if CONFIG_NFILE_DESCRIPTORS > 0
+ struct filelist *filelist; /* Maps file descriptor to file */
+#endif
+
+#if CONFIG_NFILE_STREAMS > 0
+ struct streamlist *streams; /* Holds C buffered I/O info */
+#endif
+
+ /* State save areas *************************************************/
+ /* The form and content of these fields are processor-specific. */
+
+ struct xcptcontext xcp; /* Interrupt register save area */
+
+#if CONFIG_TASK_NAME_SIZE > 0
+ char name[CONFIG_TASK_NAME_SIZE]; /* Task name */
+#endif
+
+};
+typedef struct _TCB _TCB;
+#endif /* __ASSEMBLY__ */
+
+/************************************************************
+ * Global Function Prototypes
+ ************************************************************/
+
+#ifndef __ASSEMBLY__
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/* Task Control Interfaces (non-standard) */
+
+EXTERN STATUS task_init(_TCB *tcb , char *name, int priority,
+ uint32 *stack, uint32 stack_size, main_t entry,
+ char *arg1, char *arg2, char *arg3, char *arg4);
+EXTERN STATUS task_activate(_TCB *tcb);
+EXTERN int task_create(char *name, int priority, int stack_size, main_t main,
+ char *arg1, char *arg2, char *arg3, char *arg4);
+EXTERN STATUS task_delete(pid_t pid);
+EXTERN STATUS task_restart(pid_t pid);
+
+/* Task Scheduling Interfaces (based on POSIX APIs) */
+
+EXTERN int sched_setparam(pid_t pid,
+ const struct sched_param * param);
+EXTERN int sched_getparam(pid_t pid,
+ struct sched_param * param);
+EXTERN int sched_setscheduler(pid_t pid, int policy,
+ const struct sched_param * param);
+EXTERN int sched_getscheduler(pid_t pid);
+EXTERN int sched_yield(void);
+EXTERN int sched_get_priority_max(int policy);
+EXTERN int sched_get_priority_min(int policy);
+EXTERN int sched_rr_get_interval(pid_t pid,
+ struct timespec * interval);
+
+/* Task Switching Interfaces (non-standard) */
+
+EXTERN STATUS sched_lock(void);
+EXTERN STATUS sched_unlock(void);
+EXTERN sint32 sched_lockcount(void);
+
+/* If instrumentation of the scheduler is enabled, then some
+ * outboard logic must provide the following interfaces.
+ */
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION
+
+EXTERN void sched_note_start(_TCB *tcb );
+EXTERN void sched_note_stop(_TCB *tcb );
+EXTERN void sched_note_switch(_TCB *pFromTcb, _TCB *pToTcb);
+
+#else
+# define sched_note_start(t)
+# define sched_note_stop(t)
+# define sched_note_switch(t1, t2)
+#endif /* CONFIG_SCHED_INSTRUMENTATION */
+
+/* File system helpers */
+
+#if CONFIG_NFILE_DESCRIPTORS > 0
+EXTERN struct filelist *sched_getfiles(void);
+#if CONFIG_NFILE_STREAMS > 0
+EXTERN struct streamlist *sched_getstreams(void);
+#endif /* CONFIG_NFILE_STREAMS */
+#endif /* CONFIG_NFILE_DESCRIPTORS */
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+#endif /* __ASSEMBLY__ */
+
+#endif /* __SCHED_H */
diff --git a/nuttx/include/semaphore.h b/nuttx/include/semaphore.h
new file mode 100644
index 000000000..92ac7ab89
--- /dev/null
+++ b/nuttx/include/semaphore.h
@@ -0,0 +1,103 @@
+/************************************************************
+ * semaphore.h
+ *
+ * Copyright (C) 2007 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 Gregory Nutt 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 __SEMAPHORE_H
+#define __SEMAPHORE_H
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+#include <sys/types.h>
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/* The maximum value that a semaphore may have. */
+
+#define SEM_MAX_VALUE 0x7fff /* Max value POSIX counting semaphore */
+
+/* The maximum number of semaphores that a task may have */
+
+#define SEM_NSEMS_MAX 0x7fffffff
+
+/************************************************************
+ * Public Type Declarations
+ ************************************************************/
+
+/* This is the generic semaphore structure. */
+
+struct sem_s
+{
+ sint16 semcount; /* >0 -> Num counts available */
+ /* <0 -> Num tasks waiting for semaphore */
+};
+typedef struct sem_s sem_t;
+
+/************************************************************
+ * Public Variables
+ ************************************************************/
+
+/************************************************************
+ * Public Function Prototypes
+ ************************************************************/
+
+/* Counting Semaphore Interfaces (based on POSIX APIs) */
+
+EXTERN int sem_init(sem_t *sem, int pshared, unsigned int value);
+EXTERN int sem_destroy(sem_t *sem);
+EXTERN sem_t *sem_open(const char *name, int oflag, ...);
+EXTERN int sem_close(sem_t *sem);
+EXTERN int sem_unlink(const char *name);
+EXTERN int sem_wait(sem_t *sem);
+EXTERN int sem_trywait(sem_t *sem);
+EXTERN int sem_post(sem_t *sem);
+EXTERN int sem_getvalue(sem_t *sem, int *sval);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SEMAPHORE_H */
+
diff --git a/nuttx/include/signal.h b/nuttx/include/signal.h
new file mode 100644
index 000000000..67236fd6c
--- /dev/null
+++ b/nuttx/include/signal.h
@@ -0,0 +1,176 @@
+/************************************************************
+ * signal.h
+ *
+ * Copyright (C) 2007 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 Gregory Nutt 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 __SIGNAL_H
+#define __SIGNAL_H
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+#include <time.h> /* Needed for struct timespec */
+#include <sys/types.h> /* Needed for, e.g., sigset_t */
+
+/************************************************************
+ * Compilations Switches
+ ************************************************************/
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/* Signal set management definitions and macros. */
+
+#define NULL_SIGNAL_SET ((sigset_t)0x00000000)
+#define ALL_SIGNAL_SET ((sigset_t)0xffffffff)
+#define MIN_SIGNO 0
+#define MAX_SIGNO 31
+#define GOOD_SIGNO(s) (((s)>=MIN_SIGNO)&&((s)<=MAX_SIGNO))
+#define SIGNO2SET(s) ((sigset_t)1 << (s))
+
+/* sigprocmask() "how" definitions. Only one of the following
+ * can be specified:
+ */
+
+#define SIG_BLOCK 1
+#define SIG_UNBLOCK 2
+#define SIG_SETMASK 3
+
+/* struct sigaction flag values */
+
+#define SA_NOCLDSTOP 1 /* Do not generate SIGCHILD when
+ * children stop (ignored) */
+#define SA_SIGINFO 2 /* Invoke the signal-catching function
+ * with 3 args instead of 1
+ * (always assumed) */
+
+/* Dummy value for the sigev_notify field of struct sigevent */
+
+#define SIGEV_SIGNAL 0
+
+/* These are the possible values of the signfo si_code field */
+
+#define SI_QUEUE 0 /* Signal sent from sigqueue */
+#define SI_MESGQ 1 /* Signal generated by arrival of a message on an
+ * empty message queue */
+#define SI_NOWAIT 2 /* Signal already pending -- don't know how sent */
+#define SI_TIMEOUT 3 /* No-signal, unblocked by timeout */
+
+/************************************************************
+ * Global Type Declarations
+ ************************************************************/
+
+/* This defines a set of 32 signals (numbered 0 through 31). */
+
+typedef uint32 sigset_t;
+
+/* This defines the type of the siginfo si_value field */
+
+union sigval
+{
+ int sival_int;
+ void *sival_ptr;
+};
+
+/* The following types is used to pass parameters to/from
+ * signal handlers
+ */
+
+typedef struct siginfo
+{
+ int si_signo;
+ int si_code;
+ union sigval si_value;
+} siginfo_t;
+
+/* The following structure defines the action to take for given signal */
+
+typedef void saHandType(int signo);
+typedef void saVxHandType(int signo, siginfo_t *info, void *context);
+struct sigaction
+{
+ union
+ {
+ saHandType *_sa_handler;
+ saVxHandType *_sa_sigaction;
+ } sa_u;
+ sigset_t sa_mask;
+ int sa_flags;
+};
+#define sa_handler sa_u._sa_handler
+#define sa_sigaction sa_u._sa_sigaction
+
+/************************************************************
+ * Global Variables
+ ************************************************************/
+
+/************************************************************
+ * Global Function Prototypes
+ ************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+EXTERN int sigemptyset(sigset_t *set);
+EXTERN int sigfillset(sigset_t *set);
+EXTERN int sigaddset(sigset_t *set, int signo);
+EXTERN int sigdelset(sigset_t *set, int signo);
+EXTERN int sigismember(const sigset_t *set, int signo);
+EXTERN int sigaction(int sig,
+ const struct sigaction *act,
+ struct sigaction *oact);
+EXTERN int sigprocmask(int how, const sigset_t *set,
+ sigset_t *oset);
+EXTERN int sigpending(sigset_t *set);
+EXTERN int sigsuspend(const sigset_t *sigmask);
+EXTERN int sigwaitinfo(const sigset_t *set,
+ struct siginfo *value);
+EXTERN int sigtimedwait(const sigset_t *set,
+ struct siginfo *value,
+ const struct timespec *timeout);
+EXTERN int sigqueue(int tid, int signo,
+ const union sigval value);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SIGNAL_H */
+
diff --git a/nuttx/include/stddef.h b/nuttx/include/stddef.h
new file mode 100644
index 000000000..09cfa5369
--- /dev/null
+++ b/nuttx/include/stddef.h
@@ -0,0 +1,49 @@
+/************************************************************
+ * stddef.h
+ *
+ * Copyright (C) 2007 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 Gregory Nutt 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 __STDDEF_H
+#define __STDDEF_H
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+#include <sys/types.h>
+
+/************************************************************
+ * Type Definitions
+ ************************************************************/
+
+#endif /* __STDDEF_H */
diff --git a/nuttx/include/stdio.h b/nuttx/include/stdio.h
new file mode 100644
index 000000000..b210dc708
--- /dev/null
+++ b/nuttx/include/stdio.h
@@ -0,0 +1,285 @@
+/************************************************************
+ * stdio.h
+ *
+ * Copyright (C) 2007 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 Gregory Nutt 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 __STDIO_H
+#define __STDIO_H
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+#include <nuttx/config.h>
+#include <sys/types.h>
+#include <stdarg.h>
+#include <sched.h>
+#include <semaphore.h>
+#include <time.h>
+
+#include <nuttx/fs.h>
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/* File System Definitions **********************************/
+
+/* File system error values *********************************/
+
+#define EOF (-1)
+
+/* File I/O constants ***************************************/
+
+#define MAXNAMLEN 100
+#define NAME_MAX 100
+#define PATH_MAX 101
+#define S_IFMT 0170000
+#define S_IFIFO 0010000
+#define S_IFCHR 0020000
+#define S_IFDIR 0040000
+#define S_IFBLK 0060000
+#define S_IFREG 0100000
+#define S_IFLNK 0120000
+#define S_IFSOCK 0140000
+#define SEEK_SET 0
+#define SEEK_CUR 1
+#define SEEK_END 2
+
+/* Wind-River IOCTL constants */
+
+#define FIOFLUSH 2
+#define FIONBIO 16
+#define FIOSELECT 28
+#define FIOUNSELECT 29
+#define FIOTRUNC 42
+#define FIOHANDLETONAME 45
+#define FIOLABELGET 33
+#define SET_HIDDEN 0x1004
+#define PHYS_BLK_IO 255
+
+#define SECTOR_ALIGN_BYTES 512
+#define FILE_BUF_SIZE (4 * SECTOR_ALIGN_BYTES)
+#define FILE_BUF_ALIGN_BYTES 16
+
+/* File type code for the EntryType field in dirent struct */
+
+#define FS_FILE_TYPE 0
+#define FS_DIRECTORY_TYPE 1
+
+/* The first three _iob entries are reserved for standard I/O */
+
+#define stdin (__stdfile(0))
+#define stdout (__stdfile(1))
+#define stderr (__stdfile(2))
+
+/* These APIs are not implemented and/or can be synthesized from
+ * supported APIs.
+ */
+
+#define putc(c,s) fputc((c),(s))
+#define putchar(c) fputc(c, stdout)
+#define getc(s) fgetc(s)
+#define getchar() fgetc(stdin)
+#define ftell(s) fseek((s),0,SEEK_CUR)
+#define rewind(s) ((void)fseek((s),0,SEEK_SET))
+#define fsync(f)
+
+/************************************************************
+ * Public Type Definitions
+ ************************************************************/
+
+/* The POSIX specification requires that the caller of readdir_r
+ * provide storage "large enough for a dirent with the d_name
+ * member and an array of char containing at least {NAME_MAX}
+ * plus one elements. The legacy dirent structure does not
+ * contain such an array. The legacy dirent structure is
+ * renamed _dirent below.
+ */
+
+struct _dirent
+{
+ char *d_name; /* name of directory entry */
+};
+struct dirent
+{
+ char *d_name; /* A pointer to szName */
+ char szName[NAME_MAX+1]; /* name of the directory entry */
+};
+
+typedef struct
+{
+ unsigned char EntryType; /* FS_FILE_TYPE or FS_DIRECTORY_TYPE */
+ char szName[NAME_MAX]; /* name of the directory entry */
+} fsdirent;
+
+typedef struct
+{
+ unsigned long inode;
+ int generation;
+ char *fileName;
+} HANDLE_TO_NAME_IOCTL;
+
+struct stat
+{
+ dev_t st_dev; /* ID of device containing a */
+ /* directory entry for this file */
+ ino_t st_ino; /* Inode number */
+ unsigned short st_mode; /* File type, attributes, and */
+ /* access control summary */
+ unsigned short st_nlink; /* Number of links */
+ uid_t st_uid; /* User ID of file owner */
+ gid_t st_gid; /* Group ID of file group */
+ dev_t st_rdev; /* Device ID; this entry defined */
+ /* only for char or blk spec files */
+ off_t st_size; /* File size (bytes) */
+ time_t st_atime; /* Time of last access */
+ time_t st_mtime; /* Last modification time */
+ time_t st_ctime; /* Last file status change time */
+ /* Measured in secs since */
+ /* 00:00:00 GMT, Jan 1, 1970 */
+ long st_blksize; /* Non-standard, Wind-River field */
+ unsigned long st_blocks; /* Non-standard, Wind-River field */
+ long st_gen; /* file generation value: Non-standard, Wind-River field */
+};
+
+struct statfs
+{
+ long f_bavail; /* free blocks available to non-superuser */
+ long f_bfree; /* free blocks */
+ long f_blocks; /* total blocks in file system */
+ long f_bsize; /* fundamental file system block (bytes) */
+ long f_ffree; /* free file nodes in file system */
+ long f_files; /* total file nodes in file system */
+ long f_type; /* type of info, zero for now */
+};
+
+/* Streams */
+
+typedef struct file_struct FILE;
+
+typedef void DIR;
+
+/************************************************************
+ * Public Variables
+ ************************************************************/
+
+/************************************************************
+ * Inline Functions
+ ************************************************************/
+
+/* Used to reference stdin, stdout, and stderr */
+
+static inline FILE *__stdfile(int fd)
+{
+ if ((unsigned int)fd < CONFIG_NFILE_DESCRIPTORS)
+ {
+ struct streamlist *streams = sched_getstreams();
+ if (streams)
+ {
+ return &streams->sl_streams[fd];
+ }
+ }
+ return NULL;
+}
+
+/************************************************************
+ * Public Function Prototypes
+ ************************************************************/
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/* ANSI-like File System Interfaces */
+
+EXTERN int fclose(FILE *stream);
+EXTERN int fflush(FILE *stream);
+EXTERN int feof(FILE *stream);
+EXTERN int ferror(FILE *stream);
+EXTERN int fgetc(FILE *stream);
+EXTERN char *fgets(char *s, int n, FILE *stream);
+EXTERN FILE *fopen(const char *path, const char *type);
+EXTERN int fprintf(FILE *stream, const char *format, ...);
+EXTERN int fputc(int c, FILE *stream);
+EXTERN int fputs(const char *s, FILE *stream);
+EXTERN size_t fread(void *ptr, size_t size, size_t n_items,
+ FILE *stream);
+EXTERN int fseek(FILE *stream, long int offset, int whence);
+EXTERN size_t fwrite(const void *ptr, size_t size,
+ size_t n_items, FILE *stream);
+EXTERN int printf(const char *format, ...);
+EXTERN int puts(const char *s);
+EXTERN int rename(const char *source, const char *target);
+EXTERN int sprintf(char *dest, const char *format, ...);
+EXTERN int ungetc(int c, FILE *stream);
+EXTERN int vprintf(const char *s, va_list ap);
+EXTERN int vfprintf(FILE *stream, const char *s, va_list ap);
+EXTERN int vsprintf(char *buf, const char *s, va_list ap);
+
+/* POSIX-like File System Interfaces */
+
+EXTERN int chdir(const char *path);
+EXTERN int close(int fd);
+EXTERN int closedir(DIR *dirp);
+EXTERN int creat(const char *path, mode_t mode);
+EXTERN FILE *fdopen(int fd, const char *type);
+EXTERN int fstat(int fd, struct stat *buf);
+EXTERN char *getcwd(char *buf, size_t size);
+EXTERN int ioctl(int fd, int req, unsigned long arg);
+EXTERN off_t lseek(int fd, off_t offset, int whence);
+EXTERN int mkdir(const char *path, mode_t mode);
+EXTERN int open( const char *path, int oflag, ... );
+EXTERN DIR *opendir(const char *path);
+EXTERN int read(int fd, void *buf, unsigned int nbytes);
+EXTERN struct _dirent *readdir(DIR *dirp);
+EXTERN int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result);
+EXTERN void rewinddir(DIR *dirp);
+EXTERN int rmdir(const char *path);
+EXTERN void seekdir(DIR *dirp, int loc);
+EXTERN int stat(const char *path, struct stat *buf);
+EXTERN int statfs(const char *path, struct statfs *buf);
+EXTERN int telldir(DIR *dirp);
+EXTERN int unlink(const char *path);
+EXTERN int write(int fd, const void *buf, unsigned int nbytes);
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __STDIO_H */
diff --git a/nuttx/include/stdlib.h b/nuttx/include/stdlib.h
new file mode 100644
index 000000000..c5cf3edda
--- /dev/null
+++ b/nuttx/include/stdlib.h
@@ -0,0 +1,116 @@
+/************************************************************
+ * stdlib.h
+ *
+ * Copyright (C) 2007 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 Gregory Nutt 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 __STDLIB_H
+#define __STDLIB_H
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+#include <sys/types.h>
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/* The C standard specifies two constants, EXIT_SUCCESS and
+ * EXIT_FAILURE, that may be passed to exit() to indicate
+ * successfuol or unsucessful termination, respectively.
+ */
+
+#define EXIT_SUCCESS 0
+#define EXIT_FAILURE 1
+
+/************************************************************
+ * Global Type Definitions
+ ************************************************************/
+
+struct mallinfo
+{
+ int arena; /* This is the total size of memory allocated
+ * for use by malloc in bytes. */
+ int ordblks; /* This is the number of free (not in use) chunks */
+ int mxordblk; /* Size of the largest free (not in use) chunk */
+ int uordblks; /* This is the total size of memory occupied by
+ * chunks handed out by malloc. */
+ int fordblks; /* This is the total size of memory occupied
+ * by free (not in use) chunks.*/
+};
+
+/************************************************************
+ * Global Function Prototypes
+ ************************************************************/
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/* Random number generation */
+EXTERN void srand(unsigned int seed);
+EXTERN int rand(void);
+
+/* Environment variable support */
+EXTERN char *getenv(const char *name);
+
+/* Process exit functions */
+EXTERN void exit(int status);
+EXTERN void abort(void);
+EXTERN int atexit(void (*func)(void));
+
+/* String to binary conversions */
+#define atoi(nptr) strtol((nptr), (char**)NULL, 10)
+EXTERN long strtol(const char *, char **, int);
+EXTERN double strtod(const char *, char **);
+
+/* Memory Management */
+EXTERN void *malloc(size_t);
+EXTERN void free(void*);
+EXTERN void *realloc(void*, size_t);
+EXTERN void *memalign(size_t, size_t);
+EXTERN void *zalloc(size_t);
+EXTERN void *calloc(size_t, size_t);
+EXTERN struct mallinfo mallinfo(void);
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __STDLIB_H */
diff --git a/nuttx/include/string.h b/nuttx/include/string.h
new file mode 100644
index 000000000..da77502fe
--- /dev/null
+++ b/nuttx/include/string.h
@@ -0,0 +1,94 @@
+/************************************************************
+ * string.h
+ *
+ * Copyright (C) 2007 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 Gregory Nutt 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 __STRING_H
+#define __STRING_H
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+#include <nuttx/config.h>
+#include <stddef.h> /* For size_t */
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+#define bzero(s,n) memset((s),0,(n))
+
+/************************************************************
+ * Global Function Prototypes
+ ************************************************************/
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+EXTERN char *strchr(const char *s, int c);
+EXTERN char *strdup(const char *s);
+EXTERN char *strerror(int);
+EXTERN size_t strlen(const char *);
+EXTERN char *strncat(char *, const char *, size_t);
+EXTERN int strcmp(const char *, const char *);
+EXTERN int strncmp(const char *, const char *, size_t);
+EXTERN char *strcpy(char *dest, const char *src);
+EXTERN char *strncpy(char *, const char *, size_t);
+EXTERN char *strpbrk(const char *, const char *);
+EXTERN char *strchr(const char *, int);
+EXTERN char *strrchr(const char *, int);
+EXTERN size_t strspn(const char *, const char *);
+EXTERN size_t strcspn(const char *, const char *);
+EXTERN char *strstr(const char *, const char *);
+EXTERN char *strtok(char *, const char *);
+
+EXTERN void *memset(void *s, int c, size_t n);
+EXTERN void *memcpy(void *dest, const void *src, size_t n);
+EXTERN int memcmp(const void *s1, const void *s2, size_t n);
+EXTERN void *memmove(void *dest, const void *src, size_t count);
+
+#ifndef CONFIG_ARCH_BZERO
+# define bzero(s,n) (void)memset(s,0,n)
+#endif
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+#endif /* __STRING_H */
diff --git a/nuttx/include/sys/types.h b/nuttx/include/sys/types.h
new file mode 100644
index 000000000..4cebb48a9
--- /dev/null
+++ b/nuttx/include/sys/types.h
@@ -0,0 +1,143 @@
+/************************************************************
+ * types.h
+ *
+ * Copyright (C) 2007 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 Gregory Nutt 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 __SYS_TYPES_H
+#define __SYS_TYPES_H
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+#include <arch/types.h>
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/* Values for type boolean */
+
+#define TRUE 1
+#define FALSE 0
+
+/* NULL is usually defined in stddef.h */
+
+#ifndef NULL
+#define NULL (void*)0L
+#endif
+
+/* POSIX-like OS return values: */
+
+#if !defined(__cplusplus)
+#undef ERROR
+#define ERROR -1
+#endif
+
+#undef OK
+#define OK 0
+
+/* POSIX-like scheduling policies (only SCHED_FIFO is supported) */
+
+#define SCHED_FIFO 1 /* FIFO per priority scheduling policy */
+#define SCHED_RR 2 /* Round robin scheduling policy */
+#define SCHED_OTHER 4 /* Not used */
+
+/* HPUX-like MIN/MAX value */
+
+#define PRIOR_RR_MIN 0
+#define PRIOR_RR_MAX 255
+#define PRIOR_FIFO_MIN 0
+#define PRIOR_FIFO_MAX 255
+#define PRIOR_OTHER_MIN 0
+#define PRIOR_OTHER_MAX 255
+
+/* Scheduling Priorities. NOTE: Only the idle task can take
+ * the TRUE minimum priority. */
+
+#define SCHED_PRIORITY_MAX 255
+#define SCHED_PRIORITY_DEFAULT 100
+#define SCHED_PRIORITY_MIN 1
+#define SCHED_PRIORITY_IDLE 0
+
+/* oflag bit settings for sem_open and mq_open */
+
+#define O_RDONLY 0x01 /* Open for read access */
+#define O_WRONLY 0x02 /* Open for write access */
+#define O_RDWR 0x03 /* Open for both read & write access */
+#define O_CREAT 0x04 /* Create semaphore/message queue */
+#define O_EXCL 0x08 /* Name must not exist when opened */
+#define O_APPEND 0x10
+#define O_TRUNC 0x20
+#define O_NONBLOCK 0x40 /* Don't wait for data */
+#define O_NDELAY O_NONBLOCK
+#define O_LOCK 0x80
+
+#define O_RDOK O_RDONLY /* Not POSIX */
+#define O_WROK O_WRONLY /* Not POSIX */
+
+/************************************************************
+ * Type Declarations
+ ************************************************************/
+
+/* Misc. scalar types */
+
+typedef uint32 mode_t;
+typedef uint32 size_t;
+typedef sint32 ssize_t;
+//typedef sint32 time_t;
+typedef sint32 off_t;
+typedef sint32 uid_t;
+typedef sint32 gid_t;
+typedef uint32 dev_t;
+typedef uint32 ino_t;
+typedef unsigned int sig_atomic_t;
+typedef int pid_t;
+typedef int STATUS;
+
+/* Process entry point */
+
+typedef int (*main_t)(int argc, char *argv[]);
+
+/* This is the POSIX-like scheduling parameter structure */
+
+struct sched_param
+{
+ int sched_priority;
+};
+
+/************************************************************
+ * Global Function Prototypes
+ ************************************************************/
+
+#endif /* __SYS_TYPES_H */
diff --git a/nuttx/include/time.h b/nuttx/include/time.h
new file mode 100644
index 000000000..0d0399e83
--- /dev/null
+++ b/nuttx/include/time.h
@@ -0,0 +1,126 @@
+/************************************************************
+ * time.h
+ *
+ * Copyright (C) 2007 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 Gregory Nutt 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 _TIME_H_
+#define _TIME_H_
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/************************************************************
+ * Compilations Switches
+ ************************************************************/
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/* This must be set to the last known date */
+
+#define CURRENT_YEAR 2000
+#define CURRENT_MONTH 5
+#define CURRENT_DAY 22
+
+/* This is the only clock_id supported by the "Clock and Timer
+ * Functions."
+ */
+
+#define CLOCK_REALTIME 0
+
+/************************************************************
+ * Global Type Declarations
+ ************************************************************/
+
+typedef long time_t;
+typedef long clockid_t;
+
+struct timespec
+{
+ time_t tv_sec; /* Seconds */
+ long tv_nsec; /* Nanoseconds */
+};
+
+struct timeval
+{
+ time_t tv_sec; /* Seconds */
+ long tv_usec; /* Microseconds */
+};
+
+struct tm
+{
+ int tm_sec; /* second (0-61, allows for leap seconds) */
+ int tm_min; /* minute (0-59) */
+ int tm_hour; /* hour (0-23) */
+ int tm_mday; /* day of the month (1-31) */
+ int tm_mon; /* month (0-11) */
+ int tm_year; /* years since 1900 */
+#if 0 /* not supported */
+ int tm_wday; /* day of the week (0-6) */
+ int tm_yday; /* day of the year (0-365) */
+ int tm_isdst; /* non-0 if daylight savings time is in effect */
+#endif
+};
+
+/************************************************************
+ * Global Variables
+ ************************************************************/
+
+/************************************************************
+ * Global Function Prototypes
+ ************************************************************/
+
+EXTERN int clock_settime(clockid_t clock_id, const struct timespec *tp);
+EXTERN int clock_gettime(clockid_t clock_id, struct timespec *tp);
+EXTERN int clock_getres(clockid_t clock_id, struct timespec *res);
+
+EXTERN time_t mktime(struct tm *tp);
+EXTERN struct tm *gmtime_r(const time_t *clock, struct tm *result);
+#define localtime_r(c,r) gmtime_r(c,r)
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* _TIME_H_ */
diff --git a/nuttx/include/unistd.h b/nuttx/include/unistd.h
new file mode 100644
index 000000000..d68b0e28b
--- /dev/null
+++ b/nuttx/include/unistd.h
@@ -0,0 +1,84 @@
+/************************************************************
+ * unistd.h
+ *
+ * Copyright (C) 2007 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 Gregory Nutt 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 __UNISTD_H
+#define __UNISTD_H
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+#include <sys/types.h>
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/* The number of functions that may be registerd to be called
+ * at program exit.
+ */
+
+#define ATEXIT_MAX 1
+
+/************************************************************
+ * Global Function Prototypes
+ ************************************************************/
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/* Task Control Interfaces (based on ANSII APIs) */
+
+EXTERN pid_t getpid( void );
+EXTERN void _exit(int status) __attribute__ ((noreturn));
+EXTERN unsigned int sleep(unsigned int seconds);
+EXTERN void usleep(unsigned long usec);
+
+/* File descriptor operations */
+
+EXTERN int dup(int fildes);
+EXTERN int dup2(int fildes1, int fildes2);
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __UNISTD_H */
diff --git a/nuttx/include/wdog.h b/nuttx/include/wdog.h
new file mode 100644
index 000000000..9ef16256c
--- /dev/null
+++ b/nuttx/include/wdog.h
@@ -0,0 +1,95 @@
+/************************************************************
+ * wdog.h
+ *
+ * Copyright (C) 2007 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 Gregory Nutt 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 __WDOG_H
+#define __WDOG_H
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+#include <nuttx/config.h>
+#include <sched.h>
+
+/************************************************************
+ * Compilations Switches
+ ************************************************************/
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/************************************************************
+ * Global Type Declarations
+ ************************************************************/
+
+/* This is the form of the function that is called when the
+ * watchdog function expires. Up to four parameters may be passed.
+ */
+
+typedef void (*wdentry_t)(int arg1, ...);
+
+/* Watchdog 'handle' */
+
+typedef struct wdog_s *WDOG_ID;
+
+/************************************************************
+ * Global Variables
+ ************************************************************/
+
+/************************************************************
+ * Global Function Prototypes
+ ************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+EXTERN WDOG_ID wd_create(void);
+EXTERN STATUS wd_delete(WDOG_ID wdId);
+EXTERN STATUS wd_start(WDOG_ID wdId, int delay, wdentry_t wdentry,
+ int parm1, int parm2, int parm3, int parm4);
+EXTERN STATUS wd_cancel(WDOG_ID wdId);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _WDOG_H_ */
+