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