没有合适的资源?快使用搜索试试~ 我知道了~
NuttX Operating System User's Manual
需积分: 5 2 下载量 186 浏览量
2023-11-26
13:39:54
上传
评论
收藏 2.12MB PDF 举报
温馨提示
试读
70页
NuttX Operating System User's Manual
资源推荐
资源详情
资源评论
NuttX Operating System
User's Manual
by
Gregory Nutt
Last Updated: December 13, 2009
1.0 Introduction
This manual provides general usage information for the NuttX RTOS from the perspective of the
firmware developer.
1.1 Document Overview
This user's manual is divided into three sections plus a index:
Section 1.0, Introduction: This section provides an overview of the NuttX user's manual.
Section 2.0, OS Interfaces: This section details the program interfaces provided by NuttX.
This section is divided into several paragraphs that describe different groups of OS interfaces:
Paragraph 2.1 Task Control Interfaces
Paragraph 2.2 Task Scheduling Interfaces
Paragraph 2.3 Task Switching Interfaces
Paragraph 2.4 Named Message Queue Interfaces
Paragraph 2.5 Counting Semaphore Interfaces
Paragraph 2.6 Watchdog Timer Interfaces
Paragraph 2.7 Clocks and Timers
Paragraph 2.8 Signal Interfaces
Paragraph 2.9 Pthread Interfaces
Paragraph 2.10 Environment Variables
Paragraph 2.11 File System Interfaces
Paragraph 2.12 Network Interfaces
Section 3.0, OS Data Structures: This section documents the data structures that are used at
the NuttX interface.
Paragraph 3.1 Scalar Types
Paragraph 3.2 Hidden Interface Structures
Paragraph 3.3 Access to the errno Variable
Paragraph 3.4 User Interface Structures
Index
1.2 Intended Audience and Scope
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. As such, this document does not focus on any
technical details of the organization or implementation of NuttX. Those technical details are
provided in the NuttX Porting Guide.
Information about configuring and building NuttX is also needed by the application developer.
That information can also be found in the NuttX Porting Guide.
2.0 OS Interfaces
This section describes each C-callable interface to the NuttX Operating System. The description of
each interface is presented in the following format:
Function Prototype: The C prototype of the interface function is provided.
Description: The operation performed by the interface function is discussed.
Input Parameters: All input parameters are listed along with brief descriptions of each input
parameter.
Returned Values: All possible values returned by the interface function are listed. Values returned
as side-effects (through pointer input parameters or through global variables) will be addressed in
the description of the interface function.
Assumptions/Limitations: Any unusual assumptions made by the interface function or any non-
obvious limitations to the use of the interface function will be indicated here.
POSIX Compatibility: Any significant differences between the NuttX interface and its
corresponding POSIX interface will be noted here.
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.
2.1 Task Control Interfaces
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
are threads which have a degree of independence
pthreads
share some resources.
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 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.
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.
Executing Programs within a File System. NuttX also provides internal interfaces for the
execution of separately built programs that reside in a file system. These internal interfaces are,
however, non-standard and are documented elsewhere.
Task Control Interfaces. The following task control interfaces are provided by NuttX:
2.1.1 task_create
2.1.2 task_init
2.1.3 task_activate
2.1.4 task_delete
2.1.5 exit
2.1.6 task_restart
2.1.7 getpid
2.1.1 task_create
Function Prototype:
#include <sched.h>
int task_create(char *name, int priority, int stack_size, main_t entry, const char *argv[]);
Description: This function creates and activates a new task with a specified priority and returns its
system-assigned ID.
The entry address entry is the address of the "main" function of the task. This function will be
called once the C environment has been set up. The specified function will be called with four
arguments. Should the specified routine return, a call to exit() will automatically be made.
Note that an arbitrary number of arguments may be passed to the spawned functions. The
maximum umber of arguments is an OS configuration parameter (CONFIG_MAX_TASK_ARGS).
The arguments are copied (via strdup) so that the life of the passed strings is not dependent on the
life of the caller to task_create().
The newly created task does not inherit scheduler characteristics from the parent task: The new
task is started at the default system priority and with the SCHED_FIFO scheduling policy. These
characteristics may be modified after the new task has been started.
The newly created task does inherit the first three file descriptors (corresponding to stdin, stdout,
and stderr) and redirection of standard I/O is supported.
Input Parameters:
name
. Name of the new task
priority
. Priority of the new task
stack_size
. size (in bytes) of the stack needed
entry
. Entry point of a new task
argv
. A pointer to an array of input parameters. Up to CONFIG_MAX_TASK_ARG parameters may be
provided. If fewer than CONFIG_MAX_TASK_ARG parameters are passed, the list should be terminated
with a NULL argv[] value. If no parameters are required, argv may be NULL.
Returned Values:
Returns the non-zero task ID of the new task or ERROR if memory is insufficient or the task
cannot be created (errno is not set).
Assumptions/Limitations:
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);
The NuttX task_create() differs from VxWorks' taskSpawn() in the following ways:
Interface name
Various differences in types of arguments
There is no options argument.
A variable number of parameters can be passed to a task (VxWorks supports ten).
2.1.2 task_init
Function Prototype:
#include <sched.h>
int task_init(_TCB *tcb, char *name, int priority, uint32_t *stack, uint32_t stack_size,
maint_t entry, const char *argv[]);
Description:
This function initializes a Task Control Block (TCB) in preparation for starting a new thread. It
performs a subset of the functionality of task_create() (see above).
Unlike task_create(), task_init() does not activate the task. This must be done by calling
task_activate().
Input Parameters:
tcb
. Address of the new task's TCB
name
. Name of the new task (not used)
priority
. Priority of the new task
stack
. Start of the pre-allocated stack
stack_size
. size (in bytes) of the pre-allocated stack
entry
. Entry point of a new task
argv
. A pointer to an array of input parameters. Up to CONFIG_MAX_TASK_ARG parameters may be
provided. If fewer than CONFIG_MAX_TASK_ARG parameters are passed, the list should be terminated
with a NULL argv[] value. If no parameters are required, argv may be NULL.
Returned Values:
OK, or ERROR if the task cannot be initialized.
This function can only failure is it is unable to assign a new, unique task ID to the TCB (errno is
not set).
Assumptions/Limitations:
task_init() is provided to support internal OS functionality. It is not recommended for normal
usage. task_create() is the preferred 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_t *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:
Interface name
Various differences in types or arguments
There is no options argument.
A variable number of parameters can be passed to a task (VxWorks supports ten).
2.1.3 task_activate
Function Prototype:
#include <sched.h>
int task_activate( _TCB *tcb );
Description: This function activates tasks created by task_init(). Without activation, a task is
ineligible for execution by the scheduler.
Input Parameters:
tcb
. The TCB for the task for the task (same as the task_init argument).
Returned Values:
OK, or ERROR if the task cannot be activated (errno is not set).
Assumptions/Limitations:
task_activate() is provided to support internal OS functionality. It is not recommended for
normal usage. task_create() is the preferred mechanism to initialize and start a new task.
POSIX Compatibility: This is a NON-POSIX interface. VxWorks provides the following similar
interface:
STATUS taskActivate( int tid );
The NuttX task_activate() differs from VxWorks' taskActivate() in the following ways:
Function name
With VxWork's taskActivate, the pid argument is supposed to be the pointer to the WIND_TCB
cast to an integer.
2.1.4 task_delete
Function Prototype:
#include <sched.h>
int task_delete( pid_t pid );
Description: This function causes a specified task to cease to exist -- its stack and TCB will be
deallocated. This function is the companion to task_create().
Input Parameters:
剩余69页未读,继续阅读
资源评论
CX19970
- 粉丝: 70
- 资源: 35
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功