Chapter 5
When a μC/OS-III task begins executing, it is passed an argument, p_arg . This argument is a
pointer to a void . The pointer is a universal vehicle used to pass your task the address of a
variable, a structure, or even the address of a function, if necessary. With this pointer, it is
possible to create many identical tasks, that all use the same code (or task body), but, with
different run-time characteristics. For example, one may have four asynchronous serial ports
that are each managed by their own task. However, the task code is actually identical. Instead
of copying the code four times, create the code for a “generic” task that receives a pointer to a
data structure, which contains the serial port’s parameters (baud rate, I/O port addresses,
interrupt vector number, etc.) as an argument. In other words, instantiate the same task code
four times and pass it different data for each serial port that each instance will manage.
A run-to-completion task must delete itself by calling OSTaskDel() . The task starts,
performs its function, and terminates. There would typically not be too many such tasks in
the embedded system because of the overhead associated with “creating” and “deleting”
tasks at run-time. In the task body, one can call most of μC/OS-III’s functions to help
perform the desired operation of the task.
void MyTask (void *p_arg)
{
OS_ERR err;
/* Local variables
/* Do something with ‘p_arg’
/* Task initialization
/* Task body ... do work!
*/
*/
*/
*/
OSTaskDel((OS_TCB *)0, &err);
}
Listing 5-1 Run-To-Completion task
With μC/OS-III, call either C or assembly language functions from a task. In fact, it is
possible to call the same C function from different tasks as long as the functions are
reentrant. A reentrant function is a function that does not use static or otherwise global
variables unless they are protected (μC/OS-III provides mechanisms for this) from multiple
access. If shared C functions only use local variables, they are generally reentrant (assuming
that the compiler generates reentrant code). An example of a non-reentrant function is the
famous strtok() provided by most C compilers as part of the standard library. This function
is used to parse an ASCII string for “tokens.” The first time you call this function, you specify
76
相关PDF资料
AD-UCUSBD-SPRD PRD LIC UCUSB DEV CORE CCES SGL
AD637-EVALZ BOARD EVALUATION FOR AD637
AD736-EVALZ BOARD EVALUATION FOR AD736
AD737-EVALZ BOARD EVALUATION FOR AD737
AD8007AKS-EBZ BOARD EVAL FOR AD8007AKS
AD8018ARU-EVAL BOARD EVAL FOR AD8018
AD8034ART-EBZ BOARD EVAL FOR AD8034ART
AD8040AR-EBZ BOARD EVAL FOR AD8040AR
相关代理商/技术参数
ADUCOSC100 制造商:Analog Devices 功能描述:ADC - Rail/Tube
ADUCOSC100-REEL 功能描述:DAC MICROCONVERTER DUAL TSSOP 制造商:analog devices inc. 系列:* 零件状态:上次购买时间 标准包装:1
ADUCOSC100-REEL7 功能描述:DAC MICROCONVERTER DUAL TSSOP 制造商:analog devices inc. 系列:* 零件状态:上次购买时间 标准包装:1
ADUCOSCZ100 制造商:Analog Devices 功能描述:
ADUCOSCZ100-REEL7 制造商:Analog Devices 功能描述:ANAADUCOSCZ100-REEL7 12 BIT ADC WITH EMB
ADuC-P7026 功能描述:开发板和工具包 - ARM PROTOTYPE BRD FOR ADUC7026 ARM7 RoHS:否 制造商:Arduino 产品:Development Boards 工具用于评估:ATSAM3X8EA-AU 核心:ARM Cortex M3 接口类型:DAC, ICSP, JTAG, UART, USB 工作电源电压:3.3 V
ADUCRF101 制造商:Analog Devices 功能描述:PRECISION ANALOG MICRCONTROLLER - Tape and Reel
ADUCRF101BCPZ128 制造商:Analog Devices 功能描述:PRECISION ANALOG MICROCONTROLLER WITH RF TRANSCEIVER, ARM CO - Trays