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 - Added TrustZone Module Identifier configuration for Idle and Timer Thread.
168 - Moved SVC/PendSV handler priority setup from osKernelInitialize to osKernelStart (User Priority Grouping can be updated after osKernelInitialize but before osKernelStart).
169 - Corrected SysTick and PendSV handlers for ARMv8-M Baseline.
170 - Corrected memory allocation for stack and data when "Object specific Memory allocation" configuration is used.
171 - Added support for ARMv8-M IAR compiler.
177 - Corrected IRQ and SVC exception handlers for Cortex-A.
183 - Corrected SysTick and SVC Interrupt Priority for Cortex-M.
189 - Based on CMSIS-RTOS API V2.1.1.
190 - Added support for for Cortex-A.
191 - Using OS Tick API for RTX Kernel Timer Tick.
192 - Fixed potential corruption of terminated threads list.
193 - Corrected MessageQueue to use actual message length (before padding).
194 - Corrected parameters for ThreadEnumerate and MessageQueueInserted events.
195 - Timer Thread creation moved to osKernelStart.
201 - Based on CMSIS-RTOS API V2.1.0.
202 - Added support for Event recording.
203 - Added support for IAR compiler.
204 - Updated configuration files: RTX_Config.h for the configuration settings and RTX_config.c for implementing the \ref rtx5_specific.
205 - osRtx name-space for RTX specific symbols.
211 Initial release compliant to CMSIS-RTOS2.\n
218 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
220 \page genRTOS2IF Generic RTOS Interface
222 CMSIS-RTOS2 is a generic API that is agnostic of the underlying RTOS kernel. Application programmers call CMSIS-RTOS2 API
223 functions in the user code to ensure maximum portability from one RTOS to another. Middleware using CMSIS-RTOS2 API takes
224 advantages of this approach by avoiding unnecessary porting efforts.
226 \image html "API_Structure.png" "CMSIS-RTOS API Structure"
228 A typical CMSIS-RTOS2 API implementation interfaces to an existing real-time kernel. The CMSIS-RTOS2 API provides the
229 following attributes and functionalities:
230 - Function names, identifiers, and parameters are descriptive and easy to understand. The functions are powerful and
231 flexible which reduces the number of functions exposed to the user.
232 - \ref CMSIS_RTOS_ThreadMgmt allows you to define, create, and control threads.
233 - Interrupt Service Routines (ISR) can \ref CMSIS_RTOS_ISR_Calls "call some CMSIS-RTOS functions". When a CMSIS-RTOS
234 function cannot be called from an ISR context, it rejects the invocation and returns an error code.
235 - Three different event types support communication between multiple threads and/or ISR:
236 - \ref CMSIS_RTOS_ThreadFlagsMgmt "Thread Flags": may be used to indicate specific conditions to a thread.
237 - \ref CMSIS_RTOS_EventFlags "Event Flags": may be used to indicate events to a thread or ISR.
238 - \ref CMSIS_RTOS_Message "Messages": can be sent to a thread or an ISR. Messages are buffered in a queue.
239 - \ref CMSIS_RTOS_MutexMgmt and \ref CMSIS_RTOS_SemaphoreMgmt are incorporated.
240 - CPU time can be scheduled with the following functionalities:
241 - A \a timeout parameter is incorporated in many CMSIS-RTOS functions to avoid system lockup. When a timeout is specified,
242 the system waits until a resource is available or an event occurs. While waiting, other threads are scheduled.
243 - The \ref osDelay and \ref osDelayUntil functions put a thread into the \b WAITING state for a specified period of time.
244 - The \ref osThreadYield provides co-operative thread switching and passes execution to another thread of the same
246 - \ref CMSIS_RTOS_TimerMgmt functions are used to trigger the execution of functions.
248 The CMSIS-RTOS2 API is designed to optionally incorporate multi-processor systems and/or access protection via the Cortex-M
249 Memory Protection Unit (MPU).
251 In some RTOS implementations threads may execute on different processors, thus \b message queues may reside in shared memory
254 The CMSIS-RTOS2 API encourages the software industry to evolve existing RTOS implementations. RTOS implementations can be
255 different and optimized in various aspects towards the Cortex-M processors. Optional features may be for example
256 - Support of the Cortex-M Memory Protection Unit (MPU).
257 - Support of multi-processor systems.
258 - Support of a DMA controller.
259 - Deterministic context switching.
260 - Round-robin context switching.
261 - Deadlock avoidance, for example with priority inversion.
262 - Zero interrupt latency by using ARMv7-M instructions LDREX and STREX.
264 \section usingOS2 Using a CMSIS-RTOS2 Implementation
266 A CMSIS-RTOS2 implementation is typically provided as a library. To add the RTOS functionality to an existing CMSIS-based
267 application, the RTOS library (and typically one or more configuration files) needs to be added. There is a single new header
268 file %cmsis_os2.h available. This is the only header file required for a completely portable application. In such a case,
269 user provided memory for control blocks, objects data and thread stack cannot be used. Alternatively, you can include an
270 implementation specific header file (for example rtx_os.h) which provides definitions also for resource allocation (such as
271 size of control blocks, required memory for object data and thread stack). This is optional and implies that the application
272 code is not completely portable.
274 \image html "CMSIS_RTOS_Files.png" "CMSIS-RTOS File Structure"
276 Once the files are added to a project, the user can start working with the CMSIS-RTOS functions. A code example is provided
281 /*----------------------------------------------------------------------------
282 * CMSIS-RTOS 'main' function template
283 *---------------------------------------------------------------------------*/
285 #include "RTE_Components.h"
286 #include CMSIS_device_header
287 #include "cmsis_os2.h"
289 /*----------------------------------------------------------------------------
290 * Application main thread
291 *---------------------------------------------------------------------------*/
292 void app_main (void *argument) {
300 // System Initialization
301 SystemCoreClockUpdate();
302 #ifdef RTE_Compiler_EventRecorder
303 // Initialize and start Event Recorder
304 EventRecorderInitialize(EventRecordError, 1U);
308 osKernelInitialize(); // Initialize CMSIS-RTOS
309 osThreadNew(app_main, NULL, NULL); // Create application main thread
310 osKernelStart(); // Start thread execution
316 \section cmsis_os2_h cmsis_os2.h header file
318 The file \b cmsis_os2.h is a standard header file that interfaces to every CMSIS-RTOS2 compliant real-time operating
319 systems (RTOS). Each implementation is provided the same \b cmsis_os2.h which defines the interface to the \ref rtos_api2.
321 Using the \b cmsis_os2.h along with dynamic object allocation allows to create source code or libraries that require no
322 modifications when using on a different CMSIS-RTOS2 implementation.
324 <b>Header file %cmsis_os2.h</b>
330 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
332 \page rtx5_impl RTX v5 Implementation
334 Keil RTX version 5 (RTX5) implements the CMSIS-RTOS2 as a native RTOS interface for ARM Cortex-M processor-based devices.
335 A translation layer to CMSIS-RTOS API v1 is provided. Therefore, RTX5 can be used in applications that where previously based
336 on RTX version 4 and CMSIS-RTOS version 1 with minimal effort.
338 The following sections provide further details:
339 - \subpage cre_rtx_proj explains how to setup an RTX v5 project in Keil MDK.
340 - \subpage theory_of_operation provides general information about the operation of CMSIS-RTOS RTX v5.
341 - \subpage config_rtx5 describes configuration parameters of CMSIS-RTOS RTX v5.
342 - \subpage creating_RTX5_LIB explains how to build your own CMSIS-RTOS RTX v5 library.
343 - \subpage dirstructfiles5 explains the directories and files that are supplied as part of CMSIS-RTOS RTX v5.
344 - \subpage technicalData5 lists microcontroller hardware requirements and limitations such as number of concurrent threads.
345 - \subpage misraCompliance5 describes the violations to the MISRA standard.
348 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
350 \page cre_rtx_proj Create an RTX5 Project
352 The steps to create a microcontroller application using RTX5 are:
353 - Create a new project and select a microcontroller device.
354 - In the Manage Run-Time Environment window, select <b>CMSIS\::CORE</b> and <b>CMSIS\::RTOS2 (API)\::Keil RTX5</b>. You can
355 choose to either add RTX as a library (Variant: \b Library) or to add the full source code (Variant: \b Source - required
356 if using the <a href="http://www.keil.com/pack/doc/compiler/EventRecorder/html/index.html" target="_blank"><b>Event Recorder</b></a>):
358 \image html manage_rte_output.png
360 - If the <b>Validation Output</b> requires other components to be present, try to use the \b Resolve button.
361 - Click \b OK. In the \b Project window, you will see the files that have been automatically added to you project, such as
362 \b %RTX_Config.h, \b %RTX_Config.c, the library or the source code files, as well as the system and startup files:
364 \image html project_window.png
366 - 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).
367 - You can add template files to the project by right-clicking on <b>Source Group 1</b> and selecting
368 <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
369 you will see all available template files for CMSIS-RTOS RTX:
371 \image html add_item.png
373 - \ref config_rtx5 "Configure" RTX5 to the application's needs using the \b %RTX_Config.h file.
375 \section cre_rtx_cortexa Additional requirements for RTX on Cortex-A
377 Cortex-A based microcontrollers are less unified with respect to the interrupt and timer implementations used compared to
378 M-class devices. Thus RTX requires additional components when an A-class device is used, namely
379 <a href="../../Core_A/html/group__irq__ctrl__gr.html"><b>IRQ Controller (API)</b></a> and \ref CMSIS_RTOS_TickAPI "OS Tick (API)"
382 \image html manage_rte_cortex-a.png
384 The default implementations provided along with CMSIS are
385 - ARM <a href="../../Core_A/html/group__GIC__functions.html">Generic Interrupt Controller (GIC)</a>
386 - ARM Cortex-A5, Cortex-A9 <a href="../../Core_A/html/group__PTM__timer__functions.html">Private Timer (PTIM)</a>
387 - ARM Cortex-A7 <a href="../../Core_A/html/group__PL1__timer__functions.html">Generic Physical Timer (GTIM)</a>
389 For devices not implementing GIC, PTIM nor GTIM please refer to the according device family pack and select the
390 proper implementations.
392 \section cre_rtx_proj_specifics Add support for RTX specific functions
393 If you require some of the \ref rtx5_specific "RTX specific functions" in your application code, \#include the
394 \ref rtx_os_h "header file rtx_os.h". This enables \ref lowPower "low-power" and \ref TickLess "tick-less" operation modes.
396 \section cre_rtx_proj_er Add Event Recorder Visibility
397 - To use the Event Recorder together with RTX5, select the software component <b>Compiler:Event Recorder</b>.
398 - Select the \b Source variant of the software component <b>CMSIS:RTOS2 (API):Keil RTX5</b>.
399 \image html event_recorder_rte.png "Component selection for Event Recorder"
400 - Call the function <b>EventRecorderInitialize()</b> in your application code (ideally in \c main()).
401 - Build the application code and download it to the debug hardware.
403 Once the target application generates event information, it can be viewed in the µVision debugger using the \b Event
408 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
410 \page theory_of_operation Theory of Operation
412 Many aspects of the kernel are configurable and the configuration options are mentioned where applicable.
414 \section SystemStartup System Startup
416 Since main is no longer a thread RTX5 does not interfere with the system startup until main is reached.
417 Once the execution reaches \c main() there is a recommended order to initialize the hardware and start the kernel. This is
418 also reflected in the user code template file "CMSIS-RTOS2 'main' function" supplied with the RTX5 component.
420 Your application's \c main() should implement at least the following in the given order:
421 -# Initialization and configuration of hardware including peripherals, memory, pins, clocks and the interrupt system.
422 -# Update the system core clock using the respective
423 <a href=../../Core/html/group__system__init__gr.html>CMSIS-Core (Cortex-M)</a> or
424 <a href=../../Core_A/html/group__system__init__gr.html>CMSIS-Core (Cortex-A)</a> function.
425 -# Initialize the CMSIS-RTOS kernel using \ref osKernelInitialize.
426 -# Optionally, create a new thread \c app_main, which is used as a main thread using \ref osThreadNew. Alternatively, threads
427 can be created in \c main() directly.
428 -# Start the RTOS scheduler using \ref osKernelStart. This function does not return in case of successful execution. Any
429 application code after \b osKernelStart will not be executed unless \b osKernelStart fails.
431 \note Interrupts (like SVC for example) used by the kernel are initialized in \ref osKernelInitialize. In case priorities and
432 groupings in the NVIC are altered by the application after the above sequence it might be necessary to call
433 \ref osKernelInitialize again. You might observe weird misbehaviour possibly catched by \ref osRtxErrorNotify or causing a hard fault.
435 \note The tick timer is configured during \ref osKernelStart. The tick interval is calculated based on the \c SystemCoreClock variable.
439 RTX5 implements a low-latency preemtive scheduler. Major parts of RTX5 are executed in handler mode such as
440 - \ref SysTick_Handler used for time-based scheduling.
441 - \ref SVC_Handler used for lock-based scheduling.
442 - \ref PendSV_Handler used for interrupt-based scheduling.
444 In order to be low-latency with respect to ISR execution those system exceptions are configured to use the
445 lowest priority groups available. The priorities are configured such that no preemption happens between them. Thus
446 no interrupt critical sections (i.e. interrupt locks) are needed to protect the scheduler.
448 \image html scheduling.png "Thread scheduling and interrupt execution"
450 The scheduler combines priority and round-robin based context switches. The example depicted in the image above contains
451 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
452 (\ref osThreadAttr_t::priority). As long as threads 3 and 4 are blocked the scheduler switches between thread 1 and 2 on
453 a time-slice basis (round-robin). The time-slice for round-robin scheduling can be configured, see Round-Robin Timeout in \ref systemConfig.
455 Thread 2 unblocks thread 3 by an arbitrary RTOS-call (executed in SVC handler mode) at time index 2. The scheduler switches to
456 thread 3 immidiately because thread 3 has the highest priority. Thread 4 is still blocked.
458 At time index 4 an interrupt (ISR) occurs and preempts the SysTick_Handler. RTX does not add any latency to the interrupt
459 service execution. The ISR routine uses an RTOS-call that unblocks thread 4. Instead of switching to thread 4 immediately
460 the PendSV flag is set to defer the context switching. The PendSV_Handler is executed right after the SysTick_Handler returns
461 and the defered context switch to thread 4 is carried out. As soon as highest priority thread 4 blocks again by using
462 a blocking RTOS-call execution is switched back to thread 3 immidiately during time index 5.
464 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.
465 At time index 7 the scheduler uses the round-robin mechanism to switch to thread 1 and so on.
467 \section MemoryAllocation Memory Allocation
469 RTX5 objects (thread, mutex, semaphore, timer, message queue, thread and event flags, as well as memory pool) require
470 dedicated RAM memory. Objects can be created using os<i>Object</i>New() calls and deleted using os<i>Object</i>Delete()
471 calls. The related object memory needs to be available during the lifetime of the object.
473 RTX5 offers three different memory allocation methods for objects:
474 - \ref GlobalMemoryPool uses a single global memory pool for all objects. It is easy to configure, but may have
475 the disadvantage for memory fragmentation when objects with different sizes are created and destroyed.
476 - \ref ObjectMemoryPool uses a fixed-size memory pool for each object type. The method is time deterministic
477 and avoids memory fragmentation.
478 - \ref StaticObjectMemory reserves memory during compile time and completely avoids that a system can be out of memory.
479 This is typically a required for some safety critical systems.
481 It possible to intermix all the memory allocation methods in the same application.
483 \subsection GlobalMemoryPool Global Memory Pool
485 The global memory pool allocates all objects from a memory area. This method of memory allocation is the default
486 configuration setting of RTX5.
488 \image html MemAllocGlob.png "Global Memory Pool for all objects"
490 When the memory pool does not provide sufficient memory, the creation of the object fails and the related
491 os<i>Object</i>New() function returns \token{NULL}.
493 Enabled in \ref systemConfig.
495 \subsection ObjectMemoryPool Object-specific Memory Pools
497 Object-specific memory pools avoids memory fragmentation with a dedicated fixed-size memory management for each object type.
498 This type of memory pools are fully time deterministic, which means that object creation and destruction takes always the
499 same fixed amount of time. As a fixed-size memory pool is specific to an object type, the handling of out-of-memory
500 situations is simplified.
502 \image html MemAllocSpec.png "One memory pool per object type"
504 Object-specific memory pools are selectively enabled for each object type, e.g: mutex or thread using the RTX configuration
506 - Enabled in \ref threadConfig for thread objects.
507 - Enabled in \ref timerConfig for timer objects.
508 - Enabled in \ref eventFlagsConfig for event objects.
509 - Enabled in \ref mutexConfig for mutex objects.
510 - Enabled in \ref semaphoreConfig for semaphore.
511 - Enabled in \ref memPoolConfig for memory pools.
512 - Enabled in \ref msgQueueConfig for message objects.
514 When the memory pool does not provide sufficient memory, the creation of the object fails and the related
515 os<i>Object</i>New() function returns \token{NULL}.
517 \subsection StaticObjectMemory Static Object Memory
518 In contrast to the dynamic memory allocations, the static memory allocation requires compile-time allocation of object memory.
520 \image html MemAllocStat.png "Statically allocated memory for all objects"
522 The following code example shows how to create an OS object using static memory.
524 <b> Code Example:</b>
526 /*----------------------------------------------------------------------------
527 * CMSIS-RTOS 'main' function template
528 *---------------------------------------------------------------------------*/
530 #include "RTE_Components.h"
531 #include CMSIS_device_header
532 #include "cmsis_os2.h"
534 //include rtx_os.h for types of RTX objects
537 //The thread function instanced in this example
538 void worker(void *arg)
547 // Define objects that are statically allocated for worker thread 1
548 osRtxThread_t worker_thread_tcb_1;
550 // Reserve two areas for the stacks of worker thread 1
551 // uint64_t makes sure the memory alignment is 8
552 uint64_t worker_thread_stk_1[64];
554 // Define the attributes which are used for thread creation
555 // Optional const saves RAM memory and includes the values in periodic ROM tests
556 const osThreadAttr_t worker_attr_1 = {
559 &worker_thread_tcb_1,
560 sizeof(worker_thread_tcb_1),
561 &worker_thread_stk_1[0],
562 sizeof(worker_thread_stk_1),
563 osPriorityAboveNormal,
567 // Define ID object for thread
570 /*----------------------------------------------------------------------------
571 * Application main thread
572 *---------------------------------------------------------------------------*/
573 void app_main (void *argument) {
574 uint32_t param = NULL;
576 // Create an instance of the worker thread with static resources (TCB and stack)
577 th1 = osThreadNew(worker, ¶m, &worker_attr_1);
583 // System Initialization
584 SystemCoreClockUpdate();
587 osKernelInitialize(); // Initialize CMSIS-RTOS
588 osThreadNew(app_main, NULL, NULL); // Create application main thread
589 osKernelStart(); // Start thread execution
595 \section ThreadStack Thread Stack Management
597 For Cortex-M processors without floating point unit the thread context requires 64 bytes on the local stack.
599 \note For Cortex-M4/M7 with FP the thread context requires 200 bytes on the local stack. For these devices the default stack
600 space should be increased to a minimum of 300 bytes.
602 Each thread is provided with a separate stack that holds the thread context and stack space for automatic variables and
603 return addresses for function call nesting. The stack sizes of RTX threads are flexibly configurable as explained in the
604 section \ref threadConfig. RTX offers a configurable checking for stack overflows and stack utilization.
607 \section lowPower Low-Power Operation
609 The system thread \b osRtxIdleThread can be use to switch the system into a low-power mode. The easiest form to enter a
610 low-power mode is the execution of the \c __WFE function that puts the processor into a sleep mode where it waits for an
615 #include "RTE_Components.h"
616 #include CMSIS_device_header /* Device definitions */
618 void osRtxIdleThread (void) {
619 /* The idle demon is a system thread, running when no other thread is */
623 __WFE(); /* Enter sleep mode */
629 \c __WFE() is not available in every Cortex-M implementation. Check device manuals for availability.
632 \section kernelTimer RTX Kernel Timer Tick
634 RTX uses the generic \ref CMSIS_RTOS_TickAPI to configure and control its periodic Kernel Tick.
636 To use an alternative timer as the Kernel Tick Timer one simply needs to implement a custom version
637 of the \ref CMSIS_RTOS_TickAPI.
639 \note The OS Tick implementation provided must asure that the used timer interrupt uses the same (low) priority group
640 as the service interrupts, i.e. interrupts used by RTX must not preempt each other. Refer to the \ref Scheduler section
643 \subsection TickLess Tick-less Low-Power Operation
645 RTX5 provides extension for tick-less operation which is useful for applications that use extensively low-power modes where
646 the SysTick timer is also disabled. To provide a time-tick in such power-saving modes, a wake-up timer is used to
647 derive timer intervals. The CMSIS-RTOS2 functions \ref osKernelSuspend and \ref osKernelResume control the tick-less
650 Using this functions allows the RTX5 thread scheduler to stop the periodic kernel tick interrupt. When all active threads
651 are suspended, the system enters power-down and calculates how long it can stay in this power-down mode. In the power-down
652 mode the processor and peripherals can be switched off. Only a wake-up timer must remain powered, because this timer is
653 responsible to wake-up the system after the power-down period expires.
655 The tick-less operation is controlled from the \b osRtxIdleThread thread. The wake-up timeout value is set before the system
656 enters the power-down mode. The function \ref osKernelSuspend calculates the wake-up timeout measured in RTX Timer Ticks;
657 this value is used to setup the wake-up timer that runs during the power-down mode of the system.
659 Once the system resumes operation (either by a wake-up time out or other interrupts) the RTX5 thread scheduler is started
660 with the function \ref osKernelResume. The parameter \a sleep_time specifies the time (in RTX Timer Ticks) that the system
661 was in power-down mode.
665 #include "msp.h" // Device header
667 /*----------------------------------------------------------------------------
668 * MSP432 Low-Power Extension Functions
669 *---------------------------------------------------------------------------*/
670 static void MSP432_LP_Entry(void) {
671 /* Enable PCM rude mode, which allows to device to enter LPM3 without waiting for peripherals */
672 PCM->CTL1 = PCM_CTL1_KEY_VAL | PCM_CTL1_FORCE_LPM_ENTRY;
673 /* Enable all SRAM bank retentions prior to going to LPM3 */
674 SYSCTL->SRAM_BANKRET |= SYSCTL_SRAM_BANKRET_BNK7_RET;
675 __enable_interrupt();
676 NVIC_EnableIRQ(RTC_C_IRQn);
677 /* Do not wake up on exit from ISR */
678 SCB->SCR |= SCB_SCR_SLEEPONEXIT_Msk;
679 /* Setting the sleep deep bit */
680 SCB->SCR |= (SCB_SCR_SLEEPDEEP_Msk);
683 static volatile unsigned int tc;
684 static volatile unsigned int tc_wakeup;
686 void RTC_C_IRQHandler(void)
688 if (tc++ > tc_wakeup)
690 SCB->SCR &= ~SCB_SCR_SLEEPONEXIT_Msk;
691 NVIC_DisableIRQ(RTC_C_IRQn);
692 NVIC_ClearPendingIRQ(RTC_C_IRQn);
695 if (RTC_C->PS0CTL & RTC_C_PS0CTL_RT0PSIFG)
697 RTC_C->CTL0 = RTC_C_KEY_VAL; // Unlock RTC key protected registers
698 RTC_C->PS0CTL &= ~RTC_C_PS0CTL_RT0PSIFG;
700 SCB->SCR |= (SCB_SCR_SLEEPDEEP_Msk);
704 uint32_t g_enable_sleep = 0;
706 void osRtxIdleThread (void) {
709 tc_wakeup = osKernelSuspend();
710 /* Is there some time to sleep? */
713 /* Enter the low power state */
717 /* Adjust the kernel ticks with the amount of ticks slept */
724 \c __WFE() is not available in every ARM Cortex-M implementation. Check device manuals for availability.
725 The alternative using \c __WFI() has other issues, please take note of http://www.keil.com/support/docs/3591.htm as well.
727 \section rtx_os_h RTX5 Header File
729 Every implementation of the CMSIS-RTOS2 API can bring its own additional features. RTX5 adds a couple of
730 \ref rtx5_specific "functions" for the idle more, for error notifications, and special system timer functions. It also is
731 using macros for control block and memory sizes.
733 If you require some of the RTX specific functions in your application code, \#include the header file \b %rtx_os.h:
738 \section CMSIS_RTOS_TimeOutValue Timeout Value
740 Timeout values are an argument to several \b osXxx functions to allow time for resolving a request. A timeout value of \b 0
741 means that the RTOS does not wait and the function returns instantly, even when no resource is available. A timeout value of
742 \ref osWaitForever means that the RTOS waits infinitely until a resource becomes available. Or one forces the thread to resume
743 using \ref osThreadResume which is discouraged.
745 The timeout value specifies the number of timer ticks until the time delay elapses. The value is an upper bound and
746 depends on the actual time elapsed since the last timer tick.
749 - timeout value \b 0 : the system does not wait, even when no resource is available the RTOS function returns instantly.
750 - timeout value \b 1 : the system waits until the next timer tick occurs; depending on the previous timer tick, it may be a
751 very short wait time.
752 - timeout value \b 2 : actual wait time is between 1 and 2 timer ticks.
753 - timeout value \ref osWaitForever : system waits infinite until a resource becomes available.
755 \image html TimerValues.png "Example of timeout using osDelay()"
758 \section CMSIS_RTOS_ISR_Calls Calls from Interrupt Service Routines
760 The following CMSIS-RTOS2 functions can be called from threads and Interrupt Service Routines (ISR):
761 - \ref osKernelGetInfo, \ref osKernelGetState,
762 \ref osKernelGetTickCount, \ref osKernelGetTickFreq, \ref osKernelGetSysTimerCount, \ref osKernelGetSysTimerFreq
763 - \ref osThreadFlagsSet
764 - \ref osEventFlagsSet, \ref osEventFlagsClear, \ref osEventFlagsGet, \ref osEventFlagsWait
765 - \ref osSemaphoreAcquire, \ref osSemaphoreRelease, \ref osSemaphoreGetCount
766 - \ref osMemoryPoolAlloc, \ref osMemoryPoolFree, \ref osMemoryPoolGetCapacity, \ref osMemoryPoolGetBlockSize,
767 \ref osMemoryPoolGetCount, \ref osMemoryPoolGetSpace
768 - \ref osMessageQueuePut, \ref osMessageQueueGet, \ref osMessageQueueGetCapacity, \ref osMessageQueueGetMsgSize,
769 \ref osMessageQueueGetCount, \ref osMessageQueueGetSpace
771 Functions that cannot be called from an ISR are verifying the interrupt status and return the status code \b osErrorISR, in
772 case they are called from an ISR context. In some implementations, this condition might be caught using the HARD_FAULT
776 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
778 \page config_rtx5 Configure RTX v5
780 The file "RTX_Config.h" defines the configuration parameters of CMSIS-RTOS RTX and must be part of every project that is
781 using the CMSIS-RTOS RTX kernel. The configuration options are explained in detail in the following sections:
782 - \ref systemConfig covers system-wide settings for the global memory pool, tick frequency, ISR event buffer and round-robin thread switching.
783 - \ref threadConfig provides several parameters to configure the \ref CMSIS_RTOS_ThreadMgmt functions.
784 - \ref timerConfig provides several parameters to configure the \ref CMSIS_RTOS_TimerMgmt functions.
785 - \ref eventFlagsConfig provides several parameters to configure the \ref CMSIS_RTOS_EventFlags functions.
786 - \ref mutexConfig provides several parameters to configure the \ref CMSIS_RTOS_MutexMgmt functions.
787 - \ref semaphoreConfig provides several parameters to configure the \ref CMSIS_RTOS_SemaphoreMgmt functions.
788 - \ref memPoolConfig provides several parameters to configure the \ref CMSIS_RTOS_PoolMgmt functions.
789 - \ref msgQueueConfig provides several parameters to configure the \ref CMSIS_RTOS_Message functions.
791 The file "RTX_Config.c" contains default implementations of the functions \ref osRtxIdleThread and \ref osRtxErrorNotify. Both functions
792 can simply be overwritten with a custimized behavior by redefining them as part of the user code.
794 The configuration file uses <b>Configuration Wizard Annotations</b>. Refer to <b>Pack - Configuration Wizard Annotations</b> for details.
795 Depending on the development tool, the annotations might lead to a more user-friendly graphical representation of the
796 settings. The screenshot below is a screenshot from the µVision \b Configuration \b Wizard view:
798 \image html config_wizard.png "RTX_Config.h in Configuration Wizard View"
800 Alternatively one can provide configuration options using the compiler command line.
802 For example one can customize the used tick frequency to 100us by (overwriting) the configuration using
804 cc -DOS_TICK_FREQ=100
807 \section systemConfig System Configuration
809 The system configuration covers system-wide settings for the global memory pool, tick frequency, ISR event buffer and
810 round-robin thread switching.
812 <b>System Configuration Options</b>
813 \image html config_wizard_system.png "RTX_Config.h: System Configuration"
815 Name | \#define | Description
816 ---------------------------------------|--------------------------|----------------------------------------------------------------
817 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.
818 Kernel Tick Frequency (Hz) | \c OS_TICK_FREQ | Defines base time unit for delays and timeouts in Hz. Default: 1000Hz = 1ms period.
819 Round-Robin Thread switching | \c OS_ROBIN_ENABLE | Enables Round-Robin Thread switching.
820 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]}.
821 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}.
823 \subsection systemConfig_glob_mem Global dynamic memory
824 Refer to \ref GlobalMemoryPool.
827 \subsection systemConfig_rr Round-Robin Thread Switching
829 RTX5 may be configured to use round-robin multitasking thread switching. Round-robin allows quasi-parallel execution of
830 several threads of the \a same priority. Threads are not really executed concurrently, but are scheduled where the available
831 CPU time is divided into time slices and RTX5 assigns a time slice to each thread. Because the time slice is typically short
832 (only a few milliseconds), it appears as though threads execute simultaneously.
834 Round-robin thread switching functions as follows:
835 - the tick is preloaded with the timeout value when a thread switch occurs
836 - the tick is decremented (if not already zero) each system tick if the same thread is still executing
837 - when the tick reaches 0 it indicates that a timeout has occurred. If there is another thread ready with the \a same
838 priority, then the system switches to that thread and the tick is preloaded with timeout again.
840 In other words, threads execute for the duration of their time slice (unless a thread's time slice is given up). Then, RTX
841 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
842 ready to run, the current running thread resumes it execution.
844 \note When switching to higher priority threads, the round-robin timeout value is reset.
846 Round-Robin multitasking is controlled with the <b>\#define OS_ROBIN_ENABLE</b>. The time slice period is configured (in RTX
847 timer ticks) with the <b>\#define OS_ROBIN_TIMEOUT</b>.
850 \subsection systemConfig_isr_fifo ISR FIFO Queue
851 The RTX functions (\ref CMSIS_RTOS_ISR_Calls), when called from and interrupt handler, store the request type and optional
852 parameter to the ISR FIFO queue buffer to be processed later, after the interrupt handler exits.
854 The scheduler is activated immediately after the IRQ handler has finished its execution to process the requests stored to the
855 FIFO queue buffer. The required size of this buffer depends on the number of functions that are called within the interrupt
856 handler. An insufficient queue size will be caught by \b osRtxErrorNotify with error code \b osRtxErrorISRQueueOverflow.
859 \section threadConfig Thread Configuration
861 The RTX5 provides several parameters to configure the \ref CMSIS_RTOS_ThreadMgmt functions.
863 <b>Thread Configuration Options</b>
864 \image html config_wizard_threads.png "RTX_Config.h: Thread Configuration"
867 Option | \#define | Description
868 :--------------------------------------------------------|:-----------------------|:---------------------------------------------------------------
869 Object specific Memory allocation | \c OS_THREAD_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
870 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]}.
871 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]}.
872 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}.
873 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}.
874 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}.
875 Stack overrun checking | \c OS_STACK_CHECK | Enable stack overrun checks at thread switch.
876 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.
877 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.
879 \subsection threadConfig_countstack Configuration of Thread Count and Stack Space
881 The RTX5 kernel uses a separate stack space for each thread and provides two methods for defining the stack requirements:
882 - <b>Static allocation</b>: when \ref osThreadAttr_t::stack_mem and \ref osThreadAttr_t::stack_size specify a memory area
883 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.
884 - <b>Dynamic allocation</b>: when \ref osThreadAttr_t is NULL or \ref osThreadAttr_t::stack_mem is NULL, the system
885 allocates the stack memory from:
886 - Object-specific Memory Pool (default Stack size) when "Object specific Memory allocation" is enabled and "Number of
887 user Threads with default Stack size" is not \token{0} and \ref osThreadAttr_t::stack_size is \token{0} (or
888 \ref osThreadAttr_t is NULL).
889 - Object-specific Memory Pool (user-provided Stack size) when "Object specific Memory allocation" is enabled and "Total
890 Stack size for user..." is not \token{0} and \ref osThreadAttr_t::stack_size is not \token{0}.
891 - Global Memory Pool when "Object specific Memory allocation" is disabled or (\ref osThreadAttr_t::stack_size is not
892 \token{0} and "Total Stack size for user..." is \token{0}) or (\ref osThreadAttr_t::stack_size is \token{0} and
893 "Number of user Threads with default Stack size" is \token{0}).
895 \ref osThreadAttr_t is a parameter of the function \ref osThreadNew.
898 Before the RTX kernel is started by the \ref osKernelStart() function, the main stack defined in startup_<i>device</i>.s is
899 used. The main stack is also used for:
900 - user application calls to RTX functions in \b thread \b mode using SVC calls
901 - interrupt/exception handlers.
903 \subsection threadConfig_ovfcheck Stack Overflow Checking
904 RTX5 implements a software stack overflow checking that traps stack overruns. Stack is used for return addresses and
905 automatic variables. Extensive usage or incorrect stack configuration may cause a stack overflow. Software stack overflow
906 checking is controlled with the define \c OS_STACK_CHECK.
908 If a stack overflow is detected, the function \b osRtxErrorNotify with error code \b osRtxErrorStackUnderflow is called. By
909 default, this function is implemented as an endless loop and will practically stop code execution.
911 \subsection threadConfig_watermark Stack Usage Watermark
912 RTX5 initializes thread stack with a watermark pattern (0xCC) when a thread is created. This allows the debugger to determine
913 the maximum stack usage for each thread. It is typically used during development but removed from the final application.
914 Stack usage watermark is controlled with the define \c OS_STACK_WATERMARK.
916 Enabling this option significantly increases the execution time of \ref osThreadNew (depends on thread stack size).
918 \subsection threadConfig_procmode Processor Mode for Thread Execution
919 RTX5 allows to execute threads in unprivileged or privileged processor mode. The processor mode is controlled with the
920 define \c OS_PRIVILEGE_MODE.
922 In \b unprivileged processor mode, the application software:
923 - has limited access to the MSR and MRS instructions, and cannot use the CPS instruction.
924 - cannot access the system timer, NVIC, or system control block.
925 - might have restricted access to memory or peripherals.
927 In \b privileged processor mode, the application software can use all the instructions and has access to all resources.
930 \section timerConfig Timer Configuration
932 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_TimerMgmt functions.
934 <b>Timer Configuration Options</b>
935 \image html config_wizard_timer.png "RTX_Config.h: Timer Configuration"
937 Name | \#define | Description
938 ---------------------------------------|--------------------------|----------------------------------------------------------------
939 Object specific Memory allocation | \c OS_TIMER_OBJ_MEM | Enables object specific memory allocation.
940 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]}.
941 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}
942 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}.
943 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]}.
945 \subsection timerConfig_obj Object-specific memory allocation
946 See \ref ObjectMemoryPool.
948 \subsection timerConfig_user User Timer Thread
949 The RTX5 function \b osRtxTimerThread executes callback functions when a time period expires. The priority of the timer
950 subsystem within the complete RTOS system is inherited from the priority of the \b osRtxTimerThread. This is configured by
951 \c OS_TIMER_THREAD_PRIO. Stack for callback functions is supplied by \b osRtxTimerThread. \c OS_TIMER_THREAD_STACK_SIZE must
952 satisfy the stack requirements of the callback function with the highest stack usage.
955 \section eventFlagsConfig Event Flags Configuration
957 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_EventFlags functions.
959 <b>Event Configuration Options</b>
960 \image html config_wizard_eventFlags.png "RTX_Config.h: Event Flags Configuration"
962 Name | \#define | Description
963 ---------------------------------------|--------------------------|----------------------------------------------------------------
964 Object specific Memory allocation | \c OS_EVFLAGS_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
965 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]}.
967 \subsection eventFlagsConfig_obj Object-specific memory allocation
968 When object-specific memory is used, the pool size for all Event objects is specified by \c OS_EVFLAGS_NUM. Refer to
969 \ref ObjectMemoryPool.
972 \section mutexConfig Mutex Configuration
973 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_MutexMgmt functions.
975 <b>Mutex Configuration Options</b>
976 \image html config_wizard_mutex.png "RTX_Config.h: Mutex Configuration"
979 Name | \#define | Description
980 ---------------------------------------|--------------------------|----------------------------------------------------------------
981 Object specific Memory allocation | \c OS_MUTEX_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
982 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]}.
984 \subsection mutexConfig_obj Object-specific Memory Allocation
985 When object-specific memory is used, the pool size for all Mutex objects is specified by \c OS_MUTEX_NUM. Refer to
986 \ref ObjectMemoryPool.
989 \section semaphoreConfig Semaphore Configuration
991 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_SemaphoreMgmt functions.
993 <b>Semaphore Configuration Options</b>
994 \image html config_wizard_semaphore.png "RTX_Config.h: Semaphore Configuration"
997 Name | \#define | Description
998 ---------------------------------------|--------------------------|----------------------------------------------------------------
999 Object specific Memory allocation | \c OS_SEMAPHORE_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1000 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]}.
1002 \subsection semaphoreConfig_obj Object-specific memory allocation
1003 When Object-specific Memory is used, the pool size for all Semaphore objects is specified by \c OS_SEMAPHORE_NUM. Refer to
1004 \ref ObjectMemoryPool.
1007 \section memPoolConfig Memory Pool Configuration
1009 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_PoolMgmt functions.
1011 <b>Memory Pool Configuration Options</b>
1012 \image html config_wizard_memPool.png "RTX_Config.h: Memory Pool Configuration"
1014 Name | \#define | Description
1015 ---------------------------------------|--------------------------|----------------------------------------------------------------
1016 Object specific Memory allocation | \c OS_MEMPOOL_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1017 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]}.
1018 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}.
1020 \subsection memPoolConfig_obj Object-specific memory allocation
1021 When object-specific memory is used, the number of pools for all MemoryPool objects is specified by \c OS_MEMPOOL_NUM. The
1022 total storage size reserved for all pools is configured in \c OS_MEMPOOL_DATA_SIZE. Refer to \ref ObjectMemoryPool.
1025 \section msgQueueConfig Message Queue Configuration
1027 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_Message functions.
1029 <b>MessageQueue Configuration Options</b>
1030 \image html config_wizard_msgQueue.png "RTX_Config.h: Message Queue Configuration"
1032 Name | \#define | Description
1033 ---------------------------------------|--------------------------|----------------------------------------------------------------
1034 Object specific Memory allocation | \c OS_MSGQUEUE_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1035 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]}.
1036 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}.
1038 \subsection msgQueueConfig_obj Object-specific memory allocation
1039 When Object-specific Memory is used, the number of queues for all Message Queue objects is specified by \c OS_MSGQUEUE_NUM.
1040 The total storage size reserved for all queues is configured in \c OS_MSGQUEUE_DATA_SIZE. Refer to \ref ObjectMemoryPool.
1044 /* ========================================================================================================================== */
1046 \page creating_RTX5_LIB Building the RTX5 Library
1048 The CMSIS Pack contains a µVision project for building the complete set of RTX5 libraries. This project can also be used as
1049 a reference for building the RTX5 libraries using a tool-chain of your choice.
1051 -# Open the project \b RTX_CM.uvprojx from the pack folder <b>CMSIS/RTOS2/RTX/Library/ARM/MDK</b> in µVision.
1052 -# Select the project target that matches your device's processor core.
1053 \n The project provides target configuration for all supported Cortex-M targets supported by RTX5.
1054 -# You can find out about the required preprocessor defines in the dialogs <b>Options for Target - C/C++</b> and
1055 <b>Options for Target - Asm</b>. Note the need to use at least the C99 compiler mode when building RTX from source.
1056 -# From the <b>Project</b> window you find the list of source files required for a complete library build.
1057 -# Build the library of your choice using \b Project - \b Build \b Target (or press F7).
1059 \image html own_lib_projwin.png "Project with files for ARMv8-M Mainline"
1063 /* ========================================================================================================================== */
1065 \page dirstructfiles5 Directory Structure and File Overview
1067 The following section provides an overview of the directory structure and the files that are relevant for the user's for
1068 CMSIS-RTOS RTX v5. The following directory references start below the CMSIS pack installation path, for example
1069 ARM/CMSIS/<i>version</i>/CMSIS/RTOS2.
1071 \section Folders RTX v5 Directory Structure
1073 The CMSIS-RTOS RTX v5 is delivered in source code and several examples are provided.
1075 <table class="cmtable" summary="CMSIS-RTOS RTX Library Files">
1082 <td>The include file for CMSIS-RTOS API v2. cmsis_os2.h is the central include file for user applications.</td>
1086 <td>CMSIS-RTOS API template source and header file.</td>
1090 <td>Directory with RTX specific files and folders. Also contains the component viewer description file.</td>
1094 <td>CMSIS-RTOS RTX configuration files %RTX_Config.h and %RTX_Config.c.</td>
1097 <td>RTX/Examples</td>
1098 <td>Example projects that can be directly used in development tools.</td>
1101 <td>RTX/Include</td>
1102 <td>RTX v5 specific include files.</td>
1105 <td>RTX/Include1</td>
1106 <td>CMSIS-RTOS v1 API header file.</td>
1109 <td>RTX/Library</td>
1110 <td>Pre-built libraries (see next table for details).</td>
1114 <td>Source code that can be used with ARMCC and GCC.</td>
1117 <td>RTX/Template</td>
1118 <td>User code templates for creating application projects with CMSIS-RTOS RTX v5.</td>
1122 \section libFiles RTX v5 Library Files
1124 The CMSIS-RTOS RTX Library is available pre-compiled for ARMCC and GCC compilers and supports all Cortex-M
1125 processor variants in every configuration, including ARM Cortex-M23 and Cortex-M33.
1127 <table class="cmtable" summary="CMSIS-RTOS RTX Library Files">
1129 <th>Library File</th>
1130 <th>Processor Configuration</th>
1133 <td>Library/ARM/RTX_CM0.lib</td>
1134 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Cortex-M0 and M1, little-endian.</td>
1137 <td>Library/ARM/RTX_CM3.lib</td>
1138 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Cortex-M3, M4, and M7 without FPU, little-endian.</td>
1141 <td>Library/ARM/RTX_CM4F.lib</td>
1142 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Cortex-M4 and M7 with FPU, little-endian.</td>
1145 <td>Library/ARM/RTX_V8MB.lib</td>
1146 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, ARMv8-M baseline.</td>
1149 <td>Library/ARM/RTX_V8MBN.lib</td>
1150 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, ARMv8-M baseline, non-secure.</td>
1153 <td>Library/ARM/RTX_V8MM.lib</td>
1154 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, ARMv8-M mainline.</td>
1157 <td>Library/ARM/RTX_V8MMF.lib</td>
1158 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, ARMv8-M mainline with FPU.</td>
1161 <td>Library/ARM/RTX_V8MMFN.lib</td>
1162 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, ARMv8-M mainline with FPU, non-secure.</td>
1165 <td>Library/ARM/RTX_V8MMN.lib</td>
1166 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, ARMv8-M mainline, non-secure.</td>
1169 <td>Library/GCC/libRTX_CM0.a</td>
1170 <td>CMSIS-RTOS libRTX Library for GCC Compiler, Cortex-M0 and M1, little-endian.</td>
1173 <td>Library/GCC/libRTX_CM3.a</td>
1174 <td>CMSIS-RTOS libRTX Library for GCC Compiler, Cortex-M3, M4, and M7 without FPU, little-endian.</td>
1177 <td>Library/GCC/libRTX_CM4F.a</td>
1178 <td>CMSIS-RTOS libRTX Library for GCC Compiler, Cortex-M4 and M7 with FPU, little-endian.</td>
1181 <td>Library/GCC/libRTX_V8MB.a</td>
1182 <td>CMSIS-RTOS libRTX Library for GCC Compiler, ARMv8-M baseline.</td>
1185 <td>Library/GCC/libRTX_V8MBN.a</td>
1186 <td>CMSIS-RTOS libRTX Library for GCC Compiler, ARMv8-M baseline, non-secure.</td>
1189 <td>Library/GCC/libRTX_V8MM.a</td>
1190 <td>CMSIS-RTOS libRTX Library for GCC Compiler, ARMv8-M mainline.</td>
1193 <td>Library/GCC/libRTX_V8MMF.a</td>
1194 <td>CMSIS-RTOS libRTX Library for GCC Compiler, ARMv8-M mainline with FPU.</td>
1197 <td>Library/GCC/libRTX_V8MMFN.a</td>
1198 <td>CMSIS-RTOS libRTX Library for GCC Compiler, ARMv8-M mainline with FPU, non-secure.</td>
1201 <td>Library/GCC/libRTX_V8MMN.a</td>
1202 <td>CMSIS-RTOS libRTX Library for GCC Compiler, ARMv8-M mainline, non-secure.</td>
1207 /* ========================================================================================================================== */
1209 \page technicalData5 Technical Data
1211 \section technicalData_Toolchains Supported Toolchains
1213 Keil RTX5 is developed and tested using the common toolchains and development environments.
1215 \subsection technicalData_Toolchain_ARM ARM Compiler (ARM/Keil MDK, uVision5)
1217 Major parts of RTX5 are developed and optimized using ARM Compiler and ARM/Keil MDK.
1218 The current release is tested with the following versions:
1220 <li>ARM Compiler 5.06 Update 5 (Build 528)</li>
1221 <li>ARM Compiler 6.6.1 (Long Term Maintenance)</li>
1222 <li>ARM Compiler 6.7</li>
1223 <li>RTOS-aware debugging with uVision 5.24</li>
1226 \subsection technicalData_Toolchain_IAR IAR Embedded Workbench
1228 RTX5 has been ported to fully support IAR Embedded Workbench. The following releases are known to work:
1230 <li>IAR Embedded Workbench 7.7 (<a href="https://github.com/ARM-software/CMSIS_5/issues/201">community report</a>)</li>
1231 <li>IAR Embedded Workbench 7.80.4</li>
1232 <li>IAR Embedded Workbench 8.10</li>
1235 \subsection technicalData_Toolchain_GCC GNU Compiler Collection
1237 RTX5 has also been ported to support GCC, maintenance mainly relays on community contribution.
1238 Active development is currently tested with:
1240 <li>GCC 5.4 Release Series</li>
1243 \section technicalData5_ControlBlockSizes Control Block Sizes
1245 Keil RTX5 specific control block definitions (including sizes) as well as memory pool and message queue memory requirements
1246 are defined in the RTX5 header file:
1249 /// Control Block sizes
1250 #define osRtxThreadCbSize sizeof(osRtxThread_t)
1251 #define osRtxTimerCbSize sizeof(osRtxTimer_t)
1252 #define osRtxEventFlagsCbSize sizeof(osRtxEventFlags_t)
1253 #define osRtxMutexCbSize sizeof(osRtxMutex_t)
1254 #define osRtxSemaphoreCbSize sizeof(osRtxSemaphore_t)
1255 #define osRtxMemoryPoolCbSize sizeof(osRtxMemoryPool_t)
1256 #define osRtxMessageQueueCbSize sizeof(osRtxMessageQueue_t)
1258 /// Memory size in bytes for Memory Pool storage.
1259 /// \param block_count maximum number of memory blocks in memory pool.
1260 /// \param block_size memory block size in bytes.
1261 #define osRtxMemoryPoolMemSize(block_count, block_size) \
1262 (4*(block_count)*(((block_size)+3)/4))
1264 /// Memory size in bytes for Message Queue storage.
1265 /// \param msg_count maximum number of messages in queue.
1266 /// \param msg_size maximum message size in bytes.
1267 #define osRtxMessageQueueMemSize(msg_count, msg_size) \
1268 (4*(msg_count)*(3+(((msg_size)+3)/4)))
1271 If you are using a \ref GlobalMemoryPool to allocate memory for the RTOS objects, you need to know the size that is required
1272 for each object in case of errors. Currently, the control block sizes are as follows (subject to change without
1275 Type | Control block size in bytes |
1276 --------------|:---------------------------:|
1283 Message Queue | 52 |
1285 The size of the memory that is required for memory pool and message queue data storage can be determined from the macros
1290 /* ========================================================================================================================== */
1292 \page misraCompliance5 MISRA-C Compliance Exceptions
1293 CMSIS-RTOS RTX tries to be MISRA-C compliant as much as possible. However, there are some violations in order to simplify
1294 the overall code logic and to generate more efficient code.
1296 This page will list the MISRA-C compliance exceptions. Work in progress.
1299 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1301 \page rtosValidation RTOS Validation
1303 ARM offers a <a class=el href="http://www.keil.com/pack" target="_blank">Software Pack</a> for the CMSIS-RTOS Validation.
1304 The <b>ARM::CMSIS-RTOS_Validation</b> Pack contains the following:
1306 - Source code of a CMSIS-RTOS Validation Suite along with configuration file.
1307 - Documentation of the CMSIS-RTOS Validation Suite.
1308 - Example that shows the usage of the CMSIS-RTOS Validation Suite using simulation.
1311 Currently, a public version of the test suite is available only for CMSIS-RTOS v1 API.
1313 The CMSIS-RTOS Validation Suite performs generic validation of various RTOS features. The test cases verify the
1314 functional behavior, test invalid parameters and call management functions from ISR.
1316 The following CMSIS-RTOS features can be tested with the current release:
1317 - Thread : Create multiple threads, terminate, restart, yield, change priority
1318 - Timer : Create periodic and one-shot timers
1319 - GenWait : Call generic wait functions (osDelay and osWait)
1320 - WaitFunc : Measure wait ticks (delay, mail, message, mutex, semaphore, signal)
1322 Moreover the following inter-thread communication functions can be tested:
1323 - Signal : Verify signal events
1324 - Memory Pool : Verify memory allocation
1325 - Message Queue : Exchange messages between threads
1326 - Mail Queue : Exchange data between threads
1327 - Mutex : Synchronize resource access
1328 - Semaphore : Access shared resources
1330 The RTOS Validation output can be printed to a console, output via ITM printf, or output to a memory buffer.
1332 \section test_output Sample Test Output
1334 CMSIS-RTOS Test Suite Oct 21 2015 16:39:16
1336 TEST 01: TC_ThreadCreate PASSED
1337 TEST 02: TC_ThreadMultiInstance PASSED
1338 TEST 03: TC_ThreadTerminate PASSED
1341 TEST 08: TC_ThreadChainedCreate PASSED
1342 TEST 09: TC_ThreadYield NOT EXECUTED
1343 TEST 10: TC_ThreadParam PASSED
1346 TEST 60: TC_MailFromISRToThread PASSED
1348 Test Summary: 60 Tests, 59 Executed, 59 Passed, 0 Failed, 0 Warnings.
1354 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1356 \page functionOverview Function Overview
1358 CMSIS-RTOS v2 provides multiple API interfaces:
1359 - \subpage rtos_api2 is the new C function API that supports dynamic object creation and ARMv8-M (ARM Cortex-M23 and
1361 - <a class="el" href="../../RTOS/html/functionOverview.html">CMSIS-RTOS C API v1</a> is a C function API that is backward
1362 compatible with CMSIS-RTOS v1.
1363 - \subpage rtos_apicpp is a C++ class function API.
1365 It is possible to intermix the different API variants in the same application and even in the same C/C++ source module.
1366 However, the functions of the <b>C API Version 1</b> may be deprecated in future versions of CMSIS-RTOS.
1368 \section rtos_api2 CMSIS-RTOS2
1370 Overview of all CMSIS-RTOS C API v2 functions that are implemented in the \subpage cmsis_os2_h.
1372 - \ref CMSIS_RTOS_KernelCtrl
1373 - \ref osKernelGetInfo : \copybrief osKernelGetInfo
1374 - \ref osKernelGetState : \copybrief osKernelGetState
1375 - \ref osKernelGetSysTimerCount : \copybrief osKernelGetSysTimerCount
1376 - \ref osKernelGetSysTimerFreq : \copybrief osKernelGetSysTimerFreq
1377 - \ref osKernelInitialize : \copybrief osKernelInitialize
1378 - \ref osKernelLock : \copybrief osKernelLock
1379 - \ref osKernelUnlock : \copybrief osKernelUnlock
1380 - \ref osKernelRestoreLock : \copybrief osKernelRestoreLock
1381 - \ref osKernelResume : \copybrief osKernelResume
1382 - \ref osKernelStart : \copybrief osKernelStart
1383 - \ref osKernelSuspend : \copybrief osKernelSuspend
1384 - \ref osKernelGetTickCount : \copybrief osKernelGetTickCount
1385 - \ref osKernelGetTickFreq : \copybrief osKernelGetTickFreq
1387 - \ref CMSIS_RTOS_ThreadMgmt
1388 - \ref osThreadDetach : \copybrief osThreadDetach
1389 - \ref osThreadEnumerate : \copybrief osThreadEnumerate
1390 - \ref osThreadExit : \copybrief osThreadExit
1391 - \ref osThreadGetCount : \copybrief osThreadGetCount
1392 - \ref osThreadGetId : \copybrief osThreadGetId
1393 - \ref osThreadGetName : \copybrief osThreadGetName
1394 - \ref osThreadGetPriority : \copybrief osThreadGetPriority
1395 - \ref osThreadGetStackSize : \copybrief osThreadGetStackSize
1396 - \ref osThreadGetStackSpace : \copybrief osThreadGetStackSpace
1397 - \ref osThreadGetState : \copybrief osThreadGetState
1398 - \ref osThreadJoin : \copybrief osThreadJoin
1399 - \ref osThreadNew : \copybrief osThreadNew
1400 - \ref osThreadResume : \copybrief osThreadResume
1401 - \ref osThreadSetPriority : \copybrief osThreadSetPriority
1402 - \ref osThreadSuspend : \copybrief osThreadSuspend
1403 - \ref osThreadTerminate : \copybrief osThreadTerminate
1404 - \ref osThreadYield : \copybrief osThreadYield
1406 - \ref CMSIS_RTOS_ThreadFlagsMgmt
1407 - \ref osThreadFlagsSet : \copybrief osThreadFlagsSet
1408 - \ref osThreadFlagsClear : \copybrief osThreadFlagsClear
1409 - \ref osThreadFlagsGet : \copybrief osThreadFlagsGet
1410 - \ref osThreadFlagsWait : \copybrief osThreadFlagsWait
1412 - \ref CMSIS_RTOS_EventFlags
1413 - \ref osEventFlagsGetName : \copybrief osEventFlagsGetName
1414 - \ref osEventFlagsNew : \copybrief osEventFlagsNew
1415 - \ref osEventFlagsDelete : \copybrief osEventFlagsDelete
1416 - \ref osEventFlagsSet : \copybrief osEventFlagsSet
1417 - \ref osEventFlagsClear : \copybrief osEventFlagsClear
1418 - \ref osEventFlagsGet : \copybrief osEventFlagsGet
1419 - \ref osEventFlagsWait : \copybrief osEventFlagsWait
1421 - \ref CMSIS_RTOS_Wait
1422 - \ref osDelay : \copybrief osDelay
1423 - \ref osDelayUntil : \copybrief osDelayUntil
1425 - \ref CMSIS_RTOS_TimerMgmt
1426 - \ref osTimerDelete : \copybrief osTimerDelete
1427 - \ref osTimerGetName : \copybrief osTimerGetName
1428 - \ref osTimerIsRunning : \copybrief osTimerIsRunning
1429 - \ref osTimerNew : \copybrief osTimerNew
1430 - \ref osTimerStart : \copybrief osTimerStart
1431 - \ref osTimerStop : \copybrief osTimerStop
1433 - \ref CMSIS_RTOS_MutexMgmt
1434 - \ref osMutexAcquire : \copybrief osMutexAcquire
1435 - \ref osMutexDelete : \copybrief osMutexDelete
1436 - \ref osMutexGetName : \copybrief osMutexGetName
1437 - \ref osMutexGetOwner : \copybrief osMutexGetOwner
1438 - \ref osMutexNew : \copybrief osMutexNew
1439 - \ref osMutexRelease : \copybrief osMutexRelease
1441 - \ref CMSIS_RTOS_SemaphoreMgmt
1442 - \ref osSemaphoreAcquire : \copybrief osSemaphoreAcquire
1443 - \ref osSemaphoreDelete : \copybrief osSemaphoreDelete
1444 - \ref osSemaphoreGetCount : \copybrief osSemaphoreGetCount
1445 - \ref osSemaphoreGetName : \copybrief osSemaphoreGetName
1446 - \ref osSemaphoreNew : \copybrief osSemaphoreNew
1447 - \ref osSemaphoreRelease : \copybrief osSemaphoreRelease
1449 - \ref CMSIS_RTOS_PoolMgmt
1450 - \ref osMemoryPoolAlloc : \copybrief osMemoryPoolAlloc
1451 - \ref osMemoryPoolDelete : \copybrief osMemoryPoolDelete
1452 - \ref osMemoryPoolFree : \copybrief osMemoryPoolFree
1453 - \ref osMemoryPoolGetBlockSize : \copybrief osMemoryPoolGetBlockSize
1454 - \ref osMemoryPoolGetCapacity : \copybrief osMemoryPoolGetCapacity
1455 - \ref osMemoryPoolGetCount : \copybrief osMemoryPoolGetCount
1456 - \ref osMemoryPoolGetName : \copybrief osMemoryPoolGetName
1457 - \ref osMemoryPoolGetSpace : \copybrief osMemoryPoolGetSpace
1458 - \ref osMemoryPoolNew : \copybrief osMemoryPoolNew
1460 - \ref CMSIS_RTOS_Message
1461 - \ref osMessageQueueDelete : \copybrief osMessageQueueDelete
1462 - \ref osMessageQueueGet : \copybrief osMessageQueueGet
1463 - \ref osMessageQueueGetCapacity : \copybrief osMessageQueueGetCapacity
1464 - \ref osMessageQueueGetCount : \copybrief osMessageQueueGetCount
1465 - \ref osMessageQueueGetMsgSize : \copybrief osMessageQueueGetMsgSize
1466 - \ref osMessageQueueGetName : \copybrief osMessageQueueGetName
1467 - \ref osMessageQueueGetSpace : \copybrief osMessageQueueGetSpace
1468 - \ref osMessageQueueNew : \copybrief osMessageQueueNew
1469 - \ref osMessageQueuePut : \copybrief osMessageQueuePut
1470 - \ref osMessageQueueReset : \copybrief osMessageQueueReset
1472 - \ref CMSIS_RTOS_TickAPI
1473 - \ref OS_Tick_Setup : \copybrief OS_Tick_Setup
1474 - \ref OS_Tick_Enable : \copybrief OS_Tick_Enable
1475 - \ref OS_Tick_Disable : \copybrief OS_Tick_Disable
1476 - \ref OS_Tick_AcknowledgeIRQ : \copybrief OS_Tick_AcknowledgeIRQ
1477 - \ref OS_Tick_GetIRQn : \copybrief OS_Tick_GetIRQn
1478 - \ref OS_Tick_GetClock : \copybrief OS_Tick_GetClock
1479 - \ref OS_Tick_GetInterval : \copybrief OS_Tick_GetInterval
1480 - \ref OS_Tick_GetCount : \copybrief OS_Tick_GetCount
1481 - \ref OS_Tick_GetOverflow : \copybrief OS_Tick_GetOverflow
1483 - \ref rtx5_specific
1484 - \ref osRtxErrorNotify : \copybrief osRtxErrorNotify
1485 - \ref osRtxIdleThread : \copybrief osRtxIdleThread
1487 The following CMSIS-RTOS2 functions can be called from threads and \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines"
1489 - \ref osKernelGetInfo, \ref osKernelGetState,
1490 \ref osKernelGetTickCount, \ref osKernelGetTickFreq, \ref osKernelGetSysTimerCount, \ref osKernelGetSysTimerFreq
1491 - \ref osThreadFlagsSet
1492 - \ref osEventFlagsSet, \ref osEventFlagsClear, \ref osEventFlagsGet, \ref osEventFlagsWait
1493 - \ref osSemaphoreAcquire, \ref osSemaphoreRelease, \ref osSemaphoreGetCount
1494 - \ref osMemoryPoolAlloc, \ref osMemoryPoolFree, \ref osMemoryPoolGetCapacity, \ref osMemoryPoolGetBlockSize,
1495 \ref osMemoryPoolGetCount, \ref osMemoryPoolGetSpace
1496 - \ref osMessageQueuePut, \ref osMessageQueueGet, \ref osMessageQueueGetCapacity, \ref osMessageQueueGetMsgSize,
1497 \ref osMessageQueueGetCount, \ref osMessageQueueGetSpace
1501 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1503 \page rtos_apicpp CMSIS-RTOS C++ API
1505 A C++11/C++14 interface is planned for the future.
1509 /* ======================================================================================================================== */
1510 // Group creation for Reference
1512 \addtogroup CMSIS_RTOS1 CMSIS-RTOS API v1
1513 \brief This section describes the CMSIS-RTOS API v1.
1515 The CMSIS-RTOS is a generic API layer that interfaces to an existing RTOS kernel.
1517 CMSIS-RTOS API v2 provides an translation layer for the
1518 <a class="el" href="../../RTOS/html/index.html">CMSIS-RTOS API v1</a> that simplifies migration.
1520 Refer to the <a class="el" href="../../RTOS/html/modules.html">Reference</a> guide of the CMSIS-RTOS API v1 for details.
1523 // Group creation for Reference
1525 \addtogroup CMSIS_RTOS CMSIS-RTOS2 API
1526 \brief Describes the C function interface of CMSIS-RTOS API v2.
1528 The CMSIS-RTOS2 is a generic API layer that interfaces to an RTOS kernel.
1530 The complete API interface is defined in the \ref cmsis_os2_h. When using dynamic memory allocation for objects, source code
1531 or libraries require no modifications when using on a different CMSIS-RTOS2 implementation.
1535 \addtogroup rtx5_specific RTX5 Specific API
1536 \brief This section describes CMSIS-RTOS RTX5 specifics.
1538 The RTX5 kernel can be customized for different application requirements:
1539 - If you are depending on the \ref lowPower "lowest power consumption" possible, you need to adapt the function
1540 \ref osRtxIdleThread to send the system to sleep mode as often as possible. In addition, use the
1541 \ref TickLess "tick-less low power" functions \ref osKernelSuspend and \ref osKernelResume to suspend the scheduler and to
1542 stop the SysTick timer.
1543 - If you try to find a \b runtime \b error, use the function \ref osRtxErrorNotify to debug the error.
1545 RTX5 interfaces to the <a href="http://www.keil.com/pack/doc/compiler/EventRecorder/html/index.html" target="_blank"><b>Event Recorder</b></a>
1546 to provide event information which helps you to understand and analyze the operation. Refer to \ref rtx_evr for more
1554 \defgroup rtx5_specific_defines Macros
1560 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1562 \def osRtxThreadCbSize
1565 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1567 \def osRtxTimerCbSize
1570 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1572 \def osRtxEventFlagsCbSize
1575 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1577 \def osRtxMutexCbSize
1580 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1582 \def osRtxSemaphoreCbSize
1585 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1587 \def osRtxMemoryPoolCbSize
1590 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1592 \def osRtxMessageQueueCbSize
1595 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1597 \def osRtxMemoryPoolMemSize
1600 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1602 \def osRtxMessageQueueMemSize
1610 \defgroup rtx5_specific_structs Structs
1616 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1618 \struct osRtxThread_t
1621 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1623 \struct osRtxTimerFinfo_t
1626 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1628 \struct osRtxTimer_t
1631 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1633 \struct osRtxEventFlags_t
1636 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1638 \struct osRtxMutex_t
1641 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1643 \struct osRtxSemaphore_t
1646 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1648 \struct osRtxMemoryPool_t
1651 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1653 \struct osRtxMessageQueue_t
1661 \defgroup rtx5_specific_functions Functions
1662 \brief RTX5 functions
1667 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1669 \fn uint32_t osRtxErrorNotify (uint32_t code, void *object_id);
1671 Some system error conditions can be detected during runtime. If the RTX kernel detects a runtime error, it calls the runtime
1672 error function \b osRtxErrorNotify for an object specified by parameter \a object_id.
1674 The parameter \a code passes the actual error code to this function:
1675 | Error Code | Description |
1676 |------------------------------|-----------------------------------------------------------------------------------|
1677 | osRtxErrorStackUnderflow | Stack underflow detected for thread (thread_id=object_id) |
1678 | osRtxErrorISRQueueOverflow | ISR Queue overflow detected when inserting object (object_id) |
1679 | osRtxErrorTimerQueueOverflow | User Timer Callback Queue overflow detected for timer (timer_id=object_id) |
1680 | osRtxErrorClibSpace | Standard C/C++ library libspace not available: increase \c OS_THREAD_LIBSPACE_NUM |
1681 | osRtxErrorClibMutex | Standard C/C++ library mutex initialization failed |
1683 The function \b osRtxErrorNotify must contain an infinite loop to prevent further program execution. You can use an emulator
1684 to step over the infinite loop and trace into the code introducing a runtime error. For the overflow errors this means you
1685 need to increase the size of the object causing an overflow.
1687 \note Cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
1693 uint32_t osRtxErrorNotify (uint32_t code, void *object_id) {
1697 case osRtxErrorStackUnderflow:
1698 // Stack underflow detected for thread (thread_id=object_id)
1700 case osRtxErrorISRQueueOverflow:
1701 // ISR Queue overflow detected when inserting object (object_id)
1703 case osRtxErrorTimerQueueOverflow:
1704 // User Timer Callback Queue overflow detected for timer (timer_id=object_id)
1706 case osRtxErrorClibSpace:
1707 // Standard C/C++ library libspace not available: increase OS_THREAD_LIBSPACE_NUM
1709 case osRtxErrorClibMutex:
1710 // Standard C/C++ library mutex initialization failed
1721 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1722 osRtxErrorClibMutex /**
1723 \fn void osRtxIdleThread (void *argument);
1725 The function \b osRtxIdleThread is executed by the RTX kernel, when no other threads are ready to run. By default, this
1726 thread is an empty end-less loop that does nothing. It only waits until another task becomes ready to run. You may change the
1727 code of the \b osRtxIdleThread function to put the CPU into a power-saving or idle mode, see \ref TickLess.
1729 The default stack size for this thread is defined in the file RTX_Config.h. Refer to \ref threadConfig.
1731 \note Cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
1737 __NO_RETURN void osRtxIdleThread (void *argument) {