...
Description
OSTaskStkChk()
determines a task’s stack statistics. Specifically, it computes the amount of free stack space, as well as the amount of stack space used by the specified task. This function requires that the task be created with the the OS_TASK_OPT_STK_CHK
and and OS_TASK_OPT_STK_CLR
options options.anchor
0
entries entries on the stack until a non-zero value is found.It is possible to not set the the OS_TASK_OPT_STK_CLR
when when creating the task if the startup code clears all RAM, and tasks are not deleted (this reduces the execution time of of OSTaskCreate()
).
Anchor
OSTaskStkChk()
for for each task created and stores the results in each task’s task’s OS_TCB
so so your application doesn’t need to call this function if the statistic task is enabled.Files
os.h/os_task.c
Prototype
Code Block |
---|
void OSTaskStkChk (OS_TCB *p_tcb,
CPU_STK_SIZE *p_free,
CPU_STK_SIZE *p_used,
OS_ERR *p_err) |
Arguments
p_tcb
is a pointer to the TCB of the task where the stack is being checked. A NULL
pointer indicates that the user is checking the calling task’s stack.
...
p_free
Anchor
is a pointer to a variable of type CPU_STK_SIZE
and will contain the number of free CPU_STK
elements on the stack of the task being inquired about.
...
p_used
Anchor
is a pointer to a variable of type CPU_STK_SIZE
and will contain the number of used CPU_STK
elements on the stack of the task being inquired about.
Anchor
p_err
is a pointer to a variable that will contain an error code returned by this function.
...
class | WebWorks_Indent_1 |
---|
...
...
OS_ERR_NONE
...
class | WebWorks_Indent_2 |
---|
...
If the call was successful.
...
...
class | WebWorks_Indent_1 |
---|
...
OS_ERR_PTR_INVALID
...
class | WebWorks_Indent_2 |
---|
...
If OS_CFG_ARG_CHK_EN
is set to
...
DEF_ENABLED
in os_cfg.h
: if either p_free
or p_used
are NULL
pointers.
...
class | WebWorks_Indent_1 |
---|
...
OS_ERR_TASK_NOT_EXIST
...
class | WebWorks_Indent_2 |
---|
...
If the stack pointer of the task is a NULL
pointer.
...
...
class | WebWorks_Indent_1 |
---|
...
OS_ERR_TASK_OPT
...
class | WebWorks_Indent_2 |
---|
...
If OS_OPT_TASK_STK_CHK
...
was not specififed
...
when creating the task being checked.
...
...
OS_ERR_TASK_STK_CHK_ISR
...
class | WebWorks_Indent_2 |
---|
...
If OS_CFG_CALLED_FROM_ISR_CHK_EN
set to
...
DEF_ENABLED
in os_cfg.h
: if calling this function from an ISR.
...
Returned Value
anchorNone
Required Configuration
OS_CFG_TASK_STAT_CHK_EN
must be enabled in os_cfg.h
. Refer to µC-OS-III Configuration Manual.
Callers
Application.
Notes/Warnings
...
- Execution time of this task depends on the size of the task’s stack.
...
- The application can determine the total task stack space (in number of
CPU_STK
elements) by adding the value of*p_free
and*p_used
. This number should add up to the task’s stack size which is stored in the.StkSize
field of theOS_TCB
of the task.
...
- The
...
-
#define
CPU_CFG_STK_GROWTH
must be declared (typically fromos_cpu.h
). When this#define
is set toCPU_STK_GROWTH_LO_TO_HI
, the stack grows from low memory to high memory. When this#define
is set toCPU_STK_GROWTH_HI_TO_LO
, the stack grows from high memory to low memory.
...
...
Example Usage
...
Code Block |
---|
...
HTML Table | |||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
summary | |||||||||||||||||||||||||||||||||||||||||||||||||||||
class | Code_Listing | ||||||||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
Table Cell (td) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1005995 | 1005995 | OS_TCB MyTaskTCB;|||||||||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1005996 | 1005996 | |||||||||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1005997 | 1005997 | |||||||||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1005998 | 1005998 | void Task (void *p_arg)|||||||||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1005999 | 1005999 | {|||||||||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1006000 | 1006000 | OS_ERR err;|||||||||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1006001 | 1006001 | CPU_STK_SIZE n_free;|||||||||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1006002 | 1006002 | CPU_STK_SIZE n_used;|||||||||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1006003 | 1006003 | |||||||||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1006004 | 1006004 | |||||||||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1006005 | 1006005 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||
OS_TCB MyTaskTCB; void Task (void *p_arg) { OS_ERR err; CPU_STK_SIZE n_free; CPU_STK_SIZE n_used; (void)&p_arg; Anchor | | 1006006 | 1006006 | while||||||||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1006007 | 1006007 | :|||||||||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1006008 | 1006008 | :|||||||||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1006009 | 1006009 | OSTaskStkChk(&MyTaskTCB,|||||||||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1006010 | 1006010 | &n_free,|||||||||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1006011 | 1006011 | &n_used,|||||||||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1006012 | 1006012 | &err);|||||||||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1006013 | 1006013 | /* Check “err” */|||||||||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1006014 | 1006014 | :|||||||||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1006015 | 1006015 | :|||||||||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1006016 | 1006016 | }|||||||||||||||||||||||||||||||||||||||||||||||||||
Anchor | 1006017 | 1006017 | }|||||||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
Table Row (tr) |