uC-OS-III Stacks Pools and Other os_cfg_app.h

uC-OS-III Stacks Pools and Other os_cfg_app.h

µC/OS-III allows the user to configure the sizes of the idle task stack, statistic task stack, message pool, debug tables, and more. This is done through os_cfg_app.h.

Miscellaneous

OS_CFG_ISR_STK_SIZE

This parameter specifies the size of µC/OS-III’s interrupt stack (in CPU_STK elements). Note that the stack size needs to accommodate for worst case interrupt nesting, assuming the processor supports interrupt nesting. The ISR handler task stack is declared in os_cfg_app.c as follows:

CPU_STK OSCfg_ISRStk[OS_CFG_ISR_STK_SIZE];

OS_CFG_MSG_POOL_SIZE

This entry specifies the number of OS_MSGs available in the pool of OS_MSGs. The size is specified in number of OS_MSG elements and the message pool is declared in os_cfg_app.c as follows:

OS_MSG OSCfg_MsgPool[OS_CFG_MSG_POOL_SIZE];

OS_CFG_TASK_STK_LIMIT_PCT_EMPTY

This parameter sets the position (as a percentage of empty) of the stack limit for the idle, statistic, tick, interrupt queue handler, and timer tasks stacks. In other words, the amount of space to leave before the stack is full. For example if the stack contains 1000 CPU_STK entries and the user declares OS_CFG_TASK_STK_LIMIT_PCT_EMPTY to 10u, the stack limit will be set when the stack reaches 90% full, or 10% empty.

If the stack of the processor grows from high memory to low memory, the limit would be set towards the “base address” of the stack, i.e., closer to element 0 of the stack.

If the processor used does not offer automatic stack limit checking, you should set OS_CFG_TASK_STK_LIMIT_PCT_EMPTY to 0u.

Idle Task Configuration

OS_CFG_IDLE_TASK_STK_SIZE

This parameter sets the size of the idle task’s stack (in CPU_STK elements) as follows:

CPU_STK  OSCfg_IdleTaskStk[OS_CFG_IDLE_TASK_STK_SIZE]; 

Note that OS_CFG_IDLE_TASK_STK_SIZE must be at least greater than OS_CFG_STK_SIZE_MIN.

Statistic Task Configuration

OS_CFG_STAT_TASK_PRIO

This parameter allows the user to specify the priority assigned to µC/OS-III's statistic task. It is recommended to make this task a very low priority such as one priority level above the idle task, or, OS_CFG_PRIO_MAX-2.

OS_CFG_STAT_TASK_RATE_HZ

This option defines the execution rate (in Hz) of µC/OS-III’s statistic task. It is recommended to make this rate an even multiple of the tick rate (see OS_CFG_TICK_RATE_HZ).

OS_CFG_STAT_TASK_STK_SIZE

This parameter sets the size of the statistic task’s stack (in CPU_STK elements). The statistic task stack is declared in os_cfg_app.c as follows:

CPU_STK OSCfg_StatTaskStk[OS_CFG_STAT_TASK_STK_SIZE];

Note that OS_CFG_STAT_TASK_STK_SIZE must be at least greater than OS_CFG_STK_SIZE_MIN.

Tick Rate and Task Configuration

OS_CFG_TICK_RATE_HZ

This parameter defines the execution rate (in Hz) of µC/OS-III’s tick task. The tick rate should be set between 10 and 1000 Hz. The higher the rate, the more overhead it will impose on the processor. The desired rate depends on the granularity required for time delays and timeouts.

OS_CFG_TICK_TASK_PRIO

This option specifies the priority to assign to the µC/OS-III's tick task. It is recommended to make this task a fairly high priority, but not necessarily the highest. The priority assigned to this task must be greater than 0 and less than OS_CFG_PRIO_MAX-1.

OS_CFG_TICK_TASK_STK_SIZE

This parameter specifies the size of µC/OS-III’s tick task stack (in CPU_STK elements). The tick task stack is declared in os_cfg_app.c as follows:

CPU_STK OSCfg_TickTaskStk[OS_CFG_TICK_TASK_STK_SIZE];

Note that OS_CFG_TICK_TASK_STK_SIZE must be at least greater than OS_CFG_STK_SIZE_MIN.

Timer Task Configuration

OS_CFG_TMR_TASK_PRIO

This parameter allows the user to specify the priority to assign to µC/OS-III's timer task. It is recommended to make this task a medium-to-low priority, depending on how fast the timer task will execute (see OS_CFG_TMR_TASK_RATE_HZ) and how many timers are running in the application. The priority assigned to this task must be greater than 0 and less than OS_CFG_PRIO_MAX-1.

You should start with these simple rules:

In other words:

High Timer Rate — Higher Priority

High Number of Timers — Lower Priority

OS_CFG_TMR_TASK_RATE_HZ

This option defines the execution rate (in Hz) of µC/OS-III’s timer task. The timer task rate should typically be set to 10 Hz. However, timers can run at a faster rate at the price of higher processor overhead. Note that OS_CFG_TMR_TASK_RATE_HZ must be an integer multiple of OS_CFG_TICK_TASK_RATE_HZ.

OS_CFG_TMR_TASK_STK_SIZE

This parameter sets the size of the timer task’s stack (in CPU_STK elements). The timer task stack is declared in os_cfg_app.c as follows:

CPU_STK OSCfg_TmrTaskStk[OS_CFG_TMR_TASK_STK_SIZE];

Note that OS_CFG_TMR_TASK_STK_SIZE must be at least greater than OS_CFG_STK_SIZE_MIN.