1 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
5 The <b>CMSIS-RTOS API Version 2 (CMSIS-RTOS2)</b> is a generic RTOS interface for Arm® Cortex®-M processor-based
6 devices. It provides a standardized API for software components that require RTOS functionality and gives therefore serious
7 benefits to the users and the software industry:
8 - CMSIS-RTOS2 provides basic features that are required in many applications.
9 - The unified feature set of the CMSIS-RTOS2 reduces learning efforts and simplifies sharing of software components.
10 - Middleware components that use the CMSIS-RTOS2 are RTOS agnostic and are easier to adapt.
11 - Standard project templates of the CMSIS-RTOS2 may be shipped with freely available CMSIS-RTOS2 implementations.
13 \note The CMSIS-RTOS API Version 2 defines a minimum feature set. Implementations with extended features may be provided by
16 The CMSIS-RTOS2 manages the resources of the microcontroller system and implements the concept of parallel threads that run
19 Applications frequently require several concurrent activities. CMSIS-RTOS2 can manage multiple concurrent activities at the
20 time when they are needed. Each activity gets a separate thread which executes a specific task and this simplifies the
21 overall program structure. The CMSIS-RTOS2 system is scalable and additional threads can be added easily at a later time.
22 Threads have a priority allowing faster execution of time-critical parts of a user application.
24 The CMSIS-RTOS2 offers services needed in many real-time applications, for example, periodical activation of timer functions,
25 memory management, and message exchange between threads with time limits.
27 The CMSIS-RTOS2 addresses the following new requirements:
28 - Dynamic object creation no longer requires static memory, static memory buffers are now optional.
29 - Support for Armv8-M architecture that provides a secure and non-secure state of code execution.
30 - Provisions for message passing in multi-core systems.
31 - Full support of C++ run-time environments.
32 - C interface which is binary compatible across
33 <a href="http://infocenter.arm.com/help/topic/com.arm.doc.subset.swdev.abi/index.html">ABI compatible compilers</a>.
35 As a consequence of these requirements the CMSIS-RTOS2 has the following fundamental modifications:
36 - The functions osXxxxNew replace osXxxxCreate functions; osXxxxNew and osXxxxDelete create and destroy objects.
37 - The C function \c main is no longer started as a thread (this was an optional feature in CMSIS-RTOS v1).
38 - Functions that return osEvent have been replaced.
40 CMSIS-RTOS2 provides an translation layer for the <a class="el" href="../../RTOS/html/index.html">CMSIS-RTOS API v1</a>. It
41 is possible to intermix CMSIS-RTOS API Version 2 and CMSIS-RTOS API Version 1 within the same application. Over time, you may
42 migrate to the new API as explained in \ref os2Migration.
44 CMSIS-RTOS2 is not POSIX compliant, but has provisions to enable a C++11/C++14 interface.
46 The following sections provide further details about CMSIS-RTOS2 and the RTX reference implementation.
47 - \subpage rtos_revisionHistory documents changes made in each version for CMSIS-RTOS API v2 and RTX v5.
48 - \subpage genRTOS2IF provides an overview about the CMSIS-RTOS API v2.
49 - \subpage functionOverview lists the CMSIS-RTOS2 API functions and the header file cmsis_os2.h.
50 - \subpage rtosValidation describes the validation suite that is publicly available.
51 - \subpage os2Migration shows how to use CMSIS-RTOS2 in existing projects and lists function differences to CMSIS-RTOS v1.
52 - \subpage rtx5_impl provides general information about the operation and usage of RTX v5.
56 CMSIS-RTOS2 in ARM::CMSIS Pack
57 -----------------------------
59 The following files relevant to CMSIS-RTOS2 are present in the <b>ARM::CMSIS</b> Pack directories:
61 -----------------------------|------------------------------------------------------------------------
62 \b CMSIS/Documentation/RTOS2 | This documentation
63 \b CMSIS/RTOS2/Include | \ref cmsis_os2_h
64 \b CMSIS/RTOS2/RTX | CMSIS-RTOS v2 reference implementation based on RTX version 5
65 \b CMSIS/RTOS2/Template | Compatibility layer to CMSIS-RTOS v1
69 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
71 \page rtos_revisionHistory Revision History
73 \section GenRTOS2Rev CMSIS-RTOS API Version 2
75 <table class="cmtable" summary="Revision History">
83 Additional functions allowed to be called from Interrupt Service Routines:
84 - \ref osKernelGetInfo, \ref osKernelGetState
90 Additional functions allowed to be called from Interrupt Service Routines:
91 - \ref osKernelGetTickCount, \ref osKernelGetTickFreq
93 Changed Kernel Tick type to uint32_t:
94 - updated: \ref osKernelGetTickCount, \ref osDelayUntil
100 Support for critical and uncritical sections (nesting safe):
101 - updated: \ref osKernelLock, \ref osKernelUnlock
102 - added: \ref osKernelRestoreLock
104 Updated \ref CMSIS_RTOS_ThreadFlagsMgmt "Thread Flags" and \ref CMSIS_RTOS_EventFlags "Event Flags":
105 - changed flags parameter and return type from int32_t to uint32_t
111 New API Version 2.0 available.
112 - See \ref rtos_api2 for a detailed function reference.
113 - See \ref os2Migration for details on the migration process from API Version 1.
117 <td>V1.02 - only documentation changes</td>
119 Added: Overview of the \ref rtosValidation "CMSIS-RTOS Validation" Software Pack.\n
120 Clarified: Behavior of \ref CMSIS_RTOS_TimeOutValue.
125 <td>Added: New control functions for short timeouts in microsecond resolution \b osKernelSysTick,
126 \b osKernelSysTickFrequency, \b osKernelSysTickMicroSec.\n
127 Removed: osSignalGet.
132 <td>Added capabilities for C++, kernel initialization and object deletion.\n
133 Prepared for C++ class interface. In this context to \em const attribute has been moved from osXxxxDef_t typedefs to
134 the osXxxxDef macros.\n
135 Added: \ref osTimerDelete, \ref osMutexDelete, \ref osSemaphoreDelete.\n
136 Added: \ref osKernelInitialize that prepares the kernel for object creation.\n
142 <td>First official Release.\n
143 Added: \ref osKernelStart; starting 'main' as a thread is now an optional feature.\n
144 Semaphores have now the standard behavior.\n
145 \b osTimerCreate does no longer start the timer. Added: \ref osTimerStart (replaces osTimerRestart).\n
146 Changed: osThreadPass is renamed to \ref osThreadYield.
151 <td>Preview Release.</td>
156 \section RTX5RevisionHistory CMSIS-RTOS RTX Version 5
158 <table class="cmtable" summary="Revision History">
166 - Added Object Memory usage counters.
167 - Added support for additional external configuration file.
173 - Based on CMSIS-RTOS API V2.1.2.
174 - Added TrustZone Module Identifier configuration for Idle and Timer Thread.
175 - Moved SVC/PendSV handler priority setup from osKernelInitialize to osKernelStart (User Priority Grouping can be updated after osKernelInitialize but before osKernelStart).
176 - Corrected SysTick and PendSV handlers for ARMv8-M Baseline.
177 - Corrected memory allocation for stack and data when "Object specific Memory allocation" configuration is used.
178 - Added support for ARMv8-M IAR compiler.
184 - Corrected IRQ and SVC exception handlers for Cortex-A.
190 - Corrected SysTick and SVC Interrupt Priority for Cortex-M.
196 - Based on CMSIS-RTOS API V2.1.1.
197 - Added support for for Cortex-A.
198 - Using OS Tick API for RTX Kernel Timer Tick.
199 - Fixed potential corruption of terminated threads list.
200 - Corrected MessageQueue to use actual message length (before padding).
201 - Corrected parameters for ThreadEnumerate and MessageQueueInserted events.
202 - Timer Thread creation moved to osKernelStart.
208 - Based on CMSIS-RTOS API V2.1.0.
209 - Added support for Event recording.
210 - Added support for IAR compiler.
211 - Updated configuration files: RTX_Config.h for the configuration settings and RTX_config.c for implementing the \ref rtx5_specific.
212 - osRtx name-space for RTX specific symbols.
218 Initial release compliant to CMSIS-RTOS2.\n
225 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
227 \page genRTOS2IF Generic RTOS Interface
229 CMSIS-RTOS2 is a generic API that is agnostic of the underlying RTOS kernel. Application programmers call CMSIS-RTOS2 API
230 functions in the user code to ensure maximum portability from one RTOS to another. Middleware using CMSIS-RTOS2 API takes
231 advantages of this approach by avoiding unnecessary porting efforts.
233 \image html "API_Structure.png" "CMSIS-RTOS API Structure"
235 A typical CMSIS-RTOS2 API implementation interfaces to an existing real-time kernel. The CMSIS-RTOS2 API provides the
236 following attributes and functionalities:
237 - Function names, identifiers, and parameters are descriptive and easy to understand. The functions are powerful and
238 flexible which reduces the number of functions exposed to the user.
239 - \ref CMSIS_RTOS_ThreadMgmt allows you to define, create, and control threads.
240 - Interrupt Service Routines (ISR) can \ref CMSIS_RTOS_ISR_Calls "call some CMSIS-RTOS functions". When a CMSIS-RTOS
241 function cannot be called from an ISR context, it rejects the invocation and returns an error code.
242 - Three different event types support communication between multiple threads and/or ISR:
243 - \ref CMSIS_RTOS_ThreadFlagsMgmt "Thread Flags": may be used to indicate specific conditions to a thread.
244 - \ref CMSIS_RTOS_EventFlags "Event Flags": may be used to indicate events to a thread or ISR.
245 - \ref CMSIS_RTOS_Message "Messages": can be sent to a thread or an ISR. Messages are buffered in a queue.
246 - \ref CMSIS_RTOS_MutexMgmt and \ref CMSIS_RTOS_SemaphoreMgmt are incorporated.
247 - CPU time can be scheduled with the following functionalities:
248 - A \a timeout parameter is incorporated in many CMSIS-RTOS functions to avoid system lockup. When a timeout is specified,
249 the system waits until a resource is available or an event occurs. While waiting, other threads are scheduled.
250 - The \ref osDelay and \ref osDelayUntil functions put a thread into the \b WAITING state for a specified period of time.
251 - The \ref osThreadYield provides co-operative thread switching and passes execution to another thread of the same
253 - \ref CMSIS_RTOS_TimerMgmt functions are used to trigger the execution of functions.
255 The CMSIS-RTOS2 API is designed to optionally incorporate multi-processor systems and/or access protection via the Cortex-M
256 Memory Protection Unit (MPU).
258 In some RTOS implementations threads may execute on different processors, thus \b message queues may reside in shared memory
261 The CMSIS-RTOS2 API encourages the software industry to evolve existing RTOS implementations. RTOS implementations can be
262 different and optimized in various aspects towards the Cortex-M processors. Optional features may be for example
263 - Support of the Cortex-M Memory Protection Unit (MPU).
264 - Support of multi-processor systems.
265 - Support of a DMA controller.
266 - Deterministic context switching.
267 - Round-robin context switching.
268 - Deadlock avoidance, for example with priority inversion.
269 - Zero interrupt latency by using Armv7-M instructions LDREX and STREX.
271 \section usingOS2 Using a CMSIS-RTOS2 Implementation
273 A CMSIS-RTOS2 implementation is typically provided as a library. To add the RTOS functionality to an existing CMSIS-based
274 application, the RTOS library (and typically one or more configuration files) needs to be added. There is a single new header
275 file %cmsis_os2.h available. This is the only header file required for a completely portable application. In such a case,
276 user provided memory for control blocks, objects data and thread stack cannot be used. Alternatively, you can include an
277 implementation specific header file (for example rtx_os.h) which provides definitions also for resource allocation (such as
278 size of control blocks, required memory for object data and thread stack). This is optional and implies that the application
279 code is not completely portable.
281 \image html "CMSIS_RTOS_Files.png" "CMSIS-RTOS File Structure"
283 Once the files are added to a project, the user can start working with the CMSIS-RTOS functions. A code example is provided
288 /*----------------------------------------------------------------------------
289 * CMSIS-RTOS 'main' function template
290 *---------------------------------------------------------------------------*/
292 #include "RTE_Components.h"
293 #include CMSIS_device_header
294 #include "cmsis_os2.h"
296 /*----------------------------------------------------------------------------
297 * Application main thread
298 *---------------------------------------------------------------------------*/
299 void app_main (void *argument) {
307 // System Initialization
308 SystemCoreClockUpdate();
309 #ifdef RTE_Compiler_EventRecorder
310 // Initialize and start Event Recorder
311 EventRecorderInitialize(EventRecordError, 1U);
315 osKernelInitialize(); // Initialize CMSIS-RTOS
316 osThreadNew(app_main, NULL, NULL); // Create application main thread
317 osKernelStart(); // Start thread execution
323 \section cmsis_os2_h cmsis_os2.h header file
325 The file \b cmsis_os2.h is a standard header file that interfaces to every CMSIS-RTOS2 compliant real-time operating
326 systems (RTOS). Each implementation is provided the same \b cmsis_os2.h which defines the interface to the \ref rtos_api2.
328 Using the \b cmsis_os2.h along with dynamic object allocation allows to create source code or libraries that require no
329 modifications when using on a different CMSIS-RTOS2 implementation.
331 <b>Header file %cmsis_os2.h</b>
337 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
339 \page rtx5_impl RTX v5 Implementation
341 Keil RTX version 5 (RTX5) implements the CMSIS-RTOS2 as a native RTOS interface for Arm Cortex-M processor-based devices.
342 A translation layer to CMSIS-RTOS API v1 is provided. Therefore, RTX5 can be used in applications that where previously based
343 on RTX version 4 and CMSIS-RTOS version 1 with minimal effort.
345 The following sections provide further details:
346 - \subpage cre_rtx_proj explains how to setup an RTX v5 project in Keil MDK.
347 - \subpage theory_of_operation provides general information about the operation of CMSIS-RTOS RTX v5.
348 - \subpage config_rtx5 describes configuration parameters of CMSIS-RTOS RTX v5.
349 - \subpage creating_RTX5_LIB explains how to build your own CMSIS-RTOS RTX v5 library.
350 - \subpage dirstructfiles5 explains the directories and files that are supplied as part of CMSIS-RTOS RTX v5.
351 - \subpage technicalData5 lists microcontroller hardware requirements and limitations such as number of concurrent threads.
352 - \subpage misraCompliance5 describes the violations to the MISRA standard.
355 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
357 \page cre_rtx_proj Create an RTX5 Project
359 The steps to create a microcontroller application using RTX5 are:
360 - Create a new project and select a microcontroller device.
361 - In the Manage Run-Time Environment window, select <b>CMSIS\::CORE</b> and <b>CMSIS\::RTOS2 (API)\::Keil RTX5</b>. You can
362 choose to either add RTX as a library (Variant: \b Library) or to add the full source code (Variant: \b Source - required
363 if using the <a href="http://www.keil.com/pack/doc/compiler/EventRecorder/html/index.html" target="_blank"><b>Event Recorder</b></a>):
365 \image html manage_rte_output.png
367 - If the <b>Validation Output</b> requires other components to be present, try to use the \b Resolve button.
368 - Click \b OK. In the \b Project window, you will see the files that have been automatically added to you project, such as
369 \b %RTX_Config.h, \b %RTX_Config.c, the library or the source code files, as well as the system and startup files:
371 \image html project_window.png
373 - If using the Variant: \b Source as statet above, you have to assure to use at least C99 compiler mode (Project Options -> C/C++ -> C99 Mode).
374 - You can add template files to the project by right-clicking on <b>Source Group 1</b> and selecting
375 <b>Add New Item to 'Source Group 1'</b>. In the new window, click on <b>User Code Template</b>. On the right-hand side
376 you will see all available template files for CMSIS-RTOS RTX:
378 \image html add_item.png
380 - \ref config_rtx5 "Configure" RTX5 to the application's needs using the \b %RTX_Config.h file.
382 \section cre_rtx_cortexa Additional requirements for RTX on Cortex-A
384 Cortex-A based microcontrollers are less unified with respect to the interrupt and timer implementations used compared to
385 M-class devices. Thus RTX requires additional components when an A-class device is used, namely
386 <a href="../../Core_A/html/group__irq__ctrl__gr.html"><b>IRQ Controller (API)</b></a> and \ref CMSIS_RTOS_TickAPI "OS Tick (API)"
389 \image html manage_rte_cortex-a.png
391 The default implementations provided along with CMSIS are
392 - Arm <a href="../../Core_A/html/group__GIC__functions.html">Generic Interrupt Controller (GIC)</a>
393 - Arm Cortex-A5, Cortex-A9 <a href="../../Core_A/html/group__PTM__timer__functions.html">Private Timer (PTIM)</a>
394 - Arm Cortex-A7 <a href="../../Core_A/html/group__PL1__timer__functions.html">Generic Physical Timer (GTIM)</a>
396 For devices not implementing GIC, PTIM nor GTIM please refer to the according device family pack and select the
397 proper implementations.
399 \section cre_rtx_proj_specifics Add support for RTX specific functions
400 If you require some of the \ref rtx5_specific "RTX specific functions" in your application code, \#include the
401 \ref rtx_os_h "header file rtx_os.h". This enables \ref lowPower "low-power" and \ref TickLess "tick-less" operation modes.
403 \section cre_rtx_proj_er Add Event Recorder Visibility
404 - To use the Event Recorder together with RTX5, select the software component <b>Compiler:Event Recorder</b>.
405 - Select the \b Source variant of the software component <b>CMSIS:RTOS2 (API):Keil RTX5</b>.
406 \image html event_recorder_rte.png "Component selection for Event Recorder"
407 - Call the function <b>EventRecorderInitialize()</b> in your application code (ideally in \c main()).
408 - Build the application code and download it to the debug hardware.
410 Once the target application generates event information, it can be viewed in the µVision debugger using the \b Event
415 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
417 \page theory_of_operation Theory of Operation
419 Many aspects of the kernel are configurable and the configuration options are mentioned where applicable.
421 \section SystemStartup System Startup
423 Since main is no longer a thread RTX5 does not interfere with the system startup until main is reached.
424 Once the execution reaches \c main() there is a recommended order to initialize the hardware and start the kernel. This is
425 also reflected in the user code template file "CMSIS-RTOS2 'main' function" supplied with the RTX5 component.
427 Your application's \c main() should implement at least the following in the given order:
428 -# Initialization and configuration of hardware including peripherals, memory, pins, clocks and the interrupt system.
429 -# Update the system core clock using the respective
430 <a href=../../Core/html/group__system__init__gr.html>CMSIS-Core (Cortex-M)</a> or
431 <a href=../../Core_A/html/group__system__init__gr.html>CMSIS-Core (Cortex-A)</a> function.
432 -# Initialize the CMSIS-RTOS kernel using \ref osKernelInitialize.
433 -# Optionally, create a new thread \c app_main, which is used as a main thread using \ref osThreadNew. Alternatively, threads
434 can be created in \c main() directly.
435 -# Start the RTOS scheduler using \ref osKernelStart. This function does not return in case of successful execution. Any
436 application code after \b osKernelStart will not be executed unless \b osKernelStart fails.
438 \note Interrupts (like SVC for example) used by the kernel are initialized in \ref osKernelInitialize. In case priorities and
439 groupings in the NVIC are altered by the application after the above sequence it might be necessary to call
440 \ref osKernelInitialize again. You might observe weird misbehaviour possibly catched by \ref osRtxErrorNotify or causing a hard fault.
442 \note The tick timer is configured during \ref osKernelStart. The tick interval is calculated based on the \c SystemCoreClock variable.
446 RTX5 implements a low-latency preemtive scheduler. Major parts of RTX5 are executed in handler mode such as
447 - \ref SysTick_Handler used for time-based scheduling.
448 - \ref SVC_Handler used for lock-based scheduling.
449 - \ref PendSV_Handler used for interrupt-based scheduling.
451 In order to be low-latency with respect to ISR execution those system exceptions are configured to use the
452 lowest priority groups available. The priorities are configured such that no preemption happens between them. Thus
453 no interrupt critical sections (i.e. interrupt locks) are needed to protect the scheduler.
455 \image html scheduling.png "Thread scheduling and interrupt execution"
457 The scheduler combines priority and round-robin based context switches. The example depicted in the image above contains
458 four threads (1, 2, 3, and 4). Threads 1 and 2 share the same priority, thread 3 has a higher one and thread 4 the highest
459 (\ref osThreadAttr_t::priority). As long as threads 3 and 4 are blocked the scheduler switches between thread 1 and 2 on
460 a time-slice basis (round-robin). The time-slice for round-robin scheduling can be configured, see Round-Robin Timeout in \ref systemConfig.
462 Thread 2 unblocks thread 3 by an arbitrary RTOS-call (executed in SVC handler mode) at time index 2. The scheduler switches to
463 thread 3 immidiately because thread 3 has the highest priority. Thread 4 is still blocked.
465 At time index 4 an interrupt (ISR) occurs and preempts the SysTick_Handler. RTX does not add any latency to the interrupt
466 service execution. The ISR routine uses an RTOS-call that unblocks thread 4. Instead of switching to thread 4 immediately
467 the PendSV flag is set to defer the context switching. The PendSV_Handler is executed right after the SysTick_Handler returns
468 and the defered context switch to thread 4 is carried out. As soon as highest priority thread 4 blocks again by using
469 a blocking RTOS-call execution is switched back to thread 3 immidiately during time index 5.
471 At time index 5 thread 3 uses a blocking RTOS-call as well. Thus the scheduler switches back to thread 2 for time index 6.
472 At time index 7 the scheduler uses the round-robin mechanism to switch to thread 1 and so on.
474 \section MemoryAllocation Memory Allocation
476 RTX5 objects (thread, mutex, semaphore, timer, message queue, thread and event flags, as well as memory pool) require
477 dedicated RAM memory. Objects can be created using os<i>Object</i>New() calls and deleted using os<i>Object</i>Delete()
478 calls. The related object memory needs to be available during the lifetime of the object.
480 RTX5 offers three different memory allocation methods for objects:
481 - \ref GlobalMemoryPool uses a single global memory pool for all objects. It is easy to configure, but may have
482 the disadvantage for memory fragmentation when objects with different sizes are created and destroyed.
483 - \ref ObjectMemoryPool uses a fixed-size memory pool for each object type. The method is time deterministic
484 and avoids memory fragmentation.
485 - \ref StaticObjectMemory reserves memory during compile time and completely avoids that a system can be out of memory.
486 This is typically a required for some safety critical systems.
488 It possible to intermix all the memory allocation methods in the same application.
490 \subsection GlobalMemoryPool Global Memory Pool
492 The global memory pool allocates all objects from a memory area. This method of memory allocation is the default
493 configuration setting of RTX5.
495 \image html MemAllocGlob.png "Global Memory Pool for all objects"
497 When the memory pool does not provide sufficient memory, the creation of the object fails and the related
498 os<i>Object</i>New() function returns \token{NULL}.
500 Enabled in \ref systemConfig.
502 \subsection ObjectMemoryPool Object-specific Memory Pools
504 Object-specific memory pools avoids memory fragmentation with a dedicated fixed-size memory management for each object type.
505 This type of memory pools are fully time deterministic, which means that object creation and destruction takes always the
506 same fixed amount of time. As a fixed-size memory pool is specific to an object type, the handling of out-of-memory
507 situations is simplified.
509 \image html MemAllocSpec.png "One memory pool per object type"
511 Object-specific memory pools are selectively enabled for each object type, e.g: mutex or thread using the RTX configuration
513 - Enabled in \ref threadConfig for thread objects.
514 - Enabled in \ref timerConfig for timer objects.
515 - Enabled in \ref eventFlagsConfig for event objects.
516 - Enabled in \ref mutexConfig for mutex objects.
517 - Enabled in \ref semaphoreConfig for semaphore.
518 - Enabled in \ref memPoolConfig for memory pools.
519 - Enabled in \ref msgQueueConfig for message objects.
521 When the memory pool does not provide sufficient memory, the creation of the object fails and the related
522 os<i>Object</i>New() function returns \token{NULL}.
524 \subsection StaticObjectMemory Static Object Memory
525 In contrast to the dynamic memory allocations, the static memory allocation requires compile-time allocation of object memory.
527 \image html MemAllocStat.png "Statically allocated memory for all objects"
529 Static memory allocation can be achieved by providing user-defined memory using attributes at object creation,
530 see \ref CMSIS_RTOS_MemoryMgmt_Manual. Please take special note of the following restrictions:
532 Memory type | Requirements
533 ---------------------------------------------|-------------------------------------------------------------------------------
534 Control Block (osXxxAttr_t::cb_mem) | 4-Byte alignment. Size defined by \ref osRtxThreadCbSize, \ref osRtxTimerCbSize, \ref osRtxEventFlagsCbSize, \ref osRtxMutexCbSize, \ref osRtxSemaphoreCbSize, \ref osRtxMemoryPoolCbSize, \ref osRtxMessageQueueCbSize.
535 Thread Stack (osThreadAttr_t::stack_mem) | 8-Byte alignment. Size is application specific, i.e. amount of stack variables and frames.
536 Memory Pool (osMemoryPoolAttr_t::mp_mem) | 4-Byte alignment. Size calculated with \ref osRtxMemoryPoolMemSize.
537 Message Queue (osMessageQueueAttr_t::mq_mem) | 4-Byte alignment. Size calculated with \ref osRtxMessageQueueMemSize.
540 In order to allow RTX5 aware debugging, i.e. Component Viewer, to recognize control blocks these
541 needs to be placed in individual memory sections, i.e. using `__attribute__((section(...)))`.
543 RTX Object | Linker Section
544 --------------|------------------------
545 Thread | `.bss.os.thread.cb`
546 Timer | `.bss.os.timer.cb`
547 Event Flags | `.bss.os.evflags.cb`
548 Mutex | `.bss.os.mutex.cb`
549 Semaphore | `.bss.os.semaphore.cb`
550 Memory Pool | `.bss.os.mempool.cb`
551 Message Queue | `.bss.os.msgqueue.cb`
553 The following code example shows how to create an OS object using static memory.
555 <b> Code Example:</b>
557 /*----------------------------------------------------------------------------
558 * CMSIS-RTOS 'main' function template
559 *---------------------------------------------------------------------------*/
561 #include "RTE_Components.h"
562 #include CMSIS_device_header
563 #include "cmsis_os2.h"
565 //include rtx_os.h for types of RTX objects
568 //The thread function instanced in this example
569 void worker(void *arg)
578 // Define objects that are statically allocated for worker thread 1
579 __attribute__((section(".bss.os.thread.cb")))
580 osRtxThread_t worker_thread_tcb_1;
582 // Reserve two areas for the stacks of worker thread 1
583 // uint64_t makes sure the memory alignment is 8
584 uint64_t worker_thread_stk_1[64];
586 // Define the attributes which are used for thread creation
587 // Optional const saves RAM memory and includes the values in periodic ROM tests
588 const osThreadAttr_t worker_attr_1 = {
591 &worker_thread_tcb_1,
592 sizeof(worker_thread_tcb_1),
593 &worker_thread_stk_1[0],
594 sizeof(worker_thread_stk_1),
595 osPriorityAboveNormal,
599 // Define ID object for thread
602 /*----------------------------------------------------------------------------
603 * Application main thread
604 *---------------------------------------------------------------------------*/
605 void app_main (void *argument) {
606 uint32_t param = NULL;
608 // Create an instance of the worker thread with static resources (TCB and stack)
609 th1 = osThreadNew(worker, ¶m, &worker_attr_1);
615 // System Initialization
616 SystemCoreClockUpdate();
619 osKernelInitialize(); // Initialize CMSIS-RTOS
620 osThreadNew(app_main, NULL, NULL); // Create application main thread
621 osKernelStart(); // Start thread execution
627 \section ThreadStack Thread Stack Management
629 For Cortex-M processors without floating point unit the thread context requires 64 bytes on the local stack.
631 \note For Cortex-M4/M7 with FP the thread context requires 200 bytes on the local stack. For these devices the default stack
632 space should be increased to a minimum of 300 bytes.
634 Each thread is provided with a separate stack that holds the thread context and stack space for automatic variables and
635 return addresses for function call nesting. The stack sizes of RTX threads are flexibly configurable as explained in the
636 section \ref threadConfig. RTX offers a configurable checking for stack overflows and stack utilization.
639 \section lowPower Low-Power Operation
641 The system thread \b osRtxIdleThread can be use to switch the system into a low-power mode. The easiest form to enter a
642 low-power mode is the execution of the \c __WFE function that puts the processor into a sleep mode where it waits for an
647 #include "RTE_Components.h"
648 #include CMSIS_device_header /* Device definitions */
650 void osRtxIdleThread (void) {
651 /* The idle demon is a system thread, running when no other thread is */
655 __WFE(); /* Enter sleep mode */
661 \c __WFE() is not available in every Cortex-M implementation. Check device manuals for availability.
664 \section kernelTimer RTX Kernel Timer Tick
666 RTX uses the generic \ref CMSIS_RTOS_TickAPI to configure and control its periodic Kernel Tick.
668 To use an alternative timer as the Kernel Tick Timer one simply needs to implement a custom version
669 of the \ref CMSIS_RTOS_TickAPI.
671 \note The OS Tick implementation provided must asure that the used timer interrupt uses the same (low) priority group
672 as the service interrupts, i.e. interrupts used by RTX must not preempt each other. Refer to the \ref Scheduler section
675 \subsection TickLess Tick-less Low-Power Operation
677 RTX5 provides extension for tick-less operation which is useful for applications that use extensively low-power modes where
678 the SysTick timer is also disabled. To provide a time-tick in such power-saving modes, a wake-up timer is used to
679 derive timer intervals. The CMSIS-RTOS2 functions \ref osKernelSuspend and \ref osKernelResume control the tick-less
682 Using this functions allows the RTX5 thread scheduler to stop the periodic kernel tick interrupt. When all active threads
683 are suspended, the system enters power-down and calculates how long it can stay in this power-down mode. In the power-down
684 mode the processor and peripherals can be switched off. Only a wake-up timer must remain powered, because this timer is
685 responsible to wake-up the system after the power-down period expires.
687 The tick-less operation is controlled from the \b osRtxIdleThread thread. The wake-up timeout value is set before the system
688 enters the power-down mode. The function \ref osKernelSuspend calculates the wake-up timeout measured in RTX Timer Ticks;
689 this value is used to setup the wake-up timer that runs during the power-down mode of the system.
691 Once the system resumes operation (either by a wake-up time out or other interrupts) the RTX5 thread scheduler is started
692 with the function \ref osKernelResume. The parameter \a sleep_time specifies the time (in RTX Timer Ticks) that the system
693 was in power-down mode.
697 #include "msp.h" // Device header
699 /*----------------------------------------------------------------------------
700 * MSP432 Low-Power Extension Functions
701 *---------------------------------------------------------------------------*/
702 static void MSP432_LP_Entry(void) {
703 /* Enable PCM rude mode, which allows to device to enter LPM3 without waiting for peripherals */
704 PCM->CTL1 = PCM_CTL1_KEY_VAL | PCM_CTL1_FORCE_LPM_ENTRY;
705 /* Enable all SRAM bank retentions prior to going to LPM3 */
706 SYSCTL->SRAM_BANKRET |= SYSCTL_SRAM_BANKRET_BNK7_RET;
707 __enable_interrupt();
708 NVIC_EnableIRQ(RTC_C_IRQn);
709 /* Do not wake up on exit from ISR */
710 SCB->SCR |= SCB_SCR_SLEEPONEXIT_Msk;
711 /* Setting the sleep deep bit */
712 SCB->SCR |= (SCB_SCR_SLEEPDEEP_Msk);
715 static volatile unsigned int tc;
716 static volatile unsigned int tc_wakeup;
718 void RTC_C_IRQHandler(void)
720 if (tc++ > tc_wakeup)
722 SCB->SCR &= ~SCB_SCR_SLEEPONEXIT_Msk;
723 NVIC_DisableIRQ(RTC_C_IRQn);
724 NVIC_ClearPendingIRQ(RTC_C_IRQn);
727 if (RTC_C->PS0CTL & RTC_C_PS0CTL_RT0PSIFG)
729 RTC_C->CTL0 = RTC_C_KEY_VAL; // Unlock RTC key protected registers
730 RTC_C->PS0CTL &= ~RTC_C_PS0CTL_RT0PSIFG;
732 SCB->SCR |= (SCB_SCR_SLEEPDEEP_Msk);
736 uint32_t g_enable_sleep = 0;
738 void osRtxIdleThread (void) {
741 tc_wakeup = osKernelSuspend();
742 /* Is there some time to sleep? */
745 /* Enter the low power state */
749 /* Adjust the kernel ticks with the amount of ticks slept */
756 \c __WFE() is not available in every Arm Cortex-M implementation. Check device manuals for availability.
757 The alternative using \c __WFI() has other issues, please take note of http://www.keil.com/support/docs/3591.htm as well.
759 \section rtx_os_h RTX5 Header File
761 Every implementation of the CMSIS-RTOS2 API can bring its own additional features. RTX5 adds a couple of
762 \ref rtx5_specific "functions" for the idle more, for error notifications, and special system timer functions. It also is
763 using macros for control block and memory sizes.
765 If you require some of the RTX specific functions in your application code, \#include the header file \b %rtx_os.h:
770 \section CMSIS_RTOS_TimeOutValue Timeout Value
772 Timeout values are an argument to several \b osXxx functions to allow time for resolving a request. A timeout value of \b 0
773 means that the RTOS does not wait and the function returns instantly, even when no resource is available. A timeout value of
774 \ref osWaitForever means that the RTOS waits infinitely until a resource becomes available. Or one forces the thread to resume
775 using \ref osThreadResume which is discouraged.
777 The timeout value specifies the number of timer ticks until the time delay elapses. The value is an upper bound and
778 depends on the actual time elapsed since the last timer tick.
781 - timeout value \b 0 : the system does not wait, even when no resource is available the RTOS function returns instantly.
782 - timeout value \b 1 : the system waits until the next timer tick occurs; depending on the previous timer tick, it may be a
783 very short wait time.
784 - timeout value \b 2 : actual wait time is between 1 and 2 timer ticks.
785 - timeout value \ref osWaitForever : system waits infinite until a resource becomes available.
787 \image html TimerValues.png "Example of timeout using osDelay()"
790 \section CMSIS_RTOS_ISR_Calls Calls from Interrupt Service Routines
792 The following CMSIS-RTOS2 functions can be called from threads and Interrupt Service Routines (ISR):
793 - \ref osKernelGetInfo, \ref osKernelGetState,
794 \ref osKernelGetTickCount, \ref osKernelGetTickFreq, \ref osKernelGetSysTimerCount, \ref osKernelGetSysTimerFreq
795 - \ref osThreadFlagsSet
796 - \ref osEventFlagsSet, \ref osEventFlagsClear, \ref osEventFlagsGet, \ref osEventFlagsWait
797 - \ref osSemaphoreAcquire, \ref osSemaphoreRelease, \ref osSemaphoreGetCount
798 - \ref osMemoryPoolAlloc, \ref osMemoryPoolFree, \ref osMemoryPoolGetCapacity, \ref osMemoryPoolGetBlockSize,
799 \ref osMemoryPoolGetCount, \ref osMemoryPoolGetSpace
800 - \ref osMessageQueuePut, \ref osMessageQueueGet, \ref osMessageQueueGetCapacity, \ref osMessageQueueGetMsgSize,
801 \ref osMessageQueueGetCount, \ref osMessageQueueGetSpace
803 Functions that cannot be called from an ISR are verifying the interrupt status and return the status code \b osErrorISR, in
804 case they are called from an ISR context. In some implementations, this condition might be caught using the HARD_FAULT
808 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
810 \page config_rtx5 Configure RTX v5
812 The file "RTX_Config.h" defines the configuration parameters of CMSIS-RTOS RTX and must be part of every project that is
813 using the CMSIS-RTOS RTX kernel. The configuration options are explained in detail in the following sections:
814 - \ref systemConfig covers system-wide settings for the global memory pool, tick frequency, ISR event buffer and round-robin thread switching.
815 - \ref threadConfig provides several parameters to configure the \ref CMSIS_RTOS_ThreadMgmt functions.
816 - \ref timerConfig provides several parameters to configure the \ref CMSIS_RTOS_TimerMgmt functions.
817 - \ref eventFlagsConfig provides several parameters to configure the \ref CMSIS_RTOS_EventFlags functions.
818 - \ref mutexConfig provides several parameters to configure the \ref CMSIS_RTOS_MutexMgmt functions.
819 - \ref semaphoreConfig provides several parameters to configure the \ref CMSIS_RTOS_SemaphoreMgmt functions.
820 - \ref memPoolConfig provides several parameters to configure the \ref CMSIS_RTOS_PoolMgmt functions.
821 - \ref msgQueueConfig provides several parameters to configure the \ref CMSIS_RTOS_Message functions.
823 The file "RTX_Config.c" contains default implementations of the functions \ref osRtxIdleThread and \ref osRtxErrorNotify. Both functions
824 can simply be overwritten with a custimized behavior by redefining them as part of the user code.
826 The configuration file uses <b>Configuration Wizard Annotations</b>. Refer to <b>Pack - Configuration Wizard Annotations</b> for details.
827 Depending on the development tool, the annotations might lead to a more user-friendly graphical representation of the
828 settings. The screenshot below is a screenshot from the µVision \b Configuration \b Wizard view:
830 \image html config_wizard.png "RTX_Config.h in Configuration Wizard View"
832 Alternatively one can provide configuration options using the compiler command line.
834 For example one can customize the used tick frequency to 100us by (overwriting) the configuration using
836 cc -DOS_TICK_FREQ=100
839 \section systemConfig System Configuration
841 The system configuration covers system-wide settings for the global memory pool, tick frequency, ISR event buffer and
842 round-robin thread switching.
844 <b>System Configuration Options</b>
845 \image html config_wizard_system.png "RTX_Config.h: System Configuration"
847 Name | \#define | Description
848 ---------------------------------------|--------------------------|----------------------------------------------------------------
849 Global Dynamic Memory size [bytes] | \c OS_DYNAMIC_MEM_SIZE | Defines the combined global dynamic memory size for the \ref GlobalMemoryPool. Default value is \token{4096}. Value range is \token{[0-1073741824]} bytes, in multiples of \token{8} bytes.
850 Kernel Tick Frequency (Hz) | \c OS_TICK_FREQ | Defines base time unit for delays and timeouts in Hz. Default: 1000Hz = 1ms period.
851 Round-Robin Thread switching | \c OS_ROBIN_ENABLE | Enables Round-Robin Thread switching.
852 Round-Robin Timeout | \c OS_ROBIN_TIMEOUT | Defines how long a thread will execute before a thread switch. Default value is \token{5}. Value range is \token{[1-1000]}.
853 ISR FIFO Queue | \c OS_ISR_FIFO_QUEUE | RTOS Functions called from ISR store requests to this buffer. Default value is \token{16 entries}. Value range is \token{[4-256]} entries in multiples of \token{4}.
854 Memory Management | \c OS_EVR_MEMORY | Enables Memory Management events recording.
855 Kernel | \c OS_EVR_KERNEL | Enables Kernel events recording.
856 Thread | \c OS_EVR_THREAD | Enables Thread events recording.
857 Timer | \c OS_EVR_TIMER | Enables Timer events recording.
858 Event Flags | \c OS_EVR_EVFLAGS | Enables Event Flags events recording.
859 Mutex | \c OS_EVR_MUTEX | Enables Mutex events recording.
860 Semaphore | \c OS_EVR_SEMAPHORE | Enables Semaphore events recording.
861 Memory Pool | \c OS_EVR_MEMPOOL | Enables Memory Pool events recording.
862 Message Queue | \c OS_EVR_MSGQUEUE | Enables Message Queue events recording.
863 Object Memory usage counters | \c OS_OBJ_MEM_USAGE | Enables object memory usage counters to evaluate the maximum memory pool requirements individually for each RTOS object type.
865 \subsection systemConfig_glob_mem Global dynamic memory
866 Refer to \ref GlobalMemoryPool.
869 \subsection systemConfig_rr Round-Robin Thread Switching
871 RTX5 may be configured to use round-robin multitasking thread switching. Round-robin allows quasi-parallel execution of
872 several threads of the \a same priority. Threads are not really executed concurrently, but are scheduled where the available
873 CPU time is divided into time slices and RTX5 assigns a time slice to each thread. Because the time slice is typically short
874 (only a few milliseconds), it appears as though threads execute simultaneously.
876 Round-robin thread switching functions as follows:
877 - the tick is preloaded with the timeout value when a thread switch occurs
878 - the tick is decremented (if not already zero) each system tick if the same thread is still executing
879 - when the tick reaches 0 it indicates that a timeout has occurred. If there is another thread ready with the \a same
880 priority, then the system switches to that thread and the tick is preloaded with timeout again.
882 In other words, threads execute for the duration of their time slice (unless a thread's time slice is given up). Then, RTX
883 switches to the next thread that is in \b READY state and has the same priority. If no other thread with the same priority is
884 ready to run, the current running thread resumes it execution.
886 \note When switching to higher priority threads, the round-robin timeout value is reset.
888 Round-Robin multitasking is controlled with the <b>\#define OS_ROBIN_ENABLE</b>. The time slice period is configured (in RTX
889 timer ticks) with the <b>\#define OS_ROBIN_TIMEOUT</b>.
892 \subsection systemConfig_isr_fifo ISR FIFO Queue
893 The RTX functions (\ref CMSIS_RTOS_ISR_Calls), when called from and interrupt handler, store the request type and optional
894 parameter to the ISR FIFO queue buffer to be processed later, after the interrupt handler exits.
896 The scheduler is activated immediately after the IRQ handler has finished its execution to process the requests stored to the
897 FIFO queue buffer. The required size of this buffer depends on the number of functions that are called within the interrupt
898 handler. An insufficient queue size will be caught by \b osRtxErrorNotify with error code \b osRtxErrorISRQueueOverflow.
901 \subsection systemConfig_event_recording Event Recording
903 RTX5 fully supports <a href="http://www.keil.com/pack/doc/compiler/EventRecorder/html/index.html" target="_blank">Event Recorder</a>
904 annotations. In this section, you can enable or disable the recording of events for the different elements of RTX5. This
905 leads to reduced data traffic on the debug connection.
908 \subsection systemConfig_usage_counters Object Memory Usage Counters
910 Object memory usage counters help to evaluate the maximum memory pool requirements for each object type, just like stack
911 watermarking does for threads. The initial setup starts with a global memory pool for all object types. Consecutive runs of
912 the application with object memory usage counters enabled, help to introduce object specific memory pools for each object
913 type. Normally, this is required for applications that require a functional safety certification as global memory pools are
914 not allowed in this case.
917 \section threadConfig Thread Configuration
919 The RTX5 provides several parameters to configure the \ref CMSIS_RTOS_ThreadMgmt functions.
921 <b>Thread Configuration Options</b>
922 \image html config_wizard_threads.png "RTX_Config.h: Thread Configuration"
925 Option | \#define | Description
926 :--------------------------------------------------------------------------|:-------------------------------|:---------------------------------------------------------------
927 Object specific Memory allocation | \c OS_THREAD_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
928 Number of user Threads | \c OS_THREAD_NUM | Defines maximum number of user threads that can be active at the same time. Applies to user threads with system provided memory for control blocks. Default value is \token{1}. Value range is \token{[1-1000]}.
929 Number of user Threads with default Stack size | \c OS_THREAD_DEF_STACK_NUM | Defines maximum number of user threads with default stack size and applies to user threads with \token{0} stack size specified. Value range is \token{[0-1000]}.
930 Total Stack size [bytes] for user Threads with user-provided Stack size | \c OS_THREAD_USER_STACK_SIZE | Defines the combined stack size for user threads with user-provided stack size. Default value is \token{0}. Value range is \token{[0-1073741824]} Bytes, in multiples of \token{8}.
931 Default Thread Stack size [bytes] | \c OS_STACK_SIZE | Defines stack size for threads with zero stack size specified. Default value is \token{200}. Value range is \token{[96-1073741824]} Bytes, in multiples of \token{8}.
932 Idle Thread Stack size [bytes] | \c OS_IDLE_THREAD_STACK_SIZE | Defines stack size for Idle thread. Default value is \token{200}. Value range is \token{[72-1073741824]} bytes, in multiples of \token{8}.
933 Idle Thread TrustZone Module ID | \c OS_IDLE_THREAD_TZ_MOD_ID | Defines the \ref osThreadAttr_t::tz_module "TrustZone Module ID" the Idle Thread shall use. This needs to be set to a non-zero value if the Idle Thread need to call secure functions. Default value is \token{0}.
934 Stack overrun checking | \c OS_STACK_CHECK | Enable stack overrun checks at thread switch.
935 Stack usage watermark | \c OS_STACK_WATERMARK | Initialize thread stack with watermark pattern for analyzing stack usage. Enabling this option increases significantly the execution time of thread creation.
936 Processor mode for Thread execution | \c OS_PRIVILEGE_MODE | Controls the processor mode. Default value is \token{Privileged} mode. Value range is \token{[0=Unprivileged; 1=Privileged]} mode.
938 \subsection threadConfig_countstack Configuration of Thread Count and Stack Space
940 The RTX5 kernel uses a separate stack space for each thread and provides two methods for defining the stack requirements:
941 - <b>Static allocation</b>: when \ref osThreadAttr_t::stack_mem and \ref osThreadAttr_t::stack_size specify a memory area
942 which is used for the thread stack. \b Attention: The stack memory provided must be 64-bit aligned, i.e. by using uint64_t for declaration.
943 - <b>Dynamic allocation</b>: when \ref osThreadAttr_t is NULL or \ref osThreadAttr_t::stack_mem is NULL, the system
944 allocates the stack memory from:
945 - Object-specific Memory Pool (default Stack size) when "Object specific Memory allocation" is enabled and "Number of
946 user Threads with default Stack size" is not \token{0} and \ref osThreadAttr_t::stack_size is \token{0} (or
947 \ref osThreadAttr_t is NULL).
948 - Object-specific Memory Pool (user-provided Stack size) when "Object specific Memory allocation" is enabled and "Total
949 Stack size for user..." is not \token{0} and \ref osThreadAttr_t::stack_size is not \token{0}.
950 - Global Memory Pool when "Object specific Memory allocation" is disabled or (\ref osThreadAttr_t::stack_size is not
951 \token{0} and "Total Stack size for user..." is \token{0}) or (\ref osThreadAttr_t::stack_size is \token{0} and
952 "Number of user Threads with default Stack size" is \token{0}).
954 \ref osThreadAttr_t is a parameter of the function \ref osThreadNew.
957 Before the RTX kernel is started by the \ref osKernelStart() function, the main stack defined in startup_<i>device</i>.s is
958 used. The main stack is also used for:
959 - user application calls to RTX functions in \b thread \b mode using SVC calls
960 - interrupt/exception handlers.
962 \subsection threadConfig_ovfcheck Stack Overflow Checking
963 RTX5 implements a software stack overflow checking that traps stack overruns. Stack is used for return addresses and
964 automatic variables. Extensive usage or incorrect stack configuration may cause a stack overflow. Software stack overflow
965 checking is controlled with the define \c OS_STACK_CHECK.
967 If a stack overflow is detected, the function \b osRtxErrorNotify with error code \b osRtxErrorStackUnderflow is called. By
968 default, this function is implemented as an endless loop and will practically stop code execution.
970 \subsection threadConfig_watermark Stack Usage Watermark
971 RTX5 initializes thread stack with a watermark pattern (0xCC) when a thread is created. This allows the debugger to determine
972 the maximum stack usage for each thread. It is typically used during development but removed from the final application.
973 Stack usage watermark is controlled with the define \c OS_STACK_WATERMARK.
975 Enabling this option significantly increases the execution time of \ref osThreadNew (depends on thread stack size).
977 \subsection threadConfig_procmode Processor Mode for Thread Execution
978 RTX5 allows to execute threads in unprivileged or privileged processor mode. The processor mode is controlled with the
979 define \c OS_PRIVILEGE_MODE.
981 In \b unprivileged processor mode, the application software:
982 - has limited access to the MSR and MRS instructions, and cannot use the CPS instruction.
983 - cannot access the system timer, NVIC, or system control block.
984 - might have restricted access to memory or peripherals.
986 In \b privileged processor mode, the application software can use all the instructions and has access to all resources.
989 \section timerConfig Timer Configuration
991 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_TimerMgmt functions.
993 <b>Timer Configuration Options</b>
994 \image html config_wizard_timer.png "RTX_Config.h: Timer Configuration"
996 Name | \#define | Description
997 ---------------------------------------|--------------------------------|----------------------------------------------------------------
998 Object specific Memory allocation | \c OS_TIMER_OBJ_MEM | Enables object specific memory allocation.
999 Number of Timer objects | \c OS_TIMER_NUM | Defines maximum number of objects that can be active at the same time. Applies to objects with system provided memory for control blocks. Value range is \token{[1-1000]}.
1000 Timer Thread Priority | \c OS_TIMER_THREAD_PRIO | Defines priority for timer thread. Default value is \token{40}. Value range is \token{[8-48]}, in multiples of \token{8}. The numbers have the following priority correlation: \token{8=Low}; \token{16=Below Normal}; \token{24=Normal}; \token{32=Above Normal}; \token{40=High}; \token{48=Realtime}
1001 Timer Thread Stack size [bytes] | \c OS_TIMER_THREAD_STACK_SIZE | Defines stack size for Timer thread. May be set to 0 when timers are not used. Default value is \token{200}. Value range is \token{[0-1073741824]}, in multiples of \token{8}.
1002 Timer Thread TrustZone Module ID | \c OS_TIMER_THREAD_TZ_MOD_ID | Defines the \ref osThreadAttr_t::tz_module "TrustZone Module ID" the Timer Thread shall use. This needs to be set to a non-zero value if any Timer Callbacks need to call secure functions. Default value is \token{0}.
1003 Timer Callback Queue entries | \c OS_TIMER_CB_QUEUE | Number of concurrent active timer callback functions. May be set to 0 when timers are not used. Default value is \token{4}. Value range is \token{[0-256]}.
1005 \subsection timerConfig_obj Object-specific memory allocation
1006 See \ref ObjectMemoryPool.
1008 \subsection timerConfig_user User Timer Thread
1009 The RTX5 function \b osRtxTimerThread executes callback functions when a time period expires. The priority of the timer
1010 subsystem within the complete RTOS system is inherited from the priority of the \b osRtxTimerThread. This is configured by
1011 \c OS_TIMER_THREAD_PRIO. Stack for callback functions is supplied by \b osRtxTimerThread. \c OS_TIMER_THREAD_STACK_SIZE must
1012 satisfy the stack requirements of the callback function with the highest stack usage.
1015 \section eventFlagsConfig Event Flags Configuration
1017 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_EventFlags functions.
1019 <b>Event Configuration Options</b>
1020 \image html config_wizard_eventFlags.png "RTX_Config.h: Event Flags Configuration"
1022 Name | \#define | Description
1023 ---------------------------------------|--------------------------|----------------------------------------------------------------
1024 Object specific Memory allocation | \c OS_EVFLAGS_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1025 Number of Event Flags objects | \c OS_EVFLAGS_NUM | Defines maximum number of objects that can be active at the same time. Applies to objects with system provided memory for control blocks. Value range is \token{[1-1000]}.
1027 \subsection eventFlagsConfig_obj Object-specific memory allocation
1028 When object-specific memory is used, the pool size for all Event objects is specified by \c OS_EVFLAGS_NUM. Refer to
1029 \ref ObjectMemoryPool.
1032 \section mutexConfig Mutex Configuration
1033 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_MutexMgmt functions.
1035 <b>Mutex Configuration Options</b>
1036 \image html config_wizard_mutex.png "RTX_Config.h: Mutex Configuration"
1039 Name | \#define | Description
1040 ---------------------------------------|--------------------------|----------------------------------------------------------------
1041 Object specific Memory allocation | \c OS_MUTEX_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1042 Number of Mutex objects | \c OS_MUTEX_NUM | Defines maximum number of objects that can be active at the same time. Applies to objects with system provided memory for control blocks. Value range is \token{[1-1000]}.
1044 \subsection mutexConfig_obj Object-specific Memory Allocation
1045 When object-specific memory is used, the pool size for all Mutex objects is specified by \c OS_MUTEX_NUM. Refer to
1046 \ref ObjectMemoryPool.
1049 \section semaphoreConfig Semaphore Configuration
1051 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_SemaphoreMgmt functions.
1053 <b>Semaphore Configuration Options</b>
1054 \image html config_wizard_semaphore.png "RTX_Config.h: Semaphore Configuration"
1057 Name | \#define | Description
1058 ---------------------------------------|--------------------------|----------------------------------------------------------------
1059 Object specific Memory allocation | \c OS_SEMAPHORE_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1060 Number of Semaphore objects | \c OS_SEMAPHORE_NUM | Defines maximum number of objects that can be active at the same time. Applies to objects with system provided memory for control blocks. Value range is \token{[1-1000]}.
1062 \subsection semaphoreConfig_obj Object-specific memory allocation
1063 When Object-specific Memory is used, the pool size for all Semaphore objects is specified by \c OS_SEMAPHORE_NUM. Refer to
1064 \ref ObjectMemoryPool.
1067 \section memPoolConfig Memory Pool Configuration
1069 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_PoolMgmt functions.
1071 <b>Memory Pool Configuration Options</b>
1072 \image html config_wizard_memPool.png "RTX_Config.h: Memory Pool Configuration"
1074 Name | \#define | Description
1075 ---------------------------------------|--------------------------|----------------------------------------------------------------
1076 Object specific Memory allocation | \c OS_MEMPOOL_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1077 Number of Memory Pool objects | \c OS_MEMPOOL_NUM | Defines maximum number of objects that can be active at the same time. Applies to objects with system provided memory for control blocks. Value range is \token{[1-1000]}.
1078 Data Storage Memory size [bytes] | \c OS_MEMPOOL_DATA_SIZE | Defines the combined data storage memory size. Applies to objects with system provided memory for data storage. Default value is \token{0}. Value range is \token{[0-1073741824]}, in multiples of \token{8}.
1080 \subsection memPoolConfig_obj Object-specific memory allocation
1081 When object-specific memory is used, the number of pools for all MemoryPool objects is specified by \c OS_MEMPOOL_NUM. The
1082 total storage size reserved for all pools is configured in \c OS_MEMPOOL_DATA_SIZE. Refer to \ref ObjectMemoryPool.
1085 \section msgQueueConfig Message Queue Configuration
1087 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_Message functions.
1089 <b>MessageQueue Configuration Options</b>
1090 \image html config_wizard_msgQueue.png "RTX_Config.h: Message Queue Configuration"
1092 Name | \#define | Description
1093 ---------------------------------------|--------------------------|----------------------------------------------------------------
1094 Object specific Memory allocation | \c OS_MSGQUEUE_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1095 Number of Message Queue objects | \c OS_MSGQUEUE_NUM | Defines maximum number of objects that can be active at the same time. Applies to objects with system provided memory for control blocks. Value range is \token{[1-1000]}.
1096 Data Storage Memory size [bytes] | \c OS_MSGQUEUE_DATA_SIZE | Defines the combined data storage memory size. Applies to objects with system provided memory for data storage. Default value is \token{0}. Value range is \token{[0-1073741824]}, in multiples of \token{8}.
1098 \subsection msgQueueConfig_obj Object-specific memory allocation
1099 When Object-specific Memory is used, the number of queues for all Message Queue objects is specified by \c OS_MSGQUEUE_NUM.
1100 The total storage size reserved for all queues is configured in \c OS_MSGQUEUE_DATA_SIZE. Refer to \ref ObjectMemoryPool.
1104 /* ========================================================================================================================== */
1106 \page creating_RTX5_LIB Building the RTX5 Library
1108 The CMSIS Pack contains a µVision project for building the complete set of RTX5 libraries. This project can also be used as
1109 a reference for building the RTX5 libraries using a tool-chain of your choice.
1111 -# Open the project \b RTX_CM.uvprojx from the pack folder <b>CMSIS/RTOS2/RTX/Library/ARM/MDK</b> in µVision.
1112 -# Select the project target that matches your device's processor core.
1113 \n The project provides target configuration for all supported Cortex-M targets supported by RTX5.
1114 -# You can find out about the required preprocessor defines in the dialogs <b>Options for Target - C/C++</b> and
1115 <b>Options for Target - Asm</b>. Note the need to use at least the C99 compiler mode when building RTX from source.
1116 -# From the <b>Project</b> window you find the list of source files required for a complete library build.
1117 -# Build the library of your choice using \b Project - \b Build \b Target (or press F7).
1119 \image html own_lib_projwin.png "Project with files for Armv8-M Mainline"
1123 /* ========================================================================================================================== */
1125 \page dirstructfiles5 Directory Structure and File Overview
1127 The following section provides an overview of the directory structure and the files that are relevant for the user's for
1128 CMSIS-RTOS RTX v5. The following directory references start below the CMSIS pack installation path, for example
1129 ARM/CMSIS/<i>version</i>/CMSIS/RTOS2.
1131 \section Folders RTX v5 Directory Structure
1133 The CMSIS-RTOS RTX v5 is delivered in source code and several examples are provided.
1135 <table class="cmtable" summary="CMSIS-RTOS RTX Library Files">
1142 <td>The include file for CMSIS-RTOS API v2. cmsis_os2.h is the central include file for user applications.</td>
1146 <td>CMSIS-RTOS API template source and header file.</td>
1150 <td>Directory with RTX specific files and folders. Also contains the component viewer description file.</td>
1154 <td>CMSIS-RTOS RTX configuration files %RTX_Config.h and %RTX_Config.c.</td>
1157 <td>RTX/Examples</td>
1158 <td>Example projects that can be directly used in development tools.</td>
1161 <td>RTX/Include</td>
1162 <td>RTX v5 specific include files.</td>
1165 <td>RTX/Include1</td>
1166 <td>CMSIS-RTOS v1 API header file.</td>
1169 <td>RTX/Library</td>
1170 <td>Pre-built libraries (see next table for details).</td>
1174 <td>Source code that can be used with ARMCC and GCC.</td>
1177 <td>RTX/Template</td>
1178 <td>User code templates for creating application projects with CMSIS-RTOS RTX v5.</td>
1182 \section libFiles RTX v5 Library Files
1184 The CMSIS-RTOS RTX Library is available pre-compiled for ARMCC and GCC compilers and supports all Cortex-M
1185 processor variants in every configuration, including Arm Cortex-M23 and Cortex-M33.
1187 <table class="cmtable" summary="CMSIS-RTOS RTX Library Files">
1189 <th>Library File</th>
1190 <th>Processor Configuration</th>
1193 <td>Library/ARM/RTX_CM0.lib</td>
1194 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Cortex-M0 and M1, little-endian.</td>
1197 <td>Library/ARM/RTX_CM3.lib</td>
1198 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Cortex-M3, M4, and M7 without FPU, little-endian.</td>
1201 <td>Library/ARM/RTX_CM4F.lib</td>
1202 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Cortex-M4 and M7 with FPU, little-endian.</td>
1205 <td>Library/ARM/RTX_V8MB.lib</td>
1206 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Armv8-M Baseline.</td>
1209 <td>Library/ARM/RTX_V8MBN.lib</td>
1210 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Armv8-M Baseline, non-secure.</td>
1213 <td>Library/ARM/RTX_V8MM.lib</td>
1214 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Armv8-M Mainline.</td>
1217 <td>Library/ARM/RTX_V8MMF.lib</td>
1218 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Armv8-M Mainline with FPU.</td>
1221 <td>Library/ARM/RTX_V8MMFN.lib</td>
1222 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Armv8-M Mainline with FPU, non-secure.</td>
1225 <td>Library/ARM/RTX_V8MMN.lib</td>
1226 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Armv8-M Mainline, non-secure.</td>
1229 <td>Library/GCC/libRTX_CM0.a</td>
1230 <td>CMSIS-RTOS libRTX Library for GCC Compiler, Cortex-M0 and M1, little-endian.</td>
1233 <td>Library/GCC/libRTX_CM3.a</td>
1234 <td>CMSIS-RTOS libRTX Library for GCC Compiler, Cortex-M3, M4, and M7 without FPU, little-endian.</td>
1237 <td>Library/GCC/libRTX_CM4F.a</td>
1238 <td>CMSIS-RTOS libRTX Library for GCC Compiler, Cortex-M4 and M7 with FPU, little-endian.</td>
1241 <td>Library/GCC/libRTX_V8MB.a</td>
1242 <td>CMSIS-RTOS libRTX Library for GCC Compiler, Armv8-M Baseline.</td>
1245 <td>Library/GCC/libRTX_V8MBN.a</td>
1246 <td>CMSIS-RTOS libRTX Library for GCC Compiler, Armv8-M Baseline, non-secure.</td>
1249 <td>Library/GCC/libRTX_V8MM.a</td>
1250 <td>CMSIS-RTOS libRTX Library for GCC Compiler, Armv8-M Mainline.</td>
1253 <td>Library/GCC/libRTX_V8MMF.a</td>
1254 <td>CMSIS-RTOS libRTX Library for GCC Compiler, Armv8-M Mainline with FPU.</td>
1257 <td>Library/GCC/libRTX_V8MMFN.a</td>
1258 <td>CMSIS-RTOS libRTX Library for GCC Compiler, Armv8-M Mainline with FPU, non-secure.</td>
1261 <td>Library/GCC/libRTX_V8MMN.a</td>
1262 <td>CMSIS-RTOS libRTX Library for GCC Compiler, Armv8-M Mainline, non-secure.</td>
1267 /* ========================================================================================================================== */
1269 \page technicalData5 Technical Data
1271 \section technicalData_Toolchains Supported Toolchains
1273 Keil RTX5 is developed and tested using the common toolchains and development environments.
1275 \subsection technicalData_Toolchain_ARM Arm Compiler (Arm/Keil MDK, uVision5)
1277 Major parts of RTX5 are developed and optimized using Arm Compiler and Arm/Keil MDK.
1278 The current release is tested with the following versions:
1280 <li>Arm Compiler 5.06 Update 6</li>
1281 <li>Arm Compiler 6.6.2 (Long Term Maintenance)</li>
1282 <li>Arm Compiler 6.9</li>
1283 <li>RTOS-aware debugging with uVision 5.24</li>
1286 \subsection technicalData_Toolchain_IAR IAR Embedded Workbench
1288 RTX5 has been ported to fully support IAR Embedded Workbench. The following releases are known to work:
1290 <li>IAR Embedded Workbench 7.7 (<a href="https://github.com/ARM-software/CMSIS_5/issues/201">community report</a>)</li>
1291 <li>IAR Embedded Workbench 7.80.4</li>
1292 <li><b>IAR Embedded Workbench 8.20.1</b></li>
1295 \subsection technicalData_Toolchain_GCC GNU Compiler Collection
1297 RTX5 has also been ported to support GCC, maintenance mainly relays on community contribution.
1298 Active development is currently tested with:
1300 <li>GNU Tools for Arm Embedded 6.3.1 20170620</li>
1303 \section technicalData5_ControlBlockSizes Control Block Sizes
1305 Keil RTX5 specific control block definitions (including sizes) as well as memory pool and message queue memory requirements
1306 are defined in the RTX5 header file:
1309 /// Control Block sizes
1310 #define osRtxThreadCbSize sizeof(osRtxThread_t)
1311 #define osRtxTimerCbSize sizeof(osRtxTimer_t)
1312 #define osRtxEventFlagsCbSize sizeof(osRtxEventFlags_t)
1313 #define osRtxMutexCbSize sizeof(osRtxMutex_t)
1314 #define osRtxSemaphoreCbSize sizeof(osRtxSemaphore_t)
1315 #define osRtxMemoryPoolCbSize sizeof(osRtxMemoryPool_t)
1316 #define osRtxMessageQueueCbSize sizeof(osRtxMessageQueue_t)
1318 /// Memory size in bytes for Memory Pool storage.
1319 /// \param block_count maximum number of memory blocks in memory pool.
1320 /// \param block_size memory block size in bytes.
1321 #define osRtxMemoryPoolMemSize(block_count, block_size) \
1322 (4*(block_count)*(((block_size)+3)/4))
1324 /// Memory size in bytes for Message Queue storage.
1325 /// \param msg_count maximum number of messages in queue.
1326 /// \param msg_size maximum message size in bytes.
1327 #define osRtxMessageQueueMemSize(msg_count, msg_size) \
1328 (4*(msg_count)*(3+(((msg_size)+3)/4)))
1331 If you are using a \ref GlobalMemoryPool to allocate memory for the RTOS objects, you need to know the size that is required
1332 for each object in case of errors. Currently, the control block sizes are as follows (subject to change without
1335 Type | Control block size in bytes |
1336 --------------|:---------------------------:|
1343 Message Queue | 52 |
1345 The size of the memory that is required for memory pool and message queue data storage can be determined from the macros
1349 /* ========================================================================================================================== */
1351 \page CodingRules Coding Rules
1353 - prefix osXxxx, os_xxx, osRtx
1358 /* ========================================================================================================================== */
1360 \page misraCompliance5 MISRA C:2012 Compliance
1361 The RTX5 C source files use <b><a class=el href="http://www.misra.org.uk/" target="_blank">MISRA C:2012</a></b> guidelines as underlying coding standard.
1363 For MISRA validation, <b><a class=el href="http://www.gimpel.com/" target="_blank">PC-lint</a></b> V9.00L is used with configuration for Arm Compiler V6.9.
1364 The PC-Lint validation setup is part of the project file <b>.\\CMSIS\\RTOS2\\RTX\\Library\\ARM\\MDK\\RTX_CM.uvprojx</b> as shown below.
1365 Refer to <b><a class=el href="http://www.keil.com/support/man/docs/uv4/uv4_ut_pclint_validation.htm" target="_blank">Setup for PC-Lint</a></b> for more information.
1367 \image html "PC-Lint.png" "Running PC-Lint within MDK - uVision"
1369 The PC-Lint configuration uses the following Options under <b>Tools - PC-Lint Setup...</b>:
1370 - Config File: co-ARMCC-6.lnt (20-Mar-2017) with additional options:
1373 -esym(526,__builtin_*) -esym(628,__builtin_*)
1374 -sem(__builtin_clz, pure)
1375 +doffsetof(t,m)=((size_t)&((t*)0)->m) -emacro((413,923,9078),offsetof)
1376 -ecall(534,__disable_irq)
1378 - Included Project Information:
1379 - Enable: Add 'Include' paths
1380 - Enable: Add 'Software Packs' paths
1381 - Enable: Verify 'Software Packs' includes
1382 - Enable: Add 'Preprocessor' symbols
1383 - Enable: Add 'Define' symbols
1384 - MISRA Rules Setup and Configuration:
1385 - MISRQ_C_2012_Config.lnt; all rules enabled
1386 - includes definition file: au-misra3.lnt (12-Jun-2014)
1387 - Additional Lint Commands (for both single and mutiple files):
1389 - emacro(835,osRtxConfigPrivilegedMode)
1392 The C source code is annotated with PC-Lint control comments to allows MISRA deviations.
1393 These deviations with the underlaying design decisions are described in the following.
1398 The RTX source code has the following deviations from MISRA:
1413 All source code deviations are clearly marked and in summary these deviations affect the following MISRA rules:
1414 - [MISRA 2012 Directive 4.9, advisory]: A function should be used in preference to a function-like macro where yet are interchangeable
1415 - [MISRA 2012 Rule 1.3, required]: There shall be no occurrence of undefined or critical unspecified behavior
1416 - [MISRA 2012 Rule 10.3, required]: Expression assigned to a narrower or different essential type
1417 - [MISRA 2012 Rule 10.5, advisory]: Impermissible cast; cannot cast from 'essentially unsigned' to 'essentially enum\<i\>'
1418 - [MISRA 2012 Rule 11.1, required]: Conversions shall not be performed between a pointer to a function and any other type
1419 - [MISRA 2012 Rule 11.3, required]: A cast shall not be performed between a pointer to object type and a pointer to a different object type
1420 - [MISRA 2012 Rule 11.4, advisory]: A conversion should not be performed between a pointer to object and an integer type
1421 - [MISRA 2012 Rule 11.5, advisory]: A conversion should not be performed from pointer to void into pointer to object
1422 - [MISRA 2012 Rule 11.6, required]: A cast shall not be performed between pointer to void and an arithmetic type
1423 - [MISRA 2012 Rule 15.5, advisory]: A function should have a single point of exit at the end
1424 - [MISRA 2012 Rule 20.10, advisory]: The # and ## preprocessor operators should not be used
1426 In the following all deviations are described in detail.
1428 \section MISRA_1 [MISRA Note 1]: Return statements for parameter checking
1430 Return statements are used at the beginning of several functions to validate parameter values and object states.
1431 The function returns immediately without any side-effects and typically an error status is set. This structure
1432 keeps the source code better structured and easier to understand.
1434 This design decision implies the following MISRA deviation:
1435 - [MISRA 2012 Rule 15.5, advisory]: A function should have a single point of exit at the end
1437 All locations in the source code are marked with:
1439 //lint -e{904} "Return statement before end of function" [MISRA Note 1]
1443 \section MISRA_2 [MISRA Note 2]: Object identifiers are void pointers
1445 CMSIS-RTOS is independant of an underlying RTOS implementation. The object idenifiers are therefore defined as void pointers to:
1446 - allow application programs that are agnostic from an underlying RTOS implementation.
1447 - avoid accidently accesses an RTOS control block from an application program.
1449 This design decisions imply the following MISRA deviations:
1450 - [MISRA 2012 Rule 11.3, required]: A cast shall not be performed between a pointer to object type and a pointer to a different object type
1451 - [MISRA 2012 Rule 11.5, advisory]: A conversion should not be performed from pointer to void into pointer to object
1453 All locations in the source code are marked with:
1455 //lint -e{9079} -e{9087} "cast from pointer to void to pointer to object type" [MISRA Note 2]
1458 In the RTX5 implementation the requried pointer conversions are implemented in the header file rtx_lib.h with the following inline functions:
1461 osRtxThread_t *osRtxThreadId (osThread_t thread_id);
1462 osRtxTimer_t *osRtxTimerId (osTimer_t timer_id);
1463 osRtxEventFlags_t *osRtxEventFlagsId (osEventFlags_t ef_id);
1464 osRtxMutex_t *osRtxMutexId (osMutex_t mutex_id);
1465 osRtxSemaphore_t *osRtxSemaphoreId (osSemaphore_t semaphore_id);
1466 osRtxMemoryPool_t *osRtxMemoryPoolId (osMemoryPoolId_t mp_id);
1467 osRtxMessageQueue_t *osRtxMessageQueueId(osMessageQueueId_t mq_id);
1470 \section MISRA_3 [MISRA Note 3]: Conversion to unified object control blocks
1472 RTX uses a unified object control block structure that contains common object members.
1473 The unified control blocks use a fixed layout at the beginning of the sturcture and starts always with an object identifier.
1474 This allows common object functions that receive a pointer to a unified object control block and reference only the
1475 pointer or the members in the fixed layout. Using common object functions and data (for example the ISR queue) reduces
1476 code complexity and keeps the source code better structured. Refer also to \ref MISRA_4
1478 This design decisions imply the following MISRA deviations:
1479 - [MISRA 2012 Rule 11.3, required]: A cast shall not be performed between a pointer to object type and a pointer to a different object type
1480 - [MISRA 2012 Rule 11.5, advisory]: A conversion should not be performed from pointer to void into pointer to object
1482 All locations in the source code are marked with:
1484 //lint -e{9079} -e{9087} "cast from pointer to void to pointer to object type" [MISRA Note 3]
1488 In the RTX5 implementation the requried pointer conversions are implemented in the header file \em rtx_lib.h with the following inline function:
1491 osRtxObject_t *osRtxObject (void *object);
1495 \section MISRA_4 [MISRA Note 4]: Conversion from unified object control blocks
1497 RTX uses a unified object control block structure that contains common object members. Refer to \ref MISRA_3 for more information.
1498 To process specifc control block data, pointer conversions are required.
1500 This design decisions imply the following MISRA deviations:
1501 - [MISRA 2012 Rule 1.3, required]: There shall be no occurrence of undefined or critical unspecified behavior
1502 - [MISRA 2012 Rule 11.3, required]: A cast shall not be performed between a pointer to object type and a pointer to a different object type
1503 In addition PC-Lint issues:
1504 - Info 826: Suspicious pointer-to-pointer conversion (area too small)
1506 All locations in the source code are marked with:
1508 //lint -e{740} -e{826} -e{9087} "cast from pointer to generic object to specific object" [MISRA Note 4]
1511 In the RTX5 source code the requried pointer conversions are implemented in the header file \em rtx_lib.h with the following inline functions:
1514 osRtxThread_t *osRtxThreadObject (osRtxObject_t *object);
1515 osRtxTimer_t *osRtxTimerObject (osRtxObject_t *object);
1516 osRtxEventFlags_t *osRtxEventFlagsObject (osRtxObject_t *object);
1517 osRtxMutex_t *osRtxMutexObject (osRtxObject_t *object);
1518 osRtxSemaphore_t *osRtxSemaphoreObject (osRtxObject_t *object);
1519 osRtxMemoryPool_t *osRtxMemoryPoolObject (osRtxObject_t *object);
1520 osRtxMessageQueue_t *osRtxMessageQueueObject (osRtxObject_t *object);
1521 osRtxMessage_t *osRtxMessageObject (osRtxObject_t *object);
1524 \section MISRA_5 [MISRA Note 5]: Conversion to object types
1526 The RTX5 kernel has common memory management functions that use void pointers. These memory allocation fuctions returns
1527 a void pointer which is correctly aligned for object types.
1529 This design decision implies the following MISRA deviations:
1530 - [MISRA 2012 Rule 11.5, advisory]: A conversion should not be performed from pointer to void into pointer to object
1532 All locations in the source code are marked with:
1534 //lint -e{9079} "conversion from pointer to void to pointer to other type" [MISRA Note 5]
1540 os_thread_t *thread;
1542 //lint -e{9079} "conversion from pointer to void to pointer to other type" [MISRA Note 5]
1543 thread = osRtxMemoryPoolAlloc(osRtxInfo.mpi.thread);
1548 \section MISRA_6 [MISRA Note 6]: Conversion from user provided storage
1550 CMSIS-RTOS2 and RTX5 support user provided storage for object control blocks, stack, and data storage.
1551 The API uses void pointers to define the location of this user provided storage. It is therefore
1552 required to cast the void pointer to underlying storage types. Alignment restrictions of user provided storage
1553 are checked before accessing memory. Refer also to \ref MISRA_7.
1555 This design decisions imply the following MISRA deviations:
1556 - [MISRA 2012 Rule 11.3, required]: A cast shall not be performed between a pointer to object type and a pointer to a different object type
1557 - [MISRA 2012 Rule 11.5, advisory]: A conversion should not be performed from pointer to void into pointer to object
1559 All locations in the source code are marked with:
1561 //lint -e{9079} "conversion from pointer to void to pointer to other type" [MISRA Note 6]
1566 static osTimerId_t svcRtxTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr) {
1571 //lint -e{9079} "conversion from pointer to void to pointer to other type" [MISRA Note 6]
1572 timer = attr->cb_mem;
1576 \section MISRA_7 [MISRA Note 7]: Check for proper pointer alignment
1578 RTX5 verifies the alignment of user provided storage for object control blocks, stack, and data storage.
1579 Refer also to \ref MISRA_6 for more information.
1581 This design decision implies the following MISRA deviations:
1582 - [MISRA 2012 Rule 11.4, advisory]: A conversion should not be performed between a pointer to object and an integer type
1583 - [MISRA 2012 Rule 11.6, required]: A cast shall not be performed between pointer to void and an arithmetic type
1585 All locations in the source code are marked with:
1587 //lint -e(923) -e(9078) "cast from pointer to unsigned int" [MISRA Note 7]
1592 static osThreadId_t svcRtxThreadNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr) {
1596 if (stack_mem != NULL) {
1597 //lint -e(923) -e(9078) "cast from pointer to unsigned int" [MISRA Note 7]
1598 if ((((uint32_t)stack_mem & 7U) != 0U) || (stack_size == 0U)) {
1602 \section MISRA_8 [MISRA Note 8]: Memory allocation management
1604 RTX5 implements memory allocation functions which require pointer arithmetic to manage memory.
1605 The structure with the type \em mem_block_t that is used to menage memory allocation blocks is defined in \em rtx_memory.c
1607 This design decision implies the following MISRA deviations:
1608 - [MISRA 2012 Rule 11.4, advisory]: A conversion should not be performed between a pointer to object and an integer type
1609 - [MISRA 2012 Rule 11.6, required]: A cast shall not be performed between pointer to void and an arithmetic type
1611 All locations in the source code are marked with:
1613 //lint -e(923) -e(9078) "cast from pointer to unsigned int" [MISRA Note 8]
1616 The required pointer arithmetic is implemented in \em rtx_memory.c with the following function:
1618 __STATIC_INLINE mem_block_t *MemBlockPtr (void *mem, uint32_t offset) {
1622 //lint --e{923} --e{9078} "cast between pointer and unsigned int" [MISRA Note 8]
1623 addr = (uint32_t)mem + offset;
1624 ptr = (mem_block_t *)addr;
1630 \section MISRA_9 [MISRA Note 9]: Pointer conversions for register access
1632 The CMSIS-Core peripheral register blocks are accessed using a structure. The memory address of this structure
1633 is specified as unsigned integer number. Pointer conversions are required to access the specific registers.
1635 This design decision implies the following MISRA deviations:
1636 - [MISRA 2012 Rule 11.4, advisory]: A conversion should not be performed between a pointer to object and an integer type
1637 - [MISRA 2012 Rule 11.6, required]: A cast shall not be performed between pointer to void and an arithmetic type
1639 All locations in the source code are marked with:
1641 //lint -emacro((923,9078),SCB) "cast from unsigned long to pointer" [MISRA Note 9]
1647 #define SCS_BASE (0xE000E000UL)
1648 #define SCB ((SCB_Type *)SCB_BASE)
1649 typedef struct {...} SCB_Type;
1654 \section MISRA_10 [MISRA Note 10]: SVC calls use function-like macros
1656 RTX5 is using SVC (Service Calls) to switch between thread mode (for user code execution) and handler mode (for RTOS kernel execution).
1657 The SVC function call mechanism is implemented with assembly instructions to construct the code for SVC.
1658 The source code uses C macros and are designed as C function-like macros to generate parameter passing
1659 for variables depending on macro parameters. An alternative replacement code would be complex.
1660 The C macros use multiple '##' operators however it has been verified that the order of evaluation is irrelevant
1661 and result of macro expansion is always predictable.
1663 This design decision implies the following MISRA deviations:
1664 - [MISRA 2012 Directive 4.9, advisory]: A function should be used in preference to a function-like macro where yet are interchangeable
1665 - [MISRA 2012 Rule 1.3, required]: There shall be no occurrence of undefined or critical unspecified behavior
1666 - [MISRA 2012 Rule 20.10, advisory]: The # and ## preprocessor operators should not be used
1668 The relevant source code is in the file \em rtx_core_cm.h and is marked with:
1670 //lint -save -e9023 -e9024 -e9026 "Function-like macros using '#/##'" [MISRA Note 10]
1674 \section MISRA_11 [MISRA Note 11]: SVC calls use assembly code
1676 The SVC (Service Call) functions are constructed as a mix of C and inline assembly as it is required to access CPU registers
1677 for parameter passing. The function parameters are mapped to the CPU registers R0..R3 and SVC function number to
1678 CPU register R12 (or R7). For assembly inter-working the function parameters are casted to unsigned int values.
1680 The function return value after SVC call is mapped to the CPU register R0. Return value is casted from unsigned int
1681 to the target value.
1683 It has been verified that this method has has no side-effects and is well defined.
1685 This design decision implies the following MISRA deviations:
1686 - [MISRA 2012 Rule 10.3, required]: Expression assigned to a narrower or different essential type
1687 - [MISRA 2012 Rule 10.5, advisory]: Impermissible cast; cannot cast from 'essentially unsigned' to 'essentially enum\<i\>'
1688 - [MISRA 2012 Rule 11.1, required]: Conversions shall not be performed between a pointer to a function and any other type
1689 - [MISRA 2012 Rule 11.4, advisory]: A conversion should not be performed between a pointer to object and an integer type
1690 - [MISRA 2012 Rule 11.6, required]: A cast shall not be performed between pointer to void and an arithmetic type
1692 SVC functions are marked as library modules and not processed by PC-lint. The relevant source code is marked with:
1694 //lint ++flb "Library Begin" [MISRA Note 11]
1696 //lint --flb "Library End"
1701 // Service Calls definitions
1702 //lint ++flb "Library Begin" [MISRA Note 11]
1703 SVC0_1(Delay, osStatus_t, uint32_t)
1704 SVC0_1(DelayUntil, osStatus_t, uint32_t)
1705 //lint --flb "Library End"
1708 PC-lint does not process ASM input/output operand lists and therefore falsely identifies issues:
1709 - Last value assigned to variable not used
1710 - Symbol not subsequently referenced
1711 \todo: what has been done to mitigate that?
1714 \section MISRA_12 [MISRA Note 12]: Usage of exclusive access instructions
1716 The RTX5 implementation uses the CPU instructions LDREX and STREX (when supported by the processor) to implement atomic operations.
1717 This atomic operations elimite the requirement for interrupt lock-outs. The atomic operations are implemented using
1720 PC-lint cannot process assembler instructions including the input/output operand lists and therefore falsely identifies issues:
1721 - Symbol not initialized
1722 - Symbol not subsequently referenced
1723 - Symbol not referenced
1724 - Pointer parameter could be declared as pointing to const
1726 It has been verified that atomic operations have no side-effects and are well defined.
1728 The functions that implement atomic instructions are marked as library modules and not processed by PC-lint. The relevant source code is marked with:
1730 //lint ++flb "Library Begin" [MISRA Note 12]
1732 //lint --flb "Library End"
1736 \section MISRA_13 [MISRA Note 13]: Usage of Event Recorder
1738 The Event Recorder is a generic event logger and the related functions are called to record an event.
1739 The function parameters are 32-bit id, 32-bit values, pointer to void (data) and are recorded as 32-bit numbers.
1740 The parameters for the Event Recorder may require cast opertions to unsigned int which however has no side-effects
1741 and is well defined.
1743 The return value indicates success or failure. There is no need to check the return value since no action is
1744 taken when a Event Recorder function fail. The EventID macro (part of external Event Recorder) constructs the
1745 ID based on input parameters which are shifted, masked with '&' and combined with '|'.
1746 Zero value input parameters are valid and cause zero used with '&' and '|'.
1748 The usage of the Event Recorder implies the following MISRA deviations:
1749 - [MISRA 2012 Rule 11.1, required]: Conversions shall not be performed between a pointer to a function and any other type
1750 - [MISRA 2012 Rule 11.4, advisory]: A conversion should not be performed between a pointer to object and an integer type
1751 - [MISRA 2012 Rule 11.6, required]: A cast shall not be performed between pointer to void and an arithmetic type
1752 In addition PC-Lint issues:
1753 - Info 835: A zero has been given as left argument to operator '&'
1754 - Info 845: The right argument to operator '|' is certain to be 0
1756 The functions that call the Event Recorder are in the module \em rtx_evr.c and the related PC-Lint messages are disabled with:
1758 //lint -e923 -e9074 -e9078 -emacro((835,845),EventID) [MISRA Note 13]
1763 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1765 \page rtosValidation RTOS Validation
1767 Arm offers a <a class=el href="http://www.keil.com/pack" target="_blank">Software Pack</a> for the CMSIS-RTOS Validation.
1768 The <b>ARM::CMSIS-RTOS_Validation</b> Pack contains the following:
1770 - Source code of a CMSIS-RTOS Validation Suite along with configuration file.
1771 - Documentation of the CMSIS-RTOS Validation Suite.
1772 - Example that shows the usage of the CMSIS-RTOS Validation Suite using simulation.
1775 Currently, a public version of the test suite is available only for CMSIS-RTOS v1 API.
1777 The CMSIS-RTOS Validation Suite performs generic validation of various RTOS features. The test cases verify the
1778 functional behavior, test invalid parameters and call management functions from ISR.
1780 The following CMSIS-RTOS features can be tested with the current release:
1781 - Thread : Create multiple threads, terminate, restart, yield, change priority
1782 - Timer : Create periodic and one-shot timers
1783 - GenWait : Call generic wait functions (osDelay and osWait)
1784 - WaitFunc : Measure wait ticks (delay, mail, message, mutex, semaphore, signal)
1786 Moreover the following inter-thread communication functions can be tested:
1787 - Signal : Verify signal events
1788 - Memory Pool : Verify memory allocation
1789 - Message Queue : Exchange messages between threads
1790 - Mail Queue : Exchange data between threads
1791 - Mutex : Synchronize resource access
1792 - Semaphore : Access shared resources
1794 The RTOS Validation output can be printed to a console, output via ITM printf, or output to a memory buffer.
1796 \section test_output Sample Test Output
1798 CMSIS-RTOS Test Suite Oct 21 2015 16:39:16
1800 TEST 01: TC_ThreadCreate PASSED
1801 TEST 02: TC_ThreadMultiInstance PASSED
1802 TEST 03: TC_ThreadTerminate PASSED
1805 TEST 08: TC_ThreadChainedCreate PASSED
1806 TEST 09: TC_ThreadYield NOT EXECUTED
1807 TEST 10: TC_ThreadParam PASSED
1810 TEST 60: TC_MailFromISRToThread PASSED
1812 Test Summary: 60 Tests, 59 Executed, 59 Passed, 0 Failed, 0 Warnings.
1818 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1820 \page functionOverview Function Overview
1822 CMSIS-RTOS v2 provides multiple API interfaces:
1823 - \subpage rtos_api2 is the new C function API that supports dynamic object creation and Armv8-M (Arm Cortex-M23 and
1825 - <a class="el" href="../../RTOS/html/functionOverview.html">CMSIS-RTOS C API v1</a> is a C function API that is backward
1826 compatible with CMSIS-RTOS v1.
1827 - \subpage rtos_apicpp is a C++ class function API.
1829 It is possible to intermix the different API variants in the same application and even in the same C/C++ source module.
1830 However, the functions of the <b>C API Version 1</b> may be deprecated in future versions of CMSIS-RTOS.
1832 \section rtos_api2 CMSIS-RTOS2
1834 Overview of all CMSIS-RTOS C API v2 functions that are implemented in the \subpage cmsis_os2_h.
1836 \subsection rtos_api2_basics Common Design Concepts
1838 All RTOS objects share a common design concept. The overall life-cycle of
1839 an object can be summarized as created -> in use -> destroyed.
1841 <b>Create Objects</b>
1843 An object is created by calling its `osXxxNew` function. The new function returns an identifier
1844 that can be used to operate with the new object. The actual state of an object is typically stored
1845 in an object specific control block. The memory layout (and size needed) for the control
1846 block is implementation specific. One should not make any specific assumptions about the control
1847 block. The control block layout might change and hence should be seen as an implementation
1850 In order to expose control about object specific options all `osXxxNew` functions provide an
1851 optional `attr` argument, which can be left as \token{NULL} by default. It takes a pointer to
1852 an object specific attribute structure, commonly containing the fields
1853 - `name` to attach a human readable name to the object for identification,
1854 - `attr_bits` to control object-specific options,
1855 - `cb_mem` to provide memory for the control block manually, and
1856 - `cb_size` to quantify the memory size provided for the control block.
1858 The `name` attribute is only used for object identification, e.g. using RTOS-aware debugging. The
1859 attached string is not used for any other purposes internally.
1861 The `cb_mem` and `cb_size` attributes can be used to provide memory for the control block manually
1862 instead of relying on the implementation internal memory allocation. One has to assure that the
1863 amount of memory pointed to by `cb_mem` is sufficient for the objects control block structure. If
1864 the size given as `cb_size` is not sufficient the `osXxxNew` function returns with an error, i.e.
1865 returning \token{NULL}. Furthermore providing control block memory manually is less portable. Thus
1866 one has to take care about implementation specific alignment and placement requirements for instance.
1867 Refer to \ref CMSIS_RTOS_MemoryMgmt for further details.
1871 After an object has been created successfully it can be used until it is destroyed. The actions
1872 defined for an object depends on its type. Commonly all the `osXxxDoSomething` access function
1873 require the reference to the object to work with as the first `xxx_id` parameter.
1875 The access function can be assumed to apply some sort of sanity checking on the id parameter. So
1876 that it is assured one cannot accidentally call an access function with a \token{NULL} object
1877 reference. Furthermore the concrete object type is verified, i.e. one cannot call access functions
1878 of one object type with a reference to another object type.
1880 All further parameter checks applied are either object and action specific or may even be implementation
1881 specific. Thus one should always check action function return values for `osErrorParameter` to asure the
1882 provided arguments were accepted.
1884 As a rule of thumb only non-blocking access function can be used from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines" (ISR).
1885 This incorporates `osXxxWait` functions (and similar) limited to be called with parameter `timeout`
1886 set to \token{0}, i.e. usage of try-semantics.
1888 <b>Object Destruction</b>
1890 Objects that are not needed anymore can be destructed on demand to free the control block memory. Objects
1891 are not destructed implicitly. Thus one can assume an object id to be valid until `osXxxDelete` is called
1892 explicitly. The delete function finally frees the control block memory. In case of user provided control
1893 block memory, see above, the memory must be freed manually as well.
1895 The only exception one has to take care of are Threads which do not have an explicit `osThreadDelete` function.
1896 Threads can either be `detached` or `joinable`. Detached threads are automatically destroyed on termination,
1897 i.e. call to \ref osThreadTerminate or \ref osThreadExit or return from thread function. On the other hand joinable
1898 threads are kept alive until one explicitly calls \ref osThreadJoin.
1900 \subsection rtos_api2_functions Function Reference
1902 - \ref CMSIS_RTOS_KernelCtrl
1903 - \ref osKernelGetInfo : \copybrief osKernelGetInfo
1904 - \ref osKernelGetState : \copybrief osKernelGetState
1905 - \ref osKernelGetSysTimerCount : \copybrief osKernelGetSysTimerCount
1906 - \ref osKernelGetSysTimerFreq : \copybrief osKernelGetSysTimerFreq
1907 - \ref osKernelInitialize : \copybrief osKernelInitialize
1908 - \ref osKernelLock : \copybrief osKernelLock
1909 - \ref osKernelUnlock : \copybrief osKernelUnlock
1910 - \ref osKernelRestoreLock : \copybrief osKernelRestoreLock
1911 - \ref osKernelResume : \copybrief osKernelResume
1912 - \ref osKernelStart : \copybrief osKernelStart
1913 - \ref osKernelSuspend : \copybrief osKernelSuspend
1914 - \ref osKernelGetTickCount : \copybrief osKernelGetTickCount
1915 - \ref osKernelGetTickFreq : \copybrief osKernelGetTickFreq
1917 - \ref CMSIS_RTOS_ThreadMgmt
1918 - \ref osThreadDetach : \copybrief osThreadDetach
1919 - \ref osThreadEnumerate : \copybrief osThreadEnumerate
1920 - \ref osThreadExit : \copybrief osThreadExit
1921 - \ref osThreadGetCount : \copybrief osThreadGetCount
1922 - \ref osThreadGetId : \copybrief osThreadGetId
1923 - \ref osThreadGetName : \copybrief osThreadGetName
1924 - \ref osThreadGetPriority : \copybrief osThreadGetPriority
1925 - \ref osThreadGetStackSize : \copybrief osThreadGetStackSize
1926 - \ref osThreadGetStackSpace : \copybrief osThreadGetStackSpace
1927 - \ref osThreadGetState : \copybrief osThreadGetState
1928 - \ref osThreadJoin : \copybrief osThreadJoin
1929 - \ref osThreadNew : \copybrief osThreadNew
1930 - \ref osThreadResume : \copybrief osThreadResume
1931 - \ref osThreadSetPriority : \copybrief osThreadSetPriority
1932 - \ref osThreadSuspend : \copybrief osThreadSuspend
1933 - \ref osThreadTerminate : \copybrief osThreadTerminate
1934 - \ref osThreadYield : \copybrief osThreadYield
1936 - \ref CMSIS_RTOS_ThreadFlagsMgmt
1937 - \ref osThreadFlagsSet : \copybrief osThreadFlagsSet
1938 - \ref osThreadFlagsClear : \copybrief osThreadFlagsClear
1939 - \ref osThreadFlagsGet : \copybrief osThreadFlagsGet
1940 - \ref osThreadFlagsWait : \copybrief osThreadFlagsWait
1942 - \ref CMSIS_RTOS_EventFlags
1943 - \ref osEventFlagsGetName : \copybrief osEventFlagsGetName
1944 - \ref osEventFlagsNew : \copybrief osEventFlagsNew
1945 - \ref osEventFlagsDelete : \copybrief osEventFlagsDelete
1946 - \ref osEventFlagsSet : \copybrief osEventFlagsSet
1947 - \ref osEventFlagsClear : \copybrief osEventFlagsClear
1948 - \ref osEventFlagsGet : \copybrief osEventFlagsGet
1949 - \ref osEventFlagsWait : \copybrief osEventFlagsWait
1951 - \ref CMSIS_RTOS_Wait
1952 - \ref osDelay : \copybrief osDelay
1953 - \ref osDelayUntil : \copybrief osDelayUntil
1955 - \ref CMSIS_RTOS_TimerMgmt
1956 - \ref osTimerDelete : \copybrief osTimerDelete
1957 - \ref osTimerGetName : \copybrief osTimerGetName
1958 - \ref osTimerIsRunning : \copybrief osTimerIsRunning
1959 - \ref osTimerNew : \copybrief osTimerNew
1960 - \ref osTimerStart : \copybrief osTimerStart
1961 - \ref osTimerStop : \copybrief osTimerStop
1963 - \ref CMSIS_RTOS_MutexMgmt
1964 - \ref osMutexAcquire : \copybrief osMutexAcquire
1965 - \ref osMutexDelete : \copybrief osMutexDelete
1966 - \ref osMutexGetName : \copybrief osMutexGetName
1967 - \ref osMutexGetOwner : \copybrief osMutexGetOwner
1968 - \ref osMutexNew : \copybrief osMutexNew
1969 - \ref osMutexRelease : \copybrief osMutexRelease
1971 - \ref CMSIS_RTOS_SemaphoreMgmt
1972 - \ref osSemaphoreAcquire : \copybrief osSemaphoreAcquire
1973 - \ref osSemaphoreDelete : \copybrief osSemaphoreDelete
1974 - \ref osSemaphoreGetCount : \copybrief osSemaphoreGetCount
1975 - \ref osSemaphoreGetName : \copybrief osSemaphoreGetName
1976 - \ref osSemaphoreNew : \copybrief osSemaphoreNew
1977 - \ref osSemaphoreRelease : \copybrief osSemaphoreRelease
1979 - \ref CMSIS_RTOS_PoolMgmt
1980 - \ref osMemoryPoolAlloc : \copybrief osMemoryPoolAlloc
1981 - \ref osMemoryPoolDelete : \copybrief osMemoryPoolDelete
1982 - \ref osMemoryPoolFree : \copybrief osMemoryPoolFree
1983 - \ref osMemoryPoolGetBlockSize : \copybrief osMemoryPoolGetBlockSize
1984 - \ref osMemoryPoolGetCapacity : \copybrief osMemoryPoolGetCapacity
1985 - \ref osMemoryPoolGetCount : \copybrief osMemoryPoolGetCount
1986 - \ref osMemoryPoolGetName : \copybrief osMemoryPoolGetName
1987 - \ref osMemoryPoolGetSpace : \copybrief osMemoryPoolGetSpace
1988 - \ref osMemoryPoolNew : \copybrief osMemoryPoolNew
1990 - \ref CMSIS_RTOS_Message
1991 - \ref osMessageQueueDelete : \copybrief osMessageQueueDelete
1992 - \ref osMessageQueueGet : \copybrief osMessageQueueGet
1993 - \ref osMessageQueueGetCapacity : \copybrief osMessageQueueGetCapacity
1994 - \ref osMessageQueueGetCount : \copybrief osMessageQueueGetCount
1995 - \ref osMessageQueueGetMsgSize : \copybrief osMessageQueueGetMsgSize
1996 - \ref osMessageQueueGetName : \copybrief osMessageQueueGetName
1997 - \ref osMessageQueueGetSpace : \copybrief osMessageQueueGetSpace
1998 - \ref osMessageQueueNew : \copybrief osMessageQueueNew
1999 - \ref osMessageQueuePut : \copybrief osMessageQueuePut
2000 - \ref osMessageQueueReset : \copybrief osMessageQueueReset
2002 - \ref CMSIS_RTOS_TickAPI
2003 - \ref OS_Tick_Setup : \copybrief OS_Tick_Setup
2004 - \ref OS_Tick_Enable : \copybrief OS_Tick_Enable
2005 - \ref OS_Tick_Disable : \copybrief OS_Tick_Disable
2006 - \ref OS_Tick_AcknowledgeIRQ : \copybrief OS_Tick_AcknowledgeIRQ
2007 - \ref OS_Tick_GetIRQn : \copybrief OS_Tick_GetIRQn
2008 - \ref OS_Tick_GetClock : \copybrief OS_Tick_GetClock
2009 - \ref OS_Tick_GetInterval : \copybrief OS_Tick_GetInterval
2010 - \ref OS_Tick_GetCount : \copybrief OS_Tick_GetCount
2011 - \ref OS_Tick_GetOverflow : \copybrief OS_Tick_GetOverflow
2013 - \ref rtx5_specific
2014 - \ref osRtxErrorNotify : \copybrief osRtxErrorNotify
2015 - \ref osRtxIdleThread : \copybrief osRtxIdleThread
2017 The following CMSIS-RTOS2 functions can be called from threads and \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines"
2019 - \ref osKernelGetInfo, \ref osKernelGetState,
2020 \ref osKernelGetTickCount, \ref osKernelGetTickFreq, \ref osKernelGetSysTimerCount, \ref osKernelGetSysTimerFreq
2021 - \ref osThreadFlagsSet
2022 - \ref osEventFlagsSet, \ref osEventFlagsClear, \ref osEventFlagsGet, \ref osEventFlagsWait
2023 - \ref osSemaphoreAcquire, \ref osSemaphoreRelease, \ref osSemaphoreGetCount
2024 - \ref osMemoryPoolAlloc, \ref osMemoryPoolFree, \ref osMemoryPoolGetCapacity, \ref osMemoryPoolGetBlockSize,
2025 \ref osMemoryPoolGetCount, \ref osMemoryPoolGetSpace
2026 - \ref osMessageQueuePut, \ref osMessageQueueGet, \ref osMessageQueueGetCapacity, \ref osMessageQueueGetMsgSize,
2027 \ref osMessageQueueGetCount, \ref osMessageQueueGetSpace
2031 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2033 \page rtos_apicpp CMSIS-RTOS C++ API
2035 A C++11/C++14 interface is planned for the future.
2039 /* ======================================================================================================================== */
2040 // Group creation for Reference
2042 \addtogroup CMSIS_RTOS1 CMSIS-RTOS API v1
2043 \brief This section describes the CMSIS-RTOS API v1.
2045 The CMSIS-RTOS is a generic API layer that interfaces to an existing RTOS kernel.
2047 CMSIS-RTOS API v2 provides an translation layer for the
2048 <a class="el" href="../../RTOS/html/index.html">CMSIS-RTOS API v1</a> that simplifies migration.
2050 Refer to the <a class="el" href="../../RTOS/html/modules.html">Reference</a> guide of the CMSIS-RTOS API v1 for details.
2053 // Group creation for Reference
2055 \addtogroup CMSIS_RTOS CMSIS-RTOS2 API
2056 \brief Describes the C function interface of CMSIS-RTOS API v2.
2058 The CMSIS-RTOS2 is a generic API layer that interfaces to an RTOS kernel.
2060 The complete API interface is defined in the \ref cmsis_os2_h. When using dynamic memory allocation for objects, source code
2061 or libraries require no modifications when using on a different CMSIS-RTOS2 implementation.
2063 Refer to \ref rtos_api2_basics for further details.
2067 \addtogroup CMSIS_RTOS_MemoryMgmt Memory Management
2069 \brief Information about memory management possibilities
2071 The \ref CMSIS_RTOS offers two options for memory management the user can choose. For object storage one can either use
2072 - \ref CMSIS_RTOS_MemoryMgmt_Automatic (fully portable), or
2073 - \ref CMSIS_RTOS_MemoryMgmt_Manual (implementation specific).
2075 In order to affect the memory allocation scheme all RTOS objects that can be created on request, i.e. those having a `osXxxNew`
2076 function, accept an optional `osXxxAttr_t attr` argument on creation. As a rule of thumb the object attributes at least have
2077 members to assign custom control block memory, i.e. `cb_mem` and `cb_size` members. By default, i.e. `attr` is `NULL`
2078 or `cb_mem` is `NULL`, \ref CMSIS_RTOS_MemoryMgmt_Automatic is used. Providing a pointer to user memory in `cb_mem` switches
2079 to \ref CMSIS_RTOS_MemoryMgmt_Manual.
2081 \note For detailed information about memory allocation strategies provided in RTX5 refer to \ref MemoryAllocation.
2083 \section CMSIS_RTOS_MemoryMgmt_Automatic Automatic Dynamic Allocation
2085 The automatic allocation is the default and viable for many use-cases. Moreover it is fully portable across different
2086 implementations of the \ref CMSIS_RTOS. The common drawback of dynamic memory allocation is the possibility of memory
2087 fragmentation and exhaustion. Given that all needed objects are created once upon system initialization and never
2088 deleted at runtime this class of runtime failures can be prevented, though.
2090 The actual allocation strategy used is implementation specific, i.e. whether global heap or preallocated memory pools are used.
2092 <b> Code Example:</b>
2094 #include "cmsis_os2.h" // implementation agnostic
2096 osMutexId_t mutex_id;
2097 osMutexId_t mutex2_id;
2099 const osMutexAttr_t Thread_Mutex_attr = {
2100 "myThreadMutex", // human readable mutex name
2101 osMutexRecursive | osMutexPrioInherit, // attr_bits
2102 NULL, // memory for control block (default)
2103 0U // size for control block (default)
2106 void CreateMutex (void) {
2107 mutex_id = osMutexNew(NULL); // use default values for all attributes
2108 mutex2_id = osMutexNew(&Thread_Mutex_attr); // use attributes from defined structure
2113 The Mutexes in this example are created using automatic memory allocation.
2115 \section CMSIS_RTOS_MemoryMgmt_Manual Manual User-defined Allocation
2117 One can get fine grained control over memory allocation by providing user-defined memory.
2118 The actual requirements such user-defined memory are implementation specific. Thus one
2119 needs to carefully refer to the size and alignment rules of the implementation used, e.g.
2122 <b> Code Example:</b>
2124 #include "rtx_os.h" // implementation specific
2126 osMutexId_t mutex_id;
2128 static uint32_t mutex_cb[osRtxMutexCbSize/4U]; // implementation specific
2130 const osMutexAttr_t Thread_Mutex_attr = {
2131 "myThreadMutex", // human readable mutex name
2132 osMutexRecursive | osMutexPrioInherit, // attr_bits
2133 mutex_cb, // memory for control block (user-defined)
2134 sizeof(mutex_cb) // size for control block (user-defined)
2137 void CreateMutex (void) {
2138 mutex_id = osMutexNew(&Thread_Mutex_attr); // use attributes from defined structure
2143 The above example uses user-defined memory for the mutex control block. Depending on the actual
2144 implementation used one needs to include the specific header file, `rtx_os.h` in this case.
2149 \addtogroup rtx5_specific RTX5 Specific API
2150 \brief This section describes CMSIS-RTOS RTX5 specifics.
2152 The RTX5 kernel can be customized for different application requirements:
2153 - If you are depending on the \ref lowPower "lowest power consumption" possible, you need to adapt the function
2154 \ref osRtxIdleThread to send the system to sleep mode as often as possible. In addition, use the
2155 \ref TickLess "tick-less low power" functions \ref osKernelSuspend and \ref osKernelResume to suspend the scheduler and to
2156 stop the SysTick timer.
2157 - If you try to find a \b runtime \b error, use the function \ref osRtxErrorNotify to debug the error.
2159 RTX5 interfaces to the <a href="http://www.keil.com/pack/doc/compiler/EventRecorder/html/index.html" target="_blank"><b>Event Recorder</b></a>
2160 to provide event information which helps you to understand and analyze the operation. Refer to \ref rtx_evr for more
2168 \defgroup rtx5_specific_defines Macros
2174 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2176 \def osRtxThreadCbSize
2179 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2181 \def osRtxTimerCbSize
2184 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2186 \def osRtxEventFlagsCbSize
2189 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2191 \def osRtxMutexCbSize
2194 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2196 \def osRtxSemaphoreCbSize
2199 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2201 \def osRtxMemoryPoolCbSize
2204 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2206 \def osRtxMessageQueueCbSize
2209 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2211 \def osRtxMemoryPoolMemSize
2214 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2216 \def osRtxMessageQueueMemSize
2224 \defgroup rtx5_specific_structs Structs
2230 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2232 \struct osRtxThread_t
2235 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2237 \struct osRtxTimerFinfo_t
2240 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2242 \struct osRtxTimer_t
2245 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2247 \struct osRtxEventFlags_t
2250 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2252 \struct osRtxMutex_t
2255 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2257 \struct osRtxSemaphore_t
2260 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2262 \struct osRtxMemoryPool_t
2265 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2267 \struct osRtxMessageQueue_t
2275 \defgroup rtx5_specific_functions Functions
2276 \brief RTX5 functions
2281 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2283 \fn uint32_t osRtxErrorNotify (uint32_t code, void *object_id);
2285 Some system error conditions can be detected during runtime. If the RTX kernel detects a runtime error, it calls the runtime
2286 error function \b osRtxErrorNotify for an object specified by parameter \a object_id.
2288 The parameter \a code passes the actual error code to this function:
2289 | Error Code | Description |
2290 |------------------------------|-----------------------------------------------------------------------------------|
2291 | osRtxErrorStackUnderflow | Stack overflow detected for thread (thread_id=object_id) |
2292 | osRtxErrorISRQueueOverflow | ISR Queue overflow detected when inserting object (object_id) |
2293 | osRtxErrorTimerQueueOverflow | User Timer Callback Queue overflow detected for timer (timer_id=object_id) |
2294 | osRtxErrorClibSpace | Standard C/C++ library libspace not available: increase \c OS_THREAD_LIBSPACE_NUM |
2295 | osRtxErrorClibMutex | Standard C/C++ library mutex initialization failed |
2297 The function \b osRtxErrorNotify must contain an infinite loop to prevent further program execution. You can use an emulator
2298 to step over the infinite loop and trace into the code introducing a runtime error. For the overflow errors this means you
2299 need to increase the size of the object causing an overflow.
2301 \note Cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
2307 uint32_t osRtxErrorNotify (uint32_t code, void *object_id) {
2311 case osRtxErrorStackUnderflow:
2312 // Stack overflow detected for thread (thread_id=object_id)
2314 case osRtxErrorISRQueueOverflow:
2315 // ISR Queue overflow detected when inserting object (object_id)
2317 case osRtxErrorTimerQueueOverflow:
2318 // User Timer Callback Queue overflow detected for timer (timer_id=object_id)
2320 case osRtxErrorClibSpace:
2321 // Standard C/C++ library libspace not available: increase OS_THREAD_LIBSPACE_NUM
2323 case osRtxErrorClibMutex:
2324 // Standard C/C++ library mutex initialization failed
2335 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2336 osRtxErrorClibMutex /**
2337 \fn void osRtxIdleThread (void *argument);
2339 The function \b osRtxIdleThread is executed by the RTX kernel, when no other threads are ready to run. By default, this
2340 thread is an empty end-less loop that does nothing. It only waits until another task becomes ready to run. You may change the
2341 code of the \b osRtxIdleThread function to put the CPU into a power-saving or idle mode, see \ref TickLess.
2343 The default stack size for this thread is defined in the file RTX_Config.h. Refer to \ref threadConfig.
2345 \note Cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
2351 __NO_RETURN void osRtxIdleThread (void *argument) {