]> begriffs open source - cmsis/blob - CMSIS/DoxyGen/RTOS2/src/cmsis_os2.txt
Corrected IRQ and SVC exception handlers for Cortex-A.
[cmsis] / CMSIS / DoxyGen / RTOS2 / src / cmsis_os2.txt
1 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2 /**
3 \mainpage
4
5 The <b>CMSIS-RTOS API Version 2 (CMSIS-RTOS2)</b> is a generic RTOS interface for ARM&reg; Cortex&reg;-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.
12
13 \note The CMSIS-RTOS API Version 2 defines a minimum feature set. Implementations with extended features may be provided by
14       the RTOS vendors.
15
16 The CMSIS-RTOS2 manages the resources of the microcontroller system and implements the concept of parallel threads that run
17 concurrently.
18
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.
23
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.
26
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>.
34
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.
39
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.
43
44 CMSIS-RTOS2 is not POSIX compliant, but has provisions to enable a C++11/C++14 interface.
45
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.
53
54 <hr>
55
56 CMSIS-RTOS2 in ARM::CMSIS Pack
57 -----------------------------
58
59 The following files relevant to CMSIS-RTOS2 are present in the <b>ARM::CMSIS</b> Pack directories:
60 File/Folder                  | Content                                                                
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
66 */
67
68
69 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
70 /**
71 \page rtos_revisionHistory Revision History
72
73 \section GenRTOS2Rev CMSIS-RTOS API Version 2
74
75 <table class="cmtable" summary="Revision History">
76     <tr>
77       <th>Version</th>
78       <th>Description</th>
79     </tr>
80     <tr>
81       <td>V2.1.1</td>
82       <td>
83         Additional functions allowed to be called from Interrupt Service Routines:
84          - \ref osKernelGetTickCount, \ref osKernelGetTickFreq
85          
86         Changed Kernel Tick type to uint32_t:
87          - updated: \ref osKernelGetTickCount, \ref osDelayUntil
88      </td>
89     </tr>
90     <tr>
91       <td>V2.1.0</td>
92       <td>
93         Support for critical and uncritical sections (nesting safe):
94          - updated: \ref osKernelLock, \ref osKernelUnlock
95          - added: \ref osKernelRestoreLock
96          
97         Updated \ref CMSIS_RTOS_ThreadFlagsMgmt "Thread Flags" and \ref CMSIS_RTOS_EventFlags "Event Flags":
98          - changed flags parameter and return type from int32_t to uint32_t
99      </td>
100     </tr>
101     <tr>
102       <td>V2.0.0</td>
103       <td>
104         New API Version 2.0 available. 
105          - See \ref rtos_api2 for a detailed function reference.
106          - See \ref os2Migration for details on the migration process from API Version 1.
107      </td>
108     </tr>
109     <tr>
110       <td>V1.02 - only documentation changes</td>
111       <td>
112       Added: Overview of the \ref rtosValidation "CMSIS-RTOS Validation" Software Pack.\n
113       Clarified: Behavior of \ref CMSIS_RTOS_TimeOutValue.
114      </td>
115     </tr>
116     <tr>
117       <td>V1.02</td>
118       <td>Added: New control functions for short timeouts in microsecond resolution \b osKernelSysTick,
119       \b osKernelSysTickFrequency, \b osKernelSysTickMicroSec.\n
120       Removed: osSignalGet.
121      </td>
122     </tr>fv
123     <tr>
124       <td>V1.01</td>
125       <td>Added capabilities for C++, kernel initialization and object deletion.\n
126       Prepared for C++ class interface. In this context to \em const attribute has been moved from osXxxxDef_t typedefs to
127       the osXxxxDef macros.\n
128       Added: \ref osTimerDelete, \ref osMutexDelete, \ref osSemaphoreDelete.\n
129       Added: \ref osKernelInitialize that prepares the kernel for object creation.\n
130       </td>
131     </tr>
132     <tr>
133       <td>
134       V1.00</td>
135       <td>First official Release.\n
136       Added: \ref osKernelStart; starting 'main' as a thread is now an optional feature.\n
137       Semaphores have now the standard behavior.\n
138       \b osTimerCreate does no longer start the timer. Added: \ref osTimerStart (replaces osTimerRestart).\n
139       Changed: osThreadPass is renamed to \ref osThreadYield.
140       </td>
141     </tr>
142     <tr>
143       <td>V0.02</td>
144       <td>Preview Release.</td>
145     </tr>
146 </table>
147
148
149 \section RTX5RevisionHistory CMSIS-RTOS RTX Version 5
150
151 <table class="cmtable" summary="Revision History">
152     <tr>
153       <th>Version</th>
154       <th>Description</th>
155     </tr>
156     <tr>
157       <td>V5.2.1</td>
158       <td>
159        - Corrected SysTick and SVC Interrupt Priority for Cortex-M.
160        - Corrected IRQ and SVC exception handlers for Cortex-A.
161       </td>
162     </tr>
163     <tr>
164       <td>V5.2.0</td>
165       <td>
166        - Based on CMSIS-RTOS API V2.1.1.
167        - Added support for for Cortex-A.
168        - Using OS Tick API for RTX Kernel Timer Tick.
169        - Fixed potential corruption of terminated threads list.
170        - Corrected MessageQueue to use actual message length (before padding).
171        - Corrected parameters for ThreadEnumerate and MessageQueueInserted events.
172        - Timer Thread creation moved to osKernelStart.
173       </td>
174     </tr>
175     <tr>
176       <td>V5.1.0</td>
177       <td>
178        - Based on CMSIS-RTOS API V2.1.0.
179        - Added support for Event recording.
180        - Added support for IAR compiler.
181        - Updated configuration files: RTX_Config.h for the configuration settings and RTX_config.c for implementing the \ref rtx5_specific.
182        - osRtx name-space for RTX specific symbols.
183       </td>
184     </tr>
185     <tr>
186       <td>V5.0.0</td>
187       <td>
188        Initial release compliant to CMSIS-RTOS2.\n
189       </td>
190     </tr>
191 </table>
192 */
193
194
195 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
196 /**
197 \page genRTOS2IF Generic RTOS Interface
198
199 CMSIS-RTOS2 is a generic API that is agnostic of the underlying RTOS kernel. Application programmers call CMSIS-RTOS2 API
200 functions in the user code to ensure maximum portability from one RTOS to another. Middleware using CMSIS-RTOS2 API takes
201 advantages of this approach by avoiding unnecessary porting efforts.
202
203 \image html "API_Structure.png" "CMSIS-RTOS API Structure"
204
205 A typical CMSIS-RTOS2 API implementation interfaces to an existing real-time kernel. The CMSIS-RTOS2 API provides the
206 following attributes and functionalities:
207  - Function names, identifiers, and parameters are descriptive and easy to understand. The functions are powerful and
208    flexible which reduces the number of functions exposed to the user. 
209  - \ref CMSIS_RTOS_ThreadMgmt allows you to define, create, and control threads.
210  - Interrupt Service Routines (ISR) can \ref CMSIS_RTOS_ISR_Calls "call some CMSIS-RTOS functions". When a CMSIS-RTOS
211    function cannot be called from an ISR context, it rejects the invocation and returns an error code.
212  - Three different event types support communication between multiple threads and/or ISR:
213    - \ref CMSIS_RTOS_ThreadFlagsMgmt "Thread Flags": may be used to indicate specific conditions to a thread.
214    - \ref CMSIS_RTOS_EventFlags "Event Flags": may be used to indicate events to a thread or ISR.
215    - \ref CMSIS_RTOS_Message "Messages": can be sent to a thread or an ISR. Messages are buffered in a queue.
216  - \ref CMSIS_RTOS_MutexMgmt and \ref CMSIS_RTOS_SemaphoreMgmt are incorporated.
217  - CPU time can be scheduled with the following functionalities:
218    - A \a timeout parameter is incorporated in many CMSIS-RTOS functions to avoid system lockup. When a timeout is specified,
219      the system waits until a resource is available or an event occurs. While waiting, other threads are scheduled.
220    - The \ref osDelay and \ref osDelayUntil functions put a thread into the \b WAITING state for a specified period of time.
221    - The \ref osThreadYield provides co-operative thread switching and passes execution to another thread of the same
222      priority.
223  - \ref CMSIS_RTOS_TimerMgmt  functions are used to trigger the execution of functions.
224
225 The CMSIS-RTOS2 API is designed to optionally incorporate multi-processor systems and/or access protection via the Cortex-M
226 Memory Protection Unit (MPU).
227
228 In some RTOS implementations threads may execute on different processors, thus \b message queues may reside in shared memory
229 resources.
230
231 The CMSIS-RTOS2 API encourages the software industry to evolve existing RTOS implementations. RTOS implementations can be
232 different and optimized in various aspects towards the Cortex-M processors. Optional features may be for example
233  - Support of the Cortex-M Memory Protection Unit (MPU).
234  - Support of multi-processor systems.
235  - Support of a DMA controller.
236  - Deterministic context switching.
237  - Round-robin context switching.
238  - Deadlock avoidance, for example with priority inversion.
239  - Zero interrupt latency by using ARMv7-M instructions LDREX and STREX.
240  
241 \section usingOS2 Using a CMSIS-RTOS2 Implementation
242
243 A CMSIS-RTOS2 implementation is typically provided as a library. To add the RTOS functionality to an existing CMSIS-based
244 application, the RTOS library (and typically one or more configuration files) needs to be added. There is a single new header
245 file %cmsis_os2.h available. This is the only header file required for a completely portable application. In such a case,
246 user provided memory for control blocks, objects data and thread stack cannot be used. Alternatively, you can include an
247 implementation specific header file (for example rtx_os.h) which provides definitions also for resource allocation (such as
248 size of control blocks, required memory for object data and thread stack). This is optional and implies that the application
249 code is not completely portable.
250
251 \image html "CMSIS_RTOS_Files.png" "CMSIS-RTOS File Structure"
252
253 Once the files are added to a project, the user can start working with the CMSIS-RTOS functions.  A code example is provided
254 below:
255  
256 <b>Code Example</b>
257 \code
258 /*----------------------------------------------------------------------------
259  * CMSIS-RTOS 'main' function template
260  *---------------------------------------------------------------------------*/
261  
262 #include "RTE_Components.h"
263 #include  CMSIS_device_header
264 #include "cmsis_os2.h"
265  
266 /*----------------------------------------------------------------------------
267  * Application main thread
268  *---------------------------------------------------------------------------*/
269 void app_main (void *argument) {
270  
271   // ...
272   for (;;) {}
273 }
274  
275 int main (void) {
276  
277   // System Initialization
278   SystemCoreClockUpdate();
279 #ifdef RTE_Compiler_EventRecorder
280   // Initialize and start Event Recorder
281   EventRecorderInitialize(EventRecordError, 1U);
282 #endif
283   // ...
284  
285   osKernelInitialize();                 // Initialize CMSIS-RTOS
286   osThreadNew(app_main, NULL, NULL);    // Create application main thread
287   osKernelStart();                      // Start thread execution
288   for (;;) {}
289 }
290 \endcode
291
292
293 \section cmsis_os2_h cmsis_os2.h header file
294
295 The file \b cmsis_os2.h is a standard header file that interfaces to every CMSIS-RTOS2 compliant real-time operating
296 systems (RTOS). Each implementation is provided the same \b cmsis_os2.h which defines the interface to the \ref rtos_api2.
297
298 Using the \b cmsis_os2.h along with dynamic object allocation allows to create source code or libraries that require no
299 modifications when using on a different CMSIS-RTOS2 implementation.
300
301 <b>Header file %cmsis_os2.h</b>
302
303 \include cmsis_os2.h
304 */
305
306
307 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
308 /**
309 \page rtx5_impl RTX v5 Implementation
310
311 Keil RTX version 5 (RTX5) implements the CMSIS-RTOS2 as a native RTOS interface for ARM Cortex-M processor-based devices.
312 A translation layer to CMSIS-RTOS API v1 is provided. Therefore, RTX5 can be used in applications that where previously based
313 on RTX version 4 and CMSIS-RTOS version 1 with minimal effort.
314
315 The following sections provide further details:
316  - \subpage cre_rtx_proj explains how to setup an RTX v5 project in Keil MDK.
317  - \subpage theory_of_operation provides general information about the operation of CMSIS-RTOS RTX v5.
318  - \subpage config_rtx5 describes configuration parameters of CMSIS-RTOS RTX v5.
319  - \subpage creating_RTX5_LIB explains how to build your own CMSIS-RTOS RTX v5 library.
320  - \subpage dirstructfiles5 explains the directories and files that are supplied as part of CMSIS-RTOS RTX v5.
321  - \subpage technicalData5 lists microcontroller hardware requirements and limitations such as number of concurrent threads.
322  - \subpage misraCompliance5 describes the violations to the MISRA standard.
323 */
324
325 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
326 /**
327 \page cre_rtx_proj Create an RTX5 Project
328
329 The steps to create a microcontroller application using RTX5 are:
330 - Create a new project and select a microcontroller device.
331 - In the Manage Run-Time Environment window, select <b>CMSIS\::CORE</b> and <b>CMSIS\::RTOS2 (API)\::Keil RTX5</b>. You can
332   choose to either add RTX as a library (Variant: \b Library) or to add the full source code (Variant: \b Source - required
333   if using the <a href="http://www.keil.com/pack/doc/compiler/EventRecorder/html/index.html" target="_blank"><b>Event Recorder</b></a>):
334
335    \image html manage_rte_output.png
336
337 - If the <b>Validation Output</b> requires other components to be present, try to use the \b Resolve button.
338 - Click \b OK. In the \b Project window, you will see the files that have been automatically added to you project, such as
339   \b %RTX_Config.h, \b %RTX_Config.c, the library or the source code files, as well as the system and startup files:
340
341    \image html project_window.png
342
343 - 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).   
344 - You can add template files to the project by right-clicking on <b>Source Group 1</b> and selecting
345   <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
346   you will see all available template files for CMSIS-RTOS RTX:
347   
348    \image html add_item.png
349
350 - \ref config_rtx5 "Configure" RTX5 to the application's needs using the \b %RTX_Config.h file.
351
352 \section cre_rtx_cortexa Additional requirements for RTX on Cortex-A
353
354 Cortex-A based microcontrollers are less unified with respect to the interrupt and timer implementations used compared to 
355 M-class devices. Thus RTX requires additional components when an A-class device is used, namely
356 <a href="../../Core_A/html/group__irq__ctrl__gr.html"><b>IRQ Controller (API)</b></a> and \ref CMSIS_RTOS_TickAPI "OS Tick (API)"
357 implementations. 
358
359 \image html manage_rte_cortex-a.png
360
361 The default implementations provided along with CMSIS are 
362 - ARM <a href="../../Core_A/html/group__GIC__functions.html">Generic Interrupt Controller (GIC)</a>
363 - ARM Cortex-A5, Cortex-A9 <a href="../../Core_A/html/group__PTM__timer__functions.html">Private Timer (PTIM)</a>
364 - ARM Cortex-A7 <a href="../../Core_A/html/group__PL1__timer__functions.html">Generic Physical Timer (GTIM)</a>
365
366 For devices not implementing GIC, PTIM nor GTIM please refer to the according device family pack and select the
367 proper implementations.
368
369 \section cre_rtx_proj_specifics Add support for RTX specific functions
370 If you require some of the \ref rtx5_specific "RTX specific functions" in your application code, \#include the
371 \ref rtx_os_h "header file rtx_os.h". This enables \ref lowPower "low-power" and \ref TickLess "tick-less" operation modes.
372
373 \section cre_rtx_proj_er Add Event Recorder Visibility
374 - To use the Event Recorder together with RTX5, select the software component <b>Compiler:Event Recorder</b>.
375 - Select the \b Source variant of the software component <b>CMSIS:RTOS2 (API):Keil RTX5</b>.
376   \image html event_recorder_rte.png "Component selection for Event Recorder"
377 - Call the function <b>EventRecorderInitialize()</b> in your application code (ideally in \c main()).
378 - Build the application code and download it to the debug hardware.
379   
380 Once the target application generates event information, it can be viewed in the µVision debugger using the \b Event
381  \b Recorder.
382  */
383
384
385 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
386 /**
387 \page theory_of_operation Theory of Operation
388
389 Many aspects of the kernel are configurable and the configuration options are mentioned where applicable.
390
391 \section SystemStartup System Startup
392
393 Since main is no longer a thread RTX5 does not interfere with the system startup until main is reached.
394 Once the execution reaches \c main() there is a recommended order to initialize the hardware and start the kernel. This is
395 also reflected in the user code template file "CMSIS-RTOS2 'main' function" supplied with the RTX5 component.
396
397 Your application's \c main() should implement at least the following in the given order:
398 -# Initialization and configuration of hardware including peripherals, memory, pins, clocks and the interrupt system.
399 -# Update the system core clock using the respective
400    <a href=../../Core/html/group__system__init__gr.html>CMSIS-Core (Cortex-M) function</a>.
401 -# Initialize the CMSIS-RTOS kernel using \ref osKernelInitialize.
402 -# Optionally, create a new thread \c app_main, which is used as a main thread using \ref osThreadNew. Alternatively, threads
403    can be created in \c main() directly.
404 -# Start the RTOS scheduler using \ref osKernelStart. This function does not return in case of successful execution. Any
405    application code after \b osKernelStart will not be executed unless \b osKernelStart fails.            
406
407 \note Interrupts (like SVC for example) used by the kernel are initialized in \ref osKernelInitialize. In case priorities and
408 groupings in the NVIC are altered by the application after the above sequence it might be necessary to call
409 \ref osKernelInitialize again.
410
411 \section Scheduler 
412
413 RTX5 implements a low-latency preemtive scheduler. Major parts of RTX5 are executed in handler mode such as
414   - \ref SysTick_Handler used for time-based scheduling.
415   - \ref SVC_Handler used for lock-based scheduling.
416   - \ref PendSV_Handler used for interrupt-based scheduling.
417
418 In order to be low-latency with respect to ISR execution those system exceptions are configured to use the
419 lowest priority groups available. The priorities are configured such that no preemption happens between them. Thus
420 no interrupt critical sections (i.e. interrupt locks) are needed to protect the scheduler.
421
422 \image html scheduling.png "Thread scheduling and interrupt execution"
423
424 The scheduler combines priority and round-robin based context switches. The example depicted in the image above contains
425 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
426 (\ref osThreadAttr_t::priority). As long as threads 3 and 4 are blocked the scheduler switches between thread 1 and 2 on
427 a time-slice basis (round-robin). The time-slice for round-robin scheduling can be configured, see Round-Robin Timeout in \ref systemConfig.
428
429 Thread 2 unblocks thread 3 by an arbitrary RTOS-call (executed in SVC handler mode) at time index 2. The scheduler switches to
430 thread 3 immidiately because thread 3 has the highest priority. Thread 4 is still blocked.
431
432 At time index 4 an interrupt (ISR) occurs and preempts the SysTick_Handler. RTX does not add any latency to the interrupt
433 service execution. The ISR routine uses an RTOS-call that unblocks thread 4. Instead of switching to thread 4 immediately
434 the PendSV flag is set to defer the context switching. The PendSV_Handler is executed right after the SysTick_Handler returns
435 and the defered context switch to thread 4 is carried out. As soon as highest priority thread 4 blocks again by using
436 a blocking RTOS-call execution is switched back to thread 3 immidiately during time index 5.
437
438 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.
439 At time index 7 the scheduler uses the round-robin mechanism to switch to thread 1 and so on.
440
441 \section MemoryAllocation Memory Allocation 
442
443 RTX5 objects (thread, mutex, semaphore, timer, message queue, thread and event flags, as well as memory pool) require
444 dedicated RAM memory. Objects can be created using os<i>Object</i>New() calls and deleted using os<i>Object</i>Delete()
445 calls. The related object memory needs to be available during the lifetime of the object.
446
447 RTX5 offers three different memory allocation methods for objects:
448   - \ref GlobalMemoryPool uses a single global memory pool for all objects. It is easy to configure, but may have 
449     the disadvantage for memory fragmentation when objects with different sizes are created and destroyed.
450   - \ref ObjectMemoryPool uses a fixed-size memory pool for each object type. The method is time deterministic
451      and avoids memory fragmentation.
452   - \ref StaticObjectMemory reserves memory during compile time and completely avoids that a system can be out of memory.
453     This is typically a required for some safety critical systems.
454
455 It possible to intermix all the memory allocation methods in the same application.
456
457 \subsection GlobalMemoryPool Global Memory Pool
458
459 The global memory pool allocates all objects from a memory area. This method of memory allocation is the default
460 configuration setting of RTX5.
461
462 \image html MemAllocGlob.png "Global Memory Pool for all objects"
463
464 When the memory pool does not provide sufficient memory, the creation of the object fails and the related
465 os<i>Object</i>New() function returns \token{NULL}.
466
467 Enabled in \ref systemConfig.
468
469 \subsection ObjectMemoryPool Object-specific Memory Pools
470
471 Object-specific memory pools avoids memory fragmentation with a dedicated fixed-size memory management for each object type.
472 This type of memory pools are fully time deterministic, which means that object creation and destruction takes always the
473 same fixed amount of time. As a fixed-size memory pool is specific to an object type, the handling of out-of-memory
474 situations is simplified.
475
476 \image html MemAllocSpec.png "One memory pool per object type"
477
478 Object-specific memory pools are selectively enabled for each object type, e.g: mutex or thread using the RTX configuration
479 file:
480  - Enabled in \ref threadConfig for thread objects.
481  - Enabled in \ref timerConfig for timer objects.
482  - Enabled in \ref eventFlagsConfig for event objects.
483  - Enabled in \ref mutexConfig for mutex objects.
484  - Enabled in \ref semaphoreConfig for semaphore.
485  - Enabled in \ref memPoolConfig for memory pools.
486  - Enabled in \ref msgQueueConfig for message objects.
487
488 When the memory pool does not provide sufficient memory, the creation of the object fails and the related
489 os<i>Object</i>New() function returns \token{NULL}.
490
491 \subsection StaticObjectMemory Static Object Memory
492 In contrast to the dynamic memory allocations, the static memory allocation requires compile-time allocation of object memory. 
493
494 \image html MemAllocStat.png "Statically allocated memory for all objects"
495
496 The following code example shows how to create an OS object using static memory.
497
498 <b> Code Example:</b> 
499 \code{.c}
500 /*----------------------------------------------------------------------------
501  * CMSIS-RTOS 'main' function template
502  *---------------------------------------------------------------------------*/
503
504 #include "RTE_Components.h"
505 #include  CMSIS_device_header
506 #include "cmsis_os2.h"
507  
508 //include rtx_os.h for types of RTX objects
509 #include "rtx_os.h"
510  
511 //The thread function instanced in this example
512 void worker(void *arg)
513 {
514   while(1) 
515   {
516     //work
517     osDelay(10000);
518   }  
519 }
520  
521 // Define objects that are statically allocated for worker thread 1
522 osRtxThread_t worker_thread_tcb_1;
523  
524 // Reserve two areas for the stacks of worker thread 1
525 // uint64_t makes sure the memory alignment is 8
526 uint64_t worker_thread_stk_1[64];
527  
528 // Define the attributes which are used for thread creation
529 // Optional const saves RAM memory and includes the values in periodic ROM tests 
530 const osThreadAttr_t worker_attr_1 = {
531   "wrk1",
532   osThreadJoinable,
533   &worker_thread_tcb_1,
534   sizeof(worker_thread_tcb_1),
535   &worker_thread_stk_1[0],
536   sizeof(worker_thread_stk_1),
537   osPriorityAboveNormal,
538   0
539 };
540  
541 // Define ID object for thread
542 osThreadId_t th1;
543  
544 /*----------------------------------------------------------------------------
545  * Application main thread
546  *---------------------------------------------------------------------------*/
547 void app_main (void *argument) {
548   uint32_t param = NULL;
549  
550   // Create an instance of the worker thread with static resources (TCB and stack)
551   th1 = osThreadNew(worker, &param, &worker_attr_1);
552  
553   for (;;) {}
554 }
555  
556 int main (void) {
557   // System Initialization
558   SystemCoreClockUpdate();
559   // ...
560
561   osKernelInitialize();                 // Initialize CMSIS-RTOS
562   osThreadNew(app_main, NULL, NULL);    // Create application main thread
563   osKernelStart();                      // Start thread execution
564   for (;;) {}
565 }
566 \endcode
567
568
569 \section ThreadStack Thread Stack Management
570
571 For Cortex-M processors without floating point unit the thread context requires 64 bytes on the local stack.
572
573 \note For Cortex-M4/M7 with FP the thread context requires 200 bytes on the local stack. For these devices the default stack
574 space should be increased to a minimum of 300 bytes.
575
576 Each thread is provided with a separate stack that holds the thread context and stack space for automatic variables and
577 return addresses for function call nesting. The stack sizes of RTX threads are flexibly configurable as explained in the
578 section \ref threadConfig. RTX offers a configurable checking for stack overflows and stack utilization. 
579
580
581 \section lowPower Low-Power Operation
582
583 The system thread \b osRtxIdleThread can be use to switch the system into a low-power mode. The easiest form to enter a
584 low-power mode is the execution of the \c __WFE function that puts the processor into a sleep mode where it waits for an
585 event.
586
587 <b>Code Example:</b>
588 \code
589 #include "RTE_Components.h"
590 #include CMSIS_device_header            /* Device definitions                 */
591  
592 void osRtxIdleThread (void) {
593   /* The idle demon is a system thread, running when no other thread is       */
594   /* ready to run.                                                            */
595  
596   for (;;) {
597     __WFE();                            /* Enter sleep mode                   */
598   }
599 }
600 \endcode
601
602 \note
603 \c __WFE() is not available in every Cortex-M implementation. Check device manuals for availability.
604
605
606 \section kernelTimer RTX Kernel Timer Tick
607
608 RTX uses the generic \ref CMSIS_RTOS_TickAPI to configure and control its periodic Kernel Tick.
609
610 To use an alternative timer as the Kernel Tick Timer one simply needs to implement a custom version
611 of the \ref CMSIS_RTOS_TickAPI.
612
613 \note The OS Tick implementation provided must asure that the used timer interrupt uses the same (low) priority group 
614 as the service interrupts, i.e. interrupts used by RTX must not preempt each other. Refer to the \ref Scheduler section
615 for more details.
616
617 \subsection TickLess Tick-less Low-Power Operation
618
619 RTX5 provides extension for tick-less operation which is useful for applications that use extensively low-power modes where
620 the SysTick timer is also disabled. To provide a time-tick in such power-saving modes, a wake-up timer is used to
621 derive timer intervals. The CMSIS-RTOS2 functions \ref osKernelSuspend and \ref osKernelResume control the tick-less
622 operation.
623
624 Using this functions allows the RTX5 thread scheduler to stop the periodic kernel tick interrupt. When all active threads
625 are suspended, the system enters power-down and calculates how long it can stay in this power-down mode. In the power-down
626 mode the processor and peripherals can be switched off. Only a wake-up timer must remain powered, because this timer is
627 responsible to wake-up the system after the power-down period expires.
628
629 The tick-less operation is controlled from the \b osRtxIdleThread thread. The wake-up timeout value is set before the system
630 enters the power-down mode. The function \ref osKernelSuspend calculates the wake-up timeout measured in RTX Timer Ticks;
631 this value is used to setup the wake-up timer that runs during the power-down mode of the system.
632
633 Once the system resumes operation (either by a wake-up time out or other interrupts) the RTX5 thread scheduler is started
634 with the function \ref osKernelResume. The parameter \a sleep_time specifies the time (in RTX Timer Ticks) that the system
635 was in power-down mode.
636
637 <b>Code Example:</b>
638 \code
639 #include "msp.h"                        // Device header
640
641 /*----------------------------------------------------------------------------
642  *      MSP432 Low-Power Extension Functions
643  *---------------------------------------------------------------------------*/
644 static void MSP432_LP_Entry(void) {
645   /* Enable PCM rude mode, which allows to device to enter LPM3 without waiting for peripherals */
646   PCM->CTL1 = PCM_CTL1_KEY_VAL | PCM_CTL1_FORCE_LPM_ENTRY;       
647   /* Enable all SRAM bank retentions prior to going to LPM3  */
648   SYSCTL->SRAM_BANKRET |= SYSCTL_SRAM_BANKRET_BNK7_RET;
649   __enable_interrupt();
650   NVIC_EnableIRQ(RTC_C_IRQn);
651   /* Do not wake up on exit from ISR */
652   SCB->SCR |= SCB_SCR_SLEEPONEXIT_Msk;
653   /* Setting the sleep deep bit */
654   SCB->SCR |= (SCB_SCR_SLEEPDEEP_Msk);  
655 }
656  
657 static volatile unsigned int tc;
658 static volatile unsigned int tc_wakeup;
659  
660 void RTC_C_IRQHandler(void)
661 {
662   if (tc++ > tc_wakeup) 
663   {
664     SCB->SCR &= ~SCB_SCR_SLEEPONEXIT_Msk;    
665     NVIC_DisableIRQ(RTC_C_IRQn);
666     NVIC_ClearPendingIRQ(RTC_C_IRQn);
667     return;
668   }
669   if (RTC_C->PS0CTL & RTC_C_PS0CTL_RT0PSIFG)
670   {
671     RTC_C->CTL0 = RTC_C_KEY_VAL;                 // Unlock RTC key protected registers
672     RTC_C->PS0CTL &= ~RTC_C_PS0CTL_RT0PSIFG;
673     RTC_C->CTL0 = 0;
674     SCB->SCR |= (SCB_SCR_SLEEPDEEP_Msk);
675   }
676 }
677  
678 uint32_t g_enable_sleep = 0;
679   
680 void osRtxIdleThread (void) {
681   
682   for (;;) {
683     tc_wakeup = osKernelSuspend();
684     /* Is there some time to sleep? */
685     if (tc_wakeup > 0) {
686       tc = 0;
687       /* Enter the low power state */
688       MSP432_LP_Entry();
689       __WFE();
690     }
691     /* Adjust the kernel ticks with the amount of ticks slept */
692     osKernelResume (tc);
693   }
694 }
695 \endcode
696
697 \note
698 \c __WFE() is not available in every ARM Cortex-M implementation. Check device manuals for availability. 
699 The alternative using \c __WFI() has other issues, please take note of http://www.keil.com/support/docs/3591.htm as well.
700
701 \section rtx_os_h RTX5 Header File
702
703 Every implementation of the CMSIS-RTOS2 API can bring its own additional features. RTX5 adds a couple of
704 \ref rtx5_specific "functions" for the idle more, for error notifications, and special system timer functions. It also is
705 using macros for control block and memory sizes.
706
707 If you require some of the RTX specific functions in your application code, \#include the header file \b %rtx_os.h:
708
709 \include rtx_os.h
710
711
712 \section CMSIS_RTOS_TimeOutValue Timeout Value   
713
714 Timeout values are an argument to several \b osXxx functions to allow time for resolving a request. A timeout value of \b 0
715 means that the RTOS does not wait and the function returns instantly, even when no resource is available. A timeout value of
716 \ref osWaitForever means that the RTOS waits infinitely until a resource becomes available. Or one forces the thread to resume
717 using \ref osThreadResume which is discouraged.
718  
719 The timeout value specifies the number of timer ticks until the time delay elapses. The value is an upper bound and 
720 depends on the actual time elapsed since the last timer tick. 
721
722 Examples:
723   - timeout value \b 0 : the system does not wait, even when no resource is available the RTOS function returns instantly. 
724   - timeout value \b 1 : the system waits until the next timer tick occurs; depending on the previous timer tick, it may be a
725     very short wait time.
726   - timeout value \b 2 : actual wait time is between 1 and 2 timer ticks.
727   - timeout value \ref osWaitForever : system waits infinite until a resource becomes available. 
728   
729 \image html TimerValues.png "Example of timeout using osDelay()"
730
731
732 \section CMSIS_RTOS_ISR_Calls Calls from Interrupt Service Routines 
733
734 The following CMSIS-RTOS2 functions can be called from threads and Interrupt Service Routines (ISR):
735   - \ref osKernelGetTickCount, \ref osKernelGetTickFreq, \ref osKernelGetSysTimerCount, \ref osKernelGetSysTimerFreq
736   - \ref osThreadFlagsSet
737   - \ref osEventFlagsSet, \ref osEventFlagsClear, \ref osEventFlagsGet, \ref osEventFlagsWait
738   - \ref osSemaphoreAcquire, \ref osSemaphoreRelease, \ref osSemaphoreGetCount
739   - \ref osMemoryPoolAlloc, \ref osMemoryPoolFree, \ref osMemoryPoolGetCapacity, \ref osMemoryPoolGetBlockSize,
740     \ref osMemoryPoolGetCount, \ref osMemoryPoolGetSpace
741   - \ref osMessageQueuePut, \ref osMessageQueueGet, \ref osMessageQueueGetCapacity, \ref osMessageQueueGetMsgSize,
742     \ref osMessageQueueGetCount, \ref osMessageQueueGetSpace
743
744 Functions that cannot be called from an ISR are verifying the interrupt status and return the status code \b osErrorISR, in
745 case they are called from an ISR context. In some implementations, this condition might be caught using the HARD_FAULT
746 vector.
747 */
748
749 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
750 /**
751 \page config_rtx5 Configure RTX v5
752
753 The file "RTX_Config.h" defines the configuration parameters of CMSIS-RTOS RTX and must be part of every project that is
754 using the CMSIS-RTOS RTX kernel. The configuration options are explained in detail in the following sections:
755 - \ref systemConfig covers system-wide settings for the global memory pool, tick frequency, ISR event buffer and round-robin thread switching.
756 - \ref threadConfig provides several parameters to configure the \ref CMSIS_RTOS_ThreadMgmt functions.
757 - \ref timerConfig provides several parameters to configure the \ref CMSIS_RTOS_TimerMgmt functions.
758 - \ref eventFlagsConfig provides several parameters to configure the \ref CMSIS_RTOS_EventFlags functions.
759 - \ref mutexConfig provides several parameters to configure the \ref CMSIS_RTOS_MutexMgmt functions.
760 - \ref semaphoreConfig provides several parameters to configure the \ref CMSIS_RTOS_SemaphoreMgmt functions.
761 - \ref memPoolConfig provides several parameters to configure the \ref CMSIS_RTOS_PoolMgmt functions.
762 - \ref msgQueueConfig provides several parameters to configure the \ref CMSIS_RTOS_Message functions.
763
764 The file "RTX_Config.c" contains default implementations of the functions \ref osRtxIdleThread and \ref osRtxErrorNotify. Both functions
765 can simply be overwritten with a custimized behavior by redefining them as part of the user code.
766
767 The configuration file uses <b>Configuration Wizard Annotations</b>. Refer to <b>Pack - Configuration Wizard Annotations</b> for details.
768 Depending on the development tool, the annotations might lead to a more user-friendly graphical representation of the
769 settings. The screenshot below is a screenshot from the µVision \b Configuration \b Wizard view:
770
771 \image html config_wizard.png "RTX_Config.h in Configuration Wizard View"
772
773 Alternatively one can provide configuration options using the compiler command line.
774
775 For example one can customize the used tick frequency to 100us by (overwriting) the configuration using
776 \code
777 cc -DOS_TICK_FREQ=100
778 \endcode
779
780 \section systemConfig System Configuration
781
782 The system configuration covers system-wide settings for the global memory pool, tick frequency, ISR event buffer and
783 round-robin thread switching.
784
785 <b>System Configuration Options</b>
786 \image html config_wizard_system.png "RTX_Config.h: System Configuration"
787
788 Name                                   | \#define                 | Description
789 ---------------------------------------|--------------------------|----------------------------------------------------------------
790 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.
791 Kernel Tick Frequency (Hz)             | \c OS_TICK_FREQ          | Defines base time unit for delays and timeouts in Hz. Default: 1000Hz = 1ms period.
792 Round-Robin Thread switching           | \c OS_ROBIN_ENABLE       | Enables Round-Robin Thread switching.
793 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]}.
794 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}.
795
796 \subsection systemConfig_glob_mem Global dynamic memory
797 Refer to \ref GlobalMemoryPool.
798
799
800 \subsection systemConfig_rr Round-Robin Thread Switching
801
802 RTX5 may be configured to use round-robin multitasking thread switching. Round-robin allows quasi-parallel execution of
803 several threads of the \a same priority. Threads are not really executed concurrently, but are scheduled where the available
804 CPU time is divided into time slices and RTX5 assigns a time slice to each thread. Because the time slice is typically short
805 (only a few milliseconds), it appears as though threads execute simultaneously.
806
807 Round-robin thread switching functions as follows:
808 - the tick is preloaded with the timeout value when a thread switch occurs
809 - the tick is decremented (if not already zero) each system tick if the same thread is still executing
810 - when the tick reaches 0 it indicates that a timeout has occurred. If there is another thread ready with the \a same
811   priority, then the system switches to that thread and the tick is preloaded with timeout again.
812
813 In other words, threads execute for the duration of their time slice (unless a thread's time slice is given up). Then, RTX
814 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
815 ready to run, the current running thread resumes it execution.
816
817 \note When switching to higher priority threads, the round-robin timeout value is reset.
818
819 Round-Robin multitasking is controlled with the <b>\#define OS_ROBIN_ENABLE</b>. The time slice period is configured (in RTX
820 timer ticks) with the <b>\#define OS_ROBIN_TIMEOUT</b>.
821
822
823 \subsection systemConfig_isr_fifo ISR FIFO Queue
824 The RTX functions (\ref CMSIS_RTOS_ISR_Calls), when called from and interrupt handler, store the request type and optional
825 parameter to the ISR FIFO queue buffer to be processed later, after the interrupt handler exits.
826
827 The scheduler is activated immediately after the IRQ handler has finished its execution to process the requests stored to the
828 FIFO queue buffer. The required size of this buffer depends on the number of functions that are called within the interrupt
829 handler. An insufficient queue size will be caught by \b osRtxErrorNotify with error code \b osRtxErrorISRQueueOverflow.
830
831
832 \section threadConfig Thread Configuration
833
834 The RTX5 provides several parameters to configure the \ref CMSIS_RTOS_ThreadMgmt functions.
835
836 <b>Thread Configuration Options</b>
837 \image html config_wizard_threads.png "RTX_Config.h: Thread Configuration"
838
839 <br> 
840 Option                                                   | \#define               | Description
841 :--------------------------------------------------------|:-----------------------|:---------------------------------------------------------------
842 Object specific Memory allocation                        | \c OS_THREAD_OBJ_MEM   | Enables object specific memory allocation. See \ref ObjectMemoryPool.
843 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]}.
844 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]}.
845 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}. 
846 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}. 
847 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}. 
848 Stack overrun checking                                   | \c OS_STACK_CHECK   | Enable stack overrun checks at thread switch. 
849 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.
850 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.
851
852 \subsection threadConfig_countstack Configuration of Thread Count and Stack Space
853
854 The RTX5 kernel uses a separate stack space for each thread and provides two methods for defining the stack requirements:
855  - <b>Static allocation</b>: when \ref osThreadAttr_t::stack_mem and \ref osThreadAttr_t::stack_size specify a memory area
856    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.
857  - <b>Dynamic allocation</b>: when \ref osThreadAttr_t is NULL or \ref osThreadAttr_t::stack_mem is NULL, the system
858    allocates the stack memory from:
859      - Object-specific Memory Pool (default Stack size) when "Object specific Memory allocation" is enabled and "Number of
860        user Threads with default Stack size" is not \token{0} and \ref osThreadAttr_t::stack_size is \token{0} (or
861        \ref osThreadAttr_t is NULL).
862      - Object-specific Memory Pool (user-provided Stack size) when "Object specific Memory allocation" is enabled and "Total
863        Stack size for user..."  is not \token{0} and \ref osThreadAttr_t::stack_size is not \token{0}.
864      - Global Memory Pool when "Object specific Memory allocation" is disabled or (\ref osThreadAttr_t::stack_size is not
865        \token{0} and "Total Stack size for user..." is \token{0}) or (\ref osThreadAttr_t::stack_size is \token{0} and
866        "Number of user Threads with default Stack size" is \token{0}).
867
868 \ref osThreadAttr_t is a parameter of the function \ref osThreadNew.
869
870 \note
871 Before the RTX kernel is started by the \ref osKernelStart() function, the main stack defined in startup_<i>device</i>.s is
872 used. The main stack is also used for:
873  - user application calls to RTX functions in \b thread \b mode using SVC calls
874  - interrupt/exception handlers.
875  
876 \subsection threadConfig_ovfcheck Stack Overflow Checking
877 RTX5 implements a software stack overflow checking that traps stack overruns. Stack is used for return addresses and
878 automatic variables. Extensive usage or incorrect stack configuration may cause a stack overflow. Software stack overflow
879 checking is controlled with the define \c OS_STACK_CHECK.
880  
881 If a stack overflow is detected, the function \b osRtxErrorNotify with error code \b osRtxErrorStackUnderflow is called. By
882 default, this function is implemented as an endless loop and will practically stop code execution.
883
884 \subsection threadConfig_watermark Stack Usage Watermark
885 RTX5 initializes thread stack with a watermark pattern (0xCC) when a thread is created. This allows the debugger to determine
886 the maximum stack usage for each thread. It is typically used during development but removed from the final application.
887 Stack usage watermark is controlled with the define \c OS_STACK_WATERMARK.
888   
889 Enabling this option significantly increases the execution time of \ref osThreadNew (depends on thread stack size).
890  
891 \subsection threadConfig_procmode Processor Mode for Thread Execution
892 RTX5 allows to execute threads in unprivileged or privileged processor mode. The processor mode is controlled with the
893 define \c OS_PRIVILEGE_MODE.
894  
895 In \b unprivileged processor mode, the application software:
896 - has limited access to the MSR and MRS instructions, and cannot use the CPS instruction.
897 - cannot access the system timer, NVIC, or system control block.
898 - might have restricted access to memory or peripherals.
899
900 In \b privileged processor mode, the application software can use all the instructions and has access to all resources.
901
902
903 \section timerConfig Timer Configuration
904
905 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_TimerMgmt functions.
906
907 <b>Timer Configuration Options</b>
908 \image html config_wizard_timer.png "RTX_Config.h: Timer Configuration"
909
910 Name                                   | \#define                 | Description
911 ---------------------------------------|--------------------------|----------------------------------------------------------------
912 Object specific Memory allocation      | \c OS_TIMER_OBJ_MEM      | Enables object specific memory allocation. 
913 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]}.
914 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} 
915 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}.
916 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]}.
917
918 \subsection timerConfig_obj Object-specific memory allocation
919 See \ref ObjectMemoryPool.
920
921 \subsection timerConfig_user User Timer Thread
922 The RTX5 function \b osRtxTimerThread executes callback functions when a time period expires. The priority of the timer
923 subsystem within the complete RTOS system is inherited from the priority of the \b osRtxTimerThread. This is configured by
924 \c OS_TIMER_THREAD_PRIO. Stack for callback functions is supplied by \b osRtxTimerThread. \c OS_TIMER_THREAD_STACK_SIZE must
925 satisfy the stack requirements of the callback function with the highest stack usage. 
926
927
928 \section eventFlagsConfig Event Flags Configuration
929
930 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_EventFlags functions.
931
932 <b>Event Configuration Options</b>
933 \image html config_wizard_eventFlags.png "RTX_Config.h: Event Flags Configuration"
934
935 Name                                   | \#define                 | Description
936 ---------------------------------------|--------------------------|----------------------------------------------------------------
937 Object specific Memory allocation      | \c OS_EVFLAGS_OBJ_MEM    | Enables object specific memory allocation. See \ref ObjectMemoryPool.
938 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]}.
939
940 \subsection eventFlagsConfig_obj Object-specific memory allocation
941 When object-specific memory is used, the pool size for all Event objects is specified by \c OS_EVFLAGS_NUM. Refer to
942 \ref ObjectMemoryPool.
943
944
945 \section mutexConfig Mutex Configuration
946 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_MutexMgmt functions.
947
948 <b>Mutex Configuration Options</b>
949 \image html config_wizard_mutex.png "RTX_Config.h: Mutex Configuration"
950
951
952 Name                                   | \#define                 | Description
953 ---------------------------------------|--------------------------|----------------------------------------------------------------
954 Object specific Memory allocation      | \c OS_MUTEX_OBJ_MEM      | Enables object specific memory allocation. See \ref ObjectMemoryPool.
955 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]}.
956
957 \subsection mutexConfig_obj Object-specific Memory Allocation
958 When object-specific memory is used, the pool size for all Mutex objects is specified by \c OS_MUTEX_NUM. Refer to
959 \ref ObjectMemoryPool.
960
961
962 \section semaphoreConfig Semaphore Configuration
963
964 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_SemaphoreMgmt functions.
965
966 <b>Semaphore Configuration Options</b>
967 \image html config_wizard_semaphore.png "RTX_Config.h: Semaphore Configuration"
968
969
970 Name                                   | \#define                 | Description
971 ---------------------------------------|--------------------------|----------------------------------------------------------------
972 Object specific Memory allocation      | \c OS_SEMAPHORE_OBJ_MEM  | Enables object specific memory allocation. See \ref ObjectMemoryPool.
973 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]}.
974
975 \subsection semaphoreConfig_obj Object-specific memory allocation
976 When Object-specific Memory is used, the pool size for all Semaphore objects is specified by \c OS_SEMAPHORE_NUM. Refer to
977 \ref ObjectMemoryPool.
978
979
980 \section memPoolConfig Memory Pool Configuration
981
982 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_PoolMgmt functions.
983
984 <b>Memory Pool Configuration Options</b>
985 \image html config_wizard_memPool.png "RTX_Config.h: Memory Pool Configuration"
986
987 Name                                   | \#define                 | Description
988 ---------------------------------------|--------------------------|----------------------------------------------------------------
989 Object specific Memory allocation      | \c OS_MEMPOOL_OBJ_MEM    | Enables object specific memory allocation. See \ref ObjectMemoryPool.
990 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]}.
991 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}.
992
993 \subsection memPoolConfig_obj Object-specific memory allocation
994 When object-specific memory is used, the number of pools for all MemoryPool objects is specified by \c OS_MEMPOOL_NUM. The
995 total storage size reserved for all pools is configured in \c OS_MEMPOOL_DATA_SIZE. Refer to \ref ObjectMemoryPool.
996
997
998 \section msgQueueConfig Message Queue Configuration
999
1000 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_Message functions.
1001
1002 <b>MessageQueue Configuration Options</b>
1003 \image html config_wizard_msgQueue.png "RTX_Config.h: Message Queue Configuration"
1004
1005 Name                                   | \#define                 | Description
1006 ---------------------------------------|--------------------------|----------------------------------------------------------------
1007 Object specific Memory allocation      | \c OS_MSGQUEUE_OBJ_MEM   | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1008 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]}.
1009 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}.
1010
1011 \subsection msgQueueConfig_obj Object-specific memory allocation
1012 When Object-specific Memory is used, the number of queues for all Message Queue objects is specified by \c OS_MSGQUEUE_NUM.
1013 The total storage size reserved for all queues is configured in \c OS_MSGQUEUE_DATA_SIZE. Refer to \ref ObjectMemoryPool.
1014 */
1015
1016
1017 /* ========================================================================================================================== */
1018 /** 
1019 \page creating_RTX5_LIB Building the RTX5 Library
1020
1021 The CMSIS Pack contains a µVision project for building the complete set of RTX5 libraries. This project can also be used as
1022 a reference for building the RTX5 libraries using a tool-chain of your choice.
1023
1024 -# Open the project \b RTX_CM.uvprojx from the pack folder <b>CMSIS/RTOS2/RTX/Library/ARM/MDK</b> in µVision.
1025 -# Select the project target that matches your device's processor core. 
1026    \n The project provides target configuration for all supported Cortex-M targets supported by RTX5.
1027 -# You can find out about the required preprocessor defines in the dialogs <b>Options for Target - C/C++</b> and
1028    <b>Options for Target - Asm</b>. Note the need to use at least the C99 compiler mode when building RTX from source.
1029 -# From the <b>Project</b> window you find the list of source files required for a complete library build.
1030 -# Build the library of your choice using \b Project - \b Build \b Target (or press F7).
1031
1032 \image html own_lib_projwin.png "Project with files for ARMv8-M Mainline"
1033 */
1034
1035
1036 /* ========================================================================================================================== */
1037 /** 
1038 \page dirstructfiles5 Directory Structure and File Overview
1039
1040 The following section provides an overview of the directory structure and the files that are relevant for the user's for
1041 CMSIS-RTOS RTX v5. The following directory references start below the CMSIS pack installation path, for example
1042 ARM/CMSIS/<i>version</i>/CMSIS/RTOS2.
1043
1044 \section Folders RTX v5 Directory Structure
1045
1046 The CMSIS-RTOS RTX v5 is delivered in source code and several examples are provided. 
1047
1048 <table class="cmtable" summary="CMSIS-RTOS RTX Library Files">
1049     <tr>
1050       <th>Directory</th>
1051       <th>Content</th>
1052     </tr>
1053     <tr>
1054       <td>Include</td>
1055       <td>The include file for CMSIS-RTOS API v2. cmsis_os2.h is the central include file for user applications.</td>
1056     </tr>
1057     <tr>
1058       <td>Template</td>
1059       <td>CMSIS-RTOS API template source and header file.</td>
1060     </tr>
1061     <tr>
1062       <td>RTX</td>
1063       <td>Directory with RTX specific files and folders. Also contains the component viewer description file.</td>
1064     </tr>
1065     <tr>
1066       <td>RTX/Config</td>
1067       <td>CMSIS-RTOS RTX configuration files %RTX_Config.h and %RTX_Config.c.</td>
1068     </tr>
1069     <tr>
1070       <td>RTX/Examples</td>
1071       <td>Example projects that can be directly used in development tools.</td>
1072     </tr>
1073     <tr>
1074       <td>RTX/Include</td>
1075       <td>RTX v5 specific include files.</td>
1076     </tr>
1077     <tr>
1078       <td>RTX/Include1</td>
1079       <td>CMSIS-RTOS v1 API header file.</td>
1080     </tr>
1081     <tr>
1082       <td>RTX/Library</td>
1083       <td>Pre-built libraries (see next table for details).</td>
1084     </tr>
1085     <tr>
1086       <td>RTX/Source</td>
1087       <td>Source code that can be used with ARMCC and GCC.</td>
1088     </tr>
1089     <tr>
1090       <td>RTX/Template</td>
1091       <td>User code templates for creating application projects with CMSIS-RTOS RTX v5.</td>
1092     </tr>
1093 </table>
1094
1095 \section libFiles RTX v5 Library Files
1096
1097 The CMSIS-RTOS RTX Library is available pre-compiled for ARMCC and GCC compilers and supports all Cortex-M
1098 processor variants in every configuration, including ARM Cortex-M23 and Cortex-M33.
1099
1100 <table class="cmtable" summary="CMSIS-RTOS RTX Library Files">
1101     <tr>
1102       <th>Library File</th>
1103       <th>Processor Configuration</th>
1104     </tr>
1105     <tr>
1106       <td>Library/ARM/RTX_CM0.lib</td>
1107       <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Cortex-M0 and M1, little-endian.</td>
1108     </tr>
1109     <tr>
1110       <td>Library/ARM/RTX_CM3.lib</td>
1111       <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Cortex-M3, M4, and M7 without FPU, little-endian.</td>
1112     </tr>
1113     <tr>
1114       <td>Library/ARM/RTX_CM4F.lib</td>
1115       <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Cortex-M4 and M7 with FPU, little-endian.</td>
1116     </tr>
1117     <tr>
1118       <td>Library/ARM/RTX_V8MB.lib</td>
1119       <td>CMSIS-RTOS RTX Library for ARMCC Compiler, ARMv8-M baseline.</td>
1120     </tr>
1121     <tr>
1122       <td>Library/ARM/RTX_V8MBN.lib</td>
1123       <td>CMSIS-RTOS RTX Library for ARMCC Compiler, ARMv8-M baseline, non-secure.</td>
1124     </tr>
1125     <tr>
1126       <td>Library/ARM/RTX_V8MM.lib</td>
1127       <td>CMSIS-RTOS RTX Library for ARMCC Compiler, ARMv8-M mainline.</td>
1128     </tr>
1129     <tr>
1130       <td>Library/ARM/RTX_V8MMF.lib</td>
1131       <td>CMSIS-RTOS RTX Library for ARMCC Compiler, ARMv8-M mainline with FPU.</td>
1132     </tr>
1133     <tr>
1134       <td>Library/ARM/RTX_V8MMFN.lib</td>
1135       <td>CMSIS-RTOS RTX Library for ARMCC Compiler, ARMv8-M mainline with FPU, non-secure.</td>
1136     </tr>
1137     <tr>
1138       <td>Library/ARM/RTX_V8MMN.lib</td>
1139       <td>CMSIS-RTOS RTX Library for ARMCC Compiler, ARMv8-M mainline, non-secure.</td>
1140     </tr>
1141     <tr>
1142       <td>Library/GCC/libRTX_CM0.a</td>
1143       <td>CMSIS-RTOS libRTX Library for GCC Compiler, Cortex-M0 and M1, little-endian.</td>
1144     </tr>
1145     <tr>
1146       <td>Library/GCC/libRTX_CM3.a</td>
1147       <td>CMSIS-RTOS libRTX Library for GCC Compiler, Cortex-M3, M4, and M7 without FPU, little-endian.</td>
1148     </tr>
1149     <tr>
1150       <td>Library/GCC/libRTX_CM4F.a</td>
1151       <td>CMSIS-RTOS libRTX Library for GCC Compiler, Cortex-M4 and M7 with FPU, little-endian.</td>
1152     </tr>
1153     <tr>
1154       <td>Library/GCC/libRTX_V8MB.a</td>
1155       <td>CMSIS-RTOS libRTX Library for GCC Compiler, ARMv8-M baseline.</td>
1156     </tr>
1157     <tr>
1158       <td>Library/GCC/libRTX_V8MBN.a</td>
1159       <td>CMSIS-RTOS libRTX Library for GCC Compiler, ARMv8-M baseline, non-secure.</td>
1160     </tr>
1161     <tr>
1162       <td>Library/GCC/libRTX_V8MM.a</td>
1163       <td>CMSIS-RTOS libRTX Library for GCC Compiler, ARMv8-M mainline.</td>
1164     </tr>
1165     <tr>
1166       <td>Library/GCC/libRTX_V8MMF.a</td>
1167       <td>CMSIS-RTOS libRTX Library for GCC Compiler, ARMv8-M mainline with FPU.</td>
1168     </tr>
1169     <tr>
1170       <td>Library/GCC/libRTX_V8MMFN.a</td>
1171       <td>CMSIS-RTOS libRTX Library for GCC Compiler, ARMv8-M mainline with FPU, non-secure.</td>
1172     </tr>
1173     <tr>
1174       <td>Library/GCC/libRTX_V8MMN.a</td>
1175       <td>CMSIS-RTOS libRTX Library for GCC Compiler, ARMv8-M mainline, non-secure.</td>
1176     </tr>
1177 </table>
1178 */
1179
1180 /* ========================================================================================================================== */
1181 /** 
1182 \page technicalData5 Technical Data
1183
1184 \section technicalData_Toolchains Supported Toolchains
1185
1186 Keil RTX5 is developed and tested using the common toolchains and development environments.
1187
1188 \subsection technicalData_Toolchain_ARM ARM Compiler (ARM/Keil MDK, uVision5)
1189
1190 Major parts of RTX5 are developed and optimized using ARM Compiler and ARM/Keil MDK.
1191 The current release is tested with the following versions:
1192 <ul>
1193  <li>ARM Compiler 5.06 Update 5 (Build 528)</li>
1194  <li>ARM Compiler 6.6.1 (Long Term Maintenance)</li>
1195  <li>ARM Compiler 6.7</li>
1196  <li>RTOS-aware debugging with uVision 5.24</li>
1197 </ul>
1198
1199 \subsection technicalData_Toolchain_IAR IAR Embedded Workbench
1200
1201 RTX5 has been ported to fully support IAR Embedded Workbench. The following releases are known to work:
1202 <ul>
1203  <li>IAR Embedded Workbench 7.7 (<a href="https://github.com/ARM-software/CMSIS_5/issues/201">community report</a>)</li>
1204  <li>IAR Embedded Workbench 7.80.4</li>
1205  <li>IAR Embedded Workbench 8.10</li>
1206 </ul>
1207
1208 \subsection technicalData_Toolchain_GCC GNU Compiler Collection
1209
1210 RTX5 has also been ported to support GCC, maintenance mainly relays on community contribution.
1211 Active development is currently tested with:
1212 <ul>
1213  <li>GCC 5.4 Release Series</li>
1214 </ul>
1215
1216 \section technicalData5_ControlBlockSizes Control Block Sizes
1217
1218 Keil RTX5 specific control block definitions (including sizes) as well as memory pool and message queue memory requirements
1219 are defined in the RTX5 header file:
1220
1221 \code
1222 /// Control Block sizes
1223 #define osRtxThreadCbSize        sizeof(osRtxThread_t)
1224 #define osRtxTimerCbSize         sizeof(osRtxTimer_t)
1225 #define osRtxEventFlagsCbSize    sizeof(osRtxEventFlags_t)
1226 #define osRtxMutexCbSize         sizeof(osRtxMutex_t)
1227 #define osRtxSemaphoreCbSize     sizeof(osRtxSemaphore_t)
1228 #define osRtxMemoryPoolCbSize    sizeof(osRtxMemoryPool_t)
1229 #define osRtxMessageQueueCbSize  sizeof(osRtxMessageQueue_t)
1230  
1231 /// Memory size in bytes for Memory Pool storage.
1232 /// \param         block_count   maximum number of memory blocks in memory pool.
1233 /// \param         block_size    memory block size in bytes.
1234 #define osRtxMemoryPoolMemSize(block_count, block_size) \
1235   (4*(block_count)*(((block_size)+3)/4))
1236  
1237 /// Memory size in bytes for Message Queue storage.
1238 /// \param         msg_count     maximum number of messages in queue.
1239 /// \param         msg_size      maximum message size in bytes.
1240 #define osRtxMessageQueueMemSize(msg_count, msg_size) \
1241   (4*(msg_count)*(3+(((msg_size)+3)/4)))
1242 \endcode
1243
1244 If you are using a \ref GlobalMemoryPool to allocate memory for the RTOS objects, you need to know the size that is required
1245 for each object in case of errors. Currently, the control block sizes are as follows (subject to change without
1246 notification):
1247
1248 Type          | Control block size in bytes |
1249 --------------|:---------------------------:|
1250 Thread        | 68                          |
1251 Timer         | 32                          |
1252 Event Flags   | 16                          |
1253 Mutex         | 28                          |
1254 Semaphore     | 16                          |
1255 Memory Pool   | 36                          |
1256 Message Queue | 52                          |
1257
1258 The size of the memory that is required for memory pool and message queue data storage can be determined from the macros
1259 stated above.
1260 */
1261
1262
1263 /* ========================================================================================================================== */
1264 /** 
1265 \page misraCompliance5 MISRA-C Compliance Exceptions
1266 CMSIS-RTOS RTX tries to be MISRA-C compliant as much as possible. However, there are some violations in order to simplify
1267 the overall code logic and to generate more efficient code.
1268
1269 This page will list the MISRA-C compliance exceptions. Work in progress.
1270 */
1271
1272 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1273 /**
1274 \page rtosValidation RTOS Validation
1275
1276 ARM offers a <a class=el href="http://www.keil.com/pack" target="_blank">Software Pack</a> for the CMSIS-RTOS Validation.
1277 The <b>ARM::CMSIS-RTOS_Validation</b> Pack contains the following:
1278
1279  - Source code of a CMSIS-RTOS Validation Suite along with configuration file.
1280  - Documentation of the CMSIS-RTOS Validation Suite.
1281  - Example that shows the usage of the CMSIS-RTOS Validation Suite using simulation.
1282
1283 \note
1284 Currently, a public version of the test suite is available only for CMSIS-RTOS v1 API.
1285
1286 The CMSIS-RTOS Validation Suite performs generic validation of various RTOS features. The test cases verify the 
1287 functional behavior, test invalid parameters and call management functions from ISR.
1288
1289 The following CMSIS-RTOS features can be tested with the current release:
1290  - Thread : Create multiple threads, terminate, restart, yield, change priority 
1291  - Timer : Create periodic and one-shot timers
1292  - GenWait : Call generic wait functions (osDelay and osWait)
1293  - WaitFunc : Measure wait ticks (delay, mail, message, mutex, semaphore, signal)
1294  
1295 Moreover the following inter-thread communication functions can be tested: 
1296  - Signal : Verify signal events
1297  - Memory Pool : Verify memory allocation
1298  - Message Queue : Exchange messages between threads
1299  - Mail Queue : Exchange data between threads
1300  - Mutex : Synchronize resource access 
1301  - Semaphore : Access shared resources 
1302  
1303 The RTOS Validation output can be printed to a console, output via ITM printf, or output to a memory buffer.
1304  
1305 \section test_output Sample Test Output
1306 \verbatim
1307 CMSIS-RTOS Test Suite   Oct 21 2015   16:39:16 
1308
1309 TEST 01: TC_ThreadCreate                  PASSED
1310 TEST 02: TC_ThreadMultiInstance           PASSED
1311 TEST 03: TC_ThreadTerminate               PASSED
1312   :
1313   :
1314 TEST 08: TC_ThreadChainedCreate           PASSED
1315 TEST 09: TC_ThreadYield                   NOT EXECUTED
1316 TEST 10: TC_ThreadParam                   PASSED
1317   :
1318   :
1319 TEST 60: TC_MailFromISRToThread           PASSED
1320
1321 Test Summary: 60 Tests, 59 Executed, 59 Passed, 0 Failed, 0 Warnings.
1322 Test Result: PASSED
1323 \endverbatim
1324 */
1325
1326
1327 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1328 /**
1329 \page functionOverview Function Overview
1330
1331 CMSIS-RTOS v2 provides multiple API interfaces:
1332   - \subpage rtos_api2 is the new C function API that supports dynamic object creation and ARMv8-M (ARM Cortex-M23 and
1333     Cortex-M33).
1334   - <a class="el" href="../../RTOS/html/functionOverview.html">CMSIS-RTOS C API v1</a> is a C function API that is backward
1335     compatible with CMSIS-RTOS v1.
1336   - \subpage rtos_apicpp is a C++ class function API.
1337
1338 It is possible to intermix the different API variants in the same application and even in the same C/C++ source module.
1339 However, the functions of the <b>C API Version 1</b> may be deprecated in future versions of CMSIS-RTOS.
1340
1341 \section rtos_api2 CMSIS-RTOS2
1342
1343 Overview of all CMSIS-RTOS C API v2 functions that are implemented in the \subpage cmsis_os2_h. 
1344
1345  - \ref CMSIS_RTOS_KernelCtrl
1346    - \ref osKernelGetInfo : \copybrief osKernelGetInfo
1347    - \ref osKernelGetState : \copybrief osKernelGetState
1348    - \ref osKernelGetSysTimerCount : \copybrief osKernelGetSysTimerCount
1349    - \ref osKernelGetSysTimerFreq : \copybrief osKernelGetSysTimerFreq
1350    - \ref osKernelInitialize : \copybrief osKernelInitialize
1351    - \ref osKernelLock : \copybrief osKernelLock
1352    - \ref osKernelUnlock : \copybrief osKernelUnlock
1353    - \ref osKernelRestoreLock : \copybrief osKernelRestoreLock
1354    - \ref osKernelResume : \copybrief osKernelResume
1355    - \ref osKernelStart : \copybrief osKernelStart
1356    - \ref osKernelSuspend : \copybrief osKernelSuspend
1357    - \ref osKernelGetTickCount : \copybrief osKernelGetTickCount
1358    - \ref osKernelGetTickFreq : \copybrief osKernelGetTickFreq
1359
1360  - \ref CMSIS_RTOS_ThreadMgmt
1361    - \ref osThreadDetach : \copybrief osThreadDetach
1362    - \ref osThreadEnumerate : \copybrief osThreadEnumerate
1363    - \ref osThreadExit : \copybrief osThreadExit
1364    - \ref osThreadGetCount : \copybrief osThreadGetCount
1365    - \ref osThreadGetId : \copybrief osThreadGetId
1366    - \ref osThreadGetName : \copybrief osThreadGetName
1367    - \ref osThreadGetPriority : \copybrief osThreadGetPriority
1368    - \ref osThreadGetStackSize : \copybrief osThreadGetStackSize
1369    - \ref osThreadGetStackSpace : \copybrief osThreadGetStackSpace
1370    - \ref osThreadGetState : \copybrief osThreadGetState
1371    - \ref osThreadJoin : \copybrief osThreadJoin
1372    - \ref osThreadNew : \copybrief osThreadNew
1373    - \ref osThreadResume : \copybrief osThreadResume
1374    - \ref osThreadSetPriority : \copybrief osThreadSetPriority
1375    - \ref osThreadSuspend : \copybrief osThreadSuspend
1376    - \ref osThreadTerminate : \copybrief osThreadTerminate
1377    - \ref osThreadYield : \copybrief osThreadYield
1378
1379  - \ref CMSIS_RTOS_ThreadFlagsMgmt
1380    - \ref osThreadFlagsSet : \copybrief osThreadFlagsSet
1381    - \ref osThreadFlagsClear : \copybrief osThreadFlagsClear
1382    - \ref osThreadFlagsGet : \copybrief osThreadFlagsGet
1383    - \ref osThreadFlagsWait : \copybrief osThreadFlagsWait
1384
1385  - \ref CMSIS_RTOS_EventFlags
1386    - \ref osEventFlagsGetName : \copybrief osEventFlagsGetName
1387    - \ref osEventFlagsNew : \copybrief osEventFlagsNew
1388    - \ref osEventFlagsDelete : \copybrief osEventFlagsDelete
1389    - \ref osEventFlagsSet : \copybrief osEventFlagsSet
1390    - \ref osEventFlagsClear : \copybrief osEventFlagsClear
1391    - \ref osEventFlagsGet : \copybrief osEventFlagsGet
1392    - \ref osEventFlagsWait : \copybrief osEventFlagsWait
1393
1394  - \ref CMSIS_RTOS_Wait
1395    - \ref osDelay : \copybrief osDelay
1396    - \ref osDelayUntil : \copybrief osDelayUntil
1397
1398  - \ref CMSIS_RTOS_TimerMgmt
1399    - \ref osTimerDelete : \copybrief osTimerDelete
1400    - \ref osTimerGetName : \copybrief osTimerGetName
1401    - \ref osTimerIsRunning : \copybrief osTimerIsRunning
1402    - \ref osTimerNew : \copybrief osTimerNew
1403    - \ref osTimerStart : \copybrief osTimerStart
1404    - \ref osTimerStop : \copybrief osTimerStop
1405
1406  - \ref CMSIS_RTOS_MutexMgmt
1407    - \ref osMutexAcquire : \copybrief osMutexAcquire
1408    - \ref osMutexDelete : \copybrief osMutexDelete
1409    - \ref osMutexGetName : \copybrief osMutexGetName
1410    - \ref osMutexGetOwner : \copybrief osMutexGetOwner
1411    - \ref osMutexNew : \copybrief osMutexNew
1412    - \ref osMutexRelease : \copybrief osMutexRelease
1413
1414  - \ref CMSIS_RTOS_SemaphoreMgmt
1415    - \ref osSemaphoreAcquire : \copybrief osSemaphoreAcquire
1416    - \ref osSemaphoreDelete : \copybrief osSemaphoreDelete
1417    - \ref osSemaphoreGetCount : \copybrief osSemaphoreGetCount
1418    - \ref osSemaphoreGetName : \copybrief osSemaphoreGetName
1419    - \ref osSemaphoreNew : \copybrief osSemaphoreNew
1420    - \ref osSemaphoreRelease : \copybrief osSemaphoreRelease
1421
1422  - \ref CMSIS_RTOS_PoolMgmt
1423    - \ref osMemoryPoolAlloc : \copybrief osMemoryPoolAlloc
1424    - \ref osMemoryPoolDelete : \copybrief osMemoryPoolDelete
1425    - \ref osMemoryPoolFree : \copybrief osMemoryPoolFree
1426    - \ref osMemoryPoolGetBlockSize : \copybrief osMemoryPoolGetBlockSize
1427    - \ref osMemoryPoolGetCapacity : \copybrief osMemoryPoolGetCapacity
1428    - \ref osMemoryPoolGetCount : \copybrief osMemoryPoolGetCount
1429    - \ref osMemoryPoolGetName : \copybrief osMemoryPoolGetName
1430    - \ref osMemoryPoolGetSpace : \copybrief osMemoryPoolGetSpace
1431    - \ref osMemoryPoolNew : \copybrief osMemoryPoolNew
1432
1433  - \ref CMSIS_RTOS_Message
1434    - \ref osMessageQueueDelete : \copybrief osMessageQueueDelete
1435    - \ref osMessageQueueGet : \copybrief osMessageQueueGet
1436    - \ref osMessageQueueGetCapacity : \copybrief osMessageQueueGetCapacity
1437    - \ref osMessageQueueGetCount : \copybrief osMessageQueueGetCount
1438    - \ref osMessageQueueGetMsgSize : \copybrief osMessageQueueGetMsgSize
1439    - \ref osMessageQueueGetName : \copybrief osMessageQueueGetName
1440    - \ref osMessageQueueGetSpace : \copybrief osMessageQueueGetSpace
1441    - \ref osMessageQueueNew : \copybrief osMessageQueueNew
1442    - \ref osMessageQueuePut : \copybrief osMessageQueuePut
1443    - \ref osMessageQueueReset : \copybrief osMessageQueueReset
1444  
1445  - \ref CMSIS_RTOS_TickAPI
1446    - \ref OS_Tick_Setup : \copybrief OS_Tick_Setup
1447    - \ref OS_Tick_Enable : \copybrief OS_Tick_Enable
1448    - \ref OS_Tick_Disable : \copybrief OS_Tick_Disable
1449    - \ref OS_Tick_AcknowledgeIRQ : \copybrief OS_Tick_AcknowledgeIRQ
1450    - \ref OS_Tick_GetIRQn : \copybrief OS_Tick_GetIRQn
1451    - \ref OS_Tick_GetClock : \copybrief OS_Tick_GetClock
1452    - \ref OS_Tick_GetInterval : \copybrief OS_Tick_GetInterval
1453    - \ref OS_Tick_GetCount : \copybrief OS_Tick_GetCount
1454    - \ref OS_Tick_GetOverflow : \copybrief OS_Tick_GetOverflow
1455
1456  - \ref rtx5_specific
1457    - \ref osRtxErrorNotify : \copybrief osRtxErrorNotify
1458    - \ref osRtxIdleThread : \copybrief osRtxIdleThread
1459
1460 The following CMSIS-RTOS2 functions can be called from threads and \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines"
1461 (ISR):
1462    - \ref osKernelGetTickCount, \ref osKernelGetTickFreq, \ref osKernelGetSysTimerCount, \ref osKernelGetSysTimerFreq
1463    - \ref osThreadFlagsSet
1464    - \ref osEventFlagsSet, \ref osEventFlagsClear, \ref osEventFlagsGet, \ref osEventFlagsWait
1465    - \ref osSemaphoreAcquire, \ref osSemaphoreRelease, \ref osSemaphoreGetCount
1466    - \ref osMemoryPoolAlloc, \ref osMemoryPoolFree, \ref osMemoryPoolGetCapacity, \ref osMemoryPoolGetBlockSize,
1467      \ref osMemoryPoolGetCount, \ref osMemoryPoolGetSpace
1468    - \ref osMessageQueuePut, \ref osMessageQueueGet, \ref osMessageQueueGetCapacity, \ref osMessageQueueGetMsgSize,
1469      \ref osMessageQueueGetCount, \ref osMessageQueueGetSpace
1470 */
1471
1472
1473 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1474 /**
1475 \page rtos_apicpp CMSIS-RTOS C++ API
1476
1477 A C++11/C++14 interface is planned for the future.
1478 */
1479
1480
1481 /* ======================================================================================================================== */
1482 // Group creation for Reference 
1483 /* 
1484 \addtogroup CMSIS_RTOS1 CMSIS-RTOS API v1
1485 \brief This section describes the CMSIS-RTOS API v1. 
1486 \details 
1487 The CMSIS-RTOS is a generic API layer that interfaces to an existing RTOS kernel.
1488
1489 CMSIS-RTOS API v2 provides an translation layer for the
1490 <a class="el" href="../../RTOS/html/index.html">CMSIS-RTOS API v1</a> that simplifies migration.
1491
1492 Refer to the <a class="el" href="../../RTOS/html/modules.html">Reference</a> guide of the CMSIS-RTOS API v1 for details.
1493 */
1494
1495 // Group creation for Reference 
1496 /** 
1497 \addtogroup CMSIS_RTOS CMSIS-RTOS2 API
1498 \brief Describes the C function interface of CMSIS-RTOS API v2. 
1499 \details 
1500 The CMSIS-RTOS2 is a generic API layer that interfaces to an RTOS kernel.
1501
1502 The complete API interface is defined in the \ref cmsis_os2_h. When using dynamic memory allocation for objects, source code
1503 or libraries require no modifications when using on a different CMSIS-RTOS2 implementation.
1504 */
1505
1506 /** 
1507 \addtogroup rtx5_specific RTX5 Specific API
1508 \brief This section describes CMSIS-RTOS RTX5 specifics.
1509 \details
1510 The RTX5 kernel can be customized for different application requirements:
1511 - If you are depending on the \ref lowPower "lowest power consumption" possible, you need to adapt the function
1512   \ref osRtxIdleThread to send the system to sleep mode as often as possible. In addition, use the
1513   \ref TickLess "tick-less low power" functions \ref osKernelSuspend and \ref osKernelResume to suspend the scheduler and to
1514   stop the SysTick timer.
1515 - If you try to find a \b runtime \b error, use the function \ref osRtxErrorNotify to debug the error.
1516
1517 RTX5 interfaces to the <a href="http://www.keil.com/pack/doc/compiler/EventRecorder/html/index.html" target="_blank"><b>Event Recorder</b></a> 
1518 to provide event information which helps you to understand and analyze the operation. Refer to \ref rtx_evr for more
1519 information.
1520
1521
1522 @{
1523 */
1524
1525 /**
1526 \defgroup rtx5_specific_defines Macros
1527 \brief RTX5 macros
1528 \details
1529 @{
1530 */
1531
1532 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1533 /**
1534 \def osRtxThreadCbSize
1535 */
1536
1537 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1538 /**
1539 \def osRtxTimerCbSize       
1540 */
1541
1542 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1543 /**
1544 \def osRtxEventFlagsCbSize  
1545 */
1546
1547 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1548 /**
1549 \def osRtxMutexCbSize       
1550 */
1551
1552 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1553 /**
1554 \def osRtxSemaphoreCbSize   
1555 */
1556
1557 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1558 /**
1559 \def osRtxMemoryPoolCbSize  
1560 */
1561
1562 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1563 /**
1564 \def osRtxMessageQueueCbSize
1565 */
1566
1567 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1568 /**
1569 \def osRtxMemoryPoolMemSize
1570 */
1571
1572 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1573 /**
1574 \def osRtxMessageQueueMemSize
1575 */
1576
1577 /**
1578 @}
1579 */
1580
1581 /**
1582 \defgroup rtx5_specific_structs Structs
1583 \brief RTX5 structs 
1584 \details
1585 @{
1586 */
1587
1588 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1589 /**
1590 \struct osRtxThread_t
1591 */
1592
1593 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1594 /**
1595 \struct osRtxTimerFinfo_t
1596 */
1597
1598 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1599 /**
1600 \struct osRtxTimer_t
1601 */
1602
1603 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1604 /**
1605 \struct osRtxEventFlags_t
1606 */
1607
1608 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1609 /**
1610 \struct osRtxMutex_t
1611 */
1612
1613 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1614 /**
1615 \struct osRtxSemaphore_t
1616 */
1617
1618 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1619 /**
1620 \struct osRtxMemoryPool_t
1621 */
1622
1623 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1624 /**
1625 \struct osRtxMessageQueue_t
1626 */
1627
1628 /**
1629 @}
1630 */
1631
1632 /**
1633 \defgroup rtx5_specific_functions Functions
1634 \brief RTX5 functions 
1635 \details
1636 @{
1637 */
1638
1639 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1640 /** 
1641 \fn uint32_t osRtxErrorNotify (uint32_t code, void *object_id);
1642 \details
1643 Some system error conditions can be detected during runtime. If the RTX kernel detects a runtime error, it calls the runtime
1644 error function \b osRtxErrorNotify for an object specified by parameter \a object_id.
1645
1646 The parameter \a code passes the actual error code to this function:
1647 | Error Code                   | Description                                                                       |
1648 |------------------------------|-----------------------------------------------------------------------------------|
1649 | osRtxErrorStackUnderflow     | Stack underflow detected for thread (thread_id=object_id)                         |
1650 | osRtxErrorISRQueueOverflow   | ISR Queue overflow detected when inserting object (object_id)                     |
1651 | osRtxErrorTimerQueueOverflow | User Timer Callback Queue overflow detected for timer (timer_id=object_id)        |
1652 | osRtxErrorClibSpace          | Standard C/C++ library libspace not available: increase \c OS_THREAD_LIBSPACE_NUM |
1653 | osRtxErrorClibMutex          | Standard C/C++ library mutex initialization failed                                |
1654
1655 The function \b osRtxErrorNotify must contain an infinite loop to prevent further program execution. You can use an emulator
1656 to step over the infinite loop and trace into the code introducing a runtime error. For the overflow errors this means you
1657 need to increase the size of the object causing an overflow.
1658
1659 \note Cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
1660
1661 <b>Code Example</b>
1662 \code
1663 #include "rtx_os.h"
1664  
1665 uint32_t osRtxErrorNotify (uint32_t code, void *object_id) {
1666   (void)object_id;
1667  
1668   switch (code) {
1669     case osRtxErrorStackUnderflow:
1670       // Stack underflow detected for thread (thread_id=object_id)
1671       break;
1672     case osRtxErrorISRQueueOverflow:
1673       // ISR Queue overflow detected when inserting object (object_id)
1674       break;
1675     case osRtxErrorTimerQueueOverflow:
1676       // User Timer Callback Queue overflow detected for timer (timer_id=object_id)
1677       break;
1678     case osRtxErrorClibSpace:
1679       // Standard C/C++ library libspace not available: increase OS_THREAD_LIBSPACE_NUM
1680       break;
1681     case osRtxErrorClibMutex:
1682       // Standard C/C++ library mutex initialization failed
1683       break;
1684     default:
1685       break;
1686   }
1687   for (;;) {}
1688 //return 0U;
1689 }
1690 \endcode
1691 */
1692
1693 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1694 osRtxErrorClibMutex         /** 
1695 \fn void osRtxIdleThread (void *argument);
1696 \details
1697 The function \b osRtxIdleThread is executed by the RTX kernel, when no other threads are ready to run. By default, this
1698 thread is an empty end-less loop that does nothing. It only waits until another task becomes ready to run. You may change the
1699 code of the \b osRtxIdleThread function to put the CPU into a power-saving or idle mode, see \ref TickLess.
1700
1701 The default stack size for this thread is defined in the file RTX_Config.h. Refer to \ref threadConfig.
1702
1703 \note Cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
1704
1705 <b>Code Example</b>
1706 \code
1707 #include "rtx_os.h"
1708  
1709 __NO_RETURN void osRtxIdleThread (void *argument) {
1710   (void)argument;
1711
1712   for (;;) {}
1713 }
1714 \endcode
1715 */ 
1716
1717 /**
1718 @}
1719 */
1720
1721 /// @}