...
The statistic task is optional in a µC/OS-III application and its presence is controlled by a compile-time configuration constant OS_CFG_STAT_TASK_EN
defined in os_cfg.h
. Specifically, the code is included in the build when OS_CFG_STAT_TASK_EN
is set to 1 DEF_ENABLED
.
Also, the priority of this task and the location and size of the statistic task’s stack is configurable via OS_CFG_STAT_TASK_PRIO
declared in os_cfg_app.h
().
If the application uses the statistic task, it should call OSStatTaskCPUUsageInit()
from the first, and only application task created in the main()
function as shown in Listing 5-5the listing below. The startup code should create only one task before calling OSStart()
. The single task created is, of course, allowed to create other tasks, but only after calling OSStatTaskCPUUsageInit()
.
Anchor | ||||
---|---|---|---|---|
|
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
void main (void) (1)
{
OS_ERR err;
:
OSInit(&err); (2)
if (err != OS_ERR_NONE) {
/* Something wasn't configured properly, µC/OS-III not properly initialized */
/* ... 'err' will tell you the cause (see os.h) */
}
/* (3) Create ONE task (we'll call it AppTaskStart() for sake of discussion) */
:
OSStart(&err); (4)
}
void AppTaskStart (void *p_arg)
{
OS_ERR err;
:
/* (5) Initialize the tick interrupt */
#if OS_CFG_STAT_TASK_EN == DEF_ENABLED
OSStatTaskCPUUsageInit(&err); (6)
OSStatReset(&err) (7)
#endif
:
/* (8) Create other tasks */
while (DEF_ON) {
/* AppTaskStart() body */
}
} |
Panel | ||
---|---|---|
| ||
(1) The C compiler should start up the CPU and bring it to (2) (3) As the comment indicates, you should create a single task called Normally, µC/OS-III allows the user to create as many tasks as are necessary prior to calling (4) You need to call (5) The start task should then configure and enable tick interrupts. This most likely requires that the user initialize the hardware timer used for the clock tick and have it interrupt at the rate specified by (6) For example, if when redoing the test, (7) You should call this function to reset the statistics counter so that you are not getting incorrect values from the startup code. (8) As previously described, µC/OS-III stores run-time statistics for each task in each task’s
|