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 parameters for ThreadEnumerate and MessageQueueInserted events.
151 - Timer Thread creation moved to osKernelStart.
157 - Based on CMSIS-RTOS API V2.1.
158 - Added support for Event recording.
159 - Added support for IAR compiler.
160 - Updated configuration files: RTX_Config.h for the configuration settings and RTX_config.c for implementing the \ref rtx5_specific.
161 - osRtx name-space for RTX specific symbols.
167 Initial release compliant to CMSIS-RTOS2.\n
174 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
176 \page genRTOS2IF Generic RTOS Interface
178 CMSIS-RTOS2 is a generic API that is agnostic of the underlying RTOS kernel. Application programmers call CMSIS-RTOS2 API
179 functions in the user code to ensure maximum portability from one RTOS to another. Middleware using CMSIS-RTOS2 API takes
180 advantages of this approach by avoiding unnecessary porting efforts.
182 \image html "API_Structure.png" "CMSIS-RTOS API Structure"
184 A typical CMSIS-RTOS2 API implementation interfaces to an existing real-time kernel. The CMSIS-RTOS2 API provides the
185 following attributes and functionalities:
186 - Function names, identifiers, and parameters are descriptive and easy to understand. The functions are powerful and
187 flexible which reduces the number of functions exposed to the user.
188 - \ref CMSIS_RTOS_ThreadMgmt allows you to define, create, and control threads.
189 - Interrupt Service Routines (ISR) can \ref CMSIS_RTOS_ISR_Calls "call some CMSIS-RTOS functions". When a CMSIS-RTOS
190 function cannot be called from an ISR context, it rejects the invocation and returns an error code.
191 - Three different event types support communication between multiple threads and/or ISR:
192 - \ref CMSIS_RTOS_ThreadFlagsMgmt "Thread Flags": may be used to indicate specific conditions to a thread.
193 - \ref CMSIS_RTOS_EventFlags "Event Flags": may be used to indicate events to a thread or ISR.
194 - \ref CMSIS_RTOS_Message "Messages": can be sent to a thread or an ISR. Messages are buffered in a queue.
195 - \ref CMSIS_RTOS_MutexMgmt and \ref CMSIS_RTOS_SemaphoreMgmt are incorporated.
196 - CPU time can be scheduled with the following functionalities:
197 - A \a timeout parameter is incorporated in many CMSIS-RTOS functions to avoid system lockup. When a timeout is specified,
198 the system waits until a resource is available or an event occurs. While waiting, other threads are scheduled.
199 - The \ref osDelay and \ref osDelayUntil functions put a thread into the \b WAITING state for a specified period of time.
200 - The \ref osThreadYield provides co-operative thread switching and passes execution to another thread of the same
202 - \ref CMSIS_RTOS_TimerMgmt functions are used to trigger the execution of functions.
204 The CMSIS-RTOS2 API is designed to optionally incorporate multi-processor systems and/or access protection via the Cortex-M
205 Memory Protection Unit (MPU).
207 In some RTOS implementations threads may execute on different processors, thus \b message queues may reside in shared memory
210 The CMSIS-RTOS2 API encourages the software industry to evolve existing RTOS implementations. RTOS implementations can be
211 different and optimized in various aspects towards the Cortex-M processors. Optional features may be for example
212 - Support of the Cortex-M Memory Protection Unit (MPU).
213 - Support of multi-processor systems.
214 - Support of a DMA controller.
215 - Deterministic context switching.
216 - Round-robin context switching.
217 - Deadlock avoidance, for example with priority inversion.
218 - Zero interrupt latency by using ARMv7-M instructions LDREX and STREX.
220 \section usingOS2 Using a CMSIS-RTOS2 Implementation
222 A CMSIS-RTOS2 implementation is typically provided as a library. To add the RTOS functionality to an existing CMSIS-based
223 application, the RTOS library (and typically one or more configuration files) needs to be added. There is a single new header
224 file %cmsis_os2.h available. This is the only header file required for a completely portable application. In such a case,
225 user provided memory for control blocks, objects data and thread stack cannot be used. Alternatively, you can include an
226 implementation specific header file (for example rtx_os.h) which provides definitions also for resource allocation (such as
227 size of control blocks, required memory for object data and thread stack). This is optional and implies that the application
228 code is not completely portable.
230 \image html "CMSIS_RTOS_Files.png" "CMSIS-RTOS File Structure"
232 Once the files are added to a project, the user can start working with the CMSIS-RTOS functions. A code example is provided
237 /*----------------------------------------------------------------------------
238 * CMSIS-RTOS 'main' function template
239 *---------------------------------------------------------------------------*/
241 #include "RTE_Components.h"
242 #include CMSIS_device_header
243 #include "cmsis_os2.h"
245 /*----------------------------------------------------------------------------
246 * Application main thread
247 *---------------------------------------------------------------------------*/
248 void app_main (void *argument) {
256 // System Initialization
257 SystemCoreClockUpdate();
258 #ifdef RTE_Compiler_EventRecorder
259 // Initialize and start Event Recorder
260 EventRecorderInitialize(EventRecordError, 1U);
264 osKernelInitialize(); // Initialize CMSIS-RTOS
265 osThreadNew(app_main, NULL, NULL); // Create application main thread
266 osKernelStart(); // Start thread execution
272 \section cmsis_os2_h cmsis_os2.h header file
274 The file \b cmsis_os2.h is a standard header file that interfaces to every CMSIS-RTOS2 compliant real-time operating
275 systems (RTOS). Each implementation is provided the same \b cmsis_os2.h which defines the interface to the \ref rtos_api2.
277 Using the \b cmsis_os2.h along with dynamic object allocation allows to create source code or libraries that require no
278 modifications when using on a different CMSIS-RTOS2 implementation.
280 <b>Header file %cmsis_os2.h</b>
286 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
288 \page rtx5_impl RTX v5 Implementation
290 Keil RTX version 5 (RTX5) implements the CMSIS-RTOS2 as a native RTOS interface for ARM Cortex-M processor-based devices.
291 A translation layer to CMSIS-RTOS API v1 is provided. Therefore, RTX5 can be used in applications that where previously based
292 on RTX version 4 and CMSIS-RTOS version 1 with minimal effort.
294 The following sections provide further details:
295 - \subpage cre_rtx_proj explains how to setup an RTX v5 project in Keil MDK.
296 - \subpage theory_of_operation provides general information about the operation of CMSIS-RTOS RTX v5.
297 - \subpage config_rtx5 describes configuration parameters of CMSIS-RTOS RTX v5.
298 - \subpage creating_RTX5_LIB explains how to build your own CMSIS-RTOS RTX v5 library.
299 - \subpage dirstructfiles5 explains the directories and files that are supplied as part of CMSIS-RTOS RTX v5.
300 - \subpage technicalData5 lists microcontroller hardware requirements and limitations such as number of concurrent threads.
301 - \subpage misraCompliance5 describes the violations to the MISRA standard.
304 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
306 \page cre_rtx_proj Create an RTX5 Project
308 The steps to create a microcontroller application using RTX5 are:
309 - Create a new project and select a microcontroller device.
310 - In the Manage Run-Time Environment window, select <b>CMSIS\::CORE</b> and <b>CMSIS\::RTOS2 (API)\::Keil RTX5</b>. You can
311 choose to either add RTX as a library (Variant: \b Library) or to add the full source code (Variant: \b Source - required
312 if using the <a href="http://www.keil.com/pack/doc/compiler/EventRecorder/html/index.html" target="_blank"><b>Event Recorder</b></a>):
314 \image html manage_rte_output.png
316 - If the <b>Validation Output</b> requires other components to be present, try to use the \b Resolve button.
317 - Click \b OK. In the \b Project window, you will see the files that have been automatically added to you project, such as
318 \b %RTX_Config.h, \b %RTX_Config.c, the library or the source code files, as well as the system and startup files:
320 \image html project_window.png
322 - 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).
323 - You can add template files to the project by right-clicking on <b>Source Group 1</b> and selecting
324 <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
325 you will see all available template files for CMSIS-RTOS RTX:
327 \image html add_item.png
329 - \ref config_rtx5 "Configure" RTX5 to the application's needs using the \b %RTX_Config.h file.
331 \section cre_rtx_proj_specifics Add support for RTX specific functions
332 If you require some of the \ref rtx5_specific "RTX specific functions" in your application code, \#include the
333 \ref rtx_os_h "header file rtx_os.h". This enables \ref lowPower "low-power" and \ref TickLess "tick-less" operation modes.
336 \section cre_rtx_proj_er Add Event Recorder Visibility
337 - To use the Event Recorder together with RTX5, select the software component <b>Compiler:Event Recorder</b>.
338 - Select the \b Source variant of the software component <b>CMSIS:RTOS2 (API):Keil RTX5</b>.
339 \image html event_recorder_rte.png "Component selection for Event Recorder"
340 - Call the function <b>EventRecorderInitialize()</b> in your application code (ideally in \c main()).
341 - Build the application code and download it to the debug hardware.
343 Once the target application generates event information, it can be viewed in the µVision debugger using the \b Event
348 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
350 \page theory_of_operation Theory of Operation
352 Many aspects of the kernel are configurable and the configuration options are mentioned where applicable.
354 \section SystemStartup System Startup
356 Since main is no longer a thread RTX5 does not interfere with the system startup until main is reached.
357 Once the execution reaches \c main() there is a recommended order to initialize the hardware and start the kernel. This is
358 also reflected in the user code template file "CMSIS-RTOS2 'main' function" supplied with the RTX5 component.
360 Your application's \c main() should implement at least the following in the given order:
361 -# Initialization and configuration of hardware including peripherals, memory, pins, clocks and the interrupt system.
362 -# Update the system core clock using the respective
363 <a href=../../Core/html/group__system__init__gr.html>CMSIS-Core (Cortex-M) function</a>.
364 -# Initialize the CMSIS-RTOS kernel using \ref osKernelInitialize.
365 -# Optionally, create a new thread \c app_main, which is used as a main thread using \ref osThreadNew. Alternatively, threads
366 can be created in \c main() directly.
367 -# Start the RTOS scheduler using \ref osKernelStart. This function does not return in case of successful execution. Any
368 application code after \b osKernelStart will not be executed unless \b osKernelStart fails.
370 \note Interrupts (like SVC for example) used by the kernel are initialized in \ref osKernelInitialize. In case priorities and
371 groupings in the NVIC are altered by the application after the above sequence it might be necessary to call
372 \ref osKernelInitialize again.
376 RTX5 implements a low-latency preemtive scheduler. Major parts of RTX5 are executed in handler mode such as
377 - \ref SysTick_Handler used for time-based scheduling.
378 - \ref SVC_Handler used for lock-based scheduling.
379 - \ref PendSV_Handler used for interrupt-based scheduling.
381 In order to be low-latency with respect to ISR execution those system exceptions are configured to use the
382 lowest priority groups available. The priorities are configured such that no preemption happens between them. Thus
383 no interrupt critical sections (i.e. interrupt locks) are needed to protect the scheduler.
385 \image html scheduling.png "Thread scheduling and interrupt execution"
387 The scheduler combines priority and round-robin based context switches. The example depicted in the image above contains
388 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
389 (\ref osThreadAttr_t::priority). As long as threads 3 and 4 are blocked the scheduler switches between thread 1 and 2 on
390 a time-slice basis (round-robin). The time-slice for round-robin scheduling can be configured, see Round-Robin Timeout in \ref systemConfig.
392 Thread 2 unblocks thread 3 by an arbitrary RTOS-call (executed in SVC handler mode) at time index 2. The scheduler switches to
393 thread 3 immidiately because thread 3 has the highest priority. Thread 4 is still blocked.
395 At time index 4 an interrupt (ISR) occurs and preempts the SysTick_Handler. RTX does not add any latency to the interrupt
396 service execution. The ISR routine uses an RTOS-call that unblocks thread 4. Instead of switching to thread 4 immediately
397 the PendSV flag is set to defer the context switching. The PendSV_Handler is executed right after the SysTick_Handler returns
398 and the defered context switch to thread 4 is carried out. As soon as highest priority thread 4 blocks again by using
399 a blocking RTOS-call execution is switched back to thread 3 immidiately during time index 5.
401 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.
402 At time index 7 the scheduler uses the round-robin mechanism to switch to thread 1 and so on.
404 \section MemoryAllocation Memory Allocation
406 RTX5 objects (thread, mutex, semaphore, timer, message queue, thread and event flags, as well as memory pool) require
407 dedicated RAM memory. Objects can be created using os<i>Object</i>New() calls and deleted using os<i>Object</i>Delete()
408 calls. The related object memory needs to be available during the lifetime of the object.
410 RTX5 offers three different memory allocation methods for objects:
411 - \ref GlobalMemoryPool uses a single global memory pool for all objects. It is easy to configure, but may have
412 the disadvantage for memory fragmentation when objects with different sizes are created and destroyed.
413 - \ref ObjectMemoryPool uses a fixed-size memory pool for each object type. The method is time deterministic
414 and avoids memory fragmentation.
415 - \ref StaticObjectMemory reserves memory during compile time and completely avoids that a system can be out of memory.
416 This is typically a required for some safety critical systems.
418 It possible to intermix all the memory allocation methods in the same application.
420 \subsection GlobalMemoryPool Global Memory Pool
422 The global memory pool allocates all objects from a memory area. This method of memory allocation is the default
423 configuration setting of RTX5.
425 \image html MemAllocGlob.png "Global Memory Pool for all objects"
427 When the memory pool does not provide sufficient memory, the creation of the object fails and the related
428 os<i>Object</i>New() function returns \token{NULL}.
430 Enabled in \ref systemConfig.
432 \subsection ObjectMemoryPool Object-specific Memory Pools
434 Object-specific memory pools avoids memory fragmentation with a dedicated fixed-size memory management for each object type.
435 This type of memory pools are fully time deterministic, which means that object creation and destruction takes always the
436 same fixed amount of time. As a fixed-size memory pool is specific to an object type, the handling of out-of-memory
437 situations is simplified.
439 \image html MemAllocSpec.png "One memory pool per object type"
441 Object-specific memory pools are selectively enabled for each object type, e.g: mutex or thread using the RTX configuration
443 - Enabled in \ref threadConfig for thread objects.
444 - Enabled in \ref timerConfig for timer objects.
445 - Enabled in \ref eventFlagsConfig for event objects.
446 - Enabled in \ref mutexConfig for mutex objects.
447 - Enabled in \ref semaphoreConfig for semaphore.
448 - Enabled in \ref memPoolConfig for memory pools.
449 - Enabled in \ref msgQueueConfig for message objects.
451 When the memory pool does not provide sufficient memory, the creation of the object fails and the related
452 os<i>Object</i>New() function returns \token{NULL}.
454 \subsection StaticObjectMemory Static Object Memory
455 In contrast to the dynamic memory allocations, the static memory allocation requires compile-time allocation of object memory.
457 \image html MemAllocStat.png "Statically allocated memory for all objects"
459 The following code example shows how to create an OS object using static memory.
461 <b> Code Example:</b>
463 /*----------------------------------------------------------------------------
464 * CMSIS-RTOS 'main' function template
465 *---------------------------------------------------------------------------*/
467 #include "RTE_Components.h"
468 #include CMSIS_device_header
469 #include "cmsis_os2.h"
471 //include rtx_os.h for types of RTX objects
474 //The thread function instanced in this example
475 void worker(void *arg)
484 // Define objects that are statically allocated for worker thread 1
485 osRtxThread_t worker_thread_tcb_1;
487 // Reserve two areas for the stacks of worker thread 1
488 // uint64_t makes sure the memory alignment is 8
489 uint64_t worker_thread_stk_1[64];
491 // Define the attributes which are used for thread creation
492 // Optional const saves RAM memory and includes the values in periodic ROM tests
493 const osThreadAttr_t worker_attr_1 = {
496 &worker_thread_tcb_1,
497 sizeof(worker_thread_tcb_1),
498 &worker_thread_stk_1[0],
499 sizeof(worker_thread_stk_1),
500 osPriorityAboveNormal,
504 // Define ID object for thread
507 /*----------------------------------------------------------------------------
508 * Application main thread
509 *---------------------------------------------------------------------------*/
510 void app_main (void *argument) {
511 uint32_t param = NULL;
513 // Create an instance of the worker thread with static resources (TCB and stack)
514 th1 = osThreadNew(worker, ¶m, &worker_attr_1);
520 // System Initialization
521 SystemCoreClockUpdate();
524 osKernelInitialize(); // Initialize CMSIS-RTOS
525 osThreadNew(app_main, NULL, NULL); // Create application main thread
526 osKernelStart(); // Start thread execution
532 \section ThreadStack Thread Stack Management
534 For Cortex-M processors without floating point unit the thread context requires 64 bytes on the local stack.
536 \note For Cortex-M4/M7 with FP the thread context requires 200 bytes on the local stack. For these devices the default stack
537 space should be increased to a minimum of 300 bytes.
539 Each thread is provided with a separate stack that holds the thread context and stack space for automatic variables and
540 return addresses for function call nesting. The stack sizes of RTX threads are flexibly configurable as explained in the
541 section \ref threadConfig. RTX offers a configurable checking for stack overflows and stack utilization.
544 \section lowPower Low-Power Operation
546 The system thread \b osRtxIdleThread can be use to switch the system into a low-power mode. The easiest form to enter a
547 low-power mode is the execution of the \c __WFE function that puts the processor into a sleep mode where it waits for an
552 #include "RTE_Components.h"
553 #include CMSIS_device_header /* Device definitions */
555 void osRtxIdleThread (void) {
556 /* The idle demon is a system thread, running when no other thread is */
560 __WFE(); /* Enter sleep mode */
566 \c __WFE() is not available in every Cortex-M implementation. Check device manuals for availability.
569 \section kernelTimer RTX Kernel Timer Tick
571 By default, RTX5 uses the Cortex-M
572 <a href="http://www.keil.com/support/man/docs/gsac/GSAC_SYSTICKtimer.htm" target="_blank">SysTick</a> timer to generate
573 periodic interrupts for the RTX kernel timer tick. CMSIS-RTOS provides \ref CMSIS_RTOS_TimerMgmt functions and several
574 CMSIS-RTOS functions have a \a timeout parameter. This periodic RTX kernel timer tick interrupt is used to derive the
575 required time interval. RTX5 also provides configuration options for an \ref kernelTimer_alt "alternative timer" and
576 \ref TickLess "tick-less operation".
578 To handle timeout and time delays for threads, the RTX5 thread management is controlled by the RTX kernel timer tick
579 interrupt. The thread context contains all CPU registers (R0 - R12), the return address (LR), the program counter (PC), and
580 the processor status register (xPSR). For the Cortex-M4/M7 FPU the floating point status and registers (S0 - S32, FPSCR) are
581 also part of the thread context.
583 When a thread switch occurs:
584 - the thread context of the current running thread is stored on the local stack of this thread.
585 - the stack pointer is switched to the next running thread.
586 - the thread context of this next running thread is restored and this thread starts to run.
589 \subsection kernelTimer_alt Using an Alternative Timer as RTX Kernel Timer
591 The following functions need to be adapted to enable the usage of an alternative kernel timer:
592 - \ref osRtxSysTimerSetup sets up the timer (including IRQ priority) and returns its IRQ number. Note that it is no longer
593 required to start the time in this function as a separate function is available (see next).
594 - \ref osRtxSysTimerEnable starts the timer.
595 - \ref osRtxSysTimerDisable stops the timer.
596 - \ref osRtxSysTimerAckIRQ acknowledges the IRQ.
597 - \ref osRtxSysTimerGetCount returns the current tick count as a 32-bit value. Note that this function can be called when
598 the timer is disabled. It should still provide valid tick count values.
599 - \ref osRtxSysTimerGetFreq returns the timer tick frequency. Note that this function can be called when the
600 timer is disabled. It should still provide valid tick frequency values.
602 It is important to configure the IRQ priority (it should match PendSV). This can be achieved using the ExtTick_SetupIRQ()
603 function from core_cm.h. Enabling/disabling the IRQ is handled by the system.
605 There is no need to provide an IRQ handler. Only make sure that existing SysTick_Handler is mapped to the tick IRQ.
609 The following code example shows an implementation for a Cortex-A core that does not come with a built-in SysTick timer.
612 #include "RTE_Components.h"
613 #include CMSIS_device_header
616 int32_t osRtxSysTimerSetup (void) {
619 /* Private Timer runs with the system frequency */
620 load = osRtxInfo.kernel.sys_freq / osRtxConfig.tick_freq;
622 PTIM_SetLoadValue (load - 1U);
624 /* Determine number of implemented priority bits */
625 GIC_SetPriority (PrivTimer_IRQn, 0xFFU);
627 /* Set lowest priority -1 */
628 GIC_SetPriority (PrivTimer_IRQn, GIC_GetPriority(PrivTimer_IRQn)-1);
631 GIC_EnableIRQ (PrivTimer_IRQn);
633 return (PrivTimer_IRQn);
636 void osRtxSysTimerEnable (void) {
637 /* Start the Private Timer */
640 ctrl = PTIM_GetControl();
641 /* Set bits: IRQ enable, Auto Reload, Timer enable */
644 PTIM_SetControl (ctrl);
647 void osRtxSysTimerDisable (void) {
648 /* Stop the Private Timer */
651 ctrl = PTIM_GetControl();
652 /* Clear bit: Timer enable */
655 PTIM_SetControl (ctrl);
658 void osRtxSysTimerAckIRQ (void) {
659 PTIM_ClearEventFlag();
662 uint32_t osRtxSysTimerGetCount (void) {
666 tick = (uint32_t)osRtxInfo.kernel.tick;
667 val = PTIM_GetLoadValue();
668 val -= PTIM_GetCurrentValue();
670 /* if (PTIM_GetEventFlag() != 0) */
671 if ((PTIM->ISR & 1) != 0) {
672 val = PTIM_GetLoadValue();
673 val -= PTIM_GetCurrentValue();
676 val += tick * (PTIM_GetLoadValue() + 1U);
681 uint32_t osRtxSysTimerGetFreq (void) {
682 /* Private Timer runs with the system frequency */
683 return osRtxInfo.kernel.sys_freq;
687 \subsection TickLess Tick-less Low-Power Operation
689 RTX5 provides extension for tick-less operation which is useful for applications that use extensively low-power modes where
690 the SysTick timer is also disabled. To provide a time-tick in such power-saving modes, a wake-up timer is used to
691 derive timer intervals. The CMSIS-RTOS2 functions \ref osKernelSuspend and \ref osKernelResume control the tick-less
694 Using this functions allows the RTX5 thread scheduler to stop the periodic kernel tick interrupt. When all active threads
695 are suspended, the system enters power-down and calculates how long it can stay in this power-down mode. In the power-down
696 mode the processor and peripherals can be switched off. Only a wake-up timer must remain powered, because this timer is
697 responsible to wake-up the system after the power-down period expires.
699 The tick-less operation is controlled from the \b osRtxIdleThread thread. The wake-up timeout value is set before the system
700 enters the power-down mode. The function \ref osKernelSuspend calculates the wake-up timeout measured in RTX Timer Ticks;
701 this value is used to setup the wake-up timer that runs during the power-down mode of the system.
703 Once the system resumes operation (either by a wake-up time out or other interrupts) the RTX5 thread scheduler is started
704 with the function \ref osKernelResume. The parameter \a sleep_time specifies the time (in RTX Timer Ticks) that the system
705 was in power-down mode.
709 #include "msp.h" // Device header
711 /*----------------------------------------------------------------------------
712 * MSP432 Low-Power Extension Functions
713 *---------------------------------------------------------------------------*/
714 static void MSP432_LP_Entry(void) {
715 /* Enable PCM rude mode, which allows to device to enter LPM3 without waiting for peripherals */
716 PCM->CTL1 = PCM_CTL1_KEY_VAL | PCM_CTL1_FORCE_LPM_ENTRY;
717 /* Enable all SRAM bank retentions prior to going to LPM3 */
718 SYSCTL->SRAM_BANKRET |= SYSCTL_SRAM_BANKRET_BNK7_RET;
719 __enable_interrupt();
720 NVIC_EnableIRQ(RTC_C_IRQn);
721 /* Do not wake up on exit from ISR */
722 SCB->SCR |= SCB_SCR_SLEEPONEXIT_Msk;
723 /* Setting the sleep deep bit */
724 SCB->SCR |= (SCB_SCR_SLEEPDEEP_Msk);
727 static volatile unsigned int tc;
728 static volatile unsigned int tc_wakeup;
730 void RTC_C_IRQHandler(void)
732 if (tc++ > tc_wakeup)
734 SCB->SCR &= ~SCB_SCR_SLEEPONEXIT_Msk;
735 NVIC_DisableIRQ(RTC_C_IRQn);
736 NVIC_ClearPendingIRQ(RTC_C_IRQn);
739 if (RTC_C->PS0CTL & RTC_C_PS0CTL_RT0PSIFG)
741 RTC_C->CTL0 = RTC_C_KEY_VAL; // Unlock RTC key protected registers
742 RTC_C->PS0CTL &= ~RTC_C_PS0CTL_RT0PSIFG;
744 SCB->SCR |= (SCB_SCR_SLEEPDEEP_Msk);
748 uint32_t g_enable_sleep = 0;
750 void osRtxIdleThread (void) {
753 tc_wakeup = osKernelSuspend();
754 /* Is there some time to sleep? */
757 /* Enter the low power state */
761 /* Adjust the kernel ticks with the amount of ticks slept */
768 \c __WFI() is not available in every ARM Cortex-M implementation. Check device manuals for availability.
771 \section rtx_os_h RTX5 Header File
773 Every implementation of the CMSIS-RTOS2 API can bring its own additional features. RTX5 adds a couple of
774 \ref rtx5_specific "functions" for the idle more, for error notifications, and special system timer functions. It also is
775 using macros for control block and memory sizes.
777 If you require some of the RTX specific functions in your application code, \#include the header file \b %rtx_os.h:
782 \section CMSIS_RTOS_TimeOutValue Timeout Value
784 Timeout values are an argument to several \b osXxx functions to allow time for resolving a request. A timeout value of \b 0
785 means that the RTOS does not wait and the function returns instantly, even when no resource is available. A timeout value of
786 \ref osWaitForever means that the RTOS waits infinitely until a resource becomes available. Or one forces the thread to resume
787 using \ref osThreadResume which is discouraged.
789 The timeout value specifies the number of timer ticks until the time delay elapses. The value is an upper bound and
790 depends on the actual time elapsed since the last timer tick.
793 - timeout value \b 0 : the system does not wait, even when no resource is available the RTOS function returns instantly.
794 - timeout value \b 1 : the system waits until the next timer tick occurs; depending on the previous timer tick, it may be a
795 very short wait time.
796 - timeout value \b 2 : actual wait time is between 1 and 2 timer ticks.
797 - timeout value \ref osWaitForever : system waits infinite until a resource becomes available.
799 \image html TimerValues.png "Example of timeout using osDelay()"
802 \section CMSIS_RTOS_ISR_Calls Calls from Interrupt Service Routines
804 The following CMSIS-RTOS2 functions can be called from threads and Interrupt Service Routines (ISR):
805 - \ref osKernelGetSysTimerCount, \ref osKernelGetSysTimerFreq
806 - \ref osThreadFlagsSet
807 - \ref osEventFlagsSet, \ref osEventFlagsClear, \ref osEventFlagsGet, \ref osEventFlagsWait
808 - \ref osSemaphoreAcquire, \ref osSemaphoreRelease, \ref osSemaphoreGetCount
809 - \ref osMemoryPoolAlloc, \ref osMemoryPoolFree, \ref osMemoryPoolGetCapacity, \ref osMemoryPoolGetBlockSize,
810 \ref osMemoryPoolGetCount, \ref osMemoryPoolGetSpace
811 - \ref osMessageQueuePut, \ref osMessageQueueGet, \ref osMessageQueueGetCapacity, \ref osMessageQueueGetMsgSize,
812 \ref osMessageQueueGetCount, \ref osMessageQueueGetSpace
814 Functions that cannot be called from an ISR are verifying the interrupt status and return the status code \b osErrorISR, in
815 case they are called from an ISR context. In some implementations, this condition might be caught using the HARD_FAULT
819 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
821 \page config_rtx5 Configure RTX v5
823 The file "RTX_Config.h" defines the configuration parameters of CMSIS-RTOS RTX and must be part of every project that is
824 using the CMSIS-RTOS RTX kernel. The file "RTX_Config.c" contains stubs of the functions \b osRtxIdleThread and
825 \b osRtxErrorNotify that can be adapted to the application's needs.
827 The configuration file uses
828 <b>Configuration Wizard Annotations</b>. Refer to <b>Pack - Configuration Wizard Annotations</b> for details.
829 Depending on the development tool, the annotations might lead to a more user-friendly graphical representation of the
830 settings. The screenshot below is a screenshot from the µVision \b Configuration \b Wizard view:
832 \image html config_wizard.png "RTX_Config.h in Configuration Wizard View"
834 The configuration options are explained on these pages:
838 - \ref eventFlagsConfig
840 - \ref semaphoreConfig
842 - \ref msgQueueConfig
845 \section systemConfig System Configuration
847 The system configuration covers system-wide settings for the global memory pool, tick frequency, ISR event buffer and
848 round-robin thread switching.
850 <b>System Configuration Options</b>
851 \image html config_wizard_system.png "RTX_Config.h: System Configuration"
853 Name | \#define | Description
854 ---------------------------------------|--------------------------|----------------------------------------------------------------
855 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.
856 Kernel Tick Frequency (Hz) | \c OS_TICK_FREQ | Defines base time unit for delays and timeouts in Hz. Default: 1000Hz = 1ms period.
857 Round-Robin Thread switching | \c OS_ROBIN_ENABLE | Enables Round-Robin Thread switching.
858 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]}.
859 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}.
861 \subsection systemConfig_glob_mem Global dynamic memory
862 Refer to \ref GlobalMemoryPool.
865 \subsection systemConfig_rr Round-Robin Thread Switching
867 RTX5 may be configured to use round-robin multitasking thread switching. Round-robin allows quasi-parallel execution of
868 several threads of the \a same priority. Threads are not really executed concurrently, but are scheduled where the available
869 CPU time is divided into time slices and RTX5 assigns a time slice to each thread. Because the time slice is typically short
870 (only a few milliseconds), it appears as though threads execute simultaneously.
872 Round-robin thread switching functions as follows:
873 - the tick is preloaded with the timeout value when a thread switch occurs
874 - the tick is decremented (if not already zero) each system tick if the same thread is still executing
875 - when the tick reaches 0 it indicates that a timeout has occurred. If there is another thread ready with the \a same
876 priority, then the system switches to that thread and the tick is preloaded with timeout again.
878 In other words, threads execute for the duration of their time slice (unless a thread's time slice is given up). Then, RTX
879 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
880 ready to run, the current running thread resumes it execution.
882 \note When switching to higher priority threads, the round-robin timeout value is reset.
884 Round-Robin multitasking is controlled with the <b>\#define OS_ROBIN_ENABLE</b>. The time slice period is configured (in RTX
885 timer ticks) with the <b>\#define OS_ROBIN_TIMEOUT</b>.
888 \subsection systemConfig_isr_fifo ISR FIFO Queue
889 The RTX functions (\ref CMSIS_RTOS_ISR_Calls), when called from and interrupt handler, store the request type and optional
890 parameter to the ISR FIFO queue buffer to be processed later, after the interrupt handler exits.
892 The scheduler is activated immediately after the IRQ handler has finished its execution to process the requests stored to the
893 FIFO queue buffer. The required size of this buffer depends on the number of functions that are called within the interrupt
894 handler. An insufficient queue size will be caught by \b osRtxErrorNotify with error code \b osRtxErrorISRQueueOverflow.
897 \section threadConfig Thread Configuration
899 The RTX5 provides several parameters to configure the \ref CMSIS_RTOS_ThreadMgmt functions.
901 <b>Thread Configuration Options</b>
902 \image html config_wizard_threads.png "RTX_Config.h: Thread Configuration"
905 Option | \#define | Description
906 :--------------------------------------------------------|:-----------------------|:---------------------------------------------------------------
907 Object specific Memory allocation | \c OS_THREAD_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
908 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]}.
909 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]}.
910 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}.
911 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}.
912 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}.
913 Stack overrun checking | \c OS_STACK_CHECK | Enable stack overrun checks at thread switch.
914 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.
915 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.
917 \subsection threadConfig_countstack Configuration of Thread Count and Stack Space
919 The RTX5 kernel uses a separate stack space for each thread and provides two methods for defining the stack requirements:
920 - <b>Static allocation</b>: when \ref osThreadAttr_t::stack_mem and \ref osThreadAttr_t::stack_size specify a memory area
921 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.
922 - <b>Dynamic allocation</b>: when \ref osThreadAttr_t is NULL or \ref osThreadAttr_t::stack_mem is NULL, the system
923 allocates the stack memory from:
924 - Object-specific Memory Pool (default Stack size) when "Object specific Memory allocation" is enabled and "Number of
925 user Threads with default Stack size" is not \token{0} and \ref osThreadAttr_t::stack_size is \token{0} (or
926 \ref osThreadAttr_t is NULL).
927 - Object-specific Memory Pool (user-provided Stack size) when "Object specific Memory allocation" is enabled and "Total
928 Stack size for user..." is not \token{0} and \ref osThreadAttr_t::stack_size is not \token{0}.
929 - Global Memory Pool when "Object specific Memory allocation" is disabled or (\ref osThreadAttr_t::stack_size is not
930 \token{0} and "Total Stack size for user..." is \token{0}) or (\ref osThreadAttr_t::stack_size is \token{0} and
931 "Number of user Threads with default Stack size" is \token{0}).
933 \ref osThreadAttr_t is a parameter of the function \ref osThreadNew.
936 Before the RTX kernel is started by the \ref osKernelStart() function, the main stack defined in startup_<i>device</i>.s is
937 used. The main stack is also used for:
938 - user application calls to RTX functions in \b thread \b mode using SVC calls
939 - interrupt/exception handlers.
941 \subsection threadConfig_ovfcheck Stack Overflow Checking
942 RTX5 implements a software stack overflow checking that traps stack overruns. Stack is used for return addresses and
943 automatic variables. Extensive usage or incorrect stack configuration may cause a stack overflow. Software stack overflow
944 checking is controlled with the define \c OS_STACK_CHECK.
946 If a stack overflow is detected, the function \b osRtxErrorNotify with error code \b osRtxErrorStackUnderflow is called. By
947 default, this function is implemented as an endless loop and will practically stop code execution.
949 \subsection threadConfig_watermark Stack Usage Watermark
950 RTX5 initializes thread stack with a watermark pattern (0xCC) when a thread is created. This allows the debugger to determine
951 the maximum stack usage for each thread. It is typically used during development but removed from the final application.
952 Stack usage watermark is controlled with the define \c OS_STACK_WATERMARK.
954 Enabling this option significantly increases the execution time of \ref osThreadNew (depends on thread stack size).
956 \subsection threadConfig_procmode Processor Mode for Thread Execution
957 RTX5 allows to execute threads in unprivileged or privileged processor mode. The processor mode is controlled with the
958 define \c OS_PRIVILEGE_MODE.
960 In \b unprivileged processor mode, the application software:
961 - has limited access to the MSR and MRS instructions, and cannot use the CPS instruction.
962 - cannot access the system timer, NVIC, or system control block.
963 - might have restricted access to memory or peripherals.
965 In \b privileged processor mode, the application software can use all the instructions and has access to all resources.
968 \section timerConfig Timer Configuration
970 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_TimerMgmt functions.
972 <b>Timer Configuration Options</b>
973 \image html config_wizard_timer.png "RTX_Config.h: Timer Configuration"
975 Name | \#define | Description
976 ---------------------------------------|--------------------------|----------------------------------------------------------------
977 Object specific Memory allocation | \c OS_TIMER_OBJ_MEM | Enables object specific memory allocation.
978 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]}.
979 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}
980 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}.
981 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]}.
983 \subsection timerConfig_obj Object-specific memory allocation
984 See \ref ObjectMemoryPool.
986 \subsection timerConfig_user User Timer Thread
987 The RTX5 function \b osRtxTimerThread executes callback functions when a time period expires. The priority of the timer
988 subsystem within the complete RTOS system is inherited from the priority of the \b osRtxTimerThread. This is configured by
989 \c OS_TIMER_THREAD_PRIO. Stack for callback functions is supplied by \b osRtxTimerThread. \c OS_TIMER_THREAD_STACK_SIZE must
990 satisfy the stack requirements of the callback function with the highest stack usage.
993 \section eventFlagsConfig Event Flags Configuration
995 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_EventFlags functions.
997 <b>Event Configuration Options</b>
998 \image html config_wizard_eventFlags.png "RTX_Config.h: Event Flags Configuration"
1000 Name | \#define | Description
1001 ---------------------------------------|--------------------------|----------------------------------------------------------------
1002 Object specific Memory allocation | \c OS_EVFLAGS_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1003 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]}.
1005 \subsection eventFlagsConfig_obj Object-specific memory allocation
1006 When object-specific memory is used, the pool size for all Event objects is specified by \c OS_EVFLAGS_NUM. Refer to
1007 \ref ObjectMemoryPool.
1010 \section mutexConfig Mutex Configuration
1011 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_MutexMgmt functions.
1013 <b>Mutex Configuration Options</b>
1014 \image html config_wizard_mutex.png "RTX_Config.h: Mutex Configuration"
1017 Name | \#define | Description
1018 ---------------------------------------|--------------------------|----------------------------------------------------------------
1019 Object specific Memory allocation | \c OS_MUTEX_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1020 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]}.
1022 \subsection mutexConfig_obj Object-specific Memory Allocation
1023 When object-specific memory is used, the pool size for all Mutex objects is specified by \c OS_MUTEX_NUM. Refer to
1024 \ref ObjectMemoryPool.
1027 \section semaphoreConfig Semaphore Configuration
1029 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_SemaphoreMgmt functions.
1031 <b>Semaphore Configuration Options</b>
1032 \image html config_wizard_semaphore.png "RTX_Config.h: Semaphore Configuration"
1035 Name | \#define | Description
1036 ---------------------------------------|--------------------------|----------------------------------------------------------------
1037 Object specific Memory allocation | \c OS_SEMAPHORE_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1038 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]}.
1040 \subsection semaphoreConfig_obj Object-specific memory allocation
1041 When Object-specific Memory is used, the pool size for all Semaphore objects is specified by \c OS_SEMAPHORE_NUM. Refer to
1042 \ref ObjectMemoryPool.
1045 \section memPoolConfig Memory Pool Configuration
1047 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_PoolMgmt functions.
1049 <b>Memory Pool Configuration Options</b>
1050 \image html config_wizard_memPool.png "RTX_Config.h: Memory Pool Configuration"
1052 Name | \#define | Description
1053 ---------------------------------------|--------------------------|----------------------------------------------------------------
1054 Object specific Memory allocation | \c OS_MEMPOOL_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1055 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]}.
1056 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}.
1058 \subsection memPoolConfig_obj Object-specific memory allocation
1059 When object-specific memory is used, the number of pools for all MemoryPool objects is specified by \c OS_MEMPOOL_NUM. The
1060 total storage size reserved for all pools is configured in \c OS_MEMPOOL_DATA_SIZE. Refer to \ref ObjectMemoryPool.
1063 \section msgQueueConfig Message Queue Configuration
1065 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_Message functions.
1067 <b>MessageQueue Configuration Options</b>
1068 \image html config_wizard_msgQueue.png "RTX_Config.h: Message Queue Configuration"
1070 Name | \#define | Description
1071 ---------------------------------------|--------------------------|----------------------------------------------------------------
1072 Object specific Memory allocation | \c OS_MSGQUEUE_OBJ_MEM | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1073 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]}.
1074 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}.
1076 \subsection msgQueueConfig_obj Object-specific memory allocation
1077 When Object-specific Memory is used, the number of queues for all Message Queue objects is specified by \c OS_MSGQUEUE_NUM.
1078 The total storage size reserved for all queues is configured in \c OS_MSGQUEUE_DATA_SIZE. Refer to \ref ObjectMemoryPool.
1082 /* ========================================================================================================================== */
1084 \page creating_RTX5_LIB Building the RTX5 Library
1086 The CMSIS Pack contains a µVision project for building the complete set of RTX5 libraries. This project can also be used as
1087 a reference for building the RTX5 libraries using a tool-chain of your choice.
1089 -# Open the project \b RTX_CM.uvprojx from the pack folder <b>CMSIS/RTOS2/RTX/Library/ARM/MDK</b> in µVision.
1090 -# Select the project target that matches your device's processor core.
1091 \n The project provides target configuration for all supported Cortex-M targets supported by RTX5.
1092 -# You can find out about the required preprocessor defines in the dialogs <b>Options for Target - C/C++</b> and
1093 <b>Options for Target - Asm</b>. Note the need to use at least the C99 compiler mode when building RTX from source.
1094 -# From the <b>Project</b> window you find the list of source files required for a complete library build.
1095 -# Build the library of your choice using \b Project - \b Build \b Target (or press F7).
1097 \image html own_lib_projwin.png "Project with files for ARMv8-M Mainline"
1101 /* ========================================================================================================================== */
1103 \page dirstructfiles5 Directory Structure and File Overview
1105 The following section provides an overview of the directory structure and the files that are relevant for the user's for
1106 CMSIS-RTOS RTX v5. The following directory references start below the CMSIS pack installation path, for example
1107 ARM/CMSIS/<i>version</i>/CMSIS/RTOS2.
1109 \section Folders RTX v5 Directory Structure
1111 The CMSIS-RTOS RTX v5 is delivered in source code and several examples are provided.
1113 <table class="cmtable" summary="CMSIS-RTOS RTX Library Files">
1120 <td>The include file for CMSIS-RTOS API v2. cmsis_os2.h is the central include file for user applications.</td>
1124 <td>CMSIS-RTOS API template source and header file.</td>
1128 <td>Directory with RTX specific files and folders. Also contains the component viewer description file.</td>
1132 <td>CMSIS-RTOS RTX configuration files %RTX_Config.h and %RTX_Config.c.</td>
1135 <td>RTX/Examples</td>
1136 <td>Example projects that can be directly used in development tools.</td>
1139 <td>RTX/Include</td>
1140 <td>RTX v5 specific include files.</td>
1143 <td>RTX/Include1</td>
1144 <td>CMSIS-RTOS v1 API header file.</td>
1147 <td>RTX/Library</td>
1148 <td>Pre-built libraries (see next table for details).</td>
1152 <td>Source code that can be used with ARMCC and GCC.</td>
1155 <td>RTX/Template</td>
1156 <td>User code templates for creating application projects with CMSIS-RTOS RTX v5.</td>
1160 \section libFiles RTX v5 Library Files
1162 The CMSIS-RTOS RTX Library is available pre-compiled for ARMCC and GCC compilers and supports all Cortex-M
1163 processor variants in every configuration, including ARM Cortex-M23 and Cortex-M33.
1165 <table class="cmtable" summary="CMSIS-RTOS RTX Library Files">
1167 <th>Library File</th>
1168 <th>Processor Configuration</th>
1171 <td>Library/ARM/RTX_CM0.lib</td>
1172 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Cortex-M0 and M1, little-endian.</td>
1175 <td>Library/ARM/RTX_CM3.lib</td>
1176 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Cortex-M3, M4, and M7 without FPU, little-endian.</td>
1179 <td>Library/ARM/RTX_CM4F.lib</td>
1180 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Cortex-M4 and M7 with FPU, little-endian.</td>
1183 <td>Library/ARM/RTX_V8MB.lib</td>
1184 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, ARMv8-M baseline.</td>
1187 <td>Library/ARM/RTX_V8MBN.lib</td>
1188 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, ARMv8-M baseline, non-secure.</td>
1191 <td>Library/ARM/RTX_V8MM.lib</td>
1192 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, ARMv8-M mainline.</td>
1195 <td>Library/ARM/RTX_V8MMF.lib</td>
1196 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, ARMv8-M mainline with FPU.</td>
1199 <td>Library/ARM/RTX_V8MMFN.lib</td>
1200 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, ARMv8-M mainline with FPU, non-secure.</td>
1203 <td>Library/ARM/RTX_V8MMN.lib</td>
1204 <td>CMSIS-RTOS RTX Library for ARMCC Compiler, ARMv8-M mainline, non-secure.</td>
1207 <td>Library/GCC/libRTX_CM0.a</td>
1208 <td>CMSIS-RTOS libRTX Library for GCC Compiler, Cortex-M0 and M1, little-endian.</td>
1211 <td>Library/GCC/libRTX_CM3.a</td>
1212 <td>CMSIS-RTOS libRTX Library for GCC Compiler, Cortex-M3, M4, and M7 without FPU, little-endian.</td>
1215 <td>Library/GCC/libRTX_CM4F.a</td>
1216 <td>CMSIS-RTOS libRTX Library for GCC Compiler, Cortex-M4 and M7 with FPU, little-endian.</td>
1219 <td>Library/GCC/libRTX_V8MB.a</td>
1220 <td>CMSIS-RTOS libRTX Library for GCC Compiler, ARMv8-M baseline.</td>
1223 <td>Library/GCC/libRTX_V8MBN.a</td>
1224 <td>CMSIS-RTOS libRTX Library for GCC Compiler, ARMv8-M baseline, non-secure.</td>
1227 <td>Library/GCC/libRTX_V8MM.a</td>
1228 <td>CMSIS-RTOS libRTX Library for GCC Compiler, ARMv8-M mainline.</td>
1231 <td>Library/GCC/libRTX_V8MMF.a</td>
1232 <td>CMSIS-RTOS libRTX Library for GCC Compiler, ARMv8-M mainline with FPU.</td>
1235 <td>Library/GCC/libRTX_V8MMFN.a</td>
1236 <td>CMSIS-RTOS libRTX Library for GCC Compiler, ARMv8-M mainline with FPU, non-secure.</td>
1239 <td>Library/GCC/libRTX_V8MMN.a</td>
1240 <td>CMSIS-RTOS libRTX Library for GCC Compiler, ARMv8-M mainline, non-secure.</td>
1245 /* ========================================================================================================================== */
1247 \page technicalData5 Technical Data
1249 \section technicalData5_ControlBlockSizes Control Block Sizes
1251 Keil RTX5 specific control block definitions (including sizes) as well as memory pool and message queue memory requirements
1252 are defined in the RTX5 header file:
1255 /// Control Block sizes
1256 #define osRtxThreadCbSize sizeof(osRtxThread_t)
1257 #define osRtxTimerCbSize sizeof(osRtxTimer_t)
1258 #define osRtxEventFlagsCbSize sizeof(osRtxEventFlags_t)
1259 #define osRtxMutexCbSize sizeof(osRtxMutex_t)
1260 #define osRtxSemaphoreCbSize sizeof(osRtxSemaphore_t)
1261 #define osRtxMemoryPoolCbSize sizeof(osRtxMemoryPool_t)
1262 #define osRtxMessageQueueCbSize sizeof(osRtxMessageQueue_t)
1264 /// Memory size in bytes for Memory Pool storage.
1265 /// \param block_count maximum number of memory blocks in memory pool.
1266 /// \param block_size memory block size in bytes.
1267 #define osRtxMemoryPoolMemSize(block_count, block_size) \
1268 (4*(block_count)*(((block_size)+3)/4))
1270 /// Memory size in bytes for Message Queue storage.
1271 /// \param msg_count maximum number of messages in queue.
1272 /// \param msg_size maximum message size in bytes.
1273 #define osRtxMessageQueueMemSize(msg_count, msg_size) \
1274 (4*(msg_count)*(3+(((msg_size)+3)/4)))
1277 If you are using a \ref GlobalMemoryPool to allocate memory for the RTOS objects, you need to know the size that is required
1278 for each object in case of errors. Currently, the control block sizes are as follows (subject to change without
1281 Type | Control block size in bytes |
1282 --------------|:---------------------------:|
1289 Message Queue | 52 |
1291 The size of the memory that is required for memory pool and message queue data storage can be determined from the macros
1296 /* ========================================================================================================================== */
1298 \page misraCompliance5 MISRA-C Compliance Exceptions
1299 CMSIS-RTOS RTX tries to be MISRA-C compliant as much as possible. However, there are some violations in order to simplify
1300 the overall code logic and to generate more efficient code.
1302 This page will list the MISRA-C compliance exceptions. Work in progress.
1305 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1307 \page rtosValidation RTOS Validation
1309 ARM offers a <a class=el href="http://www.keil.com/pack" target="_blank">Software Pack</a> for the CMSIS-RTOS Validation.
1310 The <b>ARM::CMSIS-RTOS_Validation</b> Pack contains the following:
1312 - Source code of a CMSIS-RTOS Validation Suite along with configuration file.
1313 - Documentation of the CMSIS-RTOS Validation Suite.
1314 - Example that shows the usage of the CMSIS-RTOS Validation Suite using simulation.
1317 Currently, a public version of the test suite is available only for CMSIS-RTOS v1 API.
1319 The CMSIS-RTOS Validation Suite performs generic validation of various RTOS features. The test cases verify the
1320 functional behavior, test invalid parameters and call management functions from ISR.
1322 The following CMSIS-RTOS features can be tested with the current release:
1323 - Thread : Create multiple threads, terminate, restart, yield, change priority
1324 - Timer : Create periodic and one-shot timers
1325 - GenWait : Call generic wait functions (osDelay and osWait)
1326 - WaitFunc : Measure wait ticks (delay, mail, message, mutex, semaphore, signal)
1328 Moreover the following inter-thread communication functions can be tested:
1329 - Signal : Verify signal events
1330 - Memory Pool : Verify memory allocation
1331 - Message Queue : Exchange messages between threads
1332 - Mail Queue : Exchange data between threads
1333 - Mutex : Synchronize resource access
1334 - Semaphore : Access shared resources
1336 The RTOS Validation output can be printed to a console, output via ITM printf, or output to a memory buffer.
1338 \section test_output Sample Test Output
1340 CMSIS-RTOS Test Suite Oct 21 2015 16:39:16
1342 TEST 01: TC_ThreadCreate PASSED
1343 TEST 02: TC_ThreadMultiInstance PASSED
1344 TEST 03: TC_ThreadTerminate PASSED
1347 TEST 08: TC_ThreadChainedCreate PASSED
1348 TEST 09: TC_ThreadYield NOT EXECUTED
1349 TEST 10: TC_ThreadParam PASSED
1352 TEST 60: TC_MailFromISRToThread PASSED
1354 Test Summary: 60 Tests, 59 Executed, 59 Passed, 0 Failed, 0 Warnings.
1360 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1362 \page functionOverview Function Overview
1364 CMSIS-RTOS v2 provides multiple API interfaces:
1365 - \subpage rtos_api2 is the new C function API that supports dynamic object creation and ARMv8-M (ARM Cortex-M23 and
1367 - <a class="el" href="../../RTOS/html/functionOverview.html">CMSIS-RTOS C API v1</a> is a C function API that is backward
1368 compatible with CMSIS-RTOS v1.
1369 - \subpage rtos_apicpp is a C++ class function API.
1371 It is possible to intermix the different API variants in the same application and even in the same C/C++ source module.
1372 However, the functions of the <b>C API Version 1</b> may be deprecated in future versions of CMSIS-RTOS.
1374 \section rtos_api2 CMSIS-RTOS2
1376 Overview of all CMSIS-RTOS C API v2 functions that are implemented in the \subpage cmsis_os2_h.
1378 - \ref CMSIS_RTOS_KernelCtrl
1379 - \ref osKernelGetInfo : \copybrief osKernelGetInfo
1380 - \ref osKernelGetState : \copybrief osKernelGetState
1381 - \ref osKernelGetSysTimerCount : \copybrief osKernelGetSysTimerCount
1382 - \ref osKernelGetSysTimerFreq : \copybrief osKernelGetSysTimerFreq
1383 - \ref osKernelInitialize : \copybrief osKernelInitialize
1384 - \ref osKernelLock : \copybrief osKernelLock
1385 - \ref osKernelUnlock : \copybrief osKernelUnlock
1386 - \ref osKernelRestoreLock : \copybrief osKernelRestoreLock
1387 - \ref osKernelResume : \copybrief osKernelResume
1388 - \ref osKernelStart : \copybrief osKernelStart
1389 - \ref osKernelSuspend : \copybrief osKernelSuspend
1390 - \ref osKernelGetTickCount : \copybrief osKernelGetTickCount
1391 - \ref osKernelGetTickFreq : \copybrief osKernelGetTickFreq
1393 - \ref CMSIS_RTOS_ThreadMgmt
1394 - \ref osThreadDetach : \copybrief osThreadDetach
1395 - \ref osThreadEnumerate : \copybrief osThreadEnumerate
1396 - \ref osThreadExit : \copybrief osThreadExit
1397 - \ref osThreadGetCount : \copybrief osThreadGetCount
1398 - \ref osThreadGetId : \copybrief osThreadGetId
1399 - \ref osThreadGetName : \copybrief osThreadGetName
1400 - \ref osThreadGetPriority : \copybrief osThreadGetPriority
1401 - \ref osThreadGetStackSize : \copybrief osThreadGetStackSize
1402 - \ref osThreadGetStackSpace : \copybrief osThreadGetStackSpace
1403 - \ref osThreadGetState : \copybrief osThreadGetState
1404 - \ref osThreadJoin : \copybrief osThreadJoin
1405 - \ref osThreadNew : \copybrief osThreadNew
1406 - \ref osThreadResume : \copybrief osThreadResume
1407 - \ref osThreadSetPriority : \copybrief osThreadSetPriority
1408 - \ref osThreadSuspend : \copybrief osThreadSuspend
1409 - \ref osThreadTerminate : \copybrief osThreadTerminate
1410 - \ref osThreadYield : \copybrief osThreadYield
1412 - \ref CMSIS_RTOS_ThreadFlagsMgmt
1413 - \ref osThreadFlagsSet : \copybrief osThreadFlagsSet
1414 - \ref osThreadFlagsClear : \copybrief osThreadFlagsClear
1415 - \ref osThreadFlagsGet : \copybrief osThreadFlagsGet
1416 - \ref osThreadFlagsWait : \copybrief osThreadFlagsWait
1418 - \ref CMSIS_RTOS_EventFlags
1419 - \ref osEventFlagsGetName : \copybrief osEventFlagsGetName
1420 - \ref osEventFlagsNew : \copybrief osEventFlagsNew
1421 - \ref osEventFlagsDelete : \copybrief osEventFlagsDelete
1422 - \ref osEventFlagsSet : \copybrief osEventFlagsSet
1423 - \ref osEventFlagsClear : \copybrief osEventFlagsClear
1424 - \ref osEventFlagsGet : \copybrief osEventFlagsGet
1425 - \ref osEventFlagsWait : \copybrief osEventFlagsWait
1427 - \ref CMSIS_RTOS_Wait
1428 - \ref osDelay : \copybrief osDelay
1429 - \ref osDelayUntil : \copybrief osDelayUntil
1431 - \ref CMSIS_RTOS_TimerMgmt
1432 - \ref osTimerDelete : \copybrief osTimerDelete
1433 - \ref osTimerGetName : \copybrief osTimerGetName
1434 - \ref osTimerIsRunning : \copybrief osTimerIsRunning
1435 - \ref osTimerNew : \copybrief osTimerNew
1436 - \ref osTimerStart : \copybrief osTimerStart
1437 - \ref osTimerStop : \copybrief osTimerStop
1439 - \ref CMSIS_RTOS_MutexMgmt
1440 - \ref osMutexAcquire : \copybrief osMutexAcquire
1441 - \ref osMutexDelete : \copybrief osMutexDelete
1442 - \ref osMutexGetName : \copybrief osMutexGetName
1443 - \ref osMutexGetOwner : \copybrief osMutexGetOwner
1444 - \ref osMutexNew : \copybrief osMutexNew
1445 - \ref osMutexRelease : \copybrief osMutexRelease
1447 - \ref CMSIS_RTOS_SemaphoreMgmt
1448 - \ref osSemaphoreAcquire : \copybrief osSemaphoreAcquire
1449 - \ref osSemaphoreDelete : \copybrief osSemaphoreDelete
1450 - \ref osSemaphoreGetCount : \copybrief osSemaphoreGetCount
1451 - \ref osSemaphoreGetName : \copybrief osSemaphoreGetName
1452 - \ref osSemaphoreNew : \copybrief osSemaphoreNew
1453 - \ref osSemaphoreRelease : \copybrief osSemaphoreRelease
1455 - \ref CMSIS_RTOS_PoolMgmt
1456 - \ref osMemoryPoolAlloc : \copybrief osMemoryPoolAlloc
1457 - \ref osMemoryPoolDelete : \copybrief osMemoryPoolDelete
1458 - \ref osMemoryPoolFree : \copybrief osMemoryPoolFree
1459 - \ref osMemoryPoolGetBlockSize : \copybrief osMemoryPoolGetBlockSize
1460 - \ref osMemoryPoolGetCapacity : \copybrief osMemoryPoolGetCapacity
1461 - \ref osMemoryPoolGetCount : \copybrief osMemoryPoolGetCount
1462 - \ref osMemoryPoolGetName : \copybrief osMemoryPoolGetName
1463 - \ref osMemoryPoolGetSpace : \copybrief osMemoryPoolGetSpace
1464 - \ref osMemoryPoolNew : \copybrief osMemoryPoolNew
1466 - \ref CMSIS_RTOS_Message
1467 - \ref osMessageQueueDelete : \copybrief osMessageQueueDelete
1468 - \ref osMessageQueueGet : \copybrief osMessageQueueGet
1469 - \ref osMessageQueueGetCapacity : \copybrief osMessageQueueGetCapacity
1470 - \ref osMessageQueueGetCount : \copybrief osMessageQueueGetCount
1471 - \ref osMessageQueueGetMsgSize : \copybrief osMessageQueueGetMsgSize
1472 - \ref osMessageQueueGetName : \copybrief osMessageQueueGetName
1473 - \ref osMessageQueueGetSpace : \copybrief osMessageQueueGetSpace
1474 - \ref osMessageQueueNew : \copybrief osMessageQueueNew
1475 - \ref osMessageQueuePut : \copybrief osMessageQueuePut
1476 - \ref osMessageQueueReset : \copybrief osMessageQueueReset
1478 - \ref rtx5_specific
1479 - \ref osRtxErrorNotify : \copybrief osRtxErrorNotify
1480 - \ref osRtxIdleThread : \copybrief osRtxIdleThread
1481 - \ref osRtxSysTimerSetup : \copybrief osRtxSysTimerSetup
1482 - \ref osRtxSysTimerEnable : \copybrief osRtxSysTimerEnable
1483 - \ref osRtxSysTimerDisable : \copybrief osRtxSysTimerDisable
1484 - \ref osRtxSysTimerAckIRQ : \copybrief osRtxSysTimerAckIRQ
1485 - \ref osRtxSysTimerGetCount : \copybrief osRtxSysTimerGetCount
1486 - \ref osRtxSysTimerGetFreq : \copybrief osRtxSysTimerGetFreq
1488 The following CMSIS-RTOS2 functions can be called from threads and \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines"
1490 - \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 The C++11/C++14 interface is planned to be released in January 2017.
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 need to specify an \ref kernelTimer "alternate hardware timer" as the system tick timer, you need to implement the
1544 functions \ref osRtxSysTimerSetup, \ref osRtxSysTimerEnable, \ref osRtxSysTimerDisable, and optionally the function
1545 \ref osRtxSysTimerAckIRQ.
1546 - If you try to find a \b runtime \b error, use the function \ref osRtxErrorNotify to debug the error.
1548 RTX5 interfaces to the <a href="http://www.keil.com/pack/doc/compiler/EventRecorder/html/index.html" target="_blank"><b>Event Recorder</b></a>
1549 to provide event information which helps you to understand and analyze the operation. Refer to \ref rtx_evr for more
1557 \defgroup rtx5_specific_defines Macros
1563 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1565 \def osRtxThreadCbSize
1568 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1570 \def osRtxTimerCbSize
1573 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1575 \def osRtxEventFlagsCbSize
1578 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1580 \def osRtxMutexCbSize
1583 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1585 \def osRtxSemaphoreCbSize
1588 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1590 \def osRtxMemoryPoolCbSize
1593 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1595 \def osRtxMessageQueueCbSize
1598 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1600 \def osRtxMemoryPoolMemSize
1603 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1605 \def osRtxMessageQueueMemSize
1613 \defgroup rtx5_specific_structs Structs
1619 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1621 \struct osRtxThread_t
1624 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1626 \struct osRtxTimerFinfo_t
1629 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1631 \struct osRtxTimer_t
1634 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1636 \struct osRtxEventFlags_t
1639 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1641 \struct osRtxMutex_t
1644 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1646 \struct osRtxSemaphore_t
1649 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1651 \struct osRtxMemoryPool_t
1654 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1656 \struct osRtxMessageQueue_t
1664 \defgroup rtx5_specific_functions Functions
1665 \brief RTX5 functions
1670 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1672 \fn uint32_t osRtxErrorNotify (uint32_t code, void *object_id);
1674 Some system error conditions can be detected during runtime. If the RTX kernel detects a runtime error, it calls the runtime
1675 error function \b osRtxErrorNotify for an object specified by parameter \a object_id.
1677 The parameter \a code passes the actual error code to this function:
1678 | Error Code | Description |
1679 |------------------------------|-----------------------------------------------------------------------------------|
1680 | osRtxErrorStackUnderflow | Stack underflow detected for thread (thread_id=object_id) |
1681 | osRtxErrorISRQueueOverflow | ISR Queue overflow detected when inserting object (object_id) |
1682 | osRtxErrorTimerQueueOverflow | User Timer Callback Queue overflow detected for timer (timer_id=object_id) |
1683 | osRtxErrorClibSpace | Standard C/C++ library libspace not available: increase \c OS_THREAD_LIBSPACE_NUM |
1684 | osRtxErrorClibMutex | Standard C/C++ library mutex initialization failed |
1686 The function \b osRtxErrorNotify must contain an infinite loop to prevent further program execution. You can use an emulator
1687 to step over the infinite loop and trace into the code introducing a runtime error. For the overflow errors this means you
1688 need to increase the size of the object causing an overflow.
1690 \note Cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
1696 uint32_t osRtxErrorNotify (uint32_t code, void *object_id) {
1700 case osRtxErrorStackUnderflow:
1701 // Stack underflow detected for thread (thread_id=object_id)
1703 case osRtxErrorISRQueueOverflow:
1704 // ISR Queue overflow detected when inserting object (object_id)
1706 case osRtxErrorTimerQueueOverflow:
1707 // User Timer Callback Queue overflow detected for timer (timer_id=object_id)
1709 case osRtxErrorClibSpace:
1710 // Standard C/C++ library libspace not available: increase OS_THREAD_LIBSPACE_NUM
1712 case osRtxErrorClibMutex:
1713 // Standard C/C++ library mutex initialization failed
1724 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1725 osRtxErrorClibMutex /**
1726 \fn void osRtxIdleThread (void *argument);
1728 The function \b osRtxIdleThread is executed by the RTX kernel, when no other threads are ready to run. By default, this
1729 thread is an empty end-less loop that does nothing. It only waits until another task becomes ready to run. You may change the
1730 code of the \b osRtxIdleThread function to put the CPU into a power-saving or idle mode.
1732 The default stack size for this thread is defined in the file RTX_Config.h. Refer to \ref threadConfig.
1734 \note Cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
1740 __NO_RETURN void osRtxIdleThread (void *argument) {
1748 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1750 \fn int32_t osRtxSysTimerSetup (void);
1752 By default, RTX5 uses the Cortex-M SysTick timer, but using \b osRtxSysTimerSetup allows to set up an alternative system
1755 \note Cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
1758 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1760 \fn void osRtxSysTimerEnable (void);
1762 The function \b osRtxSysTimerEnable enables the alternative system timer that has been set up using \ref osRtxSysTimerSetup.
1764 \note Cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
1767 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1769 \fn void osRtxSysTimerDisable (void);
1771 The function \b osRtxSysTimerDisable disables the alternative system timer that has been set up using \ref osRtxSysTimerSetup.
1773 \note Cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
1776 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1778 \fn void osRtxSysTimerAckIRQ (void);
1781 \note Cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
1784 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1786 \fn uint32_t osRtxSysTimerGetCount (void);
1788 The function \b osRtxSysTimerGetCount returns the system timer count of the alternative timer set up by
1789 \ref osRtxSysTimerSetup.
1791 \note Cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
1794 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1796 \fn uint32_t osRtxSysTimerGetFreq (void);
1798 The function \b osRtxSysTimerGetFreq returns the system timer frequency of the alternative timer set up by
1799 \ref osRtxSysTimerSetup.
1801 \note Cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".