OSTaskRegGet
Description
µC/OS-III allows the user to store task-specific values in task registers. Task registers are different than CPU registers and are used to save such information as “errno
,” which are common in software components. Task registers can also store task-related data to be associated with the task at run time such as I/O register settings, configuration values, etc. A task may have as many as OS_CFG_TASK_REG_TBL_SIZE
registers, and all registers have a data type of OS_REG
. However, OS_REG
can be declared at compile time (see os_type.h
) to be nearly anything (8-, 16-, 32-, 64-bit signed or unsigned integer, or floating-point).
As shown below, a task register is changed by calling OSTaskRegSet()
and read by calling OSTaskRegGet()
. The desired task register is specified as an argument to these functions and can take a value between 0 and OS_CFG_TASK_REG_TBL_SIZE-1
.
Files
os.h/os_task.c
Prototype
OS_REG OSTaskRegGet (OS_TCB *p_tcb, OS_REG_ID id, OS_ERR *p_err)
Arguments
p_tcb
is a pointer to the TCB of the task the user is receiving a task-register value from. A NULL
pointer indicates that the user wants the value of a task register of the calling task.
id
is the identifier of the task register and valid values are from 0
to OS_CFG_TASK_REG_TBL_SIZE-1
.
p_err
is a pointer to a variable that will contain an error code returned by this function.
OS_ERR_NONE
If the call was successful and the function returned the value of the desired task register.
OS_ERR_REG_ID_INVALID
If OS_CFG_ARG_CHK_EN
is set to DEF_ENABLED
in os_cfg.h
: if a valid task register identifier is not specified.
Returned Value
The current value of the task register.
Required Configuration
OS_CFG_TASK_REG_TBL_SIZE
must be greater than 0 in os_cfg.h
. Refer to µC-OS-III Configuration Manual.
Callers
Application.
Notes/Warnings
None
Example Usage
OS_TCB MyTaskTCB; void TaskX (void *p_arg) { OS_ERR err; OS_REG reg; while (DEF_ON) { : reg = OSTaskRegGet(&MyTaskTCB, 5, &err); /* Check "err" */ : : } }