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 Support for critical and uncritical sections (nesting safe):
84 - updated: \ref osKernelLock, \ref osKernelUnlock
85 - added: \ref osKernelRestoreLock
87 Updated \ref CMSIS_RTOS_ThreadFlagsMgmt "Thread Flags" and \ref CMSIS_RTOS_EventFlags "Event Flags":
88 - changed flags parameter and return type from int32_t to uint32_t
94 New API Version 2.0 available.
95 - See \ref rtos_api2 for a detailed function reference.
96 - See \ref os2Migration for details on the migration process from API Version 1.
100 <td>V1.02 - only documentation changes</td>
102 Added: Overview of the \ref rtosValidation "CMSIS-RTOS Validation" Software Pack.\n
103 Clarified: Behavior of \ref CMSIS_RTOS_TimeOutValue.
108 <td>Added: New control functions for short timeouts in microsecond resolution \b osKernelSysTick,
109 \b osKernelSysTickFrequency, \b osKernelSysTickMicroSec.\n
110 Removed: osSignalGet.
115 <td>Added capabilities for C++, kernel initialization and object deletion.\n
116 Prepared for C++ class interface. In this context to \em const attribute has been moved from osXxxxDef_t typedefs to
117 the osXxxxDef macros.\n
118 Added: \ref osTimerDelete, \ref osMutexDelete, \ref osSemaphoreDelete.\n
119 Added: \ref osKernelInitialize that prepares the kernel for object creation.\n
125 <td>First official Release.\n
126 Added: \ref osKernelStart; starting 'main' as a thread is now an optional feature.\n
127 Semaphores have now the standard behavior.\n
128 \b osTimerCreate does no longer start the timer. Added: \ref osTimerStart (replaces osTimerRestart).\n
129 Changed: osThreadPass is renamed to \ref osThreadYield.
134 <td>Preview Release.</td>
139 \section RTX5RevisionHistory CMSIS-RTOS RTX Version 5
141 <table class="cmtable" summary="Revision History">
149 - Fixed potential corruption of terminated threads list.
150 - Corrected MessageQueue to use actual message length (before padding).
151 - Corrected parameters for ThreadEnumerate and MessageQueueInserted events.
152 - Timer Thread creation moved to osKernelStart.
158 - Based on CMSIS-RTOS API V2.1.
159 - Added support for Event recording.
160 - Added support for IAR compiler.
161 - Updated configuration files: RTX_Config.h for the configuration settings and RTX_config.c for implementing the \ref rtx5_specific.
162 - osRtx name-space for RTX specific symbols.
168 Initial release compliant to CMSIS-RTOS2.\n
175 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
177 \page genRTOS2IF Generic RTOS Interface
179 CMSIS-RTOS2 is a generic API that is agnostic of the underlying RTOS kernel. Application programmers call CMSIS-RTOS2 API
180 functions in the user code to ensure maximum portability from one RTOS to another. Middleware using CMSIS-RTOS2 API takes
181 advantages of this approach by avoiding unnecessary porting efforts.
183 \image html "API_Structure.png" "CMSIS-RTOS API Structure"
185 A typical CMSIS-RTOS2 API implementation interfaces to an existing real-time kernel. The CMSIS-RTOS2 API provides the
186 following attributes and functionalities:
187 - Function names, identifiers, and parameters are descriptive and easy to understand. The functions are powerful and
188 flexible which reduces the number of functions exposed to the user.
189 - \ref CMSIS_RTOS_ThreadMgmt allows you to define, create, and control threads.
190 - Interrupt Service Routines (ISR) can \ref CMSIS_RTOS_ISR_Calls "call some CMSIS-RTOS functions". When a CMSIS-RTOS
191 function cannot be called from an ISR context, it rejects the invocation and returns an error code.
192 - Three different event types support communication between multiple threads and/or ISR:
193 - \ref CMSIS_RTOS_ThreadFlagsMgmt "Thread Flags": may be used to indicate specific conditions to a thread.
194 - \ref CMSIS_RTOS_EventFlags "Event Flags": may be used to indicate events to a thread or ISR.
195 - \ref CMSIS_RTOS_Message "Messages": can be sent to a thread or an ISR. Messages are buffered in a queue.
196 - \ref CMSIS_RTOS_MutexMgmt and \ref CMSIS_RTOS_SemaphoreMgmt are incorporated.
197 - CPU time can be scheduled with the following functionalities:
198 - A \a timeout parameter is incorporated in many CMSIS-RTOS functions to avoid system lockup. When a timeout is specified,
199 the system waits until a resource is available or an event occurs. While waiting, other threads are scheduled.
200 - The \ref osDelay and \ref osDelayUntil functions put a thread into the \b WAITING state for a specified period of time.
201 - The \ref osThreadYield provides co-operative thread switching and passes execution to another thread of the same
203 - \ref CMSIS_RTOS_TimerMgmt functions are used to trigger the execution of functions.
205 The CMSIS-RTOS2 API is designed to optionally incorporate multi-processor systems and/or access protection via the Cortex-M
206 Memory Protection Unit (MPU).
208 In some RTOS implementations threads may execute on different processors, thus \b message queues may reside in shared memory
211 The CMSIS-RTOS2 API encourages the software industry to evolve existing RTOS implementations. RTOS implementations can be
212 different and optimized in various aspects towards the Cortex-M processors. Optional features may be for example
213 - Support of the Cortex-M Memory Protection Unit (MPU).
214 - Support of multi-processor systems.
215 - Support of a DMA controller.
216 - Deterministic context switching.
217 - Round-robin context switching.
218 - Deadlock avoidance, for example with priority inversion.
219 - Zero interrupt latency by using ARMv7-M instructions LDREX and STREX.
221 \section usingOS2 Using a CMSIS-RTOS2 Implementation
223 A CMSIS-RTOS2 implementation is typically provided as a library. To add the RTOS functionality to an existing CMSIS-based
224 application, the RTOS library (and typically one or more configuration files) needs to be added. There is a single new header
225 file %cmsis_os2.h available. This is the only header file required for a completely portable application. In such a case,
226 user provided memory for control blocks, objects data and thread stack cannot be used. Alternatively, you can include an
227 implementation specific header file (for example rtx_os.h) which provides definitions also for resource allocation (such as
228 size of control blocks, required memory for object data and thread stack). This is optional and implies that the application
229 code is not completely portable.
231 \image html "CMSIS_RTOS_Files.png" "CMSIS-RTOS File Structure"
233 Once the files are added to a project, the user can start working with the CMSIS-RTOS functions. A code example is provided
238 /*----------------------------------------------------------------------------
239 * CMSIS-RTOS 'main' function template
240 *---------------------------------------------------------------------------*/
242 #include "RTE_Components.h"
243 #include CMSIS_device_header
244 #include "cmsis_os2.h"
246 /*----------------------------------------------------------------------------
247 * Application main thread
248 *---------------------------------------------------------------------------*/
249 void app_main (void *argument) {
257 // System Initialization
258 SystemCoreClockUpdate();
259 #ifdef RTE_Compiler_EventRecorder
260 // Initialize and start Event Recorder
261 EventRecorderInitialize(EventRecordError, 1U);
265 osKernelInitialize(); // Initialize CMSIS-RTOS
266 osThreadNew(app_main, NULL, NULL); // Create application main thread
267 osKernelStart(); // Start thread execution
273 \section cmsis_os2_h cmsis_os2.h header file
275 The file \b cmsis_os2.h is a standard header file that interfaces to every CMSIS-RTOS2 compliant real-time operating
276 systems (RTOS). Each implementation is provided the same \b cmsis_os2.h which defines the interface to the \ref rtos_api2.
278 Using the \b cmsis_os2.h along with dynamic object allocation allows to create source code or libraries that require no
279 modifications when using on a different CMSIS-RTOS2 implementation.
281 <b>Header file %cmsis_os2.h</b>
287 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
289 \page rtx5_impl RTX v5 Implementation
291 Keil RTX version 5 (RTX5) implements the CMSIS-RTOS2 as a native RTOS interface for ARM Cortex-M processor-based devices.
292 A translation layer to CMSIS-RTOS API v1 is provided. Therefore, RTX5 can be used in applications that where previously based
293 on RTX version 4 and CMSIS-RTOS version 1 with minimal effort.
295 The following sections provide further details:
296 - \subpage cre_rtx_proj explains how to setup an RTX v5 project in Keil MDK.
297 - \subpage theory_of_operation provides general information about the operation of CMSIS-RTOS RTX v5.
298 - \subpage config_rtx5 describes configuration parameters of CMSIS-RTOS RTX v5.
299 - \subpage creating_RTX5_LIB explains how to build your own CMSIS-RTOS RTX v5 library.
300 - \subpage dirstructfiles5 explains the directories and files that are supplied as part of CMSIS-RTOS RTX v5.
301 - \subpage technicalData5 lists microcontroller hardware requirements and limitations such as number of concurrent threads.
302 - \subpage misraCompliance5 describes the violations to the MISRA standard.
305 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
307 \page cre_rtx_proj Create an RTX5 Project
309 The steps to create a microcontroller application using RTX5 are:
310 - Create a new project and select a microcontroller device.
311 - In the Manage Run-Time Environment window, select <b>CMSIS\::CORE</b> and <b>CMSIS\::RTOS2 (API)\::Keil RTX5</b>. You can
312 choose to either add RTX as a library (Variant: \b Library) or to add the full source code (Variant: \b Source - required
313 if using the <a href="http://www.keil.com/pack/doc/compiler/EventRecorder/html/index.html" target="_blank"><b>Event Recorder</b></a>):
315 \image html manage_rte_output.png
317 - If the <b>Validation Output</b> requires other components to be present, try to use the \b Resolve button.
318 - Click \b OK. In the \b Project window, you will see the files that have been automatically added to you project, such as
319 \b %RTX_Config.h, \b %RTX_Config.c, the library or the source code files, as well as the system and startup files:
321 \image html project_window.png
323 - 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).
324 - You can add template files to the project by right-clicking on <b>Source Group 1</b> and selecting
325 <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
326 you will see all available template files for CMSIS-RTOS RTX:
328 \image html add_item.png
330 - \ref config_rtx5 "Configure" RTX5 to the application's needs using the \b %RTX_Config.h file.
332 \section cre_rtx_proj_specifics Add support for RTX specific functions
333 If you require some of the \ref rtx5_specific "RTX specific functions" in your application code, \#include the
334 \ref rtx_os_h "header file rtx_os.h". This enables \ref lowPower "low-power" and \ref TickLess "tick-less" operation modes.
337 \section cre_rtx_proj_er Add Event Recorder Visibility
338 - To use the Event Recorder together with RTX5, select the software component <b>Compiler:Event Recorder</b>.
339 - Select the \b Source variant of the software component <b>CMSIS:RTOS2 (API):Keil RTX5</b>.
340 \image html event_recorder_rte.png "Component selection for Event Recorder"
341 - Call the function <b>EventRecorderInitialize()</b> in your application code (ideally in \c main()).
342 - Build the application code and download it to the debug hardware.
344 Once the target application generates event information, it can be viewed in the µVision debugger using the \b Event
349 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
351 \page theory_of_operation Theory of Operation
353 Many aspects of the kernel are configurable and the configuration options are mentioned where applicable.
355 \section SystemStartup System Startup
357 Since main is no longer a thread RTX5 does not interfere with the system startup until main is reached.
358 Once the execution reaches \c main() there is a recommended order to initialize the hardware and start the kernel. This is
359 also reflected in the user code template file "CMSIS-RTOS2 'main' function" supplied with the RTX5 component.
361 Your application's \c main() should implement at least the following in the given order:
362 -# Initialization and configuration of hardware including peripherals, memory, pins, clocks and the interrupt system.
363 -# Update the system core clock using the respective
364 <a href=../../Core/html/group__system__init__gr.html>CMSIS-Core (Cortex-M) function</a>.
365 -# Initialize the CMSIS-RTOS kernel using \ref osKernelInitialize.
366 -# Optionally, create a new thread \c app_main, which is used as a main thread using \ref osThreadNew. Alternatively, threads
367 can be created in \c main() directly.
368 -# Start the RTOS scheduler using \ref osKernelStart. This function does not return in case of successful execution. Any
369 application code after \b osKernelStart will not be executed unless \b osKernelStart fails.
371 \note Interrupts (like SVC for example) used by the kernel are initialized in \ref osKernelInitialize. In case priorities and
372 groupings in the NVIC are altered by the application after the above sequence it might be necessary to call
373 \ref osKernelInitialize again.
377 RTX5 implements a low-latency preemtive scheduler. Major parts of RTX5 are executed in handler mode such as
378 - \ref SysTick_Handler used for time-based scheduling.
379 - \ref SVC_Handler used for lock-based scheduling.
380 - \ref PendSV_Handler used for interrupt-based scheduling.
382 In order to be low-latency with respect to ISR execution those system exceptions are configured to use the
383 lowest priority groups available. The priorities are configured such that no preemption happens between them. Thus
384 no interrupt critical sections (i.e. interrupt locks) are needed to protect the scheduler.
386 \image html scheduling.png "Thread scheduling and interrupt execution"
388 The scheduler combines priority and round-robin based context switches. The example depicted in the image above contains
389 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
390 (\ref osThreadAttr_t::priority). As long as threads 3 and 4 are blocked the scheduler switches between thread 1 and 2 on
391 a time-slice basis (round-robin). The time-slice for round-robin scheduling can be configured, see Round-Robin Timeout in \ref systemConfig.
393 Thread 2 unblocks thread 3 by an arbitrary RTOS-call (executed in SVC handler mode) at time index 2. The scheduler switches to
394 thread 3 immidiately because thread 3 has the highest priority. Thread 4 is still blocked.
396 At time index 4 an interrupt (ISR) occurs and preempts the SysTick_Handler. RTX does not add any latency to the interrupt
397 service execution. The ISR routine uses an RTOS-call that unblocks thread 4. Instead of switching to thread 4 immediately
398 the PendSV flag is set to defer the context switching. The PendSV_Handler is executed right after the SysTick_Handler returns
399 and the defered context switch to thread 4 is carried out. As soon as highest priority thread 4 blocks again by using
400 a blocking RTOS-call execution is switched back to thread 3 immidiately during time index 5.
402 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.
403 At time index 7 the scheduler uses the round-robin mechanism to switch to thread 1 and so on.
405 \section MemoryAllocation Memory Allocation
407 RTX5 objects (thread, mutex, semaphore, timer, message queue, thread and event flags, as well as memory pool) require
408 dedicated RAM memory. Objects can be created using os<i>Object</i>New() calls and deleted using os<i>Object</i>Delete()
409 calls. The related object memory needs to be available during the lifetime of the object.
411 RTX5 offers three different memory allocation methods for objects:
412 - \ref GlobalMemoryPool uses a single global memory pool for all objects. It is easy to configure, but may have
413 the disadvantage for memory fragmentation when objects with different sizes are created and destroyed.
414 - \ref ObjectMemoryPool uses a fixed-size memory pool for each object type. The method is time deterministic
415 and avoids memory fragmentation.
416 - \ref StaticObjectMemory reserves memory during compile time and completely avoids that a system can be out of memory.
417 This is typically a required for some safety critical systems.
419 It possible to intermix all the memory allocation methods in the same application.
421 \subsection GlobalMemoryPool Global Memory Pool
423 The global memory pool allocates all objects from a memory area. This method of memory allocation is the default
424 configuration setting of RTX5.
426 \image html MemAllocGlob.png "Global Memory Pool for all objects"
428 When the memory pool does not provide sufficient memory, the creation of the object fails and the related
429 os<i>Object</i>New() function returns \token{NULL}.
431 Enabled in \ref systemConfig.
433 \subsection ObjectMemoryPool Object-specific Memory Pools
435 Object-specific memory pools avoids memory fragmentation with a dedicated fixed-size memory management for each object type.
436 This type of memory pools are fully time deterministic, which means that object creation and destruction takes always the
437 same fixed amount of time. As a fixed-size memory pool is specific to an object type, the handling of out-of-memory
438 situations is simplified.
440 \image html MemAllocSpec.png "One memory pool per object type"
442 Object-specific memory pools are selectively enabled for each object type, e.g: mutex or thread using the RTX configuration
444 - Enabled in \ref threadConfig for thread objects.
445 - Enabled in \ref timerConfig for timer objects.
446 - Enabled in \ref eventFlagsConfig for event objects.
447 - Enabled in \ref mutexConfig for mutex objects.
448 - Enabled in \ref semaphoreConfig for semaphore.
449 - Enabled in \ref memPoolConfig for memory pools.
450 - Enabled in \ref msgQueueConfig for message objects.
452 When the memory pool does not provide sufficient memory, the creation of the object fails and the related
453 os<i>Object</i>New() function returns \token{NULL}.
455 \subsection StaticObjectMemory Static Object Memory
456 In contrast to the dynamic memory allocations, the static memory allocation requires compile-time allocation of object memory.
458 \image html MemAllocStat.png "Statically allocated memory for all objects"
460 The following code example shows how to create an OS object using static memory.
462 <b> Code Example:</b>
464 /*----------------------------------------------------------------------------
465 * CMSIS-RTOS 'main' function template
466 *---------------------------------------------------------------------------*/
468 #include "RTE_Components.h"
469 #include CMSIS_device_header
470 #include "cmsis_os2.h"
472 //include rtx_os.h for types of RTX objects
475 //The thread function instanced in this example
476 void worker(void *arg)
485 // Define objects that are statically allocated for worker thread 1
486 osRtxThread_t worker_thread_tcb_1;
488 // Reserve two areas for the stacks of worker thread 1
489 // uint64_t makes sure the memory alignment is 8
490 uint64_t worker_thread_stk_1[64];
492 // Define the attributes which are used for thread creation
493 // Optional const saves RAM memory and includes the values in periodic ROM tests
494 const osThreadAttr_t worker_attr_1 = {
497 &worker_thread_tcb_1,
498 sizeof(worker_thread_tcb_1),
499 &worker_thread_stk_1[0],
500 sizeof(worker_thread_stk_1),
501 osPriorityAboveNormal,
505 // Define ID object for thread
508 /*----------------------------------------------------------------------------
509 * Application main thread
510 *---------------------------------------------------------------------------*/
511 void app_main (void *argument) {
512 uint32_t param = NULL;
514 // Create an instance of the worker thread with static resources (TCB and stack)
515 th1 = osThreadNew(worker, ¶m, &worker_attr_1);
521 // System Initialization
522 SystemCoreClockUpdate();
525 osKernelInitialize(); // Initialize CMSIS-RTOS
526 osThreadNew(app_main, NULL, NULL); // Create application main thread
527 osKernelStart(); // Start thread execution
533 \section ThreadStack Thread Stack Management
535 For Cortex-M processors without floating point unit the thread context requires 64 bytes on the local stack.
537 \note For Cortex-M4/M7 with FP the thread context requires 200 bytes on the local stack. For these devices the default stack
538 space should be increased to a minimum of 300 bytes.
540 Each thread is provided with a separate stack that holds the thread context and stack space for automatic variables and
541 return addresses for function call nesting. The stack sizes of RTX threads are flexibly configurable as explained in the
542 section \ref threadConfig. RTX offers a configurable checking for stack overflows and stack utilization.
545 \section lowPower Low-Power Operation
547 The system thread \b osRtxIdleThread can be use to switch the system into a low-power mode. The easiest form to enter a
548 low-power mode is the execution of the \c __WFE function that puts the processor into a sleep mode where it waits for an
553 #include "RTE_Components.h"
554 #include CMSIS_device_header /* Device definitions */
556 void osRtxIdleThread (void) {
557 /* The idle demon is a system thread, running when no other thread is */
561 __WFE(); /* Enter sleep mode */
567 \c __WFE() is not available in every Cortex-M implementation. Check device manuals for availability.
570 \section kernelTimer RTX Kernel Timer Tick
572 By default, RTX5 uses the Cortex-M
573 <a href="http://www.keil.com/support/man/docs/gsac/GSAC_SYSTICKtimer.htm" target="_blank">SysTick</a> timer to generate
574 periodic interrupts for the RTX kernel timer tick. CMSIS-RTOS provides \ref CMSIS_RTOS_TimerMgmt functions and several
575 CMSIS-RTOS functions have a \a timeout parameter. This periodic RTX kernel timer tick interrupt is used to derive the
576 required time interval. RTX5 also provides configuration options for an \ref kernelTimer_alt "alternative timer" and
577 \ref TickLess "tick-less operation".
579 To handle timeout and time delays for threads, the RTX5 thread management is controlled by the RTX kernel timer tick
580 interrupt. The thread context contains all CPU registers (R0 - R12), the return address (LR), the program counter (PC), and
581 the processor status register (xPSR). For the Cortex-M4/M7 FPU the floating point status and registers (S0 - S32, FPSCR) are
582 also part of the thread context.
584 When a thread switch occurs:
585 - the thread context of the current running thread is stored on the local stack of this thread.
586 - the stack pointer is switched to the next running thread.
587 - the thread context of this next running thread is restored and this thread starts to run.
590 \subsection kernelTimer_alt Using an Alternative Timer as RTX Kernel Timer
592 The following functions need to be adapted to enable the usage of an alternative kernel timer:
593 - \ref osRtxSysTimerSetup sets up the timer (including IRQ priority) and returns its IRQ number. Note that it is no longer
594 required to start the time in this function as a separate function is available (see next).
595 - \ref osRtxSysTimerEnable starts the timer.
596 - \ref osRtxSysTimerDisable stops the timer.
597 - \ref osRtxSysTimerAckIRQ acknowledges the IRQ.
598 - \ref osRtxSysTimerGetCount returns the current tick count as a 32-bit value. Note that this function can be called when
599 the timer is disabled. It should still provide valid tick count values.
600 - \ref osRtxSysTimerGetFreq returns the timer tick frequency. Note that this function can be called when the
601 timer is disabled. It should still provide valid tick frequency values.
603 It is important to configure the IRQ priority (it should match PendSV). This can be achieved using the ExtTick_SetupIRQ()
604 function from core_cm.h. Enabling/disabling the IRQ is handled by the system.
606 There is no need to provide an IRQ handler. Only make sure that existing SysTick_Handler is mapped to the tick IRQ.
610 The following code example shows an implementation for a Cortex-A core that does not come with a built-in SysTick timer.
613 #include "RTE_Components.h"
614 #include CMSIS_device_header
617 int32_t osRtxSysTimerSetup (void) {
620 /* Private Timer runs with the system frequency */
621 load = osRtxInfo.kernel.sys_freq / osRtxConfig.tick_freq;
623 PTIM_SetLoadValue (load - 1U);
625 /* Determine number of implemented priority bits */
626 GIC_SetPriority (PrivTimer_IRQn, 0xFFU);
628 /* Set lowest priority -1 */
629 GIC_SetPriority (PrivTimer_IRQn, GIC_GetPriority(PrivTimer_IRQn)-1);
632 GIC_EnableIRQ (PrivTimer_IRQn);
634 return (PrivTimer_IRQn);
637 void osRtxSysTimerEnable (void) {
638 /* Start the Private Timer */
641 ctrl = PTIM_GetControl();
642 /* Set bits: IRQ enable, Auto Reload, Timer enable */
645 PTIM_SetControl (ctrl);
648 void osRtxSysTimerDisable (void) {
649 /* Stop the Private Timer */
652 ctrl = PTIM_GetControl();
653 /* Clear bit: Timer enable */
656 PTIM_SetControl (ctrl);
659 void osRtxSysTimerAckIRQ (void) {
660 PTIM_ClearEventFlag();
663 uint32_t osRtxSysTimerGetCount (void) {
667 tick = (uint32_t)osRtxInfo.kernel.tick;
668 val = PTIM_GetLoadValue();
669 val -= PTIM_GetCurrentValue();
671 /* if (PTIM_GetEventFlag() != 0) */
672 if ((PTIM->ISR & 1) != 0) {
673 val = PTIM_GetLoadValue();
674 val -= PTIM_GetCurrentValue();
677 val += tick * (PTIM_GetLoadValue() + 1U);
682 uint32_t osRtxSysTimerGetFreq (void) {
683 /* Private Timer runs with the system frequency */
684 return osRtxInfo.kernel.sys_freq;
688 \subsection TickLess Tick-less Low-Power Operation
690 RTX5 provides extension for tick-less operation which is useful for applications that use extensively low-power modes where
691 the SysTick timer is also disabled. To provide a time-tick in such power-saving modes, a wake-up timer is used to
692 derive timer intervals. The CMSIS-RTOS2 functions \ref osKernelSuspend and \ref osKernelResume control the tick-less
695 Using this functions allows the RTX5 thread scheduler to stop the periodic kernel tick interrupt. When all active threads
696 are suspended, the system enters power-down and calculates how long it can stay in this power-down mode. In the power-down
697 mode the processor and peripherals can be switched off. Only a wake-up timer must remain powered, because this timer is
698 responsible to wake-up the system after the power-down period expires.
700 The tick-less operation is controlled from the \b osRtxIdleThread thread. The wake-up timeout value is set before the system
701 enters the power-down mode. The function \ref osKernelSuspend calculates the wake-up timeout measured in RTX Timer Ticks;
702 this value is used to setup the wake-up timer that runs during the power-down mode of the system.
704 Once the system resumes operation (either by a wake-up time out or other interrupts) the RTX5 thread scheduler is started
705 with the function \ref osKernelResume. The parameter \a sleep_time specifies the time (in RTX Timer Ticks) that the system
706 was in power-down mode.
710 #include "msp.h" // Device header
712 /*----------------------------------------------------------------------------
713 * MSP432 Low-Power Extension Functions
714 *---------------------------------------------------------------------------*/
715 static void MSP432_LP_Entry(void) {
716 /* Enable PCM rude mode, which allows to device to enter LPM3 without waiting for peripherals */
717 PCM->CTL1 = PCM_CTL1_KEY_VAL | PCM_CTL1_FORCE_LPM_ENTRY;
718 /* Enable all SRAM bank retentions prior to going to LPM3 */
719 SYSCTL->SRAM_BANKRET |= SYSCTL_SRAM_BANKRET_BNK7_RET;
720 __enable_interrupt();
721 NVIC_EnableIRQ(RTC_C_IRQn);
722 /* Do not wake up on exit from ISR */
723 SCB->SCR |= SCB_SCR_SLEEPONEXIT_Msk;
724 /* Setting the sleep deep bit */
725 SCB->SCR |= (SCB_SCR_SLEEPDEEP_Msk);
728 static volatile unsigned int tc;
729 static volatile unsigned int tc_wakeup;
731 void RTC_C_IRQHandler(void)
733 if (tc++ > tc_wakeup)
735 SCB->SCR &= ~SCB_SCR_SLEEPONEXIT_Msk;
736 NVIC_DisableIRQ(RTC_C_IRQn);
737 NVIC_ClearPendingIRQ(RTC_C_IRQn);
740 if (RTC_C->PS0CTL & RTC_C_PS0CTL_RT0PSIFG)
742 RTC_C->CTL0 = RTC_C_KEY_VAL; // Unlock RTC key protected registers
743 RTC_C->PS0CTL &= ~RTC_C_PS0CTL_RT0PSIFG;
745 SCB->SCR |= (SCB_SCR_SLEEPDEEP_Msk);
749 uint32_t g_enable_sleep = 0;
751 void osRtxIdleThread (void) {
754 tc_wakeup = osKernelSuspend();
755 /* Is there some time to sleep? */
758 /* Enter the low power state */
762 /* Adjust the kernel ticks with the amount of ticks slept */
769 \c __WFE() is not available in every ARM Cortex-M implementation. Check device manuals for availability.
770 The alternative using \c __WFI() has other issues, please take note of http://www.keil.com/support/docs/3591.htm as well.
772 \section rtx_os_h RTX5 Header File
774 Every implementation of the CMSIS-RTOS2 API can bring its own additional features. RTX5 adds a couple of
775 \ref rtx5_specific "functions" for the idle more, for error notifications, and special system timer functions. It also is
776 using macros for control block and memory sizes.
778 If you require some of the RTX specific functions in your application code, \#include the header file \b %rtx_os.h:
783 \section CMSIS_RTOS_TimeOutValue Timeout Value
785 Timeout values are an argument to several \b osXxx functions to allow time for resolving a request. A timeout value of \b 0
786 means that the RTOS does not wait and the function returns instantly, even when no resource is available. A timeout value of
787 \ref osWaitForever means that the RTOS waits infinitely until a resource becomes available. Or one forces the thread to resume
788 using \ref osThreadResume which is discouraged.
790 The timeout value specifies the number of timer ticks until the time delay elapses. The value is an upper bound and
791 depends on the actual time elapsed since the last timer tick.
794 - timeout value \b 0 : the system does not wait, even when no resource is available the RTOS function returns instantly.
795 - timeout value \b 1 : the system waits until the next timer tick occurs; depending on the previous timer tick, it may be a
796 very short wait time.
797 - timeout value \b 2 : actual wait time is between 1 and 2 timer ticks.
798 - timeout value \ref osWaitForever : system waits infinite until a resource becomes available.
800 \image html TimerValues.png "Example of timeout using osDelay()"
803 \section CMSIS_RTOS_ISR_Calls Calls from Interrupt Service Routines
805 The following CMSIS-RTOS2 functions can be called from threads and Interrupt Service Routines (ISR):
806 - \ref osKernelGetSysTimerCount, \ref osKernelGetSysTimerFreq
807 - \ref osThreadFlagsSet
808 - \ref osEventFlagsSet, \ref osEventFlagsClear, \ref osEventFlagsGet, \ref osEventFlagsWait
809 - \ref osSemaphoreAcquire, \ref osSemaphoreRelease, \ref osSemaphoreGetCount
810 - \ref osMemoryPoolAlloc, \ref osMemoryPoolFree, \ref osMemoryPoolGetCapacity, \ref osMemoryPoolGetBlockSize,
811 \ref osMemoryPoolGetCount, \ref osMemoryPoolGetSpace
812 - \ref osMessageQueuePut, \ref osMessageQueueGet, \ref osMessageQueueGetCapacity, \ref osMessageQueueGetMsgSize,
813 \ref osMessageQueueGetCount, \ref osMessageQueueGetSpace
815 Functions that cannot be called from an ISR are verifying the interrupt status and return the status code \b osErrorISR, in
816 case they are called from an ISR context. In some implementations, this condition might be caught using the HARD_FAULT
820 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
822 \page config_rtx5 Configure RTX v5
824 The file "RTX_Config.h" defines the configuration parameters of CMSIS-RTOS RTX and must be part of every project that is
825 using the CMSIS-RTOS RTX kernel. The file "RTX_Config.c" contains stubs of the functions \b osRtxIdleThread and
826 \b osRtxErrorNotify that can be adapted to the application's needs.
828 The configuration file uses
829 <b>Configuration Wizard Annotations</b>. Refer to <b>Pack - Configuration Wizard Annotations</b> for details.
830 Depending on the development tool, the annotations might lead to a more user-friendly graphical representation of the
831 settings. The screenshot below is a screenshot from the µVision \b Configuration \b Wizard view:
833 \image html config_wizard.png "RTX_Config.h in Configuration Wizard View"
835 The configuration options are explained on these pages:
839 - \ref eventFlagsConfig
841 - \ref semaphoreConfig
843 - \ref msgQueueConfig
846 \section systemConfig System Configuration
848 The system configuration covers system-wide settings for the global memory pool, tick frequency, ISR event buffer and
849 round-robin thread switching.
851 <b>System Configuration Options</b>
852 \image html config_wizard_system.png "RTX_Config.h: System Configuration"
854 Name | \#define | Description
855 ---------------------------------------|--------------------------|----------------------------------------------------------------
856 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.
857 Kernel Tick Frequency (Hz) | \c OS_TICK_FREQ | Defines base time unit for delays and timeouts in Hz. Default: 1000Hz = 1ms period.
858 Round-Robin Thread switching | \c OS_ROBIN_ENABLE | Enables Round-Robin Thread switching.
859 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]}.
860 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}.
862 \subsection systemConfig_glob_mem Global dynamic memory
863 Refer to \ref GlobalMemoryPool.
866 \subsection systemConfig_rr Round-Robin Thread Switching
868 RTX5 may be configured to use round-robin multitasking thread switching. Round-robin allows quasi-parallel execution of
869 several threads of the \a same priority. Threads are not really executed concurrently, but are scheduled where the available
870 CPU time is divided into time slices and RTX5 assigns a time slice to each thread. Because the time slice is typically short
871 (only a few milliseconds), it appears as though threads execute simultaneously.
873 Round-robin thread switching functions as follows:
874 - the tick is preloaded with the timeout value when a thread switch occurs
875 - the tick is decremented (if not already zero) each system tick if the same thread is still executing
876 - when the tick reaches 0 it indicates that a timeout has occurred. If there is another thread ready with the \a same
877 priority, then the system switches to that thread and the tick is preloaded with timeout again.
879 In other words, threads execute for the duration of their time slice (unless a thread's time slice is given up). Then, RTX
880 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
881 ready to run, the current running thread resumes it execution.
883 \note When switching to higher priority threads, the round-robin timeout value is reset.
885 Round-Robin multitasking is controlled with the <b>\#define OS_ROBIN_ENABLE</b>. The time slice period is configured (in RTX
886 timer ticks) with the <b>\#define OS_ROBIN_TIMEOUT</b>.
889 \subsection systemConfig_isr_fifo ISR FIFO Queue
890 The RTX functions (\ref CMSIS_RTOS_ISR_Calls), when called from and interrupt handler, store the request type and optional
891 parameter to the ISR FIFO queue buffer to be processed later, after the interrupt handler exits.
893 The scheduler is activated immediately after the IRQ handler has finished its execution to process the requests stored to the
894 FIFO queue buffer. The required size of this buffer depends on the number of functions that are called within the interrupt
895 handler. An insufficient queue size will be caught by \b osRtxErrorNotify with error code \b osRtxErrorISRQueueOverflow.
898 \section threadConfig Thread Configuration
900 The RTX5 provides several parameters to configure the \ref CMSIS_RTOS_ThreadMgmt functions.
902 <b>Thread Configuration Options</b>
903 \image html config_wizard_threads.png "RTX_Config.h: Thread Configuration"
906 Option | \#define | Description
907 :--------------------------------------------------------|:-----------------------|:---------------------------------------------------------------
908 Object specific Memory allocation | \c OS_THREAD_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
909 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]}.
910 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]}.
911 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}.
912 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}.
913 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}.
914 Stack overrun checking | \c OS_STACK_CHECK | Enable stack overrun checks at thread switch.
915 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.
916 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.
918 \subsection threadConfig_countstack Configuration of Thread Count and Stack Space
920 The RTX5 kernel uses a separate stack space for each thread and provides two methods for defining the stack requirements:
921 - <b>Static allocation</b>: when \ref osThreadAttr_t::stack_mem and \ref osThreadAttr_t::stack_size specify a memory area
922 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.
923 - <b>Dynamic allocation</b>: when \ref osThreadAttr_t is NULL or \ref osThreadAttr_t::stack_mem is NULL, the system
924 allocates the stack memory from:
925 - Object-specific Memory Pool (default Stack size) when "Object specific Memory allocation" is enabled and "Number of
926 user Threads with default Stack size" is not \token{0} and \ref osThreadAttr_t::stack_size is \token{0} (or
927 \ref osThreadAttr_t is NULL).
928 - Object-specific Memory Pool (user-provided Stack size) when "Object specific Memory allocation" is enabled and "Total
929 Stack size for user..." is not \token{0} and \ref osThreadAttr_t::stack_size is not \token{0}.
930 - Global Memory Pool when "Object specific Memory allocation" is disabled or (\ref osThreadAttr_t::stack_size is not
931 \token{0} and "Total Stack size for user..." is \token{0}) or (\ref osThreadAttr_t::stack_size is \token{0} and
932 "Number of user Threads with default Stack size" is \token{0}).
934 \ref osThreadAttr_t is a parameter of the function \ref osThreadNew.
937 Before the RTX kernel is started by the \ref osKernelStart() function, the main stack defined in startup_<i>device</i>.s is
938 used. The main stack is also used for:
939 - user application calls to RTX functions in \b thread \b mode using SVC calls
940 - interrupt/exception handlers.
942 \subsection threadConfig_ovfcheck Stack Overflow Checking
943 RTX5 implements a software stack overflow checking that traps stack overruns. Stack is used for return addresses and
944 automatic variables. Extensive usage or incorrect stack configuration may cause a stack overflow. Software stack overflow
945 checking is controlled with the define \c OS_STACK_CHECK.
947 If a stack overflow is detected, the function \b osRtxErrorNotify with error code \b osRtxErrorStackUnderflow is called. By
948 default, this function is implemented as an endless loop and will practically stop code execution.
950 \subsection threadConfig_watermark Stack Usage Watermark
951 RTX5 initializes thread stack with a watermark pattern (0xCC) when a thread is created. This allows the debugger to determine
952 the maximum stack usage for each thread. It is typically used during development but removed from the final application.
953 Stack usage watermark is controlled with the define \c OS_STACK_WATERMARK.
955 Enabling this option significantly increases the execution time of \ref osThreadNew (depends on thread stack size).
957 \subsection threadConfig_procmode Processor Mode for Thread Execution
958 RTX5 allows to execute threads in unprivileged or privileged processor mode. The processor mode is controlled with the
959 define \c OS_PRIVILEGE_MODE.
961 In \b unprivileged processor mode, the application software:
962 - has limited access to the MSR and MRS instructions, and cannot use the CPS instruction.
963 - cannot access the system timer, NVIC, or system control block.
964 - might have restricted access to memory or peripherals.
966 In \b privileged processor mode, the application software can use all the instructions and has access to all resources.
969 \section timerConfig Timer Configuration
971 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_TimerMgmt functions.
973 <b>Timer Configuration Options</b>
974 \image html config_wizard_timer.png "RTX_Config.h: Timer Configuration"
976 Name | \#define | Description
977 ---------------------------------------|--------------------------|----------------------------------------------------------------
978 Object specific Memory allocation | \c OS_TIMER_OBJ_MEM | Enables object specific memory allocation.
979 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]}.
980 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}
981 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}.
982 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]}.
984 \subsection timerConfig_obj Object-specific memory allocation
985 See \ref ObjectMemoryPool.
987 \subsection timerConfig_user User Timer Thread
988 The RTX5 function \b osRtxTimerThread executes callback functions when a time period expires. The priority of the timer
989 subsystem within the complete RTOS system is inherited from the priority of the \b osRtxTimerThread. This is configured by
990 \c OS_TIMER_THREAD_PRIO. Stack for callback functions is supplied by \b osRtxTimerThread. \c OS_TIMER_THREAD_STACK_SIZE must
991 satisfy the stack requirements of the callback function with the highest stack usage.
994 \section eventFlagsConfig Event Flags Configuration
996 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_EventFlags functions.
998 <b>Event Configuration Options</b>
999 \image html config_wizard_eventFlags.png "RTX_Config.h: Event Flags Configuration"
1001 Name | \#define | Description
1002 ---------------------------------------|--------------------------|----------------------------------------------------------------
1003 Object specific Memory allocation | \c OS_EVFLAGS_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1004 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]}.
1006 \subsection eventFlagsConfig_obj Object-specific memory allocation
1007 When object-specific memory is used, the pool size for all Event objects is specified by \c OS_EVFLAGS_NUM. Refer to
1008 \ref ObjectMemoryPool.
1011 \section mutexConfig Mutex Configuration
1012 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_MutexMgmt functions.
1014 <b>Mutex Configuration Options</b>
1015 \image html config_wizard_mutex.png "RTX_Config.h: Mutex Configuration"
1018 Name | \#define | Description
1019 ---------------------------------------|--------------------------|----------------------------------------------------------------
1020 Object specific Memory allocation | \c OS_MUTEX_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1021 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]}.
1023 \subsection mutexConfig_obj Object-specific Memory Allocation
1024 When object-specific memory is used, the pool size for all Mutex objects is specified by \c OS_MUTEX_NUM. Refer to
1025 \ref ObjectMemoryPool.
1028 \section semaphoreConfig Semaphore Configuration
1030 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_SemaphoreMgmt functions.
1032 <b>Semaphore Configuration Options</b>
1033 \image html config_wizard_semaphore.png "RTX_Config.h: Semaphore Configuration"
1036 Name | \#define | Description
1037 ---------------------------------------|--------------------------|----------------------------------------------------------------
1038 Object specific Memory allocation | \c OS_SEMAPHORE_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1039 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]}.
1041 \subsection semaphoreConfig_obj Object-specific memory allocation
1042 When Object-specific Memory is used, the pool size for all Semaphore objects is specified by \c OS_SEMAPHORE_NUM. Refer to
1043 \ref ObjectMemoryPool.
1046 \section memPoolConfig Memory Pool Configuration
1048 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_PoolMgmt functions.
1050 <b>Memory Pool Configuration Options</b>
1051 \image html config_wizard_memPool.png "RTX_Config.h: Memory Pool Configuration"
1053 Name | \#define | Description
1054 ---------------------------------------|--------------------------|----------------------------------------------------------------
1055 Object specific Memory allocation | \c OS_MEMPOOL_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1056 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]}.
1057 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}.
1059 \subsection memPoolConfig_obj Object-specific memory allocation
1060 When object-specific memory is used, the number of pools for all MemoryPool objects is specified by \c OS_MEMPOOL_NUM. The
1061 total storage size reserved for all pools is configured in \c OS_MEMPOOL_DATA_SIZE. Refer to \ref ObjectMemoryPool.
1064 \section msgQueueConfig Message Queue Configuration
1066 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_Message functions.
1068 <b>MessageQueue Configuration Options</b>
1069 \image html config_wizard_msgQueue.png "RTX_Config.h: Message Queue Configuration"
1071 Name | \#define | Description
1072 ---------------------------------------|--------------------------|----------------------------------------------------------------
1073 Object specific Memory allocation | \c OS_MSGQUEUE_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1074 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]}.
1075 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}.
1077 \subsection msgQueueConfig_obj Object-specific memory allocation
1078 When Object-specific Memory is used, the number of queues for all Message Queue objects is specified by \c OS_MSGQUEUE_NUM.
1079 The total storage size reserved for all queues is configured in \c OS_MSGQUEUE_DATA_SIZE. Refer to \ref ObjectMemoryPool.
1083 /* ========================================================================================================================== */
1085 \page creating_RTX5_LIB Building the RTX5 Library
1087 The CMSIS Pack contains a µVision project for building the complete set of RTX5 libraries. This project can also be used as
1088 a reference for building the RTX5 libraries using a tool-chain of your choice.
1090 -# Open the project \b RTX_CM.uvprojx from the pack folder <b>CMSIS/RTOS2/RTX/Library/ARM/MDK</b> in µVision.
1091 -# Select the project target that matches your device's processor core.
1092 \n The project provides target configuration for all supported Cortex-M targets supported by RTX5.
1093 -# You can find out about the required preprocessor defines in the dialogs <b>Options for Target - C/C++</b> and
1094 <b>Options for Target - Asm</b>. Note the need to use at least the C99 compiler mode when building RTX from source.
1095 -# From the <b>Project</b> window you find the list of source files required for a complete library build.
1096 -# Build the library of your choice using \b Project - \b Build \b Target (or press F7).
1098 \image html own_lib_projwin.png "Project with files for ARMv8-M Mainline"
1102 /* ========================================================================================================================== */
1104 \page dirstructfiles5 Directory Structure and File Overview
1106 The following section provides an overview of the directory structure and the files that are relevant for the user's for
1107 CMSIS-RTOS RTX v5. The following directory references start below the CMSIS pack installation path, for example
1108 ARM/CMSIS/<i>version</i>/CMSIS/RTOS2.
1110 \section Folders RTX v5 Directory Structure
1112 The CMSIS-RTOS RTX v5 is delivered in source code and several examples are provided.
1114 <table class="cmtable" summary="CMSIS-RTOS RTX Library Files">
1121 <td>The include file for CMSIS-RTOS API v2. cmsis_os2.h is the central include file for user applications.</td>
1125 <td>CMSIS-RTOS API template source and header file.</td>
1129 <td>Directory with RTX specific files and folders. Also contains the component viewer description file.</td>
1133 <td>CMSIS-RTOS RTX configuration files %RTX_Config.h and %RTX_Config.c.</td>
1136 <td>RTX/Examples</td>
1137 <td>Example projects that can be directly used in development tools.</td>
1140 <td>RTX/Include</td>
1141 <td>RTX v5 specific include files.</td>
1144 <td>RTX/Include1</td>
1145 <td>CMSIS-RTOS v1 API header file.</td>
1148 <td>RTX/Library</td>
1149 <td>Pre-built libraries (see next table for details).</td>
1153 <td>Source code that can be used with ARMCC and GCC.</td>
1156 <td>RTX/Template</td>
1157 <td>User code templates for creating application projects with CMSIS-RTOS RTX v5.</td>
1161 \section libFiles RTX v5 Library Files
1163 The CMSIS-RTOS RTX Library is available pre-compiled for ARMCC and GCC compilers and supports all Cortex-M
1164 processor variants in every configuration, including ARM Cortex-M23 and Cortex-M33.
1166 <table class="cmtable" summary="CMSIS-RTOS RTX Library Files">
1168 <th>Library File</th>
1169 <th>Processor Configuration</th>
1172 <td>Library/ARM/RTX_CM0.lib</td>
1173 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Cortex-M0 and M1, little-endian.</td>
1176 <td>Library/ARM/RTX_CM3.lib</td>
1177 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Cortex-M3, M4, and M7 without FPU, little-endian.</td>
1180 <td>Library/ARM/RTX_CM4F.lib</td>
1181 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Cortex-M4 and M7 with FPU, little-endian.</td>
1184 <td>Library/ARM/RTX_V8MB.lib</td>
1185 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, ARMv8-M baseline.</td>
1188 <td>Library/ARM/RTX_V8MBN.lib</td>
1189 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, ARMv8-M baseline, non-secure.</td>
1192 <td>Library/ARM/RTX_V8MM.lib</td>
1193 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, ARMv8-M mainline.</td>
1196 <td>Library/ARM/RTX_V8MMF.lib</td>
1197 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, ARMv8-M mainline with FPU.</td>
1200 <td>Library/ARM/RTX_V8MMFN.lib</td>
1201 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, ARMv8-M mainline with FPU, non-secure.</td>
1204 <td>Library/ARM/RTX_V8MMN.lib</td>
1205 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, ARMv8-M mainline, non-secure.</td>
1208 <td>Library/GCC/libRTX_CM0.a</td>
1209 <td>CMSIS-RTOS libRTX Library for GCC Compiler, Cortex-M0 and M1, little-endian.</td>
1212 <td>Library/GCC/libRTX_CM3.a</td>
1213 <td>CMSIS-RTOS libRTX Library for GCC Compiler, Cortex-M3, M4, and M7 without FPU, little-endian.</td>
1216 <td>Library/GCC/libRTX_CM4F.a</td>
1217 <td>CMSIS-RTOS libRTX Library for GCC Compiler, Cortex-M4 and M7 with FPU, little-endian.</td>
1220 <td>Library/GCC/libRTX_V8MB.a</td>
1221 <td>CMSIS-RTOS libRTX Library for GCC Compiler, ARMv8-M baseline.</td>
1224 <td>Library/GCC/libRTX_V8MBN.a</td>
1225 <td>CMSIS-RTOS libRTX Library for GCC Compiler, ARMv8-M baseline, non-secure.</td>
1228 <td>Library/GCC/libRTX_V8MM.a</td>
1229 <td>CMSIS-RTOS libRTX Library for GCC Compiler, ARMv8-M mainline.</td>
1232 <td>Library/GCC/libRTX_V8MMF.a</td>
1233 <td>CMSIS-RTOS libRTX Library for GCC Compiler, ARMv8-M mainline with FPU.</td>
1236 <td>Library/GCC/libRTX_V8MMFN.a</td>
1237 <td>CMSIS-RTOS libRTX Library for GCC Compiler, ARMv8-M mainline with FPU, non-secure.</td>
1240 <td>Library/GCC/libRTX_V8MMN.a</td>
1241 <td>CMSIS-RTOS libRTX Library for GCC Compiler, ARMv8-M mainline, non-secure.</td>
1246 /* ========================================================================================================================== */
1248 \page technicalData5 Technical Data
1250 \section technicalData5_ControlBlockSizes Control Block Sizes
1252 Keil RTX5 specific control block definitions (including sizes) as well as memory pool and message queue memory requirements
1253 are defined in the RTX5 header file:
1256 /// Control Block sizes
1257 #define osRtxThreadCbSize sizeof(osRtxThread_t)
1258 #define osRtxTimerCbSize sizeof(osRtxTimer_t)
1259 #define osRtxEventFlagsCbSize sizeof(osRtxEventFlags_t)
1260 #define osRtxMutexCbSize sizeof(osRtxMutex_t)
1261 #define osRtxSemaphoreCbSize sizeof(osRtxSemaphore_t)
1262 #define osRtxMemoryPoolCbSize sizeof(osRtxMemoryPool_t)
1263 #define osRtxMessageQueueCbSize sizeof(osRtxMessageQueue_t)
1265 /// Memory size in bytes for Memory Pool storage.
1266 /// \param block_count maximum number of memory blocks in memory pool.
1267 /// \param block_size memory block size in bytes.
1268 #define osRtxMemoryPoolMemSize(block_count, block_size) \
1269 (4*(block_count)*(((block_size)+3)/4))
1271 /// Memory size in bytes for Message Queue storage.
1272 /// \param msg_count maximum number of messages in queue.
1273 /// \param msg_size maximum message size in bytes.
1274 #define osRtxMessageQueueMemSize(msg_count, msg_size) \
1275 (4*(msg_count)*(3+(((msg_size)+3)/4)))
1278 If you are using a \ref GlobalMemoryPool to allocate memory for the RTOS objects, you need to know the size that is required
1279 for each object in case of errors. Currently, the control block sizes are as follows (subject to change without
1282 Type | Control block size in bytes |
1283 --------------|:---------------------------:|
1290 Message Queue | 52 |
1292 The size of the memory that is required for memory pool and message queue data storage can be determined from the macros
1297 /* ========================================================================================================================== */
1299 \page misraCompliance5 MISRA-C Compliance Exceptions
1300 CMSIS-RTOS RTX tries to be MISRA-C compliant as much as possible. However, there are some violations in order to simplify
1301 the overall code logic and to generate more efficient code.
1303 This page will list the MISRA-C compliance exceptions. Work in progress.
1306 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1308 \page rtosValidation RTOS Validation
1310 ARM offers a <a class=el href="http://www.keil.com/pack" target="_blank">Software Pack</a> for the CMSIS-RTOS Validation.
1311 The <b>ARM::CMSIS-RTOS_Validation</b> Pack contains the following:
1313 - Source code of a CMSIS-RTOS Validation Suite along with configuration file.
1314 - Documentation of the CMSIS-RTOS Validation Suite.
1315 - Example that shows the usage of the CMSIS-RTOS Validation Suite using simulation.
1318 Currently, a public version of the test suite is available only for CMSIS-RTOS v1 API.
1320 The CMSIS-RTOS Validation Suite performs generic validation of various RTOS features. The test cases verify the
1321 functional behavior, test invalid parameters and call management functions from ISR.
1323 The following CMSIS-RTOS features can be tested with the current release:
1324 - Thread : Create multiple threads, terminate, restart, yield, change priority
1325 - Timer : Create periodic and one-shot timers
1326 - GenWait : Call generic wait functions (osDelay and osWait)
1327 - WaitFunc : Measure wait ticks (delay, mail, message, mutex, semaphore, signal)
1329 Moreover the following inter-thread communication functions can be tested:
1330 - Signal : Verify signal events
1331 - Memory Pool : Verify memory allocation
1332 - Message Queue : Exchange messages between threads
1333 - Mail Queue : Exchange data between threads
1334 - Mutex : Synchronize resource access
1335 - Semaphore : Access shared resources
1337 The RTOS Validation output can be printed to a console, output via ITM printf, or output to a memory buffer.
1339 \section test_output Sample Test Output
1341 CMSIS-RTOS Test Suite Oct 21 2015 16:39:16
1343 TEST 01: TC_ThreadCreate PASSED
1344 TEST 02: TC_ThreadMultiInstance PASSED
1345 TEST 03: TC_ThreadTerminate PASSED
1348 TEST 08: TC_ThreadChainedCreate PASSED
1349 TEST 09: TC_ThreadYield NOT EXECUTED
1350 TEST 10: TC_ThreadParam PASSED
1353 TEST 60: TC_MailFromISRToThread PASSED
1355 Test Summary: 60 Tests, 59 Executed, 59 Passed, 0 Failed, 0 Warnings.
1361 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1363 \page functionOverview Function Overview
1365 CMSIS-RTOS v2 provides multiple API interfaces:
1366 - \subpage rtos_api2 is the new C function API that supports dynamic object creation and ARMv8-M (ARM Cortex-M23 and
1368 - <a class="el" href="../../RTOS/html/functionOverview.html">CMSIS-RTOS C API v1</a> is a C function API that is backward
1369 compatible with CMSIS-RTOS v1.
1370 - \subpage rtos_apicpp is a C++ class function API.
1372 It is possible to intermix the different API variants in the same application and even in the same C/C++ source module.
1373 However, the functions of the <b>C API Version 1</b> may be deprecated in future versions of CMSIS-RTOS.
1375 \section rtos_api2 CMSIS-RTOS2
1377 Overview of all CMSIS-RTOS C API v2 functions that are implemented in the \subpage cmsis_os2_h.
1379 - \ref CMSIS_RTOS_KernelCtrl
1380 - \ref osKernelGetInfo : \copybrief osKernelGetInfo
1381 - \ref osKernelGetState : \copybrief osKernelGetState
1382 - \ref osKernelGetSysTimerCount : \copybrief osKernelGetSysTimerCount
1383 - \ref osKernelGetSysTimerFreq : \copybrief osKernelGetSysTimerFreq
1384 - \ref osKernelInitialize : \copybrief osKernelInitialize
1385 - \ref osKernelLock : \copybrief osKernelLock
1386 - \ref osKernelUnlock : \copybrief osKernelUnlock
1387 - \ref osKernelRestoreLock : \copybrief osKernelRestoreLock
1388 - \ref osKernelResume : \copybrief osKernelResume
1389 - \ref osKernelStart : \copybrief osKernelStart
1390 - \ref osKernelSuspend : \copybrief osKernelSuspend
1391 - \ref osKernelGetTickCount : \copybrief osKernelGetTickCount
1392 - \ref osKernelGetTickFreq : \copybrief osKernelGetTickFreq
1394 - \ref CMSIS_RTOS_ThreadMgmt
1395 - \ref osThreadDetach : \copybrief osThreadDetach
1396 - \ref osThreadEnumerate : \copybrief osThreadEnumerate
1397 - \ref osThreadExit : \copybrief osThreadExit
1398 - \ref osThreadGetCount : \copybrief osThreadGetCount
1399 - \ref osThreadGetId : \copybrief osThreadGetId
1400 - \ref osThreadGetName : \copybrief osThreadGetName
1401 - \ref osThreadGetPriority : \copybrief osThreadGetPriority
1402 - \ref osThreadGetStackSize : \copybrief osThreadGetStackSize
1403 - \ref osThreadGetStackSpace : \copybrief osThreadGetStackSpace
1404 - \ref osThreadGetState : \copybrief osThreadGetState
1405 - \ref osThreadJoin : \copybrief osThreadJoin
1406 - \ref osThreadNew : \copybrief osThreadNew
1407 - \ref osThreadResume : \copybrief osThreadResume
1408 - \ref osThreadSetPriority : \copybrief osThreadSetPriority
1409 - \ref osThreadSuspend : \copybrief osThreadSuspend
1410 - \ref osThreadTerminate : \copybrief osThreadTerminate
1411 - \ref osThreadYield : \copybrief osThreadYield
1413 - \ref CMSIS_RTOS_ThreadFlagsMgmt
1414 - \ref osThreadFlagsSet : \copybrief osThreadFlagsSet
1415 - \ref osThreadFlagsClear : \copybrief osThreadFlagsClear
1416 - \ref osThreadFlagsGet : \copybrief osThreadFlagsGet
1417 - \ref osThreadFlagsWait : \copybrief osThreadFlagsWait
1419 - \ref CMSIS_RTOS_EventFlags
1420 - \ref osEventFlagsGetName : \copybrief osEventFlagsGetName
1421 - \ref osEventFlagsNew : \copybrief osEventFlagsNew
1422 - \ref osEventFlagsDelete : \copybrief osEventFlagsDelete
1423 - \ref osEventFlagsSet : \copybrief osEventFlagsSet
1424 - \ref osEventFlagsClear : \copybrief osEventFlagsClear
1425 - \ref osEventFlagsGet : \copybrief osEventFlagsGet
1426 - \ref osEventFlagsWait : \copybrief osEventFlagsWait
1428 - \ref CMSIS_RTOS_Wait
1429 - \ref osDelay : \copybrief osDelay
1430 - \ref osDelayUntil : \copybrief osDelayUntil
1432 - \ref CMSIS_RTOS_TimerMgmt
1433 - \ref osTimerDelete : \copybrief osTimerDelete
1434 - \ref osTimerGetName : \copybrief osTimerGetName
1435 - \ref osTimerIsRunning : \copybrief osTimerIsRunning
1436 - \ref osTimerNew : \copybrief osTimerNew
1437 - \ref osTimerStart : \copybrief osTimerStart
1438 - \ref osTimerStop : \copybrief osTimerStop
1440 - \ref CMSIS_RTOS_MutexMgmt
1441 - \ref osMutexAcquire : \copybrief osMutexAcquire
1442 - \ref osMutexDelete : \copybrief osMutexDelete
1443 - \ref osMutexGetName : \copybrief osMutexGetName
1444 - \ref osMutexGetOwner : \copybrief osMutexGetOwner
1445 - \ref osMutexNew : \copybrief osMutexNew
1446 - \ref osMutexRelease : \copybrief osMutexRelease
1448 - \ref CMSIS_RTOS_SemaphoreMgmt
1449 - \ref osSemaphoreAcquire : \copybrief osSemaphoreAcquire
1450 - \ref osSemaphoreDelete : \copybrief osSemaphoreDelete
1451 - \ref osSemaphoreGetCount : \copybrief osSemaphoreGetCount
1452 - \ref osSemaphoreGetName : \copybrief osSemaphoreGetName
1453 - \ref osSemaphoreNew : \copybrief osSemaphoreNew
1454 - \ref osSemaphoreRelease : \copybrief osSemaphoreRelease
1456 - \ref CMSIS_RTOS_PoolMgmt
1457 - \ref osMemoryPoolAlloc : \copybrief osMemoryPoolAlloc
1458 - \ref osMemoryPoolDelete : \copybrief osMemoryPoolDelete
1459 - \ref osMemoryPoolFree : \copybrief osMemoryPoolFree
1460 - \ref osMemoryPoolGetBlockSize : \copybrief osMemoryPoolGetBlockSize
1461 - \ref osMemoryPoolGetCapacity : \copybrief osMemoryPoolGetCapacity
1462 - \ref osMemoryPoolGetCount : \copybrief osMemoryPoolGetCount
1463 - \ref osMemoryPoolGetName : \copybrief osMemoryPoolGetName
1464 - \ref osMemoryPoolGetSpace : \copybrief osMemoryPoolGetSpace
1465 - \ref osMemoryPoolNew : \copybrief osMemoryPoolNew
1467 - \ref CMSIS_RTOS_Message
1468 - \ref osMessageQueueDelete : \copybrief osMessageQueueDelete
1469 - \ref osMessageQueueGet : \copybrief osMessageQueueGet
1470 - \ref osMessageQueueGetCapacity : \copybrief osMessageQueueGetCapacity
1471 - \ref osMessageQueueGetCount : \copybrief osMessageQueueGetCount
1472 - \ref osMessageQueueGetMsgSize : \copybrief osMessageQueueGetMsgSize
1473 - \ref osMessageQueueGetName : \copybrief osMessageQueueGetName
1474 - \ref osMessageQueueGetSpace : \copybrief osMessageQueueGetSpace
1475 - \ref osMessageQueueNew : \copybrief osMessageQueueNew
1476 - \ref osMessageQueuePut : \copybrief osMessageQueuePut
1477 - \ref osMessageQueueReset : \copybrief osMessageQueueReset
1479 - \ref rtx5_specific
1480 - \ref osRtxErrorNotify : \copybrief osRtxErrorNotify
1481 - \ref osRtxIdleThread : \copybrief osRtxIdleThread
1482 - \ref osRtxSysTimerSetup : \copybrief osRtxSysTimerSetup
1483 - \ref osRtxSysTimerEnable : \copybrief osRtxSysTimerEnable
1484 - \ref osRtxSysTimerDisable : \copybrief osRtxSysTimerDisable
1485 - \ref osRtxSysTimerAckIRQ : \copybrief osRtxSysTimerAckIRQ
1486 - \ref osRtxSysTimerGetCount : \copybrief osRtxSysTimerGetCount
1487 - \ref osRtxSysTimerGetFreq : \copybrief osRtxSysTimerGetFreq
1489 The following CMSIS-RTOS2 functions can be called from threads and \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines"
1491 - \ref osKernelGetSysTimerCount, \ref osKernelGetSysTimerFreq
1492 - \ref osThreadFlagsSet
1493 - \ref osEventFlagsSet, \ref osEventFlagsClear, \ref osEventFlagsGet, \ref osEventFlagsWait
1494 - \ref osSemaphoreAcquire, \ref osSemaphoreRelease, \ref osSemaphoreGetCount
1495 - \ref osMemoryPoolAlloc, \ref osMemoryPoolFree, \ref osMemoryPoolGetCapacity, \ref osMemoryPoolGetBlockSize,
1496 \ref osMemoryPoolGetCount, \ref osMemoryPoolGetSpace
1497 - \ref osMessageQueuePut, \ref osMessageQueueGet, \ref osMessageQueueGetCapacity, \ref osMessageQueueGetMsgSize,
1498 \ref osMessageQueueGetCount, \ref osMessageQueueGetSpace
1502 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1504 \page rtos_apicpp CMSIS-RTOS C++ API
1506 The C++11/C++14 interface is planned to be released in January 2017.
1510 /* ======================================================================================================================== */
1511 // Group creation for Reference
1513 \addtogroup CMSIS_RTOS1 CMSIS-RTOS API v1
1514 \brief This section describes the CMSIS-RTOS API v1.
1516 The CMSIS-RTOS is a generic API layer that interfaces to an existing RTOS kernel.
1518 CMSIS-RTOS API v2 provides an translation layer for the
1519 <a class="el" href="../../RTOS/html/index.html">CMSIS-RTOS API v1</a> that simplifies migration.
1521 Refer to the <a class="el" href="../../RTOS/html/modules.html">Reference</a> guide of the CMSIS-RTOS API v1 for details.
1524 // Group creation for Reference
1526 \addtogroup CMSIS_RTOS CMSIS-RTOS2 API
1527 \brief Describes the C function interface of CMSIS-RTOS API v2.
1529 The CMSIS-RTOS2 is a generic API layer that interfaces to an RTOS kernel.
1531 The complete API interface is defined in the \ref cmsis_os2_h. When using dynamic memory allocation for objects, source code
1532 or libraries require no modifications when using on a different CMSIS-RTOS2 implementation.
1536 \addtogroup rtx5_specific RTX5 Specific API
1537 \brief This section describes CMSIS-RTOS RTX5 specifics.
1539 The RTX5 kernel can be customized for different application requirements:
1540 - If you are depending on the \ref lowPower "lowest power consumption" possible, you need to adapt the function
1541 \ref osRtxIdleThread to send the system to sleep mode as often as possible. In addition, use the
1542 \ref TickLess "tick-less low power" functions \ref osKernelSuspend and \ref osKernelResume to suspend the scheduler and to
1543 stop the SysTick timer.
1544 - If you need to specify an \ref kernelTimer "alternate hardware timer" as the system tick timer, you need to implement the
1545 functions \ref osRtxSysTimerSetup, \ref osRtxSysTimerEnable, \ref osRtxSysTimerDisable, and optionally the function
1546 \ref osRtxSysTimerAckIRQ.
1547 - If you try to find a \b runtime \b error, use the function \ref osRtxErrorNotify to debug the error.
1549 RTX5 interfaces to the <a href="http://www.keil.com/pack/doc/compiler/EventRecorder/html/index.html" target="_blank"><b>Event Recorder</b></a>
1550 to provide event information which helps you to understand and analyze the operation. Refer to \ref rtx_evr for more
1558 \defgroup rtx5_specific_defines Macros
1564 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1566 \def osRtxThreadCbSize
1569 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1571 \def osRtxTimerCbSize
1574 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1576 \def osRtxEventFlagsCbSize
1579 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1581 \def osRtxMutexCbSize
1584 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1586 \def osRtxSemaphoreCbSize
1589 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1591 \def osRtxMemoryPoolCbSize
1594 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1596 \def osRtxMessageQueueCbSize
1599 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1601 \def osRtxMemoryPoolMemSize
1604 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1606 \def osRtxMessageQueueMemSize
1614 \defgroup rtx5_specific_structs Structs
1620 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1622 \struct osRtxThread_t
1625 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1627 \struct osRtxTimerFinfo_t
1630 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1632 \struct osRtxTimer_t
1635 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1637 \struct osRtxEventFlags_t
1640 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1642 \struct osRtxMutex_t
1645 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1647 \struct osRtxSemaphore_t
1650 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1652 \struct osRtxMemoryPool_t
1655 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1657 \struct osRtxMessageQueue_t
1665 \defgroup rtx5_specific_functions Functions
1666 \brief RTX5 functions
1671 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1673 \fn uint32_t osRtxErrorNotify (uint32_t code, void *object_id);
1675 Some system error conditions can be detected during runtime. If the RTX kernel detects a runtime error, it calls the runtime
1676 error function \b osRtxErrorNotify for an object specified by parameter \a object_id.
1678 The parameter \a code passes the actual error code to this function:
1679 | Error Code | Description |
1680 |------------------------------|-----------------------------------------------------------------------------------|
1681 | osRtxErrorStackUnderflow | Stack underflow detected for thread (thread_id=object_id) |
1682 | osRtxErrorISRQueueOverflow | ISR Queue overflow detected when inserting object (object_id) |
1683 | osRtxErrorTimerQueueOverflow | User Timer Callback Queue overflow detected for timer (timer_id=object_id) |
1684 | osRtxErrorClibSpace | Standard C/C++ library libspace not available: increase \c OS_THREAD_LIBSPACE_NUM |
1685 | osRtxErrorClibMutex | Standard C/C++ library mutex initialization failed |
1687 The function \b osRtxErrorNotify must contain an infinite loop to prevent further program execution. You can use an emulator
1688 to step over the infinite loop and trace into the code introducing a runtime error. For the overflow errors this means you
1689 need to increase the size of the object causing an overflow.
1691 \note Cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
1697 uint32_t osRtxErrorNotify (uint32_t code, void *object_id) {
1701 case osRtxErrorStackUnderflow:
1702 // Stack underflow detected for thread (thread_id=object_id)
1704 case osRtxErrorISRQueueOverflow:
1705 // ISR Queue overflow detected when inserting object (object_id)
1707 case osRtxErrorTimerQueueOverflow:
1708 // User Timer Callback Queue overflow detected for timer (timer_id=object_id)
1710 case osRtxErrorClibSpace:
1711 // Standard C/C++ library libspace not available: increase OS_THREAD_LIBSPACE_NUM
1713 case osRtxErrorClibMutex:
1714 // Standard C/C++ library mutex initialization failed
1725 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1726 osRtxErrorClibMutex /**
1727 \fn void osRtxIdleThread (void *argument);
1729 The function \b osRtxIdleThread is executed by the RTX kernel, when no other threads are ready to run. By default, this
1730 thread is an empty end-less loop that does nothing. It only waits until another task becomes ready to run. You may change the
1731 code of the \b osRtxIdleThread function to put the CPU into a power-saving or idle mode.
1733 The default stack size for this thread is defined in the file RTX_Config.h. Refer to \ref threadConfig.
1735 \note Cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
1741 __NO_RETURN void osRtxIdleThread (void *argument) {
1749 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1751 \fn int32_t osRtxSysTimerSetup (void);
1753 By default, RTX5 uses the Cortex-M SysTick timer, but using \b osRtxSysTimerSetup allows to set up an alternative system
1756 \note Cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
1760 int32_t osRtxSysTimerSetup (void) {
1763 /* Private Timer runs with the system frequency */
1764 load = osRtxInfo.kernel.sys_freq / osRtxConfig.tick_freq;
1766 PTIM_SetLoadValue (load - 1U);
1768 /* Determine number of implemented priority bits */
1769 GIC_SetPriority (PrivTimer_IRQn, 0xFFU);
1771 /* Set lowest priority -1 */
1772 GIC_SetPriority (PrivTimer_IRQn, GIC_GetPriority(PrivTimer_IRQn)-1);
1775 GIC_EnableIRQ (PrivTimer_IRQn);
1777 return (PrivTimer_IRQn);
1782 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1784 \fn void osRtxSysTimerEnable (void);
1786 The function \b osRtxSysTimerEnable enables the alternative system timer that has been set up using \ref osRtxSysTimerSetup.
1788 \note Cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
1792 void osRtxSysTimerEnable (void) {
1793 /* Start the Private Timer */
1796 ctrl = PTIM_GetControl();
1797 /* Set bits: IRQ enable, Auto Reload, Timer enable */
1800 PTIM_SetControl (ctrl);
1805 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1807 \fn void osRtxSysTimerDisable (void);
1809 The function \b osRtxSysTimerDisable disables the alternative system timer that has been set up using \ref osRtxSysTimerSetup.
1811 \note Cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
1815 void osRtxSysTimerDisable (void) {
1816 /* Stop the Private Timer */
1819 ctrl = PTIM_GetControl();
1820 /* Clear bit: Timer enable */
1823 PTIM_SetControl (ctrl);
1828 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1830 \fn void osRtxSysTimerAckIRQ (void);
1833 \note Cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
1837 void osRtxSysTimerAckIRQ (void) {
1838 PTIM_ClearEventFlag();
1843 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1845 \fn uint32_t osRtxSysTimerGetCount (void);
1847 The function \b osRtxSysTimerGetCount returns the system timer count of the alternative timer set up by
1848 \ref osRtxSysTimerSetup.
1850 \note Cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
1854 uint32_t osRtxSysTimerGetCount (void) {
1858 tick = (uint32_t)osRtxInfo.kernel.tick;
1859 val = PTIM_GetLoadValue();
1860 val -= PTIM_GetCurrentValue();
1862 /* if (PTIM_GetEventFlag() != 0) */
1863 if ((PTIM->ISR & 1) != 0) {
1864 val = PTIM_GetLoadValue();
1865 val -= PTIM_GetCurrentValue();
1868 val += tick * (PTIM_GetLoadValue() + 1U);
1875 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1877 \fn uint32_t osRtxSysTimerGetFreq (void);
1879 The function \b osRtxSysTimerGetFreq returns the system timer frequency of the alternative timer set up by
1880 \ref osRtxSysTimerSetup.
1882 \note Cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
1886 uint32_t osRtxSysTimerGetFreq (void) {
1887 /* Private Timer runs with the system frequency */
1888 return osRtxInfo.kernel.sys_freq;