From 439c40e54b2dc80cd356c1c8bb7c3564d919333f Mon Sep 17 00:00:00 2001
From: patacongo
-User's Manual
-
-
-by
-
-Gregory Nutt
-
-Last Update: September 1, 2008
- User's Manual by Gregory Nutt
+ Last Updated: September 10, 2008
This manual provides general usage information for the NuttX RTOS from the
perspective of the firmware developer.
-
This user's manual is divided into three sections plus a index:
The intended audience for this document are firmware developers who are implementing applications on NuttX.
Specifically, this documented is limited to addressing only NuttX RTOS APIs that are available to the application developer.
@@ -86,9 +101,14 @@ Gregory Nutt
That information can also be found in the NuttX Porting Guide.
This section describes each C-callable interface to the NuttX
Operating System. The description of each interface is presented
@@ -120,9 +140,15 @@ NOTE: In order to achieve an independent name space for the NuttX
interface functions, differences in function names and types are
to be expected and will not be identified as differences in these
paragraphs.
-
-
-Under Construction
-
-
+
+
+
+
+
+
+ NuttX Operating System
+
-1.0 Introduction
+
+
+
+
+
+ 1.0 Introduction
+ 1.1 Document Overview
+
+
+
+
+
+
+ 1.1 Document Overview
+ 1.2 Intended Audience and Scope
+
+
+
+
+
+
+ 1.2 Intended Audience and Scope
+
+
+
-
+
+
+
+ 2.0 OS Interfaces
+ 2.0 OS Interfaces
+
+ 2.1 Task Control Interfaces+ |
+
Tasks. @@ -554,8 +580,15 @@ level.
POSIX Compatibility: Compatible with the POSIX interface of the same name. +
-
+ 2.2 Task Scheduling Interfaces+ |
+
By default, NuttX performs strict priority scheduling: Tasks of higher @@ -916,7 +949,13 @@ priority of the calling task is returned. interface of the same name.
-
+ 2.3 Task Switching Interfaces+ |
+
POSIX Compatibility: None. -
+ 2.4 Named Message Queue Interfaces+ |
+
NuttX supports POSIX named message queues for intertask communication. @@ -1626,8 +1671,15 @@ attributes include:
POSIX Compatibility: Comparable to the POSIX interface of the same name. +
-
+ 2.5 Counting Semaphore Interfaces+ |
+
Semaphores. Semaphores are the basis for @@ -2094,10 +2146,15 @@ number of tasks waiting for the semaphore.
POSIX Compatibility: Comparable to the POSIX interface of the same name. +
-
+ 2.6 Watchdog Timer Interfaces+ |
+
NuttX provides a general watchdog timer facility. @@ -2313,9 +2370,14 @@ VxWorks provides the following comparable interface: means either that wdog is not valid or that the wdog has already expired.
-
+ 2.7 Clocks and Timers+ |
+
POSIX Compatibility: Comparable to the POSIX interface of the same name. +
-
+ 2.8 Signal Interfaces+ |
+
NuttX provides signal interfaces for tasks. Signals are used to @@ -3393,7 +3460,14 @@ be sent.
+ 2.9 Pthread Interfaces+ |
+
NuttX does not support processes in the way that, say, Linux does. NuttX only supports simple threads or tasks running within the same address space. @@ -5656,7 +5730,14 @@ interface of the same name. POSIX Compatibility: Comparable to the POSIX interface of the same name.
-
+ 2.10 Environment Variables+ |
+
Overview. NuttX supports environment variables that can be used to control the behavior of programs. In the spirit of NuttX the environment variable behavior attempts to emulate the behavior of @@ -5695,12 +5776,12 @@ interface of the same name. in the board configuration file.
-getenv
getenv
Function Prototype:
- #include+ #include <stdlib.h> FAR char *getenv(const char *name);
@@ -5723,12 +5804,12 @@ interface of the same name. The value of the valiable (read-only) or NULL on failure.
-putenv
putenv
Function Prototype:
- #include+ #include <stdlib.h> int putenv(char *string);
@@ -5754,12 +5835,12 @@ interface of the same name. Zero on sucess.
-clearenv
clearenv
Function Prototype:
- #include+ #include <stdlib.h> int clearenv(void);
@@ -5776,12 +5857,12 @@ interface of the same name. Zero on success.
-setenv
setenv
Function Prototype:
- #include+ #include <stdlib.h> int setenv(const char *name, const char *value, int overwrite);
@@ -5814,12 +5895,12 @@ interface of the same name. Zero on success.
-unsetenv
unsetenv
Function Prototype:
- #include+ #include <stdlib.h> int unsetenv(const char *name);
@@ -5841,7 +5922,13 @@ interface of the same name. Zero on success.
-
+ 2.11 File System Interfaces+ |
+
mmap()
and eXecute In Place (XIP)Overview. NuttX includes an optional, scalable file system. @@ -5909,7 +5997,7 @@ interface of the same name. in a file-system-like name space.
-#include <fcntl.h> @@ -5937,7 +6025,7 @@ interface of the same name.-
#include <dirent.h> @@ -5959,7 +6047,7 @@ interface of the same name.-
#include <stdio.h> int fclose(FILE *stream); @@ -5997,14 +6085,14 @@ interface of the same name. int statfs(const char *path, FAR struct statfs *buf); /* Prototyped but not implemented */-
pipe
Function Prototype:
- #include+ #include <unistd.h> int pipe(int filedes[2]);
@@ -6038,7 +6126,7 @@ interface of the same name. Function Prototype:
- #include+ #include <sys/stat.h> int mkfifo(FAR const char *pathname, mode_t mode);
@@ -6080,13 +6168,13 @@ interface of the same name.
-mkfatfs
mkfatfs
Function Prototype:
-#include+#include <nuttx/mkfatfs.h> int mkfatfs(FAR const char *pathname, FAR struct fat_format_s *fmt);
@@ -6158,7 +6246,164 @@ struct fat_format_s
-mmap()
and eXecute In Place (XIP)
+ NuttX operates in a flat open address space.
+ Therefore, it generally does not require mmap()
functionality.
+ There is one one exception:
+ mmap()
is the API that is used to support direct access to random
+ access media under the following very restrictive conditions:
+
FIOC_MMAP
ioctl command.
+ Any file system that maps files contiguously on the media should support this
+ ioctl
command.
+ By comparison, most file system scatter files over the media in non-contiguous
+ sectors. As of this writing, ROMFS is the only file system that meets this requirement.
+ BIOC_XIPBASE
ioctl
command
+ that maps the underlying media to a randomly accessible address.
+ At present, only the RAM/ROM disk driver does this.
+ mmap
+ Function Prototype: +
++#include <sys/mman.h> +int mkfatfs(FAR const char *pathname, FAR struct fat_format_s *fmt); +FAR void *mmap(FAR void *start, size_t length, int prot, int flags, int fd, off_t offset) ++
+ Description: +
mmap()
as needed to support eXecute In Place (XIP)
+ operation (as described above).
+ + Input Parameters: +
start
+ A hint at where to map the memory -- ignored.
+ The address of the underlying media is fixed and cannot be re-mapped without MMU support.
+ length
+ The length of the mapping -- ignored.
+ The entire underlying media is always accessible.
+ prot
+ See the PROT_*
definitions in sys/mman.h
.
+ PROT_NONE
- Will cause an error.
+ PROT_READ
- PROT_WRITE
and PROT_EXEC
also assumed.
+ PROT_WRITE
- PROT_READ
and PROT_EXEC
also assumed.
+ PROT_EXEC
- PROT_READ
and PROT_WRITE
also assumed.
+ flags
+ See the MAP_*
definitions in sys/mman.h
.
+ MAP_SHARED
- Required
+ MAP_PRIVATE
- Will cause an error
+ MAP_FIXED
- Will cause an error
+ MAP_FILE
- Ignored
+ MAP_ANONYMOUS
- Will cause an error
+ MAP_ANON
- Will cause an error
+ MAP_GROWSDOWN
- Ignored
+ MAP_DENYWRITE
- Will cause an error
+ MAP_EXECUTABLE
- Ignored
+ MAP_LOCKED
- Ignored
+ MAP_NORESERVE
- Ignored
+ MAP_POPULATE
- Ignored
+ AP_NONBLOCK
- Ignored
+ fd
+ file descriptor of the backing file -- required.
+ offset
+ The offset into the file to map.
+ + Returned Values: +
+ On success, mmap()
returns a pointer to the mapped area.
+ On error, the value MAP_FAILED
is returned, and errno
is set appropriately.
+
ENOSYS
-
+ Returned if any of the unsupported mmap()
features are attempted.
+ EBADF
-
+ fd
is not a valid file descriptor.
+ EINVAL
-
+ Length is 0. flags contained neither MAP_PRIVATE
or MAP_SHARED
, or
+ contained both of these values.
+ ENODEV
-
+ The underlying filesystem of the specified file does not support memory mapping.
+
+ 2.12 Network Interfaces+ |
+
NuttX includes a simple interface layer based on uIP (see http://www.sics.se). NuttX supports subset of a standard socket interface to uIP. These network feature can be enabled by settings in the architecture @@ -6185,7 +6430,7 @@ Those socket APIs are discussed in the following paragraphs.
Function Prototype:- #include+ #include <sys/socket.h> int socket(int domain, int type, int protocol);
@@ -6227,7 +6472,7 @@ Those socket APIs are discussed in the following paragraphs.
Function Prototype:- #include+ #include <sys/socket.h> int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
@@ -6269,7 +6514,7 @@ Those socket APIs are discussed in the following paragraphs.
Function Prototype:- #include+ #include <sys/socket.h> int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
@@ -6348,7 +6593,7 @@ Those socket APIs are discussed in the following paragraphs.
Function Prototype:- #include+ #include <sys/socket.h> int listen(int sockfd, int backlog);
@@ -6386,7 +6631,7 @@ Those socket APIs are discussed in the following paragraphs.
Function Prototype:- #include+ #include <sys/socket.h> int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
@@ -6464,7 +6709,7 @@ Those socket APIs are discussed in the following paragraphs.
Function Prototype:- #include+ #include <sys/socket.h> ssize_t send(int sockfd, const void *buf, size_t len, int flags);
@@ -6496,7 +6741,7 @@ Those socket APIs are discussed in the following paragraphs.
Function Prototype:- #include@@ -6569,7 +6814,7 @@ Those socket APIs are discussed in the following paragraphs. Function Prototype:+ #include <sys/socket.h> ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *to, socklen_t tolen);
- #include+ #include <sys/socket.h> ssize_t recv(int sockfd, void *buf, size_t len, int flags);
@@ -6600,7 +6845,7 @@ Those socket APIs are discussed in the following paragraphs.
Function Prototype:- #include@@ -6662,7 +6907,7 @@ Those socket APIs are discussed in the following paragraphs. Function Prototype:+ #include <sys/socket.h> ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen);
- #include@@ -6678,7 +6923,7 @@ Those socket APIs are discussed in the following paragraphs. options at the socket level, specify the level argument as SOL_SOCKET.+ #include <sys/socket.h> int setsockopt(int sockfd, int level, int option, const void *value, socklen_t value_len);
- See option
argument.
+ See sys/socket.h
for a complete list of values for the option
argument.
Input Parameters: @@ -6722,7 +6967,7 @@ Those socket APIs are discussed in the following paragraphs.
Function Prototype:- #include@@ -6741,7 +6986,7 @@ Those socket APIs are discussed in the following paragraphs. SOL_SOCKET.+ #include <sys/socket.h> int getsockopt(int sockfd, int level, int option, void *value, socklen_t *value_len);
- See option
argument.
+ See sys/socket.h
for a complete list of values for the option
argument.
Input Parameters: @@ -6772,9 +7017,22 @@ Those socket APIs are discussed in the following paragraphs.
Insufficient resources are available in the system to complete the call. -
+ 3.0 OS Data Structures+ |
+
+ 3.1 Scalar Types+ |
+
Many of the types used to communicate with NuttX are simple scalar types. These types are used to provide architecture independence @@ -6788,7 +7046,14 @@ interface include:
+ 3.2 Hidden Interface Structures+ |
+
Several of the types used to interface with NuttX are structures that are intended to be hidden from the application. @@ -6807,9 +7072,15 @@ OS resources. These hidden structures include: specific elements within these hidden structures. These hidden structures will not be described further in this user's manual.
--
errno
Variable
+ 3.3 Access to the
+ |
+
A pointer to the thread-specific errno
value is available through a
function call:
@@ -6817,7 +7088,7 @@ OS resources. These hidden structures include:
Function Prototype:
-
#include+ #include <errno.h> #define errno *get_errno_ptr() int *get_errno_ptr( void )@@ -6841,10 +7112,16 @@ OS resources. These hidden structures include:
-
- A pointer to the thread-specific
errno
value.+
+ ++
-+ ++ +3.4 User Interface Structures
+3.4 User Interface Structures
-
3.4.1 main_t
main_t defines the type of a task entry point. main_t is declared @@ -6984,12 +7261,20 @@ notify a task when a message is available on a queue. have to do some redesign.
-Index
++
++ ++ +Index
+