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 - Fixed optimization issue when using GCC optimization level 3.
167 - Minor code optimizations (removed unnecessary checks).
173 - Added Object Memory usage counters.
174 - Added support for additional external configuration file.
175 - Added user configurable names for system threads (Idle and Timer).
176 - Added support for OS sections when using ARMCC5.
177 - Added callback for MPU integration (experimental)
178 - Increased default thread stack sizes to 256 bytes.
179 - Fixed stack context display for running thread in SCVD.
180 - Enhanced MISRA Compliance.
186 - Based on CMSIS-RTOS API V2.1.2.
187 - Added TrustZone Module Identifier configuration for Idle and Timer Thread.
188 - Moved SVC/PendSV handler priority setup from osKernelInitialize to osKernelStart (User Priority Grouping can be updated after osKernelInitialize but before osKernelStart).
189 - Corrected SysTick and PendSV handlers for ARMv8-M Baseline.
190 - Corrected memory allocation for stack and data when "Object specific Memory allocation" configuration is used.
191 - Added support for ARMv8-M IAR compiler.
197 - Corrected IRQ and SVC exception handlers for Cortex-A.
203 - Corrected SysTick and SVC Interrupt Priority for Cortex-M.
209 - Based on CMSIS-RTOS API V2.1.1.
210 - Added support for for Cortex-A.
211 - Using OS Tick API for RTX Kernel Timer Tick.
212 - Fixed potential corruption of terminated threads list.
213 - Corrected MessageQueue to use actual message length (before padding).
214 - Corrected parameters for ThreadEnumerate and MessageQueueInserted events.
215 - Timer Thread creation moved to osKernelStart.
221 - Based on CMSIS-RTOS API V2.1.0.
222 - Added support for Event recording.
223 - Added support for IAR compiler.
224 - Updated configuration files: RTX_Config.h for the configuration settings and RTX_config.c for implementing the \ref rtx5_specific.
225 - osRtx name-space for RTX specific symbols.
231 Initial release compliant to CMSIS-RTOS2.\n
238 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
240 \page genRTOS2IF Generic RTOS Interface
242 CMSIS-RTOS2 is a generic API that is agnostic of the underlying RTOS kernel. Application programmers call CMSIS-RTOS2 API
243 functions in the user code to ensure maximum portability from one RTOS to another. Middleware using CMSIS-RTOS2 API takes
244 advantages of this approach by avoiding unnecessary porting efforts.
246 \image html "API_Structure.png" "CMSIS-RTOS API Structure"
248 A typical CMSIS-RTOS2 API implementation interfaces to an existing real-time kernel. The CMSIS-RTOS2 API provides the
249 following attributes and functionalities:
250 - Function names, identifiers, and parameters are descriptive and easy to understand. The functions are powerful and
251 flexible which reduces the number of functions exposed to the user.
252 - \ref CMSIS_RTOS_ThreadMgmt allows you to define, create, and control threads.
253 - Interrupt Service Routines (ISR) can \ref CMSIS_RTOS_ISR_Calls "call some CMSIS-RTOS functions". When a CMSIS-RTOS
254 function cannot be called from an ISR context, it rejects the invocation and returns an error code.
255 - Three different event types support communication between multiple threads and/or ISR:
256 - \ref CMSIS_RTOS_ThreadFlagsMgmt "Thread Flags": may be used to indicate specific conditions to a thread.
257 - \ref CMSIS_RTOS_EventFlags "Event Flags": may be used to indicate events to a thread or ISR.
258 - \ref CMSIS_RTOS_Message "Messages": can be sent to a thread or an ISR. Messages are buffered in a queue.
259 - \ref CMSIS_RTOS_MutexMgmt and \ref CMSIS_RTOS_SemaphoreMgmt are incorporated.
260 - CPU time can be scheduled with the following functionalities:
261 - A \a timeout parameter is incorporated in many CMSIS-RTOS functions to avoid system lockup. When a timeout is specified,
262 the system waits until a resource is available or an event occurs. While waiting, other threads are scheduled.
263 - The \ref osDelay and \ref osDelayUntil functions put a thread into the \b WAITING state for a specified period of time.
264 - The \ref osThreadYield provides co-operative thread switching and passes execution to another thread of the same
266 - \ref CMSIS_RTOS_TimerMgmt functions are used to trigger the execution of functions.
268 The CMSIS-RTOS2 API is designed to optionally incorporate multi-processor systems and/or access protection via the Cortex-M
269 Memory Protection Unit (MPU).
271 In some RTOS implementations threads may execute on different processors, thus \b message queues may reside in shared memory
274 The CMSIS-RTOS2 API encourages the software industry to evolve existing RTOS implementations. RTOS implementations can be
275 different and optimized in various aspects towards the Cortex-M processors. Optional features may be for example
276 - Support of the Cortex-M Memory Protection Unit (MPU).
277 - Support of multi-processor systems.
278 - Support of a DMA controller.
279 - Deterministic context switching.
280 - Round-robin context switching.
281 - Deadlock avoidance, for example with priority inversion.
282 - Zero interrupt latency by using Armv7-M instructions LDREX and STREX.
284 \section usingOS2 Using a CMSIS-RTOS2 Implementation
286 A CMSIS-RTOS2 implementation is typically provided as a library. To add the RTOS functionality to an existing CMSIS-based
287 application, the RTOS library (and typically one or more configuration files) needs to be added. There is a single new header
288 file %cmsis_os2.h available. This is the only header file required for a completely portable application. In such a case,
289 user provided memory for control blocks, objects data and thread stack cannot be used. Alternatively, you can include an
290 implementation specific header file (for example rtx_os.h) which provides definitions also for resource allocation (such as
291 size of control blocks, required memory for object data and thread stack). This is optional and implies that the application
292 code is not completely portable.
294 \image html "CMSIS_RTOS_Files.png" "CMSIS-RTOS File Structure"
296 Once the files are added to a project, the user can start working with the CMSIS-RTOS functions. A code example is provided
301 /*----------------------------------------------------------------------------
302 * CMSIS-RTOS 'main' function template
303 *---------------------------------------------------------------------------*/
305 #include "RTE_Components.h"
306 #include CMSIS_device_header
307 #include "cmsis_os2.h"
309 /*----------------------------------------------------------------------------
310 * Application main thread
311 *---------------------------------------------------------------------------*/
312 void app_main (void *argument) {
320 // System Initialization
321 SystemCoreClockUpdate();
322 #ifdef RTE_Compiler_EventRecorder
323 // Initialize and start Event Recorder
324 EventRecorderInitialize(EventRecordError, 1U);
328 osKernelInitialize(); // Initialize CMSIS-RTOS
329 osThreadNew(app_main, NULL, NULL); // Create application main thread
330 osKernelStart(); // Start thread execution
336 \section cmsis_os2_h cmsis_os2.h header file
338 The file \b cmsis_os2.h is a standard header file that interfaces to every CMSIS-RTOS2 compliant real-time operating
339 systems (RTOS). Each implementation is provided the same \b cmsis_os2.h which defines the interface to the \ref rtos_api2.
341 Using the \b cmsis_os2.h along with dynamic object allocation allows to create source code or libraries that require no
342 modifications when using on a different CMSIS-RTOS2 implementation.
344 <b>Header file %cmsis_os2.h</b>
350 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
352 \page rtx5_impl RTX v5 Implementation
354 Keil RTX version 5 (RTX5) implements the CMSIS-RTOS2 as a native RTOS interface for Arm Cortex-M processor-based devices.
355 A translation layer to CMSIS-RTOS API v1 is provided. Therefore, RTX5 can be used in applications that where previously based
356 on RTX version 4 and CMSIS-RTOS version 1 with minimal effort.
358 The following sections provide further details:
359 - \subpage cre_rtx_proj explains how to setup an RTX v5 project in Keil MDK.
360 - \subpage theory_of_operation provides general information about the operation of CMSIS-RTOS RTX v5.
361 - \subpage config_rtx5 describes configuration parameters of CMSIS-RTOS RTX v5.
362 - \subpage creating_RTX5_LIB explains how to build your own CMSIS-RTOS RTX v5 library.
363 - \subpage dirstructfiles5 explains the directories and files that are supplied as part of CMSIS-RTOS RTX v5.
364 - \subpage technicalData5 lists microcontroller hardware requirements and limitations such as number of concurrent threads.
365 - \subpage misraCompliance5 describes the violations to the MISRA standard.
368 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
370 \page cre_rtx_proj Create an RTX5 Project
372 The steps to create a microcontroller application using RTX5 are:
373 - Create a new project and select a microcontroller device.
374 - In the Manage Run-Time Environment window, select <b>CMSIS\::CORE</b> and <b>CMSIS\::RTOS2 (API)\::Keil RTX5</b>. You can
375 choose to either add RTX as a library (Variant: \b Library) or to add the full source code (Variant: \b Source - required
376 if using the <a href="http://www.keil.com/pack/doc/compiler/EventRecorder/html/index.html" target="_blank"><b>Event Recorder</b></a>):
378 \image html manage_rte_output.png
380 - If the <b>Validation Output</b> requires other components to be present, try to use the \b Resolve button.
381 - Click \b OK. In the \b Project window, you will see the files that have been automatically added to you project, such as
382 \b %RTX_Config.h, \b %RTX_Config.c, the library or the source code files, as well as the system and startup files:
384 \image html project_window.png
386 - 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).
387 - You can add template files to the project by right-clicking on <b>Source Group 1</b> and selecting
388 <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
389 you will see all available template files for CMSIS-RTOS RTX:
391 \image html add_item.png
393 - \ref config_rtx5 "Configure" RTX5 to the application's needs using the \b %RTX_Config.h file.
395 \section cre_rtx_cortexa Additional requirements for RTX on Cortex-A
397 Cortex-A based microcontrollers are less unified with respect to the interrupt and timer implementations used compared to
398 M-class devices. Thus RTX requires additional components when an A-class device is used, namely
399 <a href="../../Core_A/html/group__irq__ctrl__gr.html"><b>IRQ Controller (API)</b></a> and \ref CMSIS_RTOS_TickAPI "OS Tick (API)"
402 \image html manage_rte_cortex-a.png
404 The default implementations provided along with CMSIS are
405 - Arm <a href="../../Core_A/html/group__GIC__functions.html">Generic Interrupt Controller (GIC)</a>
406 - Arm Cortex-A5, Cortex-A9 <a href="../../Core_A/html/group__PTM__timer__functions.html">Private Timer (PTIM)</a>
407 - Arm Cortex-A7 <a href="../../Core_A/html/group__PL1__timer__functions.html">Generic Physical Timer (GTIM)</a>
409 For devices not implementing GIC, PTIM nor GTIM please refer to the according device family pack and select the
410 proper implementations.
412 \section cre_rtx_proj_specifics Add support for RTX specific functions
413 If you require some of the \ref rtx5_specific "RTX specific functions" in your application code, \#include the
414 \ref rtx_os_h "header file rtx_os.h". This enables \ref lowPower "low-power" and \ref TickLess "tick-less" operation modes.
416 \section cre_rtx_proj_er Add Event Recorder Visibility
417 - To use the Event Recorder together with RTX5, select the software component <b>Compiler:Event Recorder</b>.
418 - Select the \b Source variant of the software component <b>CMSIS:RTOS2 (API):Keil RTX5</b>.
419 \image html event_recorder_rte.png "Component selection for Event Recorder"
420 - Call the function <b>EventRecorderInitialize()</b> in your application code (ideally in \c main()).
421 - Build the application code and download it to the debug hardware.
423 Once the target application generates event information, it can be viewed in the µVision debugger using the \b Event
428 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
430 \page theory_of_operation Theory of Operation
432 Many aspects of the kernel are configurable and the configuration options are mentioned where applicable.
434 \section SystemStartup System Startup
436 Since main is no longer a thread RTX5 does not interfere with the system startup until main is reached.
437 Once the execution reaches \c main() there is a recommended order to initialize the hardware and start the kernel. This is
438 also reflected in the user code template file "CMSIS-RTOS2 'main' function" supplied with the RTX5 component.
440 Your application's \c main() should implement at least the following in the given order:
441 -# Initialization and configuration of hardware including peripherals, memory, pins, clocks and the interrupt system.
442 -# Update the system core clock using the respective
443 <a href=../../Core/html/group__system__init__gr.html>CMSIS-Core (Cortex-M)</a> or
444 <a href=../../Core_A/html/group__system__init__gr.html>CMSIS-Core (Cortex-A)</a> function.
445 -# Initialize the CMSIS-RTOS kernel using \ref osKernelInitialize.
446 -# Optionally, create a new thread \c app_main, which is used as a main thread using \ref osThreadNew. Alternatively, threads
447 can be created in \c main() directly.
448 -# Start the RTOS scheduler using \ref osKernelStart. This function does not return in case of successful execution. Any
449 application code after \b osKernelStart will not be executed unless \b osKernelStart fails.
451 \note Interrupts (like SVC for example) used by the kernel are initialized in \ref osKernelInitialize. In case priorities and
452 groupings in the NVIC are altered by the application after the above sequence it might be necessary to call
453 \ref osKernelInitialize again. You might observe weird misbehaviour possibly catched by \ref osRtxErrorNotify or causing a hard fault.
455 \note The tick timer is configured during \ref osKernelStart. The tick interval is calculated based on the \c SystemCoreClock variable.
459 RTX5 implements a low-latency preemtive scheduler. Major parts of RTX5 are executed in handler mode such as
460 - \ref SysTick_Handler used for time-based scheduling.
461 - \ref SVC_Handler used for lock-based scheduling.
462 - \ref PendSV_Handler used for interrupt-based scheduling.
464 In order to be low-latency with respect to ISR execution those system exceptions are configured to use the
465 lowest priority groups available. The priorities are configured such that no preemption happens between them. Thus
466 no interrupt critical sections (i.e. interrupt locks) are needed to protect the scheduler.
468 \image html scheduling.png "Thread scheduling and interrupt execution"
470 The scheduler combines priority and round-robin based context switches. The example depicted in the image above contains
471 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
472 (\ref osThreadAttr_t::priority). As long as threads 3 and 4 are blocked the scheduler switches between thread 1 and 2 on
473 a time-slice basis (round-robin). The time-slice for round-robin scheduling can be configured, see Round-Robin Timeout in \ref systemConfig.
475 Thread 2 unblocks thread 3 by an arbitrary RTOS-call (executed in SVC handler mode) at time index 2. The scheduler switches to
476 thread 3 immidiately because thread 3 has the highest priority. Thread 4 is still blocked.
478 At time index 4 an interrupt (ISR) occurs and preempts the SysTick_Handler. RTX does not add any latency to the interrupt
479 service execution. The ISR routine uses an RTOS-call that unblocks thread 4. Instead of switching to thread 4 immediately
480 the PendSV flag is set to defer the context switching. The PendSV_Handler is executed right after the SysTick_Handler returns
481 and the defered context switch to thread 4 is carried out. As soon as highest priority thread 4 blocks again by using
482 a blocking RTOS-call execution is switched back to thread 3 immidiately during time index 5.
484 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.
485 At time index 7 the scheduler uses the round-robin mechanism to switch to thread 1 and so on.
487 \section MemoryAllocation Memory Allocation
489 RTX5 objects (thread, mutex, semaphore, timer, message queue, thread and event flags, as well as memory pool) require
490 dedicated RAM memory. Objects can be created using os<i>Object</i>New() calls and deleted using os<i>Object</i>Delete()
491 calls. The related object memory needs to be available during the lifetime of the object.
493 RTX5 offers three different memory allocation methods for objects:
494 - \ref GlobalMemoryPool uses a single global memory pool for all objects. It is easy to configure, but may have
495 the disadvantage for memory fragmentation when objects with different sizes are created and destroyed.
496 - \ref ObjectMemoryPool uses a fixed-size memory pool for each object type. The method is time deterministic
497 and avoids memory fragmentation.
498 - \ref StaticObjectMemory reserves memory during compile time and completely avoids that a system can be out of memory.
499 This is typically a required for some safety critical systems.
501 It possible to intermix all the memory allocation methods in the same application.
503 \subsection GlobalMemoryPool Global Memory Pool
505 The global memory pool allocates all objects from a memory area. This method of memory allocation is the default
506 configuration setting of RTX5.
508 \image html MemAllocGlob.png "Global Memory Pool for all objects"
510 When the memory pool does not provide sufficient memory, the creation of the object fails and the related
511 os<i>Object</i>New() function returns \token{NULL}.
513 Enabled in \ref systemConfig.
515 \subsection ObjectMemoryPool Object-specific Memory Pools
517 Object-specific memory pools avoids memory fragmentation with a dedicated fixed-size memory management for each object type.
518 This type of memory pools are fully time deterministic, which means that object creation and destruction takes always the
519 same fixed amount of time. As a fixed-size memory pool is specific to an object type, the handling of out-of-memory
520 situations is simplified.
522 \image html MemAllocSpec.png "One memory pool per object type"
524 Object-specific memory pools are selectively enabled for each object type, e.g: mutex or thread using the RTX configuration
526 - Enabled in \ref threadConfig for thread objects.
527 - Enabled in \ref timerConfig for timer objects.
528 - Enabled in \ref eventFlagsConfig for event objects.
529 - Enabled in \ref mutexConfig for mutex objects.
530 - Enabled in \ref semaphoreConfig for semaphore.
531 - Enabled in \ref memPoolConfig for memory pools.
532 - Enabled in \ref msgQueueConfig for message objects.
534 When the memory pool does not provide sufficient memory, the creation of the object fails and the related
535 os<i>Object</i>New() function returns \token{NULL}.
537 \subsection StaticObjectMemory Static Object Memory
538 In contrast to the dynamic memory allocations, the static memory allocation requires compile-time allocation of object memory.
540 \image html MemAllocStat.png "Statically allocated memory for all objects"
542 Static memory allocation can be achieved by providing user-defined memory using attributes at object creation,
543 see \ref CMSIS_RTOS_MemoryMgmt_Manual. Please take special note of the following restrictions:
545 Memory type | Requirements
546 ---------------------------------------------|-------------------------------------------------------------------------------
547 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.
548 Thread Stack (osThreadAttr_t::stack_mem) | 8-Byte alignment. Size is application specific, i.e. amount of stack variables and frames.
549 Memory Pool (osMemoryPoolAttr_t::mp_mem) | 4-Byte alignment. Size calculated with \ref osRtxMemoryPoolMemSize.
550 Message Queue (osMessageQueueAttr_t::mq_mem) | 4-Byte alignment. Size calculated with \ref osRtxMessageQueueMemSize.
553 In order to allow RTX5 aware debugging, i.e. Component Viewer, to recognize control blocks these
554 needs to be placed in individual memory sections, i.e. using `__attribute__((section(...)))`.
556 RTX Object | Linker Section
557 --------------|------------------------
558 Thread | `.bss.os.thread.cb`
559 Timer | `.bss.os.timer.cb`
560 Event Flags | `.bss.os.evflags.cb`
561 Mutex | `.bss.os.mutex.cb`
562 Semaphore | `.bss.os.semaphore.cb`
563 Memory Pool | `.bss.os.mempool.cb`
564 Message Queue | `.bss.os.msgqueue.cb`
566 The following code example shows how to create an OS object using static memory.
568 <b> Code Example:</b>
570 /*----------------------------------------------------------------------------
571 * CMSIS-RTOS 'main' function template
572 *---------------------------------------------------------------------------*/
574 #include "RTE_Components.h"
575 #include CMSIS_device_header
576 #include "cmsis_os2.h"
578 //include rtx_os.h for types of RTX objects
581 //The thread function instanced in this example
582 void worker(void *arg)
591 // Define objects that are statically allocated for worker thread 1
592 __attribute__((section(".bss.os.thread.cb")))
593 osRtxThread_t worker_thread_tcb_1;
595 // Reserve two areas for the stacks of worker thread 1
596 // uint64_t makes sure the memory alignment is 8
597 uint64_t worker_thread_stk_1[64];
599 // Define the attributes which are used for thread creation
600 // Optional const saves RAM memory and includes the values in periodic ROM tests
601 const osThreadAttr_t worker_attr_1 = {
604 &worker_thread_tcb_1,
605 sizeof(worker_thread_tcb_1),
606 &worker_thread_stk_1[0],
607 sizeof(worker_thread_stk_1),
608 osPriorityAboveNormal,
612 // Define ID object for thread
615 /*----------------------------------------------------------------------------
616 * Application main thread
617 *---------------------------------------------------------------------------*/
618 void app_main (void *argument) {
619 uint32_t param = NULL;
621 // Create an instance of the worker thread with static resources (TCB and stack)
622 th1 = osThreadNew(worker, ¶m, &worker_attr_1);
628 // System Initialization
629 SystemCoreClockUpdate();
632 osKernelInitialize(); // Initialize CMSIS-RTOS
633 osThreadNew(app_main, NULL, NULL); // Create application main thread
634 osKernelStart(); // Start thread execution
640 \section ThreadStack Thread Stack Management
642 For Cortex-M processors without floating point unit the thread context requires 64 bytes on the local stack.
644 \note For Cortex-M4/M7 with FP the thread context requires 200 bytes on the local stack. For these devices the default stack
645 space should be increased to a minimum of 300 bytes.
647 Each thread is provided with a separate stack that holds the thread context and stack space for automatic variables and
648 return addresses for function call nesting. The stack sizes of RTX threads are flexibly configurable as explained in the
649 section \ref threadConfig. RTX offers a configurable checking for stack overflows and stack utilization.
652 \section lowPower Low-Power Operation
654 The system thread \b osRtxIdleThread can be use to switch the system into a low-power mode. The easiest form to enter a
655 low-power mode is the execution of the \c __WFE function that puts the processor into a sleep mode where it waits for an
660 #include "RTE_Components.h"
661 #include CMSIS_device_header /* Device definitions */
663 void osRtxIdleThread (void) {
664 /* The idle demon is a system thread, running when no other thread is */
668 __WFE(); /* Enter sleep mode */
674 \c __WFE() is not available in every Cortex-M implementation. Check device manuals for availability.
677 \section kernelTimer RTX Kernel Timer Tick
679 RTX uses the generic \ref CMSIS_RTOS_TickAPI to configure and control its periodic Kernel Tick.
681 To use an alternative timer as the Kernel Tick Timer one simply needs to implement a custom version
682 of the \ref CMSIS_RTOS_TickAPI.
684 \note The OS Tick implementation provided must asure that the used timer interrupt uses the same (low) priority group
685 as the service interrupts, i.e. interrupts used by RTX must not preempt each other. Refer to the \ref Scheduler section
688 \subsection TickLess Tick-less Low-Power Operation
690 RTX5 provides extension for tick-less operation which is useful for applications that use extensively low-power modes where
691 the SysTick timer is also disabled. To provide a time-tick in such power-saving modes, a wake-up timer is used to
692 derive timer intervals. The CMSIS-RTOS2 functions \ref osKernelSuspend and \ref osKernelResume control the tick-less
695 Using this functions allows the RTX5 thread scheduler to stop the periodic kernel tick interrupt. When all active threads
696 are suspended, the system enters power-down and calculates how long it can stay in this power-down mode. In the power-down
697 mode the processor and peripherals can be switched off. Only a wake-up timer must remain powered, because this timer is
698 responsible to wake-up the system after the power-down period expires.
700 The tick-less operation is controlled from the \b osRtxIdleThread thread. The wake-up timeout value is set before the system
701 enters the power-down mode. The function \ref osKernelSuspend calculates the wake-up timeout measured in RTX Timer Ticks;
702 this value is used to setup the wake-up timer that runs during the power-down mode of the system.
704 Once the system resumes operation (either by a wake-up time out or other interrupts) the RTX5 thread scheduler is started
705 with the function \ref osKernelResume. The parameter \a sleep_time specifies the time (in RTX Timer Ticks) that the system
706 was in power-down mode.
710 #include "msp.h" // Device header
712 /*----------------------------------------------------------------------------
713 * MSP432 Low-Power Extension Functions
714 *---------------------------------------------------------------------------*/
715 static void MSP432_LP_Entry(void) {
716 /* Enable PCM rude mode, which allows to device to enter LPM3 without waiting for peripherals */
717 PCM->CTL1 = PCM_CTL1_KEY_VAL | PCM_CTL1_FORCE_LPM_ENTRY;
718 /* Enable all SRAM bank retentions prior to going to LPM3 */
719 SYSCTL->SRAM_BANKRET |= SYSCTL_SRAM_BANKRET_BNK7_RET;
720 __enable_interrupt();
721 NVIC_EnableIRQ(RTC_C_IRQn);
722 /* Do not wake up on exit from ISR */
723 SCB->SCR |= SCB_SCR_SLEEPONEXIT_Msk;
724 /* Setting the sleep deep bit */
725 SCB->SCR |= (SCB_SCR_SLEEPDEEP_Msk);
728 static volatile unsigned int tc;
729 static volatile unsigned int tc_wakeup;
731 void RTC_C_IRQHandler(void)
733 if (tc++ > tc_wakeup)
735 SCB->SCR &= ~SCB_SCR_SLEEPONEXIT_Msk;
736 NVIC_DisableIRQ(RTC_C_IRQn);
737 NVIC_ClearPendingIRQ(RTC_C_IRQn);
740 if (RTC_C->PS0CTL & RTC_C_PS0CTL_RT0PSIFG)
742 RTC_C->CTL0 = RTC_C_KEY_VAL; // Unlock RTC key protected registers
743 RTC_C->PS0CTL &= ~RTC_C_PS0CTL_RT0PSIFG;
745 SCB->SCR |= (SCB_SCR_SLEEPDEEP_Msk);
749 uint32_t g_enable_sleep = 0;
751 void osRtxIdleThread (void) {
754 tc_wakeup = osKernelSuspend();
755 /* Is there some time to sleep? */
758 /* Enter the low power state */
762 /* Adjust the kernel ticks with the amount of ticks slept */
769 \c __WFE() is not available in every Arm Cortex-M implementation. Check device manuals for availability.
770 The alternative using \c __WFI() has other issues, please take note of http://www.keil.com/support/docs/3591.htm as well.
772 \section rtx_os_h RTX5 Header File
774 Every implementation of the CMSIS-RTOS2 API can bring its own additional features. RTX5 adds a couple of
775 \ref rtx5_specific "functions" for the idle more, for error notifications, and special system timer functions. It also is
776 using macros for control block and memory sizes.
778 If you require some of the RTX specific functions in your application code, \#include the header file \b %rtx_os.h:
783 \section CMSIS_RTOS_TimeOutValue Timeout Value
785 Timeout values are an argument to several \b osXxx functions to allow time for resolving a request. A timeout value of \b 0
786 means that the RTOS does not wait and the function returns instantly, even when no resource is available. A timeout value of
787 \ref osWaitForever means that the RTOS waits infinitely until a resource becomes available. Or one forces the thread to resume
788 using \ref osThreadResume which is discouraged.
790 The timeout value specifies the number of timer ticks until the time delay elapses. The value is an upper bound and
791 depends on the actual time elapsed since the last timer tick.
794 - timeout value \b 0 : the system does not wait, even when no resource is available the RTOS function returns instantly.
795 - timeout value \b 1 : the system waits until the next timer tick occurs; depending on the previous timer tick, it may be a
796 very short wait time.
797 - timeout value \b 2 : actual wait time is between 1 and 2 timer ticks.
798 - timeout value \ref osWaitForever : system waits infinite until a resource becomes available.
800 \image html TimerValues.png "Example of timeout using osDelay()"
803 \section CMSIS_RTOS_ISR_Calls Calls from Interrupt Service Routines
805 The following CMSIS-RTOS2 functions can be called from threads and Interrupt Service Routines (ISR):
806 - \ref osKernelGetInfo, \ref osKernelGetState,
807 \ref osKernelGetTickCount, \ref osKernelGetTickFreq, \ref osKernelGetSysTimerCount, \ref osKernelGetSysTimerFreq
808 - \ref osThreadFlagsSet
809 - \ref osEventFlagsSet, \ref osEventFlagsClear, \ref osEventFlagsGet, \ref osEventFlagsWait
810 - \ref osSemaphoreAcquire, \ref osSemaphoreRelease, \ref osSemaphoreGetCount
811 - \ref osMemoryPoolAlloc, \ref osMemoryPoolFree, \ref osMemoryPoolGetCapacity, \ref osMemoryPoolGetBlockSize,
812 \ref osMemoryPoolGetCount, \ref osMemoryPoolGetSpace
813 - \ref osMessageQueuePut, \ref osMessageQueueGet, \ref osMessageQueueGetCapacity, \ref osMessageQueueGetMsgSize,
814 \ref osMessageQueueGetCount, \ref osMessageQueueGetSpace
816 Functions that cannot be called from an ISR are verifying the interrupt status and return the status code \b osErrorISR, in
817 case they are called from an ISR context. In some implementations, this condition might be caught using the HARD_FAULT
821 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
823 \page config_rtx5 Configure RTX v5
825 The file "RTX_Config.h" defines the configuration parameters of CMSIS-RTOS RTX and must be part of every project that is
826 using the CMSIS-RTOS RTX kernel. The configuration options are explained in detail in the following sections:
827 - \ref systemConfig covers system-wide settings for the global memory pool, tick frequency, ISR event buffer and round-robin thread switching.
828 - \ref threadConfig provides several parameters to configure the \ref CMSIS_RTOS_ThreadMgmt functions.
829 - \ref timerConfig provides several parameters to configure the \ref CMSIS_RTOS_TimerMgmt functions.
830 - \ref eventFlagsConfig provides several parameters to configure the \ref CMSIS_RTOS_EventFlags functions.
831 - \ref mutexConfig provides several parameters to configure the \ref CMSIS_RTOS_MutexMgmt functions.
832 - \ref semaphoreConfig provides several parameters to configure the \ref CMSIS_RTOS_SemaphoreMgmt functions.
833 - \ref memPoolConfig provides several parameters to configure the \ref CMSIS_RTOS_PoolMgmt functions.
834 - \ref msgQueueConfig provides several parameters to configure the \ref CMSIS_RTOS_Message functions.
836 The file "RTX_Config.c" contains default implementations of the functions \ref osRtxIdleThread and \ref osRtxErrorNotify. Both functions
837 can simply be overwritten with a custimized behavior by redefining them as part of the user code.
839 The configuration file uses <b>Configuration Wizard Annotations</b>. Refer to <b>Pack - Configuration Wizard Annotations</b> for details.
840 Depending on the development tool, the annotations might lead to a more user-friendly graphical representation of the
841 settings. The screenshot below is a screenshot from the µVision \b Configuration \b Wizard view:
843 \image html config_wizard.png "RTX_Config.h in Configuration Wizard View"
845 Alternatively one can provide configuration options using the compiler command line.
847 For example one can customize the used tick frequency to 100us by (overwriting) the configuration using
849 cc -DOS_TICK_FREQ=100
852 \section systemConfig System Configuration
854 The system configuration covers system-wide settings for the global memory pool, tick frequency, ISR event buffer and
855 round-robin thread switching.
857 <b>System Configuration Options</b>
858 \image html config_wizard_system.png "RTX_Config.h: System Configuration"
860 Name | \#define | Description
861 ---------------------------------------|--------------------------|----------------------------------------------------------------
862 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.
863 Kernel Tick Frequency (Hz) | \c OS_TICK_FREQ | Defines base time unit for delays and timeouts in Hz. Default: 1000Hz = 1ms period.
864 Round-Robin Thread switching | \c OS_ROBIN_ENABLE | Enables Round-Robin Thread switching.
865 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]}.
866 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}.
867 Memory Management | \c OS_EVR_MEMORY | Enables Memory Management events recording.
868 Kernel | \c OS_EVR_KERNEL | Enables Kernel events recording.
869 Thread | \c OS_EVR_THREAD | Enables Thread events recording.
870 Timer | \c OS_EVR_TIMER | Enables Timer events recording.
871 Event Flags | \c OS_EVR_EVFLAGS | Enables Event Flags events recording.
872 Mutex | \c OS_EVR_MUTEX | Enables Mutex events recording.
873 Semaphore | \c OS_EVR_SEMAPHORE | Enables Semaphore events recording.
874 Memory Pool | \c OS_EVR_MEMPOOL | Enables Memory Pool events recording.
875 Message Queue | \c OS_EVR_MSGQUEUE | Enables Message Queue events recording.
876 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.
878 \subsection systemConfig_glob_mem Global dynamic memory
879 Refer to \ref GlobalMemoryPool.
882 \subsection systemConfig_rr Round-Robin Thread Switching
884 RTX5 may be configured to use round-robin multitasking thread switching. Round-robin allows quasi-parallel execution of
885 several threads of the \a same priority. Threads are not really executed concurrently, but are scheduled where the available
886 CPU time is divided into time slices and RTX5 assigns a time slice to each thread. Because the time slice is typically short
887 (only a few milliseconds), it appears as though threads execute simultaneously.
889 Round-robin thread switching functions as follows:
890 - the tick is preloaded with the timeout value when a thread switch occurs
891 - the tick is decremented (if not already zero) each system tick if the same thread is still executing
892 - when the tick reaches 0 it indicates that a timeout has occurred. If there is another thread ready with the \a same
893 priority, then the system switches to that thread and the tick is preloaded with timeout again.
895 In other words, threads execute for the duration of their time slice (unless a thread's time slice is given up). Then, RTX
896 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
897 ready to run, the current running thread resumes it execution.
899 \note When switching to higher priority threads, the round-robin timeout value is reset.
901 Round-Robin multitasking is controlled with the <b>\#define OS_ROBIN_ENABLE</b>. The time slice period is configured (in RTX
902 timer ticks) with the <b>\#define OS_ROBIN_TIMEOUT</b>.
905 \subsection systemConfig_isr_fifo ISR FIFO Queue
906 The RTX functions (\ref CMSIS_RTOS_ISR_Calls), when called from and interrupt handler, store the request type and optional
907 parameter to the ISR FIFO queue buffer to be processed later, after the interrupt handler exits.
909 The scheduler is activated immediately after the IRQ handler has finished its execution to process the requests stored to the
910 FIFO queue buffer. The required size of this buffer depends on the number of functions that are called within the interrupt
911 handler. An insufficient queue size will be caught by \b osRtxErrorNotify with error code \b osRtxErrorISRQueueOverflow.
914 \subsection systemConfig_event_recording Event Recording
916 RTX5 fully supports <a href="http://www.keil.com/pack/doc/compiler/EventRecorder/html/index.html" target="_blank">Event Recorder</a>
917 annotations. In this section, you can enable or disable the recording of events for the different elements of RTX5. This
918 leads to reduced data traffic on the debug connection.
920 This setting should be used to disable the generation of messages for a complete family of events. To disable events only for
921 a certain API call, use the \#defines that are available from the rtx_evrt.h header file by adding them manually to the
924 \b Memory \b events \n
925 \c EVR_RTX_MEMORY_INIT_DISABLE, \c EVR_RTX_MEMORY_ALLOC_DISABLE, \c EVR_RTX_MEMORY_FREE_DISABLE,
926 \c EVR_RTX_MEMORY_BLOCK_INIT_DISABLE, \c EVR_RTX_MEMORY_BLOCK_ALLOC_DISABLE, \c EVR_RTX_MEMORY_BLOCK_FREE_DISABLE
928 \b Kernel \b events \n
929 \c EVR_RTX_KERNEL_ERROR_DISABLE, \c EVR_RTX_KERNEL_INITIALIZE_DISABLE, \c EVR_RTX_KERNEL_INITIALIZE_COMPLETED_DISABLE,
930 \c EVR_RTX_KERNEL_GET_INFO_DISABLE, \c EVR_RTX_KERNEL_INFO_RETRIEVED_DISABLE, \c EVR_RTX_KERNEL_GET_STATE_DISABLE,
931 \c EVR_RTX_KERNEL_START_DISABLE, \c EVR_RTX_KERNEL_STARTED_DISABLE, \c EVR_RTX_KERNEL_LOCK_DISABLE,
932 \c EVR_RTX_KERNEL_LOCKED_DISABLE, \c EVR_RTX_KERNEL_UNLOCK_DISABLE, \c EVR_RTX_KERNEL_UNLOCKED_DISABLE,
933 \c EVR_RTX_KERNEL_RESTORE_LOCK_DISABLE, \c EVR_RTX_KERNEL_LOCK_RESTORED_DISABLE, \c EVR_RTX_KERNEL_SUSPEND_DISABLE,
934 \c EVR_RTX_KERNEL_SUSPENDED_DISABLE, \c EVR_RTX_KERNEL_RESUME_DISABLE, \c EVR_RTX_KERNEL_RESUMED_DISABLE,
935 \c EVR_RTX_KERNEL_GET_TICK_COUNT_DISABLE, \c EVR_RTX_KERNEL_GET_TICK_FREQ_DISABLE,
936 \c EVR_RTX_KERNEL_GET_SYS_TIMER_COUNT_DISABLE, \c EVR_RTX_KERNEL_GET_SYS_TIMER_FREQ_DISABLE
938 \b Thread \b events \n
939 \c EVR_RTX_THREAD_ERROR_DISABLE, \c EVR_RTX_THREAD_NEW_DISABLE, \c EVR_RTX_THREAD_CREATED_DISABLE,
940 \c EVR_RTX_THREAD_GET_NAME_DISABLE, \c EVR_RTX_THREAD_GET_ID_DISABLE, \c EVR_RTX_THREAD_GET_STATE_DISABLE,
941 \c EVR_RTX_THREAD_GET_STACK_SIZE_DISABLE, \c EVR_RTX_THREAD_GET_STACK_SPACE_DISABLE, \c EVR_RTX_THREAD_SET_PRIORITY_DISABLE,
942 \c EVR_RTX_THREAD_GET_PRIORITY_DISABLE, \c EVR_RTX_THREAD_YIELD_DISABLE, \c EVR_RTX_THREAD_SUSPEND_DISABLE,
943 \c EVR_RTX_THREAD_SUSPENDED_DISABLE, \c EVR_RTX_THREAD_RESUME_DISABLE, \c EVR_RTX_THREAD_RESUMED_DISABLE,
944 \c EVR_RTX_THREAD_DETACH_DISABLE, \c EVR_RTX_THREAD_DETACHED_DISABLE, \c EVR_RTX_THREAD_JOIN_DISABLE,
945 \c EVR_RTX_THREAD_JOIN_PENDING_DISABLE, \c EVR_RTX_THREAD_JOINED_DISABLE, \c EVR_RTX_THREAD_BLOCKED_DISABLE,
946 \c EVR_RTX_THREAD_UNBLOCKED_DISABLE, \c EVR_RTX_THREAD_PREEMPTED_DISABLE, \c EVR_RTX_THREAD_SWITCHED_DISABLE,
947 \c EVR_RTX_THREAD_EXIT_DISABLE, \c EVR_RTX_THREAD_TERMINATE_DISABLE, \c EVR_RTX_THREAD_DESTROYED_DISABLE,
948 \c EVR_RTX_THREAD_GET_COUNT_DISABLE, \c EVR_RTX_THREAD_ENUMERATE_DISABLE
950 \b Thread \b flag \b events \n
951 \c EVR_RTX_THREAD_FLAGS_SET_DISABLE, \c EVR_RTX_THREAD_FLAGS_SET_DONE_DISABLE, \c EVR_RTX_THREAD_FLAGS_CLEAR_DISABLE,
952 \c EVR_RTX_THREAD_FLAGS_CLEAR_DONE_DISABLE, \c EVR_RTX_THREAD_FLAGS_GET_DISABLE, \c EVR_RTX_THREAD_FLAGS_WAIT_DISABLE,
953 \c EVR_RTX_THREAD_FLAGS_WAIT_PENDING_DISABLE, \c EVR_RTX_THREAD_FLAGS_WAIT_TIMEOUT_DISABLE,
954 \c EVR_RTX_THREAD_FLAGS_WAIT_COMPLETED_DISABLE, \c EVR_RTX_THREAD_FLAGS_WAIT_NOT_COMPLETED_DISABLE
956 \b Generic \b wait \b events \n
957 \c EVR_RTX_THREAD_DELAY_DISABLE, \c EVR_RTX_THREAD_DELAY_UNTIL_DISABLE, \c EVR_RTX_THREAD_DELAY_COMPLETED_DISABLE
959 \b Timer \b events \n
960 \c EVR_RTX_TIMER_ERROR_DISABLE, \c EVR_RTX_TIMER_CALLBACK_DISABLE, \c EVR_RTX_TIMER_NEW_DISABLE,
961 \c EVR_RTX_TIMER_CREATED_DISABLE, \c EVR_RTX_TIMER_GET_NAME_DISABLE, \c EVR_RTX_TIMER_START_DISABLE,
962 \c EVR_RTX_TIMER_STARTED_DISABLE, \c EVR_RTX_TIMER_STOP_DISABLE, \c EVR_RTX_TIMER_STOPPED_DISABLE,
963 \c EVR_RTX_TIMER_IS_RUNNING_DISABLE, \c EVR_RTX_TIMER_DELETE_DISABLE, \c EVR_RTX_TIMER_DESTROYED_DISABLE
965 \b Event \b flag \b events \n
966 \c EVR_RTX_EVENT_FLAGS_ERROR_DISABLE, \c EVR_RTX_EVENT_FLAGS_NEW_DISABLE, \c EVR_RTX_EVENT_FLAGS_CREATED_DISABLE,
967 \c EVR_RTX_EVENT_FLAGS_GET_NAME_DISABLE, \c EVR_RTX_EVENT_FLAGS_SET_DISABLE, \c EVR_RTX_EVENT_FLAGS_SET_DONE_DISABLE,
968 \c EVR_RTX_EVENT_FLAGS_CLEAR_DISABLE, \c EVR_RTX_EVENT_FLAGS_CLEAR_DONE_DISABLE, \c EVR_RTX_EVENT_FLAGS_GET_DISABLE,
969 \c EVR_RTX_EVENT_FLAGS_WAIT_DISABLE, \c EVR_RTX_EVENT_FLAGS_WAIT_PENDING_DISABLE,
970 \c EVR_RTX_EVENT_FLAGS_WAIT_TIMEOUT_DISABLE, \c EVR_RTX_EVENT_FLAGS_WAIT_COMPLETED_DISABLE,
971 \c EVR_RTX_EVENT_FLAGS_WAIT_NOT_COMPLETED_DISABLE, \c EVR_RTX_EVENT_FLAGS_DELETE_DISABLE,
972 \c EVR_RTX_EVENT_FLAGS_DESTROYED_DISABLE
974 \b Mutex \b events \n
975 \c EVR_RTX_MUTEX_ERROR_DISABLE, \c EVR_RTX_MUTEX_NEW_DISABLE, \c EVR_RTX_MUTEX_CREATED_DISABLE,
976 \c EVR_RTX_MUTEX_GET_NAME_DISABLE, \c EVR_RTX_MUTEX_ACQUIRE_DISABLE, \c EVR_RTX_MUTEX_ACQUIRE_PENDING_DISABLE,
977 \c EVR_RTX_MUTEX_ACQUIRE_TIMEOUT_DISABLE, \c EVR_RTX_MUTEX_ACQUIRED_DISABLE, \c EVR_RTX_MUTEX_NOT_ACQUIRED_DISABLE,
978 \c EVR_RTX_MUTEX_RELEASE_DISABLE, \c EVR_RTX_MUTEX_RELEASED_DISABLE, \c EVR_RTX_MUTEX_GET_OWNER_DISABLE,
979 \c EVR_RTX_MUTEX_DELETE_DISABLE, \c EVR_RTX_MUTEX_DESTROYED_DISABLE
981 \b Semaphore \b events \n
982 \c EVR_RTX_SEMAPHORE_ERROR_DISABLE, \c EVR_RTX_SEMAPHORE_NEW_DISABLE, \c EVR_RTX_SEMAPHORE_CREATED_DISABLE,
983 \c EVR_RTX_SEMAPHORE_GET_NAME_DISABLE, \c EVR_RTX_SEMAPHORE_ACQUIRE_DISABLE, \c EVR_RTX_SEMAPHORE_ACQUIRE_PENDING_DISABLE,
984 \c EVR_RTX_SEMAPHORE_ACQUIRE_TIMEOUT_DISABLE, \c EVR_RTX_SEMAPHORE_ACQUIRED_DISABLE,
985 \c EVR_RTX_SEMAPHORE_NOT_ACQUIRED_DISABLE, \c EVR_RTX_SEMAPHORE_RELEASE_DISABLE, \c EVR_RTX_SEMAPHORE_RELEASED_DISABLE,
986 \c EVR_RTX_SEMAPHORE_GET_COUNT_DISABLE, \c EVR_RTX_SEMAPHORE_DELETE_DISABLE, \c EVR_RTX_SEMAPHORE_DESTROYED_DISABLE
988 \b Memory \b pool \b events \n
989 \c EVR_RTX_MEMORY_POOL_ERROR_DISABLE, \c EVR_RTX_MEMORY_POOL_NEW_DISABLE, \c EVR_RTX_MEMORY_POOL_CREATED_DISABLE,
990 \c EVR_RTX_MEMORY_POOL_GET_NAME_DISABLE, \c EVR_RTX_MEMORY_POOL_ALLOC_DISABLE, \c EVR_RTX_MEMORY_POOL_ALLOC_PENDING_DISABLE,
991 \c EVR_RTX_MEMORY_POOL_ALLOC_TIMEOUT_DISABLE, \c EVR_RTX_MEMORY_POOL_ALLOCATED_DISABLE,
992 \c EVR_RTX_MEMORY_POOL_ALLOC_FAILED_DISABLE, \c EVR_RTX_MEMORY_POOL_FREE_DISABLE, \c EVR_RTX_MEMORY_POOL_DEALLOCATED_DISABLE,
993 \c EVR_RTX_MEMORY_POOL_FREE_FAILED_DISABLE, \c EVR_RTX_MEMORY_POOL_GET_CAPACITY_DISABLE,
994 \c EVR_RTX_MEMORY_POOL_GET_BLOCK_SZIE_DISABLE, \c EVR_RTX_MEMORY_POOL_GET_COUNT_DISABLE,
995 \c EVR_RTX_MEMORY_POOL_GET_SPACE_DISABLE, \c EVR_RTX_MEMORY_POOL_DELETE_DISABLE, \c EVR_RTX_MEMORY_POOL_DESTROYED_DISABLE
997 \b Message \b queue \b events \n
998 \c EVR_RTX_MESSAGE_QUEUE_ERROR_DISABLE, \c EVR_RTX_MESSAGE_QUEUE_NEW_DISABLE, \c EVR_RTX_MESSAGE_QUEUE_CREATED_DISABLE,
999 \c EVR_RTX_MESSAGE_QUEUE_GET_NAME_DISABLE, \c EVR_RTX_MESSAGE_QUEUE_PUT_DISABLE,
1000 \c EVR_RTX_MESSAGE_QUEUE_PUT_PENDING_DISABLE, \c EVR_RTX_MESSAGE_QUEUE_PUT_TIMEOUT_DISABLE,
1001 \c EVR_RTX_MESSAGE_QUEUE_INSERT_PENDING_DISABLE, \c EVR_RTX_MESSAGE_QUEUE_INSERTED_DISABLE,
1002 \c EVR_RTX_MESSAGE_QUEUE_NOT_INSERTED_DISABLE, \c EVR_RTX_MESSAGE_QUEUE_GET_DISABLE,
1003 \c EVR_RTX_MESSAGE_QUEUE_GET_PENDING_DISABLE, \c EVR_RTX_MESSAGE_QUEUE_GET_TIMEOUT_DISABLE,
1004 \c EVR_RTX_MESSAGE_QUEUE_RETRIEVED_DISABLE, \c EVR_RTX_MESSAGE_QUEUE_NOT_RETRIEVED_DISABLE,
1005 \c EVR_RTX_MESSAGE_QUEUE_GET_CAPACITY_DISABLE, \c EVR_RTX_MESSAGE_QUEUE_GET_MSG_SIZE_DISABLE,
1006 \c EVR_RTX_MESSAGE_QUEUE_GET_COUNT_DISABLE, \c EVR_RTX_MESSAGE_QUEUE_GET_SPACE_DISABLE,
1007 \c EVR_RTX_MESSAGE_QUEUE_RESET_DISABLE, \c EVR_RTX_MESSAGE_QUEUE_RESET_DONE_DISABLE,
1008 \c EVR_RTX_MESSAGE_QUEUE_DELETE_DISABLE, \c EVR_RTX_MESSAGE_QUEUE_DESTROYED_DISABLE
1011 \subsection systemConfig_usage_counters Object Memory Usage Counters
1013 Object memory usage counters help to evaluate the maximum memory pool requirements for each object type, just like stack
1014 watermarking does for threads. The initial setup starts with a global memory pool for all object types. Consecutive runs of
1015 the application with object memory usage counters enabled, help to introduce object specific memory pools for each object
1016 type. Normally, this is required for applications that require a functional safety certification as global memory pools are
1017 not allowed in this case.
1020 \section threadConfig Thread Configuration
1022 The RTX5 provides several parameters to configure the \ref CMSIS_RTOS_ThreadMgmt functions.
1024 <b>Thread Configuration Options</b>
1025 \image html config_wizard_threads.png "RTX_Config.h: Thread Configuration"
1028 Option | \#define | Description
1029 :--------------------------------------------------------------------------|:-------------------------------|:---------------------------------------------------------------
1030 Object specific Memory allocation | \c OS_THREAD_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1031 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]}.
1032 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]}.
1033 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}.
1034 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}.
1035 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}.
1036 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}.
1037 Stack overrun checking | \c OS_STACK_CHECK | Enable stack overrun checks at thread switch.
1038 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.
1039 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.
1041 \subsection threadConfig_countstack Configuration of Thread Count and Stack Space
1043 The RTX5 kernel uses a separate stack space for each thread and provides two methods for defining the stack requirements:
1044 - <b>Static allocation</b>: when \ref osThreadAttr_t::stack_mem and \ref osThreadAttr_t::stack_size specify a memory area
1045 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.
1046 - <b>Dynamic allocation</b>: when \ref osThreadAttr_t is NULL or \ref osThreadAttr_t::stack_mem is NULL, the system
1047 allocates the stack memory from:
1048 - Object-specific Memory Pool (default Stack size) when "Object specific Memory allocation" is enabled and "Number of
1049 user Threads with default Stack size" is not \token{0} and \ref osThreadAttr_t::stack_size is \token{0} (or
1050 \ref osThreadAttr_t is NULL).
1051 - Object-specific Memory Pool (user-provided Stack size) when "Object specific Memory allocation" is enabled and "Total
1052 Stack size for user..." is not \token{0} and \ref osThreadAttr_t::stack_size is not \token{0}.
1053 - Global Memory Pool when "Object specific Memory allocation" is disabled or (\ref osThreadAttr_t::stack_size is not
1054 \token{0} and "Total Stack size for user..." is \token{0}) or (\ref osThreadAttr_t::stack_size is \token{0} and
1055 "Number of user Threads with default Stack size" is \token{0}).
1057 \ref osThreadAttr_t is a parameter of the function \ref osThreadNew.
1060 Before the RTX kernel is started by the \ref osKernelStart() function, the main stack defined in startup_<i>device</i>.s is
1061 used. The main stack is also used for:
1062 - user application calls to RTX functions in \b thread \b mode using SVC calls
1063 - interrupt/exception handlers.
1065 \subsection threadConfig_ovfcheck Stack Overflow Checking
1066 RTX5 implements a software stack overflow checking that traps stack overruns. Stack is used for return addresses and
1067 automatic variables. Extensive usage or incorrect stack configuration may cause a stack overflow. Software stack overflow
1068 checking is controlled with the define \c OS_STACK_CHECK.
1070 If a stack overflow is detected, the function \b osRtxErrorNotify with error code \b osRtxErrorStackUnderflow is called. By
1071 default, this function is implemented as an endless loop and will practically stop code execution.
1073 \subsection threadConfig_watermark Stack Usage Watermark
1074 RTX5 initializes thread stack with a watermark pattern (0xCC) when a thread is created. This allows the debugger to determine
1075 the maximum stack usage for each thread. It is typically used during development but removed from the final application.
1076 Stack usage watermark is controlled with the define \c OS_STACK_WATERMARK.
1078 Enabling this option significantly increases the execution time of \ref osThreadNew (depends on thread stack size).
1080 \subsection threadConfig_procmode Processor Mode for Thread Execution
1081 RTX5 allows to execute threads in unprivileged or privileged processor mode. The processor mode is controlled with the
1082 define \c OS_PRIVILEGE_MODE.
1084 In \b unprivileged processor mode, the application software:
1085 - has limited access to the MSR and MRS instructions, and cannot use the CPS instruction.
1086 - cannot access the system timer, NVIC, or system control block.
1087 - might have restricted access to memory or peripherals.
1089 In \b privileged processor mode, the application software can use all the instructions and has access to all resources.
1092 \section timerConfig Timer Configuration
1094 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_TimerMgmt functions.
1096 <b>Timer Configuration Options</b>
1097 \image html config_wizard_timer.png "RTX_Config.h: Timer Configuration"
1099 Name | \#define | Description
1100 ---------------------------------------|--------------------------------|----------------------------------------------------------------
1101 Object specific Memory allocation | \c OS_TIMER_OBJ_MEM | Enables object specific memory allocation.
1102 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]}.
1103 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}
1104 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}.
1105 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}.
1106 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]}.
1108 \subsection timerConfig_obj Object-specific memory allocation
1109 See \ref ObjectMemoryPool.
1111 \subsection timerConfig_user User Timer Thread
1112 The RTX5 function \b osRtxTimerThread executes callback functions when a time period expires. The priority of the timer
1113 subsystem within the complete RTOS system is inherited from the priority of the \b osRtxTimerThread. This is configured by
1114 \c OS_TIMER_THREAD_PRIO. Stack for callback functions is supplied by \b osRtxTimerThread. \c OS_TIMER_THREAD_STACK_SIZE must
1115 satisfy the stack requirements of the callback function with the highest stack usage.
1118 \section eventFlagsConfig Event Flags Configuration
1120 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_EventFlags functions.
1122 <b>Event Configuration Options</b>
1123 \image html config_wizard_eventFlags.png "RTX_Config.h: Event Flags Configuration"
1125 Name | \#define | Description
1126 ---------------------------------------|--------------------------|----------------------------------------------------------------
1127 Object specific Memory allocation | \c OS_EVFLAGS_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1128 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]}.
1130 \subsection eventFlagsConfig_obj Object-specific memory allocation
1131 When object-specific memory is used, the pool size for all Event objects is specified by \c OS_EVFLAGS_NUM. Refer to
1132 \ref ObjectMemoryPool.
1135 \section mutexConfig Mutex Configuration
1136 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_MutexMgmt functions.
1138 <b>Mutex Configuration Options</b>
1139 \image html config_wizard_mutex.png "RTX_Config.h: Mutex Configuration"
1142 Name | \#define | Description
1143 ---------------------------------------|--------------------------|----------------------------------------------------------------
1144 Object specific Memory allocation | \c OS_MUTEX_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1145 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]}.
1147 \subsection mutexConfig_obj Object-specific Memory Allocation
1148 When object-specific memory is used, the pool size for all Mutex objects is specified by \c OS_MUTEX_NUM. Refer to
1149 \ref ObjectMemoryPool.
1152 \section semaphoreConfig Semaphore Configuration
1154 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_SemaphoreMgmt functions.
1156 <b>Semaphore Configuration Options</b>
1157 \image html config_wizard_semaphore.png "RTX_Config.h: Semaphore Configuration"
1160 Name | \#define | Description
1161 ---------------------------------------|--------------------------|----------------------------------------------------------------
1162 Object specific Memory allocation | \c OS_SEMAPHORE_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1163 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]}.
1165 \subsection semaphoreConfig_obj Object-specific memory allocation
1166 When Object-specific Memory is used, the pool size for all Semaphore objects is specified by \c OS_SEMAPHORE_NUM. Refer to
1167 \ref ObjectMemoryPool.
1170 \section memPoolConfig Memory Pool Configuration
1172 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_PoolMgmt functions.
1174 <b>Memory Pool Configuration Options</b>
1175 \image html config_wizard_memPool.png "RTX_Config.h: Memory Pool Configuration"
1177 Name | \#define | Description
1178 ---------------------------------------|--------------------------|----------------------------------------------------------------
1179 Object specific Memory allocation | \c OS_MEMPOOL_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1180 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]}.
1181 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}.
1183 \subsection memPoolConfig_obj Object-specific memory allocation
1184 When object-specific memory is used, the number of pools for all MemoryPool objects is specified by \c OS_MEMPOOL_NUM. The
1185 total storage size reserved for all pools is configured in \c OS_MEMPOOL_DATA_SIZE. Refer to \ref ObjectMemoryPool.
1188 \section msgQueueConfig Message Queue Configuration
1190 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_Message functions.
1192 <b>MessageQueue Configuration Options</b>
1193 \image html config_wizard_msgQueue.png "RTX_Config.h: Message Queue Configuration"
1195 Name | \#define | Description
1196 ---------------------------------------|--------------------------|----------------------------------------------------------------
1197 Object specific Memory allocation | \c OS_MSGQUEUE_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1198 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]}.
1199 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}.
1201 \subsection msgQueueConfig_obj Object-specific memory allocation
1202 When Object-specific Memory is used, the number of queues for all Message Queue objects is specified by \c OS_MSGQUEUE_NUM.
1203 The total storage size reserved for all queues is configured in \c OS_MSGQUEUE_DATA_SIZE. Refer to \ref ObjectMemoryPool.
1207 /* ========================================================================================================================== */
1209 \page creating_RTX5_LIB Building the RTX5 Library
1211 The CMSIS Pack contains a µVision project for building the complete set of RTX5 libraries. This project can also be used as
1212 a reference for building the RTX5 libraries using a tool-chain of your choice.
1214 -# Open the project \b RTX_CM.uvprojx from the pack folder <b>CMSIS/RTOS2/RTX/Library/ARM/MDK</b> in µVision.
1215 -# Select the project target that matches your device's processor core.
1216 \n The project provides target configuration for all supported Cortex-M targets supported by RTX5.
1217 -# You can find out about the required preprocessor defines in the dialogs <b>Options for Target - C/C++</b> and
1218 <b>Options for Target - Asm</b>. Note the need to use at least the C99 compiler mode when building RTX from source.
1219 -# From the <b>Project</b> window you find the list of source files required for a complete library build.
1220 -# Build the library of your choice using \b Project - \b Build \b Target (or press F7).
1222 \image html own_lib_projwin.png "Project with files for Armv8-M Mainline"
1226 /* ========================================================================================================================== */
1228 \page dirstructfiles5 Directory Structure and File Overview
1230 The following section provides an overview of the directory structure and the files that are relevant for the user's for
1231 CMSIS-RTOS RTX v5. The following directory references start below the CMSIS pack installation path, for example
1232 ARM/CMSIS/<i>version</i>/CMSIS/RTOS2.
1234 \section Folders RTX v5 Directory Structure
1236 The CMSIS-RTOS RTX v5 is delivered in source code and several examples are provided.
1238 <table class="cmtable" summary="CMSIS-RTOS RTX Library Files">
1245 <td>The include file for CMSIS-RTOS API v2. cmsis_os2.h is the central include file for user applications.</td>
1249 <td>CMSIS-RTOS API template source and header file.</td>
1253 <td>Directory with RTX specific files and folders. Also contains the component viewer description file.</td>
1257 <td>CMSIS-RTOS RTX configuration files %RTX_Config.h and %RTX_Config.c.</td>
1260 <td>RTX/Examples</td>
1261 <td>Example projects that can be directly used in development tools.</td>
1264 <td>RTX/Include</td>
1265 <td>RTX v5 specific include files.</td>
1268 <td>RTX/Include1</td>
1269 <td>CMSIS-RTOS v1 API header file.</td>
1272 <td>RTX/Library</td>
1273 <td>Pre-built libraries (see next table for details).</td>
1277 <td>Source code that can be used with ARMCC and GCC.</td>
1280 <td>RTX/Template</td>
1281 <td>User code templates for creating application projects with CMSIS-RTOS RTX v5.</td>
1285 \section libFiles RTX v5 Library Files
1287 The CMSIS-RTOS RTX Library is available pre-compiled for ARMCC and GCC compilers and supports all Cortex-M
1288 processor variants in every configuration, including Arm Cortex-M23 and Cortex-M33.
1290 <table class="cmtable" summary="CMSIS-RTOS RTX Library Files">
1292 <th>Library File</th>
1293 <th>Processor Configuration</th>
1296 <td>Library/ARM/RTX_CM0.lib</td>
1297 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Cortex-M0 and M1, little-endian.</td>
1300 <td>Library/ARM/RTX_CM3.lib</td>
1301 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Cortex-M3, M4, and M7 without FPU, little-endian.</td>
1304 <td>Library/ARM/RTX_CM4F.lib</td>
1305 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Cortex-M4 and M7 with FPU, little-endian.</td>
1308 <td>Library/ARM/RTX_V8MB.lib</td>
1309 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Armv8-M Baseline.</td>
1312 <td>Library/ARM/RTX_V8MBN.lib</td>
1313 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Armv8-M Baseline, non-secure.</td>
1316 <td>Library/ARM/RTX_V8MM.lib</td>
1317 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Armv8-M Mainline.</td>
1320 <td>Library/ARM/RTX_V8MMF.lib</td>
1321 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Armv8-M Mainline with FPU.</td>
1324 <td>Library/ARM/RTX_V8MMFN.lib</td>
1325 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Armv8-M Mainline with FPU, non-secure.</td>
1328 <td>Library/ARM/RTX_V8MMN.lib</td>
1329 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Armv8-M Mainline, non-secure.</td>
1332 <td>Library/GCC/libRTX_CM0.a</td>
1333 <td>CMSIS-RTOS libRTX Library for GCC Compiler, Cortex-M0 and M1, little-endian.</td>
1336 <td>Library/GCC/libRTX_CM3.a</td>
1337 <td>CMSIS-RTOS libRTX Library for GCC Compiler, Cortex-M3, M4, and M7 without FPU, little-endian.</td>
1340 <td>Library/GCC/libRTX_CM4F.a</td>
1341 <td>CMSIS-RTOS libRTX Library for GCC Compiler, Cortex-M4 and M7 with FPU, little-endian.</td>
1344 <td>Library/GCC/libRTX_V8MB.a</td>
1345 <td>CMSIS-RTOS libRTX Library for GCC Compiler, Armv8-M Baseline.</td>
1348 <td>Library/GCC/libRTX_V8MBN.a</td>
1349 <td>CMSIS-RTOS libRTX Library for GCC Compiler, Armv8-M Baseline, non-secure.</td>
1352 <td>Library/GCC/libRTX_V8MM.a</td>
1353 <td>CMSIS-RTOS libRTX Library for GCC Compiler, Armv8-M Mainline.</td>
1356 <td>Library/GCC/libRTX_V8MMF.a</td>
1357 <td>CMSIS-RTOS libRTX Library for GCC Compiler, Armv8-M Mainline with FPU.</td>
1360 <td>Library/GCC/libRTX_V8MMFN.a</td>
1361 <td>CMSIS-RTOS libRTX Library for GCC Compiler, Armv8-M Mainline with FPU, non-secure.</td>
1364 <td>Library/GCC/libRTX_V8MMN.a</td>
1365 <td>CMSIS-RTOS libRTX Library for GCC Compiler, Armv8-M Mainline, non-secure.</td>
1370 /* ========================================================================================================================== */
1372 \page technicalData5 Technical Data
1374 \section technicalData_Toolchains Supported Toolchains
1376 Keil RTX5 is developed and tested using the common toolchains and development environments.
1378 \subsection technicalData_Toolchain_ARM Arm Compiler (Arm/Keil MDK, uVision5)
1380 Major parts of RTX5 are developed and optimized using Arm Compiler and Arm/Keil MDK.
1381 The current release is tested with the following versions:
1383 <li>Arm Compiler 5.06 Update 6</li>
1384 <li>Arm Compiler 6.6.2 (Long Term Maintenance)</li>
1385 <li>Arm Compiler 6.9</li>
1386 <li>RTOS-aware debugging with uVision 5.24</li>
1389 \subsection technicalData_Toolchain_IAR IAR Embedded Workbench
1391 RTX5 has been ported to fully support IAR Embedded Workbench. The following releases are known to work:
1393 <li>IAR Embedded Workbench 7.7 (<a href="https://github.com/ARM-software/CMSIS_5/issues/201">community report</a>)</li>
1394 <li>IAR Embedded Workbench 7.80.4</li>
1395 <li><b>IAR Embedded Workbench 8.20.1</b></li>
1398 \subsection technicalData_Toolchain_GCC GNU Compiler Collection
1400 RTX5 has also been ported to support GCC, maintenance mainly relays on community contribution.
1401 Active development is currently tested with:
1403 <li>GNU Tools for Arm Embedded 6.3.1 20170620</li>
1406 \section technicalData5_ControlBlockSizes Control Block Sizes
1408 Keil RTX5 specific control block definitions (including sizes) as well as memory pool and message queue memory requirements
1409 are defined in the RTX5 header file:
1412 /// Control Block sizes
1413 #define osRtxThreadCbSize sizeof(osRtxThread_t)
1414 #define osRtxTimerCbSize sizeof(osRtxTimer_t)
1415 #define osRtxEventFlagsCbSize sizeof(osRtxEventFlags_t)
1416 #define osRtxMutexCbSize sizeof(osRtxMutex_t)
1417 #define osRtxSemaphoreCbSize sizeof(osRtxSemaphore_t)
1418 #define osRtxMemoryPoolCbSize sizeof(osRtxMemoryPool_t)
1419 #define osRtxMessageQueueCbSize sizeof(osRtxMessageQueue_t)
1421 /// Memory size in bytes for Memory Pool storage.
1422 /// \param block_count maximum number of memory blocks in memory pool.
1423 /// \param block_size memory block size in bytes.
1424 #define osRtxMemoryPoolMemSize(block_count, block_size) \
1425 (4*(block_count)*(((block_size)+3)/4))
1427 /// Memory size in bytes for Message Queue storage.
1428 /// \param msg_count maximum number of messages in queue.
1429 /// \param msg_size maximum message size in bytes.
1430 #define osRtxMessageQueueMemSize(msg_count, msg_size) \
1431 (4*(msg_count)*(3+(((msg_size)+3)/4)))
1434 If you are using a \ref GlobalMemoryPool to allocate memory for the RTOS objects, you need to know the size that is required
1435 for each object in case of errors. Currently, the control block sizes are as follows (subject to change without
1438 Type | Control block size in bytes |
1439 --------------|:---------------------------:|
1446 Message Queue | 52 |
1448 The size of the memory that is required for memory pool and message queue data storage can be determined from the macros
1452 /* ========================================================================================================================== */
1454 \page CodingRules Coding Rules
1456 - prefix osXxxx, os_xxx, osRtx
1461 /* ========================================================================================================================== */
1463 \page misraCompliance5 MISRA C:2012 Compliance
1464 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.
1466 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.
1467 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.
1468 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.
1470 \image html "PC-Lint.png" "Running PC-Lint within MDK - uVision"
1472 The PC-Lint configuration uses the following Options under <b>Tools - PC-Lint Setup...</b>:
1473 - Config File: co-ARMCC-6.lnt (20-Mar-2017) with additional options:
1476 -esym(526,__builtin_*) -esym(628,__builtin_*)
1477 -sem(__builtin_clz, pure)
1478 +doffsetof(t,m)=((size_t)&((t*)0)->m) -emacro((413,923,9078),offsetof)
1479 -ecall(534,__disable_irq)
1481 - Included Project Information:
1482 - Enable: Add 'Include' paths
1483 - Enable: Add 'Software Packs' paths
1484 - Enable: Verify 'Software Packs' includes
1485 - Enable: Add 'Preprocessor' symbols
1486 - Enable: Add 'Define' symbols
1487 - MISRA Rules Setup and Configuration:
1488 - MISRQ_C_2012_Config.lnt; all rules enabled
1489 - includes definition file: au-misra3.lnt (12-Jun-2014)
1490 - Additional Lint Commands (for both single and mutiple files):
1492 - emacro(835,osRtxConfigPrivilegedMode)
1495 The C source code is annotated with PC-Lint control comments to allows MISRA deviations.
1496 These deviations with the underlaying design decisions are described in the following.
1501 The RTX source code has the following deviations from MISRA:
1516 All source code deviations are clearly marked and in summary these deviations affect the following MISRA rules:
1517 - [MISRA 2012 Directive 4.9, advisory]: A function should be used in preference to a function-like macro where yet are interchangeable
1518 - [MISRA 2012 Rule 1.3, required]: There shall be no occurrence of undefined or critical unspecified behavior
1519 - [MISRA 2012 Rule 10.3, required]: Expression assigned to a narrower or different essential type
1520 - [MISRA 2012 Rule 10.5, advisory]: Impermissible cast; cannot cast from 'essentially unsigned' to 'essentially enum\<i\>'
1521 - [MISRA 2012 Rule 11.1, required]: Conversions shall not be performed between a pointer to a function and any other type
1522 - [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
1523 - [MISRA 2012 Rule 11.4, advisory]: A conversion should not be performed between a pointer to object and an integer type
1524 - [MISRA 2012 Rule 11.5, advisory]: A conversion should not be performed from pointer to void into pointer to object
1525 - [MISRA 2012 Rule 11.6, required]: A cast shall not be performed between pointer to void and an arithmetic type
1526 - [MISRA 2012 Rule 15.5, advisory]: A function should have a single point of exit at the end
1527 - [MISRA 2012 Rule 20.10, advisory]: The # and ## preprocessor operators should not be used
1529 In the following all deviations are described in detail.
1531 \section MISRA_1 [MISRA Note 1]: Return statements for parameter checking
1533 Return statements are used at the beginning of several functions to validate parameter values and object states.
1534 The function returns immediately without any side-effects and typically an error status is set. This structure
1535 keeps the source code better structured and easier to understand.
1537 This design decision implies the following MISRA deviation:
1538 - [MISRA 2012 Rule 15.5, advisory]: A function should have a single point of exit at the end
1540 All locations in the source code are marked with:
1542 //lint -e{904} "Return statement before end of function" [MISRA Note 1]
1546 \section MISRA_2 [MISRA Note 2]: Object identifiers are void pointers
1548 CMSIS-RTOS is independant of an underlying RTOS implementation. The object idenifiers are therefore defined as void pointers to:
1549 - allow application programs that are agnostic from an underlying RTOS implementation.
1550 - avoid accidently accesses an RTOS control block from an application program.
1552 This design decisions imply the following MISRA deviations:
1553 - [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
1554 - [MISRA 2012 Rule 11.5, advisory]: A conversion should not be performed from pointer to void into pointer to object
1556 All locations in the source code are marked with:
1558 //lint -e{9079} -e{9087} "cast from pointer to void to pointer to object type" [MISRA Note 2]
1561 In the RTX5 implementation the requried pointer conversions are implemented in the header file rtx_lib.h with the following inline functions:
1564 osRtxThread_t *osRtxThreadId (osThread_t thread_id);
1565 osRtxTimer_t *osRtxTimerId (osTimer_t timer_id);
1566 osRtxEventFlags_t *osRtxEventFlagsId (osEventFlags_t ef_id);
1567 osRtxMutex_t *osRtxMutexId (osMutex_t mutex_id);
1568 osRtxSemaphore_t *osRtxSemaphoreId (osSemaphore_t semaphore_id);
1569 osRtxMemoryPool_t *osRtxMemoryPoolId (osMemoryPoolId_t mp_id);
1570 osRtxMessageQueue_t *osRtxMessageQueueId(osMessageQueueId_t mq_id);
1573 \section MISRA_3 [MISRA Note 3]: Conversion to unified object control blocks
1575 RTX uses a unified object control block structure that contains common object members.
1576 The unified control blocks use a fixed layout at the beginning of the sturcture and starts always with an object identifier.
1577 This allows common object functions that receive a pointer to a unified object control block and reference only the
1578 pointer or the members in the fixed layout. Using common object functions and data (for example the ISR queue) reduces
1579 code complexity and keeps the source code better structured. Refer also to \ref MISRA_4
1581 This design decisions imply the following MISRA deviations:
1582 - [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
1583 - [MISRA 2012 Rule 11.5, advisory]: A conversion should not be performed from pointer to void into pointer to object
1585 All locations in the source code are marked with:
1587 //lint -e{9079} -e{9087} "cast from pointer to void to pointer to object type" [MISRA Note 3]
1591 In the RTX5 implementation the requried pointer conversions are implemented in the header file \em rtx_lib.h with the following inline function:
1594 osRtxObject_t *osRtxObject (void *object);
1598 \section MISRA_4 [MISRA Note 4]: Conversion from unified object control blocks
1600 RTX uses a unified object control block structure that contains common object members. Refer to \ref MISRA_3 for more information.
1601 To process specifc control block data, pointer conversions are required.
1603 This design decisions imply the following MISRA deviations:
1604 - [MISRA 2012 Rule 1.3, required]: There shall be no occurrence of undefined or critical unspecified behavior
1605 - [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
1606 In addition PC-Lint issues:
1607 - Info 826: Suspicious pointer-to-pointer conversion (area too small)
1609 All locations in the source code are marked with:
1611 //lint -e{740} -e{826} -e{9087} "cast from pointer to generic object to specific object" [MISRA Note 4]
1614 In the RTX5 source code the requried pointer conversions are implemented in the header file \em rtx_lib.h with the following inline functions:
1617 osRtxThread_t *osRtxThreadObject (osRtxObject_t *object);
1618 osRtxTimer_t *osRtxTimerObject (osRtxObject_t *object);
1619 osRtxEventFlags_t *osRtxEventFlagsObject (osRtxObject_t *object);
1620 osRtxMutex_t *osRtxMutexObject (osRtxObject_t *object);
1621 osRtxSemaphore_t *osRtxSemaphoreObject (osRtxObject_t *object);
1622 osRtxMemoryPool_t *osRtxMemoryPoolObject (osRtxObject_t *object);
1623 osRtxMessageQueue_t *osRtxMessageQueueObject (osRtxObject_t *object);
1624 osRtxMessage_t *osRtxMessageObject (osRtxObject_t *object);
1627 \section MISRA_5 [MISRA Note 5]: Conversion to object types
1629 The RTX5 kernel has common memory management functions that use void pointers. These memory allocation fuctions returns
1630 a void pointer which is correctly aligned for object types.
1632 This design decision implies the following MISRA deviations:
1633 - [MISRA 2012 Rule 11.5, advisory]: A conversion should not be performed from pointer to void into pointer to object
1635 All locations in the source code are marked with:
1637 //lint -e{9079} "conversion from pointer to void to pointer to other type" [MISRA Note 5]
1643 os_thread_t *thread;
1645 //lint -e{9079} "conversion from pointer to void to pointer to other type" [MISRA Note 5]
1646 thread = osRtxMemoryPoolAlloc(osRtxInfo.mpi.thread);
1651 \section MISRA_6 [MISRA Note 6]: Conversion from user provided storage
1653 CMSIS-RTOS2 and RTX5 support user provided storage for object control blocks, stack, and data storage.
1654 The API uses void pointers to define the location of this user provided storage. It is therefore
1655 required to cast the void pointer to underlying storage types. Alignment restrictions of user provided storage
1656 are checked before accessing memory. Refer also to \ref MISRA_7.
1658 This design decisions imply the following MISRA deviations:
1659 - [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
1660 - [MISRA 2012 Rule 11.5, advisory]: A conversion should not be performed from pointer to void into pointer to object
1662 All locations in the source code are marked with:
1664 //lint -e{9079} "conversion from pointer to void to pointer to other type" [MISRA Note 6]
1669 static osTimerId_t svcRtxTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr) {
1674 //lint -e{9079} "conversion from pointer to void to pointer to other type" [MISRA Note 6]
1675 timer = attr->cb_mem;
1679 \section MISRA_7 [MISRA Note 7]: Check for proper pointer alignment
1681 RTX5 verifies the alignment of user provided storage for object control blocks, stack, and data storage.
1682 Refer also to \ref MISRA_6 for more information.
1684 This design decision implies the following MISRA deviations:
1685 - [MISRA 2012 Rule 11.4, advisory]: A conversion should not be performed between a pointer to object and an integer type
1686 - [MISRA 2012 Rule 11.6, required]: A cast shall not be performed between pointer to void and an arithmetic type
1688 All locations in the source code are marked with:
1690 //lint -e(923) -e(9078) "cast from pointer to unsigned int" [MISRA Note 7]
1695 static osThreadId_t svcRtxThreadNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr) {
1699 if (stack_mem != NULL) {
1700 //lint -e(923) -e(9078) "cast from pointer to unsigned int" [MISRA Note 7]
1701 if ((((uint32_t)stack_mem & 7U) != 0U) || (stack_size == 0U)) {
1705 \section MISRA_8 [MISRA Note 8]: Memory allocation management
1707 RTX5 implements memory allocation functions which require pointer arithmetic to manage memory.
1708 The structure with the type \em mem_block_t that is used to menage memory allocation blocks is defined in \em rtx_memory.c
1710 This design decision implies the following MISRA deviations:
1711 - [MISRA 2012 Rule 11.4, advisory]: A conversion should not be performed between a pointer to object and an integer type
1712 - [MISRA 2012 Rule 11.6, required]: A cast shall not be performed between pointer to void and an arithmetic type
1714 All locations in the source code are marked with:
1716 //lint -e(923) -e(9078) "cast from pointer to unsigned int" [MISRA Note 8]
1719 The required pointer arithmetic is implemented in \em rtx_memory.c with the following function:
1721 __STATIC_INLINE mem_block_t *MemBlockPtr (void *mem, uint32_t offset) {
1725 //lint --e{923} --e{9078} "cast between pointer and unsigned int" [MISRA Note 8]
1726 addr = (uint32_t)mem + offset;
1727 ptr = (mem_block_t *)addr;
1733 \section MISRA_9 [MISRA Note 9]: Pointer conversions for register access
1735 The CMSIS-Core peripheral register blocks are accessed using a structure. The memory address of this structure
1736 is specified as unsigned integer number. Pointer conversions are required to access the specific registers.
1738 This design decision implies the following MISRA deviations:
1739 - [MISRA 2012 Rule 11.4, advisory]: A conversion should not be performed between a pointer to object and an integer type
1740 - [MISRA 2012 Rule 11.6, required]: A cast shall not be performed between pointer to void and an arithmetic type
1742 All locations in the source code are marked with:
1744 //lint -emacro((923,9078),SCB) "cast from unsigned long to pointer" [MISRA Note 9]
1750 #define SCS_BASE (0xE000E000UL)
1751 #define SCB ((SCB_Type *)SCB_BASE)
1752 typedef struct {...} SCB_Type;
1757 \section MISRA_10 [MISRA Note 10]: SVC calls use function-like macros
1759 RTX5 is using SVC (Service Calls) to switch between thread mode (for user code execution) and handler mode (for RTOS kernel execution).
1760 The SVC function call mechanism is implemented with assembly instructions to construct the code for SVC.
1761 The source code uses C macros and are designed as C function-like macros to generate parameter passing
1762 for variables depending on macro parameters. An alternative replacement code would be complex.
1763 The C macros use multiple '##' operators however it has been verified that the order of evaluation is irrelevant
1764 and result of macro expansion is always predictable.
1766 This design decision implies the following MISRA deviations:
1767 - [MISRA 2012 Directive 4.9, advisory]: A function should be used in preference to a function-like macro where yet are interchangeable
1768 - [MISRA 2012 Rule 1.3, required]: There shall be no occurrence of undefined or critical unspecified behavior
1769 - [MISRA 2012 Rule 20.10, advisory]: The # and ## preprocessor operators should not be used
1771 The relevant source code is in the file \em rtx_core_cm.h and is marked with:
1773 //lint -save -e9023 -e9024 -e9026 "Function-like macros using '#/##'" [MISRA Note 10]
1777 \section MISRA_11 [MISRA Note 11]: SVC calls use assembly code
1779 The SVC (Service Call) functions are constructed as a mix of C and inline assembly as it is required to access CPU registers
1780 for parameter passing. The function parameters are mapped to the CPU registers R0..R3 and SVC function number to
1781 CPU register R12 (or R7). For assembly inter-working the function parameters are casted to unsigned int values.
1783 The function return value after SVC call is mapped to the CPU register R0. Return value is casted from unsigned int
1784 to the target value.
1786 It has been verified that this method has has no side-effects and is well defined.
1788 This design decision implies the following MISRA deviations:
1789 - [MISRA 2012 Rule 10.3, required]: Expression assigned to a narrower or different essential type
1790 - [MISRA 2012 Rule 10.5, advisory]: Impermissible cast; cannot cast from 'essentially unsigned' to 'essentially enum\<i\>'
1791 - [MISRA 2012 Rule 11.1, required]: Conversions shall not be performed between a pointer to a function and any other type
1792 - [MISRA 2012 Rule 11.4, advisory]: A conversion should not be performed between a pointer to object and an integer type
1793 - [MISRA 2012 Rule 11.6, required]: A cast shall not be performed between pointer to void and an arithmetic type
1795 SVC functions are marked as library modules and not processed by PC-lint. The relevant source code is marked with:
1797 //lint ++flb "Library Begin" [MISRA Note 11]
1799 //lint --flb "Library End"
1804 // Service Calls definitions
1805 //lint ++flb "Library Begin" [MISRA Note 11]
1806 SVC0_1(Delay, osStatus_t, uint32_t)
1807 SVC0_1(DelayUntil, osStatus_t, uint32_t)
1808 //lint --flb "Library End"
1811 PC-lint does not process ASM input/output operand lists and therefore falsely identifies issues:
1812 - Last value assigned to variable not used
1813 - Symbol not subsequently referenced
1814 \todo: what has been done to mitigate that?
1817 \section MISRA_12 [MISRA Note 12]: Usage of exclusive access instructions
1819 The RTX5 implementation uses the CPU instructions LDREX and STREX (when supported by the processor) to implement atomic operations.
1820 This atomic operations elimite the requirement for interrupt lock-outs. The atomic operations are implemented using
1823 PC-lint cannot process assembler instructions including the input/output operand lists and therefore falsely identifies issues:
1824 - Symbol not initialized
1825 - Symbol not subsequently referenced
1826 - Symbol not referenced
1827 - Pointer parameter could be declared as pointing to const
1829 It has been verified that atomic operations have no side-effects and are well defined.
1831 The functions that implement atomic instructions are marked as library modules and not processed by PC-lint. The relevant source code is marked with:
1833 //lint ++flb "Library Begin" [MISRA Note 12]
1835 //lint --flb "Library End"
1839 \section MISRA_13 [MISRA Note 13]: Usage of Event Recorder
1841 The Event Recorder is a generic event logger and the related functions are called to record an event.
1842 The function parameters are 32-bit id, 32-bit values, pointer to void (data) and are recorded as 32-bit numbers.
1843 The parameters for the Event Recorder may require cast opertions to unsigned int which however has no side-effects
1844 and is well defined.
1846 The return value indicates success or failure. There is no need to check the return value since no action is
1847 taken when a Event Recorder function fail. The EventID macro (part of external Event Recorder) constructs the
1848 ID based on input parameters which are shifted, masked with '&' and combined with '|'.
1849 Zero value input parameters are valid and cause zero used with '&' and '|'.
1851 The usage of the Event Recorder implies the following MISRA deviations:
1852 - [MISRA 2012 Rule 11.1, required]: Conversions shall not be performed between a pointer to a function and any other type
1853 - [MISRA 2012 Rule 11.4, advisory]: A conversion should not be performed between a pointer to object and an integer type
1854 - [MISRA 2012 Rule 11.6, required]: A cast shall not be performed between pointer to void and an arithmetic type
1855 In addition PC-Lint issues:
1856 - Info 835: A zero has been given as left argument to operator '&'
1857 - Info 845: The right argument to operator '|' is certain to be 0
1859 The functions that call the Event Recorder are in the module \em rtx_evr.c and the related PC-Lint messages are disabled with:
1861 //lint -e923 -e9074 -e9078 -emacro((835,845),EventID) [MISRA Note 13]
1866 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1868 \page rtosValidation RTOS Validation
1870 Arm offers a <a class=el href="http://www.keil.com/pack" target="_blank">Software Pack</a> for the CMSIS-RTOS Validation.
1871 The <b>ARM::CMSIS-RTOS_Validation</b> Pack contains the following:
1873 - Source code of a CMSIS-RTOS Validation Suite along with configuration file.
1874 - Documentation of the CMSIS-RTOS Validation Suite.
1875 - Example that shows the usage of the CMSIS-RTOS Validation Suite using simulation.
1878 Currently, a public version of the test suite is available only for CMSIS-RTOS v1 API.
1880 The CMSIS-RTOS Validation Suite performs generic validation of various RTOS features. The test cases verify the
1881 functional behavior, test invalid parameters and call management functions from ISR.
1883 The following CMSIS-RTOS features can be tested with the current release:
1884 - Thread : Create multiple threads, terminate, restart, yield, change priority
1885 - Timer : Create periodic and one-shot timers
1886 - GenWait : Call generic wait functions (osDelay and osWait)
1887 - WaitFunc : Measure wait ticks (delay, mail, message, mutex, semaphore, signal)
1889 Moreover the following inter-thread communication functions can be tested:
1890 - Signal : Verify signal events
1891 - Memory Pool : Verify memory allocation
1892 - Message Queue : Exchange messages between threads
1893 - Mail Queue : Exchange data between threads
1894 - Mutex : Synchronize resource access
1895 - Semaphore : Access shared resources
1897 The RTOS Validation output can be printed to a console, output via ITM printf, or output to a memory buffer.
1899 \section test_output Sample Test Output
1901 CMSIS-RTOS Test Suite Oct 21 2015 16:39:16
1903 TEST 01: TC_ThreadCreate PASSED
1904 TEST 02: TC_ThreadMultiInstance PASSED
1905 TEST 03: TC_ThreadTerminate PASSED
1908 TEST 08: TC_ThreadChainedCreate PASSED
1909 TEST 09: TC_ThreadYield NOT EXECUTED
1910 TEST 10: TC_ThreadParam PASSED
1913 TEST 60: TC_MailFromISRToThread PASSED
1915 Test Summary: 60 Tests, 59 Executed, 59 Passed, 0 Failed, 0 Warnings.
1921 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1923 \page functionOverview Function Overview
1925 CMSIS-RTOS v2 provides multiple API interfaces:
1926 - \subpage rtos_api2 is the new C function API that supports dynamic object creation and Armv8-M (Arm Cortex-M23 and
1928 - <a class="el" href="../../RTOS/html/functionOverview.html">CMSIS-RTOS C API v1</a> is a C function API that is backward
1929 compatible with CMSIS-RTOS v1.
1930 - \subpage rtos_apicpp is a C++ class function API.
1932 It is possible to intermix the different API variants in the same application and even in the same C/C++ source module.
1933 However, the functions of the <b>C API Version 1</b> may be deprecated in future versions of CMSIS-RTOS.
1935 \section rtos_api2 CMSIS-RTOS2
1937 Overview of all CMSIS-RTOS C API v2 functions that are implemented in the \subpage cmsis_os2_h.
1939 \subsection rtos_api2_basics Common Design Concepts
1941 All RTOS objects share a common design concept. The overall life-cycle of
1942 an object can be summarized as created -> in use -> destroyed.
1944 <b>Create Objects</b>
1946 An object is created by calling its `osXxxNew` function. The new function returns an identifier
1947 that can be used to operate with the new object. The actual state of an object is typically stored
1948 in an object specific control block. The memory layout (and size needed) for the control
1949 block is implementation specific. One should not make any specific assumptions about the control
1950 block. The control block layout might change and hence should be seen as an implementation
1953 In order to expose control about object specific options all `osXxxNew` functions provide an
1954 optional `attr` argument, which can be left as \token{NULL} by default. It takes a pointer to
1955 an object specific attribute structure, commonly containing the fields
1956 - `name` to attach a human readable name to the object for identification,
1957 - `attr_bits` to control object-specific options,
1958 - `cb_mem` to provide memory for the control block manually, and
1959 - `cb_size` to quantify the memory size provided for the control block.
1961 The `name` attribute is only used for object identification, e.g. using RTOS-aware debugging. The
1962 attached string is not used for any other purposes internally.
1964 The `cb_mem` and `cb_size` attributes can be used to provide memory for the control block manually
1965 instead of relying on the implementation internal memory allocation. One has to assure that the
1966 amount of memory pointed to by `cb_mem` is sufficient for the objects control block structure. If
1967 the size given as `cb_size` is not sufficient the `osXxxNew` function returns with an error, i.e.
1968 returning \token{NULL}. Furthermore providing control block memory manually is less portable. Thus
1969 one has to take care about implementation specific alignment and placement requirements for instance.
1970 Refer to \ref CMSIS_RTOS_MemoryMgmt for further details.
1974 After an object has been created successfully it can be used until it is destroyed. The actions
1975 defined for an object depends on its type. Commonly all the `osXxxDoSomething` access function
1976 require the reference to the object to work with as the first `xxx_id` parameter.
1978 The access function can be assumed to apply some sort of sanity checking on the id parameter. So
1979 that it is assured one cannot accidentally call an access function with a \token{NULL} object
1980 reference. Furthermore the concrete object type is verified, i.e. one cannot call access functions
1981 of one object type with a reference to another object type.
1983 All further parameter checks applied are either object and action specific or may even be implementation
1984 specific. Thus one should always check action function return values for `osErrorParameter` to asure the
1985 provided arguments were accepted.
1987 As a rule of thumb only non-blocking access function can be used from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines" (ISR).
1988 This incorporates `osXxxWait` functions (and similar) limited to be called with parameter `timeout`
1989 set to \token{0}, i.e. usage of try-semantics.
1991 <b>Object Destruction</b>
1993 Objects that are not needed anymore can be destructed on demand to free the control block memory. Objects
1994 are not destructed implicitly. Thus one can assume an object id to be valid until `osXxxDelete` is called
1995 explicitly. The delete function finally frees the control block memory. In case of user provided control
1996 block memory, see above, the memory must be freed manually as well.
1998 The only exception one has to take care of are Threads which do not have an explicit `osThreadDelete` function.
1999 Threads can either be `detached` or `joinable`. Detached threads are automatically destroyed on termination,
2000 i.e. call to \ref osThreadTerminate or \ref osThreadExit or return from thread function. On the other hand joinable
2001 threads are kept alive until one explicitly calls \ref osThreadJoin.
2003 \subsection rtos_api2_functions Function Reference
2005 - \ref CMSIS_RTOS_KernelCtrl
2006 - \ref osKernelGetInfo : \copybrief osKernelGetInfo
2007 - \ref osKernelGetState : \copybrief osKernelGetState
2008 - \ref osKernelGetSysTimerCount : \copybrief osKernelGetSysTimerCount
2009 - \ref osKernelGetSysTimerFreq : \copybrief osKernelGetSysTimerFreq
2010 - \ref osKernelInitialize : \copybrief osKernelInitialize
2011 - \ref osKernelLock : \copybrief osKernelLock
2012 - \ref osKernelUnlock : \copybrief osKernelUnlock
2013 - \ref osKernelRestoreLock : \copybrief osKernelRestoreLock
2014 - \ref osKernelResume : \copybrief osKernelResume
2015 - \ref osKernelStart : \copybrief osKernelStart
2016 - \ref osKernelSuspend : \copybrief osKernelSuspend
2017 - \ref osKernelGetTickCount : \copybrief osKernelGetTickCount
2018 - \ref osKernelGetTickFreq : \copybrief osKernelGetTickFreq
2020 - \ref CMSIS_RTOS_ThreadMgmt
2021 - \ref osThreadDetach : \copybrief osThreadDetach
2022 - \ref osThreadEnumerate : \copybrief osThreadEnumerate
2023 - \ref osThreadExit : \copybrief osThreadExit
2024 - \ref osThreadGetCount : \copybrief osThreadGetCount
2025 - \ref osThreadGetId : \copybrief osThreadGetId
2026 - \ref osThreadGetName : \copybrief osThreadGetName
2027 - \ref osThreadGetPriority : \copybrief osThreadGetPriority
2028 - \ref osThreadGetStackSize : \copybrief osThreadGetStackSize
2029 - \ref osThreadGetStackSpace : \copybrief osThreadGetStackSpace
2030 - \ref osThreadGetState : \copybrief osThreadGetState
2031 - \ref osThreadJoin : \copybrief osThreadJoin
2032 - \ref osThreadNew : \copybrief osThreadNew
2033 - \ref osThreadResume : \copybrief osThreadResume
2034 - \ref osThreadSetPriority : \copybrief osThreadSetPriority
2035 - \ref osThreadSuspend : \copybrief osThreadSuspend
2036 - \ref osThreadTerminate : \copybrief osThreadTerminate
2037 - \ref osThreadYield : \copybrief osThreadYield
2039 - \ref CMSIS_RTOS_ThreadFlagsMgmt
2040 - \ref osThreadFlagsSet : \copybrief osThreadFlagsSet
2041 - \ref osThreadFlagsClear : \copybrief osThreadFlagsClear
2042 - \ref osThreadFlagsGet : \copybrief osThreadFlagsGet
2043 - \ref osThreadFlagsWait : \copybrief osThreadFlagsWait
2045 - \ref CMSIS_RTOS_EventFlags
2046 - \ref osEventFlagsGetName : \copybrief osEventFlagsGetName
2047 - \ref osEventFlagsNew : \copybrief osEventFlagsNew
2048 - \ref osEventFlagsDelete : \copybrief osEventFlagsDelete
2049 - \ref osEventFlagsSet : \copybrief osEventFlagsSet
2050 - \ref osEventFlagsClear : \copybrief osEventFlagsClear
2051 - \ref osEventFlagsGet : \copybrief osEventFlagsGet
2052 - \ref osEventFlagsWait : \copybrief osEventFlagsWait
2054 - \ref CMSIS_RTOS_Wait
2055 - \ref osDelay : \copybrief osDelay
2056 - \ref osDelayUntil : \copybrief osDelayUntil
2058 - \ref CMSIS_RTOS_TimerMgmt
2059 - \ref osTimerDelete : \copybrief osTimerDelete
2060 - \ref osTimerGetName : \copybrief osTimerGetName
2061 - \ref osTimerIsRunning : \copybrief osTimerIsRunning
2062 - \ref osTimerNew : \copybrief osTimerNew
2063 - \ref osTimerStart : \copybrief osTimerStart
2064 - \ref osTimerStop : \copybrief osTimerStop
2066 - \ref CMSIS_RTOS_MutexMgmt
2067 - \ref osMutexAcquire : \copybrief osMutexAcquire
2068 - \ref osMutexDelete : \copybrief osMutexDelete
2069 - \ref osMutexGetName : \copybrief osMutexGetName
2070 - \ref osMutexGetOwner : \copybrief osMutexGetOwner
2071 - \ref osMutexNew : \copybrief osMutexNew
2072 - \ref osMutexRelease : \copybrief osMutexRelease
2074 - \ref CMSIS_RTOS_SemaphoreMgmt
2075 - \ref osSemaphoreAcquire : \copybrief osSemaphoreAcquire
2076 - \ref osSemaphoreDelete : \copybrief osSemaphoreDelete
2077 - \ref osSemaphoreGetCount : \copybrief osSemaphoreGetCount
2078 - \ref osSemaphoreGetName : \copybrief osSemaphoreGetName
2079 - \ref osSemaphoreNew : \copybrief osSemaphoreNew
2080 - \ref osSemaphoreRelease : \copybrief osSemaphoreRelease
2082 - \ref CMSIS_RTOS_PoolMgmt
2083 - \ref osMemoryPoolAlloc : \copybrief osMemoryPoolAlloc
2084 - \ref osMemoryPoolDelete : \copybrief osMemoryPoolDelete
2085 - \ref osMemoryPoolFree : \copybrief osMemoryPoolFree
2086 - \ref osMemoryPoolGetBlockSize : \copybrief osMemoryPoolGetBlockSize
2087 - \ref osMemoryPoolGetCapacity : \copybrief osMemoryPoolGetCapacity
2088 - \ref osMemoryPoolGetCount : \copybrief osMemoryPoolGetCount
2089 - \ref osMemoryPoolGetName : \copybrief osMemoryPoolGetName
2090 - \ref osMemoryPoolGetSpace : \copybrief osMemoryPoolGetSpace
2091 - \ref osMemoryPoolNew : \copybrief osMemoryPoolNew
2093 - \ref CMSIS_RTOS_Message
2094 - \ref osMessageQueueDelete : \copybrief osMessageQueueDelete
2095 - \ref osMessageQueueGet : \copybrief osMessageQueueGet
2096 - \ref osMessageQueueGetCapacity : \copybrief osMessageQueueGetCapacity
2097 - \ref osMessageQueueGetCount : \copybrief osMessageQueueGetCount
2098 - \ref osMessageQueueGetMsgSize : \copybrief osMessageQueueGetMsgSize
2099 - \ref osMessageQueueGetName : \copybrief osMessageQueueGetName
2100 - \ref osMessageQueueGetSpace : \copybrief osMessageQueueGetSpace
2101 - \ref osMessageQueueNew : \copybrief osMessageQueueNew
2102 - \ref osMessageQueuePut : \copybrief osMessageQueuePut
2103 - \ref osMessageQueueReset : \copybrief osMessageQueueReset
2105 - \ref CMSIS_RTOS_TickAPI
2106 - \ref OS_Tick_Setup : \copybrief OS_Tick_Setup
2107 - \ref OS_Tick_Enable : \copybrief OS_Tick_Enable
2108 - \ref OS_Tick_Disable : \copybrief OS_Tick_Disable
2109 - \ref OS_Tick_AcknowledgeIRQ : \copybrief OS_Tick_AcknowledgeIRQ
2110 - \ref OS_Tick_GetIRQn : \copybrief OS_Tick_GetIRQn
2111 - \ref OS_Tick_GetClock : \copybrief OS_Tick_GetClock
2112 - \ref OS_Tick_GetInterval : \copybrief OS_Tick_GetInterval
2113 - \ref OS_Tick_GetCount : \copybrief OS_Tick_GetCount
2114 - \ref OS_Tick_GetOverflow : \copybrief OS_Tick_GetOverflow
2116 - \ref rtx5_specific
2117 - \ref osRtxErrorNotify : \copybrief osRtxErrorNotify
2118 - \ref osRtxIdleThread : \copybrief osRtxIdleThread
2120 The following CMSIS-RTOS2 functions can be called from threads and \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines"
2122 - \ref osKernelGetInfo, \ref osKernelGetState,
2123 \ref osKernelGetTickCount, \ref osKernelGetTickFreq, \ref osKernelGetSysTimerCount, \ref osKernelGetSysTimerFreq
2124 - \ref osThreadFlagsSet
2125 - \ref osEventFlagsSet, \ref osEventFlagsClear, \ref osEventFlagsGet, \ref osEventFlagsWait
2126 - \ref osSemaphoreAcquire, \ref osSemaphoreRelease, \ref osSemaphoreGetCount
2127 - \ref osMemoryPoolAlloc, \ref osMemoryPoolFree, \ref osMemoryPoolGetCapacity, \ref osMemoryPoolGetBlockSize,
2128 \ref osMemoryPoolGetCount, \ref osMemoryPoolGetSpace
2129 - \ref osMessageQueuePut, \ref osMessageQueueGet, \ref osMessageQueueGetCapacity, \ref osMessageQueueGetMsgSize,
2130 \ref osMessageQueueGetCount, \ref osMessageQueueGetSpace
2134 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2136 \page rtos_apicpp CMSIS-RTOS C++ API
2138 A C++11/C++14 interface is planned for the future.
2142 /* ======================================================================================================================== */
2143 // Group creation for Reference
2145 \addtogroup CMSIS_RTOS1 CMSIS-RTOS API v1
2146 \brief This section describes the CMSIS-RTOS API v1.
2148 The CMSIS-RTOS is a generic API layer that interfaces to an existing RTOS kernel.
2150 CMSIS-RTOS API v2 provides an translation layer for the
2151 <a class="el" href="../../RTOS/html/index.html">CMSIS-RTOS API v1</a> that simplifies migration.
2153 Refer to the <a class="el" href="../../RTOS/html/modules.html">Reference</a> guide of the CMSIS-RTOS API v1 for details.
2156 // Group creation for Reference
2158 \addtogroup CMSIS_RTOS CMSIS-RTOS2 API
2159 \brief Describes the C function interface of CMSIS-RTOS API v2.
2161 The CMSIS-RTOS2 is a generic API layer that interfaces to an RTOS kernel.
2163 The complete API interface is defined in the \ref cmsis_os2_h. When using dynamic memory allocation for objects, source code
2164 or libraries require no modifications when using on a different CMSIS-RTOS2 implementation.
2166 Refer to \ref rtos_api2_basics for further details.
2170 \addtogroup CMSIS_RTOS_MemoryMgmt Memory Management
2172 \brief Information about memory management possibilities
2174 The \ref CMSIS_RTOS offers two options for memory management the user can choose. For object storage one can either use
2175 - \ref CMSIS_RTOS_MemoryMgmt_Automatic (fully portable), or
2176 - \ref CMSIS_RTOS_MemoryMgmt_Manual (implementation specific).
2178 In order to affect the memory allocation scheme all RTOS objects that can be created on request, i.e. those having a `osXxxNew`
2179 function, accept an optional `osXxxAttr_t attr` argument on creation. As a rule of thumb the object attributes at least have
2180 members to assign custom control block memory, i.e. `cb_mem` and `cb_size` members. By default, i.e. `attr` is `NULL`
2181 or `cb_mem` is `NULL`, \ref CMSIS_RTOS_MemoryMgmt_Automatic is used. Providing a pointer to user memory in `cb_mem` switches
2182 to \ref CMSIS_RTOS_MemoryMgmt_Manual.
2184 \note For detailed information about memory allocation strategies provided in RTX5 refer to \ref MemoryAllocation.
2186 \section CMSIS_RTOS_MemoryMgmt_Automatic Automatic Dynamic Allocation
2188 The automatic allocation is the default and viable for many use-cases. Moreover it is fully portable across different
2189 implementations of the \ref CMSIS_RTOS. The common drawback of dynamic memory allocation is the possibility of memory
2190 fragmentation and exhaustion. Given that all needed objects are created once upon system initialization and never
2191 deleted at runtime this class of runtime failures can be prevented, though.
2193 The actual allocation strategy used is implementation specific, i.e. whether global heap or preallocated memory pools are used.
2195 <b> Code Example:</b>
2197 #include "cmsis_os2.h" // implementation agnostic
2199 osMutexId_t mutex_id;
2200 osMutexId_t mutex2_id;
2202 const osMutexAttr_t Thread_Mutex_attr = {
2203 "myThreadMutex", // human readable mutex name
2204 osMutexRecursive | osMutexPrioInherit, // attr_bits
2205 NULL, // memory for control block (default)
2206 0U // size for control block (default)
2209 void CreateMutex (void) {
2210 mutex_id = osMutexNew(NULL); // use default values for all attributes
2211 mutex2_id = osMutexNew(&Thread_Mutex_attr); // use attributes from defined structure
2216 The Mutexes in this example are created using automatic memory allocation.
2218 \section CMSIS_RTOS_MemoryMgmt_Manual Manual User-defined Allocation
2220 One can get fine grained control over memory allocation by providing user-defined memory.
2221 The actual requirements such user-defined memory are implementation specific. Thus one
2222 needs to carefully refer to the size and alignment rules of the implementation used, e.g.
2223 for RTX see \ref StaticObjectMemory.
2225 <b> Code Example:</b>
2227 #include "rtx_os.h" // implementation specific
2229 osMutexId_t mutex_id;
2231 static uint32_t mutex_cb[osRtxMutexCbSize/4U]; // implementation specific
2233 const osMutexAttr_t Thread_Mutex_attr = {
2234 "myThreadMutex", // human readable mutex name
2235 osMutexRecursive | osMutexPrioInherit, // attr_bits
2236 mutex_cb, // memory for control block (user-defined)
2237 sizeof(mutex_cb) // size for control block (user-defined)
2240 void CreateMutex (void) {
2241 mutex_id = osMutexNew(&Thread_Mutex_attr); // use attributes from defined structure
2246 The above example uses user-defined memory for the mutex control block. Depending on the actual
2247 implementation used one needs to include the specific header file, `rtx_os.h` in this case.
2252 \addtogroup rtx5_specific RTX5 Specific API
2253 \brief This section describes CMSIS-RTOS RTX5 specifics.
2255 The RTX5 kernel can be customized for different application requirements:
2256 - If you are depending on the \ref lowPower "lowest power consumption" possible, you need to adapt the function
2257 \ref osRtxIdleThread to send the system to sleep mode as often as possible. In addition, use the
2258 \ref TickLess "tick-less low power" functions \ref osKernelSuspend and \ref osKernelResume to suspend the scheduler and to
2259 stop the SysTick timer.
2260 - If you try to find a \b runtime \b error, use the function \ref osRtxErrorNotify to debug the error.
2262 RTX5 interfaces to the <a href="http://www.keil.com/pack/doc/compiler/EventRecorder/html/index.html" target="_blank"><b>Event Recorder</b></a>
2263 to provide event information which helps you to understand and analyze the operation. Refer to \ref rtx_evr for more
2271 \defgroup rtx5_specific_defines Macros
2277 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2279 \def osRtxThreadCbSize
2280 \brief Thread Control Block size
2282 This macro exposes the minimum amount of memory needed for an RTX5 Thread Control Block,
2283 see osThreadAttr_t::cb_mem and \ref osThreadAttr_t::cb_size.
2287 // Used-defined memory for thread control block
2288 static uint32_t thread_cb[osRtxThreadCbSize/4U];
2292 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2294 \def osRtxTimerCbSize
2295 \brief Timer Control Block size
2297 This macro exposes the minimum amount of memory needed for an RTX5 Timer Control Block,
2298 see osTimerAttr_t::cb_mem and \ref osTimerAttr_t::cb_size.
2302 // Used-defined memory for timer control block
2303 static uint32_t timer_cb[osRtxTimerCbSize/4U];
2307 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2309 \def osRtxEventFlagsCbSize
2310 \brief Event Flags Control Block size
2312 This macro exposes the minimum amount of memory needed for an RTX5 Event Flags Control Block,
2313 see osEventFlagsAttr_t::cb_mem and \ref osEventFlagsAttr_t::cb_size.
2317 // Used-defined memory for event flags control block
2318 static uint32_t evflags_cb[osRtxEventFlagsCbSize/4U];
2322 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2324 \def osRtxMutexCbSize
2325 \brief Mutex Control Block size
2327 This macro exposes the minimum amount of memory needed for an RTX5 Mutex Control Block,
2328 see osMutexAttr_t::cb_mem and \ref osMutexAttr_t::cb_size.
2332 // Used-defined memory for mutex control block
2333 static uint32_t mutex_cb[osRtxMutexCbSize/4U];
2337 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2339 \def osRtxSemaphoreCbSize
2340 \brief Semaphore Control Block size
2342 This macro exposes the minimum amount of memory needed for an RTX5 Semaphore Control Block,
2343 see osSemaphoreAttr_t::cb_mem and osSemaphoreAttr_t::cb_size.
2347 // Used-defined memory for semaphore control block
2348 static uint32_t sema_cb[osRtxSemaphoreCbSize/4U];
2352 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2354 \def osRtxMemoryPoolCbSize
2355 \brief Memory Pool Control Block size
2357 This macro exposes the minimum amount of memory needed for an RTX5 Memory Pool Control Block,
2358 see osMemoryPoolAttr_t::cb_mem and osMemoryPoolAttr_t::cb_size.
2362 // Used-defined memory for memory pool control block
2363 static uint32_t timer_cb[osRtxMemoryPoolCbSize/4U];
2367 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2369 \def osRtxMessageQueueCbSize
2370 \brief Message Queue Control Block size
2372 This macro exposes the minimum amount of memory needed for an RTX5 Message Queue Control Block,
2373 see osMessageQueueAttr_t::cb_mem and osMessageQueueAttr_t::cb_size.
2377 // Used-defined memory for message queue control block
2378 static uint32_t msgqueue_cb[osRtxMessageQueueCbSize/4U];
2382 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2384 \def osRtxMemoryPoolMemSize
2385 \brief Memory Pool Memory size
2387 This macro exposes the minimum amount of memory needed for an RTX5 Memory Pool Memory,
2388 see osMemoryPoolAttr_t::mp_mem and osMemoryPoolAttr_t::mp_size.
2392 // Maximum number of objects
2393 #define OBJ_COUNT 8U
2401 // Used-defined memory for memory pool memory
2402 static uint32_t mempool_cb[osRtxMemoryPoolMemSize(OBJ_COUNT, sizeof(object_t))/4U];
2406 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2408 \def osRtxMessageQueueMemSize
2409 \brief Message Queue Memory size
2411 This macro exposes the minimum amount of memory needed for an RTX5 Message Queue Memory,
2412 see osMessageQueueAttr_t::mq_mem and osMessageQueueAttr_t::mq_size.
2416 // Maximum number of messages
2417 #define MSG_COUNT 16U
2419 // Message data type
2425 // Used-defined memory for message queue
2426 static uint32_t mq_mem[osRtxMessageQueueMemSize(MSG_COUNT, sizeof(msg_item_t))/4U];
2435 \defgroup rtx5_specific_structs Structs
2441 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2443 \struct osRtxThread_t
2446 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2448 \struct osRtxTimerFinfo_t
2451 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2453 \struct osRtxTimer_t
2456 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2458 \struct osRtxEventFlags_t
2461 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2463 \struct osRtxMutex_t
2466 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2468 \struct osRtxSemaphore_t
2471 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2473 \struct osRtxMemoryPool_t
2476 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2478 \struct osRtxMessageQueue_t
2486 \defgroup rtx5_specific_functions Functions
2487 \brief RTX5 functions
2492 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2494 \fn uint32_t osRtxErrorNotify (uint32_t code, void *object_id);
2496 Some system error conditions can be detected during runtime. If the RTX kernel detects a runtime error, it calls the runtime
2497 error function \b osRtxErrorNotify for an object specified by parameter \a object_id.
2499 The parameter \a code passes the actual error code to this function:
2500 | Error Code | Description |
2501 |------------------------------|-----------------------------------------------------------------------------------|
2502 | osRtxErrorStackUnderflow | Stack overflow detected for thread (thread_id=object_id) |
2503 | osRtxErrorISRQueueOverflow | ISR Queue overflow detected when inserting object (object_id) |
2504 | osRtxErrorTimerQueueOverflow | User Timer Callback Queue overflow detected for timer (timer_id=object_id) |
2505 | osRtxErrorClibSpace | Standard C/C++ library libspace not available: increase \c OS_THREAD_LIBSPACE_NUM |
2506 | osRtxErrorClibMutex | Standard C/C++ library mutex initialization failed |
2508 The function \b osRtxErrorNotify must contain an infinite loop to prevent further program execution. You can use an emulator
2509 to step over the infinite loop and trace into the code introducing a runtime error. For the overflow errors this means you
2510 need to increase the size of the object causing an overflow.
2512 \note Cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
2518 uint32_t osRtxErrorNotify (uint32_t code, void *object_id) {
2522 case osRtxErrorStackUnderflow:
2523 // Stack overflow detected for thread (thread_id=object_id)
2525 case osRtxErrorISRQueueOverflow:
2526 // ISR Queue overflow detected when inserting object (object_id)
2528 case osRtxErrorTimerQueueOverflow:
2529 // User Timer Callback Queue overflow detected for timer (timer_id=object_id)
2531 case osRtxErrorClibSpace:
2532 // Standard C/C++ library libspace not available: increase OS_THREAD_LIBSPACE_NUM
2534 case osRtxErrorClibMutex:
2535 // Standard C/C++ library mutex initialization failed
2546 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2547 osRtxErrorClibMutex /**
2548 \fn void osRtxIdleThread (void *argument);
2550 The function \b osRtxIdleThread is executed by the RTX kernel, when no other threads are ready to run. By default, this
2551 thread is an empty end-less loop that does nothing. It only waits until another task becomes ready to run. You may change the
2552 code of the \b osRtxIdleThread function to put the CPU into a power-saving or idle mode, see \ref TickLess.
2554 The default stack size for this thread is defined in the file RTX_Config.h. Refer to \ref threadConfig.
2556 \note Cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
2562 __NO_RETURN void osRtxIdleThread (void *argument) {