summaryrefslogtreecommitdiff
path: root/docs/RTOS2/html/theory_of_operation.html
blob: a285476ca386e2a3926a71809556699b0fd91412 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Theory of Operation</title>
<title>CMSIS-RTOS2: Theory of Operation</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="cmsis.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script type="text/javascript" src="printComponentTabs.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 46px;">
  <td id="projectlogo"><img alt="Logo" src="CMSIS_Logo_Final.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">CMSIS-RTOS2
   &#160;<span id="projectnumber">Version 2.1.3</span>
   </div>
   <div id="projectbrief">Real-Time Operating System: API and RTX Reference Implementation</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<div id="CMSISnav" class="tabs1">
    <ul class="tablist">
      <script type="text/javascript">
		<!--
		writeComponentTabs.call(this);
		//-->
      </script>
	  </ul>
</div>
<!-- Generated by Doxygen 1.8.6 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Usage&#160;and&#160;Description</span></a></li>
      <li><a href="modules.html"><span>Reference</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('theory_of_operation.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Macros</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">Theory of Operation </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>Many aspects of the kernel are configurable and the configuration options are mentioned where applicable.</p>
<h1><a class="anchor" id="SystemStartup"></a>
System Startup</h1>
<p>Since main is no longer a thread RTX5 does not interfere with the system startup until main is reached. Once the execution reaches <code>main()</code> there is a recommended order to initialize the hardware and start the kernel. This is also reflected in the user code template file "CMSIS-RTOS2 'main' function" supplied with the RTX5 component.</p>
<p>Your application's <code>main()</code> should implement at least the following in the given order:</p>
<ol type="1">
<li>Initialization and configuration of hardware including peripherals, memory, pins, clocks and the interrupt system.</li>
<li>Update the system core clock using the respective <a href="../../Core/html/group__system__init__gr.html">CMSIS-Core (Cortex-M)</a> or <a href="../../Core_A/html/group__system__init__gr.html">CMSIS-Core (Cortex-A)</a> function.</li>
<li>Initialize the CMSIS-RTOS kernel using <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#gae818f6611d25ba3140bede410a52d659">osKernelInitialize</a>.</li>
<li>Optionally, create one thread (for example <code>app_main</code>), which is used as a main thread using <a class="el" href="group__CMSIS__RTOS__ThreadMgmt.html#ga48d68b8666d99d28fa646ee1d2182b8f">osThreadNew</a>. This thread should take care of creating and starting objects, once it is run by the scheduler. Alternatively, threads can be created in <code>main()</code> directly.</li>
<li>Start the RTOS scheduler using <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga9ae2cc00f0d89d7b6a307bba942b5221">osKernelStart</a> which also configures the system tick timer and initializes RTOS specific interrupts. This function does not return in case of successful execution. Therefore, any application code after <b>osKernelStart</b> will not be executed.</li>
</ol>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>Modifying priorities and groupings in the NVIC by the application after the above sequence is not recommended.</li>
<li>Before executing <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga9ae2cc00f0d89d7b6a307bba942b5221">osKernelStart</a>, only the functions <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga6f7764e7250c5c5364c00c45a5d1d199">osKernelGetInfo</a>, <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga48b69b81012fce051f639be288b243ba">osKernelGetState</a>, and object creation functions (osXxxNew) may be called.</li>
</ul>
</dd></dl>
<h1><a class="anchor" id="Scheduler"></a>
Scheduler</h1>
<p>RTX5 implements a low-latency preemptive scheduler. Major parts of RTX5 are executed in handler mode such as</p>
<ul>
<li><a class="el" href="rtx__os_8h.html#ab5e09814056d617c521549e542639b7e">SysTick_Handler</a> used for time-based scheduling.</li>
<li><a class="el" href="rtx__os_8h.html#a3e5ddb3df0d62f2dc357e64a3f04a6ce">SVC_Handler</a> used for lock-based scheduling.</li>
<li><a class="el" href="rtx__os_8h.html#a6303e1f258cbdc1f970ce579cc015623">PendSV_Handler</a> used for interrupt-based scheduling.</li>
</ul>
<p>In order to be low-latency with respect to ISR execution those system exceptions are configured to use the lowest priority groups available. The priorities are configured such that no preemption happens between them. Thus no interrupt critical sections (i.e. interrupt locks) are needed to protect the scheduler.</p>
<div class="image">
<img src="scheduling.png" alt="scheduling.png"/>
<div class="caption">
Thread scheduling and interrupt execution</div></div>
<p> The scheduler combines priority and round-robin based context switches. The example depicted in the image above contains 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 (<a class="el" href="group__CMSIS__RTOS__ThreadMgmt.html#a6a5183df4c54c3e28dc8dc704f2487d5">osThreadAttr_t::priority</a>). As long as threads 3 and 4 are blocked the scheduler switches between thread 1 and 2 on a time-slice basis (round-robin). The time-slice for round-robin scheduling can be configured, see Round-Robin Timeout in <a class="el" href="config_rtx5.html#systemConfig">System Configuration</a>.</p>
<p>Thread 2 unblocks thread 3 by an arbitrary RTOS-call (executed in <a class="el" href="theory_of_operation.html#CMSIS_RTOS_svcFunctions">SVC</a> handler mode) at time index 2. The scheduler switches to thread 3 immediately because thread 3 has the highest priority. Thread 4 is still blocked.</p>
<p>At time index 4 an interrupt (ISR) occurs and preempts the SysTick_Handler. RTX does not add any latency to the interrupt service execution. The ISR routine uses an RTOS-call that unblocks thread 4. Instead of switching to thread 4 immediately the PendSV flag is set to defer the context switching. The PendSV_Handler is executed right after the SysTick_Handler returns and the deferred context switch to thread 4 is carried out. As soon as highest priority thread 4 blocks again by using a blocking RTOS-call execution is switched back to thread 3 immediately during time index 5.</p>
<p>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. At time index 7 the scheduler uses the round-robin mechanism to switch to thread 1 and so on.</p>
<h1><a class="anchor" id="MemoryAllocation"></a>
Memory Allocation</h1>
<p>RTX5 objects (thread, mutex, semaphore, timer, message queue, thread and event flags, as well as memory pool) require dedicated RAM memory. Objects can be created using os<em>Object</em>New() calls and deleted using os<em>Object</em>Delete() calls. The related object memory needs to be available during the lifetime of the object.</p>
<p>RTX5 offers three different memory allocation methods for objects:</p>
<ul>
<li><a class="el" href="theory_of_operation.html#GlobalMemoryPool">Global Memory Pool</a> uses a single global memory pool for all objects. It is easy to configure, but may have the disadvantage for memory fragmentation when objects with different sizes are created and destroyed.</li>
<li><a class="el" href="theory_of_operation.html#ObjectMemoryPool">Object-specific Memory Pools</a> uses a fixed-size memory pool for each object type. The method is time deterministic and avoids memory fragmentation.</li>
<li><a class="el" href="theory_of_operation.html#StaticObjectMemory">Static Object Memory</a> reserves memory during compile time and completely avoids that a system can be out of memory. This is typically a required for some safety critical systems.</li>
</ul>
<p>It possible to intermix all the memory allocation methods in the same application.</p>
<h2><a class="anchor" id="GlobalMemoryPool"></a>
Global Memory Pool</h2>
<p>The global memory pool allocates all objects from a memory area. This method of memory allocation is the default configuration setting of RTX5.</p>
<div class="image">
<img src="MemAllocGlob.png" alt="MemAllocGlob.png"/>
<div class="caption">
Global Memory Pool for all objects</div></div>
<p> When the memory pool does not provide sufficient memory, the creation of the object fails and the related os<em>Object</em>New() function returns <span class="XML-Token">NULL</span>.</p>
<p>Enabled in <a class="el" href="config_rtx5.html#systemConfig">System Configuration</a>.</p>
<h2><a class="anchor" id="ObjectMemoryPool"></a>
Object-specific Memory Pools</h2>
<p>Object-specific memory pools avoids memory fragmentation with a dedicated fixed-size memory management for each object type. This type of memory pools are fully time deterministic, which means that object creation and destruction takes always the same fixed amount of time. As a fixed-size memory pool is specific to an object type, the handling of out-of-memory situations is simplified.</p>
<div class="image">
<img src="MemAllocSpec.png" alt="MemAllocSpec.png"/>
<div class="caption">
One memory pool per object type</div></div>
<p> Object-specific memory pools are selectively enabled for each object type, e.g: mutex or thread using the RTX configuration file:</p>
<ul>
<li>Enabled in <a class="el" href="config_rtx5.html#threadConfig">Thread Configuration</a> for thread objects.</li>
<li>Enabled in <a class="el" href="config_rtx5.html#timerConfig">Timer Configuration</a> for timer objects.</li>
<li>Enabled in <a class="el" href="config_rtx5.html#eventFlagsConfig">Event Flags Configuration</a> for event objects.</li>
<li>Enabled in <a class="el" href="config_rtx5.html#mutexConfig">Mutex Configuration</a> for mutex objects.</li>
<li>Enabled in <a class="el" href="config_rtx5.html#semaphoreConfig">Semaphore Configuration</a> for semaphore.</li>
<li>Enabled in <a class="el" href="config_rtx5.html#memPoolConfig">Memory Pool Configuration</a> for memory pools.</li>
<li>Enabled in <a class="el" href="config_rtx5.html#msgQueueConfig">Message Queue Configuration</a> for message objects.</li>
</ul>
<p>When the memory pool does not provide sufficient memory, the creation of the object fails and the related os<em>Object</em>New() function returns <span class="XML-Token">NULL</span>.</p>
<h2><a class="anchor" id="StaticObjectMemory"></a>
Static Object Memory</h2>
<p>In contrast to the dynamic memory allocations, the static memory allocation requires compile-time allocation of object memory.</p>
<div class="image">
<img src="MemAllocStat.png" alt="MemAllocStat.png"/>
<div class="caption">
Statically allocated memory for all objects</div></div>
<p> Static memory allocation can be achieved by providing user-defined memory using attributes at object creation, see <a class="el" href="group__CMSIS__RTOS__MemoryMgmt.html#CMSIS_RTOS_MemoryMgmt_Manual">Manual User-defined Allocation</a>. Please take special note of the following restrictions:</p>
<table class="doxtable">
<tr>
<th>Memory type </th><th>Requirements  </th></tr>
<tr>
<td>Control Block (osXxxAttr_t::cb_mem) </td><td>4-Byte alignment. Size defined by <a class="el" href="group__rtx5__specific__defines.html#ga30d19272204231956582ebfff69567f6">osRtxThreadCbSize</a>, <a class="el" href="group__rtx5__specific__defines.html#gaf8a145fdeb24fd912971f0671b1a3603">osRtxTimerCbSize</a>, <a class="el" href="group__rtx5__specific__defines.html#ga68100c8c44931f03547973294c433075">osRtxEventFlagsCbSize</a>, <a class="el" href="group__rtx5__specific__defines.html#ga188bfaaf7477cf24cbc9f207feaeb53a">osRtxMutexCbSize</a>, <a class="el" href="group__rtx5__specific__defines.html#ga0949b67063d0bd427fbee9c816b5d45a">osRtxSemaphoreCbSize</a>, <a class="el" href="group__rtx5__specific__defines.html#gab8e49e9e1eea5a015f2a3114cabceb48">osRtxMemoryPoolCbSize</a>, <a class="el" href="group__rtx5__specific__defines.html#gaa8d067c476faa6bfc8e5e21f3b3c844e">osRtxMessageQueueCbSize</a>. </td></tr>
<tr>
<td>Thread Stack (<a class="el" href="group__CMSIS__RTOS__ThreadMgmt.html#ad7c9b42355a4c8b9467130ab3fb19e43" title="memory for stack ">osThreadAttr_t::stack_mem</a>) </td><td>8-Byte alignment. Size is application specific, i.e. amount of stack variables and frames. </td></tr>
<tr>
<td>Memory Pool (<a class="el" href="group__CMSIS__RTOS__PoolMgmt.html#a5799465cca9c71c5587ceb0986f5b06a" title="memory for data storage ">osMemoryPoolAttr_t::mp_mem</a>) </td><td>4-Byte alignment. Size calculated with <a class="el" href="group__rtx5__specific__defines.html#gac6bea3541b458bbc79eafce42a2d87a2">osRtxMemoryPoolMemSize</a>. </td></tr>
<tr>
<td>Message Queue (<a class="el" href="group__CMSIS__RTOS__Message.html#a4e208dc0fb049b42c4b90cbd2791c5ad" title="memory for data storage ">osMessageQueueAttr_t::mq_mem</a>) </td><td>4-Byte alignment. Size calculated with <a class="el" href="group__rtx5__specific__defines.html#ga47eb1e21f1bf9a42281c6c89c7473e99">osRtxMessageQueueMemSize</a>. </td></tr>
</table>
<p>In order to allow RTX5 aware debugging, i.e. Component Viewer, to recognize control blocks these needs to be placed in individual memory sections, i.e. using <code>__attribute__((section(...)))</code>.</p>
<table class="doxtable">
<tr>
<th>RTX Object </th><th>Linker Section  </th></tr>
<tr>
<td>Thread </td><td><code>.bss.os.thread.cb</code> </td></tr>
<tr>
<td>Timer </td><td><code>.bss.os.timer.cb</code> </td></tr>
<tr>
<td>Event Flags </td><td><code>.bss.os.evflags.cb</code> </td></tr>
<tr>
<td>Mutex </td><td><code>.bss.os.mutex.cb</code> </td></tr>
<tr>
<td>Semaphore </td><td><code>.bss.os.semaphore.cb</code> </td></tr>
<tr>
<td>Memory Pool </td><td><code>.bss.os.mempool.cb</code> </td></tr>
<tr>
<td>Message Queue </td><td><code>.bss.os.msgqueue.cb</code> </td></tr>
</table>
<p>It must be assured that these sections are placed into contiguous memory. This can fail, i.e. sections end up being split over multiple memory segments, when assigning compilation units to memory segments, manually.</p>
<p>The following code example shows how to create an OS object using static memory.</p>
<p><b> Code Example:</b> </p>
<div class="fragment"><div class="line"><span class="comment">/*----------------------------------------------------------------------------</span></div>
<div class="line"><span class="comment"> * CMSIS-RTOS &#39;main&#39; function template</span></div>
<div class="line"><span class="comment"> *---------------------------------------------------------------------------*/</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &quot;RTE_Components.h&quot;</span></div>
<div class="line"><span class="preprocessor">#include  CMSIS_device_header</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#include &quot;<a class="code" href="cmsis__os2_8h.html">cmsis_os2.h</a>&quot;</span></div>
<div class="line"> </div>
<div class="line"><span class="comment">//include rtx_os.h for types of RTX objects</span></div>
<div class="line"><span class="preprocessor">#include &quot;<a class="code" href="rtx__os_8h.html">rtx_os.h</a>&quot;</span></div>
<div class="line"> </div>
<div class="line"><span class="comment">//The thread function instanced in this example</span></div>
<div class="line"><span class="keywordtype">void</span> worker(<span class="keywordtype">void</span> *arg)</div>
<div class="line">{</div>
<div class="line">  <span class="keywordflow">while</span>(1) </div>
<div class="line">  {</div>
<div class="line">    <span class="comment">//work</span></div>
<div class="line">    <a class="code" href="group__CMSIS__RTOS__Wait.html#gaf6055a51390ef65b6b6edc28bf47322e">osDelay</a>(10000);</div>
<div class="line">  }  </div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Define objects that are statically allocated for worker thread 1</span></div>
<div class="line">__attribute__((section(<span class="stringliteral">&quot;.bss.os.thread.cb&quot;</span>)))</div>
<div class="line"><a class="code" href="rtx__os_8h.html#structosRtxThread__t">osRtxThread_t</a> worker_thread_tcb_1;</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Reserve two areas for the stacks of worker thread 1</span></div>
<div class="line"><span class="comment">// uint64_t makes sure the memory alignment is 8</span></div>
<div class="line">uint64_t worker_thread_stk_1[64];</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Define the attributes which are used for thread creation</span></div>
<div class="line"><span class="comment">// Optional const saves RAM memory and includes the values in periodic ROM tests </span></div>
<div class="line">const <a class="code" href="group__CMSIS__RTOS__ThreadMgmt.html#structosThreadAttr__t">osThreadAttr_t</a> worker_attr_1 = {</div>
<div class="line">  <span class="stringliteral">&quot;wrk1&quot;</span>,</div>
<div class="line">  <a class="code" href="group__CMSIS__RTOS__ThreadMgmt.html#ga249499c519f3f8eef5673009ab6cfcbe">osThreadJoinable</a>,</div>
<div class="line">  &amp;worker_thread_tcb_1,</div>
<div class="line">  <span class="keyword">sizeof</span>(worker_thread_tcb_1),</div>
<div class="line">  &amp;worker_thread_stk_1[0],</div>
<div class="line">  <span class="keyword">sizeof</span>(worker_thread_stk_1),</div>
<div class="line">  <a class="code" href="cmsis__os2_8h.html#gad4e3e0971b41f2d17584a8c6837342eca17b36cd9cd38652c2bc6d4803990674b">osPriorityAboveNormal</a>,</div>
<div class="line">  0</div>
<div class="line">};</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Define ID object for thread</span></div>
<div class="line"><a class="code" href="group__CMSIS__RTOS__ThreadMgmt.html#gaa6c32fe2a3e0a2e01f212d55b02e51c7">osThreadId_t</a> th1;</div>
<div class="line"> </div>
<div class="line"><span class="comment">/*----------------------------------------------------------------------------</span></div>
<div class="line"><span class="comment"> * Application main thread</span></div>
<div class="line"><span class="comment"> *---------------------------------------------------------------------------*/</span></div>
<div class="line"><span class="keywordtype">void</span> app_main (<span class="keywordtype">void</span> *argument) {</div>
<div class="line">  uint32_t param = NULL;</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// Create an instance of the worker thread with static resources (TCB and stack)</span></div>
<div class="line">  th1 = <a class="code" href="group__CMSIS__RTOS__ThreadMgmt.html#ga48d68b8666d99d28fa646ee1d2182b8f">osThreadNew</a>(worker, &amp;param, &amp;worker_attr_1);</div>
<div class="line"> </div>
<div class="line">  <span class="keywordflow">for</span> (;;) {}</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main (<span class="keywordtype">void</span>) {</div>
<div class="line">  <span class="comment">// System Initialization</span></div>
<div class="line">  SystemCoreClockUpdate();</div>
<div class="line">  <span class="comment">// ...</span></div>
<div class="line"></div>
<div class="line">  <a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#gae818f6611d25ba3140bede410a52d659">osKernelInitialize</a>();                 <span class="comment">// Initialize CMSIS-RTOS</span></div>
<div class="line">  <a class="code" href="group__CMSIS__RTOS__ThreadMgmt.html#ga48d68b8666d99d28fa646ee1d2182b8f">osThreadNew</a>(app_main, NULL, NULL);    <span class="comment">// Create application main thread</span></div>
<div class="line">  <a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#ga9ae2cc00f0d89d7b6a307bba942b5221">osKernelStart</a>();                      <span class="comment">// Start thread execution</span></div>
<div class="line">  <span class="keywordflow">for</span> (;;) {}</div>
<div class="line">}</div>
</div><!-- fragment --><h1><a class="anchor" id="ThreadStack"></a>
Thread Stack Management</h1>
<p>For Cortex-M processors without floating point unit the thread context requires 64 bytes on the local stack.</p>
<dl class="section note"><dt>Note</dt><dd>For Cortex-M4/M7 with FP the thread context requires 200 bytes on the local stack. For these devices the default stack space should be increased to a minimum of 300 bytes.</dd></dl>
<p>Each thread is provided with a separate stack that holds the thread context and stack space for automatic variables and return addresses for function call nesting. The stack sizes of RTX threads are flexibly configurable as explained in the section <a class="el" href="config_rtx5.html#threadConfig">Thread Configuration</a>. RTX offers a configurable checking for stack overflows and stack utilization.</p>
<h1><a class="anchor" id="lowPower"></a>
Low-Power Operation</h1>
<p>The system thread <b>osRtxIdleThread</b> can be use to switch the system into a low-power mode. The easiest form to enter a low-power mode is the execution of the <code>__WFE</code> function that puts the processor into a sleep mode where it waits for an event.</p>
<p><b>Code Example:</b> </p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;RTE_Components.h&quot;</span></div>
<div class="line"><span class="preprocessor">#include CMSIS_device_header            </span><span class="comment">/* Device definitions                 */</span><span class="preprocessor"></span></div>
<div class="line"><span class="preprocessor"></span> </div>
<div class="line"><span class="keywordtype">void</span> <a class="code" href="group__rtx5__specific__functions.html#ga074068b8efa7074cee68a71481d0b072">osRtxIdleThread</a> (<span class="keywordtype">void</span>) {</div>
<div class="line">  <span class="comment">/* The idle demon is a system thread, running when no other thread is       */</span></div>
<div class="line">  <span class="comment">/* ready to run.                                                            */</span></div>
<div class="line"> </div>
<div class="line">  <span class="keywordflow">for</span> (;;) {</div>
<div class="line">    __WFE();                            <span class="comment">/* Enter sleep mode                   */</span></div>
<div class="line">  }</div>
<div class="line">}</div>
</div><!-- fragment --><dl class="section note"><dt>Note</dt><dd><code>__WFE()</code> is not available in every Cortex-M implementation. Check device manuals for availability.</dd></dl>
<h1><a class="anchor" id="kernelTimer"></a>
RTX Kernel Timer Tick</h1>
<p>RTX uses the generic <a class="el" href="group__CMSIS__RTOS__TickAPI.html">OS Tick API</a> to configure and control its periodic Kernel Tick.</p>
<p>To use an alternative timer as the Kernel Tick Timer one simply needs to implement a custom version of the <a class="el" href="group__CMSIS__RTOS__TickAPI.html">OS Tick API</a>.</p>
<dl class="section note"><dt>Note</dt><dd>The OS Tick implementation provided must assure that the used timer interrupt uses the same (low) priority group as the service interrupts, i.e. interrupts used by RTX must not preempt each other. Refer to the <a class="el" href="theory_of_operation.html#Scheduler">Scheduler</a> section for more details.</dd></dl>
<h2><a class="anchor" id="TickLess"></a>
Tick-less Low-Power Operation</h2>
<p>RTX5 provides extension for tick-less operation which is useful for applications that use extensively low-power modes where the SysTick timer is also disabled. To provide a time-tick in such power-saving modes, a wake-up timer is used to derive timer intervals. The CMSIS-RTOS2 functions <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#gae26683e1606ec633354a2876c68f0c1f">osKernelSuspend</a> and <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga8c4b4d7ed34cab73c001665d9176aced">osKernelResume</a> control the tick-less operation.</p>
<p>Using this functions allows the RTX5 thread scheduler to stop the periodic kernel tick interrupt. When all active threads are suspended, the system enters power-down and calculates how long it can stay in this power-down mode. In the power-down mode the processor and peripherals can be switched off. Only a wake-up timer must remain powered, because this timer is responsible to wake-up the system after the power-down period expires.</p>
<p>The tick-less operation is controlled from the <b>osRtxIdleThread</b> thread. The wake-up timeout value is set before the system enters the power-down mode. The function <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#gae26683e1606ec633354a2876c68f0c1f">osKernelSuspend</a> calculates the wake-up timeout measured in RTX Timer Ticks; this value is used to setup the wake-up timer that runs during the power-down mode of the system.</p>
<p>Once the system resumes operation (either by a wake-up time out or other interrupts) the RTX5 thread scheduler is started with the function <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga8c4b4d7ed34cab73c001665d9176aced">osKernelResume</a>. The parameter <em>sleep_time</em> specifies the time (in RTX Timer Ticks) that the system was in power-down mode.</p>
<p><b>Code Example:</b> </p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;msp.h&quot;</span>                        <span class="comment">// Device header</span></div>
<div class="line"></div>
<div class="line"><span class="comment">/*----------------------------------------------------------------------------</span></div>
<div class="line"><span class="comment"> *      MSP432 Low-Power Extension Functions</span></div>
<div class="line"><span class="comment"> *---------------------------------------------------------------------------*/</span></div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> MSP432_LP_Entry(<span class="keywordtype">void</span>) {</div>
<div class="line">  <span class="comment">/* Enable PCM rude mode, which allows to device to enter LPM3 without waiting for peripherals */</span></div>
<div class="line">  PCM-&gt;CTL1 = PCM_CTL1_KEY_VAL | PCM_CTL1_FORCE_LPM_ENTRY;       </div>
<div class="line">  <span class="comment">/* Enable all SRAM bank retentions prior to going to LPM3  */</span></div>
<div class="line">  SYSCTL-&gt;SRAM_BANKRET |= SYSCTL_SRAM_BANKRET_BNK7_RET;</div>
<div class="line">  __enable_interrupt();</div>
<div class="line">  NVIC_EnableIRQ(RTC_C_IRQn);</div>
<div class="line">  <span class="comment">/* Do not wake up on exit from ISR */</span></div>
<div class="line">  SCB-&gt;SCR |= SCB_SCR_SLEEPONEXIT_Msk;</div>
<div class="line">  <span class="comment">/* Setting the sleep deep bit */</span></div>
<div class="line">  SCB-&gt;SCR |= (SCB_SCR_SLEEPDEEP_Msk);  </div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="keyword">static</span> <span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> tc;</div>
<div class="line"><span class="keyword">static</span> <span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> tc_wakeup;</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> RTC_C_IRQHandler(<span class="keywordtype">void</span>)</div>
<div class="line">{</div>
<div class="line">  <span class="keywordflow">if</span> (tc++ &gt; tc_wakeup) </div>
<div class="line">  {</div>
<div class="line">    SCB-&gt;SCR &amp;= ~SCB_SCR_SLEEPONEXIT_Msk;    </div>
<div class="line">    NVIC_DisableIRQ(RTC_C_IRQn);</div>
<div class="line">    NVIC_ClearPendingIRQ(RTC_C_IRQn);</div>
<div class="line">    <span class="keywordflow">return</span>;</div>
<div class="line">  }</div>
<div class="line">  <span class="keywordflow">if</span> (RTC_C-&gt;PS0CTL &amp; RTC_C_PS0CTL_RT0PSIFG)</div>
<div class="line">  {</div>
<div class="line">    RTC_C-&gt;CTL0 = RTC_C_KEY_VAL;                 <span class="comment">// Unlock RTC key protected registers</span></div>
<div class="line">    RTC_C-&gt;PS0CTL &amp;= ~RTC_C_PS0CTL_RT0PSIFG;</div>
<div class="line">    RTC_C-&gt;CTL0 = 0;</div>
<div class="line">    SCB-&gt;SCR |= (SCB_SCR_SLEEPDEEP_Msk);</div>
<div class="line">  }</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line">uint32_t g_enable_sleep = 0;</div>
<div class="line">  </div>
<div class="line"><span class="keywordtype">void</span> <a class="code" href="group__rtx5__specific__functions.html#ga074068b8efa7074cee68a71481d0b072">osRtxIdleThread</a> (<span class="keywordtype">void</span>) {</div>
<div class="line">  </div>
<div class="line">  <span class="keywordflow">for</span> (;;) {</div>
<div class="line">    tc_wakeup = <a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#gae26683e1606ec633354a2876c68f0c1f">osKernelSuspend</a>();</div>
<div class="line">    <span class="comment">/* Is there some time to sleep? */</span></div>
<div class="line">    <span class="keywordflow">if</span> (tc_wakeup &gt; 0) {</div>
<div class="line">      tc = 0;</div>
<div class="line">      <span class="comment">/* Enter the low power state */</span></div>
<div class="line">      MSP432_LP_Entry();</div>
<div class="line">      __WFE();</div>
<div class="line">    }</div>
<div class="line">    <span class="comment">/* Adjust the kernel ticks with the amount of ticks slept */</span></div>
<div class="line">    <a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#ga8c4b4d7ed34cab73c001665d9176aced">osKernelResume</a> (tc);</div>
<div class="line">  }</div>
<div class="line">}</div>
</div><!-- fragment --><dl class="section note"><dt>Note</dt><dd><code>__WFE()</code> is not available in every Arm Cortex-M implementation. Check device manuals for availability. The alternative using <code>__WFI()</code> has other issues, please take note of <a href="http://www.keil.com/support/docs/3591.htm">http://www.keil.com/support/docs/3591.htm</a> as well.</dd></dl>
<h1><a class="anchor" id="rtx_os_h"></a>
RTX5 Header File</h1>
<p>Every implementation of the CMSIS-RTOS2 API can bring its own additional features. RTX5 adds a couple of <a class="el" href="group__rtx5__specific.html">functions</a> for the idle more, for error notifications, and special system timer functions. It also is using macros for control block and memory sizes.</p>
<p>If you require some of the RTX specific functions in your application code, #include the header file <b>rtx_os.h</b>:</p>
<div class="fragment"><div class="line"><span class="comment">/*</span></div>
<div class="line"><span class="comment"> * Copyright (c) 2013-2019 Arm Limited. All rights reserved.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * SPDX-License-Identifier: Apache-2.0</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * Licensed under the Apache License, Version 2.0 (the License); you may</span></div>
<div class="line"><span class="comment"> * not use this file except in compliance with the License.</span></div>
<div class="line"><span class="comment"> * You may obtain a copy of the License at</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * www.apache.org/licenses/LICENSE-2.0</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * Unless required by applicable law or agreed to in writing, software</span></div>
<div class="line"><span class="comment"> * distributed under the License is distributed on an AS IS BASIS, WITHOUT</span></div>
<div class="line"><span class="comment"> * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span></div>
<div class="line"><span class="comment"> * See the License for the specific language governing permissions and</span></div>
<div class="line"><span class="comment"> * limitations under the License.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * -----------------------------------------------------------------------------</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * Project:     CMSIS-RTOS RTX</span></div>
<div class="line"><span class="comment"> * Title:       RTX OS definitions</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * -----------------------------------------------------------------------------</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#ifndef RTX_OS_H_</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define RTX_OS_H_</span></div>
<div class="line"><span class="preprocessor"></span> </div>
<div class="line"><span class="preprocessor">#include &lt;stdint.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;stddef.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &quot;<a class="code" href="cmsis__os2_8h.html">cmsis_os2.h</a>&quot;</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#ifdef  __cplusplus</span></div>
<div class="line"><span class="preprocessor"></span><span class="keyword">extern</span> <span class="stringliteral">&quot;C&quot;</span></div>
<div class="line">{</div>
<div class="line"><span class="preprocessor">#endif</span></div>
<div class="line"><span class="preprocessor"></span> </div>
<div class="line"> <span class="comment"></span></div>
<div class="line"><span class="comment">/// Kernel Information</span></div>
<div class="line"><span class="comment"></span><span class="preprocessor">#define osRtxVersionAPI      20010003   </span><span class="comment">///&lt; API version (2.1.3)</span></div>
<div class="line"><span class="comment"></span>#define osRtxVersionKernel   50050001   <span class="comment">///&lt; Kernel version (5.5.1)</span></div>
<div class="line"><span class="comment"></span>#define osRtxKernelId     &quot;RTX V5.5.1&quot;  <span class="comment">///&lt; Kernel identification string</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"> </div>
<div class="line"><span class="comment">//  ==== Common definitions ====</span></div>
<div class="line"> <span class="comment"></span></div>
<div class="line"><span class="comment">/// Object Identifier definitions</span></div>
<div class="line"><span class="comment"></span><span class="preprocessor">#define osRtxIdInvalid          0x00U</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxIdThread           0xF1U</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxIdTimer            0xF2U</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxIdEventFlags       0xF3U</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxIdMutex            0xF5U</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxIdSemaphore        0xF6U</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxIdMemoryPool       0xF7U</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxIdMessage          0xF9U</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxIdMessageQueue     0xFAU</span></div>
<div class="line"><span class="preprocessor"></span> <span class="comment"></span></div>
<div class="line"><span class="comment">/// Object Flags definitions</span></div>
<div class="line"><span class="comment"></span><span class="preprocessor">#define osRtxFlagSystemObject   0x01U</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxFlagSystemMemory   0x02U</span></div>
<div class="line"><span class="preprocessor"></span> </div>
<div class="line"> </div>
<div class="line"><span class="comment">//  ==== Kernel definitions ====</span></div>
<div class="line"> <span class="comment"></span></div>
<div class="line"><span class="comment">/// Kernel State definitions</span></div>
<div class="line"><span class="comment"></span><span class="preprocessor">#define osRtxKernelInactive             ((uint8_t)osKernelInactive)</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxKernelReady                ((uint8_t)osKernelReady)</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxKernelRunning              ((uint8_t)osKernelRunning)</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxKernelLocked               ((uint8_t)osKernelLocked)</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxKernelSuspended            ((uint8_t)osKernelSuspended)</span></div>
<div class="line"><span class="preprocessor"></span> </div>
<div class="line"> </div>
<div class="line"><span class="comment">//  ==== Thread definitions ====</span></div>
<div class="line"> <span class="comment"></span></div>
<div class="line"><span class="comment">/// Thread State definitions (extending osThreadState)</span></div>
<div class="line"><span class="comment"></span><span class="preprocessor">#define osRtxThreadStateMask            0x0FU</span></div>
<div class="line"><span class="preprocessor"></span> </div>
<div class="line"><span class="preprocessor">#define osRtxThreadInactive             ((uint8_t)osThreadInactive)</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxThreadReady                ((uint8_t)osThreadReady)</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxThreadRunning              ((uint8_t)osThreadRunning)</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxThreadBlocked              ((uint8_t)osThreadBlocked)</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxThreadTerminated           ((uint8_t)osThreadTerminated)</span></div>
<div class="line"><span class="preprocessor"></span> </div>
<div class="line"><span class="preprocessor">#define osRtxThreadWaitingDelay         ((uint8_t)(osRtxThreadBlocked | 0x10U))</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxThreadWaitingJoin          ((uint8_t)(osRtxThreadBlocked | 0x20U))</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxThreadWaitingThreadFlags   ((uint8_t)(osRtxThreadBlocked | 0x30U))</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxThreadWaitingEventFlags    ((uint8_t)(osRtxThreadBlocked | 0x40U))</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxThreadWaitingMutex         ((uint8_t)(osRtxThreadBlocked | 0x50U))</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxThreadWaitingSemaphore     ((uint8_t)(osRtxThreadBlocked | 0x60U))</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxThreadWaitingMemoryPool    ((uint8_t)(osRtxThreadBlocked | 0x70U))</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxThreadWaitingMessageGet    ((uint8_t)(osRtxThreadBlocked | 0x80U))</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxThreadWaitingMessagePut    ((uint8_t)(osRtxThreadBlocked | 0x90U))</span></div>
<div class="line"><span class="preprocessor"></span> <span class="comment"></span></div>
<div class="line"><span class="comment">/// Thread Flags definitions</span></div>
<div class="line"><span class="comment"></span><span class="preprocessor">#define osRtxThreadFlagDefStack 0x10U   </span><span class="comment">///&lt; Default Stack flag</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">/// Stack Marker definitions</span></div>
<div class="line"><span class="comment"></span><span class="preprocessor">#define osRtxStackMagicWord     0xE25A2EA5U </span><span class="comment">///&lt; Stack Magic Word (Stack Base)</span></div>
<div class="line"><span class="comment"></span>#define osRtxStackFillPattern   0xCCCCCCCCU <span class="comment">///&lt; Stack Fill Pattern </span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">/// Thread Control Block</span></div>
<div class="line"><span class="comment"></span><span class="keyword">typedef</span> <span class="keyword">struct </span>osRtxThread_s {</div>
<div class="line">  uint8_t                          id;  <span class="comment">///&lt; Object Identifier</span></div>
<div class="line"><span class="comment"></span>  uint8_t                       state;  <span class="comment">///&lt; Object State</span></div>
<div class="line"><span class="comment"></span>  uint8_t                       flags;  <span class="comment">///&lt; Object Flags</span></div>
<div class="line"><span class="comment"></span>  uint8_t                        attr;  <span class="comment">///&lt; Object Attributes</span></div>
<div class="line"><span class="comment"></span>  <span class="keyword">const</span> <span class="keywordtype">char</span>                    *name;  <span class="comment">///&lt; Object Name</span></div>
<div class="line"><span class="comment"></span>  <span class="keyword">struct </span>osRtxThread_s   *thread_next;  <span class="comment">///&lt; Link pointer to next Thread in Object list</span></div>
<div class="line"><span class="comment"></span>  <span class="keyword">struct </span>osRtxThread_s   *thread_prev;  <span class="comment">///&lt; Link pointer to previous Thread in Object list</span></div>
<div class="line"><span class="comment"></span>  <span class="keyword">struct </span>osRtxThread_s    *delay_next;  <span class="comment">///&lt; Link pointer to next Thread in Delay list</span></div>
<div class="line"><span class="comment"></span>  <span class="keyword">struct </span>osRtxThread_s    *delay_prev;  <span class="comment">///&lt; Link pointer to previous Thread in Delay list</span></div>
<div class="line"><span class="comment"></span>  <span class="keyword">struct </span>osRtxThread_s   *thread_join;  <span class="comment">///&lt; Thread waiting to Join</span></div>
<div class="line"><span class="comment"></span>  uint32_t                      delay;  <span class="comment">///&lt; Delay Time</span></div>
<div class="line"><span class="comment"></span>  int8_t                     priority;  <span class="comment">///&lt; Thread Priority</span></div>
<div class="line"><span class="comment"></span>  int8_t                priority_base;  <span class="comment">///&lt; Base Priority</span></div>
<div class="line"><span class="comment"></span>  uint8_t                 stack_frame;  <span class="comment">///&lt; Stack Frame (EXC_RETURN[7..0])</span></div>
<div class="line"><span class="comment"></span>  uint8_t               flags_options;  <span class="comment">///&lt; Thread/Event Flags Options</span></div>
<div class="line"><span class="comment"></span>  uint32_t                 wait_flags;  <span class="comment">///&lt; Waiting Thread/Event Flags</span></div>
<div class="line"><span class="comment"></span>  uint32_t               thread_flags;  <span class="comment">///&lt; Thread Flags</span></div>
<div class="line"><span class="comment"></span>  <span class="keyword">struct </span>osRtxMutex_s     *mutex_list;  <span class="comment">///&lt; Link pointer to list of owned Mutexes</span></div>
<div class="line"><span class="comment"></span>  <span class="keywordtype">void</span>                     *stack_mem;  <span class="comment">///&lt; Stack Memory</span></div>
<div class="line"><span class="comment"></span>  uint32_t                 stack_size;  <span class="comment">///&lt; Stack Size</span></div>
<div class="line"><span class="comment"></span>  uint32_t                         sp;  <span class="comment">///&lt; Current Stack Pointer</span></div>
<div class="line"><span class="comment"></span>  uint32_t                thread_addr;  <span class="comment">///&lt; Thread entry address</span></div>
<div class="line"><span class="comment"></span>  uint32_t                  tz_memory;  <span class="comment">///&lt; TrustZone Memory Identifier</span></div>
<div class="line"><span class="comment"></span><span class="preprocessor">#ifdef RTX_TF_M_EXTENSION</span></div>
<div class="line"><span class="preprocessor"></span>  uint32_t                  tz_module;  <span class="comment">///&lt; TrustZone Module Identifier</span></div>
<div class="line"><span class="comment"></span><span class="preprocessor">#endif</span></div>
<div class="line"><span class="preprocessor"></span>} <a class="code" href="rtx__os_8h.html#structosRtxThread__t">osRtxThread_t</a>;</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="comment">//  ==== Timer definitions ====</span></div>
<div class="line"> <span class="comment"></span></div>
<div class="line"><span class="comment">/// Timer State definitions</span></div>
<div class="line"><span class="comment"></span><span class="preprocessor">#define osRtxTimerInactive      0x00U   </span><span class="comment">///&lt; Timer Inactive</span></div>
<div class="line"><span class="comment"></span>#define osRtxTimerStopped       0x01U   <span class="comment">///&lt; Timer Stopped</span></div>
<div class="line"><span class="comment"></span>#define osRtxTimerRunning       0x02U   <span class="comment">///&lt; Timer Running</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">/// Timer Type definitions</span></div>
<div class="line"><span class="comment"></span><span class="preprocessor">#define osRtxTimerPeriodic      ((uint8_t)osTimerPeriodic)</span></div>
<div class="line"><span class="preprocessor"></span> <span class="comment"></span></div>
<div class="line"><span class="comment">/// Timer Function Information</span></div>
<div class="line"><span class="comment"></span><span class="keyword">typedef</span> <span class="keyword">struct </span>{</div>
<div class="line">  <a class="code" href="group__CMSIS__RTOS__TimerMgmt.html#gaacf768c1ec64b020598afb985d7b30be">osTimerFunc_t</a>                  func;  <span class="comment">///&lt; Function Pointer</span></div>
<div class="line"><span class="comment"></span>  <span class="keywordtype">void</span>                           *arg;  <span class="comment">///&lt; Function Argument</span></div>
<div class="line"><span class="comment"></span>} <a class="code" href="rtx__os_8h.html#structosRtxTimerFinfo__t">osRtxTimerFinfo_t</a>;</div>
<div class="line"> <span class="comment"></span></div>
<div class="line"><span class="comment">/// Timer Control Block</span></div>
<div class="line"><span class="comment"></span><span class="keyword">typedef</span> <span class="keyword">struct </span>osRtxTimer_s {</div>
<div class="line">  uint8_t                          id;  <span class="comment">///&lt; Object Identifier</span></div>
<div class="line"><span class="comment"></span>  uint8_t                       state;  <span class="comment">///&lt; Object State</span></div>
<div class="line"><span class="comment"></span>  uint8_t                       flags;  <span class="comment">///&lt; Object Flags</span></div>
<div class="line"><span class="comment"></span>  uint8_t                        type;  <span class="comment">///&lt; Timer Type (Periodic/One-shot)</span></div>
<div class="line"><span class="comment"></span>  <span class="keyword">const</span> <span class="keywordtype">char</span>                    *name;  <span class="comment">///&lt; Object Name</span></div>
<div class="line"><span class="comment"></span>  <span class="keyword">struct </span>osRtxTimer_s           *prev;  <span class="comment">///&lt; Pointer to previous active Timer</span></div>
<div class="line"><span class="comment"></span>  <span class="keyword">struct </span>osRtxTimer_s           *next;  <span class="comment">///&lt; Pointer to next active Timer</span></div>
<div class="line"><span class="comment"></span>  uint32_t                       tick;  <span class="comment">///&lt; Timer current Tick</span></div>
<div class="line"><span class="comment"></span>  uint32_t                       load;  <span class="comment">///&lt; Timer Load value</span></div>
<div class="line"><span class="comment"></span>  <a class="code" href="rtx__os_8h.html#structosRtxTimerFinfo__t">osRtxTimerFinfo_t</a>             finfo;  <span class="comment">///&lt; Timer Function Info</span></div>
<div class="line"><span class="comment"></span>} <a class="code" href="rtx__os_8h.html#structosRtxTimer__t">osRtxTimer_t</a>;</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="comment">//  ==== Event Flags definitions ====</span></div>
<div class="line"> <span class="comment"></span></div>
<div class="line"><span class="comment">/// Event Flags Control Block</span></div>
<div class="line"><span class="comment"></span><span class="keyword">typedef</span> <span class="keyword">struct </span>{</div>
<div class="line">  uint8_t                          id;  <span class="comment">///&lt; Object Identifier</span></div>
<div class="line"><span class="comment"></span>  uint8_t              reserved_state;  <span class="comment">///&lt; Object State (not used)</span></div>
<div class="line"><span class="comment"></span>  uint8_t                       flags;  <span class="comment">///&lt; Object Flags</span></div>
<div class="line"><span class="comment"></span>  uint8_t                    reserved;</div>
<div class="line">  <span class="keyword">const</span> <span class="keywordtype">char</span>                    *name;  <span class="comment">///&lt; Object Name</span></div>
<div class="line"><span class="comment"></span>  <a class="code" href="rtx__os_8h.html#structosRtxThread__t">osRtxThread_t</a>          *thread_list;  <span class="comment">///&lt; Waiting Threads List</span></div>
<div class="line"><span class="comment"></span>  uint32_t                event_flags;  <span class="comment">///&lt; Event Flags</span></div>
<div class="line"><span class="comment"></span>} <a class="code" href="rtx__os_8h.html#structosRtxEventFlags__t">osRtxEventFlags_t</a>;</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="comment">//  ==== Mutex definitions ====</span></div>
<div class="line"> <span class="comment"></span></div>
<div class="line"><span class="comment">/// Mutex Control Block</span></div>
<div class="line"><span class="comment"></span><span class="keyword">typedef</span> <span class="keyword">struct </span>osRtxMutex_s {</div>
<div class="line">  uint8_t                          id;  <span class="comment">///&lt; Object Identifier</span></div>
<div class="line"><span class="comment"></span>  uint8_t              reserved_state;  <span class="comment">///&lt; Object State (not used)</span></div>
<div class="line"><span class="comment"></span>  uint8_t                       flags;  <span class="comment">///&lt; Object Flags</span></div>
<div class="line"><span class="comment"></span>  uint8_t                        attr;  <span class="comment">///&lt; Object Attributes</span></div>
<div class="line"><span class="comment"></span>  <span class="keyword">const</span> <span class="keywordtype">char</span>                    *name;  <span class="comment">///&lt; Object Name</span></div>
<div class="line"><span class="comment"></span>  <a class="code" href="rtx__os_8h.html#structosRtxThread__t">osRtxThread_t</a>          *thread_list;  <span class="comment">///&lt; Waiting Threads List</span></div>
<div class="line"><span class="comment"></span>  <a class="code" href="rtx__os_8h.html#structosRtxThread__t">osRtxThread_t</a>         *owner_thread;  <span class="comment">///&lt; Owner Thread</span></div>
<div class="line"><span class="comment"></span>  <span class="keyword">struct </span>osRtxMutex_s     *owner_prev;  <span class="comment">///&lt; Pointer to previous owned Mutex</span></div>
<div class="line"><span class="comment"></span>  <span class="keyword">struct </span>osRtxMutex_s     *owner_next;  <span class="comment">///&lt; Pointer to next owned Mutex</span></div>
<div class="line"><span class="comment"></span>  uint8_t                        lock;  <span class="comment">///&lt; Lock counter</span></div>
<div class="line"><span class="comment"></span>  uint8_t                  padding[3];</div>
<div class="line">} <a class="code" href="rtx__os_8h.html#structosRtxMutex__t">osRtxMutex_t</a>;</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="comment">//  ==== Semaphore definitions ====</span></div>
<div class="line"> <span class="comment"></span></div>
<div class="line"><span class="comment">/// Semaphore Control Block</span></div>
<div class="line"><span class="comment"></span><span class="keyword">typedef</span> <span class="keyword">struct </span>{</div>
<div class="line">  uint8_t                          id;  <span class="comment">///&lt; Object Identifier</span></div>
<div class="line"><span class="comment"></span>  uint8_t              reserved_state;  <span class="comment">///&lt; Object State (not used)</span></div>
<div class="line"><span class="comment"></span>  uint8_t                       flags;  <span class="comment">///&lt; Object Flags</span></div>
<div class="line"><span class="comment"></span>  uint8_t                    reserved;</div>
<div class="line">  <span class="keyword">const</span> <span class="keywordtype">char</span>                    *name;  <span class="comment">///&lt; Object Name</span></div>
<div class="line"><span class="comment"></span>  <a class="code" href="rtx__os_8h.html#structosRtxThread__t">osRtxThread_t</a>          *thread_list;  <span class="comment">///&lt; Waiting Threads List</span></div>
<div class="line"><span class="comment"></span>  uint16_t                     tokens;  <span class="comment">///&lt; Current number of tokens</span></div>
<div class="line"><span class="comment"></span>  uint16_t                 max_tokens;  <span class="comment">///&lt; Maximum number of tokens</span></div>
<div class="line"><span class="comment"></span>} <a class="code" href="rtx__os_8h.html#structosRtxSemaphore__t">osRtxSemaphore_t</a>;</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="comment">//  ==== Memory Pool definitions ====</span></div>
<div class="line"> <span class="comment"></span></div>
<div class="line"><span class="comment">/// Memory Pool Information</span></div>
<div class="line"><span class="comment"></span><span class="keyword">typedef</span> <span class="keyword">struct </span>{</div>
<div class="line">  uint32_t                 max_blocks;  <span class="comment">///&lt; Maximum number of Blocks</span></div>
<div class="line"><span class="comment"></span>  uint32_t                used_blocks;  <span class="comment">///&lt; Number of used Blocks</span></div>
<div class="line"><span class="comment"></span>  uint32_t                 block_size;  <span class="comment">///&lt; Block Size</span></div>
<div class="line"><span class="comment"></span>  <span class="keywordtype">void</span>                    *block_base;  <span class="comment">///&lt; Block Memory Base Address</span></div>
<div class="line"><span class="comment"></span>  <span class="keywordtype">void</span>                     *block_lim;  <span class="comment">///&lt; Block Memory Limit Address</span></div>
<div class="line"><span class="comment"></span>  <span class="keywordtype">void</span>                    *block_free;  <span class="comment">///&lt; First free Block Address</span></div>
<div class="line"><span class="comment"></span>} <a class="code" href="rtx__os_8h.html#structosRtxMpInfo__t">osRtxMpInfo_t</a>;</div>
<div class="line"> <span class="comment"></span></div>
<div class="line"><span class="comment">/// Memory Pool Control Block</span></div>
<div class="line"><span class="comment"></span><span class="keyword">typedef</span> <span class="keyword">struct </span>{</div>
<div class="line">  uint8_t                          id;  <span class="comment">///&lt; Object Identifier</span></div>
<div class="line"><span class="comment"></span>  uint8_t              reserved_state;  <span class="comment">///&lt; Object State (not used)</span></div>
<div class="line"><span class="comment"></span>  uint8_t                       flags;  <span class="comment">///&lt; Object Flags</span></div>
<div class="line"><span class="comment"></span>  uint8_t                    reserved;</div>
<div class="line">  <span class="keyword">const</span> <span class="keywordtype">char</span>                    *name;  <span class="comment">///&lt; Object Name</span></div>
<div class="line"><span class="comment"></span>  <a class="code" href="rtx__os_8h.html#structosRtxThread__t">osRtxThread_t</a>          *thread_list;  <span class="comment">///&lt; Waiting Threads List</span></div>
<div class="line"><span class="comment"></span>  <a class="code" href="rtx__os_8h.html#structosRtxMpInfo__t">osRtxMpInfo_t</a>               mp_info;  <span class="comment">///&lt; Memory Pool Info</span></div>
<div class="line"><span class="comment"></span>} <a class="code" href="rtx__os_8h.html#structosRtxMemoryPool__t">osRtxMemoryPool_t</a>;</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="comment">//  ==== Message Queue definitions ====</span></div>
<div class="line"> <span class="comment"></span></div>
<div class="line"><span class="comment">/// Message Control Block</span></div>
<div class="line"><span class="comment"></span><span class="keyword">typedef</span> <span class="keyword">struct </span>osRtxMessage_s {</div>
<div class="line">  uint8_t                          id;  <span class="comment">///&lt; Object Identifier</span></div>
<div class="line"><span class="comment"></span>  uint8_t              reserved_state;  <span class="comment">///&lt; Object State (not used)</span></div>
<div class="line"><span class="comment"></span>  uint8_t                       flags;  <span class="comment">///&lt; Object Flags</span></div>
<div class="line"><span class="comment"></span>  uint8_t                    priority;  <span class="comment">///&lt; Message Priority</span></div>
<div class="line"><span class="comment"></span>  <span class="keyword">struct </span>osRtxMessage_s         *prev;  <span class="comment">///&lt; Pointer to previous Message</span></div>
<div class="line"><span class="comment"></span>  <span class="keyword">struct </span>osRtxMessage_s         *next;  <span class="comment">///&lt; Pointer to next Message</span></div>
<div class="line"><span class="comment"></span>} <a class="code" href="rtx__os_8h.html#structosRtxMessage__t">osRtxMessage_t</a>;</div>
<div class="line"> <span class="comment"></span></div>
<div class="line"><span class="comment">/// Message Queue Control Block</span></div>
<div class="line"><span class="comment"></span><span class="keyword">typedef</span> <span class="keyword">struct </span>{</div>
<div class="line">  uint8_t                          id;  <span class="comment">///&lt; Object Identifier</span></div>
<div class="line"><span class="comment"></span>  uint8_t              reserved_state;  <span class="comment">///&lt; Object State (not used)</span></div>
<div class="line"><span class="comment"></span>  uint8_t                       flags;  <span class="comment">///&lt; Object Flags</span></div>
<div class="line"><span class="comment"></span>  uint8_t                    reserved;</div>
<div class="line">  <span class="keyword">const</span> <span class="keywordtype">char</span>                    *name;  <span class="comment">///&lt; Object Name</span></div>
<div class="line"><span class="comment"></span>  <a class="code" href="rtx__os_8h.html#structosRtxThread__t">osRtxThread_t</a>          *thread_list;  <span class="comment">///&lt; Waiting Threads List</span></div>
<div class="line"><span class="comment"></span>  <a class="code" href="rtx__os_8h.html#structosRtxMpInfo__t">osRtxMpInfo_t</a>               mp_info;  <span class="comment">///&lt; Memory Pool Info</span></div>
<div class="line"><span class="comment"></span>  uint32_t                   msg_size;  <span class="comment">///&lt; Message Size</span></div>
<div class="line"><span class="comment"></span>  uint32_t                  msg_count;  <span class="comment">///&lt; Number of queued Messages</span></div>
<div class="line"><span class="comment"></span>  <a class="code" href="rtx__os_8h.html#structosRtxMessage__t">osRtxMessage_t</a>           *msg_first;  <span class="comment">///&lt; Pointer to first Message</span></div>
<div class="line"><span class="comment"></span>  <a class="code" href="rtx__os_8h.html#structosRtxMessage__t">osRtxMessage_t</a>            *msg_last;  <span class="comment">///&lt; Pointer to last Message</span></div>
<div class="line"><span class="comment"></span>} <a class="code" href="rtx__os_8h.html#structosRtxMessageQueue__t">osRtxMessageQueue_t</a>;</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="comment">//  ==== Generic Object definitions ====</span></div>
<div class="line"> <span class="comment"></span></div>
<div class="line"><span class="comment">/// Generic Object Control Block</span></div>
<div class="line"><span class="comment"></span><span class="keyword">typedef</span> <span class="keyword">struct </span>{</div>
<div class="line">  uint8_t                          id;  <span class="comment">///&lt; Object Identifier</span></div>
<div class="line"><span class="comment"></span>  uint8_t                       state;  <span class="comment">///&lt; Object State</span></div>
<div class="line"><span class="comment"></span>  uint8_t                       flags;  <span class="comment">///&lt; Object Flags</span></div>
<div class="line"><span class="comment"></span>  uint8_t                    reserved;</div>
<div class="line">  <span class="keyword">const</span> <span class="keywordtype">char</span>                    *name;  <span class="comment">///&lt; Object Name</span></div>
<div class="line"><span class="comment"></span>  <a class="code" href="rtx__os_8h.html#structosRtxThread__t">osRtxThread_t</a>          *thread_list;  <span class="comment">///&lt; Threads List</span></div>
<div class="line"><span class="comment"></span>} <a class="code" href="rtx__os_8h.html#structosRtxObject__t">osRtxObject_t</a>;</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="comment">//  ==== OS Runtime Information definitions ====</span></div>
<div class="line"> <span class="comment"></span></div>
<div class="line"><span class="comment">/// OS Runtime Information structure</span></div>
<div class="line"><span class="comment"></span><span class="keyword">typedef</span> <span class="keyword">struct </span>{</div>
<div class="line">  <span class="keyword">const</span> <span class="keywordtype">char</span>                   *os_id;  <span class="comment">///&lt; OS Identification</span></div>
<div class="line"><span class="comment"></span>  uint32_t                    version;  <span class="comment">///&lt; OS Version</span></div>
<div class="line"><span class="comment"></span>  <span class="keyword">struct </span>{                              <span class="comment">///&lt; Kernel Info</span></div>
<div class="line"><span class="comment"></span>    uint8_t                     state;  <span class="comment">///&lt; State</span></div>
<div class="line"><span class="comment"></span>    <span class="keyword">volatile</span> uint8_t          blocked;  <span class="comment">///&lt; Blocked</span></div>
<div class="line"><span class="comment"></span>    uint8_t                    pendSV;  <span class="comment">///&lt; Pending SV</span></div>
<div class="line"><span class="comment"></span>    uint8_t                  reserved;</div>
<div class="line">    uint32_t                     tick;  <span class="comment">///&lt; Tick counter</span></div>
<div class="line"><span class="comment"></span>  } kernel;</div>
<div class="line">  int32_t                   tick_irqn;  <span class="comment">///&lt; Tick Timer IRQ Number</span></div>
<div class="line"><span class="comment"></span>  <span class="keyword">struct </span>{                              <span class="comment">///&lt; Thread Info</span></div>
<div class="line"><span class="comment"></span>    <span class="keyword">struct </span>{                            <span class="comment">///&lt; Thread Run Info</span></div>
<div class="line"><span class="comment"></span>      <a class="code" href="rtx__os_8h.html#structosRtxThread__t">osRtxThread_t</a>             *curr;  <span class="comment">///&lt; Current running Thread</span></div>
<div class="line"><span class="comment"></span>      <a class="code" href="rtx__os_8h.html#structosRtxThread__t">osRtxThread_t</a>             *next;  <span class="comment">///&lt; Next Thread to Run</span></div>
<div class="line"><span class="comment"></span>    } run;</div>
<div class="line">    <a class="code" href="rtx__os_8h.html#structosRtxObject__t">osRtxObject_t</a>               ready;  <span class="comment">///&lt; Ready List Object</span></div>
<div class="line"><span class="comment"></span>    <a class="code" href="rtx__os_8h.html#structosRtxThread__t">osRtxThread_t</a>               *idle;  <span class="comment">///&lt; Idle Thread</span></div>
<div class="line"><span class="comment"></span>    <a class="code" href="rtx__os_8h.html#structosRtxThread__t">osRtxThread_t</a>         *delay_list;  <span class="comment">///&lt; Delay List</span></div>
<div class="line"><span class="comment"></span>    <a class="code" href="rtx__os_8h.html#structosRtxThread__t">osRtxThread_t</a>          *wait_list;  <span class="comment">///&lt; Wait List (no Timeout)</span></div>
<div class="line"><span class="comment"></span>    <a class="code" href="rtx__os_8h.html#structosRtxThread__t">osRtxThread_t</a>     *terminate_list;  <span class="comment">///&lt; Terminate Thread List</span></div>
<div class="line"><span class="comment"></span>    <span class="keyword">struct </span>{                            <span class="comment">///&lt; Thread Round Robin Info</span></div>
<div class="line"><span class="comment"></span>      <a class="code" href="rtx__os_8h.html#structosRtxThread__t">osRtxThread_t</a>           *thread;  <span class="comment">///&lt; Round Robin Thread</span></div>
<div class="line"><span class="comment"></span>      uint32_t                   tick;  <span class="comment">///&lt; Round Robin Time Tick</span></div>
<div class="line"><span class="comment"></span>      uint32_t                timeout;  <span class="comment">///&lt; Round Robin Timeout</span></div>
<div class="line"><span class="comment"></span>    } robin;</div>
<div class="line">  } thread;</div>
<div class="line">  <span class="keyword">struct </span>{                              <span class="comment">///&lt; Timer Info</span></div>
<div class="line"><span class="comment"></span>    <a class="code" href="rtx__os_8h.html#structosRtxTimer__t">osRtxTimer_t</a>                *list;  <span class="comment">///&lt; Active Timer List</span></div>
<div class="line"><span class="comment"></span>    <a class="code" href="rtx__os_8h.html#structosRtxThread__t">osRtxThread_t</a>             *thread;  <span class="comment">///&lt; Timer Thread</span></div>
<div class="line"><span class="comment"></span>    <a class="code" href="rtx__os_8h.html#structosRtxMessageQueue__t">osRtxMessageQueue_t</a>           *mq;  <span class="comment">///&lt; Timer Message Queue</span></div>
<div class="line"><span class="comment"></span>    void                (*tick)(void);  <span class="comment">///&lt; Timer Tick Function</span></div>
<div class="line"><span class="comment"></span>  } timer;</div>
<div class="line">  <span class="keyword">struct </span>{                              <span class="comment">///&lt; ISR Post Processing Queue</span></div>
<div class="line"><span class="comment"></span>    uint16_t                      max;  <span class="comment">///&lt; Maximum Items</span></div>
<div class="line"><span class="comment"></span>    uint16_t                      cnt;  <span class="comment">///&lt; Item Count</span></div>
<div class="line"><span class="comment"></span>    uint16_t                       in;  <span class="comment">///&lt; Incoming Item Index</span></div>
<div class="line"><span class="comment"></span>    uint16_t                      out;  <span class="comment">///&lt; Outgoing Item Index</span></div>
<div class="line"><span class="comment"></span>    <span class="keywordtype">void</span>                       **data;  <span class="comment">///&lt; Queue Data</span></div>
<div class="line"><span class="comment"></span>  } isr_queue;</div>
<div class="line">  <span class="keyword">struct </span>{                                      <span class="comment">///&lt; ISR Post Processing functions</span></div>
<div class="line"><span class="comment"></span>    void          (*thread)(<a class="code" href="rtx__os_8h.html#structosRtxThread__t">osRtxThread_t</a>*);    <span class="comment">///&lt; Thread Post Processing function</span></div>
<div class="line"><span class="comment"></span>    void (*event_flags)(<a class="code" href="rtx__os_8h.html#structosRtxEventFlags__t">osRtxEventFlags_t</a>*);    <span class="comment">///&lt; Event Flags Post Processing function</span></div>
<div class="line"><span class="comment"></span>    void    (*semaphore)(<a class="code" href="rtx__os_8h.html#structosRtxSemaphore__t">osRtxSemaphore_t</a>*);    <span class="comment">///&lt; Semaphore Post Processing function</span></div>
<div class="line"><span class="comment"></span>    void (*memory_pool)(<a class="code" href="rtx__os_8h.html#structosRtxMemoryPool__t">osRtxMemoryPool_t</a>*);    <span class="comment">///&lt; Memory Pool Post Processing function</span></div>
<div class="line"><span class="comment"></span>    void        (*message)(<a class="code" href="rtx__os_8h.html#structosRtxMessage__t">osRtxMessage_t</a>*);    <span class="comment">///&lt; Message Post Processing function</span></div>
<div class="line"><span class="comment"></span>  } post_process;</div>
<div class="line">  <span class="keyword">struct </span>{                              <span class="comment">///&lt; Memory Pools (Variable Block Size)</span></div>
<div class="line"><span class="comment"></span>    <span class="keywordtype">void</span>                       *stack;  <span class="comment">///&lt; Stack Memory</span></div>
<div class="line"><span class="comment"></span>    <span class="keywordtype">void</span>                     *mp_data;  <span class="comment">///&lt; Memory Pool Data Memory</span></div>
<div class="line"><span class="comment"></span>    <span class="keywordtype">void</span>                     *mq_data;  <span class="comment">///&lt; Message Queue Data Memory</span></div>
<div class="line"><span class="comment"></span>    <span class="keywordtype">void</span>                      *common;  <span class="comment">///&lt; Common Memory</span></div>
<div class="line"><span class="comment"></span>  } mem;</div>
<div class="line">  <span class="keyword">struct </span>{                              <span class="comment">///&lt; Memory Pools (Fixed Block Size)</span></div>
<div class="line"><span class="comment"></span>    <a class="code" href="rtx__os_8h.html#structosRtxMpInfo__t">osRtxMpInfo_t</a>              *stack;  <span class="comment">///&lt; Stack for Threads</span></div>
<div class="line"><span class="comment"></span>    <a class="code" href="rtx__os_8h.html#structosRtxMpInfo__t">osRtxMpInfo_t</a>             *thread;  <span class="comment">///&lt; Thread Control Blocks</span></div>
<div class="line"><span class="comment"></span>    <a class="code" href="rtx__os_8h.html#structosRtxMpInfo__t">osRtxMpInfo_t</a>              *timer;  <span class="comment">///&lt; Timer Control Blocks</span></div>
<div class="line"><span class="comment"></span>    <a class="code" href="rtx__os_8h.html#structosRtxMpInfo__t">osRtxMpInfo_t</a>        *event_flags;  <span class="comment">///&lt; Event Flags Control Blocks</span></div>
<div class="line"><span class="comment"></span>    <a class="code" href="rtx__os_8h.html#structosRtxMpInfo__t">osRtxMpInfo_t</a>              *mutex;  <span class="comment">///&lt; Mutex Control Blocks</span></div>
<div class="line"><span class="comment"></span>    <a class="code" href="rtx__os_8h.html#structosRtxMpInfo__t">osRtxMpInfo_t</a>          *semaphore;  <span class="comment">///&lt; Semaphore Control Blocks</span></div>
<div class="line"><span class="comment"></span>    <a class="code" href="rtx__os_8h.html#structosRtxMpInfo__t">osRtxMpInfo_t</a>        *memory_pool;  <span class="comment">///&lt; Memory Pool Control Blocks</span></div>
<div class="line"><span class="comment"></span>    <a class="code" href="rtx__os_8h.html#structosRtxMpInfo__t">osRtxMpInfo_t</a>      *message_queue;  <span class="comment">///&lt; Message Queue Control Blocks</span></div>
<div class="line"><span class="comment"></span>  } mpi;</div>
<div class="line">} <a class="code" href="rtx__os_8h.html#structosRtxInfo__t">osRtxInfo_t</a>;</div>
<div class="line"> </div>
<div class="line"><span class="keyword">extern</span> <a class="code" href="rtx__os_8h.html#structosRtxInfo__t">osRtxInfo_t</a> <a class="code" href="rtx__os_8h.html#ad2270125c4e4991c3231d752b6ee5f3f">osRtxInfo</a>;           <span class="comment">///&lt; OS Runtime Information</span></div>
<div class="line"><span class="comment"></span> <span class="comment"></span></div>
<div class="line"><span class="comment">/// OS Runtime Object Memory Usage structure</span></div>
<div class="line"><span class="comment"></span><span class="keyword">typedef</span> <span class="keyword">struct </span>{</div>
<div class="line">  uint32_t cnt_alloc;                   <span class="comment">///&lt; Counter for alloc</span></div>
<div class="line"><span class="comment"></span>  uint32_t cnt_free;                    <span class="comment">///&lt; Counter for free</span></div>
<div class="line"><span class="comment"></span>  uint32_t max_used;                    <span class="comment">///&lt; Maximum used</span></div>
<div class="line"><span class="comment"></span>} <a class="code" href="rtx__os_8h.html#structosRtxObjectMemUsage__t">osRtxObjectMemUsage_t</a>;</div>
<div class="line"> <span class="comment"></span></div>
<div class="line"><span class="comment">/// OS Runtime Object Memory Usage variables</span></div>
<div class="line"><span class="comment"></span><span class="keyword">extern</span> <a class="code" href="rtx__os_8h.html#structosRtxObjectMemUsage__t">osRtxObjectMemUsage_t</a> <a class="code" href="rtx__os_8h.html#a90374bf1d999b2e1594763ab6c97cd69">osRtxThreadMemUsage</a>;</div>
<div class="line"><span class="keyword">extern</span> <a class="code" href="rtx__os_8h.html#structosRtxObjectMemUsage__t">osRtxObjectMemUsage_t</a> <a class="code" href="rtx__os_8h.html#aa3e7cf488411dbdc814420b81f36b935">osRtxTimerMemUsage</a>;</div>
<div class="line"><span class="keyword">extern</span> <a class="code" href="rtx__os_8h.html#structosRtxObjectMemUsage__t">osRtxObjectMemUsage_t</a> <a class="code" href="rtx__os_8h.html#a0c81327f94697890809ce4a594bb9d5c">osRtxEventFlagsMemUsage</a>;</div>
<div class="line"><span class="keyword">extern</span> <a class="code" href="rtx__os_8h.html#structosRtxObjectMemUsage__t">osRtxObjectMemUsage_t</a> <a class="code" href="rtx__os_8h.html#a683927dcd67dcb912884d16efa81a58d">osRtxMutexMemUsage</a>;</div>
<div class="line"><span class="keyword">extern</span> <a class="code" href="rtx__os_8h.html#structosRtxObjectMemUsage__t">osRtxObjectMemUsage_t</a> <a class="code" href="rtx__os_8h.html#aec50b39ce30d9c87916d077f6f764387">osRtxSemaphoreMemUsage</a>;</div>
<div class="line"><span class="keyword">extern</span> <a class="code" href="rtx__os_8h.html#structosRtxObjectMemUsage__t">osRtxObjectMemUsage_t</a> <a class="code" href="rtx__os_8h.html#ae5dea30a13d7a2316699a7f201504bc7">osRtxMemoryPoolMemUsage</a>;</div>
<div class="line"><span class="keyword">extern</span> <a class="code" href="rtx__os_8h.html#structosRtxObjectMemUsage__t">osRtxObjectMemUsage_t</a> <a class="code" href="rtx__os_8h.html#af3da38b316a84990128e8d9f34e3e6d3">osRtxMessageQueueMemUsage</a>;</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="comment">//  ==== OS API definitions ====</span></div>
<div class="line"> </div>
<div class="line"><span class="comment">// Object Limits definitions</span></div>
<div class="line"><span class="preprocessor">#define osRtxThreadFlagsLimit    31U    </span><span class="comment">///&lt; number of Thread Flags available per thread</span></div>
<div class="line"><span class="comment"></span>#define osRtxEventFlagsLimit     31U    <span class="comment">///&lt; number of Event Flags available per object</span></div>
<div class="line"><span class="comment"></span>#define osRtxMutexLockLimit      255U   <span class="comment">///&lt; maximum number of recursive mutex locks</span></div>
<div class="line"><span class="comment"></span>#define osRtxSemaphoreTokenLimit 65535U <span class="comment">///&lt; maximum number of tokens per semaphore</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">// Control Block sizes</span></div>
<div class="line"><span class="preprocessor">#define osRtxThreadCbSize        sizeof(osRtxThread_t)</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxTimerCbSize         sizeof(osRtxTimer_t)</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxEventFlagsCbSize    sizeof(osRtxEventFlags_t)</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxMutexCbSize         sizeof(osRtxMutex_t)</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxSemaphoreCbSize     sizeof(osRtxSemaphore_t)</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxMemoryPoolCbSize    sizeof(osRtxMemoryPool_t)</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define osRtxMessageQueueCbSize  sizeof(osRtxMessageQueue_t)</span></div>
<div class="line"><span class="preprocessor"></span> <span class="comment"></span></div>
<div class="line"><span class="comment">/// Memory size in bytes for Memory Pool storage.</span></div>
<div class="line"><span class="comment">/// \param         block_count   maximum number of memory blocks in memory pool.</span></div>
<div class="line"><span class="comment">/// \param         block_size    memory block size in bytes.</span></div>
<div class="line"><span class="comment"></span><span class="preprocessor">#define osRtxMemoryPoolMemSize(block_count, block_size) \</span></div>
<div class="line"><span class="preprocessor">  (4*(block_count)*(((block_size)+3)/4))</span></div>
<div class="line"><span class="preprocessor"></span> <span class="comment"></span></div>
<div class="line"><span class="comment">/// Memory size in bytes for Message Queue storage.</span></div>
<div class="line"><span class="comment">/// \param         msg_count     maximum number of messages in queue.</span></div>
<div class="line"><span class="comment">/// \param         msg_size      maximum message size in bytes.</span></div>
<div class="line"><span class="comment"></span><span class="preprocessor">#define osRtxMessageQueueMemSize(msg_count, msg_size) \</span></div>
<div class="line"><span class="preprocessor">  (4*(msg_count)*(3+(((msg_size)+3)/4)))</span></div>
<div class="line"><span class="preprocessor"></span> </div>
<div class="line"> </div>
<div class="line"><span class="comment">//  ==== OS External Functions ====</span></div>
<div class="line"> </div>
<div class="line"><span class="comment">// OS Error Codes</span></div>
<div class="line"><span class="preprocessor">#define osRtxErrorStackUnderflow        1U  </span><span class="comment">///&lt; Stack overflow, i.e. stack pointer below its lower memory limit for descending stacks.</span></div>
<div class="line"><span class="comment"></span>#define osRtxErrorISRQueueOverflow      2U  <span class="comment">///&lt; ISR Queue overflow detected when inserting object.</span></div>
<div class="line"><span class="comment"></span>#define osRtxErrorTimerQueueOverflow    3U  <span class="comment">///&lt; User Timer Callback Queue overflow detected for timer.</span></div>
<div class="line"><span class="comment"></span>#define osRtxErrorClibSpace             4U  <span class="comment">///&lt; Standard C/C++ library libspace not available: increase \c OS_THREAD_LIBSPACE_NUM.</span></div>
<div class="line"><span class="comment"></span>#define osRtxErrorClibMutex             5U  <span class="comment">///&lt; Standard C/C++ library mutex initialization failed.</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">/// OS Error Callback function</span></div>
<div class="line"><span class="comment"></span><span class="keyword">extern</span> uint32_t <a class="code" href="group__rtx5__specific__functions.html#gaf1745a88f9cc60b609ab1c8076bd346d">osRtxErrorNotify</a> (uint32_t code, <span class="keywordtype">void</span> *object_id);</div>
<div class="line"> <span class="comment"></span></div>
<div class="line"><span class="comment">/// OS Idle Thread</span></div>
<div class="line"><span class="comment"></span><span class="keyword">extern</span> <span class="keywordtype">void</span> <a class="code" href="group__rtx5__specific__functions.html#ga074068b8efa7074cee68a71481d0b072">osRtxIdleThread</a> (<span class="keywordtype">void</span> *argument);</div>
<div class="line"> <span class="comment"></span></div>
<div class="line"><span class="comment">/// OS Exception handlers</span></div>
<div class="line"><span class="comment"></span><span class="keyword">extern</span> <span class="keywordtype">void</span> <a class="code" href="rtx__os_8h.html#a3e5ddb3df0d62f2dc357e64a3f04a6ce">SVC_Handler</a>     (<span class="keywordtype">void</span>);</div>
<div class="line"><span class="keyword">extern</span> <span class="keywordtype">void</span> <a class="code" href="rtx__os_8h.html#a6303e1f258cbdc1f970ce579cc015623">PendSV_Handler</a>  (<span class="keywordtype">void</span>);</div>
<div class="line"><span class="keyword">extern</span> <span class="keywordtype">void</span> <a class="code" href="rtx__os_8h.html#ab5e09814056d617c521549e542639b7e">SysTick_Handler</a> (<span class="keywordtype">void</span>);</div>
<div class="line"> <span class="comment"></span></div>
<div class="line"><span class="comment">/// OS Trusted Firmware M Extension</span></div>
<div class="line"><span class="comment"></span><span class="preprocessor">#ifdef RTX_TF_M_EXTENSION</span></div>
<div class="line"><span class="preprocessor"></span><span class="keyword">extern</span> uint32_t osRtxTzGetModuleId (<span class="keywordtype">void</span>);</div>
<div class="line"><span class="preprocessor">#endif</span></div>
<div class="line"><span class="preprocessor"></span> </div>
<div class="line"> </div>
<div class="line"><span class="comment">//  ==== OS External Configuration ====</span></div>
<div class="line"> <span class="comment"></span></div>
<div class="line"><span class="comment">/// OS Configuration flags</span></div>
<div class="line"><span class="comment"></span><span class="preprocessor">#define osRtxConfigPrivilegedMode   (1UL&lt;&lt;0)    </span><span class="comment">///&lt; Threads in Privileged mode</span></div>
<div class="line"><span class="comment"></span>#define osRtxConfigStackCheck       (1UL&lt;&lt;1)    <span class="comment">///&lt; Stack overrun checking</span></div>
<div class="line"><span class="comment"></span>#define osRtxConfigStackWatermark   (1UL&lt;&lt;2)    <span class="comment">///&lt; Stack usage Watermark</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">/// OS Configuration structure</span></div>
<div class="line"><span class="comment"></span><span class="keyword">typedef</span> <span class="keyword">struct </span>{</div>
<div class="line">  uint32_t                             flags;   <span class="comment">///&lt; OS Configuration Flags</span></div>
<div class="line"><span class="comment"></span>  uint32_t                         tick_freq;   <span class="comment">///&lt; Kernel Tick Frequency</span></div>
<div class="line"><span class="comment"></span>  uint32_t                     robin_timeout;   <span class="comment">///&lt; Round Robin Timeout Tick</span></div>
<div class="line"><span class="comment"></span>  <span class="keyword">struct </span>{                                      <span class="comment">///&lt; ISR Post Processing Queue</span></div>
<div class="line"><span class="comment"></span>    <span class="keywordtype">void</span>                              **data;   <span class="comment">///&lt; Queue Data</span></div>
<div class="line"><span class="comment"></span>    uint16_t                             max;   <span class="comment">///&lt; Maximum Items</span></div>
<div class="line"><span class="comment"></span>    uint16_t                         padding;</div>
<div class="line">  } isr_queue;</div>
<div class="line">  <span class="keyword">struct </span>{                                      <span class="comment">///&lt; Memory Pools (Variable Block Size)</span></div>
<div class="line"><span class="comment"></span>    <span class="keywordtype">void</span>                         *stack_addr;   <span class="comment">///&lt; Stack Memory Address</span></div>
<div class="line"><span class="comment"></span>    uint32_t                      stack_size;   <span class="comment">///&lt; Stack Memory Size</span></div>
<div class="line"><span class="comment"></span>    <span class="keywordtype">void</span>                       *mp_data_addr;   <span class="comment">///&lt; Memory Pool Memory Address</span></div>
<div class="line"><span class="comment"></span>    uint32_t                    mp_data_size;   <span class="comment">///&lt; Memory Pool Memory Size</span></div>
<div class="line"><span class="comment"></span>    <span class="keywordtype">void</span>                       *mq_data_addr;   <span class="comment">///&lt; Message Queue Data Memory Address</span></div>
<div class="line"><span class="comment"></span>    uint32_t                    mq_data_size;   <span class="comment">///&lt; Message Queue Data Memory Size</span></div>
<div class="line"><span class="comment"></span>    <span class="keywordtype">void</span>                        *common_addr;   <span class="comment">///&lt; Common Memory Address</span></div>
<div class="line"><span class="comment"></span>    uint32_t                     common_size;   <span class="comment">///&lt; Common Memory Size</span></div>
<div class="line"><span class="comment"></span>  } mem;</div>
<div class="line">  <span class="keyword">struct </span>{                                      <span class="comment">///&lt; Memory Pools (Fixed Block Size)</span></div>
<div class="line"><span class="comment"></span>    <a class="code" href="rtx__os_8h.html#structosRtxMpInfo__t">osRtxMpInfo_t</a>                     *stack;   <span class="comment">///&lt; Stack for Threads</span></div>
<div class="line"><span class="comment"></span>    <a class="code" href="rtx__os_8h.html#structosRtxMpInfo__t">osRtxMpInfo_t</a>                    *thread;   <span class="comment">///&lt; Thread Control Blocks</span></div>
<div class="line"><span class="comment"></span>    <a class="code" href="rtx__os_8h.html#structosRtxMpInfo__t">osRtxMpInfo_t</a>                     *timer;   <span class="comment">///&lt; Timer Control Blocks</span></div>
<div class="line"><span class="comment"></span>    <a class="code" href="rtx__os_8h.html#structosRtxMpInfo__t">osRtxMpInfo_t</a>               *event_flags;   <span class="comment">///&lt; Event Flags Control Blocks</span></div>
<div class="line"><span class="comment"></span>    <a class="code" href="rtx__os_8h.html#structosRtxMpInfo__t">osRtxMpInfo_t</a>                     *mutex;   <span class="comment">///&lt; Mutex Control Blocks</span></div>
<div class="line"><span class="comment"></span>    <a class="code" href="rtx__os_8h.html#structosRtxMpInfo__t">osRtxMpInfo_t</a>                 *semaphore;   <span class="comment">///&lt; Semaphore Control Blocks</span></div>
<div class="line"><span class="comment"></span>    <a class="code" href="rtx__os_8h.html#structosRtxMpInfo__t">osRtxMpInfo_t</a>               *memory_pool;   <span class="comment">///&lt; Memory Pool Control Blocks</span></div>
<div class="line"><span class="comment"></span>    <a class="code" href="rtx__os_8h.html#structosRtxMpInfo__t">osRtxMpInfo_t</a>             *message_queue;   <span class="comment">///&lt; Message Queue Control Blocks</span></div>
<div class="line"><span class="comment"></span>  } mpi;</div>
<div class="line">  uint32_t                 thread_stack_size;   <span class="comment">///&lt; Default Thread Stack Size</span></div>
<div class="line"><span class="comment"></span>  <span class="keyword">const</span> </div>
<div class="line">  <a class="code" href="group__CMSIS__RTOS__ThreadMgmt.html#structosThreadAttr__t">osThreadAttr_t</a>           *idle_thread_attr;   <span class="comment">///&lt; Idle Thread Attributes</span></div>
<div class="line"><span class="comment"></span>  <span class="keyword">const</span></div>
<div class="line">  <a class="code" href="group__CMSIS__RTOS__ThreadMgmt.html#structosThreadAttr__t">osThreadAttr_t</a>          *timer_thread_attr;   <span class="comment">///&lt; Timer Thread Attributes</span></div>
<div class="line"><span class="comment"></span>  <span class="keyword">const</span></div>
<div class="line">  <a class="code" href="group__CMSIS__RTOS__Message.html#structosMessageQueueAttr__t">osMessageQueueAttr_t</a>        *timer_mq_attr;   <span class="comment">///&lt; Timer Message Queue Attributes</span></div>
<div class="line"><span class="comment"></span>  uint32_t                     timer_mq_mcnt;   <span class="comment">///&lt; Timer Message Queue maximum Messages</span></div>
<div class="line"><span class="comment"></span>} <a class="code" href="rtx__os_8h.html#structosRtxConfig__t">osRtxConfig_t</a>;</div>
<div class="line"> </div>
<div class="line"><span class="keyword">extern</span> <span class="keyword">const</span> <a class="code" href="rtx__os_8h.html#structosRtxConfig__t">osRtxConfig_t</a> <a class="code" href="rtx__os_8h.html#a489fda965fa634809f401ae6458a6f45">osRtxConfig</a>;         <span class="comment">///&lt; OS Configuration</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#ifdef  __cplusplus</span></div>
<div class="line"><span class="preprocessor"></span>}</div>
<div class="line"><span class="preprocessor">#endif</span></div>
<div class="line"><span class="preprocessor"></span> </div>
<div class="line"><span class="preprocessor">#endif  // RTX_OS_H_</span></div>
</div><!-- fragment --><h1><a class="anchor" id="CMSIS_RTOS_TimeOutValue"></a>
Timeout Value</h1>
<p>Timeout values are an argument to several <b>osXxx</b> functions to allow time for resolving a request. A timeout value of <b>0</b> means that the RTOS does not wait and the function returns instantly, even when no resource is available. A timeout value of <a class="el" href="group__CMSIS__RTOS__Definitions.html#ga9eb9a7a797a42e4b55eb171ecc609ddb">osWaitForever</a> means that the RTOS waits infinitely until a resource becomes available. Or one forces the thread to resume using <a class="el" href="group__CMSIS__RTOS__ThreadMgmt.html#ga3dbad90eff394b02de76a452c84c5d80">osThreadResume</a> which is discouraged.</p>
<p>The timeout value specifies the number of timer ticks until the time delay elapses. The value is an upper bound and depends on the actual time elapsed since the last timer tick.</p>
<p>Examples:</p>
<ul>
<li>timeout value <b>0</b> : the system does not wait, even when no resource is available the RTOS function returns instantly.</li>
<li>timeout value <b>1</b> : the system waits until the next timer tick occurs; depending on the previous timer tick, it may be a very short wait time.</li>
<li>timeout value <b>2</b> : actual wait time is between 1 and 2 timer ticks.</li>
<li>timeout value <a class="el" href="group__CMSIS__RTOS__Definitions.html#ga9eb9a7a797a42e4b55eb171ecc609ddb">osWaitForever</a> : system waits infinite until a resource becomes available.</li>
</ul>
<div class="image">
<img src="TimerValues.png" alt="TimerValues.png"/>
<div class="caption">
Example of timeout using osDelay()</div></div>
<h1><a class="anchor" id="CMSIS_RTOS_ISR_Calls"></a>
Calls from Interrupt Service Routines</h1>
<p>The following CMSIS-RTOS2 functions can be called from threads and Interrupt Service Routines (ISR):</p>
<ul>
<li><a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga6f7764e7250c5c5364c00c45a5d1d199">osKernelGetInfo</a>, <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga48b69b81012fce051f639be288b243ba">osKernelGetState</a>, <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga84bcdbf2fb76b10c8df4e439f0c7e11b">osKernelGetTickCount</a>, <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga7a8d7bd927eaaa58999f91d7d6310cee">osKernelGetTickFreq</a>, <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#gae0fcaff6cecfb4013bb556c87afcd7d2">osKernelGetSysTimerCount</a>, <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga4d69215a93220f72be3684cad582f16a">osKernelGetSysTimerFreq</a></li>
<li><a class="el" href="group__CMSIS__RTOS__ThreadMgmt.html#ga8df03548e89fbc56402a5cd584a505da">osThreadGetId</a>, <a class="el" href="group__CMSIS__RTOS__ThreadFlagsMgmt.html#ga6f89ef9caded1d9963c7b12b0f6412c9">osThreadFlagsSet</a></li>
<li><a class="el" href="group__CMSIS__RTOS__EventFlags.html#ga33b71d14cecf90b4e72639dd19f23a5e">osEventFlagsSet</a>, <a class="el" href="group__CMSIS__RTOS__EventFlags.html#ga93bf258ca0007c6641fbe8e4f2b8a1e5">osEventFlagsClear</a>, <a class="el" href="group__CMSIS__RTOS__EventFlags.html#ga8bda3185f46bfd278cea8a6cf357677d">osEventFlagsGet</a>, <a class="el" href="group__CMSIS__RTOS__EventFlags.html#ga52acb34a8322e58020227344fe662b4e">osEventFlagsWait</a></li>
<li><a class="el" href="group__CMSIS__RTOS__SemaphoreMgmt.html#ga7e94c8b242a0c81f2cc79ec22895c87b">osSemaphoreAcquire</a>, <a class="el" href="group__CMSIS__RTOS__SemaphoreMgmt.html#ga0abcee1b5449d7a6928fb9248c690bb6">osSemaphoreRelease</a>, <a class="el" href="group__CMSIS__RTOS__SemaphoreMgmt.html#ga7559d4dff3cda9992fc5ab5de3e74c70">osSemaphoreGetCount</a></li>
<li><a class="el" href="group__CMSIS__RTOS__PoolMgmt.html#ga8ead54e99ccb8f112356c88f99d38fbe">osMemoryPoolAlloc</a>, <a class="el" href="group__CMSIS__RTOS__PoolMgmt.html#gabb4f4560daa6d1f8c8789082ee186d16">osMemoryPoolFree</a>, <a class="el" href="group__CMSIS__RTOS__PoolMgmt.html#gad696e94bfbe28f0b6613f9303fdf6a37">osMemoryPoolGetCapacity</a>, <a class="el" href="group__CMSIS__RTOS__PoolMgmt.html#gab2bf059b7fa7679c3cccdaeec60b6c0e">osMemoryPoolGetBlockSize</a>, <a class="el" href="group__CMSIS__RTOS__PoolMgmt.html#ga958a9449bff8c95ce213de98eef5739d">osMemoryPoolGetCount</a>, <a class="el" href="group__CMSIS__RTOS__PoolMgmt.html#ga0394cffa9479a7994e3b03c79c1cb909">osMemoryPoolGetSpace</a></li>
<li><a class="el" href="group__CMSIS__RTOS__Message.html#gaa515fc8b956f721a8f72b2c505813bfc">osMessageQueuePut</a>, <a class="el" href="group__CMSIS__RTOS__Message.html#gad90d4959466a7a65105061da8256ab9e">osMessageQueueGet</a>, <a class="el" href="group__CMSIS__RTOS__Message.html#gac24f87d4f395e9e9c900c320e45ade8a">osMessageQueueGetCapacity</a>, <a class="el" href="group__CMSIS__RTOS__Message.html#ga96d3d84069b20359de48109e28a1a89e">osMessageQueueGetMsgSize</a>, <a class="el" href="group__CMSIS__RTOS__Message.html#ga6a32ac394fcff568b251c160cc3014b2">osMessageQueueGetCount</a>, <a class="el" href="group__CMSIS__RTOS__Message.html#gaddf0904427436dd3880d46263c2dc9fa">osMessageQueueGetSpace</a></li>
</ul>
<p>Functions that cannot be called from an ISR are verifying the interrupt status and return the status code <b>osErrorISR</b>, in case they are called from an ISR context. In some implementations, this condition might be caught using the HARD_FAULT vector.</p>
<h1><a class="anchor" id="CMSIS_RTOS_svcFunctions"></a>
SVC Functions</h1>
<p>Supervisor Calls (SVC) are exceptions targeted at software and operating systems for generating system function calls. They are sometimes called software interrupts. For example, instead of allowing user programs to directly access hardware, an operating system may provide access to hardware through an SVC. So when a user program wants to use certain hardware, it generates the exception using SVC instructions. The software exception handler in the operating system executes and provides the requested service to the user application. In this way, access to hardware is under the control of the OS, which can provide a more robust system by preventing the user applications from directly accessing the hardware.</p>
<p>SVCs can also make software more portable because the user application does not need to know the programming details of the underlying hardware. The user program will only need to know the application programming interface (API) function ID and parameters; the actual hardware-level programming is handled by device drivers.</p>
<p>SVCs run in <b>privileged</b> <b>handler</b> mode of the Arm Cortex-M core. SVC functions accept arguments and can return values. The functions are used in the same way as other functions; however, they are executed indirectly through the SVC instruction. When executing SVC instructions, the controller changes to the privileged handler mode.</p>
<p>Interrupts are <b>not</b> <b>disabled</b> in this mode. To protect SVC functions from interrupts, you need to include the disable/enable intrinsic functions <code>__disable_irq()</code> and <code>__enable_irq()</code> in your code.</p>
<p>You can use SVC functions to access <b>protected</b> <b>peripherals</b>, for example, to configure NVIC and interrupts. This is required if you run threads in unprivileged (protected) mode and you need to change interrupts from the within the thread.</p>
<p>To implement SVC functions in your Keil RTX5 project, you need to:</p>
<ol type="1">
<li>Add the SVC User Table file <b>svc_user.c</b> to your project folder and include it into your project. This file is available as a user code template.</li>
<li>Write a function implementation. Example: <div class="fragment"><div class="line">uint32_t svc_atomic_inc32 (uint32_t *mem) {</div>
<div class="line">  <span class="comment">// A protected function to increment a counter. </span></div>
<div class="line">  uint32_t val;</div>
<div class="line">   </div>
<div class="line">  __disable_irq();</div>
<div class="line">  val  = *mem;</div>
<div class="line">  (*mem) = val + 1U;</div>
<div class="line">  __enable_irq();</div>
<div class="line">   </div>
<div class="line">  <span class="keywordflow">return</span> (val);</div>
<div class="line">}</div>
</div><!-- fragment --></li>
<li>Add the function to the SVC function table in the <b>svc_user.c</b> module: <div class="fragment"><div class="line"><span class="keywordtype">void</span> * <span class="keyword">const</span> osRtxUserSVC[1+USER_SVC_COUNT] = {</div>
<div class="line">  (<span class="keywordtype">void</span> *)USER_SVC_COUNT,</div>
<div class="line">  (<span class="keywordtype">void</span> *)svc_atomic_inc32,</div>
<div class="line">};</div>
</div><!-- fragment --></li>
<li>Increment the number of user SVC functions: <div class="fragment"><div class="line"><span class="preprocessor">#define USER_SVC_COUNT  1       // Number of user SVC functions</span></div>
</div><!-- fragment --></li>
<li><p class="startli">Declare a function wrapper to be called by the user to execute the SVC call.<br/>
 <b>Code</b> <b>Example</b> (Arm Compiler 6) </p>
<div class="fragment"><div class="line">__STATIC_FORCEINLINE uint32_t atomic_inc32 (uint32_t *mem) {</div>
<div class="line">  <span class="keyword">register</span> uint32_t val;</div>
<div class="line">       </div>
<div class="line">  __ASM <span class="keyword">volatile</span> (</div>
<div class="line">    <span class="stringliteral">&quot;svc 1&quot;</span> : <span class="stringliteral">&quot;=l&quot;</span> (val) : <span class="stringliteral">&quot;l&quot;</span> (mem) : <span class="stringliteral">&quot;cc&quot;</span>, <span class="stringliteral">&quot;memory&quot;</span></div>
<div class="line">  );</div>
<div class="line">  <span class="keywordflow">return</span> (val);</div>
<div class="line">}</div>
</div><!-- fragment --><p class="startli"><b>Code</b> <b>Example</b> (Arm Compiler 5 using <code>__svc(x)</code> attribute) </p>
<div class="fragment"><div class="line">uint32_t atomic_inc32 (uint32_t *mem) __svc(1);</div>
</div><!-- fragment --></li>
</ol>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>The SVC function <span class="XML-Token">0</span> is <b>reserved</b> for the Keil RTX5 kernel.</li>
<li>Do not leave gaps when numbering SVC functions. They must occupy a <b>continuous</b> range of numbers starting from 1.</li>
<li>SVC functions can still be interrupted. </li>
</ul>
</dd></dl>
</div></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="index.html">index</a></li><li class="navelem"><a class="el" href="rtx5_impl.html">RTX v5 Implementation</a></li>
    <li class="footer">Generated on Wed Jul 10 2019 15:21:03 for CMSIS-RTOS2 Version 2.1.3 by Arm Ltd. All rights reserved.
	<!--
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.6 
	-->
	</li>
  </ul>
</div>
</body>
</html>