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