Kernel Configuration#
The kernel can be configured to meet any needs your application may have. Most kernel features can be toggled on or off to preserve data space, code size, and execution time. Some of the kernel's features are used only while profiling and debugging and can be disabled for production builds.
There are two configurations types:
Compile-time configuration : Allows you to enable or disable specific features.
Run-time configuration : Allows you to specify the size of the kernel's object pools and internal task stacks.
Kernel Compile-Time and Data Type Configurations#
Compile-Time Configurations#
Compile-time configuration allows you to specify which features of the kernel to enable. By enabling only the necessary features, you can reduce the code and data size of the kernel (i.e., its footprint).
To configure the compile-time parameters, you must set the #define constants in the os_cfg.h file provided by the application. These #define constants are listed below in the same order as in the os_cfg.h file (default values are in bold).
Miscellaneous Options#
Table - Miscellaneous Configuration Constants#
Constant | Description | Possible values |
---|---|---|
OS_CFG_APP_HOOKS_EN | Enables application-defined hooks that can be called by the kernel port hooks. For more information, see Extending the Kernel with Application Hooks . | 1 (enabled) or 0 (disabled) |
OS_CFG_DBG_EN | When set to 1, this configuration adds ROM constants to help support kernel-aware debuggers. Specifically, a number of named ROM variables can be queried by a debugger to check compile-time options. For example, a debugger can check the size of an OS_TCB, the kernel's version number, the size of an event flag group, and much more. | 1 (enabled) or 0 (disabled) |
OS_CFG_TICK_EN | If your application does not require any form of timeouts or time keeping, either with timeouts on kernel objects or delayed execution times, set this option to 0. Doing so removes all time-keeping facilities from the kernel. | 1 (enabled) or 0 (disabled) |
OS_CFG_TS_EN | When set to 1, the timestamp facilities provided by the CPU module are used to measure the time between various events. For example, the kernel will measure the time spent by a task pending on an object, the time the scheduler is locked, etc. This option is used mostly for profiling and performance measurement. To save space and processing time, set this option to 0. Note: To use the timestamp facilities, the CPU module Board Support Package or Port should implement the functions described in the CPU Port Board Support Package . | 1 (enabled) or 0 (disabled) |
OS_CFG_PRIO_MAX | Specifies the number of task priorities available to the application. OS_CFG_PRIO_MAX should always be set to even multiples of 8 (8, 16, 32, 64, 128, 256, etc.). The higher the number of different priorities, the more RAM the kernel will consume. Task priorities can range from 0 (highest priority) to a maximum of 255 (lowest priority) when the data type OS_PRIO is defined as a CPU_INT08U. However, there is no practical limit to the number of available priorities. If OS_PRIO is defined as CPU_INT16U, there can be up to 65536 priority levels. We recommend leaving OS_PRIO defined as CPU_INT08U since 256 priority levels is sufficient for most applications. An application cannot create tasks with a priority number higher than OS_CFG_PRIO_MAX. To ensure proper operation of kernel and its services, use care when setting the priorities of other system tasks, such as the Statistics Task and the Timer Task in the run-time configuration. | Integer, 64 u |
OS_CFG_SCHED_LOCK_TIME_MEAS_EN | When set to 1, this allows the kernel to use the timestamp facilities (provided OS_CFG_TS_EN is also set to 1) to measure the peak amount of time that the scheduler is locked. Use this feature to profile the application during development and testing. A deployed application should have this set to 0. | 1 (enabled) or 0 (disabled) |
OS_CFG_SCHED_ROUND_ROBIN_EN | When set to 1, use the Round Robin Scheduler. This is only useful when there are multiple tasks sharing the same priority. If this is not the case, set this option to 0. | 1 (enabled) or 0 (disabled) |
OS_CFG_STK_SIZE_MIN | Specifies the minimum stack size (in CPU_STK elements) for each task, which the kernel uses to verify that sufficient stack space is provided when the task is created. For example, suppose the full context of a processor consists of 16 registers of 32 bits and that CPU_STK is declared as being of type CPU_INT32U. OS_CFG_STK_SIZE_MIN would then be set to 16. However, it would be wise to also account for storage of local variables, function call returns, and possibly nested ISRs. Refer to the “port” of the processor used to see how to set this minimum. | Integer, 64 u |
OS_CFG_TRACE_EN | When set to 1, this adds the Trace Instrumentation to the Kernel. Note that an external tracer, like SystemView , is needed to extract the tracing information generated by the Kernel. | 1 (enabled) or 0 (disabled) |
Event Flag Configuration#
Table - Event Flag Configuration Constants#
Constant | Description | Possible values |
---|---|---|
OS_CFG_FLAG_EN | When set to 1, this enables the event flag services and data structures. If event flags are not needed, set this to 0to reduce the amount of code and data space needed by the kernel. Note: When OS_CFG_FLAG_EN is set to 0, it is unnecessary to enable or disable the OS_CFG_FLAG_MODE_CLR_EN option. | 1 (enabled) or 0 (disabled) |
OS_CFG_FLAG_MODE_CLR_EN | If you require your application to wait until a flag is cleared, set this to 1. If not, set this to 0. Generally, you would wait for event flags to be set. | 1 (enabled) or 0 (disabled) |
Mutal Exclusion Semaphore Configuration#
Table - Mutual Exclusion Semaphore Configuration Constants#
Constant | Description | Possible values |
---|---|---|
OS_CFG_MUTEX_EN | When set to 1, this enables the mutual exclusion semaphore services and data structures. If mutual exclusion semaphores are not needed, set this to 0, which reduces the amount of code and data space needed by the kernel. | 1 (enabled) or 0 (disabled) |
Message Queue Configuration#
Table - Message Queue Configuration Constants#
Constant | Description | Possible values |
---|---|---|
OS_CFG_Q_EN | When set to 1, this enables the message queue services and data structures. If message queues are not needed, set this to 0 to reduce the amount of code and data space needed by the kernel. | 1 (enabled) or 0 (disabled) |
Semaphore Configuration#
Table - Semaphore Configuration Constants#
Constant | Description | Possible values |
---|---|---|
OS_CFG_SEM_EN | When set to 1, this enables the semaphore services and data structures. If semaphores are not needed, set this to 0. It reduces the amount of code and data space needed by the kernel. | 1 (enabled) or 0 (disabled) |
Monitor Configuration#
Table - Monitor Configuration Constants#
Constant | Description | Possible values |
---|---|---|
OS_CFG_MON_EN | When set to 1, this enables the monitor services and data structures. If monitors are not needed, set this to 0 to reduce the amount of code and data space needed by the kernel. | 1 (enabled) or 0 (disabled) |
Task Management Options#
Table - Task Management Constants#
Constant | Description | Possible values |
---|---|---|
OS_CFG_STAT_TASK_EN | When set to 1, this enables the kernel's Statistics Task. This task computes the CPU usage of an application, the stack usage of each task, the CPU usage of each task, and more at run-time. When enabled, the Statistics Task executes at a rate equal to the .RateHz member of the Statistics Task configuration structure used in the kernel's initialization function. The Statistics Task calls OSStatTaskHook() every time it executes so that you can add your own statistics calculations as needed. The priority of the Statistics Task is set by the .Prio member of the Statistics Task configuration structure used in the kernel's initialization function. For more information, see the Statistics Task configuration in the Run-Time Application Specifics page. When OS_CFG_STAT_TASK_EN is set to 0, all variables used by the statistic task are not declared. This reduces the amount of RAM and code space needed by the kernel. | 1 (enabled) or 0 (disabled) |
OS_CFG_STAT_TASK_STK_CHK_EN | When set to 1, the Statistics Task computes the stack usage of each task created. In this case, the Statistics Task calls OSTaskStkChk() for each task and places the result in the task’s TCB. The .StkFree and .StkUsed fields of the task’s TCB represent the amount of free space (in CPU_STK elements) and amount of used space (in CPU_STK elements), respectively. Note: This option, OS_CFG_STAT_TASK_EN must also be set to 1. | 1 (enabled) or 0 (disabled) |
OS_CFG_TASK_PROFILE_EN | To enable the performance profiling tools within the kernel, set this option to 1, which allows variables to be allocated in each task’s TCB to hold performance data about each task. Each task uses variables to keep track of the number of times a task is switched in, the task execution time, the CPU usage percentage of the task relative to the other tasks, and more. The information made available with this feature is highly useful when debugging, but requires extra RAM. To save data and code space, set this option to 0 after you are certain that your application is profiled and works correctly. | 1 (enabled) or 0 (disabled) |
OS_CFG_TASK_Q_EN | When set to 1, the kernel will offer task messages queues with the OSTaskQ???() functions, which send and receive messages directly to and from tasks and ISRs. Sending messages directly to a task is more efficient than sending messages using a traditional message queue because there is no pend list associated with messages sent to a task. If your application does not require task-level message queues, set this option to 0. | 1 (enabled) or 0 (disabled) |
OS_CFG_TASK_REG_TBL_SIZE | This constant allows each task to have task context variables, which allow you to store such elements as “errno”, task identifiers, and other task-specific values. The number of variables that a task contains is set by this option. Each variable is identified by a unique identifier from 0 to OS_CFG_TASK_REG_TBL_SIZE-1. Also, each variable is declared as having an OS_REG data type (see Data Type Configuration ). To disable the usage of task context variables, set this option to 0 u. | Integer, 3u |
OS_CFG_TASK_STK_REDZONE_EN | While debugging, you should determine if a task has overflowed its stack space by setting this option to 1. Every time a task is switched in, its stack is checked. If the monitored zone located at the end of a task's stack is corrupted, an application-defined hook is called and a software exception is generated. To disable this feature, set this option to 0. | 1 (enabled) or 0 (disabled) |
OS_CFG_TASK_STK_REDZONE_DEPTH | The default monitored zone is 8 CPU_STK elements long (located at the end of a task's stack). Use this option to change the size of the monitored zone. If OS_CFG_TASK_STK_REDZONE_EN is set to 0, this value is ignored. Note: The effectively usable stack space is the task's stack size minus the OS_CFG_TASK_STK_REDZONE_DEPTH value. | Integer, 8u |
Task Local Storage Configuration#
Table - Task Local Storage Configuration Constant#
Constant | Description | Possible values |
---|---|---|
OS_CFG_TLS_TBL_SIZE | If your application requires Task Local Storage, set this option to a positive integer value. This value determines the size of the Task Local Storage Table (.TLS_Tbl, member of OS_TCB) present in each task. To disable TLS, set this option to 0 u. Task local storage is disabled by default because none of Micrium OS's modules need it. However, if your application requires a standard C library, like newlib for example, you would need enable this feature. Most third-party libraries will indicate if they need TLS or not. | Integer, 0 u |
Timer Management Configuration#
Table - Timer Management Configuration Constants#
Constant | Description | Possible values |
---|---|---|
OS_CFG_TMR_EN | When set to 1, this enables the timer management services and data structures. If your application does not require programmable timers, set this option to 0 to reduce the kernel's required data and code space. | 1 (enabled) or 0 (disabled) |
Kernel Run-Time Application Specific Configurations#
This section describes the application-specific configurations of the kernel, that are set at run-time.
Kernel Initialization#
For information on the methods that can be used to initialize any Micrium product, see Stacks Initialization Methods . To initialize the kernel, OSInit() must be called.
Optional Configurations#
This section describes the configurations that are optional. If you do not set them in your application, the default configurations will apply.
The default values can be retrieved via the structure OS_InitCfgDflt. For examples of how to change the run-time configuration, see the Kernel Initialization page of the Kernel Programming Guide.
Note: These configurations must be set before you call the function OSInit(). |
---|
Memory Segment#
The kernel can allocate its internal task's stack and objects on a specific memory segment.
Type | Function to call | Default | Field from default configuration structure |
---|---|---|---|
MEM_SEG * | OS_ConfigureMemSeg() | The General-purpose heap . | .MemSeg |
Message Pool Size#
The kernel can manage a variable number of messages used by both the message queues and the per-task message queues.
Type | Function to call | Default | Field from default configuration structure |
---|---|---|---|
OS_MSG_SIZE | OS_ConfigureMsgPoolSize() | The kernel will manage 100 messages. | .MsgPoolSize |
Task Stack Limit#
Some processors offer the ability to monitor the task's stack usage. This option sets the percentage to Full, at which point the processor must alert the application.
Type | Function to call | Default | Field from default configuration structure |
---|---|---|---|
CPU_STK_SIZE | OS_ConfigureStkLimit() | 10% from Full is the limit. | .TaskStkLimit |
ISR Stack#
If the processor allows it, a separate stack may be used for the ISRs. This option specifies the stack used by the ISRs.
Type | Function to call | Default | Field from default configuration structure |
---|---|---|---|
OS_STACK_CFG | OS_ConfigureISRStk() | The ISRs will use a 256 element stack allocated in the kernel memory segment. | .ISR |
Statistics Task#
This option changes the Statistics Task's stack, priority, and rate of execution.
Type | Function to call | Default | Field from default configuration structure |
---|---|---|---|
OS_TASK_CFG | OS_ConfigureStatTask() | The Statistics Task will use a 256 element stack allocated in the kernel memory segment. It will run at rate of 10Hz with a priority of 3. | .StatTaskCfg |
Timer Task#
This option alters the Timer Management Task's stack, priority, and rate of execution.
Type | Function to call | Default | Field from default configuration structure |
---|---|---|---|
OS_TASK_CFG | OS_ConfigureTmrTask() | The Timer Management Task will use a 256 element stack allocated in the kernel memory segment. It will run at rate of 10Hz with a priority of 2 . | .TmrTaskCfg |
Kernel Task Configuration Structure#
The kernel defines structures to configure its internal tasks. The usage depends on the task being configured, which is described in detail below.
Task Configuration for Statistic task#
Table - OS_TASK_CFG for the Statistics Task#
Field | Description | Possible Values |
---|---|---|
.StkBasePtr | Pointer to the base of the buffer used as a stack. | Any valid pointer, or DEF_NULL to allocate the stack in the kernel's memory segment. |
.StkSize | Size of the buffer, in CPU_STK elements. | Any positive integer. |
.Prio | The execution priority of the Task. When choosing its priority, keep the rate of execution of this task in mind to assure proper operation of the kernel. | 1 to OS_CFG_PRIO_MAX-2. |
.RateHz | The rate of execution of the Task (measured in Hertz). | 1 to 10. |
Task Configuration for Timer#
Table - OS_TASK_CFG for the Timer Management Task#
Field | Description | Possible Values |
---|---|---|
.StkBasePtr | Pointer to the base of the buffer used as a stack. | Any valid pointer, or DEF_NULL to allocate the stack in the kernel's memory segment. |
.StkSize | Size of the buffer, in CPU_STK elements. | Any positive integer. |
.Prio | The execution priority of the Timer Management Task. When choosing its priority, keep the rate of execution of this task in mind to assure proper operation of the kernel. | 1 to OS_CFG_PRIO_MAX-2. |
.RateHz | The rate of execution of the Timer Management Task (in hertz). The software timers will be updated at RateHz times per second. This also specifies the minimum delay a timer can use. | 10 to 1000. |
Kernel Task Stack Configuration Structure#
The kernel has an internal stack used for ISR handlers. To configure the stack, the following structure is used:
Table - OS_STACK_CFG for ISR handlers#
Field | Description | Possible Values |
---|---|---|
.StkBasePtr | Pointer to the base of the buffer used as a stack for ISR. | Any valid pointer, or DEF_NULL to allocate the stack in the kernel's memory segment. |
.StkSize | Size of the buffer, in CPU_STK elements. | Any positive integer. |