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 - Based on CMSIS-RTOS API V2.1.2.
167 - Moved SVC/PendSV handler priority setup from osKernelInitialize to osKernelStart (User Priority Grouping can be updated after osKernelInitialize but before osKernelStart).
168 - Corrected SysTick and PendSV handlers for ARMv8-M Baseline.
169 - Corrected memory allocation for stack and data when "Object specific Memory allocation" configuration is used.
175 - Corrected IRQ and SVC exception handlers for Cortex-A.
181 - Corrected SysTick and SVC Interrupt Priority for Cortex-M.
187 - Based on CMSIS-RTOS API V2.1.1.
188 - Added support for for Cortex-A.
189 - Using OS Tick API for RTX Kernel Timer Tick.
190 - Fixed potential corruption of terminated threads list.
191 - Corrected MessageQueue to use actual message length (before padding).
192 - Corrected parameters for ThreadEnumerate and MessageQueueInserted events.
193 - Timer Thread creation moved to osKernelStart.
199 - Based on CMSIS-RTOS API V2.1.0.
200 - Added support for Event recording.
201 - Added support for IAR compiler.
202 - Updated configuration files: RTX_Config.h for the configuration settings and RTX_config.c for implementing the \ref rtx5_specific.
203 - osRtx name-space for RTX specific symbols.
209 Initial release compliant to CMSIS-RTOS2.\n
216 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
218 \page genRTOS2IF Generic RTOS Interface
220 CMSIS-RTOS2 is a generic API that is agnostic of the underlying RTOS kernel. Application programmers call CMSIS-RTOS2 API
221 functions in the user code to ensure maximum portability from one RTOS to another. Middleware using CMSIS-RTOS2 API takes
222 advantages of this approach by avoiding unnecessary porting efforts.
224 \image html "API_Structure.png" "CMSIS-RTOS API Structure"
226 A typical CMSIS-RTOS2 API implementation interfaces to an existing real-time kernel. The CMSIS-RTOS2 API provides the
227 following attributes and functionalities:
228 - Function names, identifiers, and parameters are descriptive and easy to understand. The functions are powerful and
229 flexible which reduces the number of functions exposed to the user.
230 - \ref CMSIS_RTOS_ThreadMgmt allows you to define, create, and control threads.
231 - Interrupt Service Routines (ISR) can \ref CMSIS_RTOS_ISR_Calls "call some CMSIS-RTOS functions". When a CMSIS-RTOS
232 function cannot be called from an ISR context, it rejects the invocation and returns an error code.
233 - Three different event types support communication between multiple threads and/or ISR:
234 - \ref CMSIS_RTOS_ThreadFlagsMgmt "Thread Flags": may be used to indicate specific conditions to a thread.
235 - \ref CMSIS_RTOS_EventFlags "Event Flags": may be used to indicate events to a thread or ISR.
236 - \ref CMSIS_RTOS_Message "Messages": can be sent to a thread or an ISR. Messages are buffered in a queue.
237 - \ref CMSIS_RTOS_MutexMgmt and \ref CMSIS_RTOS_SemaphoreMgmt are incorporated.
238 - CPU time can be scheduled with the following functionalities:
239 - A \a timeout parameter is incorporated in many CMSIS-RTOS functions to avoid system lockup. When a timeout is specified,
240 the system waits until a resource is available or an event occurs. While waiting, other threads are scheduled.
241 - The \ref osDelay and \ref osDelayUntil functions put a thread into the \b WAITING state for a specified period of time.
242 - The \ref osThreadYield provides co-operative thread switching and passes execution to another thread of the same
244 - \ref CMSIS_RTOS_TimerMgmt functions are used to trigger the execution of functions.
246 The CMSIS-RTOS2 API is designed to optionally incorporate multi-processor systems and/or access protection via the Cortex-M
247 Memory Protection Unit (MPU).
249 In some RTOS implementations threads may execute on different processors, thus \b message queues may reside in shared memory
252 The CMSIS-RTOS2 API encourages the software industry to evolve existing RTOS implementations. RTOS implementations can be
253 different and optimized in various aspects towards the Cortex-M processors. Optional features may be for example
254 - Support of the Cortex-M Memory Protection Unit (MPU).
255 - Support of multi-processor systems.
256 - Support of a DMA controller.
257 - Deterministic context switching.
258 - Round-robin context switching.
259 - Deadlock avoidance, for example with priority inversion.
260 - Zero interrupt latency by using ARMv7-M instructions LDREX and STREX.
262 \section usingOS2 Using a CMSIS-RTOS2 Implementation
264 A CMSIS-RTOS2 implementation is typically provided as a library. To add the RTOS functionality to an existing CMSIS-based
265 application, the RTOS library (and typically one or more configuration files) needs to be added. There is a single new header
266 file %cmsis_os2.h available. This is the only header file required for a completely portable application. In such a case,
267 user provided memory for control blocks, objects data and thread stack cannot be used. Alternatively, you can include an
268 implementation specific header file (for example rtx_os.h) which provides definitions also for resource allocation (such as
269 size of control blocks, required memory for object data and thread stack). This is optional and implies that the application
270 code is not completely portable.
272 \image html "CMSIS_RTOS_Files.png" "CMSIS-RTOS File Structure"
274 Once the files are added to a project, the user can start working with the CMSIS-RTOS functions. A code example is provided
279 /*----------------------------------------------------------------------------
280 * CMSIS-RTOS 'main' function template
281 *---------------------------------------------------------------------------*/
283 #include "RTE_Components.h"
284 #include CMSIS_device_header
285 #include "cmsis_os2.h"
287 /*----------------------------------------------------------------------------
288 * Application main thread
289 *---------------------------------------------------------------------------*/
290 void app_main (void *argument) {
298 // System Initialization
299 SystemCoreClockUpdate();
300 #ifdef RTE_Compiler_EventRecorder
301 // Initialize and start Event Recorder
302 EventRecorderInitialize(EventRecordError, 1U);
306 osKernelInitialize(); // Initialize CMSIS-RTOS
307 osThreadNew(app_main, NULL, NULL); // Create application main thread
308 osKernelStart(); // Start thread execution
314 \section cmsis_os2_h cmsis_os2.h header file
316 The file \b cmsis_os2.h is a standard header file that interfaces to every CMSIS-RTOS2 compliant real-time operating
317 systems (RTOS). Each implementation is provided the same \b cmsis_os2.h which defines the interface to the \ref rtos_api2.
319 Using the \b cmsis_os2.h along with dynamic object allocation allows to create source code or libraries that require no
320 modifications when using on a different CMSIS-RTOS2 implementation.
322 <b>Header file %cmsis_os2.h</b>
328 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
330 \page rtx5_impl RTX v5 Implementation
332 Keil RTX version 5 (RTX5) implements the CMSIS-RTOS2 as a native RTOS interface for ARM Cortex-M processor-based devices.
333 A translation layer to CMSIS-RTOS API v1 is provided. Therefore, RTX5 can be used in applications that where previously based
334 on RTX version 4 and CMSIS-RTOS version 1 with minimal effort.
336 The following sections provide further details:
337 - \subpage cre_rtx_proj explains how to setup an RTX v5 project in Keil MDK.
338 - \subpage theory_of_operation provides general information about the operation of CMSIS-RTOS RTX v5.
339 - \subpage config_rtx5 describes configuration parameters of CMSIS-RTOS RTX v5.
340 - \subpage creating_RTX5_LIB explains how to build your own CMSIS-RTOS RTX v5 library.
341 - \subpage dirstructfiles5 explains the directories and files that are supplied as part of CMSIS-RTOS RTX v5.
342 - \subpage technicalData5 lists microcontroller hardware requirements and limitations such as number of concurrent threads.
343 - \subpage misraCompliance5 describes the violations to the MISRA standard.
346 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
348 \page cre_rtx_proj Create an RTX5 Project
350 The steps to create a microcontroller application using RTX5 are:
351 - Create a new project and select a microcontroller device.
352 - In the Manage Run-Time Environment window, select <b>CMSIS\::CORE</b> and <b>CMSIS\::RTOS2 (API)\::Keil RTX5</b>. You can
353 choose to either add RTX as a library (Variant: \b Library) or to add the full source code (Variant: \b Source - required
354 if using the <a href="http://www.keil.com/pack/doc/compiler/EventRecorder/html/index.html" target="_blank"><b>Event Recorder</b></a>):
356 \image html manage_rte_output.png
358 - If the <b>Validation Output</b> requires other components to be present, try to use the \b Resolve button.
359 - Click \b OK. In the \b Project window, you will see the files that have been automatically added to you project, such as
360 \b %RTX_Config.h, \b %RTX_Config.c, the library or the source code files, as well as the system and startup files:
362 \image html project_window.png
364 - 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).
365 - You can add template files to the project by right-clicking on <b>Source Group 1</b> and selecting
366 <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
367 you will see all available template files for CMSIS-RTOS RTX:
369 \image html add_item.png
371 - \ref config_rtx5 "Configure" RTX5 to the application's needs using the \b %RTX_Config.h file.
373 \section cre_rtx_cortexa Additional requirements for RTX on Cortex-A
375 Cortex-A based microcontrollers are less unified with respect to the interrupt and timer implementations used compared to
376 M-class devices. Thus RTX requires additional components when an A-class device is used, namely
377 <a href="../../Core_A/html/group__irq__ctrl__gr.html"><b>IRQ Controller (API)</b></a> and \ref CMSIS_RTOS_TickAPI "OS Tick (API)"
380 \image html manage_rte_cortex-a.png
382 The default implementations provided along with CMSIS are
383 - ARM <a href="../../Core_A/html/group__GIC__functions.html">Generic Interrupt Controller (GIC)</a>
384 - ARM Cortex-A5, Cortex-A9 <a href="../../Core_A/html/group__PTM__timer__functions.html">Private Timer (PTIM)</a>
385 - ARM Cortex-A7 <a href="../../Core_A/html/group__PL1__timer__functions.html">Generic Physical Timer (GTIM)</a>
387 For devices not implementing GIC, PTIM nor GTIM please refer to the according device family pack and select the
388 proper implementations.
390 \section cre_rtx_proj_specifics Add support for RTX specific functions
391 If you require some of the \ref rtx5_specific "RTX specific functions" in your application code, \#include the
392 \ref rtx_os_h "header file rtx_os.h". This enables \ref lowPower "low-power" and \ref TickLess "tick-less" operation modes.
394 \section cre_rtx_proj_er Add Event Recorder Visibility
395 - To use the Event Recorder together with RTX5, select the software component <b>Compiler:Event Recorder</b>.
396 - Select the \b Source variant of the software component <b>CMSIS:RTOS2 (API):Keil RTX5</b>.
397 \image html event_recorder_rte.png "Component selection for Event Recorder"
398 - Call the function <b>EventRecorderInitialize()</b> in your application code (ideally in \c main()).
399 - Build the application code and download it to the debug hardware.
401 Once the target application generates event information, it can be viewed in the µVision debugger using the \b Event
406 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
408 \page theory_of_operation Theory of Operation
410 Many aspects of the kernel are configurable and the configuration options are mentioned where applicable.
412 \section SystemStartup System Startup
414 Since main is no longer a thread RTX5 does not interfere with the system startup until main is reached.
415 Once the execution reaches \c main() there is a recommended order to initialize the hardware and start the kernel. This is
416 also reflected in the user code template file "CMSIS-RTOS2 'main' function" supplied with the RTX5 component.
418 Your application's \c main() should implement at least the following in the given order:
419 -# Initialization and configuration of hardware including peripherals, memory, pins, clocks and the interrupt system.
420 -# Update the system core clock using the respective
421 <a href=../../Core/html/group__system__init__gr.html>CMSIS-Core (Cortex-M)</a> or
422 <a href=../../Core_A/html/group__system__init__gr.html>CMSIS-Core (Cortex-A)</a> function.
423 -# Initialize the CMSIS-RTOS kernel using \ref osKernelInitialize.
424 -# Optionally, create a new thread \c app_main, which is used as a main thread using \ref osThreadNew. Alternatively, threads
425 can be created in \c main() directly.
426 -# Start the RTOS scheduler using \ref osKernelStart. This function does not return in case of successful execution. Any
427 application code after \b osKernelStart will not be executed unless \b osKernelStart fails.
429 \note Interrupts (like SVC for example) used by the kernel are initialized in \ref osKernelInitialize. In case priorities and
430 groupings in the NVIC are altered by the application after the above sequence it might be necessary to call
431 \ref osKernelInitialize again. You might observe weird misbehaviour possibly catched by \ref osRtxErrorNotify or causing a hard fault.
433 \note The tick timer is configured during \ref osKernelStart. The tick interval is calculated based on the \c SystemCoreClock variable.
437 RTX5 implements a low-latency preemtive scheduler. Major parts of RTX5 are executed in handler mode such as
438 - \ref SysTick_Handler used for time-based scheduling.
439 - \ref SVC_Handler used for lock-based scheduling.
440 - \ref PendSV_Handler used for interrupt-based scheduling.
442 In order to be low-latency with respect to ISR execution those system exceptions are configured to use the
443 lowest priority groups available. The priorities are configured such that no preemption happens between them. Thus
444 no interrupt critical sections (i.e. interrupt locks) are needed to protect the scheduler.
446 \image html scheduling.png "Thread scheduling and interrupt execution"
448 The scheduler combines priority and round-robin based context switches. The example depicted in the image above contains
449 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
450 (\ref osThreadAttr_t::priority). As long as threads 3 and 4 are blocked the scheduler switches between thread 1 and 2 on
451 a time-slice basis (round-robin). The time-slice for round-robin scheduling can be configured, see Round-Robin Timeout in \ref systemConfig.
453 Thread 2 unblocks thread 3 by an arbitrary RTOS-call (executed in SVC handler mode) at time index 2. The scheduler switches to
454 thread 3 immidiately because thread 3 has the highest priority. Thread 4 is still blocked.
456 At time index 4 an interrupt (ISR) occurs and preempts the SysTick_Handler. RTX does not add any latency to the interrupt
457 service execution. The ISR routine uses an RTOS-call that unblocks thread 4. Instead of switching to thread 4 immediately
458 the PendSV flag is set to defer the context switching. The PendSV_Handler is executed right after the SysTick_Handler returns
459 and the defered context switch to thread 4 is carried out. As soon as highest priority thread 4 blocks again by using
460 a blocking RTOS-call execution is switched back to thread 3 immidiately during time index 5.
462 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.
463 At time index 7 the scheduler uses the round-robin mechanism to switch to thread 1 and so on.
465 \section MemoryAllocation Memory Allocation
467 RTX5 objects (thread, mutex, semaphore, timer, message queue, thread and event flags, as well as memory pool) require
468 dedicated RAM memory. Objects can be created using os<i>Object</i>New() calls and deleted using os<i>Object</i>Delete()
469 calls. The related object memory needs to be available during the lifetime of the object.
471 RTX5 offers three different memory allocation methods for objects:
472 - \ref GlobalMemoryPool uses a single global memory pool for all objects. It is easy to configure, but may have
473 the disadvantage for memory fragmentation when objects with different sizes are created and destroyed.
474 - \ref ObjectMemoryPool uses a fixed-size memory pool for each object type. The method is time deterministic
475 and avoids memory fragmentation.
476 - \ref StaticObjectMemory reserves memory during compile time and completely avoids that a system can be out of memory.
477 This is typically a required for some safety critical systems.
479 It possible to intermix all the memory allocation methods in the same application.
481 \subsection GlobalMemoryPool Global Memory Pool
483 The global memory pool allocates all objects from a memory area. This method of memory allocation is the default
484 configuration setting of RTX5.
486 \image html MemAllocGlob.png "Global Memory Pool for all objects"
488 When the memory pool does not provide sufficient memory, the creation of the object fails and the related
489 os<i>Object</i>New() function returns \token{NULL}.
491 Enabled in \ref systemConfig.
493 \subsection ObjectMemoryPool Object-specific Memory Pools
495 Object-specific memory pools avoids memory fragmentation with a dedicated fixed-size memory management for each object type.
496 This type of memory pools are fully time deterministic, which means that object creation and destruction takes always the
497 same fixed amount of time. As a fixed-size memory pool is specific to an object type, the handling of out-of-memory
498 situations is simplified.
500 \image html MemAllocSpec.png "One memory pool per object type"
502 Object-specific memory pools are selectively enabled for each object type, e.g: mutex or thread using the RTX configuration
504 - Enabled in \ref threadConfig for thread objects.
505 - Enabled in \ref timerConfig for timer objects.
506 - Enabled in \ref eventFlagsConfig for event objects.
507 - Enabled in \ref mutexConfig for mutex objects.
508 - Enabled in \ref semaphoreConfig for semaphore.
509 - Enabled in \ref memPoolConfig for memory pools.
510 - Enabled in \ref msgQueueConfig for message objects.
512 When the memory pool does not provide sufficient memory, the creation of the object fails and the related
513 os<i>Object</i>New() function returns \token{NULL}.
515 \subsection StaticObjectMemory Static Object Memory
516 In contrast to the dynamic memory allocations, the static memory allocation requires compile-time allocation of object memory.
518 \image html MemAllocStat.png "Statically allocated memory for all objects"
520 The following code example shows how to create an OS object using static memory.
522 <b> Code Example:</b>
524 /*----------------------------------------------------------------------------
525 * CMSIS-RTOS 'main' function template
526 *---------------------------------------------------------------------------*/
528 #include "RTE_Components.h"
529 #include CMSIS_device_header
530 #include "cmsis_os2.h"
532 //include rtx_os.h for types of RTX objects
535 //The thread function instanced in this example
536 void worker(void *arg)
545 // Define objects that are statically allocated for worker thread 1
546 osRtxThread_t worker_thread_tcb_1;
548 // Reserve two areas for the stacks of worker thread 1
549 // uint64_t makes sure the memory alignment is 8
550 uint64_t worker_thread_stk_1[64];
552 // Define the attributes which are used for thread creation
553 // Optional const saves RAM memory and includes the values in periodic ROM tests
554 const osThreadAttr_t worker_attr_1 = {
557 &worker_thread_tcb_1,
558 sizeof(worker_thread_tcb_1),
559 &worker_thread_stk_1[0],
560 sizeof(worker_thread_stk_1),
561 osPriorityAboveNormal,
565 // Define ID object for thread
568 /*----------------------------------------------------------------------------
569 * Application main thread
570 *---------------------------------------------------------------------------*/
571 void app_main (void *argument) {
572 uint32_t param = NULL;
574 // Create an instance of the worker thread with static resources (TCB and stack)
575 th1 = osThreadNew(worker, ¶m, &worker_attr_1);
581 // System Initialization
582 SystemCoreClockUpdate();
585 osKernelInitialize(); // Initialize CMSIS-RTOS
586 osThreadNew(app_main, NULL, NULL); // Create application main thread
587 osKernelStart(); // Start thread execution
593 \section ThreadStack Thread Stack Management
595 For Cortex-M processors without floating point unit the thread context requires 64 bytes on the local stack.
597 \note For Cortex-M4/M7 with FP the thread context requires 200 bytes on the local stack. For these devices the default stack
598 space should be increased to a minimum of 300 bytes.
600 Each thread is provided with a separate stack that holds the thread context and stack space for automatic variables and
601 return addresses for function call nesting. The stack sizes of RTX threads are flexibly configurable as explained in the
602 section \ref threadConfig. RTX offers a configurable checking for stack overflows and stack utilization.
605 \section lowPower Low-Power Operation
607 The system thread \b osRtxIdleThread can be use to switch the system into a low-power mode. The easiest form to enter a
608 low-power mode is the execution of the \c __WFE function that puts the processor into a sleep mode where it waits for an
613 #include "RTE_Components.h"
614 #include CMSIS_device_header /* Device definitions */
616 void osRtxIdleThread (void) {
617 /* The idle demon is a system thread, running when no other thread is */
621 __WFE(); /* Enter sleep mode */
627 \c __WFE() is not available in every Cortex-M implementation. Check device manuals for availability.
630 \section kernelTimer RTX Kernel Timer Tick
632 RTX uses the generic \ref CMSIS_RTOS_TickAPI to configure and control its periodic Kernel Tick.
634 To use an alternative timer as the Kernel Tick Timer one simply needs to implement a custom version
635 of the \ref CMSIS_RTOS_TickAPI.
637 \note The OS Tick implementation provided must asure that the used timer interrupt uses the same (low) priority group
638 as the service interrupts, i.e. interrupts used by RTX must not preempt each other. Refer to the \ref Scheduler section
641 \subsection TickLess Tick-less Low-Power Operation
643 RTX5 provides extension for tick-less operation which is useful for applications that use extensively low-power modes where
644 the SysTick timer is also disabled. To provide a time-tick in such power-saving modes, a wake-up timer is used to
645 derive timer intervals. The CMSIS-RTOS2 functions \ref osKernelSuspend and \ref osKernelResume control the tick-less
648 Using this functions allows the RTX5 thread scheduler to stop the periodic kernel tick interrupt. When all active threads
649 are suspended, the system enters power-down and calculates how long it can stay in this power-down mode. In the power-down
650 mode the processor and peripherals can be switched off. Only a wake-up timer must remain powered, because this timer is
651 responsible to wake-up the system after the power-down period expires.
653 The tick-less operation is controlled from the \b osRtxIdleThread thread. The wake-up timeout value is set before the system
654 enters the power-down mode. The function \ref osKernelSuspend calculates the wake-up timeout measured in RTX Timer Ticks;
655 this value is used to setup the wake-up timer that runs during the power-down mode of the system.
657 Once the system resumes operation (either by a wake-up time out or other interrupts) the RTX5 thread scheduler is started
658 with the function \ref osKernelResume. The parameter \a sleep_time specifies the time (in RTX Timer Ticks) that the system
659 was in power-down mode.
663 #include "msp.h" // Device header
665 /*----------------------------------------------------------------------------
666 * MSP432 Low-Power Extension Functions
667 *---------------------------------------------------------------------------*/
668 static void MSP432_LP_Entry(void) {
669 /* Enable PCM rude mode, which allows to device to enter LPM3 without waiting for peripherals */
670 PCM->CTL1 = PCM_CTL1_KEY_VAL | PCM_CTL1_FORCE_LPM_ENTRY;
671 /* Enable all SRAM bank retentions prior to going to LPM3 */
672 SYSCTL->SRAM_BANKRET |= SYSCTL_SRAM_BANKRET_BNK7_RET;
673 __enable_interrupt();
674 NVIC_EnableIRQ(RTC_C_IRQn);
675 /* Do not wake up on exit from ISR */
676 SCB->SCR |= SCB_SCR_SLEEPONEXIT_Msk;
677 /* Setting the sleep deep bit */
678 SCB->SCR |= (SCB_SCR_SLEEPDEEP_Msk);
681 static volatile unsigned int tc;
682 static volatile unsigned int tc_wakeup;
684 void RTC_C_IRQHandler(void)
686 if (tc++ > tc_wakeup)
688 SCB->SCR &= ~SCB_SCR_SLEEPONEXIT_Msk;
689 NVIC_DisableIRQ(RTC_C_IRQn);
690 NVIC_ClearPendingIRQ(RTC_C_IRQn);
693 if (RTC_C->PS0CTL & RTC_C_PS0CTL_RT0PSIFG)
695 RTC_C->CTL0 = RTC_C_KEY_VAL; // Unlock RTC key protected registers
696 RTC_C->PS0CTL &= ~RTC_C_PS0CTL_RT0PSIFG;
698 SCB->SCR |= (SCB_SCR_SLEEPDEEP_Msk);
702 uint32_t g_enable_sleep = 0;
704 void osRtxIdleThread (void) {
707 tc_wakeup = osKernelSuspend();
708 /* Is there some time to sleep? */
711 /* Enter the low power state */
715 /* Adjust the kernel ticks with the amount of ticks slept */
722 \c __WFE() is not available in every ARM Cortex-M implementation. Check device manuals for availability.
723 The alternative using \c __WFI() has other issues, please take note of http://www.keil.com/support/docs/3591.htm as well.
725 \section rtx_os_h RTX5 Header File
727 Every implementation of the CMSIS-RTOS2 API can bring its own additional features. RTX5 adds a couple of
728 \ref rtx5_specific "functions" for the idle more, for error notifications, and special system timer functions. It also is
729 using macros for control block and memory sizes.
731 If you require some of the RTX specific functions in your application code, \#include the header file \b %rtx_os.h:
736 \section CMSIS_RTOS_TimeOutValue Timeout Value
738 Timeout values are an argument to several \b osXxx functions to allow time for resolving a request. A timeout value of \b 0
739 means that the RTOS does not wait and the function returns instantly, even when no resource is available. A timeout value of
740 \ref osWaitForever means that the RTOS waits infinitely until a resource becomes available. Or one forces the thread to resume
741 using \ref osThreadResume which is discouraged.
743 The timeout value specifies the number of timer ticks until the time delay elapses. The value is an upper bound and
744 depends on the actual time elapsed since the last timer tick.
747 - timeout value \b 0 : the system does not wait, even when no resource is available the RTOS function returns instantly.
748 - timeout value \b 1 : the system waits until the next timer tick occurs; depending on the previous timer tick, it may be a
749 very short wait time.
750 - timeout value \b 2 : actual wait time is between 1 and 2 timer ticks.
751 - timeout value \ref osWaitForever : system waits infinite until a resource becomes available.
753 \image html TimerValues.png "Example of timeout using osDelay()"
756 \section CMSIS_RTOS_ISR_Calls Calls from Interrupt Service Routines
758 The following CMSIS-RTOS2 functions can be called from threads and Interrupt Service Routines (ISR):
759 - \ref osKernelGetInfo, \ref osKernelGetState,
760 \ref osKernelGetTickCount, \ref osKernelGetTickFreq, \ref osKernelGetSysTimerCount, \ref osKernelGetSysTimerFreq
761 - \ref osThreadFlagsSet
762 - \ref osEventFlagsSet, \ref osEventFlagsClear, \ref osEventFlagsGet, \ref osEventFlagsWait
763 - \ref osSemaphoreAcquire, \ref osSemaphoreRelease, \ref osSemaphoreGetCount
764 - \ref osMemoryPoolAlloc, \ref osMemoryPoolFree, \ref osMemoryPoolGetCapacity, \ref osMemoryPoolGetBlockSize,
765 \ref osMemoryPoolGetCount, \ref osMemoryPoolGetSpace
766 - \ref osMessageQueuePut, \ref osMessageQueueGet, \ref osMessageQueueGetCapacity, \ref osMessageQueueGetMsgSize,
767 \ref osMessageQueueGetCount, \ref osMessageQueueGetSpace
769 Functions that cannot be called from an ISR are verifying the interrupt status and return the status code \b osErrorISR, in
770 case they are called from an ISR context. In some implementations, this condition might be caught using the HARD_FAULT
774 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
776 \page config_rtx5 Configure RTX v5
778 The file "RTX_Config.h" defines the configuration parameters of CMSIS-RTOS RTX and must be part of every project that is
779 using the CMSIS-RTOS RTX kernel. The configuration options are explained in detail in the following sections:
780 - \ref systemConfig covers system-wide settings for the global memory pool, tick frequency, ISR event buffer and round-robin thread switching.
781 - \ref threadConfig provides several parameters to configure the \ref CMSIS_RTOS_ThreadMgmt functions.
782 - \ref timerConfig provides several parameters to configure the \ref CMSIS_RTOS_TimerMgmt functions.
783 - \ref eventFlagsConfig provides several parameters to configure the \ref CMSIS_RTOS_EventFlags functions.
784 - \ref mutexConfig provides several parameters to configure the \ref CMSIS_RTOS_MutexMgmt functions.
785 - \ref semaphoreConfig provides several parameters to configure the \ref CMSIS_RTOS_SemaphoreMgmt functions.
786 - \ref memPoolConfig provides several parameters to configure the \ref CMSIS_RTOS_PoolMgmt functions.
787 - \ref msgQueueConfig provides several parameters to configure the \ref CMSIS_RTOS_Message functions.
789 The file "RTX_Config.c" contains default implementations of the functions \ref osRtxIdleThread and \ref osRtxErrorNotify. Both functions
790 can simply be overwritten with a custimized behavior by redefining them as part of the user code.
792 The configuration file uses <b>Configuration Wizard Annotations</b>. Refer to <b>Pack - Configuration Wizard Annotations</b> for details.
793 Depending on the development tool, the annotations might lead to a more user-friendly graphical representation of the
794 settings. The screenshot below is a screenshot from the µVision \b Configuration \b Wizard view:
796 \image html config_wizard.png "RTX_Config.h in Configuration Wizard View"
798 Alternatively one can provide configuration options using the compiler command line.
800 For example one can customize the used tick frequency to 100us by (overwriting) the configuration using
802 cc -DOS_TICK_FREQ=100
805 \section systemConfig System Configuration
807 The system configuration covers system-wide settings for the global memory pool, tick frequency, ISR event buffer and
808 round-robin thread switching.
810 <b>System Configuration Options</b>
811 \image html config_wizard_system.png "RTX_Config.h: System Configuration"
813 Name | \#define | Description
814 ---------------------------------------|--------------------------|----------------------------------------------------------------
815 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.
816 Kernel Tick Frequency (Hz) | \c OS_TICK_FREQ | Defines base time unit for delays and timeouts in Hz. Default: 1000Hz = 1ms period.
817 Round-Robin Thread switching | \c OS_ROBIN_ENABLE | Enables Round-Robin Thread switching.
818 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]}.
819 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}.
821 \subsection systemConfig_glob_mem Global dynamic memory
822 Refer to \ref GlobalMemoryPool.
825 \subsection systemConfig_rr Round-Robin Thread Switching
827 RTX5 may be configured to use round-robin multitasking thread switching. Round-robin allows quasi-parallel execution of
828 several threads of the \a same priority. Threads are not really executed concurrently, but are scheduled where the available
829 CPU time is divided into time slices and RTX5 assigns a time slice to each thread. Because the time slice is typically short
830 (only a few milliseconds), it appears as though threads execute simultaneously.
832 Round-robin thread switching functions as follows:
833 - the tick is preloaded with the timeout value when a thread switch occurs
834 - the tick is decremented (if not already zero) each system tick if the same thread is still executing
835 - when the tick reaches 0 it indicates that a timeout has occurred. If there is another thread ready with the \a same
836 priority, then the system switches to that thread and the tick is preloaded with timeout again.
838 In other words, threads execute for the duration of their time slice (unless a thread's time slice is given up). Then, RTX
839 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
840 ready to run, the current running thread resumes it execution.
842 \note When switching to higher priority threads, the round-robin timeout value is reset.
844 Round-Robin multitasking is controlled with the <b>\#define OS_ROBIN_ENABLE</b>. The time slice period is configured (in RTX
845 timer ticks) with the <b>\#define OS_ROBIN_TIMEOUT</b>.
848 \subsection systemConfig_isr_fifo ISR FIFO Queue
849 The RTX functions (\ref CMSIS_RTOS_ISR_Calls), when called from and interrupt handler, store the request type and optional
850 parameter to the ISR FIFO queue buffer to be processed later, after the interrupt handler exits.
852 The scheduler is activated immediately after the IRQ handler has finished its execution to process the requests stored to the
853 FIFO queue buffer. The required size of this buffer depends on the number of functions that are called within the interrupt
854 handler. An insufficient queue size will be caught by \b osRtxErrorNotify with error code \b osRtxErrorISRQueueOverflow.
857 \section threadConfig Thread Configuration
859 The RTX5 provides several parameters to configure the \ref CMSIS_RTOS_ThreadMgmt functions.
861 <b>Thread Configuration Options</b>
862 \image html config_wizard_threads.png "RTX_Config.h: Thread Configuration"
865 Option | \#define | Description
866 :--------------------------------------------------------|:-----------------------|:---------------------------------------------------------------
867 Object specific Memory allocation | \c OS_THREAD_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
868 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]}.
869 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]}.
870 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}.
871 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}.
872 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}.
873 Stack overrun checking | \c OS_STACK_CHECK | Enable stack overrun checks at thread switch.
874 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.
875 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.
877 \subsection threadConfig_countstack Configuration of Thread Count and Stack Space
879 The RTX5 kernel uses a separate stack space for each thread and provides two methods for defining the stack requirements:
880 - <b>Static allocation</b>: when \ref osThreadAttr_t::stack_mem and \ref osThreadAttr_t::stack_size specify a memory area
881 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.
882 - <b>Dynamic allocation</b>: when \ref osThreadAttr_t is NULL or \ref osThreadAttr_t::stack_mem is NULL, the system
883 allocates the stack memory from:
884 - Object-specific Memory Pool (default Stack size) when "Object specific Memory allocation" is enabled and "Number of
885 user Threads with default Stack size" is not \token{0} and \ref osThreadAttr_t::stack_size is \token{0} (or
886 \ref osThreadAttr_t is NULL).
887 - Object-specific Memory Pool (user-provided Stack size) when "Object specific Memory allocation" is enabled and "Total
888 Stack size for user..." is not \token{0} and \ref osThreadAttr_t::stack_size is not \token{0}.
889 - Global Memory Pool when "Object specific Memory allocation" is disabled or (\ref osThreadAttr_t::stack_size is not
890 \token{0} and "Total Stack size for user..." is \token{0}) or (\ref osThreadAttr_t::stack_size is \token{0} and
891 "Number of user Threads with default Stack size" is \token{0}).
893 \ref osThreadAttr_t is a parameter of the function \ref osThreadNew.
896 Before the RTX kernel is started by the \ref osKernelStart() function, the main stack defined in startup_<i>device</i>.s is
897 used. The main stack is also used for:
898 - user application calls to RTX functions in \b thread \b mode using SVC calls
899 - interrupt/exception handlers.
901 \subsection threadConfig_ovfcheck Stack Overflow Checking
902 RTX5 implements a software stack overflow checking that traps stack overruns. Stack is used for return addresses and
903 automatic variables. Extensive usage or incorrect stack configuration may cause a stack overflow. Software stack overflow
904 checking is controlled with the define \c OS_STACK_CHECK.
906 If a stack overflow is detected, the function \b osRtxErrorNotify with error code \b osRtxErrorStackUnderflow is called. By
907 default, this function is implemented as an endless loop and will practically stop code execution.
909 \subsection threadConfig_watermark Stack Usage Watermark
910 RTX5 initializes thread stack with a watermark pattern (0xCC) when a thread is created. This allows the debugger to determine
911 the maximum stack usage for each thread. It is typically used during development but removed from the final application.
912 Stack usage watermark is controlled with the define \c OS_STACK_WATERMARK.
914 Enabling this option significantly increases the execution time of \ref osThreadNew (depends on thread stack size).
916 \subsection threadConfig_procmode Processor Mode for Thread Execution
917 RTX5 allows to execute threads in unprivileged or privileged processor mode. The processor mode is controlled with the
918 define \c OS_PRIVILEGE_MODE.
920 In \b unprivileged processor mode, the application software:
921 - has limited access to the MSR and MRS instructions, and cannot use the CPS instruction.
922 - cannot access the system timer, NVIC, or system control block.
923 - might have restricted access to memory or peripherals.
925 In \b privileged processor mode, the application software can use all the instructions and has access to all resources.
928 \section timerConfig Timer Configuration
930 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_TimerMgmt functions.
932 <b>Timer Configuration Options</b>
933 \image html config_wizard_timer.png "RTX_Config.h: Timer Configuration"
935 Name | \#define | Description
936 ---------------------------------------|--------------------------|----------------------------------------------------------------
937 Object specific Memory allocation | \c OS_TIMER_OBJ_MEM | Enables object specific memory allocation.
938 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]}.
939 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}
940 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}.
941 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]}.
943 \subsection timerConfig_obj Object-specific memory allocation
944 See \ref ObjectMemoryPool.
946 \subsection timerConfig_user User Timer Thread
947 The RTX5 function \b osRtxTimerThread executes callback functions when a time period expires. The priority of the timer
948 subsystem within the complete RTOS system is inherited from the priority of the \b osRtxTimerThread. This is configured by
949 \c OS_TIMER_THREAD_PRIO. Stack for callback functions is supplied by \b osRtxTimerThread. \c OS_TIMER_THREAD_STACK_SIZE must
950 satisfy the stack requirements of the callback function with the highest stack usage.
953 \section eventFlagsConfig Event Flags Configuration
955 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_EventFlags functions.
957 <b>Event Configuration Options</b>
958 \image html config_wizard_eventFlags.png "RTX_Config.h: Event Flags Configuration"
960 Name | \#define | Description
961 ---------------------------------------|--------------------------|----------------------------------------------------------------
962 Object specific Memory allocation | \c OS_EVFLAGS_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
963 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]}.
965 \subsection eventFlagsConfig_obj Object-specific memory allocation
966 When object-specific memory is used, the pool size for all Event objects is specified by \c OS_EVFLAGS_NUM. Refer to
967 \ref ObjectMemoryPool.
970 \section mutexConfig Mutex Configuration
971 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_MutexMgmt functions.
973 <b>Mutex Configuration Options</b>
974 \image html config_wizard_mutex.png "RTX_Config.h: Mutex Configuration"
977 Name | \#define | Description
978 ---------------------------------------|--------------------------|----------------------------------------------------------------
979 Object specific Memory allocation | \c OS_MUTEX_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
980 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]}.
982 \subsection mutexConfig_obj Object-specific Memory Allocation
983 When object-specific memory is used, the pool size for all Mutex objects is specified by \c OS_MUTEX_NUM. Refer to
984 \ref ObjectMemoryPool.
987 \section semaphoreConfig Semaphore Configuration
989 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_SemaphoreMgmt functions.
991 <b>Semaphore Configuration Options</b>
992 \image html config_wizard_semaphore.png "RTX_Config.h: Semaphore Configuration"
995 Name | \#define | Description
996 ---------------------------------------|--------------------------|----------------------------------------------------------------
997 Object specific Memory allocation | \c OS_SEMAPHORE_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
998 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]}.
1000 \subsection semaphoreConfig_obj Object-specific memory allocation
1001 When Object-specific Memory is used, the pool size for all Semaphore objects is specified by \c OS_SEMAPHORE_NUM. Refer to
1002 \ref ObjectMemoryPool.
1005 \section memPoolConfig Memory Pool Configuration
1007 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_PoolMgmt functions.
1009 <b>Memory Pool Configuration Options</b>
1010 \image html config_wizard_memPool.png "RTX_Config.h: Memory Pool Configuration"
1012 Name | \#define | Description
1013 ---------------------------------------|--------------------------|----------------------------------------------------------------
1014 Object specific Memory allocation | \c OS_MEMPOOL_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1015 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]}.
1016 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}.
1018 \subsection memPoolConfig_obj Object-specific memory allocation
1019 When object-specific memory is used, the number of pools for all MemoryPool objects is specified by \c OS_MEMPOOL_NUM. The
1020 total storage size reserved for all pools is configured in \c OS_MEMPOOL_DATA_SIZE. Refer to \ref ObjectMemoryPool.
1023 \section msgQueueConfig Message Queue Configuration
1025 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_Message functions.
1027 <b>MessageQueue Configuration Options</b>
1028 \image html config_wizard_msgQueue.png "RTX_Config.h: Message Queue Configuration"
1030 Name | \#define | Description
1031 ---------------------------------------|--------------------------|----------------------------------------------------------------
1032 Object specific Memory allocation | \c OS_MSGQUEUE_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1033 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]}.
1034 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}.
1036 \subsection msgQueueConfig_obj Object-specific memory allocation
1037 When Object-specific Memory is used, the number of queues for all Message Queue objects is specified by \c OS_MSGQUEUE_NUM.
1038 The total storage size reserved for all queues is configured in \c OS_MSGQUEUE_DATA_SIZE. Refer to \ref ObjectMemoryPool.
1042 /* ========================================================================================================================== */
1044 \page creating_RTX5_LIB Building the RTX5 Library
1046 The CMSIS Pack contains a µVision project for building the complete set of RTX5 libraries. This project can also be used as
1047 a reference for building the RTX5 libraries using a tool-chain of your choice.
1049 -# Open the project \b RTX_CM.uvprojx from the pack folder <b>CMSIS/RTOS2/RTX/Library/ARM/MDK</b> in µVision.
1050 -# Select the project target that matches your device's processor core.
1051 \n The project provides target configuration for all supported Cortex-M targets supported by RTX5.
1052 -# You can find out about the required preprocessor defines in the dialogs <b>Options for Target - C/C++</b> and
1053 <b>Options for Target - Asm</b>. Note the need to use at least the C99 compiler mode when building RTX from source.
1054 -# From the <b>Project</b> window you find the list of source files required for a complete library build.
1055 -# Build the library of your choice using \b Project - \b Build \b Target (or press F7).
1057 \image html own_lib_projwin.png "Project with files for ARMv8-M Mainline"
1061 /* ========================================================================================================================== */
1063 \page dirstructfiles5 Directory Structure and File Overview
1065 The following section provides an overview of the directory structure and the files that are relevant for the user's for
1066 CMSIS-RTOS RTX v5. The following directory references start below the CMSIS pack installation path, for example
1067 ARM/CMSIS/<i>version</i>/CMSIS/RTOS2.
1069 \section Folders RTX v5 Directory Structure
1071 The CMSIS-RTOS RTX v5 is delivered in source code and several examples are provided.
1073 <table class="cmtable" summary="CMSIS-RTOS RTX Library Files">
1080 <td>The include file for CMSIS-RTOS API v2. cmsis_os2.h is the central include file for user applications.</td>
1084 <td>CMSIS-RTOS API template source and header file.</td>
1088 <td>Directory with RTX specific files and folders. Also contains the component viewer description file.</td>
1092 <td>CMSIS-RTOS RTX configuration files %RTX_Config.h and %RTX_Config.c.</td>
1095 <td>RTX/Examples</td>
1096 <td>Example projects that can be directly used in development tools.</td>
1099 <td>RTX/Include</td>
1100 <td>RTX v5 specific include files.</td>
1103 <td>RTX/Include1</td>
1104 <td>CMSIS-RTOS v1 API header file.</td>
1107 <td>RTX/Library</td>
1108 <td>Pre-built libraries (see next table for details).</td>
1112 <td>Source code that can be used with ARMCC and GCC.</td>
1115 <td>RTX/Template</td>
1116 <td>User code templates for creating application projects with CMSIS-RTOS RTX v5.</td>
1120 \section libFiles RTX v5 Library Files
1122 The CMSIS-RTOS RTX Library is available pre-compiled for ARMCC and GCC compilers and supports all Cortex-M
1123 processor variants in every configuration, including ARM Cortex-M23 and Cortex-M33.
1125 <table class="cmtable" summary="CMSIS-RTOS RTX Library Files">
1127 <th>Library File</th>
1128 <th>Processor Configuration</th>
1131 <td>Library/ARM/RTX_CM0.lib</td>
1132 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Cortex-M0 and M1, little-endian.</td>
1135 <td>Library/ARM/RTX_CM3.lib</td>
1136 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Cortex-M3, M4, and M7 without FPU, little-endian.</td>
1139 <td>Library/ARM/RTX_CM4F.lib</td>
1140 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Cortex-M4 and M7 with FPU, little-endian.</td>
1143 <td>Library/ARM/RTX_V8MB.lib</td>
1144 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, ARMv8-M baseline.</td>
1147 <td>Library/ARM/RTX_V8MBN.lib</td>
1148 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, ARMv8-M baseline, non-secure.</td>
1151 <td>Library/ARM/RTX_V8MM.lib</td>
1152 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, ARMv8-M mainline.</td>
1155 <td>Library/ARM/RTX_V8MMF.lib</td>
1156 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, ARMv8-M mainline with FPU.</td>
1159 <td>Library/ARM/RTX_V8MMFN.lib</td>
1160 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, ARMv8-M mainline with FPU, non-secure.</td>
1163 <td>Library/ARM/RTX_V8MMN.lib</td>
1164 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, ARMv8-M mainline, non-secure.</td>
1167 <td>Library/GCC/libRTX_CM0.a</td>
1168 <td>CMSIS-RTOS libRTX Library for GCC Compiler, Cortex-M0 and M1, little-endian.</td>
1171 <td>Library/GCC/libRTX_CM3.a</td>
1172 <td>CMSIS-RTOS libRTX Library for GCC Compiler, Cortex-M3, M4, and M7 without FPU, little-endian.</td>
1175 <td>Library/GCC/libRTX_CM4F.a</td>
1176 <td>CMSIS-RTOS libRTX Library for GCC Compiler, Cortex-M4 and M7 with FPU, little-endian.</td>
1179 <td>Library/GCC/libRTX_V8MB.a</td>
1180 <td>CMSIS-RTOS libRTX Library for GCC Compiler, ARMv8-M baseline.</td>
1183 <td>Library/GCC/libRTX_V8MBN.a</td>
1184 <td>CMSIS-RTOS libRTX Library for GCC Compiler, ARMv8-M baseline, non-secure.</td>
1187 <td>Library/GCC/libRTX_V8MM.a</td>
1188 <td>CMSIS-RTOS libRTX Library for GCC Compiler, ARMv8-M mainline.</td>
1191 <td>Library/GCC/libRTX_V8MMF.a</td>
1192 <td>CMSIS-RTOS libRTX Library for GCC Compiler, ARMv8-M mainline with FPU.</td>
1195 <td>Library/GCC/libRTX_V8MMFN.a</td>
1196 <td>CMSIS-RTOS libRTX Library for GCC Compiler, ARMv8-M mainline with FPU, non-secure.</td>
1199 <td>Library/GCC/libRTX_V8MMN.a</td>
1200 <td>CMSIS-RTOS libRTX Library for GCC Compiler, ARMv8-M mainline, non-secure.</td>
1205 /* ========================================================================================================================== */
1207 \page technicalData5 Technical Data
1209 \section technicalData_Toolchains Supported Toolchains
1211 Keil RTX5 is developed and tested using the common toolchains and development environments.
1213 \subsection technicalData_Toolchain_ARM ARM Compiler (ARM/Keil MDK, uVision5)
1215 Major parts of RTX5 are developed and optimized using ARM Compiler and ARM/Keil MDK.
1216 The current release is tested with the following versions:
1218 <li>ARM Compiler 5.06 Update 5 (Build 528)</li>
1219 <li>ARM Compiler 6.6.1 (Long Term Maintenance)</li>
1220 <li>ARM Compiler 6.7</li>
1221 <li>RTOS-aware debugging with uVision 5.24</li>
1224 \subsection technicalData_Toolchain_IAR IAR Embedded Workbench
1226 RTX5 has been ported to fully support IAR Embedded Workbench. The following releases are known to work:
1228 <li>IAR Embedded Workbench 7.7 (<a href="https://github.com/ARM-software/CMSIS_5/issues/201">community report</a>)</li>
1229 <li>IAR Embedded Workbench 7.80.4</li>
1230 <li>IAR Embedded Workbench 8.10</li>
1233 \subsection technicalData_Toolchain_GCC GNU Compiler Collection
1235 RTX5 has also been ported to support GCC, maintenance mainly relays on community contribution.
1236 Active development is currently tested with:
1238 <li>GCC 5.4 Release Series</li>
1241 \section technicalData5_ControlBlockSizes Control Block Sizes
1243 Keil RTX5 specific control block definitions (including sizes) as well as memory pool and message queue memory requirements
1244 are defined in the RTX5 header file:
1247 /// Control Block sizes
1248 #define osRtxThreadCbSize sizeof(osRtxThread_t)
1249 #define osRtxTimerCbSize sizeof(osRtxTimer_t)
1250 #define osRtxEventFlagsCbSize sizeof(osRtxEventFlags_t)
1251 #define osRtxMutexCbSize sizeof(osRtxMutex_t)
1252 #define osRtxSemaphoreCbSize sizeof(osRtxSemaphore_t)
1253 #define osRtxMemoryPoolCbSize sizeof(osRtxMemoryPool_t)
1254 #define osRtxMessageQueueCbSize sizeof(osRtxMessageQueue_t)
1256 /// Memory size in bytes for Memory Pool storage.
1257 /// \param block_count maximum number of memory blocks in memory pool.
1258 /// \param block_size memory block size in bytes.
1259 #define osRtxMemoryPoolMemSize(block_count, block_size) \
1260 (4*(block_count)*(((block_size)+3)/4))
1262 /// Memory size in bytes for Message Queue storage.
1263 /// \param msg_count maximum number of messages in queue.
1264 /// \param msg_size maximum message size in bytes.
1265 #define osRtxMessageQueueMemSize(msg_count, msg_size) \
1266 (4*(msg_count)*(3+(((msg_size)+3)/4)))
1269 If you are using a \ref GlobalMemoryPool to allocate memory for the RTOS objects, you need to know the size that is required
1270 for each object in case of errors. Currently, the control block sizes are as follows (subject to change without
1273 Type | Control block size in bytes |
1274 --------------|:---------------------------:|
1281 Message Queue | 52 |
1283 The size of the memory that is required for memory pool and message queue data storage can be determined from the macros
1288 /* ========================================================================================================================== */
1290 \page misraCompliance5 MISRA-C Compliance Exceptions
1291 CMSIS-RTOS RTX tries to be MISRA-C compliant as much as possible. However, there are some violations in order to simplify
1292 the overall code logic and to generate more efficient code.
1294 This page will list the MISRA-C compliance exceptions. Work in progress.
1297 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1299 \page rtosValidation RTOS Validation
1301 ARM offers a <a class=el href="http://www.keil.com/pack" target="_blank">Software Pack</a> for the CMSIS-RTOS Validation.
1302 The <b>ARM::CMSIS-RTOS_Validation</b> Pack contains the following:
1304 - Source code of a CMSIS-RTOS Validation Suite along with configuration file.
1305 - Documentation of the CMSIS-RTOS Validation Suite.
1306 - Example that shows the usage of the CMSIS-RTOS Validation Suite using simulation.
1309 Currently, a public version of the test suite is available only for CMSIS-RTOS v1 API.
1311 The CMSIS-RTOS Validation Suite performs generic validation of various RTOS features. The test cases verify the
1312 functional behavior, test invalid parameters and call management functions from ISR.
1314 The following CMSIS-RTOS features can be tested with the current release:
1315 - Thread : Create multiple threads, terminate, restart, yield, change priority
1316 - Timer : Create periodic and one-shot timers
1317 - GenWait : Call generic wait functions (osDelay and osWait)
1318 - WaitFunc : Measure wait ticks (delay, mail, message, mutex, semaphore, signal)
1320 Moreover the following inter-thread communication functions can be tested:
1321 - Signal : Verify signal events
1322 - Memory Pool : Verify memory allocation
1323 - Message Queue : Exchange messages between threads
1324 - Mail Queue : Exchange data between threads
1325 - Mutex : Synchronize resource access
1326 - Semaphore : Access shared resources
1328 The RTOS Validation output can be printed to a console, output via ITM printf, or output to a memory buffer.
1330 \section test_output Sample Test Output
1332 CMSIS-RTOS Test Suite Oct 21 2015 16:39:16
1334 TEST 01: TC_ThreadCreate PASSED
1335 TEST 02: TC_ThreadMultiInstance PASSED
1336 TEST 03: TC_ThreadTerminate PASSED
1339 TEST 08: TC_ThreadChainedCreate PASSED
1340 TEST 09: TC_ThreadYield NOT EXECUTED
1341 TEST 10: TC_ThreadParam PASSED
1344 TEST 60: TC_MailFromISRToThread PASSED
1346 Test Summary: 60 Tests, 59 Executed, 59 Passed, 0 Failed, 0 Warnings.
1352 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1354 \page functionOverview Function Overview
1356 CMSIS-RTOS v2 provides multiple API interfaces:
1357 - \subpage rtos_api2 is the new C function API that supports dynamic object creation and ARMv8-M (ARM Cortex-M23 and
1359 - <a class="el" href="../../RTOS/html/functionOverview.html">CMSIS-RTOS C API v1</a> is a C function API that is backward
1360 compatible with CMSIS-RTOS v1.
1361 - \subpage rtos_apicpp is a C++ class function API.
1363 It is possible to intermix the different API variants in the same application and even in the same C/C++ source module.
1364 However, the functions of the <b>C API Version 1</b> may be deprecated in future versions of CMSIS-RTOS.
1366 \section rtos_api2 CMSIS-RTOS2
1368 Overview of all CMSIS-RTOS C API v2 functions that are implemented in the \subpage cmsis_os2_h.
1370 - \ref CMSIS_RTOS_KernelCtrl
1371 - \ref osKernelGetInfo : \copybrief osKernelGetInfo
1372 - \ref osKernelGetState : \copybrief osKernelGetState
1373 - \ref osKernelGetSysTimerCount : \copybrief osKernelGetSysTimerCount
1374 - \ref osKernelGetSysTimerFreq : \copybrief osKernelGetSysTimerFreq
1375 - \ref osKernelInitialize : \copybrief osKernelInitialize
1376 - \ref osKernelLock : \copybrief osKernelLock
1377 - \ref osKernelUnlock : \copybrief osKernelUnlock
1378 - \ref osKernelRestoreLock : \copybrief osKernelRestoreLock
1379 - \ref osKernelResume : \copybrief osKernelResume
1380 - \ref osKernelStart : \copybrief osKernelStart
1381 - \ref osKernelSuspend : \copybrief osKernelSuspend
1382 - \ref osKernelGetTickCount : \copybrief osKernelGetTickCount
1383 - \ref osKernelGetTickFreq : \copybrief osKernelGetTickFreq
1385 - \ref CMSIS_RTOS_ThreadMgmt
1386 - \ref osThreadDetach : \copybrief osThreadDetach
1387 - \ref osThreadEnumerate : \copybrief osThreadEnumerate
1388 - \ref osThreadExit : \copybrief osThreadExit
1389 - \ref osThreadGetCount : \copybrief osThreadGetCount
1390 - \ref osThreadGetId : \copybrief osThreadGetId
1391 - \ref osThreadGetName : \copybrief osThreadGetName
1392 - \ref osThreadGetPriority : \copybrief osThreadGetPriority
1393 - \ref osThreadGetStackSize : \copybrief osThreadGetStackSize
1394 - \ref osThreadGetStackSpace : \copybrief osThreadGetStackSpace
1395 - \ref osThreadGetState : \copybrief osThreadGetState
1396 - \ref osThreadJoin : \copybrief osThreadJoin
1397 - \ref osThreadNew : \copybrief osThreadNew
1398 - \ref osThreadResume : \copybrief osThreadResume
1399 - \ref osThreadSetPriority : \copybrief osThreadSetPriority
1400 - \ref osThreadSuspend : \copybrief osThreadSuspend
1401 - \ref osThreadTerminate : \copybrief osThreadTerminate
1402 - \ref osThreadYield : \copybrief osThreadYield
1404 - \ref CMSIS_RTOS_ThreadFlagsMgmt
1405 - \ref osThreadFlagsSet : \copybrief osThreadFlagsSet
1406 - \ref osThreadFlagsClear : \copybrief osThreadFlagsClear
1407 - \ref osThreadFlagsGet : \copybrief osThreadFlagsGet
1408 - \ref osThreadFlagsWait : \copybrief osThreadFlagsWait
1410 - \ref CMSIS_RTOS_EventFlags
1411 - \ref osEventFlagsGetName : \copybrief osEventFlagsGetName
1412 - \ref osEventFlagsNew : \copybrief osEventFlagsNew
1413 - \ref osEventFlagsDelete : \copybrief osEventFlagsDelete
1414 - \ref osEventFlagsSet : \copybrief osEventFlagsSet
1415 - \ref osEventFlagsClear : \copybrief osEventFlagsClear
1416 - \ref osEventFlagsGet : \copybrief osEventFlagsGet
1417 - \ref osEventFlagsWait : \copybrief osEventFlagsWait
1419 - \ref CMSIS_RTOS_Wait
1420 - \ref osDelay : \copybrief osDelay
1421 - \ref osDelayUntil : \copybrief osDelayUntil
1423 - \ref CMSIS_RTOS_TimerMgmt
1424 - \ref osTimerDelete : \copybrief osTimerDelete
1425 - \ref osTimerGetName : \copybrief osTimerGetName
1426 - \ref osTimerIsRunning : \copybrief osTimerIsRunning
1427 - \ref osTimerNew : \copybrief osTimerNew
1428 - \ref osTimerStart : \copybrief osTimerStart
1429 - \ref osTimerStop : \copybrief osTimerStop
1431 - \ref CMSIS_RTOS_MutexMgmt
1432 - \ref osMutexAcquire : \copybrief osMutexAcquire
1433 - \ref osMutexDelete : \copybrief osMutexDelete
1434 - \ref osMutexGetName : \copybrief osMutexGetName
1435 - \ref osMutexGetOwner : \copybrief osMutexGetOwner
1436 - \ref osMutexNew : \copybrief osMutexNew
1437 - \ref osMutexRelease : \copybrief osMutexRelease
1439 - \ref CMSIS_RTOS_SemaphoreMgmt
1440 - \ref osSemaphoreAcquire : \copybrief osSemaphoreAcquire
1441 - \ref osSemaphoreDelete : \copybrief osSemaphoreDelete
1442 - \ref osSemaphoreGetCount : \copybrief osSemaphoreGetCount
1443 - \ref osSemaphoreGetName : \copybrief osSemaphoreGetName
1444 - \ref osSemaphoreNew : \copybrief osSemaphoreNew
1445 - \ref osSemaphoreRelease : \copybrief osSemaphoreRelease
1447 - \ref CMSIS_RTOS_PoolMgmt
1448 - \ref osMemoryPoolAlloc : \copybrief osMemoryPoolAlloc
1449 - \ref osMemoryPoolDelete : \copybrief osMemoryPoolDelete
1450 - \ref osMemoryPoolFree : \copybrief osMemoryPoolFree
1451 - \ref osMemoryPoolGetBlockSize : \copybrief osMemoryPoolGetBlockSize
1452 - \ref osMemoryPoolGetCapacity : \copybrief osMemoryPoolGetCapacity
1453 - \ref osMemoryPoolGetCount : \copybrief osMemoryPoolGetCount
1454 - \ref osMemoryPoolGetName : \copybrief osMemoryPoolGetName
1455 - \ref osMemoryPoolGetSpace : \copybrief osMemoryPoolGetSpace
1456 - \ref osMemoryPoolNew : \copybrief osMemoryPoolNew
1458 - \ref CMSIS_RTOS_Message
1459 - \ref osMessageQueueDelete : \copybrief osMessageQueueDelete
1460 - \ref osMessageQueueGet : \copybrief osMessageQueueGet
1461 - \ref osMessageQueueGetCapacity : \copybrief osMessageQueueGetCapacity
1462 - \ref osMessageQueueGetCount : \copybrief osMessageQueueGetCount
1463 - \ref osMessageQueueGetMsgSize : \copybrief osMessageQueueGetMsgSize
1464 - \ref osMessageQueueGetName : \copybrief osMessageQueueGetName
1465 - \ref osMessageQueueGetSpace : \copybrief osMessageQueueGetSpace
1466 - \ref osMessageQueueNew : \copybrief osMessageQueueNew
1467 - \ref osMessageQueuePut : \copybrief osMessageQueuePut
1468 - \ref osMessageQueueReset : \copybrief osMessageQueueReset
1470 - \ref CMSIS_RTOS_TickAPI
1471 - \ref OS_Tick_Setup : \copybrief OS_Tick_Setup
1472 - \ref OS_Tick_Enable : \copybrief OS_Tick_Enable
1473 - \ref OS_Tick_Disable : \copybrief OS_Tick_Disable
1474 - \ref OS_Tick_AcknowledgeIRQ : \copybrief OS_Tick_AcknowledgeIRQ
1475 - \ref OS_Tick_GetIRQn : \copybrief OS_Tick_GetIRQn
1476 - \ref OS_Tick_GetClock : \copybrief OS_Tick_GetClock
1477 - \ref OS_Tick_GetInterval : \copybrief OS_Tick_GetInterval
1478 - \ref OS_Tick_GetCount : \copybrief OS_Tick_GetCount
1479 - \ref OS_Tick_GetOverflow : \copybrief OS_Tick_GetOverflow
1481 - \ref rtx5_specific
1482 - \ref osRtxErrorNotify : \copybrief osRtxErrorNotify
1483 - \ref osRtxIdleThread : \copybrief osRtxIdleThread
1485 The following CMSIS-RTOS2 functions can be called from threads and \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines"
1487 - \ref osKernelGetInfo, \ref osKernelGetState,
1488 \ref osKernelGetTickCount, \ref osKernelGetTickFreq, \ref osKernelGetSysTimerCount, \ref osKernelGetSysTimerFreq
1489 - \ref osThreadFlagsSet
1490 - \ref osEventFlagsSet, \ref osEventFlagsClear, \ref osEventFlagsGet, \ref osEventFlagsWait
1491 - \ref osSemaphoreAcquire, \ref osSemaphoreRelease, \ref osSemaphoreGetCount
1492 - \ref osMemoryPoolAlloc, \ref osMemoryPoolFree, \ref osMemoryPoolGetCapacity, \ref osMemoryPoolGetBlockSize,
1493 \ref osMemoryPoolGetCount, \ref osMemoryPoolGetSpace
1494 - \ref osMessageQueuePut, \ref osMessageQueueGet, \ref osMessageQueueGetCapacity, \ref osMessageQueueGetMsgSize,
1495 \ref osMessageQueueGetCount, \ref osMessageQueueGetSpace
1499 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1501 \page rtos_apicpp CMSIS-RTOS C++ API
1503 A C++11/C++14 interface is planned for the future.
1507 /* ======================================================================================================================== */
1508 // Group creation for Reference
1510 \addtogroup CMSIS_RTOS1 CMSIS-RTOS API v1
1511 \brief This section describes the CMSIS-RTOS API v1.
1513 The CMSIS-RTOS is a generic API layer that interfaces to an existing RTOS kernel.
1515 CMSIS-RTOS API v2 provides an translation layer for the
1516 <a class="el" href="../../RTOS/html/index.html">CMSIS-RTOS API v1</a> that simplifies migration.
1518 Refer to the <a class="el" href="../../RTOS/html/modules.html">Reference</a> guide of the CMSIS-RTOS API v1 for details.
1521 // Group creation for Reference
1523 \addtogroup CMSIS_RTOS CMSIS-RTOS2 API
1524 \brief Describes the C function interface of CMSIS-RTOS API v2.
1526 The CMSIS-RTOS2 is a generic API layer that interfaces to an RTOS kernel.
1528 The complete API interface is defined in the \ref cmsis_os2_h. When using dynamic memory allocation for objects, source code
1529 or libraries require no modifications when using on a different CMSIS-RTOS2 implementation.
1533 \addtogroup rtx5_specific RTX5 Specific API
1534 \brief This section describes CMSIS-RTOS RTX5 specifics.
1536 The RTX5 kernel can be customized for different application requirements:
1537 - If you are depending on the \ref lowPower "lowest power consumption" possible, you need to adapt the function
1538 \ref osRtxIdleThread to send the system to sleep mode as often as possible. In addition, use the
1539 \ref TickLess "tick-less low power" functions \ref osKernelSuspend and \ref osKernelResume to suspend the scheduler and to
1540 stop the SysTick timer.
1541 - If you try to find a \b runtime \b error, use the function \ref osRtxErrorNotify to debug the error.
1543 RTX5 interfaces to the <a href="http://www.keil.com/pack/doc/compiler/EventRecorder/html/index.html" target="_blank"><b>Event Recorder</b></a>
1544 to provide event information which helps you to understand and analyze the operation. Refer to \ref rtx_evr for more
1552 \defgroup rtx5_specific_defines Macros
1558 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1560 \def osRtxThreadCbSize
1563 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1565 \def osRtxTimerCbSize
1568 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1570 \def osRtxEventFlagsCbSize
1573 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1575 \def osRtxMutexCbSize
1578 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1580 \def osRtxSemaphoreCbSize
1583 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1585 \def osRtxMemoryPoolCbSize
1588 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1590 \def osRtxMessageQueueCbSize
1593 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1595 \def osRtxMemoryPoolMemSize
1598 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1600 \def osRtxMessageQueueMemSize
1608 \defgroup rtx5_specific_structs Structs
1614 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1616 \struct osRtxThread_t
1619 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1621 \struct osRtxTimerFinfo_t
1624 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1626 \struct osRtxTimer_t
1629 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1631 \struct osRtxEventFlags_t
1634 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1636 \struct osRtxMutex_t
1639 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1641 \struct osRtxSemaphore_t
1644 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1646 \struct osRtxMemoryPool_t
1649 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1651 \struct osRtxMessageQueue_t
1659 \defgroup rtx5_specific_functions Functions
1660 \brief RTX5 functions
1665 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1667 \fn uint32_t osRtxErrorNotify (uint32_t code, void *object_id);
1669 Some system error conditions can be detected during runtime. If the RTX kernel detects a runtime error, it calls the runtime
1670 error function \b osRtxErrorNotify for an object specified by parameter \a object_id.
1672 The parameter \a code passes the actual error code to this function:
1673 | Error Code | Description |
1674 |------------------------------|-----------------------------------------------------------------------------------|
1675 | osRtxErrorStackUnderflow | Stack underflow detected for thread (thread_id=object_id) |
1676 | osRtxErrorISRQueueOverflow | ISR Queue overflow detected when inserting object (object_id) |
1677 | osRtxErrorTimerQueueOverflow | User Timer Callback Queue overflow detected for timer (timer_id=object_id) |
1678 | osRtxErrorClibSpace | Standard C/C++ library libspace not available: increase \c OS_THREAD_LIBSPACE_NUM |
1679 | osRtxErrorClibMutex | Standard C/C++ library mutex initialization failed |
1681 The function \b osRtxErrorNotify must contain an infinite loop to prevent further program execution. You can use an emulator
1682 to step over the infinite loop and trace into the code introducing a runtime error. For the overflow errors this means you
1683 need to increase the size of the object causing an overflow.
1685 \note Cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
1691 uint32_t osRtxErrorNotify (uint32_t code, void *object_id) {
1695 case osRtxErrorStackUnderflow:
1696 // Stack underflow detected for thread (thread_id=object_id)
1698 case osRtxErrorISRQueueOverflow:
1699 // ISR Queue overflow detected when inserting object (object_id)
1701 case osRtxErrorTimerQueueOverflow:
1702 // User Timer Callback Queue overflow detected for timer (timer_id=object_id)
1704 case osRtxErrorClibSpace:
1705 // Standard C/C++ library libspace not available: increase OS_THREAD_LIBSPACE_NUM
1707 case osRtxErrorClibMutex:
1708 // Standard C/C++ library mutex initialization failed
1719 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1720 osRtxErrorClibMutex /**
1721 \fn void osRtxIdleThread (void *argument);
1723 The function \b osRtxIdleThread is executed by the RTX kernel, when no other threads are ready to run. By default, this
1724 thread is an empty end-less loop that does nothing. It only waits until another task becomes ready to run. You may change the
1725 code of the \b osRtxIdleThread function to put the CPU into a power-saving or idle mode, see \ref TickLess.
1727 The default stack size for this thread is defined in the file RTX_Config.h. Refer to \ref threadConfig.
1729 \note Cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
1735 __NO_RETURN void osRtxIdleThread (void *argument) {