diff options
Diffstat (limited to 'nuttx')
63 files changed, 1024 insertions, 611 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 666c83dae..f98e28187 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -60,6 +60,10 @@ 0.1.3 2007-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> * Fix error in handing signed decimal in vsprintf(). + * Major restructuring of header files to get closer to + POSIX compliance. + * Eliminate compilation warnings that that crept into + recent check-ins * Some Documentation updates * Added support for the Neuros OSD / DM320 diff --git a/nuttx/Documentation/NuttxUserGuide.html b/nuttx/Documentation/NuttxUserGuide.html index 48be3bee8..4efacd9fd 100644 --- a/nuttx/Documentation/NuttxUserGuide.html +++ b/nuttx/Documentation/NuttxUserGuide.html @@ -1492,7 +1492,8 @@ This parameter is required but not used in the present implementation. <LI><I>value</I>. The value parameter is type unsigned int. The semaphore is created with an initial value of <I>value</I>. Valid initial values for -semaphores must be less than or equal to <I>SEM_MAX_VALUE</I>. +semaphores must be less than or equal to <I>SEM_VALUE_MAX</I> (defined in +<CODE>include/limits.h</CODE>). </UL> </UL> @@ -2406,18 +2407,11 @@ in the si_code member. The content of si_value is only meaningful if the signal was generated by sigqueue(). The following values for si_code are defined in signal.h: <UL> -<LI>Standard: -<UL> -<LI><I>SI_QUEUE</I>. Signal sent from sigqueue -<LI><I>SI_MESGQ</I>. Signal generated by arrival of a message -on an empty message queue -</UL> - -<LI>Unique to this implementation: -<UL> -<LI><I>SI_TIMEOUT</I>. No Signal, restarted by timeout -</UL> - + <LI><I>SI_USER</I>. Signal sent from kill, raise, or abort + <LI><I>SI_QUEUE</I>. Signal sent from sigqueue + <LI><I>SI_TIMER</I>. Signal is result of timer expiration + <LI><I>SI_ASYNCIO</I>. Signal is the result of asynch IO completion + <LI><I>SI_MESGQ</I>. Signal generated by arrival of a message on an empty message queue. </UL> <P> diff --git a/nuttx/arch/c5471/include/limits.h b/nuttx/arch/c5471/include/limits.h index 554c9f1f1..a692c9c36 100644 --- a/nuttx/arch/c5471/include/limits.h +++ b/nuttx/arch/c5471/include/limits.h @@ -44,6 +44,7 @@ * Definitions ************************************************************/ +#define CHAR_BIT 8 #define SCHAR_MIN 0x80 #define SCHAR_MAX 0x7f #define UCHAR_MAX 0xff diff --git a/nuttx/arch/dm320/include/limits.h b/nuttx/arch/dm320/include/limits.h index 554c9f1f1..a692c9c36 100644 --- a/nuttx/arch/dm320/include/limits.h +++ b/nuttx/arch/dm320/include/limits.h @@ -44,6 +44,7 @@ * Definitions ************************************************************/ +#define CHAR_BIT 8 #define SCHAR_MIN 0x80 #define SCHAR_MAX 0x7f #define UCHAR_MAX 0xff diff --git a/nuttx/arch/pjrc-8051/include/limits.h b/nuttx/arch/pjrc-8051/include/limits.h index c0b91e63d..a6bffc0ed 100644 --- a/nuttx/arch/pjrc-8051/include/limits.h +++ b/nuttx/arch/pjrc-8051/include/limits.h @@ -44,6 +44,7 @@ * Definitions ************************************************************/ +#define CHAR_BIT 8 #define SCHAR_MIN 0x80 #define SCHAR_MAX 0x7f #define UCHAR_MAX 0xff diff --git a/nuttx/arch/sim/include/limits.h b/nuttx/arch/sim/include/limits.h index 554c9f1f1..a692c9c36 100644 --- a/nuttx/arch/sim/include/limits.h +++ b/nuttx/arch/sim/include/limits.h @@ -44,6 +44,7 @@ * Definitions ************************************************************/ +#define CHAR_BIT 8 #define SCHAR_MIN 0x80 #define SCHAR_MAX 0x7f #define UCHAR_MAX 0xff diff --git a/nuttx/examples/ostest/dev_null.c b/nuttx/examples/ostest/dev_null.c index 28b4287fd..55f6b0c25 100644 --- a/nuttx/examples/ostest/dev_null.c +++ b/nuttx/examples/ostest/dev_null.c @@ -43,6 +43,8 @@ #include <nuttx/config.h> #include <stdio.h> +#include <unistd.h> +#include <fcntl.h> #include <nuttx/os_external.h> #include "ostest.h" diff --git a/nuttx/examples/ostest/main.c b/nuttx/examples/ostest/main.c index 8b7096972..497aa3e4f 100644 --- a/nuttx/examples/ostest/main.c +++ b/nuttx/examples/ostest/main.c @@ -43,6 +43,7 @@ #include <nuttx/os_external.h> #include <stdio.h> +#include <unistd.h> #include <string.h> #include <sched.h> #include "ostest.h" diff --git a/nuttx/examples/ostest/mqueue.c b/nuttx/examples/ostest/mqueue.c index a0c454e44..3ad68459c 100644 --- a/nuttx/examples/ostest/mqueue.c +++ b/nuttx/examples/ostest/mqueue.c @@ -40,6 +40,7 @@ #include <stdio.h> #include <string.h> #include <ctype.h> +#include <fcntl.h> #include <pthread.h> #include <mqueue.h> #include <sched.h> diff --git a/nuttx/fs/fs_close.c b/nuttx/fs/fs_close.c index 3d3c7ca5c..d3fa1c0f2 100644 --- a/nuttx/fs/fs_close.c +++ b/nuttx/fs/fs_close.c @@ -39,7 +39,7 @@ #include <nuttx/config.h> #include <sys/types.h> -#include <stdio.h> +#include <unistd.h> #include <sched.h> #include <errno.h> #include <nuttx/fs.h> diff --git a/nuttx/fs/fs_closedir.c b/nuttx/fs/fs_closedir.c index cf22902af..fd2d79d05 100644 --- a/nuttx/fs/fs_closedir.c +++ b/nuttx/fs/fs_closedir.c @@ -76,7 +76,6 @@ int closedir(FAR DIR *dirp) { struct internal_dir_s *idir = (struct internal_dir_s *)dirp; - off_t i; if (!idir) { diff --git a/nuttx/fs/fs_inodefinddir.c b/nuttx/fs/fs_inodefinddir.c index 044021598..73d818ba8 100644 --- a/nuttx/fs/fs_inodefinddir.c +++ b/nuttx/fs/fs_inodefinddir.c @@ -39,6 +39,7 @@ #include <nuttx/config.h> #include <sys/types.h> +#include <string.h> #include <errno.h> #include <nuttx/fs.h> #include "fs_internal.h" diff --git a/nuttx/fs/fs_inoderelease.c b/nuttx/fs/fs_inoderelease.c index 15dc49ae6..360f07298 100644 --- a/nuttx/fs/fs_inoderelease.c +++ b/nuttx/fs/fs_inoderelease.c @@ -39,6 +39,7 @@ #include <nuttx/config.h> #include <sys/types.h> +#include <stdlib.h> #include <errno.h> #include <nuttx/fs.h> #include "fs_internal.h" diff --git a/nuttx/fs/fs_open.c b/nuttx/fs/fs_open.c index 53af359fb..9b235f57b 100644 --- a/nuttx/fs/fs_open.c +++ b/nuttx/fs/fs_open.c @@ -39,7 +39,7 @@ #include <nuttx/config.h> #include <sys/types.h> -#include <stdio.h> +#include <fcntl.h> #include <sched.h> #include <errno.h> #ifdef CONFIG_FILE_MODE diff --git a/nuttx/fs/fs_read.c b/nuttx/fs/fs_read.c index f23ea016f..7d0edb25e 100644 --- a/nuttx/fs/fs_read.c +++ b/nuttx/fs/fs_read.c @@ -43,7 +43,8 @@ #include <nuttx/config.h> #include <sys/types.h> -#include <stdio.h> +#include <unistd.h> +#include <fcntl.h> #include <sched.h> #include <errno.h> #include "fs_internal.h" diff --git a/nuttx/fs/fs_write.c b/nuttx/fs/fs_write.c index 764b887d8..d25a88489 100644 --- a/nuttx/fs/fs_write.c +++ b/nuttx/fs/fs_write.c @@ -43,7 +43,8 @@ #include <nuttx/config.h> #include <sys/types.h> -#include <stdio.h> +#include <unistd.h> +#include <fcntl.h> #include <sched.h> #include <errno.h> #include "fs_internal.h" diff --git a/nuttx/include/ctype.h b/nuttx/include/ctype.h index fb30746de..6cc2cb895 100644 --- a/nuttx/include/ctype.h +++ b/nuttx/include/ctype.h @@ -76,7 +76,7 @@ * ************************************************************/ -#define isascii(c) ((c) >= 0 && (c) <= 0x7f); +#define isascii(c) ((c) >= 0 && (c) <= 0x7f); /************************************************************ * Function: isprint @@ -86,7 +86,17 @@ * ************************************************************/ -#define isprint(c) ((c) >= 0x20 && (c) < 0x7f) +#define isprint(c) ((c) >= 0x20 && (c) < 0x7f) + +/************************************************************ + * Function: isgraph + * + * Description: + * Checks for a printable character (excluding space) + * + ************************************************************/ + +#define isgraph(c) ((c) > 0x20 && (c) < 0x7f) /************************************************************ * Function: iscntrl @@ -99,6 +109,36 @@ #define iscontrol(c) (!isprint(c)) /************************************************************ + * Function: islower + * + * Description: + * Checks for an lowercase letter. + * + ************************************************************/ + +#define islower(c) ((c) >= 'a' && (c) <= 'z') + +/************************************************************ + * Function: isupper + * + * Description: + * Checks for an uppercase letter. + * + ************************************************************/ + +#define isupper(c) ((c) >= 'a' && (c) <= 'z') + +/************************************************************ + * Function: isalpha + * + * Description: + * Checks for an alphabetic character + * + ************************************************************/ + +#define isalpha(c) (islower(c) || isupper(c)) + +/************************************************************ * Function: isdigit * * Description: @@ -109,6 +149,27 @@ #define isdigit(c) ((c) >= '0' && (c) <= '9') /************************************************************ + * Function: isalnum + * + * Description: + * Checks for an alphanumeric character + * + ************************************************************/ + +#define isalnum(c) (isalpha(c) || isdigit(c)) + +/************************************************************ + * Function: ispunct + * + * Description: + * Checks for a printable character which is not a space + * or an alphanumeric character + * + ************************************************************/ + +#define ispunct(c) (isgraph(c) && !isalnum(c)) + +/************************************************************ * Function: isxdigit * * Description: diff --git a/nuttx/include/fcntl.h b/nuttx/include/fcntl.h new file mode 100644 index 000000000..1949be42a --- /dev/null +++ b/nuttx/include/fcntl.h @@ -0,0 +1,181 @@ +/******************************************************************************** + * fcntl.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 __FCNTL_H +#define __FCNTL_H + +/******************************************************************************** + * Included Files + ********************************************************************************/ + +#include <nuttx/config.h> +#include <sys/types.h> + +/******************************************************************************** + * Definitions + ********************************************************************************/ + +/* open flag settings for open() (and related APIs) */ + +#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 file/sem/mq object */ +#define O_EXCL 0x08 /* Name must not exist when opened */ +#define O_APPEND 0x10 /* Keep contents, append to end */ +#define O_TRUNC 0x20 /* Delete contents */ +#define O_NONBLOCK 0x40 /* Don't wait for data */ +#define O_SYNC 0x80 /* Synchronize output on write */ +#define O_DSYNC OSYNC + +#define O_RSYNC 0x00 /* Sychronize input on read */ +#define O_ACCMODE 0x00 /* Required by POSIX */ +#define O_NOCTTY 0x00 /* Reqired by POSIX */ + +#define O_RDOK O_RDONLY /* Not POSIX */ +#define O_WROK O_WRONLY /* Not POSIX */ + +/* fcntl() commands */ + +#define F_DUPFD 0 /* Duplicate a file descriptor */ +#define F_GETFD 1 /* Read the file descriptor flags */ +#define F_GETFL 2 /* Read the file status flags */ +#define F_GETLEASE 3 /* Indicas what type of lease is held on fd (linux) */ +#define F_GETLK 4 /* Check if we could place a lock */ +#define F_GETOWN 5 /* Get the pid receiving SIGIO and SIGURG signals for fd */ +#define F_GETSIG 6 /* Get the signal sent */ +#define F_NOTIFY 7 /* Provide notification when directory referred to by fd changes (linux)*/ +#define F_SETFD 8 /* Set the file descriptor flags to value */ +#define F_SETFL 9 /* Set the file status flags to the value */ +#define F_SETLEASE 10 /* Set or remove file lease (linux) */ +#define F_SETLK 11 /* Acquire or release a lock on range of bytes */ +#define F_SETLKW 12 /* Like F_SETLK, but wait for lock to become available */ +#define F_SETOWN 13 /* Set pid that will receive SIGIO and SIGURG signals for fd */ +#define F_SETSIG 14 /* Set the signal to be sent */ + +/* close-on-exec flag for F_GETRL and F_SETFL */ + +#define FD_CLOEXEC 1 + +/* Arguments to F_SETLEASE */ + +#define F_RDLCK 0 /* Take out a read lease */ +#define F_WRLCK 2 /* Take out a write lease */ +#define F_UNLCK 3 /* Remove a lease */ + +/* These are the notifications that can be received from F_NOTIFY (linux) */ + +#define DN_ACCESS 0 /* A file was accessed */ +#define DN_MODIFY 1 /* A file was modified */ +#define DN_CREATE 2 /* A file was created */ +#define DN_DELETE 3 /* A file was unlinked */ +#define DN_RENAME 4 /* A file was renamed */ +#define DN_ATTRIB 5 /* Attributes of a file were changed */ + +#define S_IFMT 0170000 +#define S_IFSOCK 0140000 +#define S_IFLNK 0120000 +#define S_IFREG 0100000 +#define S_IFBLK 0060000 +#define S_IFCHR 0020000 +#define S_IFDIR 0040000 +#define S_IFIFO 0010000 +#define S_ISUID 0004000 +#define S_ISGID 0002000 +#define S_ISVTX 0001000 +#define S_IRWXU 0000700 +#define S_IRUSR 0000400 +#define S_IWUSR 0000200 +#define S_IXUSR 0000100 +#define S_IRWXG 0000070 +#define S_IRGRP 0000040 +#define S_IWGRP 0000020 +#define S_IXGRP 0000010 +#define S_IRWXO 0000007 +#define S_IROTH 0000004 +#define S_IWOTH 0000002 +#define S_IXOTH 0000001 + +#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) +#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) +#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) +#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) +#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) + +/******************************************************************************** + * Public Type Definitions + ********************************************************************************/ + +/* struct flock is the third argument for F_GETLK, F_SETLK and F_SETLKW */ + +struct flock +{ + short l_type; /* Type of lock: F_RDLCK, F_WRLCK, F_UNLCK */ + short l_whence; /* How to interpret l_start: SEEK_SET, SEEK_CUR, SEEK_END */ + off_t l_start; /* Starting offset for lock */ + off_t l_len; /* Number of bytes to lock */ + pid_t l_pid; /* PID of process blocking our lock (F_GETLK only) */ +}; + +/******************************************************************************** + * Public Variables + ********************************************************************************/ + +/******************************************************************************** + * Public Function Prototypes + ********************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" { +#else +#define EXTERN extern +#endif + +/* POSIX-like File System Interfaces */ + +EXTERN int creat(const char *path, mode_t mode); +EXTERN int open(const char *path, int oflag, ...); +EXTERN int fcntl(int fd, int cmd, ...); + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __FCNTL_H */ diff --git a/nuttx/include/limits.h b/nuttx/include/limits.h index da3cebaf9..285eea684 100644 --- a/nuttx/include/limits.h +++ b/nuttx/include/limits.h @@ -1,4 +1,4 @@ -/************************************************************ +/******************************************************************************** * limits.h * * Copyright (C) 2007 Gregory Nutt. All rights reserved. @@ -31,14 +31,14 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************/ + ********************************************************************************/ #ifndef __LIMITS_H #define __LIMITS_H -/************************************************************ +/******************************************************************************** * Included Files - ************************************************************/ + ********************************************************************************/ #include <nuttx/config.h> @@ -46,13 +46,133 @@ #include <arch/limits.h> -/************************************************************ +/******************************************************************************** * Definitions - ************************************************************/ + ********************************************************************************/ -/* Configurable limits */ +/* Configurable limits required by POSIX + * + * Required for all implementations: + * + * _POSIX_ARG_MAX Total length of string arguments + * _POSIX_CHILD_MAX Number of child tasks active + * _POSIX_LINK_MAX The number of links a file can have + * _POSIX_MAX_CANON Number bytes in TTY canonical input queue + * _POSIX_MAX_INPUT Number bytes in TTY canonical input queue + * _POSIX_NAME_MAX Number of bytes in a file or pathname component + * _POSIX_NGROUPS_MAX Number supplementary group IDs + * _POSIX_OPEN_MAX Number of files a task can have open at once + * _POSIX_PATH_MAX Number of bytes in a full pathname + * _POSIX_PIPE_BUF Number of bytes for atomic write into pipe + * _POSIX_SSIZE_MAX Largest filesystem write; also max value of ssize_t + * _POSIX_STREAM_MAX Number of std I/O streams open at once + * _POSIX_TZNAME_MAX Max number of bytes of a timezone name + * + * Required for sigqueue + * + * _POSIX_RTSIG_MAX Difference between SIGRTMIN and SIGRTMAX + * _POSIX_SIGQUEUE_MAX Max number signals a task can queue + * + * Required for POSIX timers + * + * _POSIX_DELAYTIMER_MAX Max number timer overruns + * _POSIX_TIMER_MAX Max number of timers per task + * _POSIX_CLOCKRES_MIN Clock resolution in nanoseconds + * + * Required for asynchronous I/O + * + * _POSIX_AIO_LISTIO_MAX Max number of AIOs in single listio call + * _POSIX_AIO_MAX Max number of simultaneous AIO operations + * + * Required for POSIX message passing + * + * _POSIX_MQ_OPEN_MAX Max number message queues task may open (mq_open) + * _POSIX_MQ_PRIO_MAX Max message priority (mq_send) + * + * Required for POSIX semaphores + * + * _POSIX_SEM_NSEMS_MAX Max number of open semaphores per task + * _POSIX_SEM_VALUE_MAX Max value a semaphore may have + */ + +#define _POSIX_ARG_MAX 4096 +#define _POSIX_CHILD_MAX 6 +#define _POSIX_LINK_MAX 8 +#define _POSIX_MAX_CANON 255 +#define _POSIX_MAX_INPUT 255 +#define _POSIX_NAME_MAX CONFIG_NAME_MAX +#define _POSIX_NGROUPS_MAX 0 +#define _POSIX_OPEN_MAX CONFIG_NFILE_DESCRIPTORS +#define _POSIX_PATH_MAX 255 +#define _POSIX_PIPE_BUF 512 +#define _POSIX_SSIZE_MAX INT_MAX +#define _POSIX_STREAM_MAX CONFIG_NFILE_STREAMS +#define _POSIX_TZNAME_MAX 3 + +/* Requred for sigqueue */ + +#define _POSIX_RTSIG_MAX 31 +#define _POSIX_SIGQUEUE_MAX 32 + +/* Required for POSIX timers */ + +#define _POSIX_DELAYTIMER_MAX 32 +#define _POSIX_TIMER_MAX 32 +#define _POSIX_CLOCKRES_MIN 10000000 + +/* Required for asynchronous I/O */ + +#define _POSIX_AIO_LISTIO_MAX 2 +#define _POSIX_AIO_MAX 1 + +/* Required for POSIX message passing */ + +#define _POSIX_MQ_OPEN_MAX 8 +#define _POSIX_MQ_PRIO_MAX UCHAR_MAX + +/* Required for POSIX semaphores */ + +#define _POSIX_SEM_NSEMS_MAX INT_MAX +#define _POSIX_SEM_VALUE_MAX 0x7fff + +/* Actual limits. These values may be increased from the POSIX minimum + * values above or made indeterminate + */ + +#define ARG_MAX _POSIX_ARG_MAX +#define CHILD_MAX _POSIX_CHILD_MAX +#define LINK_MAX _POSIX_LINK_MAX +#define MAX_CANON _POSIX_MAX_CANON +#define MAX_INPUT _POSIX_MAX_INPUT +#define NAME_MAX _POSIX_NAME_MAX +#define NGROUPS_MAX _POSIX_NGROUPS_MAX +#define OPEN_MAX _POSIX_OPEN_MAX +#define PATH_MAX _POSIX_PATH_MAX +#define PIPE_BUF _POSIX_PIPE_BUF +#define SSIZE_MAX _POSIX_SSIZE_MAX +#define STREAM_MAX _POSIX_STREAM_MAX +#define TZNAME_MAX _POSIX_TZNAME_MAX + +#define RTSIG_MAX _POSIX_RTSIG_MAX +#define SIGQUEUE_MAX _POSIX_SIGQUEUE_MAX + +#define DELAYTIMER_MAX _POSIX_DELAYTIMER_MAX +#define TIMER_MAX _POSIX_TIMER_MAX +#define CLOCKRES_MIN _POSIX_CLOCKRES_MIN + +/* Required for asynchronous I/O */ + +#define AIO_LISTIO_MAX _POSIX_AIO_LISTIO_MAX +#define AIO_MAX _POSIX_AIO_MAX + +/* Required for POSIX message passing */ + +#define MQ_OPEN_MAX _POSIX_MQ_OPEN_MAX +#define MQ_PRIO_MAX _POSIX_MQ_PRIO_MAX + +/* Required for POSIX semaphores */ -#define NAME_MAX CONFIG_NAME_MAX -#define MAXNAMELEN CONFIG_NAME_MAX +#define SEM_NSEMS_MAX _POSIX_SEM_NSEMS_MAX +#define SEM_VALUE_MAX _POSIX_SEM_VALUE_MAX #endif /* __LIMITS_H */ diff --git a/nuttx/include/mqueue.h b/nuttx/include/mqueue.h index 7e0966d25..22e853a16 100644 --- a/nuttx/include/mqueue.h +++ b/nuttx/include/mqueue.h @@ -1,4 +1,4 @@ -/************************************************************ +/******************************************************************************** * mqueue.h * * Copyright (C) 2007 Gregory Nutt. All rights reserved. @@ -31,62 +31,54 @@ * 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 - ************************************************************/ + ********************************************************************************/ -/************************************************************ +#define MQ_NONBLOCK O_NONBLOCK + +/******************************************************************************** * 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; + 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 */ }; /* Message queue descriptor */ typedef FAR struct mq_des *mqd_t; -/************************************************************ +/******************************************************************************** * Global Variables - ************************************************************/ + ********************************************************************************/ -/************************************************************ +/******************************************************************************** * Global Function Prototypes - ************************************************************/ + ********************************************************************************/ #ifdef __cplusplus #define EXTERN extern "C" @@ -98,17 +90,12 @@ extern "C" { 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, +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); +EXTERN int mq_getattr(mqd_t mqdes, struct mq_attr *mq_stat); #undef EXTERN #ifdef __cplusplus diff --git a/nuttx/include/nuttx/sched.h b/nuttx/include/nuttx/sched.h new file mode 100644 index 000000000..494f5dcd9 --- /dev/null +++ b/nuttx/include/nuttx/sched.h @@ -0,0 +1,287 @@ +/******************************************************************************** + * 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 __NUTTX_SCHED_H +#define __NUTTX_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 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 */ + +/******************************************************************************** + * 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 - And running */ + + TSTATE_TASK_INACTIVE = 4, /* BLOCKED - Initialized but not yet activated */ + TSTATE_WAIT_SEM = 5, /* BLOCKED - Waiting for a semaphore */ +#ifndef CONFIG_DISABLE_SIGNALS + TSTATE_WAIT_SIG = 6, /* BLOCKED - Waiting for a signal */ +#endif +#ifndef CONFIG_DISABLE_MQUEUE + TSTATE_WAIT_MQNOTEMPTY, /* BLOCKED - Waiting for a MQ to become not empty. */ + TSTATE_WAIT_MQNOTFULL /* BLOCKED - Waiting for a MQ to become not full. */ +#endif +}; +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 +#ifndef CONFIG_DISABLE_MQUEUE +# define LAST_BLOCKED_STATE TSTATE_WAIT_MQNOTFULL +# ifndef CONFIG_DISABLE_SIGNALS +# define NUM_TASK_STATES 9 +# else +# define NUM_TASK_STATES 8 +# endif +#else +# ifndef CONFIG_DISABLE_SIGNALS +# define LAST_BLOCKED_STATE TSTATE_WAIT_SIG +# define NUM_TASK_STATES 7 +# else +# define LAST_BLOCKED_STATE TSTATE_WAIT_SEM +# define NUM_TASK_STATES 6 +# endif +#endif + +/* 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 *************************************/ + + FAR struct _TCB *flink; /* link in DQ of TCBs */ + FAR struct _TCB *blink; + + /* 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) */ + FAR 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[CONFIG_MAX_TASK_ARGS+1]; /* Name+start-up parameters */ + + /* Stack-Related Fields *******************************************************/ + +#ifndef CONFIG_CUSTOM_STACK + size_t adj_stack_size; /* Stack size after adjustment */ + /* for hardware, processor, etc. */ + /* (for debug purposes only) */ + FAR void *stack_alloc_ptr; /* Pointer to allocated stack */ + /* Need to deallocate stack */ + FAR void *adj_stack_ptr; /* Adjusted stack_alloc_ptr for HW */ + /* The initial stack pointer value */ +#endif + + /* POSIX thread Specific Data *************************************************/ + +#if !defined(CONFIG_DISABLE_PTHREAD) && CONFIG_NPTHREAD_KEYS > 0 + FAR void *pthread_data[CONFIG_NPTHREAD_KEYS]; +#endif + + /* POSIX Semaphore Control Fields *********************************************/ + + sem_t *waitsem; /* Semaphore ID waiting on */ + + /* POSIX Signal Control Fields ************************************************/ + +#ifndef CONFIG_DISABLE_SIGNALS + 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 */ +#endif + + /* POSIX Named Message Queue Fields *******************************************/ + +#ifndef CONFIG_DISABLE_MQUEUE + sq_queue_t msgdesq; /* List of opened message queues */ + FAR msgq_t *msgwaitq; /* Waiting for this message queue */ +#endif + + /* Library related fields *****************************************************/ + + int errno; /* Current per-thread errno */ + + /* File system support ********************************************************/ + +#if CONFIG_NFILE_DESCRIPTORS > 0 + FAR struct filelist *filelist; /* Maps file descriptor to file */ +#endif + +#if CONFIG_NFILE_STREAMS > 0 + FAR 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; + +/* This is the callback type used by sched_foreach() */ + +typedef void (sched_foreach_t)(FAR _TCB *tcb, FAR void *arg); + +#endif /* __ASSEMBLY__ */ + +/******************************************************************************** + * Global Function Prototypes + ********************************************************************************/ + +#ifndef __ASSEMBLY__ +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" { +#else +#define EXTERN extern +#endif + +/* File system helpers */ + +#if CONFIG_NFILE_DESCRIPTORS > 0 +EXTERN FAR struct filelist *sched_getfiles(void); +#if CONFIG_NFILE_STREAMS > 0 +EXTERN FAR struct streamlist *sched_getstreams(void); +#endif /* CONFIG_NFILE_STREAMS */ +#endif /* CONFIG_NFILE_DESCRIPTORS */ + +/* sched_foreach will enumerate over each task and provide the + * TCB of each task to a user callback functions. Interrupts + * will be disabled throughout this enumeration! + */ + +EXTERN void sched_foreach(sched_foreach_t handler, FAR void *arg); + +#undef EXTERN +#if defined(__cplusplus) +} +#endif +#endif /* __ASSEMBLY__ */ + +#endif /* __NUTTX_SCHED_H */ diff --git a/nuttx/include/pthread.h b/nuttx/include/pthread.h index 5ff44f718..16973a5a5 100644 --- a/nuttx/include/pthread.h +++ b/nuttx/include/pthread.h @@ -1,4 +1,4 @@ -/************************************************************ +/******************************************************************************** * pthread.h * * Copyright (C) 2007 Gregory Nutt. All rights reserved. @@ -31,14 +31,14 @@ * 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 <nuttx/compiler.h> /* Compiler settings */ @@ -47,9 +47,9 @@ #include <time.h> /* Needed for struct timespec */ #include <nuttx/compiler.h> /* For noreturn_function */ -/************************************************************ +/******************************************************************************** * Compilation Switches - ************************************************************/ + ********************************************************************************/ /* Standard POSIX switches */ @@ -60,9 +60,9 @@ #define _POSIX_THREAD_ATTR_STACKSIZE #endif -/************************************************************ +/******************************************************************************** * Definitions - ************************************************************/ + ********************************************************************************/ #define PTHREAD_PROCESS_PRIVATE 0 #define PTHREAD_PROCESS_SHARED 1 @@ -88,9 +88,9 @@ # define PTHREAD_CANCELED ((FAR void*)ERROR) -/************************************************************ +/******************************************************************************** * Global Type Declarations - ************************************************************/ + ********************************************************************************/ #ifdef __cplusplus #define EXTERN extern "C" @@ -144,125 +144,96 @@ struct pthread_mutex_s typedef struct pthread_mutex_s pthread_mutex_t; #define PTHREAD_MUTEX_INITIALIZER {0, {1, 0xffff}} -/************************************************************ +/* Forware references */ + +struct sched_param; /* Defined in sched.h */ + +/******************************************************************************** * 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. - *----------------------------------------------------------*/ + ********************************************************************************/ +/* 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. - *----------------------------------------------------------*/ +/* 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 - *----------------------------------------------------------*/ +/* 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_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); + 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); + 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); + int *inheritsched); -/*----------------------------------------------------------* - * Set or obtain the default stack size - *----------------------------------------------------------*/ +/* 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); +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. - *----------------------------------------------------------*/ +/* 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); +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. - *----------------------------------------------------------*/ +/* 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. - *----------------------------------------------------------*/ +/* A thread may terminate it's own execution or the execution of another + * thread. + */ EXTERN void pthread_exit(pthread_addr_t value) noreturn_function; 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. - *----------------------------------------------------------*/ +/* 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 *value); +EXTERN int pthread_join(pthread_t thread, pthread_addr_t *value); -/*----------------------------------------------------------* - * A thread may tell the scheduler that its processor can be - * made available. - *----------------------------------------------------------*/ +/* 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. - *----------------------------------------------------------*/ +/* A thread may obtain a copy of its own thread handle. */ #define pthread_self() ((pthread_t)getpid()) -/*----------------------------------------------------------* - * Compare to thread IDs. - *----------------------------------------------------------*/ +/* Compare two thread IDs. */ #define pthread_equal(t1,t2) (t1 == t2) -/*----------------------------------------------------------* - * Thread scheduling parameters - *----------------------------------------------------------*/ +/* Thread scheduling parameters */ -EXTERN int pthread_getschedparam(pthread_t thread, - int *policy, - struct sched_param *param); +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); + const struct sched_param *param); -/*----------------------------------------------------------* - * Thread-specific Data Interfaces - *----------------------------------------------------------*/ +/* Thread-specific Data Interfaces */ EXTERN int pthread_key_create(pthread_key_t *key, FAR void (*destructor)(FAR void*)); @@ -270,65 +241,43 @@ EXTERN int pthread_setspecific(pthread_key_t key, FAR void *value); EXTERN FAR void *pthread_getspecific(pthread_key_t key); EXTERN int pthread_key_delete(pthread_key_t key); -/*----------------------------------------------------------* - * Create, operate on, and destroy mutex attributes. - *----------------------------------------------------------*/ +/* 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); +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. - *----------------------------------------------------------*/ +/* 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_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 - *----------------------------------------------------------*/ +/* 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. - *----------------------------------------------------------*/ +/* 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_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. - *----------------------------------------------------------*/ +/* 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 *cond); -/*----------------------------------------------------------* - * A thread can wait for a condition variable to be signalled - * or broadcast. - *----------------------------------------------------------*/ +/* 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); +EXTERN int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex); -/*----------------------------------------------------------* - * A thread can perform a timed wait on a condition variable. - *----------------------------------------------------------*/ +/* A thread can perform a timed wait on a condition variable. */ -EXTERN int pthread_cond_timedwait(pthread_cond_t *cond, - pthread_mutex_t *mutex, +EXTERN int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime); #undef EXTERN diff --git a/nuttx/include/sched.h b/nuttx/include/sched.h index bab6f517f..0efce85db 100644 --- a/nuttx/include/sched.h +++ b/nuttx/include/sched.h @@ -1,4 +1,4 @@ -/************************************************************ +/******************************************************************************** * sched.h * * Copyright (C) 2007 Gregory Nutt. All rights reserved. @@ -31,231 +31,48 @@ * 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> +#include <nuttx/sched.h> -/************************************************************ +/******************************************************************************** * Definitions - ************************************************************/ + ********************************************************************************/ -/* Task Management Definitins *******************************/ +/* Task Management Definitins ***************************************************/ -/* This is the maximum number of times that a lock can be set */ +/* POSIX-like scheduling policies */ -#define MAX_LOCK_COUNT 127 +#define SCHED_FIFO 1 /* FIFO per priority scheduling policy */ +#define SCHED_RR 2 /* Round robin scheduling policy */ +#define SCHED_OTHER 4 /* Not used */ -/* 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 **************************************/ +/* 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 - And running */ - - TSTATE_TASK_INACTIVE = 4, /* BLOCKED - Initialized but not yet activated */ - TSTATE_WAIT_SEM = 5, /* BLOCKED - Waiting for a semaphore */ -#ifndef CONFIG_DISABLE_SIGNALS - TSTATE_WAIT_SIG = 6, /* BLOCKED - Waiting for a signal */ -#endif -#ifndef CONFIG_DISABLE_MQUEUE - TSTATE_WAIT_MQNOTEMPTY, /* BLOCKED - Waiting for a MQ to become not empty. */ - TSTATE_WAIT_MQNOTFULL /* BLOCKED - Waiting for a MQ to become not full. */ -#endif -}; -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 -#ifndef CONFIG_DISABLE_MQUEUE -# define LAST_BLOCKED_STATE TSTATE_WAIT_MQNOTFULL -# ifndef CONFIG_DISABLE_SIGNALS -# define NUM_TASK_STATES 9 -# else -# define NUM_TASK_STATES 8 -# endif -#else -# ifndef CONFIG_DISABLE_SIGNALS -# define LAST_BLOCKED_STATE TSTATE_WAIT_SIG -# define NUM_TASK_STATES 7 -# else -# define LAST_BLOCKED_STATE TSTATE_WAIT_SEM -# define NUM_TASK_STATES 6 -# endif -#endif + ********************************************************************************/ -/* The following is the form of a thread start-up function */ +/* This is the POSIX-like scheduling parameter structure */ -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 +struct sched_param { - /* Fields used to support list management ***************************/ - - FAR struct _TCB *flink; /* link in DQ of TCBs */ - FAR struct _TCB *blink; - - /* 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) */ - FAR 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[CONFIG_MAX_TASK_ARGS+1]; /* Name+start-up parameters */ - - /* Stack-Related Fields *********************************************/ - -#ifndef CONFIG_CUSTOM_STACK - size_t adj_stack_size; /* Stack size after adjustment */ - /* for hardware, processor, etc. */ - /* (for debug purposes only) */ - FAR void *stack_alloc_ptr; /* Pointer to allocated stack */ - /* Need to deallocate stack */ - FAR void *adj_stack_ptr; /* Adjusted stack_alloc_ptr for HW */ - /* The initial stack pointer value */ -#endif - - /* POSIX thread Specific Data ***************************************/ - -#if !defined(CONFIG_DISABLE_PTHREAD) && CONFIG_NPTHREAD_KEYS > 0 - FAR void *pthread_data[CONFIG_NPTHREAD_KEYS]; -#endif - - /* POSIX Semaphore Control Fields ***********************************/ - - sem_t *waitsem; /* Semaphore ID waiting on */ - - /* POSIX Signal Control Fields **************************************/ - -#ifndef CONFIG_DISABLE_SIGNALS - 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 */ -#endif - - /* POSIX Named Message Queue Fields *********************************/ - -#ifndef CONFIG_DISABLE_MQUEUE - sq_queue_t msgdesq; /* List of opened message queues */ - FAR msgq_t *msgwaitq; /* Waiting for this message queue */ -#endif - - /* Library related fields *******************************************/ - - int errno; /* Current per-thread errno */ - - /* File system support **********************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 - FAR struct filelist *filelist; /* Maps file descriptor to file */ -#endif - -#if CONFIG_NFILE_STREAMS > 0 - FAR 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 - + int sched_priority; }; -typedef struct _TCB _TCB; -/* This is the callback type used by sched_foreach() */ - -typedef void (sched_foreach_t)(FAR _TCB *tcb, FAR void *arg); - -#endif /* __ASSEMBLY__ */ - -/************************************************************ +/******************************************************************************** * Global Function Prototypes - ************************************************************/ + ********************************************************************************/ #ifndef __ASSEMBLY__ #undef EXTERN @@ -289,18 +106,15 @@ 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_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); +EXTERN int sched_rr_get_interval(pid_t pid, struct timespec *interval); /* Task Switching Interfaces (non-standard) */ @@ -314,9 +128,9 @@ EXTERN sint32 sched_lockcount(void); #ifdef CONFIG_SCHED_INSTRUMENTATION -EXTERN void sched_note_start(FAR _TCB *tcb ); -EXTERN void sched_note_stop(FAR _TCB *tcb ); -EXTERN void sched_note_switch(FAR _TCB *pFromTcb, FAR _TCB *pToTcb); +EXTERN void sched_note_start(FAR _TCB *tcb ); +EXTERN void sched_note_stop(FAR _TCB *tcb ); +EXTERN void sched_note_switch(FAR _TCB *pFromTcb, FAR _TCB *pToTcb); #else # define sched_note_start(t) @@ -324,22 +138,6 @@ EXTERN void sched_note_switch(FAR _TCB *pFromTcb, FAR _TCB *pToTcb); # define sched_note_switch(t1, t2) #endif /* CONFIG_SCHED_INSTRUMENTATION */ -/* File system helpers */ - -#if CONFIG_NFILE_DESCRIPTORS > 0 -EXTERN FAR struct filelist *sched_getfiles(void); -#if CONFIG_NFILE_STREAMS > 0 -EXTERN FAR struct streamlist *sched_getstreams(void); -#endif /* CONFIG_NFILE_STREAMS */ -#endif /* CONFIG_NFILE_DESCRIPTORS */ - -/* sched_foreach will enumerate over each task and provide the - * TCB of each task to a user callback functions. Interrupts - * will be disabled throughout this enumeration! - */ - -EXTERN void sched_foreach(sched_foreach_t handler, FAR void *arg); - #undef EXTERN #if defined(__cplusplus) } diff --git a/nuttx/include/semaphore.h b/nuttx/include/semaphore.h index f23435a1a..565acaf31 100644 --- a/nuttx/include/semaphore.h +++ b/nuttx/include/semaphore.h @@ -41,6 +41,7 @@ ************************************************************/ #include <sys/types.h> +#include <limits.h> #ifdef __cplusplus #define EXTERN extern "C" @@ -53,14 +54,6 @@ extern "C" { * 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 ************************************************************/ diff --git a/nuttx/include/signal.h b/nuttx/include/signal.h index df8fe214d..8e25f8c00 100644 --- a/nuttx/include/signal.h +++ b/nuttx/include/signal.h @@ -1,4 +1,4 @@ -/************************************************************ +/******************************************************************************** * signal.h * * Copyright (C) 2007 Gregory Nutt. All rights reserved. @@ -31,27 +31,27 @@ * 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 <nuttx/config.h> #include <nuttx/compiler.h> #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. */ @@ -62,13 +62,18 @@ #define GOOD_SIGNO(s) (((s)>=MIN_SIGNO)&&((s)<=MAX_SIGNO)) #define SIGNO2SET(s) ((sigset_t)1 << (s)) +/* All signals are "real time" signals */ + +#define SIGRTMIN 0 /* First real time signal */ +#define SIGRTMAX 31 /* Last real time signal */ + /* sigprocmask() "how" definitions. Only one of the following * can be specified: */ -#define SIG_BLOCK 1 -#define SIG_UNBLOCK 2 -#define SIG_SETMASK 3 +#define SIG_BLOCK 1 /* Block the given signals */ +#define SIG_UNBLOCK 2 /* Unblock the given signals */ +#define SIG_SETMASK 3 /* Set the signal mask to the current set */ /* struct sigaction flag values */ @@ -80,19 +85,25 @@ /* Dummy value for the sigev_notify field of struct sigevent */ -#define SIGEV_SIGNAL 0 +#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 */ +#define SI_USER 0 /* Signal sent from kill, raise, or abort */ +#define SI_QUEUE 1 /* Signal sent from sigqueue */ +#define SI_TIMER 2 /* Signal is result of timer expiration */ +#define SI_ASYNCIO 3 /* Signal is the result of asynch IO completion */ +#define SI_MESGQ 4 /* Signal generated by arrival of a message on an */ + /* empty message queue */ + +/* sigevent definitions */ -/************************************************************ +#define SIGEV_NONE 0 /* No notification desired */ +#define SIGEV_SIGNAL 1 /* Notify via signal */ + +/******************************************************************************** * Global Type Declarations - ************************************************************/ + ********************************************************************************/ /* This defines a set of 32 signals (numbered 0 through 31). */ @@ -106,6 +117,18 @@ union sigval void *sival_ptr; }; +/* This structure contains elements that define a queue signal. + * 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; /* Notification: SIGNAL or NONE */ + union sigval sigev_value; /* Generate this signal */ + int sigev_notify; /* Queue this value */ +}; + /* The following types is used to pass parameters to/from * signal handlers */ @@ -132,13 +155,13 @@ struct sigaction #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" @@ -147,26 +170,21 @@ extern "C" { #define EXTERN extern #endif +EXTERN int kill(pid_t, int); 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 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 sigwaitinfo(const sigset_t *set, struct siginfo *value); +EXTERN int sigtimedwait(const sigset_t *set, struct siginfo *value, + const struct timespec *timeout); #ifdef CONFIG_CAN_PASS_STRUCTS -EXTERN int sigqueue(int pid, int signo, - const union sigval value); +EXTERN int sigqueue(int pid, int signo, const union sigval value); #else EXTERN int sigqueue(int pid, int signo, void *sival_ptr); #endif diff --git a/nuttx/include/stdio.h b/nuttx/include/stdio.h index 666bb22fa..eba23a9ce 100644 --- a/nuttx/include/stdio.h +++ b/nuttx/include/stdio.h @@ -59,37 +59,6 @@ #define EOF (-1) -/* File I/O constants ***************************************/ - -#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 - /* The first three _iob entries are reserved for standard I/O */ #define stdin (&sched_getstreams()->sl_streams[0]) @@ -106,7 +75,6 @@ #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 @@ -197,21 +165,14 @@ 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 creat(const char *path, mode_t mode); EXTERN FILE *fdopen(int fd, const char *type); EXTERN int fstat(int fd, FAR struct stat *buf); EXTERN char *getcwd(FAR 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 int read(int fd, void *buf, unsigned int nbytes); EXTERN int rmdir(const char *path); EXTERN int stat(const char *path, FAR struct stat *buf); EXTERN int statfs(const char *path, FAR struct statfs *buf); -EXTERN int unlink(const char *path); -EXTERN int write(int fd, const void *buf, unsigned int nbytes); #undef EXTERN #if defined(__cplusplus) diff --git a/nuttx/include/sys/types.h b/nuttx/include/sys/types.h index 45971e4fd..916681c39 100644 --- a/nuttx/include/sys/types.h +++ b/nuttx/include/sys/types.h @@ -69,12 +69,6 @@ #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 @@ -92,22 +86,6 @@ #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 ************************************************************/ @@ -144,12 +122,6 @@ typedef int STATUS; typedef int (*main_t)(int argc, char *argv[]); -/* This is the POSIX-like scheduling parameter structure */ - -struct sched_param -{ - int sched_priority; -}; #endif /************************************************************ diff --git a/nuttx/include/time.h b/nuttx/include/time.h index 0d0399e83..4ae943565 100644 --- a/nuttx/include/time.h +++ b/nuttx/include/time.h @@ -1,4 +1,4 @@ -/************************************************************ +/******************************************************************************** * time.h * * Copyright (C) 2007 Gregory Nutt. All rights reserved. @@ -31,49 +31,44 @@ * 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 +#include <nuttx/config.h> +#include <sys/types.h> -/************************************************************ +/******************************************************************************** * Compilations Switches - ************************************************************/ + ********************************************************************************/ -/************************************************************ +/******************************************************************************** * Definitions - ************************************************************/ + ********************************************************************************/ -/* This must be set to the last known date */ +/* Clock tick of the system */ -#define CURRENT_YEAR 2000 -#define CURRENT_MONTH 5 -#define CURRENT_DAY 22 +#define CLK_TCK 100 /* This is the only clock_id supported by the "Clock and Timer * Functions." */ #define CLOCK_REALTIME 0 +#define CLOCK_ABSTIME -/************************************************************ +/******************************************************************************** * Global Type Declarations - ************************************************************/ + ********************************************************************************/ -typedef long time_t; -typedef long clockid_t; +typedef uint32 time_t; +typedef ubyte clockid_t; +typedef ubyte timer_t; struct timespec { @@ -102,22 +97,51 @@ struct tm #endif }; -/************************************************************ +/* Struct itimerspec is used to define settings for an interval timer */ + +struct itimerspec +{ + struct timespec it_value; /* First time */ + struct timespec it_interval; /* and thereafter */ +}; + +/* forward reference (defined in signal.h) */ + +struct sigevent; + +/******************************************************************************** * Global Variables - ************************************************************/ + ********************************************************************************/ + +/* extern char *tznames[]; not supported */ -/************************************************************ +/******************************************************************************** * 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); +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" { +#else +#define EXTERN extern +#endif + +EXTERN int clock_settime(clockid_t clockid, const struct timespec *tp); +EXTERN int clock_gettime(clockid_t clockid, struct timespec *tp); +EXTERN int clock_getres(clockid_t clockid, 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) +EXTERN int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid); +EXTERN int timer_delete(timer_t timerid); +EXTERN int timer_settime(timer_t timerid, int flags, const struct itimerspec *value, + struct itimerspec *ovalue); +EXTERN int timer_gettime(timer_t timerid, struct itimerspec *value); +EXTERN int timer_getoverrun(timer_t timerid); + #undef EXTERN #if defined(__cplusplus) } diff --git a/nuttx/include/unistd.h b/nuttx/include/unistd.h index faf50e3a3..164b5368e 100644 --- a/nuttx/include/unistd.h +++ b/nuttx/include/unistd.h @@ -53,6 +53,49 @@ #define ATEXIT_MAX 1 +/* Values for seeking */ + +#define SEEK_SET 0 /* From the start of the file */ +#define SEEK_CUR 1 /* From the current file offset */ +#define SEEK_END 2 /* From the end of the file */ + +/* Bit values for the second argument to access */ + +#define F_OK 0 /* Test existence */ +#define R_OK 1 /* Test read permission */ +#define W_OK 2 /* Test write permission */ +#define X_OK 4 /* Test execute permission */ + +/* POSIX feature set macros */ + +#define POSIX_VERSION +#undef _POSIX_SAVED_IDS +#undef _POSIX_JOB_CONTROL +#define _POSIX_REALTIME_SIGNALS 1 +#define _POSIX_MESSAGE_PASSING 1 +#undef _POSIX_MAPPED_FILES +#undef _POSIX_SHARED_MEMORY_OBJECTS +#define _POSIX_PRIORITY_SCHEDULING 1 +#define _POSIX_TIMERS +#undef _POSIX_MEMLOCK +#undef _POSIX_MEMLOCK_RANGE +#undef _POSIX_FSYNC +#define _POSIX_SYNCHRONIZED_IO +#undef _POSIX_ASYNCHRONOUS_IO +#undef _POSIX_PRIORITIZED_IO + +/* Execution time constants (not supported) */ + +#undef _POSIX_CHOWN_RESTRICTED +#undef _POSIX_NO_TRUNC +#undef _POSIX_VDISABLE + +#define _POSIX_SYNC_IO +#undef _POSIX_ASYNC_IO +#undef _POSIX_PRIO_IO + +#define fsync(f) + /************************************************************ * Global Function Prototypes ************************************************************/ @@ -70,12 +113,17 @@ extern "C" { EXTERN pid_t getpid(void); EXTERN void _exit(int status) noreturn_function; EXTERN unsigned int sleep(unsigned int seconds); -EXTERN void usleep(unsigned long usec); +EXTERN void usleep(unsigned long usec); /* File descriptor operations */ -EXTERN int dup(int fildes); -EXTERN int dup2(int fildes1, int fildes2); +EXTERN int close(int fd); +EXTERN int dup(int fildes); +EXTERN int dup2(int fildes1, int fildes2); +EXTERN off_t lseek(int fd, off_t offset, int whence); +EXTERN int read(int fd, void *buf, unsigned int nbytes); +EXTERN int unlink(const char *path); +EXTERN int write(int fd, const void *buf, unsigned int nbytes); #undef EXTERN #if defined(__cplusplus) diff --git a/nuttx/lib/lib_fclose.c b/nuttx/lib/lib_fclose.c index 979e75a6f..a7960e823 100644 --- a/nuttx/lib/lib_fclose.c +++ b/nuttx/lib/lib_fclose.c @@ -44,6 +44,7 @@ #include <nuttx/config.h> #include <sys/types.h> #include <stdio.h> +#include <unistd.h> #include <stdlib.h> #include <string.h> #include <errno.h> diff --git a/nuttx/lib/lib_fflush.c b/nuttx/lib/lib_fflush.c index e7f4e6960..12dfd8b12 100644 --- a/nuttx/lib/lib_fflush.c +++ b/nuttx/lib/lib_fflush.c @@ -43,6 +43,8 @@ #include <nuttx/config.h> /* for CONFIG_STDIO_BUFFER_SIZE */ #include <stdio.h> +#include <unistd.h> +#include <fcntl.h> #include <errno.h> #include <nuttx/fs.h> #include "lib_internal.h" diff --git a/nuttx/lib/lib_fgets.c b/nuttx/lib/lib_fgets.c index 27f9ecdcd..561d4a85e 100644 --- a/nuttx/lib/lib_fgets.c +++ b/nuttx/lib/lib_fgets.c @@ -37,7 +37,9 @@ * Included Files ************************************************************/ +#include <nuttx/config.h> #include <stdio.h> +#include <unistd.h> #include <string.h> #include <ctype.h> #include <debug.h> diff --git a/nuttx/lib/lib_fopen.c b/nuttx/lib/lib_fopen.c index 1d4b66ac8..ec699c340 100644 --- a/nuttx/lib/lib_fopen.c +++ b/nuttx/lib/lib_fopen.c @@ -45,6 +45,8 @@ #include <sys/types.h> #include <stdio.h> #include <stdlib.h> +#include <unistd.h> +#include <fcntl.h> #include <string.h> #include <errno.h> #include "lib_internal.h" diff --git a/nuttx/lib/lib_init.c b/nuttx/lib/lib_init.c index dc0643144..0e820ff4c 100644 --- a/nuttx/lib/lib_init.c +++ b/nuttx/lib/lib_init.c @@ -57,27 +57,6 @@ * Private Functions ************************************************************/ -#if CONFIG_NFILE_STREAMS > 0 -static void _lib_semtake(FAR struct streamlist *list) -{ - /* Take the semaphore (perhaps waiting) */ - - while (sem_wait(&list->sl_sem) != 0) - { - /* The only case that an error should occr here is if - * the wait was awakened by a signal. - */ - - ASSERT(*get_errno_ptr() == EINTR); - } -} - -# define _lib_semgive(list) sem_post(&list->sl_sem) -#else -# define _lib_semtake(list) -# define _lib_semgive(list) -#endif - /************************************************************ * Public Functions ************************************************************/ diff --git a/nuttx/lib/lib_libfread.c b/nuttx/lib/lib_libfread.c index 069721d8f..92e53025d 100644 --- a/nuttx/lib/lib_libfread.c +++ b/nuttx/lib/lib_libfread.c @@ -43,7 +43,9 @@ #include <nuttx/config.h> /* for CONFIG_STDIO_BUFFER_SIZE */ #include <stdio.h> +#include <unistd.h> #include <string.h> +#include <fcntl.h> #include <errno.h> #include "lib_internal.h" diff --git a/nuttx/lib/lib_libfwrite.c b/nuttx/lib/lib_libfwrite.c index d53f68e2c..f62e8ddb9 100644 --- a/nuttx/lib/lib_libfwrite.c +++ b/nuttx/lib/lib_libfwrite.c @@ -43,6 +43,7 @@ #include <nuttx/config.h> /* for CONFIG_STDIO_BUFFER_SIZE */ #include <stdio.h> +#include <fcntl.h> #include <errno.h> #include "lib_internal.h" diff --git a/nuttx/lib/lib_rawstream.c b/nuttx/lib/lib_rawstream.c index dbb59ad82..8ec80bacd 100644 --- a/nuttx/lib/lib_rawstream.c +++ b/nuttx/lib/lib_rawstream.c @@ -37,7 +37,7 @@ * Included Files ************************************************************/ -#include <stdio.h> +#include <unistd.h> #include <errno.h> #include "lib_internal.h" diff --git a/nuttx/lib/lib_ungetc.c b/nuttx/lib/lib_ungetc.c index 6e246c814..fe333344c 100644 --- a/nuttx/lib/lib_ungetc.c +++ b/nuttx/lib/lib_ungetc.c @@ -42,8 +42,8 @@ ************************************************************/ #include <nuttx/config.h> - #include <stdio.h> +#include <fcntl.h> #include <errno.h> #include <nuttx/fs.h> #include "lib_internal.h" diff --git a/nuttx/sched/mq_internal.h b/nuttx/sched/mq_internal.h index 0ffdea53e..a19e71bdf 100644 --- a/nuttx/sched/mq_internal.h +++ b/nuttx/sched/mq_internal.h @@ -41,6 +41,7 @@ ************************************************************/ #include <sys/types.h> +#include <limits.h> #include <mqueue.h> #include <sched.h> #include <signal.h> @@ -57,7 +58,7 @@ #define MQ_MAX_BYTES CONFIG_MQ_MAXMSGSIZE #define MQ_MAX_HWORDS ((MQ_MAX_BYTES + sizeof(uint16) - 1) / sizeof(uint16)) #define MQ_MAX_MSGS 16 -#define MQ_PRIO_MAX 255 +#define MQ_PRIO_MAX _POSIX_MQ_PRIO_MAX /* This defines the number of messages descriptors to allocate * at each "gulp." diff --git a/nuttx/sched/mq_notify.c b/nuttx/sched/mq_notify.c index 3632c7636..60d5bc1a8 100644 --- a/nuttx/sched/mq_notify.c +++ b/nuttx/sched/mq_notify.c @@ -38,6 +38,7 @@ ************************************************************/ #include <sys/types.h> /* uint32, etc. */ +#include <signal.h> #include <mqueue.h> #include <sched.h> #include "os_internal.h" diff --git a/nuttx/sched/mq_open.c b/nuttx/sched/mq_open.c index 13c964e53..8290aa0d2 100644 --- a/nuttx/sched/mq_open.c +++ b/nuttx/sched/mq_open.c @@ -40,6 +40,7 @@ #include <sys/types.h> /* uint32, etc. */ #include <stdarg.h> /* va_list */ #include <mqueue.h> +#include <fcntl.h> #include <string.h> #include <sched.h> #include <errno.h> diff --git a/nuttx/sched/mq_receive.c b/nuttx/sched/mq_receive.c index 35b84bb74..65fcb81c2 100644 --- a/nuttx/sched/mq_receive.c +++ b/nuttx/sched/mq_receive.c @@ -40,6 +40,7 @@ #include <sys/types.h> /* uint32, etc. */ #include <stdarg.h> /* va_list */ #include <unistd.h> +#include <fcntl.h> /* O_NONBLOCK */ #include <string.h> #include <assert.h> #include <mqueue.h> @@ -183,7 +184,7 @@ int mq_receive(mqd_t mqdes, void *msg, size_t msglen, int *prio) /* Copy the message into the caller's buffer */ - memcpy(msg, (void*)curr->mail, rcvmsglen); + memcpy(msg, (const void*)curr->mail, rcvmsglen); /* Copy the message priority as well (if a buffer is provided) */ diff --git a/nuttx/sched/mq_send.c b/nuttx/sched/mq_send.c index a0172a154..96d577759 100644 --- a/nuttx/sched/mq_send.c +++ b/nuttx/sched/mq_send.c @@ -40,6 +40,7 @@ #include <nuttx/compiler.h> #include <nuttx/kmalloc.h> #include <sys/types.h> /* uint32, etc. */ +#include <fcntl.h> #include <mqueue.h> #include <string.h> #include <sched.h> @@ -306,7 +307,7 @@ int mq_send(mqd_t mqdes, const void *msg, size_t msglen, int prio) /* Copy the message data into the message */ - memcpy((const void*)curr->mail, (void*)msg, msglen); + memcpy((void*)curr->mail, (const void*)msg, msglen); /* Insert the new message in the message queue */ diff --git a/nuttx/sched/mq_setattr.c b/nuttx/sched/mq_setattr.c index 6976886de..f0eca4eae 100644 --- a/nuttx/sched/mq_setattr.c +++ b/nuttx/sched/mq_setattr.c @@ -38,6 +38,7 @@ ************************************************************/ #include <sys/types.h> /* uint32, etc. */ +#include <fcntl.h> /* O_NONBLOCK */ #include <mqueue.h> #include "mq_internal.h" diff --git a/nuttx/sched/pthread_attrgetschedparam.c b/nuttx/sched/pthread_attrgetschedparam.c index defed57e6..e33b132cd 100644 --- a/nuttx/sched/pthread_attrgetschedparam.c +++ b/nuttx/sched/pthread_attrgetschedparam.c @@ -40,6 +40,7 @@ #include <sys/types.h> #include <pthread.h> #include <string.h> +#include <sched.h> #include <debug.h> #include <errno.h> #include "pthread_internal.h" diff --git a/nuttx/sched/pthread_attrsetschedparam.c b/nuttx/sched/pthread_attrsetschedparam.c index 77dfa1ccc..c9660c31c 100644 --- a/nuttx/sched/pthread_attrsetschedparam.c +++ b/nuttx/sched/pthread_attrsetschedparam.c @@ -40,6 +40,7 @@ #include <sys/types.h> #include <pthread.h> #include <string.h> +#include <sched.h> #include <debug.h> #include <errno.h> #include "pthread_internal.h" diff --git a/nuttx/sched/pthread_attrsetschedpolicy.c b/nuttx/sched/pthread_attrsetschedpolicy.c index 2ba20db51..09a9e92a0 100644 --- a/nuttx/sched/pthread_attrsetschedpolicy.c +++ b/nuttx/sched/pthread_attrsetschedpolicy.c @@ -40,6 +40,7 @@ #include <sys/types.h> #include <pthread.h> #include <string.h> +#include <sched.h> #include <debug.h> #include <errno.h> #include "pthread_internal.h" diff --git a/nuttx/sched/pthread_create.c b/nuttx/sched/pthread_create.c index 4346a6f65..8247ed78e 100644 --- a/nuttx/sched/pthread_create.c +++ b/nuttx/sched/pthread_create.c @@ -39,6 +39,7 @@ #include <nuttx/config.h> #include <sys/types.h> +#include <string.h> #include <pthread.h> #include <sched.h> #include <debug.h> @@ -408,7 +409,7 @@ int pthread_create(pthread_t *thread, pthread_attr_t *attr, else { sched_unlock(); - dq_rem((FAR dq_entry_t*)ptcb, &g_inactivetasks); + dq_rem((FAR dq_entry_t*)ptcb, (dq_queue_t*)&g_inactivetasks); (void)sem_destroy(&pjoin->data_sem); (void)sem_destroy(&pjoin->exit_sem); sched_releasetcb(ptcb); diff --git a/nuttx/sched/sched_addblocked.c b/nuttx/sched/sched_addblocked.c index 648d3f581..571b532a5 100644 --- a/nuttx/sched/sched_addblocked.c +++ b/nuttx/sched/sched_addblocked.c @@ -102,13 +102,13 @@ void sched_addblocked(FAR _TCB *btcb, tstate_t task_state) { /* Add the task to a prioritized list */ - sched_addprioritized(btcb, g_tasklisttable[task_state].list); + sched_addprioritized(btcb, (dq_queue_t*)g_tasklisttable[task_state].list); } else { /* Add the task to a non-prioritized list */ - dq_addlast((FAR dq_entry_t*)btcb, g_tasklisttable[task_state].list); + dq_addlast((FAR dq_entry_t*)btcb, (dq_queue_t*)g_tasklisttable[task_state].list); } /* Make sure the TCB's state corresponds to the list */ diff --git a/nuttx/sched/sched_addreadytorun.c b/nuttx/sched/sched_addreadytorun.c index 4344caf31..d3b32fef1 100644 --- a/nuttx/sched/sched_addreadytorun.c +++ b/nuttx/sched/sched_addreadytorun.c @@ -111,14 +111,14 @@ boolean sched_addreadytorun(FAR _TCB *btcb) * task to the g_pendingtasks task list for now. */ - sched_addprioritized(btcb, &g_pendingtasks); + sched_addprioritized(btcb, (dq_queue_t*)&g_pendingtasks); btcb->task_state = TSTATE_TASK_PENDING; ret = FALSE; } /* Otherwise, add the new task to the g_readytorun task list */ - else if (sched_addprioritized(btcb, &g_readytorun)) + else if (sched_addprioritized(btcb, (dq_queue_t*)&g_readytorun)) { /* Information the instrumentation logic that we are switching tasks */ diff --git a/nuttx/sched/sched_free.c b/nuttx/sched/sched_free.c index 832e71082..ec2688c57 100644 --- a/nuttx/sched/sched_free.c +++ b/nuttx/sched/sched_free.c @@ -93,7 +93,7 @@ void sched_free(FAR void *address) /* Yes.. Delay the deallocation until a more appropriate time. */ irqstate_t saved_state = irqsave(); - sq_addlast((FAR sq_entry_t*)address, &g_delayeddeallocations); + sq_addlast((FAR sq_entry_t*)address, (sq_queue_t*)&g_delayeddeallocations); irqrestore(saved_state); } else diff --git a/nuttx/sched/sched_removeblocked.c b/nuttx/sched/sched_removeblocked.c index 2b9294003..79e8a3e75 100644 --- a/nuttx/sched/sched_removeblocked.c +++ b/nuttx/sched/sched_removeblocked.c @@ -103,7 +103,7 @@ void sched_removeblocked(FAR _TCB *btcb) * with this state */ - dq_rem((FAR dq_entry_t*)btcb, g_tasklisttable[task_state].list); + dq_rem((FAR dq_entry_t*)btcb, (dq_queue_t*)g_tasklisttable[task_state].list); /* Make sure the TCB's state corresponds to not being in * any list diff --git a/nuttx/sched/sched_removereadytorun.c b/nuttx/sched/sched_removereadytorun.c index 1c17feba0..2c3c8352d 100644 --- a/nuttx/sched/sched_removereadytorun.c +++ b/nuttx/sched/sched_removereadytorun.c @@ -110,7 +110,7 @@ boolean sched_removereadytorun(FAR _TCB *rtcb) /* Remove the TCB from the ready-to-run list */ - dq_rem((FAR dq_entry_t*)rtcb, &g_readytorun); + dq_rem((FAR dq_entry_t*)rtcb, (dq_queue_t*)&g_readytorun); rtcb->task_state = TSTATE_TASK_INVALID; return ret; diff --git a/nuttx/sched/sched_setparam.c b/nuttx/sched/sched_setparam.c index 52389ae49..cb363950c 100644 --- a/nuttx/sched/sched_setparam.c +++ b/nuttx/sched/sched_setparam.c @@ -240,7 +240,7 @@ int sched_setparam(pid_t pid, const struct sched_param *param) { /* Remove the TCB from the prioritized task list */ - dq_rem((FAR dq_entry_t*)tcb, g_tasklisttable[task_state].list); + dq_rem((FAR dq_entry_t*)tcb, (dq_queue_t*)g_tasklisttable[task_state].list); /* Change the task priority */ @@ -250,7 +250,7 @@ int sched_setparam(pid_t pid, const struct sched_param *param) * position */ - sched_addprioritized(tcb, g_tasklisttable[task_state].list); + sched_addprioritized(tcb, (dq_queue_t*)g_tasklisttable[task_state].list); } /* CASE 3b. The task resides in a non-prioritized list. */ diff --git a/nuttx/sched/sched_setupidlefiles.c b/nuttx/sched/sched_setupidlefiles.c index 871a445bd..78d8d60ad 100644 --- a/nuttx/sched/sched_setupidlefiles.c +++ b/nuttx/sched/sched_setupidlefiles.c @@ -40,6 +40,7 @@ #include <nuttx/config.h> #include <stdio.h> #include <unistd.h> +#include <fcntl.h> #include <sched.h> #include <errno.h> #include "os_internal.h" diff --git a/nuttx/sched/sem_init.c b/nuttx/sched/sem_init.c index 36f2b9942..861d62056 100644 --- a/nuttx/sched/sem_init.c +++ b/nuttx/sched/sem_init.c @@ -38,6 +38,7 @@ ************************************************************/ #include <sys/types.h> +#include <limits.h> #include <semaphore.h> #include "sem_internal.h" @@ -100,7 +101,7 @@ int sem_init (sem_t *sem, int pshared, unsigned int value) { int ret = ERROR; - if (sem && value <= SEM_MAX_VALUE) + if (sem && value <= SEM_VALUE_MAX) { sem->semcount = (sint16)value; ret = OK; diff --git a/nuttx/sched/sem_open.c b/nuttx/sched/sem_open.c index e9f6335c6..dbfa98fd5 100644 --- a/nuttx/sched/sem_open.c +++ b/nuttx/sched/sem_open.c @@ -39,6 +39,8 @@ #include <sys/types.h> #include <stdarg.h> +#include <limits.h> +#include <fcntl.h> #include <string.h> #include <semaphore.h> #include <errno.h> @@ -105,7 +107,7 @@ * 1. mode_t mode (ignored), and * 2. unsigned int value. This initial value of the semaphore. * valid initial values of the semaphore must be less than - * or equal to SEM_MAX_VALUE. + * or equal to SEM_VALUE_MAX. * * Return Value: * A pointer to sem_t or -1 (ERROR) if unsuccessful. @@ -170,7 +172,7 @@ FAR sem_t *sem_open (const char *name, int oflag, ...) /* Verify that a legal initial value was selected. */ - if (value <= SEM_MAX_VALUE) + if (value <= SEM_VALUE_MAX) { /* Allocate memory for the new semaphore */ diff --git a/nuttx/sched/sem_post.c b/nuttx/sched/sem_post.c index 857b20def..2a6af5e21 100644 --- a/nuttx/sched/sem_post.c +++ b/nuttx/sched/sem_post.c @@ -38,6 +38,7 @@ ************************************************************/ #include <sys/types.h> +#include <limits.h> #include <semaphore.h> #include <sched.h> #include <nuttx/arch.h> @@ -123,7 +124,7 @@ int sem_post(sem_t *sem) /* Perform the semaphore unlock operation. */ - ASSERT(sem->semcount < SEM_MAX_VALUE); + ASSERT(sem->semcount < SEM_VALUE_MAX); sem->semcount++; /* If the result of of semaphore unlock is non-positive, then diff --git a/nuttx/sched/sig_timedwait.c b/nuttx/sched/sig_timedwait.c index eb3151dfa..78fc9c28a 100644 --- a/nuttx/sched/sig_timedwait.c +++ b/nuttx/sched/sig_timedwait.c @@ -106,7 +106,7 @@ static void sig_timeout(int argc, uint32 itcb, ...) if (u.wtcb->task_state == TSTATE_WAIT_SIG) { u.wtcb->sigunbinfo.si_signo = ERROR; - u.wtcb->sigunbinfo.si_code = SI_TIMEOUT; + u.wtcb->sigunbinfo.si_code = SI_TIMER; u.wtcb->sigunbinfo.si_value.sival_int = 0; up_unblock_task(u.wtcb); } @@ -138,11 +138,12 @@ static void sig_timeout(int argc, uint32 itcb, ...) * generated by sigqueue(). * * The following values for si_code are defined in signal.h: + * SI_USER - Signal sent from kill, raise, or abort * SI_QUEUE - Signal sent from sigqueue + * SI_TIMER - Signal is result of timer expiration + * SI_ASYNCIO - Signal is the result of asynch IO completion * SI_MESGQ - Signal generated by arrival of a message on an - * empty message queue - * SI_NOWAIT - Signal already pending -- don't know how sent - * SI_TIMEOUT - No Signal, restarted by timeout + * empty message queue. * * Parameters: * set - The pending signal set. diff --git a/nuttx/sched/task_create.c b/nuttx/sched/task_create.c index 04313c499..d142581ff 100644 --- a/nuttx/sched/task_create.c +++ b/nuttx/sched/task_create.c @@ -170,7 +170,7 @@ int task_create(const char *name, int priority, status = task_activate(tcb); if (status != OK) { - dq_rem((FAR dq_entry_t*)tcb, &g_inactivetasks); + dq_rem((FAR dq_entry_t*)tcb, (dq_queue_t*)&g_inactivetasks); sched_releasetcb(tcb); return ERROR; } diff --git a/nuttx/sched/task_delete.c b/nuttx/sched/task_delete.c index f6f2827e1..4f463bd60 100644 --- a/nuttx/sched/task_delete.c +++ b/nuttx/sched/task_delete.c @@ -148,7 +148,7 @@ STATUS task_delete(pid_t pid) /* Remove the task from the OS's tasks lists. */ - dq_rem((FAR dq_entry_t*)dtcb, g_tasklisttable[dtcb->task_state].list); + dq_rem((FAR dq_entry_t*)dtcb, (dq_queue_t*)g_tasklisttable[dtcb->task_state].list); dtcb->task_state = TSTATE_TASK_INVALID; irqrestore(saved_state); diff --git a/nuttx/sched/task_restart.c b/nuttx/sched/task_restart.c index eb6ef8d72..399bcb6e5 100644 --- a/nuttx/sched/task_restart.c +++ b/nuttx/sched/task_restart.c @@ -139,7 +139,7 @@ STATUS task_restart(pid_t pid) */ state = irqsave(); - dq_rem((FAR dq_entry_t*)tcb, g_tasklisttable[tcb->task_state].list); + dq_rem((FAR dq_entry_t*)tcb, (dq_queue_t*)g_tasklisttable[tcb->task_state].list); tcb->task_state = TSTATE_TASK_INVALID; irqrestore(state); @@ -159,7 +159,7 @@ STATUS task_restart(pid_t pid) /* Add the task to the inactive task list */ - dq_addfirst((FAR dq_entry_t*)tcb, &g_inactivetasks); + dq_addfirst((FAR dq_entry_t*)tcb, (dq_queue_t*)&g_inactivetasks); tcb->task_state = TSTATE_TASK_INACTIVE; /* Activate the task */ @@ -167,7 +167,7 @@ STATUS task_restart(pid_t pid) status = task_activate(tcb); if (status != OK) { - dq_rem((FAR dq_entry_t*)tcb, &g_inactivetasks); + dq_rem((FAR dq_entry_t*)tcb, (dq_queue_t*)&g_inactivetasks); sched_releasetcb(tcb); return ERROR; } diff --git a/nuttx/sched/task_setup.c b/nuttx/sched/task_setup.c index fbce5fcee..6b2a5c2ff 100644 --- a/nuttx/sched/task_setup.c +++ b/nuttx/sched/task_setup.c @@ -201,7 +201,7 @@ STATUS task_schedsetup(FAR _TCB *tcb, int priority, /* Add the task to the inactive task list */ sched_lock(); - dq_addfirst((FAR dq_entry_t*)tcb, &g_inactivetasks); + dq_addfirst((FAR dq_entry_t*)tcb, (dq_queue_t*)&g_inactivetasks); tcb->task_state = TSTATE_TASK_INACTIVE; sched_unlock(); } |