]> begriffs open source - cmsis/blob - CMSIS/DoxyGen/RTOS2/src/cmsis_os2.txt
RTX5: fixed optimization issue when using GCC optimization level 3
[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.2</td>
82       <td>
83         Additional functions allowed to be called from Interrupt Service Routines:
84          - \ref osKernelGetInfo, \ref osKernelGetState
85      </td>
86     </tr>
87     <tr>
88       <td>V2.1.1</td>
89       <td>
90         Additional functions allowed to be called from Interrupt Service Routines:
91          - \ref osKernelGetTickCount, \ref osKernelGetTickFreq
92          
93         Changed Kernel Tick type to uint32_t:
94          - updated: \ref osKernelGetTickCount, \ref osDelayUntil
95      </td>
96     </tr>
97     <tr>
98       <td>V2.1.0</td>
99       <td>
100         Support for critical and uncritical sections (nesting safe):
101          - updated: \ref osKernelLock, \ref osKernelUnlock
102          - added: \ref osKernelRestoreLock
103          
104         Updated \ref CMSIS_RTOS_ThreadFlagsMgmt "Thread Flags" and \ref CMSIS_RTOS_EventFlags "Event Flags":
105          - changed flags parameter and return type from int32_t to uint32_t
106      </td>
107     </tr>
108     <tr>
109       <td>V2.0.0</td>
110       <td>
111         New API Version 2.0 available. 
112          - See \ref rtos_api2 for a detailed function reference.
113          - See \ref os2Migration for details on the migration process from API Version 1.
114      </td>
115     </tr>
116     <tr>
117       <td>V1.02 - only documentation changes</td>
118       <td>
119       Added: Overview of the \ref rtosValidation "CMSIS-RTOS Validation" Software Pack.\n
120       Clarified: Behavior of \ref CMSIS_RTOS_TimeOutValue.
121      </td>
122     </tr>
123     <tr>
124       <td>V1.02</td>
125       <td>Added: New control functions for short timeouts in microsecond resolution \b osKernelSysTick,
126       \b osKernelSysTickFrequency, \b osKernelSysTickMicroSec.\n
127       Removed: osSignalGet.
128      </td>
129     </tr>fv
130     <tr>
131       <td>V1.01</td>
132       <td>Added capabilities for C++, kernel initialization and object deletion.\n
133       Prepared for C++ class interface. In this context to \em const attribute has been moved from osXxxxDef_t typedefs to
134       the osXxxxDef macros.\n
135       Added: \ref osTimerDelete, \ref osMutexDelete, \ref osSemaphoreDelete.\n
136       Added: \ref osKernelInitialize that prepares the kernel for object creation.\n
137       </td>
138     </tr>
139     <tr>
140       <td>
141       V1.00</td>
142       <td>First official Release.\n
143       Added: \ref osKernelStart; starting 'main' as a thread is now an optional feature.\n
144       Semaphores have now the standard behavior.\n
145       \b osTimerCreate does no longer start the timer. Added: \ref osTimerStart (replaces osTimerRestart).\n
146       Changed: osThreadPass is renamed to \ref osThreadYield.
147       </td>
148     </tr>
149     <tr>
150       <td>V0.02</td>
151       <td>Preview Release.</td>
152     </tr>
153 </table>
154
155
156 \section RTX5RevisionHistory CMSIS-RTOS RTX Version 5
157
158 <table class="cmtable" summary="Revision History">
159     <tr>
160       <th>Version</th>
161       <th>Description</th>
162     </tr>
163     <tr>
164       <td>V5.3.1</td>
165       <td>
166        - Fixed optimization issue when using GCC optimization level 3.
167       </td>
168     </tr>
169     <tr>
170       <td>V5.3.0</td>
171       <td>
172        - Added Object Memory usage counters.
173        - Added support for additional external configuration file.
174        - Added user configurable names for system threads (Idle and Timer).
175        - Added support for OS sections when using ARMCC5.
176        - Added callback for MPU integration (experimental)
177        - Increased default thread stack sizes to 256 bytes.
178        - Fixed stack context display for running thread in SCVD.
179        - Enhanced MISRA Compliance.
180       </td>
181     </tr>
182     <tr>
183       <td>V5.2.3</td>
184       <td>
185        - Based on CMSIS-RTOS API V2.1.2.
186        - Added TrustZone Module Identifier configuration for Idle and Timer Thread.
187        - Moved SVC/PendSV handler priority setup from osKernelInitialize to osKernelStart (User Priority Grouping can be updated after osKernelInitialize but before osKernelStart).
188        - Corrected SysTick and PendSV handlers for ARMv8-M Baseline.
189        - Corrected memory allocation for stack and data when "Object specific Memory allocation" configuration is used.
190        - Added support for ARMv8-M IAR compiler.
191       </td>
192     </tr>
193     <tr>
194       <td>V5.2.2</td>
195       <td>
196        - Corrected IRQ and SVC exception handlers for Cortex-A.
197       </td>
198     </tr>
199     <tr>
200       <td>V5.2.1</td>
201       <td>
202        - Corrected SysTick and SVC Interrupt Priority for Cortex-M.
203       </td>
204     </tr>
205     <tr>
206       <td>V5.2.0</td>
207       <td>
208        - Based on CMSIS-RTOS API V2.1.1.
209        - Added support for for Cortex-A.
210        - Using OS Tick API for RTX Kernel Timer Tick.
211        - Fixed potential corruption of terminated threads list.
212        - Corrected MessageQueue to use actual message length (before padding).
213        - Corrected parameters for ThreadEnumerate and MessageQueueInserted events.
214        - Timer Thread creation moved to osKernelStart.
215       </td>
216     </tr>
217     <tr>
218       <td>V5.1.0</td>
219       <td>
220        - Based on CMSIS-RTOS API V2.1.0.
221        - Added support for Event recording.
222        - Added support for IAR compiler.
223        - Updated configuration files: RTX_Config.h for the configuration settings and RTX_config.c for implementing the \ref rtx5_specific.
224        - osRtx name-space for RTX specific symbols.
225       </td>
226     </tr>
227     <tr>
228       <td>V5.0.0</td>
229       <td>
230        Initial release compliant to CMSIS-RTOS2.\n
231       </td>
232     </tr>
233 </table>
234 */
235
236
237 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
238 /**
239 \page genRTOS2IF Generic RTOS Interface
240
241 CMSIS-RTOS2 is a generic API that is agnostic of the underlying RTOS kernel. Application programmers call CMSIS-RTOS2 API
242 functions in the user code to ensure maximum portability from one RTOS to another. Middleware using CMSIS-RTOS2 API takes
243 advantages of this approach by avoiding unnecessary porting efforts.
244
245 \image html "API_Structure.png" "CMSIS-RTOS API Structure"
246
247 A typical CMSIS-RTOS2 API implementation interfaces to an existing real-time kernel. The CMSIS-RTOS2 API provides the
248 following attributes and functionalities:
249  - Function names, identifiers, and parameters are descriptive and easy to understand. The functions are powerful and
250    flexible which reduces the number of functions exposed to the user. 
251  - \ref CMSIS_RTOS_ThreadMgmt allows you to define, create, and control threads.
252  - Interrupt Service Routines (ISR) can \ref CMSIS_RTOS_ISR_Calls "call some CMSIS-RTOS functions". When a CMSIS-RTOS
253    function cannot be called from an ISR context, it rejects the invocation and returns an error code.
254  - Three different event types support communication between multiple threads and/or ISR:
255    - \ref CMSIS_RTOS_ThreadFlagsMgmt "Thread Flags": may be used to indicate specific conditions to a thread.
256    - \ref CMSIS_RTOS_EventFlags "Event Flags": may be used to indicate events to a thread or ISR.
257    - \ref CMSIS_RTOS_Message "Messages": can be sent to a thread or an ISR. Messages are buffered in a queue.
258  - \ref CMSIS_RTOS_MutexMgmt and \ref CMSIS_RTOS_SemaphoreMgmt are incorporated.
259  - CPU time can be scheduled with the following functionalities:
260    - A \a timeout parameter is incorporated in many CMSIS-RTOS functions to avoid system lockup. When a timeout is specified,
261      the system waits until a resource is available or an event occurs. While waiting, other threads are scheduled.
262    - The \ref osDelay and \ref osDelayUntil functions put a thread into the \b WAITING state for a specified period of time.
263    - The \ref osThreadYield provides co-operative thread switching and passes execution to another thread of the same
264      priority.
265  - \ref CMSIS_RTOS_TimerMgmt  functions are used to trigger the execution of functions.
266
267 The CMSIS-RTOS2 API is designed to optionally incorporate multi-processor systems and/or access protection via the Cortex-M
268 Memory Protection Unit (MPU).
269
270 In some RTOS implementations threads may execute on different processors, thus \b message queues may reside in shared memory
271 resources.
272
273 The CMSIS-RTOS2 API encourages the software industry to evolve existing RTOS implementations. RTOS implementations can be
274 different and optimized in various aspects towards the Cortex-M processors. Optional features may be for example
275  - Support of the Cortex-M Memory Protection Unit (MPU).
276  - Support of multi-processor systems.
277  - Support of a DMA controller.
278  - Deterministic context switching.
279  - Round-robin context switching.
280  - Deadlock avoidance, for example with priority inversion.
281  - Zero interrupt latency by using Armv7-M instructions LDREX and STREX.
282  
283 \section usingOS2 Using a CMSIS-RTOS2 Implementation
284
285 A CMSIS-RTOS2 implementation is typically provided as a library. To add the RTOS functionality to an existing CMSIS-based
286 application, the RTOS library (and typically one or more configuration files) needs to be added. There is a single new header
287 file %cmsis_os2.h available. This is the only header file required for a completely portable application. In such a case,
288 user provided memory for control blocks, objects data and thread stack cannot be used. Alternatively, you can include an
289 implementation specific header file (for example rtx_os.h) which provides definitions also for resource allocation (such as
290 size of control blocks, required memory for object data and thread stack). This is optional and implies that the application
291 code is not completely portable.
292
293 \image html "CMSIS_RTOS_Files.png" "CMSIS-RTOS File Structure"
294
295 Once the files are added to a project, the user can start working with the CMSIS-RTOS functions.  A code example is provided
296 below:
297  
298 <b>Code Example</b>
299 \code
300 /*----------------------------------------------------------------------------
301  * CMSIS-RTOS 'main' function template
302  *---------------------------------------------------------------------------*/
303  
304 #include "RTE_Components.h"
305 #include  CMSIS_device_header
306 #include "cmsis_os2.h"
307  
308 /*----------------------------------------------------------------------------
309  * Application main thread
310  *---------------------------------------------------------------------------*/
311 void app_main (void *argument) {
312  
313   // ...
314   for (;;) {}
315 }
316  
317 int main (void) {
318  
319   // System Initialization
320   SystemCoreClockUpdate();
321 #ifdef RTE_Compiler_EventRecorder
322   // Initialize and start Event Recorder
323   EventRecorderInitialize(EventRecordError, 1U);
324 #endif
325   // ...
326  
327   osKernelInitialize();                 // Initialize CMSIS-RTOS
328   osThreadNew(app_main, NULL, NULL);    // Create application main thread
329   osKernelStart();                      // Start thread execution
330   for (;;) {}
331 }
332 \endcode
333
334
335 \section cmsis_os2_h cmsis_os2.h header file
336
337 The file \b cmsis_os2.h is a standard header file that interfaces to every CMSIS-RTOS2 compliant real-time operating
338 systems (RTOS). Each implementation is provided the same \b cmsis_os2.h which defines the interface to the \ref rtos_api2.
339
340 Using the \b cmsis_os2.h along with dynamic object allocation allows to create source code or libraries that require no
341 modifications when using on a different CMSIS-RTOS2 implementation.
342
343 <b>Header file %cmsis_os2.h</b>
344
345 \include cmsis_os2.h
346 */
347
348
349 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
350 /**
351 \page rtx5_impl RTX v5 Implementation
352
353 Keil RTX version 5 (RTX5) implements the CMSIS-RTOS2 as a native RTOS interface for Arm Cortex-M processor-based devices.
354 A translation layer to CMSIS-RTOS API v1 is provided. Therefore, RTX5 can be used in applications that where previously based
355 on RTX version 4 and CMSIS-RTOS version 1 with minimal effort.
356
357 The following sections provide further details:
358  - \subpage cre_rtx_proj explains how to setup an RTX v5 project in Keil MDK.
359  - \subpage theory_of_operation provides general information about the operation of CMSIS-RTOS RTX v5.
360  - \subpage config_rtx5 describes configuration parameters of CMSIS-RTOS RTX v5.
361  - \subpage creating_RTX5_LIB explains how to build your own CMSIS-RTOS RTX v5 library.
362  - \subpage dirstructfiles5 explains the directories and files that are supplied as part of CMSIS-RTOS RTX v5.
363  - \subpage technicalData5 lists microcontroller hardware requirements and limitations such as number of concurrent threads.
364  - \subpage misraCompliance5 describes the violations to the MISRA standard.
365 */
366
367 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
368 /**
369 \page cre_rtx_proj Create an RTX5 Project
370
371 The steps to create a microcontroller application using RTX5 are:
372 - Create a new project and select a microcontroller device.
373 - In the Manage Run-Time Environment window, select <b>CMSIS\::CORE</b> and <b>CMSIS\::RTOS2 (API)\::Keil RTX5</b>. You can
374   choose to either add RTX as a library (Variant: \b Library) or to add the full source code (Variant: \b Source - required
375   if using the <a href="http://www.keil.com/pack/doc/compiler/EventRecorder/html/index.html" target="_blank"><b>Event Recorder</b></a>):
376
377    \image html manage_rte_output.png
378
379 - If the <b>Validation Output</b> requires other components to be present, try to use the \b Resolve button.
380 - Click \b OK. In the \b Project window, you will see the files that have been automatically added to you project, such as
381   \b %RTX_Config.h, \b %RTX_Config.c, the library or the source code files, as well as the system and startup files:
382
383    \image html project_window.png
384
385 - 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).   
386 - You can add template files to the project by right-clicking on <b>Source Group 1</b> and selecting
387   <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
388   you will see all available template files for CMSIS-RTOS RTX:
389   
390    \image html add_item.png
391
392 - \ref config_rtx5 "Configure" RTX5 to the application's needs using the \b %RTX_Config.h file.
393
394 \section cre_rtx_cortexa Additional requirements for RTX on Cortex-A
395
396 Cortex-A based microcontrollers are less unified with respect to the interrupt and timer implementations used compared to 
397 M-class devices. Thus RTX requires additional components when an A-class device is used, namely
398 <a href="../../Core_A/html/group__irq__ctrl__gr.html"><b>IRQ Controller (API)</b></a> and \ref CMSIS_RTOS_TickAPI "OS Tick (API)"
399 implementations. 
400
401 \image html manage_rte_cortex-a.png
402
403 The default implementations provided along with CMSIS are 
404 - Arm <a href="../../Core_A/html/group__GIC__functions.html">Generic Interrupt Controller (GIC)</a>
405 - Arm Cortex-A5, Cortex-A9 <a href="../../Core_A/html/group__PTM__timer__functions.html">Private Timer (PTIM)</a>
406 - Arm Cortex-A7 <a href="../../Core_A/html/group__PL1__timer__functions.html">Generic Physical Timer (GTIM)</a>
407
408 For devices not implementing GIC, PTIM nor GTIM please refer to the according device family pack and select the
409 proper implementations.
410
411 \section cre_rtx_proj_specifics Add support for RTX specific functions
412 If you require some of the \ref rtx5_specific "RTX specific functions" in your application code, \#include the
413 \ref rtx_os_h "header file rtx_os.h". This enables \ref lowPower "low-power" and \ref TickLess "tick-less" operation modes.
414
415 \section cre_rtx_proj_er Add Event Recorder Visibility
416 - To use the Event Recorder together with RTX5, select the software component <b>Compiler:Event Recorder</b>.
417 - Select the \b Source variant of the software component <b>CMSIS:RTOS2 (API):Keil RTX5</b>.
418   \image html event_recorder_rte.png "Component selection for Event Recorder"
419 - Call the function <b>EventRecorderInitialize()</b> in your application code (ideally in \c main()).
420 - Build the application code and download it to the debug hardware.
421   
422 Once the target application generates event information, it can be viewed in the µVision debugger using the \b Event
423  \b Recorder.
424  */
425
426
427 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
428 /**
429 \page theory_of_operation Theory of Operation
430
431 Many aspects of the kernel are configurable and the configuration options are mentioned where applicable.
432
433 \section SystemStartup System Startup
434
435 Since main is no longer a thread RTX5 does not interfere with the system startup until main is reached.
436 Once the execution reaches \c main() there is a recommended order to initialize the hardware and start the kernel. This is
437 also reflected in the user code template file "CMSIS-RTOS2 'main' function" supplied with the RTX5 component.
438
439 Your application's \c main() should implement at least the following in the given order:
440 -# Initialization and configuration of hardware including peripherals, memory, pins, clocks and the interrupt system.
441 -# Update the system core clock using the respective
442    <a href=../../Core/html/group__system__init__gr.html>CMSIS-Core (Cortex-M)</a> or 
443    <a href=../../Core_A/html/group__system__init__gr.html>CMSIS-Core (Cortex-A)</a> function.
444 -# Initialize the CMSIS-RTOS kernel using \ref osKernelInitialize.
445 -# Optionally, create a new thread \c app_main, which is used as a main thread using \ref osThreadNew. Alternatively, threads
446    can be created in \c main() directly.
447 -# Start the RTOS scheduler using \ref osKernelStart. This function does not return in case of successful execution. Any
448    application code after \b osKernelStart will not be executed unless \b osKernelStart fails.
449
450 \note Interrupts (like SVC for example) used by the kernel are initialized in \ref osKernelInitialize. In case priorities and
451 groupings in the NVIC are altered by the application after the above sequence it might be necessary to call
452 \ref osKernelInitialize again. You might observe weird misbehaviour possibly catched by \ref osRtxErrorNotify or causing a hard fault.
453
454 \note The tick timer is configured during \ref osKernelStart. The tick interval is calculated based on the \c SystemCoreClock variable.
455
456 \section Scheduler 
457
458 RTX5 implements a low-latency preemtive scheduler. Major parts of RTX5 are executed in handler mode such as
459   - \ref SysTick_Handler used for time-based scheduling.
460   - \ref SVC_Handler used for lock-based scheduling.
461   - \ref PendSV_Handler used for interrupt-based scheduling.
462
463 In order to be low-latency with respect to ISR execution those system exceptions are configured to use the
464 lowest priority groups available. The priorities are configured such that no preemption happens between them. Thus
465 no interrupt critical sections (i.e. interrupt locks) are needed to protect the scheduler.
466
467 \image html scheduling.png "Thread scheduling and interrupt execution"
468
469 The scheduler combines priority and round-robin based context switches. The example depicted in the image above contains
470 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
471 (\ref osThreadAttr_t::priority). As long as threads 3 and 4 are blocked the scheduler switches between thread 1 and 2 on
472 a time-slice basis (round-robin). The time-slice for round-robin scheduling can be configured, see Round-Robin Timeout in \ref systemConfig.
473
474 Thread 2 unblocks thread 3 by an arbitrary RTOS-call (executed in SVC handler mode) at time index 2. The scheduler switches to
475 thread 3 immidiately because thread 3 has the highest priority. Thread 4 is still blocked.
476
477 At time index 4 an interrupt (ISR) occurs and preempts the SysTick_Handler. RTX does not add any latency to the interrupt
478 service execution. The ISR routine uses an RTOS-call that unblocks thread 4. Instead of switching to thread 4 immediately
479 the PendSV flag is set to defer the context switching. The PendSV_Handler is executed right after the SysTick_Handler returns
480 and the defered context switch to thread 4 is carried out. As soon as highest priority thread 4 blocks again by using
481 a blocking RTOS-call execution is switched back to thread 3 immidiately during time index 5.
482
483 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.
484 At time index 7 the scheduler uses the round-robin mechanism to switch to thread 1 and so on.
485
486 \section MemoryAllocation Memory Allocation 
487
488 RTX5 objects (thread, mutex, semaphore, timer, message queue, thread and event flags, as well as memory pool) require
489 dedicated RAM memory. Objects can be created using os<i>Object</i>New() calls and deleted using os<i>Object</i>Delete()
490 calls. The related object memory needs to be available during the lifetime of the object.
491
492 RTX5 offers three different memory allocation methods for objects:
493   - \ref GlobalMemoryPool uses a single global memory pool for all objects. It is easy to configure, but may have 
494     the disadvantage for memory fragmentation when objects with different sizes are created and destroyed.
495   - \ref ObjectMemoryPool uses a fixed-size memory pool for each object type. The method is time deterministic
496      and avoids memory fragmentation.
497   - \ref StaticObjectMemory reserves memory during compile time and completely avoids that a system can be out of memory.
498     This is typically a required for some safety critical systems.
499
500 It possible to intermix all the memory allocation methods in the same application.
501
502 \subsection GlobalMemoryPool Global Memory Pool
503
504 The global memory pool allocates all objects from a memory area. This method of memory allocation is the default
505 configuration setting of RTX5.
506
507 \image html MemAllocGlob.png "Global Memory Pool for all objects"
508
509 When the memory pool does not provide sufficient memory, the creation of the object fails and the related
510 os<i>Object</i>New() function returns \token{NULL}.
511
512 Enabled in \ref systemConfig.
513
514 \subsection ObjectMemoryPool Object-specific Memory Pools
515
516 Object-specific memory pools avoids memory fragmentation with a dedicated fixed-size memory management for each object type.
517 This type of memory pools are fully time deterministic, which means that object creation and destruction takes always the
518 same fixed amount of time. As a fixed-size memory pool is specific to an object type, the handling of out-of-memory
519 situations is simplified.
520
521 \image html MemAllocSpec.png "One memory pool per object type"
522
523 Object-specific memory pools are selectively enabled for each object type, e.g: mutex or thread using the RTX configuration
524 file:
525  - Enabled in \ref threadConfig for thread objects.
526  - Enabled in \ref timerConfig for timer objects.
527  - Enabled in \ref eventFlagsConfig for event objects.
528  - Enabled in \ref mutexConfig for mutex objects.
529  - Enabled in \ref semaphoreConfig for semaphore.
530  - Enabled in \ref memPoolConfig for memory pools.
531  - Enabled in \ref msgQueueConfig for message objects.
532
533 When the memory pool does not provide sufficient memory, the creation of the object fails and the related
534 os<i>Object</i>New() function returns \token{NULL}.
535
536 \subsection StaticObjectMemory Static Object Memory
537 In contrast to the dynamic memory allocations, the static memory allocation requires compile-time allocation of object memory. 
538
539 \image html MemAllocStat.png "Statically allocated memory for all objects"
540
541 Static memory allocation can be achieved by providing user-defined memory using attributes at object creation,
542 see \ref CMSIS_RTOS_MemoryMgmt_Manual. Please take special note of the following restrictions:
543
544 Memory type                                  | Requirements
545 ---------------------------------------------|-------------------------------------------------------------------------------
546 Control Block (osXxxAttr_t::cb_mem)          | 4-Byte alignment. Size defined by \ref osRtxThreadCbSize, \ref osRtxTimerCbSize, \ref osRtxEventFlagsCbSize, \ref osRtxMutexCbSize, \ref osRtxSemaphoreCbSize, \ref osRtxMemoryPoolCbSize, \ref osRtxMessageQueueCbSize.
547 Thread Stack (osThreadAttr_t::stack_mem)     | 8-Byte alignment. Size is application specific, i.e. amount of stack variables and frames.
548 Memory Pool (osMemoryPoolAttr_t::mp_mem)     | 4-Byte alignment. Size calculated with \ref osRtxMemoryPoolMemSize.
549 Message Queue (osMessageQueueAttr_t::mq_mem) | 4-Byte alignment. Size calculated with \ref osRtxMessageQueueMemSize.
550
551
552 In order to allow RTX5 aware debugging, i.e. Component Viewer, to recognize control blocks these
553 needs to be placed in individual memory sections, i.e. using `__attribute__((section(...)))`.
554
555 RTX Object    | Linker Section 
556 --------------|------------------------
557 Thread        | `.bss.os.thread.cb`
558 Timer         | `.bss.os.timer.cb`
559 Event Flags   | `.bss.os.evflags.cb`
560 Mutex         | `.bss.os.mutex.cb`
561 Semaphore     | `.bss.os.semaphore.cb`
562 Memory Pool   | `.bss.os.mempool.cb`
563 Message Queue | `.bss.os.msgqueue.cb`
564
565 The following code example shows how to create an OS object using static memory.
566
567 <b> Code Example:</b> 
568 \code{.c}
569 /*----------------------------------------------------------------------------
570  * CMSIS-RTOS 'main' function template
571  *---------------------------------------------------------------------------*/
572
573 #include "RTE_Components.h"
574 #include  CMSIS_device_header
575 #include "cmsis_os2.h"
576  
577 //include rtx_os.h for types of RTX objects
578 #include "rtx_os.h"
579  
580 //The thread function instanced in this example
581 void worker(void *arg)
582 {
583   while(1) 
584   {
585     //work
586     osDelay(10000);
587   }  
588 }
589  
590 // Define objects that are statically allocated for worker thread 1
591 __attribute__((section(".bss.os.thread.cb")))
592 osRtxThread_t worker_thread_tcb_1;
593  
594 // Reserve two areas for the stacks of worker thread 1
595 // uint64_t makes sure the memory alignment is 8
596 uint64_t worker_thread_stk_1[64];
597  
598 // Define the attributes which are used for thread creation
599 // Optional const saves RAM memory and includes the values in periodic ROM tests 
600 const osThreadAttr_t worker_attr_1 = {
601   "wrk1",
602   osThreadJoinable,
603   &worker_thread_tcb_1,
604   sizeof(worker_thread_tcb_1),
605   &worker_thread_stk_1[0],
606   sizeof(worker_thread_stk_1),
607   osPriorityAboveNormal,
608   0
609 };
610  
611 // Define ID object for thread
612 osThreadId_t th1;
613  
614 /*----------------------------------------------------------------------------
615  * Application main thread
616  *---------------------------------------------------------------------------*/
617 void app_main (void *argument) {
618   uint32_t param = NULL;
619  
620   // Create an instance of the worker thread with static resources (TCB and stack)
621   th1 = osThreadNew(worker, &param, &worker_attr_1);
622  
623   for (;;) {}
624 }
625  
626 int main (void) {
627   // System Initialization
628   SystemCoreClockUpdate();
629   // ...
630
631   osKernelInitialize();                 // Initialize CMSIS-RTOS
632   osThreadNew(app_main, NULL, NULL);    // Create application main thread
633   osKernelStart();                      // Start thread execution
634   for (;;) {}
635 }
636 \endcode
637
638
639 \section ThreadStack Thread Stack Management
640
641 For Cortex-M processors without floating point unit the thread context requires 64 bytes on the local stack.
642
643 \note For Cortex-M4/M7 with FP the thread context requires 200 bytes on the local stack. For these devices the default stack
644 space should be increased to a minimum of 300 bytes.
645
646 Each thread is provided with a separate stack that holds the thread context and stack space for automatic variables and
647 return addresses for function call nesting. The stack sizes of RTX threads are flexibly configurable as explained in the
648 section \ref threadConfig. RTX offers a configurable checking for stack overflows and stack utilization. 
649
650
651 \section lowPower Low-Power Operation
652
653 The system thread \b osRtxIdleThread can be use to switch the system into a low-power mode. The easiest form to enter a
654 low-power mode is the execution of the \c __WFE function that puts the processor into a sleep mode where it waits for an
655 event.
656
657 <b>Code Example:</b>
658 \code
659 #include "RTE_Components.h"
660 #include CMSIS_device_header            /* Device definitions                 */
661  
662 void osRtxIdleThread (void) {
663   /* The idle demon is a system thread, running when no other thread is       */
664   /* ready to run.                                                            */
665  
666   for (;;) {
667     __WFE();                            /* Enter sleep mode                   */
668   }
669 }
670 \endcode
671
672 \note
673 \c __WFE() is not available in every Cortex-M implementation. Check device manuals for availability.
674
675
676 \section kernelTimer RTX Kernel Timer Tick
677
678 RTX uses the generic \ref CMSIS_RTOS_TickAPI to configure and control its periodic Kernel Tick.
679
680 To use an alternative timer as the Kernel Tick Timer one simply needs to implement a custom version
681 of the \ref CMSIS_RTOS_TickAPI.
682
683 \note The OS Tick implementation provided must asure that the used timer interrupt uses the same (low) priority group 
684 as the service interrupts, i.e. interrupts used by RTX must not preempt each other. Refer to the \ref Scheduler section
685 for more details.
686
687 \subsection TickLess Tick-less Low-Power Operation
688
689 RTX5 provides extension for tick-less operation which is useful for applications that use extensively low-power modes where
690 the SysTick timer is also disabled. To provide a time-tick in such power-saving modes, a wake-up timer is used to
691 derive timer intervals. The CMSIS-RTOS2 functions \ref osKernelSuspend and \ref osKernelResume control the tick-less
692 operation.
693
694 Using this functions allows the RTX5 thread scheduler to stop the periodic kernel tick interrupt. When all active threads
695 are suspended, the system enters power-down and calculates how long it can stay in this power-down mode. In the power-down
696 mode the processor and peripherals can be switched off. Only a wake-up timer must remain powered, because this timer is
697 responsible to wake-up the system after the power-down period expires.
698
699 The tick-less operation is controlled from the \b osRtxIdleThread thread. The wake-up timeout value is set before the system
700 enters the power-down mode. The function \ref osKernelSuspend calculates the wake-up timeout measured in RTX Timer Ticks;
701 this value is used to setup the wake-up timer that runs during the power-down mode of the system.
702
703 Once the system resumes operation (either by a wake-up time out or other interrupts) the RTX5 thread scheduler is started
704 with the function \ref osKernelResume. The parameter \a sleep_time specifies the time (in RTX Timer Ticks) that the system
705 was in power-down mode.
706
707 <b>Code Example:</b>
708 \code
709 #include "msp.h"                        // Device header
710
711 /*----------------------------------------------------------------------------
712  *      MSP432 Low-Power Extension Functions
713  *---------------------------------------------------------------------------*/
714 static void MSP432_LP_Entry(void) {
715   /* Enable PCM rude mode, which allows to device to enter LPM3 without waiting for peripherals */
716   PCM->CTL1 = PCM_CTL1_KEY_VAL | PCM_CTL1_FORCE_LPM_ENTRY;       
717   /* Enable all SRAM bank retentions prior to going to LPM3  */
718   SYSCTL->SRAM_BANKRET |= SYSCTL_SRAM_BANKRET_BNK7_RET;
719   __enable_interrupt();
720   NVIC_EnableIRQ(RTC_C_IRQn);
721   /* Do not wake up on exit from ISR */
722   SCB->SCR |= SCB_SCR_SLEEPONEXIT_Msk;
723   /* Setting the sleep deep bit */
724   SCB->SCR |= (SCB_SCR_SLEEPDEEP_Msk);  
725 }
726  
727 static volatile unsigned int tc;
728 static volatile unsigned int tc_wakeup;
729  
730 void RTC_C_IRQHandler(void)
731 {
732   if (tc++ > tc_wakeup) 
733   {
734     SCB->SCR &= ~SCB_SCR_SLEEPONEXIT_Msk;    
735     NVIC_DisableIRQ(RTC_C_IRQn);
736     NVIC_ClearPendingIRQ(RTC_C_IRQn);
737     return;
738   }
739   if (RTC_C->PS0CTL & RTC_C_PS0CTL_RT0PSIFG)
740   {
741     RTC_C->CTL0 = RTC_C_KEY_VAL;                 // Unlock RTC key protected registers
742     RTC_C->PS0CTL &= ~RTC_C_PS0CTL_RT0PSIFG;
743     RTC_C->CTL0 = 0;
744     SCB->SCR |= (SCB_SCR_SLEEPDEEP_Msk);
745   }
746 }
747  
748 uint32_t g_enable_sleep = 0;
749   
750 void osRtxIdleThread (void) {
751   
752   for (;;) {
753     tc_wakeup = osKernelSuspend();
754     /* Is there some time to sleep? */
755     if (tc_wakeup > 0) {
756       tc = 0;
757       /* Enter the low power state */
758       MSP432_LP_Entry();
759       __WFE();
760     }
761     /* Adjust the kernel ticks with the amount of ticks slept */
762     osKernelResume (tc);
763   }
764 }
765 \endcode
766
767 \note
768 \c __WFE() is not available in every Arm Cortex-M implementation. Check device manuals for availability. 
769 The alternative using \c __WFI() has other issues, please take note of http://www.keil.com/support/docs/3591.htm as well.
770
771 \section rtx_os_h RTX5 Header File
772
773 Every implementation of the CMSIS-RTOS2 API can bring its own additional features. RTX5 adds a couple of
774 \ref rtx5_specific "functions" for the idle more, for error notifications, and special system timer functions. It also is
775 using macros for control block and memory sizes.
776
777 If you require some of the RTX specific functions in your application code, \#include the header file \b %rtx_os.h:
778
779 \include rtx_os.h
780
781
782 \section CMSIS_RTOS_TimeOutValue Timeout Value   
783
784 Timeout values are an argument to several \b osXxx functions to allow time for resolving a request. A timeout value of \b 0
785 means that the RTOS does not wait and the function returns instantly, even when no resource is available. A timeout value of
786 \ref osWaitForever means that the RTOS waits infinitely until a resource becomes available. Or one forces the thread to resume
787 using \ref osThreadResume which is discouraged.
788  
789 The timeout value specifies the number of timer ticks until the time delay elapses. The value is an upper bound and 
790 depends on the actual time elapsed since the last timer tick. 
791
792 Examples:
793   - timeout value \b 0 : the system does not wait, even when no resource is available the RTOS function returns instantly. 
794   - timeout value \b 1 : the system waits until the next timer tick occurs; depending on the previous timer tick, it may be a
795     very short wait time.
796   - timeout value \b 2 : actual wait time is between 1 and 2 timer ticks.
797   - timeout value \ref osWaitForever : system waits infinite until a resource becomes available. 
798   
799 \image html TimerValues.png "Example of timeout using osDelay()"
800
801
802 \section CMSIS_RTOS_ISR_Calls Calls from Interrupt Service Routines 
803
804 The following CMSIS-RTOS2 functions can be called from threads and Interrupt Service Routines (ISR):
805   - \ref osKernelGetInfo, \ref osKernelGetState,
806     \ref osKernelGetTickCount, \ref osKernelGetTickFreq, \ref osKernelGetSysTimerCount, \ref osKernelGetSysTimerFreq
807   - \ref osThreadFlagsSet
808   - \ref osEventFlagsSet, \ref osEventFlagsClear, \ref osEventFlagsGet, \ref osEventFlagsWait
809   - \ref osSemaphoreAcquire, \ref osSemaphoreRelease, \ref osSemaphoreGetCount
810   - \ref osMemoryPoolAlloc, \ref osMemoryPoolFree, \ref osMemoryPoolGetCapacity, \ref osMemoryPoolGetBlockSize,
811     \ref osMemoryPoolGetCount, \ref osMemoryPoolGetSpace
812   - \ref osMessageQueuePut, \ref osMessageQueueGet, \ref osMessageQueueGetCapacity, \ref osMessageQueueGetMsgSize,
813     \ref osMessageQueueGetCount, \ref osMessageQueueGetSpace
814
815 Functions that cannot be called from an ISR are verifying the interrupt status and return the status code \b osErrorISR, in
816 case they are called from an ISR context. In some implementations, this condition might be caught using the HARD_FAULT
817 vector.
818 */
819
820 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
821 /**
822 \page config_rtx5 Configure RTX v5
823
824 The file "RTX_Config.h" defines the configuration parameters of CMSIS-RTOS RTX and must be part of every project that is
825 using the CMSIS-RTOS RTX kernel. The configuration options are explained in detail in the following sections:
826 - \ref systemConfig covers system-wide settings for the global memory pool, tick frequency, ISR event buffer and round-robin thread switching.
827 - \ref threadConfig provides several parameters to configure the \ref CMSIS_RTOS_ThreadMgmt functions.
828 - \ref timerConfig provides several parameters to configure the \ref CMSIS_RTOS_TimerMgmt functions.
829 - \ref eventFlagsConfig provides several parameters to configure the \ref CMSIS_RTOS_EventFlags functions.
830 - \ref mutexConfig provides several parameters to configure the \ref CMSIS_RTOS_MutexMgmt functions.
831 - \ref semaphoreConfig provides several parameters to configure the \ref CMSIS_RTOS_SemaphoreMgmt functions.
832 - \ref memPoolConfig provides several parameters to configure the \ref CMSIS_RTOS_PoolMgmt functions.
833 - \ref msgQueueConfig provides several parameters to configure the \ref CMSIS_RTOS_Message functions.
834
835 The file "RTX_Config.c" contains default implementations of the functions \ref osRtxIdleThread and \ref osRtxErrorNotify. Both functions
836 can simply be overwritten with a custimized behavior by redefining them as part of the user code.
837
838 The configuration file uses <b>Configuration Wizard Annotations</b>. Refer to <b>Pack - Configuration Wizard Annotations</b> for details.
839 Depending on the development tool, the annotations might lead to a more user-friendly graphical representation of the
840 settings. The screenshot below is a screenshot from the µVision \b Configuration \b Wizard view:
841
842 \image html config_wizard.png "RTX_Config.h in Configuration Wizard View"
843
844 Alternatively one can provide configuration options using the compiler command line.
845
846 For example one can customize the used tick frequency to 100us by (overwriting) the configuration using
847 \code
848 cc -DOS_TICK_FREQ=100
849 \endcode
850
851 \section systemConfig System Configuration
852
853 The system configuration covers system-wide settings for the global memory pool, tick frequency, ISR event buffer and
854 round-robin thread switching.
855
856 <b>System Configuration Options</b>
857 \image html config_wizard_system.png "RTX_Config.h: System Configuration"
858
859 Name                                   | \#define                 | Description
860 ---------------------------------------|--------------------------|----------------------------------------------------------------
861 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.
862 Kernel Tick Frequency (Hz)             | \c OS_TICK_FREQ          | Defines base time unit for delays and timeouts in Hz. Default: 1000Hz = 1ms period.
863 Round-Robin Thread switching           | \c OS_ROBIN_ENABLE       | Enables Round-Robin Thread switching.
864 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]}.
865 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}.
866 Memory Management                      | \c OS_EVR_MEMORY         | Enables Memory Management events recording.
867 Kernel                                 | \c OS_EVR_KERNEL         | Enables Kernel events recording.
868 Thread                                 | \c OS_EVR_THREAD         | Enables Thread events recording.
869 Timer                                  | \c OS_EVR_TIMER          | Enables Timer events recording.
870 Event Flags                            | \c OS_EVR_EVFLAGS        | Enables Event Flags events recording.
871 Mutex                                  | \c OS_EVR_MUTEX          | Enables Mutex events recording.
872 Semaphore                              | \c OS_EVR_SEMAPHORE      | Enables Semaphore events recording.
873 Memory Pool                            | \c OS_EVR_MEMPOOL        | Enables Memory Pool events recording.
874 Message Queue                          | \c OS_EVR_MSGQUEUE       | Enables Message Queue events recording.
875 Object Memory usage counters           | \c OS_OBJ_MEM_USAGE      | Enables object memory usage counters to evaluate the maximum memory pool requirements individually for each RTOS object type.
876
877 \subsection systemConfig_glob_mem Global dynamic memory
878 Refer to \ref GlobalMemoryPool.
879
880
881 \subsection systemConfig_rr Round-Robin Thread Switching
882
883 RTX5 may be configured to use round-robin multitasking thread switching. Round-robin allows quasi-parallel execution of
884 several threads of the \a same priority. Threads are not really executed concurrently, but are scheduled where the available
885 CPU time is divided into time slices and RTX5 assigns a time slice to each thread. Because the time slice is typically short
886 (only a few milliseconds), it appears as though threads execute simultaneously.
887
888 Round-robin thread switching functions as follows:
889 - the tick is preloaded with the timeout value when a thread switch occurs
890 - the tick is decremented (if not already zero) each system tick if the same thread is still executing
891 - when the tick reaches 0 it indicates that a timeout has occurred. If there is another thread ready with the \a same
892   priority, then the system switches to that thread and the tick is preloaded with timeout again.
893
894 In other words, threads execute for the duration of their time slice (unless a thread's time slice is given up). Then, RTX
895 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
896 ready to run, the current running thread resumes it execution.
897
898 \note When switching to higher priority threads, the round-robin timeout value is reset.
899
900 Round-Robin multitasking is controlled with the <b>\#define OS_ROBIN_ENABLE</b>. The time slice period is configured (in RTX
901 timer ticks) with the <b>\#define OS_ROBIN_TIMEOUT</b>.
902
903
904 \subsection systemConfig_isr_fifo ISR FIFO Queue
905 The RTX functions (\ref CMSIS_RTOS_ISR_Calls), when called from and interrupt handler, store the request type and optional
906 parameter to the ISR FIFO queue buffer to be processed later, after the interrupt handler exits.
907
908 The scheduler is activated immediately after the IRQ handler has finished its execution to process the requests stored to the
909 FIFO queue buffer. The required size of this buffer depends on the number of functions that are called within the interrupt
910 handler. An insufficient queue size will be caught by \b osRtxErrorNotify with error code \b osRtxErrorISRQueueOverflow.
911
912
913 \subsection systemConfig_event_recording Event Recording
914
915 RTX5 fully supports <a href="http://www.keil.com/pack/doc/compiler/EventRecorder/html/index.html" target="_blank">Event Recorder</a>
916 annotations. In this section, you can enable or disable the recording of events for the different elements of RTX5. This
917 leads to reduced data traffic on the debug connection.
918
919 This setting should be used to disable the generation of messages for a complete family of events. To disable events only for
920 a certain API call, use the \#defines that are available from the rtx_evrt.h header file by adding them manually to the
921 RTX_Config.h file:
922
923 \b Memory \b events \n
924 \c EVR_RTX_MEMORY_INIT_DISABLE, \c EVR_RTX_MEMORY_ALLOC_DISABLE, \c EVR_RTX_MEMORY_FREE_DISABLE,
925 \c EVR_RTX_MEMORY_BLOCK_INIT_DISABLE, \c EVR_RTX_MEMORY_BLOCK_ALLOC_DISABLE, \c EVR_RTX_MEMORY_BLOCK_FREE_DISABLE
926
927 \b Kernel \b events \n
928 \c EVR_RTX_KERNEL_ERROR_DISABLE, \c EVR_RTX_KERNEL_INITIALIZE_DISABLE, \c EVR_RTX_KERNEL_INITIALIZE_COMPLETED_DISABLE,
929 \c EVR_RTX_KERNEL_GET_INFO_DISABLE, \c EVR_RTX_KERNEL_INFO_RETRIEVED_DISABLE, \c EVR_RTX_KERNEL_GET_STATE_DISABLE,
930 \c EVR_RTX_KERNEL_START_DISABLE, \c EVR_RTX_KERNEL_STARTED_DISABLE, \c EVR_RTX_KERNEL_LOCK_DISABLE,
931 \c EVR_RTX_KERNEL_LOCKED_DISABLE, \c EVR_RTX_KERNEL_UNLOCK_DISABLE, \c EVR_RTX_KERNEL_UNLOCKED_DISABLE,
932 \c EVR_RTX_KERNEL_RESTORE_LOCK_DISABLE, \c EVR_RTX_KERNEL_LOCK_RESTORED_DISABLE, \c EVR_RTX_KERNEL_SUSPEND_DISABLE,
933 \c EVR_RTX_KERNEL_SUSPENDED_DISABLE, \c EVR_RTX_KERNEL_RESUME_DISABLE, \c EVR_RTX_KERNEL_RESUMED_DISABLE,
934 \c EVR_RTX_KERNEL_GET_TICK_COUNT_DISABLE, \c EVR_RTX_KERNEL_GET_TICK_FREQ_DISABLE,
935 \c EVR_RTX_KERNEL_GET_SYS_TIMER_COUNT_DISABLE, \c EVR_RTX_KERNEL_GET_SYS_TIMER_FREQ_DISABLE
936
937 \b Thread \b events \n
938 \c EVR_RTX_THREAD_ERROR_DISABLE, \c EVR_RTX_THREAD_NEW_DISABLE, \c EVR_RTX_THREAD_CREATED_DISABLE,
939 \c EVR_RTX_THREAD_GET_NAME_DISABLE, \c EVR_RTX_THREAD_GET_ID_DISABLE, \c EVR_RTX_THREAD_GET_STATE_DISABLE,
940 \c EVR_RTX_THREAD_GET_STACK_SIZE_DISABLE, \c EVR_RTX_THREAD_GET_STACK_SPACE_DISABLE, \c EVR_RTX_THREAD_SET_PRIORITY_DISABLE,
941 \c EVR_RTX_THREAD_GET_PRIORITY_DISABLE, \c EVR_RTX_THREAD_YIELD_DISABLE, \c EVR_RTX_THREAD_SUSPEND_DISABLE,
942 \c EVR_RTX_THREAD_SUSPENDED_DISABLE, \c EVR_RTX_THREAD_RESUME_DISABLE, \c EVR_RTX_THREAD_RESUMED_DISABLE,
943 \c EVR_RTX_THREAD_DETACH_DISABLE, \c EVR_RTX_THREAD_DETACHED_DISABLE, \c EVR_RTX_THREAD_JOIN_DISABLE,
944 \c EVR_RTX_THREAD_JOIN_PENDING_DISABLE, \c EVR_RTX_THREAD_JOINED_DISABLE, \c EVR_RTX_THREAD_BLOCKED_DISABLE,
945 \c EVR_RTX_THREAD_UNBLOCKED_DISABLE, \c EVR_RTX_THREAD_PREEMPTED_DISABLE, \c EVR_RTX_THREAD_SWITCHED_DISABLE,
946 \c EVR_RTX_THREAD_EXIT_DISABLE, \c EVR_RTX_THREAD_TERMINATE_DISABLE, \c EVR_RTX_THREAD_DESTROYED_DISABLE,
947 \c EVR_RTX_THREAD_GET_COUNT_DISABLE, \c EVR_RTX_THREAD_ENUMERATE_DISABLE
948
949 \b Thread \b flag \b events \n
950 \c EVR_RTX_THREAD_FLAGS_SET_DISABLE, \c EVR_RTX_THREAD_FLAGS_SET_DONE_DISABLE, \c EVR_RTX_THREAD_FLAGS_CLEAR_DISABLE,
951 \c EVR_RTX_THREAD_FLAGS_CLEAR_DONE_DISABLE, \c EVR_RTX_THREAD_FLAGS_GET_DISABLE, \c EVR_RTX_THREAD_FLAGS_WAIT_DISABLE,
952 \c EVR_RTX_THREAD_FLAGS_WAIT_PENDING_DISABLE, \c EVR_RTX_THREAD_FLAGS_WAIT_TIMEOUT_DISABLE,
953 \c EVR_RTX_THREAD_FLAGS_WAIT_COMPLETED_DISABLE, \c EVR_RTX_THREAD_FLAGS_WAIT_NOT_COMPLETED_DISABLE
954
955 \b Generic \b wait \b events \n
956 \c EVR_RTX_THREAD_DELAY_DISABLE, \c EVR_RTX_THREAD_DELAY_UNTIL_DISABLE, \c EVR_RTX_THREAD_DELAY_COMPLETED_DISABLE
957
958 \b Timer \b events \n
959 \c EVR_RTX_TIMER_ERROR_DISABLE, \c EVR_RTX_TIMER_CALLBACK_DISABLE, \c EVR_RTX_TIMER_NEW_DISABLE,
960 \c EVR_RTX_TIMER_CREATED_DISABLE, \c EVR_RTX_TIMER_GET_NAME_DISABLE, \c EVR_RTX_TIMER_START_DISABLE,
961 \c EVR_RTX_TIMER_STARTED_DISABLE, \c EVR_RTX_TIMER_STOP_DISABLE, \c EVR_RTX_TIMER_STOPPED_DISABLE,
962 \c EVR_RTX_TIMER_IS_RUNNING_DISABLE, \c EVR_RTX_TIMER_DELETE_DISABLE, \c EVR_RTX_TIMER_DESTROYED_DISABLE
963
964 \b Event \b flag \b events \n
965 \c EVR_RTX_EVENT_FLAGS_ERROR_DISABLE, \c EVR_RTX_EVENT_FLAGS_NEW_DISABLE, \c EVR_RTX_EVENT_FLAGS_CREATED_DISABLE,
966 \c EVR_RTX_EVENT_FLAGS_GET_NAME_DISABLE, \c EVR_RTX_EVENT_FLAGS_SET_DISABLE, \c EVR_RTX_EVENT_FLAGS_SET_DONE_DISABLE,
967 \c EVR_RTX_EVENT_FLAGS_CLEAR_DISABLE, \c EVR_RTX_EVENT_FLAGS_CLEAR_DONE_DISABLE, \c EVR_RTX_EVENT_FLAGS_GET_DISABLE,
968 \c EVR_RTX_EVENT_FLAGS_WAIT_DISABLE, \c EVR_RTX_EVENT_FLAGS_WAIT_PENDING_DISABLE,
969 \c EVR_RTX_EVENT_FLAGS_WAIT_TIMEOUT_DISABLE, \c EVR_RTX_EVENT_FLAGS_WAIT_COMPLETED_DISABLE,
970 \c EVR_RTX_EVENT_FLAGS_WAIT_NOT_COMPLETED_DISABLE, \c EVR_RTX_EVENT_FLAGS_DELETE_DISABLE,
971 \c EVR_RTX_EVENT_FLAGS_DESTROYED_DISABLE
972
973 \b Mutex \b events \n
974 \c EVR_RTX_MUTEX_ERROR_DISABLE, \c EVR_RTX_MUTEX_NEW_DISABLE, \c EVR_RTX_MUTEX_CREATED_DISABLE,
975 \c EVR_RTX_MUTEX_GET_NAME_DISABLE, \c EVR_RTX_MUTEX_ACQUIRE_DISABLE, \c EVR_RTX_MUTEX_ACQUIRE_PENDING_DISABLE,
976 \c EVR_RTX_MUTEX_ACQUIRE_TIMEOUT_DISABLE, \c EVR_RTX_MUTEX_ACQUIRED_DISABLE, \c EVR_RTX_MUTEX_NOT_ACQUIRED_DISABLE,
977 \c EVR_RTX_MUTEX_RELEASE_DISABLE, \c EVR_RTX_MUTEX_RELEASED_DISABLE, \c EVR_RTX_MUTEX_GET_OWNER_DISABLE,
978 \c EVR_RTX_MUTEX_DELETE_DISABLE, \c EVR_RTX_MUTEX_DESTROYED_DISABLE
979
980 \b Semaphore \b events \n
981 \c EVR_RTX_SEMAPHORE_ERROR_DISABLE, \c EVR_RTX_SEMAPHORE_NEW_DISABLE, \c EVR_RTX_SEMAPHORE_CREATED_DISABLE,
982 \c EVR_RTX_SEMAPHORE_GET_NAME_DISABLE, \c EVR_RTX_SEMAPHORE_ACQUIRE_DISABLE, \c EVR_RTX_SEMAPHORE_ACQUIRE_PENDING_DISABLE,
983 \c EVR_RTX_SEMAPHORE_ACQUIRE_TIMEOUT_DISABLE, \c EVR_RTX_SEMAPHORE_ACQUIRED_DISABLE,
984 \c EVR_RTX_SEMAPHORE_NOT_ACQUIRED_DISABLE, \c EVR_RTX_SEMAPHORE_RELEASE_DISABLE, \c EVR_RTX_SEMAPHORE_RELEASED_DISABLE,
985 \c EVR_RTX_SEMAPHORE_GET_COUNT_DISABLE, \c EVR_RTX_SEMAPHORE_DELETE_DISABLE, \c EVR_RTX_SEMAPHORE_DESTROYED_DISABLE
986
987 \b Memory \b pool \b events \n
988 \c EVR_RTX_MEMORY_POOL_ERROR_DISABLE, \c EVR_RTX_MEMORY_POOL_NEW_DISABLE, \c EVR_RTX_MEMORY_POOL_CREATED_DISABLE,
989 \c EVR_RTX_MEMORY_POOL_GET_NAME_DISABLE, \c EVR_RTX_MEMORY_POOL_ALLOC_DISABLE, \c EVR_RTX_MEMORY_POOL_ALLOC_PENDING_DISABLE,
990 \c EVR_RTX_MEMORY_POOL_ALLOC_TIMEOUT_DISABLE, \c EVR_RTX_MEMORY_POOL_ALLOCATED_DISABLE,
991 \c EVR_RTX_MEMORY_POOL_ALLOC_FAILED_DISABLE, \c EVR_RTX_MEMORY_POOL_FREE_DISABLE, \c EVR_RTX_MEMORY_POOL_DEALLOCATED_DISABLE,
992 \c EVR_RTX_MEMORY_POOL_FREE_FAILED_DISABLE, \c EVR_RTX_MEMORY_POOL_GET_CAPACITY_DISABLE,
993 \c EVR_RTX_MEMORY_POOL_GET_BLOCK_SZIE_DISABLE, \c EVR_RTX_MEMORY_POOL_GET_COUNT_DISABLE,
994 \c EVR_RTX_MEMORY_POOL_GET_SPACE_DISABLE, \c EVR_RTX_MEMORY_POOL_DELETE_DISABLE, \c EVR_RTX_MEMORY_POOL_DESTROYED_DISABLE
995
996 \b Message \b queue \b events \n
997 \c EVR_RTX_MESSAGE_QUEUE_ERROR_DISABLE, \c EVR_RTX_MESSAGE_QUEUE_NEW_DISABLE, \c EVR_RTX_MESSAGE_QUEUE_CREATED_DISABLE,
998 \c EVR_RTX_MESSAGE_QUEUE_GET_NAME_DISABLE, \c EVR_RTX_MESSAGE_QUEUE_PUT_DISABLE,
999 \c EVR_RTX_MESSAGE_QUEUE_PUT_PENDING_DISABLE, \c EVR_RTX_MESSAGE_QUEUE_PUT_TIMEOUT_DISABLE,
1000 \c EVR_RTX_MESSAGE_QUEUE_INSERT_PENDING_DISABLE, \c EVR_RTX_MESSAGE_QUEUE_INSERTED_DISABLE,
1001 \c EVR_RTX_MESSAGE_QUEUE_NOT_INSERTED_DISABLE, \c EVR_RTX_MESSAGE_QUEUE_GET_DISABLE,
1002 \c EVR_RTX_MESSAGE_QUEUE_GET_PENDING_DISABLE, \c EVR_RTX_MESSAGE_QUEUE_GET_TIMEOUT_DISABLE,
1003 \c EVR_RTX_MESSAGE_QUEUE_RETRIEVED_DISABLE, \c EVR_RTX_MESSAGE_QUEUE_NOT_RETRIEVED_DISABLE,
1004 \c EVR_RTX_MESSAGE_QUEUE_GET_CAPACITY_DISABLE, \c EVR_RTX_MESSAGE_QUEUE_GET_MSG_SIZE_DISABLE,
1005 \c EVR_RTX_MESSAGE_QUEUE_GET_COUNT_DISABLE, \c EVR_RTX_MESSAGE_QUEUE_GET_SPACE_DISABLE,
1006 \c EVR_RTX_MESSAGE_QUEUE_RESET_DISABLE, \c EVR_RTX_MESSAGE_QUEUE_RESET_DONE_DISABLE,
1007 \c EVR_RTX_MESSAGE_QUEUE_DELETE_DISABLE, \c EVR_RTX_MESSAGE_QUEUE_DESTROYED_DISABLE
1008
1009
1010 \subsection systemConfig_usage_counters Object Memory Usage Counters
1011
1012 Object memory usage counters help to evaluate the maximum memory pool requirements for each object type, just like stack
1013 watermarking does for threads. The initial setup starts with a global memory pool for all object types. Consecutive runs of
1014 the application with object memory usage counters enabled, help to introduce object specific memory pools for each object
1015 type. Normally, this is required for applications that require a functional safety certification as global memory pools are
1016 not allowed in this case.
1017
1018
1019 \section threadConfig Thread Configuration
1020
1021 The RTX5 provides several parameters to configure the \ref CMSIS_RTOS_ThreadMgmt functions.
1022
1023 <b>Thread Configuration Options</b>
1024 \image html config_wizard_threads.png "RTX_Config.h: Thread Configuration"
1025
1026 <br> 
1027 Option                                                   | \#define               | Description
1028 :--------------------------------------------------------------------------|:-------------------------------|:---------------------------------------------------------------
1029 Object specific Memory allocation                        | \c OS_THREAD_OBJ_MEM   | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1030 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]}.
1031 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]}.
1032 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}. 
1033 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}. 
1034 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}. 
1035 Idle Thread TrustZone Module ID                                            | \c OS_IDLE_THREAD_TZ_MOD_ID    | Defines the \ref osThreadAttr_t::tz_module "TrustZone Module ID" the Idle Thread shall use. This needs to be set to a non-zero value if the Idle Thread need to call secure functions. Default value is \token{0}.
1036 Stack overrun checking                                   | \c OS_STACK_CHECK   | Enable stack overrun checks at thread switch. 
1037 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.
1038 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.
1039
1040 \subsection threadConfig_countstack Configuration of Thread Count and Stack Space
1041
1042 The RTX5 kernel uses a separate stack space for each thread and provides two methods for defining the stack requirements:
1043  - <b>Static allocation</b>: when \ref osThreadAttr_t::stack_mem and \ref osThreadAttr_t::stack_size specify a memory area
1044    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.
1045  - <b>Dynamic allocation</b>: when \ref osThreadAttr_t is NULL or \ref osThreadAttr_t::stack_mem is NULL, the system
1046    allocates the stack memory from:
1047      - Object-specific Memory Pool (default Stack size) when "Object specific Memory allocation" is enabled and "Number of
1048        user Threads with default Stack size" is not \token{0} and \ref osThreadAttr_t::stack_size is \token{0} (or
1049        \ref osThreadAttr_t is NULL).
1050      - Object-specific Memory Pool (user-provided Stack size) when "Object specific Memory allocation" is enabled and "Total
1051        Stack size for user..."  is not \token{0} and \ref osThreadAttr_t::stack_size is not \token{0}.
1052      - Global Memory Pool when "Object specific Memory allocation" is disabled or (\ref osThreadAttr_t::stack_size is not
1053        \token{0} and "Total Stack size for user..." is \token{0}) or (\ref osThreadAttr_t::stack_size is \token{0} and
1054        "Number of user Threads with default Stack size" is \token{0}).
1055
1056 \ref osThreadAttr_t is a parameter of the function \ref osThreadNew.
1057
1058 \note
1059 Before the RTX kernel is started by the \ref osKernelStart() function, the main stack defined in startup_<i>device</i>.s is
1060 used. The main stack is also used for:
1061  - user application calls to RTX functions in \b thread \b mode using SVC calls
1062  - interrupt/exception handlers.
1063  
1064 \subsection threadConfig_ovfcheck Stack Overflow Checking
1065 RTX5 implements a software stack overflow checking that traps stack overruns. Stack is used for return addresses and
1066 automatic variables. Extensive usage or incorrect stack configuration may cause a stack overflow. Software stack overflow
1067 checking is controlled with the define \c OS_STACK_CHECK.
1068  
1069 If a stack overflow is detected, the function \b osRtxErrorNotify with error code \b osRtxErrorStackUnderflow is called. By
1070 default, this function is implemented as an endless loop and will practically stop code execution.
1071
1072 \subsection threadConfig_watermark Stack Usage Watermark
1073 RTX5 initializes thread stack with a watermark pattern (0xCC) when a thread is created. This allows the debugger to determine
1074 the maximum stack usage for each thread. It is typically used during development but removed from the final application.
1075 Stack usage watermark is controlled with the define \c OS_STACK_WATERMARK.
1076   
1077 Enabling this option significantly increases the execution time of \ref osThreadNew (depends on thread stack size).
1078  
1079 \subsection threadConfig_procmode Processor Mode for Thread Execution
1080 RTX5 allows to execute threads in unprivileged or privileged processor mode. The processor mode is controlled with the
1081 define \c OS_PRIVILEGE_MODE.
1082  
1083 In \b unprivileged processor mode, the application software:
1084 - has limited access to the MSR and MRS instructions, and cannot use the CPS instruction.
1085 - cannot access the system timer, NVIC, or system control block.
1086 - might have restricted access to memory or peripherals.
1087
1088 In \b privileged processor mode, the application software can use all the instructions and has access to all resources.
1089
1090
1091 \section timerConfig Timer Configuration
1092
1093 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_TimerMgmt functions.
1094
1095 <b>Timer Configuration Options</b>
1096 \image html config_wizard_timer.png "RTX_Config.h: Timer Configuration"
1097
1098 Name                                   | \#define                 | Description
1099 ---------------------------------------|--------------------------------|----------------------------------------------------------------
1100 Object specific Memory allocation      | \c OS_TIMER_OBJ_MEM      | Enables object specific memory allocation. 
1101 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]}.
1102 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} 
1103 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}.
1104 Timer Thread TrustZone Module ID       | \c OS_TIMER_THREAD_TZ_MOD_ID   | Defines the \ref osThreadAttr_t::tz_module "TrustZone Module ID" the Timer Thread shall use. This needs to be set to a non-zero value if any Timer Callbacks need to call secure functions. Default value is \token{0}.
1105 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]}.
1106
1107 \subsection timerConfig_obj Object-specific memory allocation
1108 See \ref ObjectMemoryPool.
1109
1110 \subsection timerConfig_user User Timer Thread
1111 The RTX5 function \b osRtxTimerThread executes callback functions when a time period expires. The priority of the timer
1112 subsystem within the complete RTOS system is inherited from the priority of the \b osRtxTimerThread. This is configured by
1113 \c OS_TIMER_THREAD_PRIO. Stack for callback functions is supplied by \b osRtxTimerThread. \c OS_TIMER_THREAD_STACK_SIZE must
1114 satisfy the stack requirements of the callback function with the highest stack usage. 
1115
1116
1117 \section eventFlagsConfig Event Flags Configuration
1118
1119 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_EventFlags functions.
1120
1121 <b>Event Configuration Options</b>
1122 \image html config_wizard_eventFlags.png "RTX_Config.h: Event Flags Configuration"
1123
1124 Name                                   | \#define                 | Description
1125 ---------------------------------------|--------------------------|----------------------------------------------------------------
1126 Object specific Memory allocation      | \c OS_EVFLAGS_OBJ_MEM    | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1127 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]}.
1128
1129 \subsection eventFlagsConfig_obj Object-specific memory allocation
1130 When object-specific memory is used, the pool size for all Event objects is specified by \c OS_EVFLAGS_NUM. Refer to
1131 \ref ObjectMemoryPool.
1132
1133
1134 \section mutexConfig Mutex Configuration
1135 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_MutexMgmt functions.
1136
1137 <b>Mutex Configuration Options</b>
1138 \image html config_wizard_mutex.png "RTX_Config.h: Mutex Configuration"
1139
1140
1141 Name                                   | \#define                 | Description
1142 ---------------------------------------|--------------------------|----------------------------------------------------------------
1143 Object specific Memory allocation      | \c OS_MUTEX_OBJ_MEM      | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1144 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]}.
1145
1146 \subsection mutexConfig_obj Object-specific Memory Allocation
1147 When object-specific memory is used, the pool size for all Mutex objects is specified by \c OS_MUTEX_NUM. Refer to
1148 \ref ObjectMemoryPool.
1149
1150
1151 \section semaphoreConfig Semaphore Configuration
1152
1153 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_SemaphoreMgmt functions.
1154
1155 <b>Semaphore Configuration Options</b>
1156 \image html config_wizard_semaphore.png "RTX_Config.h: Semaphore Configuration"
1157
1158
1159 Name                                   | \#define                 | Description
1160 ---------------------------------------|--------------------------|----------------------------------------------------------------
1161 Object specific Memory allocation      | \c OS_SEMAPHORE_OBJ_MEM  | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1162 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]}.
1163
1164 \subsection semaphoreConfig_obj Object-specific memory allocation
1165 When Object-specific Memory is used, the pool size for all Semaphore objects is specified by \c OS_SEMAPHORE_NUM. Refer to
1166 \ref ObjectMemoryPool.
1167
1168
1169 \section memPoolConfig Memory Pool Configuration
1170
1171 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_PoolMgmt functions.
1172
1173 <b>Memory Pool Configuration Options</b>
1174 \image html config_wizard_memPool.png "RTX_Config.h: Memory Pool Configuration"
1175
1176 Name                                   | \#define                 | Description
1177 ---------------------------------------|--------------------------|----------------------------------------------------------------
1178 Object specific Memory allocation      | \c OS_MEMPOOL_OBJ_MEM    | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1179 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]}.
1180 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}.
1181
1182 \subsection memPoolConfig_obj Object-specific memory allocation
1183 When object-specific memory is used, the number of pools for all MemoryPool objects is specified by \c OS_MEMPOOL_NUM. The
1184 total storage size reserved for all pools is configured in \c OS_MEMPOOL_DATA_SIZE. Refer to \ref ObjectMemoryPool.
1185
1186
1187 \section msgQueueConfig Message Queue Configuration
1188
1189 RTX5 provides several parameters to configure the \ref CMSIS_RTOS_Message functions.
1190
1191 <b>MessageQueue Configuration Options</b>
1192 \image html config_wizard_msgQueue.png "RTX_Config.h: Message Queue Configuration"
1193
1194 Name                                   | \#define                 | Description
1195 ---------------------------------------|--------------------------|----------------------------------------------------------------
1196 Object specific Memory allocation      | \c OS_MSGQUEUE_OBJ_MEM   | Enables object specific memory allocation. See \ref ObjectMemoryPool.
1197 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]}.
1198 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}.
1199
1200 \subsection msgQueueConfig_obj Object-specific memory allocation
1201 When Object-specific Memory is used, the number of queues for all Message Queue objects is specified by \c OS_MSGQUEUE_NUM.
1202 The total storage size reserved for all queues is configured in \c OS_MSGQUEUE_DATA_SIZE. Refer to \ref ObjectMemoryPool.
1203 */
1204
1205
1206 /* ========================================================================================================================== */
1207 /** 
1208 \page creating_RTX5_LIB Building the RTX5 Library
1209
1210 The CMSIS Pack contains a µVision project for building the complete set of RTX5 libraries. This project can also be used as
1211 a reference for building the RTX5 libraries using a tool-chain of your choice.
1212
1213 -# Open the project \b RTX_CM.uvprojx from the pack folder <b>CMSIS/RTOS2/RTX/Library/ARM/MDK</b> in µVision.
1214 -# Select the project target that matches your device's processor core. 
1215    \n The project provides target configuration for all supported Cortex-M targets supported by RTX5.
1216 -# You can find out about the required preprocessor defines in the dialogs <b>Options for Target - C/C++</b> and
1217    <b>Options for Target - Asm</b>. Note the need to use at least the C99 compiler mode when building RTX from source.
1218 -# From the <b>Project</b> window you find the list of source files required for a complete library build.
1219 -# Build the library of your choice using \b Project - \b Build \b Target (or press F7).
1220
1221 \image html own_lib_projwin.png "Project with files for Armv8-M Mainline"
1222 */
1223
1224
1225 /* ========================================================================================================================== */
1226 /** 
1227 \page dirstructfiles5 Directory Structure and File Overview
1228
1229 The following section provides an overview of the directory structure and the files that are relevant for the user's for
1230 CMSIS-RTOS RTX v5. The following directory references start below the CMSIS pack installation path, for example
1231 ARM/CMSIS/<i>version</i>/CMSIS/RTOS2.
1232
1233 \section Folders RTX v5 Directory Structure
1234
1235 The CMSIS-RTOS RTX v5 is delivered in source code and several examples are provided. 
1236
1237 <table class="cmtable" summary="CMSIS-RTOS RTX Library Files">
1238     <tr>
1239       <th>Directory</th>
1240       <th>Content</th>
1241     </tr>
1242     <tr>
1243       <td>Include</td>
1244       <td>The include file for CMSIS-RTOS API v2. cmsis_os2.h is the central include file for user applications.</td>
1245     </tr>
1246     <tr>
1247       <td>Template</td>
1248       <td>CMSIS-RTOS API template source and header file.</td>
1249     </tr>
1250     <tr>
1251       <td>RTX</td>
1252       <td>Directory with RTX specific files and folders. Also contains the component viewer description file.</td>
1253     </tr>
1254     <tr>
1255       <td>RTX/Config</td>
1256       <td>CMSIS-RTOS RTX configuration files %RTX_Config.h and %RTX_Config.c.</td>
1257     </tr>
1258     <tr>
1259       <td>RTX/Examples</td>
1260       <td>Example projects that can be directly used in development tools.</td>
1261     </tr>
1262     <tr>
1263       <td>RTX/Include</td>
1264       <td>RTX v5 specific include files.</td>
1265     </tr>
1266     <tr>
1267       <td>RTX/Include1</td>
1268       <td>CMSIS-RTOS v1 API header file.</td>
1269     </tr>
1270     <tr>
1271       <td>RTX/Library</td>
1272       <td>Pre-built libraries (see next table for details).</td>
1273     </tr>
1274     <tr>
1275       <td>RTX/Source</td>
1276       <td>Source code that can be used with ARMCC and GCC.</td>
1277     </tr>
1278     <tr>
1279       <td>RTX/Template</td>
1280       <td>User code templates for creating application projects with CMSIS-RTOS RTX v5.</td>
1281     </tr>
1282 </table>
1283
1284 \section libFiles RTX v5 Library Files
1285
1286 The CMSIS-RTOS RTX Library is available pre-compiled for ARMCC and GCC compilers and supports all Cortex-M
1287 processor variants in every configuration, including Arm Cortex-M23 and Cortex-M33.
1288
1289 <table class="cmtable" summary="CMSIS-RTOS RTX Library Files">
1290     <tr>
1291       <th>Library File</th>
1292       <th>Processor Configuration</th>
1293     </tr>
1294     <tr>
1295       <td>Library/ARM/RTX_CM0.lib</td>
1296       <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Cortex-M0 and M1, little-endian.</td>
1297     </tr>
1298     <tr>
1299       <td>Library/ARM/RTX_CM3.lib</td>
1300       <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Cortex-M3, M4, and M7 without FPU, little-endian.</td>
1301     </tr>
1302     <tr>
1303       <td>Library/ARM/RTX_CM4F.lib</td>
1304       <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Cortex-M4 and M7 with FPU, little-endian.</td>
1305     </tr>
1306     <tr>
1307       <td>Library/ARM/RTX_V8MB.lib</td>
1308       <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Armv8-M Baseline.</td>
1309     </tr>
1310     <tr>
1311       <td>Library/ARM/RTX_V8MBN.lib</td>
1312       <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Armv8-M Baseline, non-secure.</td>
1313     </tr>
1314     <tr>
1315       <td>Library/ARM/RTX_V8MM.lib</td>
1316       <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Armv8-M Mainline.</td>
1317     </tr>
1318     <tr>
1319       <td>Library/ARM/RTX_V8MMF.lib</td>
1320       <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Armv8-M Mainline with FPU.</td>
1321     </tr>
1322     <tr>
1323       <td>Library/ARM/RTX_V8MMFN.lib</td>
1324       <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Armv8-M Mainline with FPU, non-secure.</td>
1325     </tr>
1326     <tr>
1327       <td>Library/ARM/RTX_V8MMN.lib</td>
1328       <td>CMSIS-RTOS RTX Library for ARMCC Compiler, Armv8-M Mainline, non-secure.</td>
1329     </tr>
1330     <tr>
1331       <td>Library/GCC/libRTX_CM0.a</td>
1332       <td>CMSIS-RTOS libRTX Library for GCC Compiler, Cortex-M0 and M1, little-endian.</td>
1333     </tr>
1334     <tr>
1335       <td>Library/GCC/libRTX_CM3.a</td>
1336       <td>CMSIS-RTOS libRTX Library for GCC Compiler, Cortex-M3, M4, and M7 without FPU, little-endian.</td>
1337     </tr>
1338     <tr>
1339       <td>Library/GCC/libRTX_CM4F.a</td>
1340       <td>CMSIS-RTOS libRTX Library for GCC Compiler, Cortex-M4 and M7 with FPU, little-endian.</td>
1341     </tr>
1342     <tr>
1343       <td>Library/GCC/libRTX_V8MB.a</td>
1344       <td>CMSIS-RTOS libRTX Library for GCC Compiler, Armv8-M Baseline.</td>
1345     </tr>
1346     <tr>
1347       <td>Library/GCC/libRTX_V8MBN.a</td>
1348       <td>CMSIS-RTOS libRTX Library for GCC Compiler, Armv8-M Baseline, non-secure.</td>
1349     </tr>
1350     <tr>
1351       <td>Library/GCC/libRTX_V8MM.a</td>
1352       <td>CMSIS-RTOS libRTX Library for GCC Compiler, Armv8-M Mainline.</td>
1353     </tr>
1354     <tr>
1355       <td>Library/GCC/libRTX_V8MMF.a</td>
1356       <td>CMSIS-RTOS libRTX Library for GCC Compiler, Armv8-M Mainline with FPU.</td>
1357     </tr>
1358     <tr>
1359       <td>Library/GCC/libRTX_V8MMFN.a</td>
1360       <td>CMSIS-RTOS libRTX Library for GCC Compiler, Armv8-M Mainline with FPU, non-secure.</td>
1361     </tr>
1362     <tr>
1363       <td>Library/GCC/libRTX_V8MMN.a</td>
1364       <td>CMSIS-RTOS libRTX Library for GCC Compiler, Armv8-M Mainline, non-secure.</td>
1365     </tr>
1366 </table>
1367 */
1368
1369 /* ========================================================================================================================== */
1370 /** 
1371 \page technicalData5 Technical Data
1372
1373 \section technicalData_Toolchains Supported Toolchains
1374
1375 Keil RTX5 is developed and tested using the common toolchains and development environments.
1376
1377 \subsection technicalData_Toolchain_ARM Arm Compiler (Arm/Keil MDK, uVision5)
1378
1379 Major parts of RTX5 are developed and optimized using Arm Compiler and Arm/Keil MDK.
1380 The current release is tested with the following versions:
1381 <ul>
1382  <li>Arm Compiler 5.06 Update 6</li>
1383  <li>Arm Compiler 6.6.2 (Long Term Maintenance)</li>
1384  <li>Arm Compiler 6.9</li>
1385  <li>RTOS-aware debugging with uVision 5.24</li>
1386 </ul>
1387
1388 \subsection technicalData_Toolchain_IAR IAR Embedded Workbench
1389
1390 RTX5 has been ported to fully support IAR Embedded Workbench. The following releases are known to work:
1391 <ul>
1392  <li>IAR Embedded Workbench 7.7 (<a href="https://github.com/ARM-software/CMSIS_5/issues/201">community report</a>)</li>
1393  <li>IAR Embedded Workbench 7.80.4</li>
1394  <li><b>IAR Embedded Workbench 8.20.1</b></li>
1395 </ul>
1396
1397 \subsection technicalData_Toolchain_GCC GNU Compiler Collection
1398
1399 RTX5 has also been ported to support GCC, maintenance mainly relays on community contribution.
1400 Active development is currently tested with:
1401 <ul>
1402  <li>GNU Tools for Arm Embedded 6.3.1 20170620</li>
1403 </ul>
1404
1405 \section technicalData5_ControlBlockSizes Control Block Sizes
1406
1407 Keil RTX5 specific control block definitions (including sizes) as well as memory pool and message queue memory requirements
1408 are defined in the RTX5 header file:
1409
1410 \code
1411 /// Control Block sizes
1412 #define osRtxThreadCbSize        sizeof(osRtxThread_t)
1413 #define osRtxTimerCbSize         sizeof(osRtxTimer_t)
1414 #define osRtxEventFlagsCbSize    sizeof(osRtxEventFlags_t)
1415 #define osRtxMutexCbSize         sizeof(osRtxMutex_t)
1416 #define osRtxSemaphoreCbSize     sizeof(osRtxSemaphore_t)
1417 #define osRtxMemoryPoolCbSize    sizeof(osRtxMemoryPool_t)
1418 #define osRtxMessageQueueCbSize  sizeof(osRtxMessageQueue_t)
1419  
1420 /// Memory size in bytes for Memory Pool storage.
1421 /// \param         block_count   maximum number of memory blocks in memory pool.
1422 /// \param         block_size    memory block size in bytes.
1423 #define osRtxMemoryPoolMemSize(block_count, block_size) \
1424   (4*(block_count)*(((block_size)+3)/4))
1425  
1426 /// Memory size in bytes for Message Queue storage.
1427 /// \param         msg_count     maximum number of messages in queue.
1428 /// \param         msg_size      maximum message size in bytes.
1429 #define osRtxMessageQueueMemSize(msg_count, msg_size) \
1430   (4*(msg_count)*(3+(((msg_size)+3)/4)))
1431 \endcode
1432
1433 If you are using a \ref GlobalMemoryPool to allocate memory for the RTOS objects, you need to know the size that is required
1434 for each object in case of errors. Currently, the control block sizes are as follows (subject to change without
1435 notification):
1436
1437 Type          | Control block size in bytes |
1438 --------------|:---------------------------:|
1439 Thread        | 68                          |
1440 Timer         | 32                          |
1441 Event Flags   | 16                          |
1442 Mutex         | 28                          |
1443 Semaphore     | 16                          |
1444 Memory Pool   | 36                          |
1445 Message Queue | 52                          |
1446
1447 The size of the memory that is required for memory pool and message queue data storage can be determined from the macros
1448 stated above.
1449 */
1450
1451 /* ========================================================================================================================== */
1452 /** 
1453 \page CodingRules Coding Rules 
1454 \todo explain:
1455   - prefix  osXxxx, os_xxx, osRtx
1456
1457
1458 */
1459
1460 /* ========================================================================================================================== */
1461 /** 
1462 \page misraCompliance5 MISRA C:2012 Compliance 
1463 The RTX5 C source files use <b><a class=el href="http://www.misra.org.uk/" target="_blank">MISRA C:2012</a></b> guidelines as underlying coding standard.
1464
1465 For MISRA validation, <b><a class=el href="http://www.gimpel.com/" target="_blank">PC-lint</a></b> V9.00L is used with configuration for Arm Compiler V6.9.
1466 The PC-Lint validation setup is part of the project file <b>.\\CMSIS\\RTOS2\\RTX\\Library\\ARM\\MDK\\RTX_CM.uvprojx</b> as shown below. 
1467 Refer to <b><a class=el href="http://www.keil.com/support/man/docs/uv4/uv4_ut_pclint_validation.htm" target="_blank">Setup for PC-Lint</a></b> for more information.
1468
1469 \image html "PC-Lint.png" "Running PC-Lint within MDK - uVision"
1470
1471 The PC-Lint configuration uses the following Options under <b>Tools - PC-Lint Setup...</b>:
1472  - Config File: co-ARMCC-6.lnt (20-Mar-2017) with additional options:
1473 \code
1474    +rw(__restrict)
1475    -esym(526,__builtin_*) -esym(628,__builtin_*)
1476    -sem(__builtin_clz, pure)
1477    +doffsetof(t,m)=((size_t)&((t*)0)->m) -emacro((413,923,9078),offsetof)
1478    -ecall(534,__disable_irq)
1479 \endcode
1480  - Included Project Information: 
1481    - Enable: Add 'Include' paths
1482    - Enable: Add 'Software Packs' paths
1483    - Enable: Verify 'Software Packs' includes
1484    - Enable: Add 'Preprocessor' symbols
1485    - Enable: Add 'Define' symbols
1486  - MISRA  Rules Setup and Configuration: 
1487    - MISRQ_C_2012_Config.lnt; all rules enabled
1488    - includes definition file: au-misra3.lnt (12-Jun-2014)
1489  - Additional Lint Commands (for both single and mutiple files):
1490 \code
1491    - emacro(835,osRtxConfigPrivilegedMode)
1492 \endcode
1493
1494 The C source code is annotated with PC-Lint control comments to allows MISRA deviations.
1495 These deviations with the underlaying design decisions are described in the following.
1496    
1497 Deviations
1498 ----------
1499
1500 The RTX source code has the following deviations from MISRA:
1501   - \ref MISRA_1
1502   - \ref MISRA_2
1503   - \ref MISRA_3
1504   - \ref MISRA_4
1505   - \ref MISRA_5
1506   - \ref MISRA_6
1507   - \ref MISRA_7
1508   - \ref MISRA_8
1509   - \ref MISRA_9
1510   - \ref MISRA_10
1511   - \ref MISRA_11
1512   - \ref MISRA_12
1513   - \ref MISRA_13
1514
1515 All source code deviations are clearly marked and in summary these deviations affect the following MISRA rules:
1516  - [MISRA 2012 Directive  4.9,  advisory]: A function should be used in preference to a function-like macro where yet are interchangeable
1517  - [MISRA 2012 Rule       1.3,  required]: There shall be no occurrence of undefined or critical unspecified behavior
1518  - [MISRA 2012 Rule      10.3,  required]: Expression assigned to a narrower or different essential type
1519  - [MISRA 2012 Rule      10.5,  advisory]: Impermissible cast; cannot cast from 'essentially unsigned' to 'essentially enum\<i\>'
1520  - [MISRA 2012 Rule      11.1,  required]: Conversions shall not be performed between a pointer to a function and any other type
1521  - [MISRA 2012 Rule      11.3,  required]: A cast shall not be performed between a pointer to object type and a pointer to a different object type
1522  - [MISRA 2012 Rule      11.4,  advisory]: A conversion should not be performed between a pointer to object and an integer type
1523  - [MISRA 2012 Rule      11.5,  advisory]: A conversion should not be performed from pointer to void into pointer to object
1524  - [MISRA 2012 Rule      11.6,  required]: A cast shall not be performed between pointer to void and an arithmetic type
1525  - [MISRA 2012 Rule      15.5,  advisory]: A function should have a single point of exit at the end
1526  - [MISRA 2012 Rule      20.10, advisory]: The # and ## preprocessor operators should not be used
1527
1528 In the following all deviations are described in detail.
1529
1530 \section MISRA_1 [MISRA Note 1]: Return statements for parameter checking
1531
1532 Return statements are used at the beginning of several functions to validate parameter values and object states.
1533 The function returns immediately without any side-effects and typically an error status is set. This structure
1534 keeps the source code better structured and easier to understand.
1535
1536 This design decision implies the following MISRA deviation:
1537  - [MISRA 2012 Rule      15.5,  advisory]: A function should have a single point of exit at the end
1538
1539 All locations in the source code are marked with: 
1540 \code
1541   //lint -e{904} "Return statement before end of function" [MISRA Note 1]
1542 \endcode 
1543
1544
1545 \section MISRA_2 [MISRA Note 2]: Object identifiers are void pointers
1546
1547 CMSIS-RTOS is independant of an underlying RTOS implementation. The object idenifiers are therefore defined as void pointers to:
1548   - allow application programs that are agnostic from an underlying RTOS implementation.
1549   - avoid accidently accesses an RTOS control block from an application program.
1550
1551 This design decisions imply the following MISRA deviations:
1552  - [MISRA 2012 Rule      11.3,  required]: A cast shall not be performed between a pointer to object type and a pointer to a different object type
1553  - [MISRA 2012 Rule      11.5,  advisory]: A conversion should not be performed from pointer to void into pointer to object
1554
1555 All locations in the source code are marked with: 
1556 \code
1557   //lint -e{9079} -e{9087} "cast from pointer to void to pointer to object type" [MISRA Note 2]
1558 \endcode 
1559
1560 In the RTX5 implementation the requried pointer conversions are implemented in the header file rtx_lib.h with the following inline functions:
1561
1562 \code
1563 osRtxThread_t       *osRtxThreadId (osThread_t thread_id);
1564 osRtxTimer_t        *osRtxTimerId (osTimer_t timer_id);
1565 osRtxEventFlags_t   *osRtxEventFlagsId (osEventFlags_t ef_id);
1566 osRtxMutex_t        *osRtxMutexId (osMutex_t mutex_id);
1567 osRtxSemaphore_t    *osRtxSemaphoreId (osSemaphore_t semaphore_id);
1568 osRtxMemoryPool_t   *osRtxMemoryPoolId (osMemoryPoolId_t mp_id);
1569 osRtxMessageQueue_t *osRtxMessageQueueId(osMessageQueueId_t mq_id);
1570 \endcode
1571
1572 \section MISRA_3 [MISRA Note 3]: Conversion to unified object control blocks
1573
1574 RTX uses a unified object control block structure that contains common object members.
1575 The unified control blocks use a fixed layout at the beginning of the sturcture and starts always with an object identifier.
1576 This allows common object functions that receive a pointer to a unified object control block and reference only the
1577 pointer or the members in the fixed layout. Using common object functions and data (for example the ISR queue) reduces 
1578 code complexity and keeps the source code better structured.  Refer also to \ref MISRA_4
1579
1580 This design decisions imply the following MISRA deviations:
1581  - [MISRA 2012 Rule      11.3,  required]: A cast shall not be performed between a pointer to object type and a pointer to a different object type
1582  - [MISRA 2012 Rule      11.5,  advisory]: A conversion should not be performed from pointer to void into pointer to object
1583
1584 All locations in the source code are marked with: 
1585 \code
1586   //lint -e{9079} -e{9087} "cast from pointer to void to pointer to object type" [MISRA Note 3]
1587 \endcode 
1588
1589
1590 In the RTX5 implementation the requried pointer conversions are implemented in the header file \em rtx_lib.h with the following inline function:
1591
1592 \code
1593 osRtxObject_t *osRtxObject (void *object);
1594 \endcode
1595
1596
1597 \section MISRA_4 [MISRA Note 4]: Conversion from unified object control blocks
1598
1599 RTX uses a unified object control block structure that contains common object members. Refer to \ref MISRA_3 for more information.
1600 To process specifc control block data, pointer conversions are required.
1601
1602 This design decisions imply the following MISRA deviations:
1603  - [MISRA 2012 Rule       1.3,  required]: There shall be no occurrence of undefined or critical unspecified behavior
1604  - [MISRA 2012 Rule      11.3,  required]: A cast shall not be performed between a pointer to object type and a pointer to a different object type
1605 In addition PC-Lint issues:
1606  - Info  826: Suspicious pointer-to-pointer conversion (area too small)
1607
1608 All locations in the source code are marked with: 
1609 \code
1610   //lint -e{740} -e{826} -e{9087} "cast from pointer to generic object to specific object" [MISRA Note 4]
1611 \endcode 
1612
1613 In the RTX5 source code the requried pointer conversions are implemented in the header file \em rtx_lib.h with the following inline functions:
1614
1615 \code
1616 osRtxThread_t       *osRtxThreadObject (osRtxObject_t *object);
1617 osRtxTimer_t        *osRtxTimerObject (osRtxObject_t *object);
1618 osRtxEventFlags_t   *osRtxEventFlagsObject (osRtxObject_t *object);
1619 osRtxMutex_t        *osRtxMutexObject (osRtxObject_t *object);
1620 osRtxSemaphore_t    *osRtxSemaphoreObject (osRtxObject_t *object);
1621 osRtxMemoryPool_t   *osRtxMemoryPoolObject (osRtxObject_t *object);
1622 osRtxMessageQueue_t *osRtxMessageQueueObject (osRtxObject_t *object);
1623 osRtxMessage_t      *osRtxMessageObject (osRtxObject_t *object);
1624 \endcode
1625
1626 \section MISRA_5 [MISRA Note 5]: Conversion to object types
1627
1628 The RTX5 kernel has common memory management functions that use void pointers. These memory allocation fuctions returns 
1629 a void pointer which is correctly aligned for object types.
1630
1631 This design decision implies the following MISRA deviations:
1632  - [MISRA 2012 Rule      11.5,  advisory]: A conversion should not be performed from pointer to void into pointer to object
1633
1634 All locations in the source code are marked with: 
1635 \code
1636   //lint -e{9079} "conversion from pointer to void to pointer to other type" [MISRA Note 5]
1637 \endcode 
1638
1639 Code example:
1640
1641 \code 
1642   os_thread_t  *thread;
1643    :
1644   //lint -e{9079} "conversion from pointer to void to pointer to other type" [MISRA Note 5]
1645   thread = osRtxMemoryPoolAlloc(osRtxInfo.mpi.thread);
1646 \endcode
1647
1648
1649
1650 \section MISRA_6 [MISRA Note 6]: Conversion from user provided storage
1651
1652 CMSIS-RTOS2 and RTX5 support user provided storage for object control blocks, stack, and data storage.
1653 The API uses void pointers to define the location of this user provided storage. It is therefore
1654 required to cast the void pointer to underlying storage types. Alignment restrictions of user provided storage 
1655 are checked before accessing memory. Refer also to \ref MISRA_7.
1656
1657 This design decisions imply the following MISRA deviations:
1658  - [MISRA 2012 Rule      11.3,  required]: A cast shall not be performed between a pointer to object type and a pointer to a different object type
1659  - [MISRA 2012 Rule      11.5,  advisory]: A conversion should not be performed from pointer to void into pointer to object
1660
1661 All locations in the source code are marked with: 
1662 \code
1663   //lint -e{9079} "conversion from pointer to void to pointer to other type" [MISRA Note 6]
1664 \endcode 
1665
1666 Code example:
1667 \code
1668 static osTimerId_t svcRtxTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr) {
1669   os_timer_t *timer;
1670     :
1671   if (attr != NULL) {
1672     :
1673     //lint -e{9079} "conversion from pointer to void to pointer to other type" [MISRA Note 6]
1674     timer = attr->cb_mem;
1675         :
1676 \endcode        
1677
1678 \section MISRA_7 [MISRA Note 7]: Check for proper pointer alignment
1679
1680 RTX5 verifies the alignment of user provided storage for object control blocks, stack, and data storage.
1681 Refer also to \ref MISRA_6 for more information.
1682
1683 This design decision implies the following MISRA deviations:
1684  - [MISRA 2012 Rule      11.4,  advisory]: A conversion should not be performed between a pointer to object and an integer type
1685  - [MISRA 2012 Rule      11.6,  required]: A cast shall not be performed between pointer to void and an arithmetic type
1686
1687 All locations in the source code are marked with: 
1688 \code
1689   //lint -e(923) -e(9078) "cast from pointer to unsigned int" [MISRA Note 7]
1690 \endcode
1691
1692 Code example:
1693 \code
1694 static osThreadId_t svcRtxThreadNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr) {
1695     :
1696   void         *stack_mem;
1697     :
1698   if (stack_mem != NULL) {
1699     //lint -e(923) -e(9078) "cast from pointer to unsigned int" [MISRA Note 7]
1700     if ((((uint32_t)stack_mem & 7U) != 0U) || (stack_size == 0U)) {
1701     :
1702 \endcode        
1703
1704 \section MISRA_8 [MISRA Note 8]: Memory allocation management
1705
1706 RTX5 implements memory allocation functions which require pointer arithmetic to manage memory.
1707 The structure with the type \em mem_block_t that is used to menage memory allocation blocks is defined in \em rtx_memory.c
1708
1709 This design decision implies the following MISRA deviations:
1710  - [MISRA 2012 Rule      11.4,  advisory]: A conversion should not be performed between a pointer to object and an integer type
1711  - [MISRA 2012 Rule      11.6,  required]: A cast shall not be performed between pointer to void and an arithmetic type
1712
1713 All locations in the source code are marked with: 
1714 \code
1715   //lint -e(923) -e(9078) "cast from pointer to unsigned int" [MISRA Note 8]
1716 \endcode
1717
1718 The required pointer arithmetic is implemented in \em rtx_memory.c with the following function:
1719 \code
1720 __STATIC_INLINE mem_block_t *MemBlockPtr (void *mem, uint32_t offset) {
1721   uint32_t     addr;
1722   mem_block_t *ptr;
1723
1724   //lint --e{923} --e{9078} "cast between pointer and unsigned int" [MISRA Note 8]
1725   addr = (uint32_t)mem + offset;
1726   ptr  = (mem_block_t *)addr;
1727
1728   return ptr;
1729 }
1730 \endcode
1731
1732 \section MISRA_9 [MISRA Note 9]: Pointer conversions for register access
1733
1734 The CMSIS-Core peripheral register blocks are accessed using a structure. The memory address of this structure 
1735 is specified as unsigned integer number. Pointer conversions are required to access the specific registers.
1736
1737 This design decision implies the following MISRA deviations:
1738  - [MISRA 2012 Rule      11.4,  advisory]: A conversion should not be performed between a pointer to object and an integer type
1739  - [MISRA 2012 Rule      11.6,  required]: A cast shall not be performed between pointer to void and an arithmetic type
1740
1741 All locations in the source code are marked with: 
1742 \code
1743   //lint -emacro((923,9078),SCB) "cast from unsigned long to pointer" [MISRA Note 9]
1744 \endcode
1745
1746
1747 Code example:
1748 \code
1749 #define SCS_BASE  (0xE000E000UL)
1750 #define SCB      ((SCB_Type *)SCB_BASE)
1751 typedef struct {...} SCB_Type;
1752
1753 SCB->... = ...;
1754 \endcode
1755
1756 \section MISRA_10 [MISRA Note 10]: SVC calls use function-like macros
1757
1758 RTX5 is using SVC (Service Calls) to switch between thread mode (for user code execution) and handler mode (for RTOS kernel execution).
1759 The SVC function call mechanism is implemented with assembly instructions to construct the code for SVC.
1760 The source code uses C macros and are designed as C function-like macros to generate parameter passing
1761 for variables depending on macro parameters. An alternative replacement code would be complex.
1762 The C macros use multiple '##' operators however it has been verified that the order of evaluation is irrelevant 
1763 and result of macro expansion is always predictable.
1764
1765 This design decision implies the following MISRA deviations:
1766  - [MISRA 2012 Directive  4.9,  advisory]: A function should be used in preference to a function-like macro where yet are interchangeable
1767  - [MISRA 2012 Rule       1.3,  required]: There shall be no occurrence of undefined or critical unspecified behavior
1768  - [MISRA 2012 Rule      20.10, advisory]: The # and ## preprocessor operators should not be used
1769
1770 The relevant source code is in the file \em rtx_core_cm.h and is marked with: 
1771 \code
1772   //lint -save -e9023 -e9024 -e9026 "Function-like macros using '#/##'" [MISRA Note 10]
1773 \endcode
1774
1775
1776 \section MISRA_11 [MISRA Note 11]: SVC calls use assembly code
1777
1778 The SVC (Service Call) functions are constructed as a mix of C and inline assembly as it is required to access CPU registers
1779 for parameter passing. The function parameters are mapped to the CPU registers R0..R3 and SVC function number to 
1780 CPU register R12 (or R7). For assembly inter-working the function parameters are casted to unsigned int values.
1781
1782 The function return value after SVC call is mapped to the CPU register R0. Return value is casted from unsigned int 
1783 to the target value. 
1784
1785 It has been verified that this method has has no side-effects and is well defined.
1786
1787 This design decision implies the following MISRA deviations:
1788  - [MISRA 2012 Rule      10.3,  required]: Expression assigned to a narrower or different essential type
1789  - [MISRA 2012 Rule      10.5,  advisory]: Impermissible cast; cannot cast from 'essentially unsigned' to 'essentially enum\<i\>'
1790  - [MISRA 2012 Rule      11.1,  required]: Conversions shall not be performed between a pointer to a function and any other type
1791  - [MISRA 2012 Rule      11.4,  advisory]: A conversion should not be performed between a pointer to object and an integer type
1792  - [MISRA 2012 Rule      11.6,  required]: A cast shall not be performed between pointer to void and an arithmetic type
1793
1794 SVC functions are marked as library modules and not processed by PC-lint. The relevant source code is marked with: 
1795 \code
1796   //lint ++flb "Library Begin" [MISRA Note 11]
1797     :
1798   //lint --flb "Library End"
1799 \endcode
1800
1801 Code example:
1802 \code
1803 //  Service Calls definitions
1804 //lint ++flb "Library Begin" [MISRA Note 11]
1805 SVC0_1(Delay,      osStatus_t, uint32_t)
1806 SVC0_1(DelayUntil, osStatus_t, uint32_t)
1807 //lint --flb "Library End"
1808 \endcode
1809
1810 PC-lint does not process ASM input/output operand lists and therefore falsely identifies issues:
1811  - Last value assigned to variable not used
1812  - Symbol not subsequently referenced
1813 \todo: what has been done to mitigate that?
1814
1815
1816 \section MISRA_12 [MISRA Note 12]: Usage of exclusive access instructions
1817
1818 The RTX5 implementation uses the CPU instructions LDREX and STREX (when supported by the processor) to implement atomic operations.
1819 This atomic operations elimite the requirement for interrupt lock-outs. The atomic operations are implemented using 
1820 inline assembly.
1821
1822 PC-lint cannot process assembler instructions including the input/output operand lists and therefore falsely identifies issues:
1823  - Symbol not initialized
1824  - Symbol not subsequently referenced
1825  - Symbol not referenced
1826  - Pointer parameter could be declared as pointing to const
1827
1828 It has been verified that atomic operations have no side-effects and are well defined.
1829
1830 The functions that implement atomic instructions are marked as library modules and not processed by PC-lint. The relevant source code is marked with: 
1831 \code
1832   //lint ++flb "Library Begin" [MISRA Note 12]
1833     :
1834   //lint --flb "Library End"
1835 \endcode
1836
1837
1838 \section MISRA_13 [MISRA Note 13]: Usage of Event Recorder
1839
1840 The Event Recorder is a generic event logger and the related functions are called to record an event.
1841 The function parameters are 32-bit id, 32-bit values, pointer to void (data) and are recorded as 32-bit numbers.
1842 The parameters for the Event Recorder may require cast opertions to unsigned int which however has no side-effects 
1843 and is well defined. 
1844
1845 The return value indicates success or failure. There is no need to check the return value since no action is 
1846 taken when a Event Recorder function fail. The EventID macro (part of external Event Recorder) constructs the 
1847 ID based on input parameters which are shifted, masked with '&' and combined with '|'.
1848 Zero value input parameters are valid and cause zero used with '&' and '|'.
1849
1850 The usage of the Event Recorder implies the following MISRA deviations:
1851  - [MISRA 2012 Rule      11.1,  required]: Conversions shall not be performed between a pointer to a function and any other type
1852  - [MISRA 2012 Rule      11.4,  advisory]: A conversion should not be performed between a pointer to object and an integer type
1853  - [MISRA 2012 Rule      11.6,  required]: A cast shall not be performed between pointer to void and an arithmetic type
1854 In addition PC-Lint issues:
1855  - Info  835: A zero has been given as left argument to operator '&'
1856  - Info  845: The right argument to operator '|' is certain to be 0
1857
1858 The functions that call the Event Recorder are in the module \em rtx_evr.c and the related PC-Lint messages are disabled with:
1859 \code
1860   //lint -e923 -e9074 -e9078 -emacro((835,845),EventID) [MISRA Note 13]
1861 \endcode
1862
1863 */
1864
1865 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1866 /**
1867 \page rtosValidation RTOS Validation
1868
1869 Arm offers a <a class=el href="http://www.keil.com/pack" target="_blank">Software Pack</a> for the CMSIS-RTOS Validation.
1870 The <b>ARM::CMSIS-RTOS_Validation</b> Pack contains the following:
1871
1872  - Source code of a CMSIS-RTOS Validation Suite along with configuration file.
1873  - Documentation of the CMSIS-RTOS Validation Suite.
1874  - Example that shows the usage of the CMSIS-RTOS Validation Suite using simulation.
1875
1876 \note
1877 Currently, a public version of the test suite is available only for CMSIS-RTOS v1 API.
1878
1879 The CMSIS-RTOS Validation Suite performs generic validation of various RTOS features. The test cases verify the 
1880 functional behavior, test invalid parameters and call management functions from ISR.
1881
1882 The following CMSIS-RTOS features can be tested with the current release:
1883  - Thread : Create multiple threads, terminate, restart, yield, change priority 
1884  - Timer : Create periodic and one-shot timers
1885  - GenWait : Call generic wait functions (osDelay and osWait)
1886  - WaitFunc : Measure wait ticks (delay, mail, message, mutex, semaphore, signal)
1887  
1888 Moreover the following inter-thread communication functions can be tested: 
1889  - Signal : Verify signal events
1890  - Memory Pool : Verify memory allocation
1891  - Message Queue : Exchange messages between threads
1892  - Mail Queue : Exchange data between threads
1893  - Mutex : Synchronize resource access 
1894  - Semaphore : Access shared resources 
1895  
1896 The RTOS Validation output can be printed to a console, output via ITM printf, or output to a memory buffer.
1897  
1898 \section test_output Sample Test Output
1899 \verbatim
1900 CMSIS-RTOS Test Suite   Oct 21 2015   16:39:16 
1901
1902 TEST 01: TC_ThreadCreate                  PASSED
1903 TEST 02: TC_ThreadMultiInstance           PASSED
1904 TEST 03: TC_ThreadTerminate               PASSED
1905   :
1906   :
1907 TEST 08: TC_ThreadChainedCreate           PASSED
1908 TEST 09: TC_ThreadYield                   NOT EXECUTED
1909 TEST 10: TC_ThreadParam                   PASSED
1910   :
1911   :
1912 TEST 60: TC_MailFromISRToThread           PASSED
1913
1914 Test Summary: 60 Tests, 59 Executed, 59 Passed, 0 Failed, 0 Warnings.
1915 Test Result: PASSED
1916 \endverbatim
1917 */
1918
1919
1920 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1921 /**
1922 \page functionOverview Function Overview
1923
1924 CMSIS-RTOS v2 provides multiple API interfaces:
1925   - \subpage rtos_api2 is the new C function API that supports dynamic object creation and Armv8-M (Arm Cortex-M23 and
1926     Cortex-M33).
1927   - <a class="el" href="../../RTOS/html/functionOverview.html">CMSIS-RTOS C API v1</a> is a C function API that is backward
1928     compatible with CMSIS-RTOS v1.
1929   - \subpage rtos_apicpp is a C++ class function API.
1930
1931 It is possible to intermix the different API variants in the same application and even in the same C/C++ source module.
1932 However, the functions of the <b>C API Version 1</b> may be deprecated in future versions of CMSIS-RTOS.
1933
1934 \section rtos_api2 CMSIS-RTOS2
1935
1936 Overview of all CMSIS-RTOS C API v2 functions that are implemented in the \subpage cmsis_os2_h. 
1937
1938 \subsection rtos_api2_basics Common Design Concepts
1939
1940 All RTOS objects share a common design concept. The overall life-cycle of
1941 an object can be summarized as created -> in use -> destroyed.
1942
1943 <b>Create Objects</b>
1944
1945 An object is created by calling its `osXxxNew` function. The new function returns an identifier
1946 that can be used to operate with the new object. The actual state of an object is typically stored
1947 in an object specific control block. The memory layout (and size needed) for the control
1948 block is implementation specific. One should not make any specific assumptions about the control
1949 block. The control block layout might change and hence should be seen as an implementation
1950 internal detail.
1951
1952 In order to expose control about object specific options all `osXxxNew` functions provide an
1953 optional `attr` argument, which can be left as \token{NULL} by default. It takes a pointer to
1954 an object specific attribute structure, commonly containing the fields
1955  - `name` to attach a human readable name to the object for identification,
1956  - `attr_bits` to control object-specific options,
1957  - `cb_mem` to provide memory for the control block manually, and
1958  - `cb_size` to quantify the memory size provided for the control block.
1959
1960 The `name` attribute is only used for object identification, e.g. using RTOS-aware debugging. The
1961 attached string is not used for any other purposes internally.
1962
1963 The `cb_mem` and `cb_size` attributes can be used to provide memory for the control block manually
1964 instead of relying on the implementation internal memory allocation. One has to assure that the
1965 amount of memory pointed to by `cb_mem` is sufficient for the objects control block structure. If
1966 the size given as `cb_size` is not sufficient the `osXxxNew` function returns with an error, i.e.
1967 returning \token{NULL}. Furthermore providing control block memory manually is less portable. Thus
1968 one has to take care about implementation specific alignment and placement requirements for instance.
1969 Refer to \ref CMSIS_RTOS_MemoryMgmt for further details.
1970
1971 <b>Object Usage</b>
1972
1973 After an object has been created successfully it can be used until it is destroyed. The actions
1974 defined for an object depends on its type. Commonly all the `osXxxDoSomething` access function
1975 require the reference to the object to work with as the first `xxx_id` parameter.
1976
1977 The access function can be assumed to apply some sort of sanity checking on the id parameter. So
1978 that it is assured one cannot accidentally call an access function with a \token{NULL} object
1979 reference. Furthermore the concrete object type is verified, i.e. one cannot call access functions
1980 of one object type with a reference to another object type.
1981
1982 All further parameter checks applied are either object and action specific or may even be implementation
1983 specific. Thus one should always check action function return values for `osErrorParameter` to asure the
1984 provided arguments were accepted.
1985
1986 As a rule of thumb only non-blocking access function can be used from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines" (ISR).
1987 This incorporates `osXxxWait` functions (and similar) limited to be called with parameter `timeout`
1988 set to \token{0}, i.e. usage of try-semantics.
1989
1990 <b>Object Destruction</b>
1991
1992 Objects that are not needed anymore can be destructed on demand to free the control block memory. Objects
1993 are not destructed implicitly. Thus one can assume an object id to be valid until `osXxxDelete` is called
1994 explicitly. The delete function finally frees the control block memory. In case of user provided control
1995 block memory, see above, the memory must be freed manually as well. 
1996
1997 The only exception one has to take care of are Threads which do not have an explicit `osThreadDelete` function.
1998 Threads can either be `detached` or `joinable`. Detached threads are automatically destroyed on termination,
1999 i.e. call to \ref osThreadTerminate or \ref osThreadExit or return from thread function. On the other hand joinable
2000 threads are kept alive until one explicitly calls \ref osThreadJoin.
2001
2002 \subsection rtos_api2_functions Function Reference
2003
2004  - \ref CMSIS_RTOS_KernelCtrl
2005    - \ref osKernelGetInfo : \copybrief osKernelGetInfo
2006    - \ref osKernelGetState : \copybrief osKernelGetState
2007    - \ref osKernelGetSysTimerCount : \copybrief osKernelGetSysTimerCount
2008    - \ref osKernelGetSysTimerFreq : \copybrief osKernelGetSysTimerFreq
2009    - \ref osKernelInitialize : \copybrief osKernelInitialize
2010    - \ref osKernelLock : \copybrief osKernelLock
2011    - \ref osKernelUnlock : \copybrief osKernelUnlock
2012    - \ref osKernelRestoreLock : \copybrief osKernelRestoreLock
2013    - \ref osKernelResume : \copybrief osKernelResume
2014    - \ref osKernelStart : \copybrief osKernelStart
2015    - \ref osKernelSuspend : \copybrief osKernelSuspend
2016    - \ref osKernelGetTickCount : \copybrief osKernelGetTickCount
2017    - \ref osKernelGetTickFreq : \copybrief osKernelGetTickFreq
2018
2019  - \ref CMSIS_RTOS_ThreadMgmt
2020    - \ref osThreadDetach : \copybrief osThreadDetach
2021    - \ref osThreadEnumerate : \copybrief osThreadEnumerate
2022    - \ref osThreadExit : \copybrief osThreadExit
2023    - \ref osThreadGetCount : \copybrief osThreadGetCount
2024    - \ref osThreadGetId : \copybrief osThreadGetId
2025    - \ref osThreadGetName : \copybrief osThreadGetName
2026    - \ref osThreadGetPriority : \copybrief osThreadGetPriority
2027    - \ref osThreadGetStackSize : \copybrief osThreadGetStackSize
2028    - \ref osThreadGetStackSpace : \copybrief osThreadGetStackSpace
2029    - \ref osThreadGetState : \copybrief osThreadGetState
2030    - \ref osThreadJoin : \copybrief osThreadJoin
2031    - \ref osThreadNew : \copybrief osThreadNew
2032    - \ref osThreadResume : \copybrief osThreadResume
2033    - \ref osThreadSetPriority : \copybrief osThreadSetPriority
2034    - \ref osThreadSuspend : \copybrief osThreadSuspend
2035    - \ref osThreadTerminate : \copybrief osThreadTerminate
2036    - \ref osThreadYield : \copybrief osThreadYield
2037
2038  - \ref CMSIS_RTOS_ThreadFlagsMgmt
2039    - \ref osThreadFlagsSet : \copybrief osThreadFlagsSet
2040    - \ref osThreadFlagsClear : \copybrief osThreadFlagsClear
2041    - \ref osThreadFlagsGet : \copybrief osThreadFlagsGet
2042    - \ref osThreadFlagsWait : \copybrief osThreadFlagsWait
2043
2044  - \ref CMSIS_RTOS_EventFlags
2045    - \ref osEventFlagsGetName : \copybrief osEventFlagsGetName
2046    - \ref osEventFlagsNew : \copybrief osEventFlagsNew
2047    - \ref osEventFlagsDelete : \copybrief osEventFlagsDelete
2048    - \ref osEventFlagsSet : \copybrief osEventFlagsSet
2049    - \ref osEventFlagsClear : \copybrief osEventFlagsClear
2050    - \ref osEventFlagsGet : \copybrief osEventFlagsGet
2051    - \ref osEventFlagsWait : \copybrief osEventFlagsWait
2052
2053  - \ref CMSIS_RTOS_Wait
2054    - \ref osDelay : \copybrief osDelay
2055    - \ref osDelayUntil : \copybrief osDelayUntil
2056
2057  - \ref CMSIS_RTOS_TimerMgmt
2058    - \ref osTimerDelete : \copybrief osTimerDelete
2059    - \ref osTimerGetName : \copybrief osTimerGetName
2060    - \ref osTimerIsRunning : \copybrief osTimerIsRunning
2061    - \ref osTimerNew : \copybrief osTimerNew
2062    - \ref osTimerStart : \copybrief osTimerStart
2063    - \ref osTimerStop : \copybrief osTimerStop
2064
2065  - \ref CMSIS_RTOS_MutexMgmt
2066    - \ref osMutexAcquire : \copybrief osMutexAcquire
2067    - \ref osMutexDelete : \copybrief osMutexDelete
2068    - \ref osMutexGetName : \copybrief osMutexGetName
2069    - \ref osMutexGetOwner : \copybrief osMutexGetOwner
2070    - \ref osMutexNew : \copybrief osMutexNew
2071    - \ref osMutexRelease : \copybrief osMutexRelease
2072
2073  - \ref CMSIS_RTOS_SemaphoreMgmt
2074    - \ref osSemaphoreAcquire : \copybrief osSemaphoreAcquire
2075    - \ref osSemaphoreDelete : \copybrief osSemaphoreDelete
2076    - \ref osSemaphoreGetCount : \copybrief osSemaphoreGetCount
2077    - \ref osSemaphoreGetName : \copybrief osSemaphoreGetName
2078    - \ref osSemaphoreNew : \copybrief osSemaphoreNew
2079    - \ref osSemaphoreRelease : \copybrief osSemaphoreRelease
2080
2081  - \ref CMSIS_RTOS_PoolMgmt
2082    - \ref osMemoryPoolAlloc : \copybrief osMemoryPoolAlloc
2083    - \ref osMemoryPoolDelete : \copybrief osMemoryPoolDelete
2084    - \ref osMemoryPoolFree : \copybrief osMemoryPoolFree
2085    - \ref osMemoryPoolGetBlockSize : \copybrief osMemoryPoolGetBlockSize
2086    - \ref osMemoryPoolGetCapacity : \copybrief osMemoryPoolGetCapacity
2087    - \ref osMemoryPoolGetCount : \copybrief osMemoryPoolGetCount
2088    - \ref osMemoryPoolGetName : \copybrief osMemoryPoolGetName
2089    - \ref osMemoryPoolGetSpace : \copybrief osMemoryPoolGetSpace
2090    - \ref osMemoryPoolNew : \copybrief osMemoryPoolNew
2091
2092  - \ref CMSIS_RTOS_Message
2093    - \ref osMessageQueueDelete : \copybrief osMessageQueueDelete
2094    - \ref osMessageQueueGet : \copybrief osMessageQueueGet
2095    - \ref osMessageQueueGetCapacity : \copybrief osMessageQueueGetCapacity
2096    - \ref osMessageQueueGetCount : \copybrief osMessageQueueGetCount
2097    - \ref osMessageQueueGetMsgSize : \copybrief osMessageQueueGetMsgSize
2098    - \ref osMessageQueueGetName : \copybrief osMessageQueueGetName
2099    - \ref osMessageQueueGetSpace : \copybrief osMessageQueueGetSpace
2100    - \ref osMessageQueueNew : \copybrief osMessageQueueNew
2101    - \ref osMessageQueuePut : \copybrief osMessageQueuePut
2102    - \ref osMessageQueueReset : \copybrief osMessageQueueReset
2103  
2104  - \ref CMSIS_RTOS_TickAPI
2105    - \ref OS_Tick_Setup : \copybrief OS_Tick_Setup
2106    - \ref OS_Tick_Enable : \copybrief OS_Tick_Enable
2107    - \ref OS_Tick_Disable : \copybrief OS_Tick_Disable
2108    - \ref OS_Tick_AcknowledgeIRQ : \copybrief OS_Tick_AcknowledgeIRQ
2109    - \ref OS_Tick_GetIRQn : \copybrief OS_Tick_GetIRQn
2110    - \ref OS_Tick_GetClock : \copybrief OS_Tick_GetClock
2111    - \ref OS_Tick_GetInterval : \copybrief OS_Tick_GetInterval
2112    - \ref OS_Tick_GetCount : \copybrief OS_Tick_GetCount
2113    - \ref OS_Tick_GetOverflow : \copybrief OS_Tick_GetOverflow
2114
2115  - \ref rtx5_specific
2116    - \ref osRtxErrorNotify : \copybrief osRtxErrorNotify
2117    - \ref osRtxIdleThread : \copybrief osRtxIdleThread
2118
2119 The following CMSIS-RTOS2 functions can be called from threads and \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines"
2120 (ISR):
2121    - \ref osKernelGetInfo, \ref osKernelGetState,
2122      \ref osKernelGetTickCount, \ref osKernelGetTickFreq, \ref osKernelGetSysTimerCount, \ref osKernelGetSysTimerFreq
2123    - \ref osThreadFlagsSet
2124    - \ref osEventFlagsSet, \ref osEventFlagsClear, \ref osEventFlagsGet, \ref osEventFlagsWait
2125    - \ref osSemaphoreAcquire, \ref osSemaphoreRelease, \ref osSemaphoreGetCount
2126    - \ref osMemoryPoolAlloc, \ref osMemoryPoolFree, \ref osMemoryPoolGetCapacity, \ref osMemoryPoolGetBlockSize,
2127      \ref osMemoryPoolGetCount, \ref osMemoryPoolGetSpace
2128    - \ref osMessageQueuePut, \ref osMessageQueueGet, \ref osMessageQueueGetCapacity, \ref osMessageQueueGetMsgSize,
2129      \ref osMessageQueueGetCount, \ref osMessageQueueGetSpace
2130 */
2131
2132
2133 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2134 /**
2135 \page rtos_apicpp CMSIS-RTOS C++ API
2136
2137 A C++11/C++14 interface is planned for the future.
2138 */
2139
2140
2141 /* ======================================================================================================================== */
2142 // Group creation for Reference 
2143 /* 
2144 \addtogroup CMSIS_RTOS1 CMSIS-RTOS API v1
2145 \brief This section describes the CMSIS-RTOS API v1. 
2146 \details 
2147 The CMSIS-RTOS is a generic API layer that interfaces to an existing RTOS kernel.
2148
2149 CMSIS-RTOS API v2 provides an translation layer for the
2150 <a class="el" href="../../RTOS/html/index.html">CMSIS-RTOS API v1</a> that simplifies migration.
2151
2152 Refer to the <a class="el" href="../../RTOS/html/modules.html">Reference</a> guide of the CMSIS-RTOS API v1 for details.
2153 */
2154
2155 // Group creation for Reference 
2156 /** 
2157 \addtogroup CMSIS_RTOS CMSIS-RTOS2 API
2158 \brief Describes the C function interface of CMSIS-RTOS API v2. 
2159 \details 
2160 The CMSIS-RTOS2 is a generic API layer that interfaces to an RTOS kernel.
2161
2162 The complete API interface is defined in the \ref cmsis_os2_h. When using dynamic memory allocation for objects, source code
2163 or libraries require no modifications when using on a different CMSIS-RTOS2 implementation.
2164
2165 Refer to \ref rtos_api2_basics for further details.
2166 */
2167
2168 /**
2169 \addtogroup CMSIS_RTOS_MemoryMgmt Memory Management
2170 \ingroup CMSIS_RTOS
2171 \brief Information about memory management possibilities
2172 \details
2173 The \ref CMSIS_RTOS offers two options for memory management the user can choose. For object storage one can either use
2174  - \ref CMSIS_RTOS_MemoryMgmt_Automatic (fully portable), or
2175  - \ref CMSIS_RTOS_MemoryMgmt_Manual (implementation specific).
2176  
2177 In order to affect the memory allocation scheme all RTOS objects that can be created on request, i.e. those having a `osXxxNew`
2178 function, accept an optional `osXxxAttr_t attr` argument on creation. As a rule of thumb the object attributes at least have
2179 members to assign custom control block memory, i.e. `cb_mem` and `cb_size` members. By default, i.e. `attr` is `NULL`
2180 or `cb_mem` is `NULL`, \ref CMSIS_RTOS_MemoryMgmt_Automatic is used. Providing a pointer to user memory in `cb_mem` switches
2181 to \ref CMSIS_RTOS_MemoryMgmt_Manual.
2182
2183 \note For detailed information about memory allocation strategies provided in RTX5 refer to \ref MemoryAllocation.
2184
2185 \section CMSIS_RTOS_MemoryMgmt_Automatic Automatic Dynamic Allocation
2186
2187 The automatic allocation is the default and viable for many use-cases. Moreover it is fully portable across different
2188 implementations of the \ref CMSIS_RTOS. The common drawback of dynamic memory allocation is the possibility of memory
2189 fragmentation and exhaustion. Given that all needed objects are created once upon system initialization and never
2190 deleted at runtime this class of runtime failures can be prevented, though.
2191
2192 The actual allocation strategy used is implementation specific, i.e. whether global heap or preallocated memory pools are used.
2193
2194 <b> Code Example:</b> 
2195 \code{.c}
2196 #include "cmsis_os2.h"                          // implementation agnostic
2197   
2198 osMutexId_t mutex_id;
2199 osMutexId_t mutex2_id;
2200   
2201 const osMutexAttr_t Thread_Mutex_attr = {
2202   "myThreadMutex",                              // human readable mutex name
2203   osMutexRecursive | osMutexPrioInherit,        // attr_bits
2204   NULL,                                         // memory for control block (default)
2205   0U                                            // size for control block (default)
2206 };
2207   
2208 void CreateMutex (void)  {
2209   mutex_id = osMutexNew(NULL);                  // use default values for all attributes
2210   mutex2_id = osMutexNew(&Thread_Mutex_attr);   // use attributes from defined structure
2211   :
2212 }
2213 \endcode
2214
2215 The Mutexes in this example are created using automatic memory allocation.
2216
2217 \section CMSIS_RTOS_MemoryMgmt_Manual Manual User-defined Allocation
2218
2219 One can get fine grained control over memory allocation by providing user-defined memory.
2220 The actual requirements such user-defined memory are implementation specific. Thus one
2221 needs to carefully refer to the size and alignment rules of the implementation used, e.g.
2222 for RTX see \ref StaticObjectMemory.
2223
2224 <b> Code Example:</b> 
2225 \code{.c}
2226 #include "rtx_os.h"                             // implementation specific
2227   
2228 osMutexId_t mutex_id;
2229   
2230 static uint32_t mutex_cb[osRtxMutexCbSize/4U];  // implementation specific
2231   
2232 const osMutexAttr_t Thread_Mutex_attr = {
2233   "myThreadMutex",                              // human readable mutex name
2234   osMutexRecursive | osMutexPrioInherit,        // attr_bits
2235   mutex_cb,                                     // memory for control block (user-defined)
2236   sizeof(mutex_cb)                              // size for control block (user-defined)
2237 };
2238   
2239 void CreateMutex (void)  {
2240   mutex_id = osMutexNew(&Thread_Mutex_attr);    // use attributes from defined structure
2241   :
2242 }
2243 \endcode
2244
2245 The above example uses user-defined memory for the mutex control block. Depending on the actual
2246 implementation used one needs to include the specific header file, `rtx_os.h` in this case.
2247
2248 */
2249
2250 /** 
2251 \addtogroup rtx5_specific RTX5 Specific API
2252 \brief This section describes CMSIS-RTOS RTX5 specifics.
2253 \details
2254 The RTX5 kernel can be customized for different application requirements:
2255 - If you are depending on the \ref lowPower "lowest power consumption" possible, you need to adapt the function
2256   \ref osRtxIdleThread to send the system to sleep mode as often as possible. In addition, use the
2257   \ref TickLess "tick-less low power" functions \ref osKernelSuspend and \ref osKernelResume to suspend the scheduler and to
2258   stop the SysTick timer.
2259 - If you try to find a \b runtime \b error, use the function \ref osRtxErrorNotify to debug the error.
2260
2261 RTX5 interfaces to the <a href="http://www.keil.com/pack/doc/compiler/EventRecorder/html/index.html" target="_blank"><b>Event Recorder</b></a> 
2262 to provide event information which helps you to understand and analyze the operation. Refer to \ref rtx_evr for more
2263 information.
2264
2265
2266 @{
2267 */
2268
2269 /**
2270 \defgroup rtx5_specific_defines Macros
2271 \brief RTX5 macros
2272 \details
2273 @{
2274 */
2275
2276 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2277 /**
2278 \def osRtxThreadCbSize
2279 \brief Thread Control Block size
2280 \details
2281 This macro exposes the minimum amount of memory needed for an RTX5 Thread Control Block,
2282 see osThreadAttr_t::cb_mem and \ref osThreadAttr_t::cb_size.
2283
2284 Example:
2285 \code
2286 // Used-defined memory for thread control block
2287 static uint32_t thread_cb[osRtxThreadCbSize/4U];
2288 \endcode
2289 */
2290
2291 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2292 /**
2293 \def osRtxTimerCbSize
2294 \brief Timer Control Block size
2295 \details
2296 This macro exposes the minimum amount of memory needed for an RTX5 Timer Control Block,
2297 see osTimerAttr_t::cb_mem and \ref osTimerAttr_t::cb_size.
2298
2299 Example:
2300 \code
2301 // Used-defined memory for timer control block
2302 static uint32_t timer_cb[osRtxTimerCbSize/4U];
2303 \endcode
2304 */
2305
2306 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2307 /**
2308 \def osRtxEventFlagsCbSize
2309 \brief Event Flags Control Block size
2310 \details
2311 This macro exposes the minimum amount of memory needed for an RTX5 Event Flags Control Block,
2312 see osEventFlagsAttr_t::cb_mem and \ref osEventFlagsAttr_t::cb_size.
2313
2314 Example:
2315 \code
2316 // Used-defined memory for event flags control block
2317 static uint32_t evflags_cb[osRtxEventFlagsCbSize/4U];
2318 \endcode
2319 */
2320
2321 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2322 /**
2323 \def osRtxMutexCbSize
2324 \brief Mutex Control Block size
2325 \details
2326 This macro exposes the minimum amount of memory needed for an RTX5 Mutex Control Block,
2327 see osMutexAttr_t::cb_mem and \ref osMutexAttr_t::cb_size.
2328
2329 Example:
2330 \code
2331 // Used-defined memory for mutex control block
2332 static uint32_t mutex_cb[osRtxMutexCbSize/4U];
2333 \endcode
2334 */
2335
2336 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2337 /**
2338 \def osRtxSemaphoreCbSize
2339 \brief Semaphore Control Block size
2340 \details
2341 This macro exposes the minimum amount of memory needed for an RTX5 Semaphore Control Block,
2342 see osSemaphoreAttr_t::cb_mem and osSemaphoreAttr_t::cb_size.
2343
2344 Example:
2345 \code
2346 // Used-defined memory for semaphore control block
2347 static uint32_t sema_cb[osRtxSemaphoreCbSize/4U];
2348 \endcode
2349 */
2350
2351 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2352 /**
2353 \def osRtxMemoryPoolCbSize
2354 \brief Memory Pool Control Block size
2355 \details
2356 This macro exposes the minimum amount of memory needed for an RTX5 Memory Pool Control Block,
2357 see osMemoryPoolAttr_t::cb_mem and osMemoryPoolAttr_t::cb_size.
2358
2359 Example:
2360 \code
2361 // Used-defined memory for memory pool control block
2362 static uint32_t timer_cb[osRtxMemoryPoolCbSize/4U];
2363 \endcode
2364 */
2365
2366 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2367 /**
2368 \def osRtxMessageQueueCbSize
2369 \brief Message Queue Control Block size
2370 \details
2371 This macro exposes the minimum amount of memory needed for an RTX5 Message Queue Control Block,
2372 see osMessageQueueAttr_t::cb_mem and osMessageQueueAttr_t::cb_size.
2373
2374 Example:
2375 \code
2376 // Used-defined memory for message queue control block
2377 static uint32_t msgqueue_cb[osRtxMessageQueueCbSize/4U];
2378 \endcode
2379 */
2380
2381 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2382 /**
2383 \def osRtxMemoryPoolMemSize
2384 \brief Memory Pool Memory size
2385 \details
2386 This macro exposes the minimum amount of memory needed for an RTX5 Memory Pool Memory,
2387 see osMemoryPoolAttr_t::mp_mem and osMemoryPoolAttr_t::mp_size.
2388
2389 Example:
2390 \code
2391 // Maximum number of objects
2392 #define OBJ_COUNT 8U
2393  
2394 // Object type
2395 typedef struct {
2396    uint32_t value1;
2397    uint8_t  value2;
2398 } object_t;
2399  
2400 // Used-defined memory for memory pool memory
2401 static uint32_t mempool_cb[osRtxMemoryPoolMemSize(OBJ_COUNT, sizeof(object_t))/4U];
2402 \endcode
2403 */
2404
2405 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2406 /**
2407 \def osRtxMessageQueueMemSize
2408 \brief Message Queue Memory size
2409 \details
2410 This macro exposes the minimum amount of memory needed for an RTX5 Message Queue Memory,
2411 see osMessageQueueAttr_t::mq_mem and osMessageQueueAttr_t::mq_size.
2412
2413 Example:
2414 \code
2415 // Maximum number of messages
2416 #define MSG_COUNT 16U
2417  
2418 // Message data type
2419 typedef struct {
2420    uint32_t value1;
2421    uint8_t  value2;
2422 } msg_item_t;
2423  
2424 // Used-defined memory for message queue
2425 static uint32_t mq_mem[osRtxMessageQueueMemSize(MSG_COUNT, sizeof(msg_item_t))/4U];
2426 \endcode
2427 */
2428
2429 /**
2430 @}
2431 */
2432
2433 /**
2434 \defgroup rtx5_specific_structs Structs
2435 \brief RTX5 structs 
2436 \details
2437 @{
2438 */
2439
2440 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2441 /**
2442 \struct osRtxThread_t
2443 */
2444
2445 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2446 /**
2447 \struct osRtxTimerFinfo_t
2448 */
2449
2450 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2451 /**
2452 \struct osRtxTimer_t
2453 */
2454
2455 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2456 /**
2457 \struct osRtxEventFlags_t
2458 */
2459
2460 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2461 /**
2462 \struct osRtxMutex_t
2463 */
2464
2465 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2466 /**
2467 \struct osRtxSemaphore_t
2468 */
2469
2470 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2471 /**
2472 \struct osRtxMemoryPool_t
2473 */
2474
2475 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2476 /**
2477 \struct osRtxMessageQueue_t
2478 */
2479
2480 /**
2481 @}
2482 */
2483
2484 /**
2485 \defgroup rtx5_specific_functions Functions
2486 \brief RTX5 functions 
2487 \details
2488 @{
2489 */
2490
2491 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2492 /** 
2493 \fn uint32_t osRtxErrorNotify (uint32_t code, void *object_id);
2494 \details
2495 Some system error conditions can be detected during runtime. If the RTX kernel detects a runtime error, it calls the runtime
2496 error function \b osRtxErrorNotify for an object specified by parameter \a object_id.
2497
2498 The parameter \a code passes the actual error code to this function:
2499 | Error Code                   | Description                                                                       |
2500 |------------------------------|-----------------------------------------------------------------------------------|
2501 | osRtxErrorStackUnderflow     | Stack overflow detected for thread (thread_id=object_id)                          |
2502 | osRtxErrorISRQueueOverflow   | ISR Queue overflow detected when inserting object (object_id)                     |
2503 | osRtxErrorTimerQueueOverflow | User Timer Callback Queue overflow detected for timer (timer_id=object_id)        |
2504 | osRtxErrorClibSpace          | Standard C/C++ library libspace not available: increase \c OS_THREAD_LIBSPACE_NUM |
2505 | osRtxErrorClibMutex          | Standard C/C++ library mutex initialization failed                                |
2506
2507 The function \b osRtxErrorNotify must contain an infinite loop to prevent further program execution. You can use an emulator
2508 to step over the infinite loop and trace into the code introducing a runtime error. For the overflow errors this means you
2509 need to increase the size of the object causing an overflow.
2510
2511 \note Cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
2512
2513 <b>Code Example</b>
2514 \code
2515 #include "rtx_os.h"
2516  
2517 uint32_t osRtxErrorNotify (uint32_t code, void *object_id) {
2518   (void)object_id;
2519  
2520   switch (code) {
2521     case osRtxErrorStackUnderflow:
2522       // Stack overflow detected for thread (thread_id=object_id)
2523       break;
2524     case osRtxErrorISRQueueOverflow:
2525       // ISR Queue overflow detected when inserting object (object_id)
2526       break;
2527     case osRtxErrorTimerQueueOverflow:
2528       // User Timer Callback Queue overflow detected for timer (timer_id=object_id)
2529       break;
2530     case osRtxErrorClibSpace:
2531       // Standard C/C++ library libspace not available: increase OS_THREAD_LIBSPACE_NUM
2532       break;
2533     case osRtxErrorClibMutex:
2534       // Standard C/C++ library mutex initialization failed
2535       break;
2536     default:
2537       break;
2538   }
2539   for (;;) {}
2540 //return 0U;
2541 }
2542 \endcode
2543 */
2544
2545 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2546 osRtxErrorClibMutex         /** 
2547 \fn void osRtxIdleThread (void *argument);
2548 \details
2549 The function \b osRtxIdleThread is executed by the RTX kernel, when no other threads are ready to run. By default, this
2550 thread is an empty end-less loop that does nothing. It only waits until another task becomes ready to run. You may change the
2551 code of the \b osRtxIdleThread function to put the CPU into a power-saving or idle mode, see \ref TickLess.
2552
2553 The default stack size for this thread is defined in the file RTX_Config.h. Refer to \ref threadConfig.
2554
2555 \note Cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
2556
2557 <b>Code Example</b>
2558 \code
2559 #include "rtx_os.h"
2560  
2561 __NO_RETURN void osRtxIdleThread (void *argument) {
2562   (void)argument;
2563
2564   for (;;) {}
2565 }
2566 \endcode
2567 */ 
2568
2569 /**
2570 @}
2571 */
2572
2573 /// @}