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