From 8b098e598a029c60efea69e20f19231dd176b951 Mon Sep 17 00:00:00 2001
From: patacongo
-This user's manual is divided into three sections:
+This user's manual is divided into three sections plus a index:
-Tasks.
-NuttX is a flat address OS. As such it does not support "processes"
-in the way that, say, Linux does.
-NuttX only supports simple threads running within the same address space.
-However, the programming model makes a distinction between "tasks"
-and pthreads:
+ Tasks.
+ NuttX is a flat address OS. As such it does not support "processes"
+ in the way that, say, Linux does.
+ NuttX only supports simple threads running within the same address space.
+ However, the programming model makes a distinction between "tasks"
+ and pthreads:
+
-File Descriptors and Streams.
-This applies, in particular, in the area of opened file descriptors and streams.
-When a task is started using the interfaces in this section, it will be created
-with at most three open files.
-
-If CONFIG_DEV_CONSOLE is defined, the first three file descriptors (corresponding
-to stdin, stdout, stderr) will be duplicated for the the new task.
-Since these file descriptors are duplicated, the child task can free close
-them or manipulate them in any way without effecting the parent task.
-File-related operations (open, close, etc.) within a task will have no effect
-on other tasks.
-Since the three file descriptors are duplicated, it is also possible to perform
-some level of redirection.
+ File Descriptors and Streams.
+ This applies, in particular, in the area of opened file descriptors and streams.
+ When a task is started using the interfaces in this section, it will be created
+ with at most three open files.
+1.0 Introduction
+
2.0 OS Interfaces
@@ -89,47 +90,58 @@ paragraphs.
2.1 Task Control Interfaces
-
-pthreads, on the other hand, will always share file descriptors with the parent -thread. In this case, file operations will have effect only all pthreads the -were started from the same parent thread. + pthreads, on the other hand, will always share file descriptors with the parent + thread. In this case, file operations will have effect only all pthreads the + were started from the same parent thread. +
++ The following task control interfaces are provided by Nuttx: +
+Function Prototype:
#include <sched.h> - int task_create( - char *name, - int priority, - int stack_size, - main_t entry, - const char *argv[]); + int task_create(char *name, int priority, int stack_size, main_t entry, const char *argv[]);
@@ -196,19 +208,15 @@ were started from the same parent thread. POSIX Compatibility: This is a NON-POSIX interface. VxWorks provides the following similar interface:
- int taskSpawn( - char *name, - int priority, - int options, - int stackSize, - FUNCPTR entryPt, - int arg1, int arg2, int arg3, int arg4, int arg5, - int arg6, int arg7, int arg8, int arg9, int arg10); + int taskSpawn(char *name, int priority, int options, int stackSize, FUNCPTR entryPt, + int arg1, int arg2, int arg3, int arg4, int arg5, + int arg6, int arg7, int arg8, int arg9, int arg10);
-The NuttX task_create() differs from VxWorks' taskSpawn() in the -following ways: + The NuttX task_create() differs from VxWorks' taskSpawn() in the + following ways: +
Function Prototype:
#include <sched.h> - STATUS task_init( - _TCB *tcb, - char *name, - int priority, - uint32 *stack, - uint32 stack_size, - maint_t entry, - const char *argv[]); + STATUS task_init(_TCB *tcb, char *name, int priority, uint32 *stack, uint32 stack_size, + maint_t entry, const char *argv[]);
@@ -278,21 +280,15 @@ mechanism to initialize and start a new task. POSIX Compatibility: This is a NON-POSIX interface. VxWorks provides the following similar interface:
- STATUS taskInit( - WIND_TCB *pTcb, - char *name, - int priority, - int options, - uint32 *pStackBase, - int stackSize, - FUNCPTR entryPt, - int arg1, int arg2, int arg3, int arg4, int arg5, - int arg6, int arg7, int arg8, int arg9, int arg10); + STATUS taskInit(WIND_TCB *pTcb, char *name, int priority, int options, uint32 *pStackBase, int stackSize, + FUNCPTR entryPt, int arg1, int arg2, int arg3, int arg4, int arg5, + int arg6, int arg7, int arg8, int arg9, int arg10);
-The NuttX task_init() differs from VxWorks' taskInit() in the -following ways: + The NuttX task_init() differs from VxWorks' taskInit() in the + following ways: +
Function Prototype: @@ -341,15 +337,16 @@ VxWorks provides the following similar interface:
-The NuttX task_activate() differs from VxWorks' taskActivate() in the -following ways: + The NuttX task_activate() differs from VxWorks' taskActivate() in the + following ways: +
Function Prototype: @@ -390,15 +387,16 @@ VxWorks provides the following similar interface:
-The NuttX task_delete() differs from VxWorks' taskDelete() in -the following ways: + The NuttX task_delete() differs from VxWorks' taskDelete() in + the following ways: +
Function Prototype: @@ -438,13 +436,13 @@ And the unix interface:
-The NuttX exit() differs from ANSI exit() in -the following ways: + The NuttX exit() differs from ANSI exit() in the following ways: +
Function Prototype: @@ -487,15 +485,15 @@ VxWorks provides the following similar interface:
-The NuttX task_restart() differs from VxWorks' taskRestart() in -the following ways: + The NuttX task_restart() differs from VxWorks' taskRestart() in the following ways: +
Function Prototype: @@ -524,19 +522,35 @@ Compatible with the POSIX interface of the same name.
-NuttX performs strict priority scheduling: Tasks of higher -priority have exclusive access to the CPU until they become blocked. -At that time, the CPU is available to tasks of lower priority. -Tasks of equal priority are scheduled FIFO. -
-The OS interfaces described in the following paragraphs provide -a POSIX- compliant interface to the NuttX scheduler. However, these -POSIX interfaces assume a greater range of scheduling options -than those provided by the NuttX scheduler. As a result, many of -these POSIX interfaces are little more than stubs. +
+ By default, NuttX performs strict priority scheduling: Tasks of higher + priority have exclusive access to the CPU until they become blocked. + At that time, the CPU is available to tasks of lower priority. + Tasks of equal priority are scheduled FIFO. +
+
+ Optionally, a Nuttx task or thread can be configured with round-robin
+ scheduler. This is similar to priority scheduling except that
+ tasks with equal priority and share CPU time via time-slicing.
+ The time-slice interval is a constant determined by the configuration
+ setting CONFIG_RR_INTERVAL
.
+
+ The OS interfaces described in the following paragraphs provide + a POSIX- compliant interface to the NuttX scheduler: +
+Function Prototype: @@ -583,7 +597,7 @@ Differences from the full POSIX implementation include:
Function Prototype: @@ -617,7 +631,7 @@ element of this structure. POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -660,7 +674,7 @@ interface of the same name. POSIX Compatibility: Comparable to the POSIX interface of the same name. -2.2.4 sched_getscheduler
+2.2.4 sched_getscheduler
Function Prototype:
@@ -670,7 +684,7 @@ interface of the same name.Description: sched_getscheduler() returns the scheduling policy - currently applied to the process identified by pid. If + currently applied to the task identified by pid. If pid equals zero, the policy of the calling process will be retrieved. * @@ -710,7 +724,7 @@ Differences from the full POSIX implementation include:
Function Prototype: @@ -736,7 +750,7 @@ up the CPU (only to other tasks at the same priority). POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype: @@ -766,7 +780,7 @@ possible task priority for a specified scheduling policy. POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype: @@ -796,7 +810,7 @@ possible task priority for a specified scheduling policy. POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype: @@ -844,7 +858,13 @@ priority of the calling task is returned.
Function Prototype: @@ -876,7 +896,7 @@ VxWorks provides the comparable interface: STATUS taskLock( void ); -
Function Prototype: @@ -909,7 +929,7 @@ VxWorks provides the comparable interface: STATUS taskUnlock( void ); -
Function Prototype: @@ -939,12 +959,23 @@ on this thread of execution.
-The NuttX supports POSIX named message queues for intertask communication. -Any task may send or receive messages on named message queues. -Interrupt handlers may send messages via named message queues. +
+ NuttX supports POSIX named message queues for intertask communication. + Any task may send or receive messages on named message queues. + Interrupt handlers may send messages via named message queues. +
+Function Prototype: @@ -1013,7 +1044,7 @@ may be sent or received. In the present implementation, this maximum message size is limited at 22 bytes. -
Function Prototype: @@ -1058,7 +1089,7 @@ return from mq_close() is undefined. POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype: @@ -1087,7 +1118,7 @@ closed. POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype: @@ -1136,7 +1167,7 @@ Differences from the full POSIX implementation include:
Function Prototype: @@ -1186,7 +1217,7 @@ Differences from the full POSIX implementation include:
Function Prototype: @@ -1242,7 +1273,7 @@ appropriate mq_receive() ... The resulting behavior is as if the message queue remains empty, and no notification shall be sent." -
Function Prototype: @@ -1281,7 +1312,7 @@ would have been returned by mq_getattr()). POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype: @@ -1322,53 +1353,71 @@ interface of the same name.
-Semaphores. Semaphores are the basis for -synchronization and mutual exclusion in NuttX. NuttX supports -POSIX semaphores. -
-Semaphores are the preferred mechanism for gaining exclusive access to a -resource. sched_lock() and sched_unlock() can also be used for this purpose. -However, sched_lock() and sched_unlock() have other undesirable side-affects -in the operation of the system: sched_lock() also prevents higher-priority -tasks from running that do not depend upon the semaphore-managed resource -and, as a result, can adversely affect system response times. -
-Priority Inversion. Proper use of semaphores avoids the issues of -sched_lock(). However, consider the following example: -
-Some operating systems avoid priority inversion by automatically -increasing the priority of the low-priority Task C (the operable -buzz-word for this behavior is mutex semaphores). The NuttX does not -support this behavior. As a consequence, it is left to the designer to -provide implementations that will not suffer from priority inversion. -The designer may, as examples: +
+ Semaphores. Semaphores are the basis for + synchronization and mutual exclusion in NuttX. NuttX supports + POSIX semaphores. +
++ Semaphores are the preferred mechanism for gaining exclusive access to a + resource. sched_lock() and sched_unlock() can also be used for this purpose. + However, sched_lock() and sched_unlock() have other undesirable side-affects + in the operation of the system: sched_lock() also prevents higher-priority + tasks from running that do not depend upon the semaphore-managed resource + and, as a result, can adversely affect system response times. +
++ Priority Inversion. Proper use of semaphores avoids the issues of + sched_lock(). However, consider the following example: +
+ At this point, the high-priority Task A cannot execute until + Task B (and possibly other medium-priority tasks) completes and until + Task C relinquishes the semaphore. In effect, the high-priority task, + Task A behaves as though it were lower in priority than the + low-priority task, Task C! This phenomenon is called priority + inversion. +
++ Some operating systems avoid priority inversion by automatically + increasing the priority of the low-priority Task C (the operable + buzz-word for this behavior is priority inheritance). NuttX does not + support this behavior. As a consequence, it is left to the designer to + provide implementations that will not suffer from priority inversion. + The designer may, as examples: +
+
+ POSIX semaphore interfaces: +
+Function Prototype: @@ -1411,7 +1460,7 @@ Differences from the full POSIX implementation include:
Function Prototype: @@ -1448,7 +1497,7 @@ blocked is undefined. POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype: @@ -1514,7 +1563,7 @@ Differences from the full POSIX implementation include: just a counting semaphore. -
Function Prototype: @@ -1559,7 +1608,7 @@ has already locked. POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype: @@ -1605,7 +1654,7 @@ refer to the same semaphore; POSIX specifies that a new semaphore with the same name should be created after sem_unlink() is called. -
Function Prototype: @@ -1648,7 +1697,7 @@ received by this task. In this case, the semaphore has not be acquired. POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype: @@ -1690,7 +1739,7 @@ not valid. POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype: @@ -1733,7 +1782,7 @@ task is the one that is performing the unlock. POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype: @@ -1777,15 +1826,21 @@ interface of the same name.
-The NuttX provides a general watchdog timer facility. This -facility allows the NuttX user to specify a watchdog timer function -that will run after a specified delay. The watchdog timer function -will run in the context of the timer interrupt handler. Because -of this, a limited number of NuttX interfaces are available to -the watchdog timer function. However, the watchdog timer function -may use mq_send(), and sigqueue() to communicate with NuttX tasks. + NuttX provides a general watchdog timer facility. + This facility allows the NuttX user to specify a watchdog timer function + that will run after a specified delay. + The watchdog timer function will run in the context of the timer interrupt handler. + Because of this, a limited number of NuttX interfaces are available to he watchdog timer function. + However, the watchdog timer function may use mq_send(), sigqueue(), or kill() to communicate with NuttX tasks. +
+ -Function Prototype: @@ -1823,7 +1878,7 @@ Differences from the VxWorks interface include: initialization time). -
Function Prototype: @@ -1867,7 +1922,7 @@ Differences from the VxWorks interface include: before de-allocating it (i.e., never returns ERROR). -
Function Prototype: @@ -1927,7 +1982,7 @@ to wdentry; VxWorks supports only a single parameter. The maximum number of parameters is determined by -
Function Prototype: @@ -1965,27 +2020,46 @@ VxWorks provides the following comparable interface:
-The NuttX provides signal interfaces for tasks. Signals are -used to alter the flow control of tasks by communicating asynchronous -events within or between task contexts. Any task or interrupt -handler can post (or send) a signal to a particular task. The -task being signaled will execute task-specified signal handler -function the next time that the task has priority. -The signal handler is a user-supplied function that is bound to -a specific signal and performs whatever actions are necessary -whenever the signal is received. -
-Signal handlers execute in the context of the task that registered -the signal handler. -
-There are no predefined actions for any signal. -The default action for all signals (i.e., when no signal handler has -been supplied by the user) is to ignore the signal. -
-Tasks may also suspend themselves and wait until a signal is received. +
+ NuttX provides signal interfaces for tasks. Signals are used to + alter the flow control of tasks by communicating asynchronous events + within or between task contexts. + Any task or interrupt handler can post (or send) a signal to a particular task. + The task being signaled will execute task-specified signal handler + function the next time that the task has priority. + The signal handler is a user-supplied function that is bound to + a specific signal and performs whatever actions are necessary + whenever the signal is received. +
++ There are no predefined actions for any signal. + The default action for all signals (i.e., when no signal handler has + been supplied by the user) is to ignore the signal. + In this sense, all NuttX are real time signals. +
++ Tasks may also suspend themselves and wait until a signal is received. +
++ The following signal handling interfaces are provided by NuttX: +
+Function Prototype: @@ -2015,7 +2089,7 @@ by set such that all signals are excluded. POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype: @@ -2045,7 +2119,7 @@ by set such that all signals are included. POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype: @@ -2076,7 +2150,7 @@ signo to the signal set specified by set. POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype: @@ -2107,7 +2181,7 @@ by signo from the signal set specified by set. POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype: @@ -2140,7 +2214,7 @@ by signo is a member of the set specified by set. POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype: @@ -2213,7 +2287,7 @@ not handled (SIG_DFL, SIG_IGN). (all treated like SA_SIGINFO). -
Function Prototype: @@ -2263,7 +2337,7 @@ pointed to by the set input parameter. POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype: @@ -2301,7 +2375,7 @@ is delivered more than once." POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype: @@ -2349,7 +2423,7 @@ function or to terminate the task." Only delivery of the signal is required in the present implementation (even if the signal is ignored). -
Function Prototype: @@ -2381,7 +2455,7 @@ with a NULL timeout parameter. (see below). POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype: @@ -2447,7 +2521,7 @@ that the unblocked signal be caught; the task will be resumed even if the unblocked signal is ignored. -
Function Prototype: @@ -2470,7 +2544,7 @@ is delivered more than once."
Input Parameters:
Returned Values:
EGAIN
. The limit of signals which may be queued has been reached.EINVAL
. signo was invalid.EPERM
. The task does not have permission to send the signal to the receiving process.ESRCH
. No process has a PID matching pid.@@ -2490,17 +2572,114 @@ Differences from the POSIX interface include:
-
+ #include <sys/types.h> + #include <signal.h> + int kill(pid_t pid, int sig); ++ +
+Description: + The kill() system call can be used to send any signal to + any task. +
++ If the receiving task has the signal blocked via its sigprocmask, + the signal will pend until it is unmasked. Only one pending signal + (for a given signo) is retained by the system. This is consistent with + POSIX which states: "If a subsequent occurrence of a pending signal + is generated, it is implementation defined as to whether the signal + is delivered more than once." +
++Input Parameters: +
kill()
specification encodes process group
+ information as zero and negative pid values.
+ Only positive, non-zero values of pid are supported by this
+ implementation. ID of the task to receive signal
++ Returned Values: +
+ Assumptions/Limitations: +
++ POSIX Compatibility: + Comparable to the POSIX interface of the same name. + Differences from the POSIX interface include: +
+Function Prototype:
@@ -2533,7 +2712,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name.
-
Function Prototype:
@@ -2565,7 +2744,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name.
-
Function Prototype:
@@ -2596,7 +2775,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -2627,7 +2806,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -2659,7 +2838,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -2691,7 +2870,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -2723,7 +2902,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name.
-
Function Prototype:
@@ -2755,7 +2934,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -2786,7 +2965,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -2817,7 +2996,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -2856,7 +3035,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -2889,7 +3068,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -2921,7 +3100,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -2977,7 +3156,7 @@ the time when cancelation is re-enabled.
Function Prototype:
@@ -3019,17 +3198,17 @@ No thread could be found corresponding to that specified by the given thread ID. POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
#include <pthread.h> - int pthread_setcancelstate(int state, int *oldstate); + int pthread_setcancelstate(void);
Description: -
+
NOT SUPPORTED Input Parameters:
Function Prototype:
@@ -3083,7 +3262,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -3116,7 +3295,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -3148,7 +3327,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -3180,7 +3359,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -3212,7 +3391,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -3267,7 +3446,7 @@ interface of the same name.
Function Prototype:
@@ -3317,7 +3496,7 @@ interface of the same name. destructor function. -
Function Prototype:
@@ -3358,7 +3537,7 @@ interface of the same name. destructor function. -
Function Prototype:
@@ -3390,7 +3569,7 @@ this function does nothing in the present implementation. POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -3421,7 +3600,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Protoype:
@@ -3452,7 +3631,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -3484,7 +3663,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -3516,7 +3695,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -3548,7 +3727,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -3579,7 +3758,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -3610,7 +3789,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -3641,7 +3820,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -3672,7 +3851,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -3703,7 +3882,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -3734,7 +3913,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -3765,7 +3944,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -3796,7 +3975,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -3827,7 +4006,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -3858,7 +4037,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -3889,7 +4068,7 @@ returned to indicate the error: POSIX Compatibility: Comparable to the POSIX interface of the same name. -
Function Prototype:
@@ -4124,5 +4303,115 @@ notify a task when a message is available on a queue. have to do some redesign.
+