Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Anchor10922941092294 µC/OS-III Features (os_cfg.h) Anchor10751991075199Compile-time configuration allows users to determine which features to enable and those features that are not needed. With compile-time configuration, the code and data sizes of µC/OS-III (i.e., its footprint) can be reduced by enabling only the desired functionality. Anchor

10752001075200 CompileCompile-time configuration is accomplished by setting a number of #define constants in a file called os_cfg.h that the application is expected to provide. You simply copy os_cfg.h into the application directory and change the copied file to satisfy the application’s requirements. This way, os_cfg.h is not recreated from scratch. Anchor

10752011075201The compile-time configuration #defines are listed below in alphabetic order and are not necessarily found in this order in os_cfg.h. Anchor10950281095028

OS_CFG_APP_HOOKS_EN

...

When set to 1, this #define specifies that application-defined hooks can be called from µC/OS-III’s hooks. This allows the application code to extend the functionality of µC/OS-III. Specifically: Anchor10940431094043  

...

The µC/OS-III hook …

...

Calls the Application-define hook through…

...

...

OSIdleTaskHook()

...

OS_AppIdleTaskHookPtr

OSInitHook()

...

...

None

...

OSStatTaskHook()

...

OS_AppStatTaskHookPtr

...

OSTaskCreateHook()

...

OS_AppTaskCreateHookPtr

...

...

OSTaskDelHook()

...

OS_AppTaskDelHookPtr

OSTaskReturnHook()

...

...

OS_AppTaskReturnHookPtr

...

OSTaskSwHook()

...

OS_AppTaskSwHookPtr

...

OSTimeTickHook()

...

...

OS_AppTimeTickHookPtr

...

1092434Application hook functions could be declared as shown in the code below. Anchor10940491094049  

...

rowspan32

...

rowspan18

...

Anchor10752661075266It’s also up to a user to set the value of the pointers so that they point to the appropriate functions as shown below. The pointers do not have to be set in main() but, you can set them after calling OSInit().

Note that not every hook function need to be defined, only the ones the user wants to place in the application code.

Anchor10752671075267Also, if you don't intend to extend µC/OS-III’s hook through these application hooks, you can set OS_CFG_APP_HOOKS_EN to 0 to save RAM (i.e., the pointers). Anchor10752691075269

OS_CFG_ARG_CHK

...

_EN

OS_CFG_ARG_CHK_EN determines whether the user wants most of µC/OS-III functions to perform argument checking. When set to 1, µC/OS-III ensures that pointers passed to functions are non-NULL, that arguments passed are within allowable range, that options are valid, and more. When set to 0, OS_CFG_ARG_CHK_EN those arguments are not checked and the amount of code space and processing time required by µC/OS-III is reduced. You would set OS_CFG_ARG_CHK_EN to 0 if you are certain that the arguments are correct.anchor

10752711075271µC/OS-III performs argument checking in over 40 functions. Therefore, you can save a few hundred bytes of code space by disabling this check. However, you should always enable argument checking until you are certain the code can be trusted. Anchor10752721075272

OS_CFG_CALLED_FROM_ISR_CHK_EN

...

1075273OS_CFG_CALLED_FROM_ISR_CHK_EN determines whether most of µC/OS-III functions are to confirm that the function is not called from an ISR. In other words, most of the functions from µC/OS-III should be called by task-level code except “post” type functions (which can also be called from ISRs). By setting this #define to 1 µC/OS-III is told to make sure that functions that are only supposed to be called by tasks are not called by ISRs. It’s highly recommended to set this #define to 1 until you are absolutely certain that the code is behaving correctly and that task-level functions are always called from tasks. You can set this #define to 0 to save code space and, of course, processing time. Anchor10752741075274

µC/OS-III performs this check in approximately 50 functions. Therefore, you can save a few hundred bytes of code space by disabling this check. Anchor10752751075275

OS_CFG_DBG_EN

Anchor10752761075276When set to 1, this #define adds ROM constants located in os_dbg.c to help support kernel aware debuggers. Specifically, a number of named ROM variables can be queried by a debugger to find out about compiled-in options. For example, a debugger can find out the size of an OS_TCB, µC/OS-III’s version number, the size of an event flag group (OS_FLAG_GRP), and much more. Anchor10752771075277

OS_CFG_FLAG_EN

Anchor10752781075278OS_CFG_FLAG_EN enables (when set to 1) or disables (when set to 0) code generation of event flag services and data structures. This reduces the amount of code and data space needed when an application does not require event flags. When OS_CFG_FLAG_EN is set to 0, it is not necessary to enable or disable any of the other OS_CFG_FLAG_xxx #define constants in this section. Anchor10752791075279

OS_CFG_FLAG_DEL_EN

Anchor10752801075280OS_CFG_FLAG_DEL_EN enables (when set to 1) or disables (when set to 0) code generation of the function OSFlagDel(). Anchor10752811075281

OS_CFG_FLAG_MODE_CLR

...

_EN

OS_CFG_FLAG_MODE_CLR_EN enables (when set to 1) or disables (when set to 0) code generation used to wait for event flags to be 0 instead of 1. Generally, you would wait for event flags to be set. However, the user may also want to wait for event flags to be clear and in this case, enable this option.anchor10752831075283

OS_CFG_FLAG_PEND_ABORT_EN

Anchor10752841075284OS_CFG_FLAG_PEND_ABORT_EN enables (when set to 1) or disables (when set to 0) code generation of the function OSFlagPendAbort(). Anchor10842021084202

OS_CFG_ISR_POST_DEFERRED_EN

...

10842041084204When set to 1, OS_CFG_ISR_POST_DEFERRED_EN reduces interrupt latency since interrupts are not disabled during most critical sections of code within µC/OS-III. Instead, the scheduler is locked during the processing of these critical sections. The advantage of setting OS_CFG_ISR_POST_DEFERRED_EN to 1 is that interrupt latency is lower, however, ISR to task response is slightly higher. It is recommended to set OS_CFG_ISR_POST_DEFERRED_EN to 1 when enabling the following services, since setting this #define to 0 would potentially make interrupt latency unacceptably high: Anchor10940551094055  

...

µC/OS-III Services

...

Enabled by …

...

Event Flags

...

...

OS_CFG_FLAG_EN

...

Multiple Pend

...

OS_CFG_PEND_MULTI_EN

...

OS???Post() with broadcast

...

...

OS???Del() with OS_OPT_DEL_

...

ALWAYS

OS???PendAbort()

...

The compromise to make is: Anchor10752951075295

	OS_CFG_ISR_POST_DEFERRED_EN set to 1

...

Short interrupt latency, longer ISR-to-task response.

...

	OS_CFG_ISR_POST_DEFERRED_EN set to 0

...

Long interrupt latency (see table above), shorter ISR-to-task response.

...

OS_CFG_MEM_EN

Anchor10753001075300OS_CFG_MEM_EN enables (when set to 1) or disables (when set to 0) code generation of the µC/OS-III partition memory manager and its associated data structures. This feature allows users to reduce the amount of code and data space needed when an application does not require the use of memory partitions. Anchor10753011075301

OS_CFG_MUTEX

...

_EN

OS_CFG_MUTEX_EN enables (when set to 1) or disables (when set to 0) the code generation of all mutual exclusion semaphore services and data structures. This feature allows users to reduce the amount of code and data space needed when an application does not require the use of mutexes. When OS_CFG_MUTEX_EN is set to 0, there is no need to enable or disable any of the other OS_CFG_MUTEX_XXX #define constants in this section.anchor10753031075303

OS_CFG_MUTEX_DEL_EN

Anchor10753041075304OS_CFG_MUTEX_DEL_EN enables (when set to 1) or disables (when set to 0) code generation of the function OSMutexDel(). Anchor10753051075305

OS_CFG_MUTEX_PEND_ABORT_EN

...

1075306OS_CFG_MUTEX_PEND_ABORT_EN enables (when set to 1) or disables (when set to 0) code generation of the function OSMutexPendAbort(). Anchor10753071075307

OS_CFG_OBJ_TYPE_CHK_EN

Anchor10753081075308OS_CFG_OBJ_TYPE_CHK_EN determines whether most of µC/OS-III functions should check to see if the function is manipulating the proper object. In other words, if attempting to post to a semaphore, is the user in fact passing a semaphore object or another object by mistake? It is recommended to set this #define to 1 until absolutely certain that the code is behaving correctly and the user code is always pointing to the proper objects. You would set this #define to 0 to save code space as well as data space. µC/OS-III object type checking is done nearly 30 times, and it is possible to save a few hundred bytes of code space and processing time by disabling this check. Anchor10753091075309

OS_CFG_PEND_MULTI_EN

Anchor10753101075310This constant determines whether the code to support pending on multiple events (i.e., semaphores or message queues) will be enabled (1) or not (0). Anchor10753111075311

OS_CFG_PRIO_MAX

Anchor10753121075312OS_CFG_PRIO_MAX specifies the maximum number of priorities available in the application. Specifying OS_CFG_PRIO_MAX to just the number of priorities the user intends to use, reduces the amount of RAM needed by µC/OS-III. Anchor10753131075313

In µC/OS-III, task priorities can range from 0 (highest priority) to a maximum of 255 (lowest possible priority) when the data type OS_PRIO is defined as a CPU_INT08U. However, in Anchor10753141075314

µC/OS-III, there is no practical limit to the number of available priorities. Specifically, if defining OS_PRIO as a CPU_INT16U, there can be up to 65536 priority levels. It is recommended to leave OS_PRIO defined as a CPU_INT08U and use only 256 different priority levels (i.e., 0..255), which is generally sufficient for every application. You should always set the value of OS_CFG_PRIO_MAX to even multiples of 8 (8, 16, 32, 64, 128, 256, etc.). The higher the number of different priorities, the more RAM µC/OS-III will consume. Anchor10753151075315

An application cannot create tasks with a priority number higher than or equal to OS_CFG_PRIO_MAX. In fact, µC/OS-III reserves priority OS_CFG_PRIO_MAX-2 and OS_CFG_PRIO_MAX-1 for itself; OS_CFG_PRIO_MAX-1 is reserved for the idle task OS_IdleTask(). Additionally, do not use priority 0 for an application since it is reserved by µC/OS-III’s ISR handler task. The priorities of the application tasks can therefore take a value between 2 and OS_CFG_PRIO_MAX–3 (inclusive).

Anchor10753181075318To summarize, there are two priority levels to avoid in an application: Anchor10940641094064  

...

Priority

Reserved by µC/OS-III for …

0

The ISR Handler Task (OS_IntQTask())

...

1

...

...

Reserved

...

OS_CFG_PRIO_

...

MAX-2

Reserved

OS_CFG_PRIO_MAX-1

...

The idle task (OS_IdleTask())

...

...

OS_CFG_Q_EN

Anchor10753231075323OS_CFG_Q_EN enables (when set to 1) or disables (when set to 0) code generation of message queue services and data structures. This reduces the amount of code space needed when an application does not require the use of message queues. When OS_CFG_Q_EN is set to 0, you do not need to enable or disable any of the other OS_CFG_Q_XXX #define constants in this section. Anchor10753241075324

OS_CFG_Q_DEL_EN

...

OS_CFG_Q_DEL_EN enables (when set to 1) or disables (when set to 0) code generation of the function OSQDel(). Anchor10753261075326

OS_CFG_Q_FLUSH_EN

Anchor10753271075327OS_CFG_Q_FLUSH_EN enables (when set to 1) or disables (when set to 0) code generation of the function OSQFlush(). Anchor10753281075328

OS_CFG_Q_PEND_ABORT_EN

...

1075329OS_CFG_Q_PEND_ABORT_EN enables (when set to 1) or disables (when set to 0) code generation of the function OSQPendAbort(). Anchor10753301075330).

OS_CFG_SCHED_LOCK_TIME_MEAS_EN

...

10753311075331This constant enables (when set to 1) or disables (when set to 0) code generation to measure the amount of time the scheduler is locked. This is useful when determining task latency. Anchor10753321075332

OS_CFG_SCHED_ROUND_ROBIN_EN

...

1075333This constant enables (when set to 1) or disables (when set to 0) code generation for the round-robin feature of µC/OS-III. Anchor10753341075334

OS_CFG_SEM_EN

Anchor10753351075335OS_CFG_SEM_EN enables (when set to 1) or disables (when set to 0) code generation of the semaphore manager and associated data structures. This reduces the amount of code and data space needed when an application does not require the use of semaphores. When OS_CFG_SEM_EN is set to 0, it is not necessary to enable or disable any of the other OS_CFG_SEM_XXX #define constants in this section. Anchor10753381075338

OS_CFG_SEM_DEL_EN

...

1075339OS_CFG_SEM_DEL_EN enables (when set to 1) or disables (when set to 0) code generation of the function OSSemDel(). Anchor10753401075340

OS_CFG_SEM_PEND_ABORT_EN

Anchor10753411075341OS_CFG_SEM_PEND_ABORT_EN enables (when set to 1) or disables (when set to 0) code generation of the function OSSemPendAbort(). Anchor10753421075342

OS_CFG_SEM_SET_EN

...

1075343OS_CFG_SEM_SET_EN enables (when set to 1) or disables (when set to 0) code generation of the function OSSemSet(). Anchor10753441075344.

OS_CFG_STAT_TASK_EN

...

1075345OS_CFG_STAT_TASK_EN specifies whether or not to enable µC/OS-III’s statistic task, as well as its initialization function. When set to 1, the statistic task OS_StatTask() and statistic task initialization function are enabled. OS_StatTask() computes the CPU usage of an application, stack usage of each task, the CPU usage of each task at run time and more.

Anchor10753461075346When enabled, OS_StatTask() executes at a rate of OS_CFG_STAT_TASK_RATE_HZ (see os_cfg_app.h), and computes the value of OSStatTaskCPUUsage, which is a variable that contains the percentage of CPU used by the application. OS_StatTask() calls OSStatTaskHook() every time it executes so that the user can add their own statistics as needed. See os_stat.c for details on the statistic task. The priority of OS_StatTask() is configurable by the application code (see os_cfg_app.h). Anchor10753471075347

OS_StatTask() also computes stack usage of each task created when the #define OS_CFG_STAT_TASK_STK_CHK_EN is set to 1. In this case, OS_StatTask() calls OSTaskStkChk() for each task and the result is placed in the task’s TCB. The .StkFree and .StkUsed field of the task’s TCB represents the amount of free space (in bytes) and amount of used space, respectively. Anchor10753491075349

When OS_CFG_STAT_TASK_EN is set to 0, all variables used by the statistic task are not declared (see os.h). This, of course, reduces the amount of RAM needed by µC/OS-III when not enabling the statistic task. When setting OS_CFG_STAT_TASK_EN to 1, statistics will be determined at a rate of OS_CFG_STAT_TASK_RATE_HZ (see os_cfg_app.h). Anchor10753501075350

OS_CFG_STAT_TASK_STK_CHK_EN

Anchor10753511075351This constant allows the statistic task to call OSTaskStkChk() for each task created. For this to happen, OS_CFG_STAT_TASK_EN needs to be set to 1 (i.e., the statistic task needs to be enabled). However, you can call OSStatStkChk() from one of the tasks to obtain this information about the task(s). Anchor10753521075352

OS_CFG_STK_SIZE_MIN

Anchor10753531075353This #define specifies the minimum stack size (in CPU_STK elements) for each task. This is used by µC/OS-III to verify that sufficient stack space is provided for when each task is created. Suppose the full context of a processor consists of 16 registers of 32 bits. Also, suppose CPU_STK is declared as being of type CPU_INT32U, at a bare minimum, set OS_CFG_STK_SIZE_MIN to 16. However, it would be quite unwise to not accommodate 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. Again, this is a safeguard to make sure task stacks have sufficient stack space. Anchor10753541075354

OS_CFG_TASK_CHANGE_PRIO_EN

Anchor10753551075355OS_CFG_TASK_CHANGE_PRIO_EN enables (when set to 1) or disables (when set to 0) code generation of the function OSTaskChangePrio(). Anchor10753561075356

OS_CFG_TASK_DEL_EN

...

OS_CFG_TASK_DEL_EN enables (when set to 1) or disables (when set to 0) code generation of the function OSTaskDel(). Anchor10753581075358

OS_CFG_TASK_Q_EN

Anchor10753591075359OS_CFG_TASK_Q_EN enables (when set to 1) or disables (when set to 0) code generation of the OSTaskQXXX() functions used to send and receive messages directly to/from tasks and ISRs. Sending messages directly to a task is more efficient than sending messages using a message queue because there is no pend list associated with messages sent to a task. Anchor10753601075360

OS_CFG_TASK_Q_PEND_ABORT_EN

...

OS_CFG_TASK_Q_PEND_ABORT_EN enables (when set to 1) or disables (when set to 0) code generation of code for the function OSTaskQPendAbort().anchor10753621075362

OS_CFG_TASK_PROFILE_EN

Anchor10753631075363This constant allows variables to be allocated in each task’s OS_TCB to hold performance data about each task. If OS_CFG_TASK_PROFILE_EN is set to 1, each task will have a variable to keep track of the number of times a task is switched to, the task execution time, the percent CPU usage 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.anchor10753641075364

OS_CFG_TASK_REG_TBL_SIZE

...

10753651075365This constant allows each task to have task context variables. Use task variables to store such elements as “errno”errno, task identifiers and other task-specific values. The number of variables that a task contains is set by this constant. 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 os_type.h). If OS_REG is a CPU_INT32U, all variables in this table are of this type. Anchor10753661075366

OS_CFG_TASK_SEM_PEND_ABORT_EN

Anchor10753671075367OS_CFG_TASK_SEM_PEND_ABORT_EN enables (when set to 1) or disables (when set to 0) code generation of code for the function OSTaskSemPendAbort(). Anchor10753681075368

OS_CFG_TASK_SUSPEND_

...

EN

OS_CFG_TASK_SUSPEND_EN enables (when set to 1) or disables (when set to 0) code generation of the functions OSTaskSuspend() and OSTaskResume(), which allows the application to explicitly suspend and resume tasks, respectively. Suspending and resuming a task is useful when debugging, especially if calling these functions via a terminal interface at run time. Anchor10753701075370

OS_CFG_TIME_DLY_HMSM_EN

Anchor10753711075371OS_CFG_TIME_DLY_HMSM_EN enables (when set to 1) or disables (when set to 0) the code generation of the function OSTimeDlyHMSM(), which is used to delay a task for a specified number of hours, minutes, seconds, and milliseconds. Anchor10753721075372

OS_CFG_TIME_DLY_RESUME_EN

...

1075373OS_CFG_TIME_DLY_RESUME_EN enables (when set to 1) or disables (when set to 0) the code generation of the function OSTimeDlyResume(). Anchor10946241094624

OS_CFG_TLS_TBL_SIZE

Anchor10946251094625OS_CFG_TLS_TBL_SIZE determines the size of the array: .TLS_Tbl[] in each task’s OS_TCB. OS_CFG_TLS_TBL_SIZE also serves the purpose of enabling (when > 0) or disabling the TLS (thread-local storage) feature (when == 0). The TLS feature was added in V3.03.00. Anchor10753741075374

OS_CFG_TMR_EN

Anchor10753751075375Enables (when set to 1) or disables (when set to 0) the code generation of timer management services. Anchor10753761075376

OS_CFG_TMR_DEL_EN

Anchor10753771075377OS_CFG_TMR_DEL_EN enables (when set to 1) or disables (when set to 0) the code generation of the function OSTmrDel(). Anchor10955491095549

TRACE_CFG_EN

...

Although not specifically part of µC/OS-III, µC/Trace, a Windows-based RTOS Event Analyzer (i.e. tool) is fully integrated in the latest version of µC/OS-III. µC/Trace functionality is enabled by setting TRACE_CFG_EN to 1 in os_cfg.h. You will need to have purchased the µC/Trace product in order to set TRACE_CFG_EN to 1 or else your compiler will complain about missing macros and functions. Consult the Micriµm website (http://www.Micrium.com) for details and availability of this highly useful tool.