Select one of the symbols to view example projects that use it.
 
Outline
#include <string.h>
#include "cmsis_os2.h"
#include "cmsis_compiler.h"
#include "tx_api.h"
#include "tx_initialize.h"
#include "tx_thread.h"
#include "tx_timer.h"
#include "tx_byte_pool.h"
#include "tx_event_flags.h"
#include "tx_mutex.h"
#include "tx_semaphore.h"
#include "tx_queue.h"
#define KERNEL_ID
#define IS_IRQ_MODE
#define RTOS2_DEFAULT_THREAD_STACK_SIZE
#define RTOS2_INTERNAL_BYTE_POOL_SIZE
#define RTOS2_BYTE_POOL_STACK_SIZE
#define RTOS2_BYTE_POOL_HEAP_SIZE
#define RTOS2_DEFAULT_TIME_SLICE
#define RTOS2_BYTE_POOL_STACK_TYPE
#define RTOS2_BYTE_POOL_HEAP_TYPE
KernelState
HeapBytePool
StackBytePool
-------------------CMSIS RTOS2 Internal Functions
MemAlloc(uint32_t, uint8_t)
MemFree(void *)
MemInit()
---------------------------Kenel Management APIs
osKernelInitialize()
osKernelGetInfo(osVersion_t *, char *, uint32_t)
osKernelGetState()
osKernelStart()
osKernelGetTickCount()
osKernelGetTickFreq()
osKernelGetSysTimerCount()
osKernelGetSysTimerFreq()
-----------------------------Generic Wait APIs
osDelay(uint32_t)
osDelayUntil(uint32_t)
--------------------------Thread Management APIs
osThreadNew(osThreadFunc_t, void *, const osThreadAttr_t *)
osThreadGetName(osThreadId_t)
osThreadGetId()
osThreadGetState(osThreadId_t)
osThreadGetStackSize(osThreadId_t)
osThreadGetStackSpace(osThreadId_t)
osThreadSetPriority(osThreadId_t, osPriority_t)
osThreadGetPriority(osThreadId_t)
osThreadYield()
osThreadSuspend(osThreadId_t)
osThreadResume(osThreadId_t)
osThreadExit()
osThreadTerminate(osThreadId_t)
osThreadDetach(osThreadId_t)
osThreadJoin(osThreadId_t)
osThreadGetCount()
osThreadEnumerate(osThreadId_t *, uint32_t)
---------------------------Timer Management APIs
osTimerNew(osTimerFunc_t, osTimerType_t, void *, const osTimerAttr_t *)
osTimerGetName(osTimerId_t)
osTimerIsRunning(osTimerId_t)
osTimerStop(osTimerId_t)
osTimerStart(osTimerId_t, uint32_t)
osTimerDelete(osTimerId_t)
-----------------------------Event flags APIs
osEventFlagsNew(const osEventFlagsAttr_t *)
osEventFlagsGetName(osEventFlagsId_t)
osEventFlagsSet(osEventFlagsId_t, uint32_t)
osEventFlagsClear(osEventFlagsId_t, uint32_t)
osEventFlagsGet(osEventFlagsId_t)
osEventFlagsWait(osEventFlagsId_t, uint32_t, uint32_t, uint32_t)
osEventFlagsDelete(osEventFlagsId_t)
---------------------------Mutex Management APIs
osMutexNew(const osMutexAttr_t *)
osMutexGetName(osMutexId_t)
osMutexAcquire(osMutexId_t, uint32_t)
osMutexRelease(osMutexId_t)
osMutexGetOwner(osMutexId_t)
osMutexDelete(osMutexId_t)
------------------------------Semaphores APIs
osSemaphoreNew(uint32_t, uint32_t, const osSemaphoreAttr_t *)
osSemaphoreGetName(osSemaphoreId_t)
osSemaphoreAcquire(osSemaphoreId_t, uint32_t)
osSemaphoreRelease(osSemaphoreId_t)
osSemaphoreDelete(osSemaphoreId_t)
------------------------------Message Queue APIs
osMessageQueueNew(uint32_t, uint32_t, const osMessageQueueAttr_t *)
osMessageQueueGetName(osMessageQueueId_t)
osMessageQueueGetCapacity(osMessageQueueId_t)
osMessageQueueGetMsgSize(osMessageQueueId_t)
osMessageQueueGetCount(osMessageQueueId_t)
osMessageQueueGetSpace(osMessageQueueId_t)
osMessageQueueReset(osMessageQueueId_t)
osMessageQueueDelete(osMessageQueueId_t)
osMessageQueuePut(osMessageQueueId_t, const void *, uint8_t, uint32_t)
osMessageQueueGet(osMessageQueueId_t, void *, uint8_t *, uint32_t)
------------------------tx_application_define API
tx_application_define(void *)
Files
loading...
SourceVuSTM32 Libraries and Samplescmsis_rtos_threadxcmsis_os2.c
 
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
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file cmsis_os2.c * @author MCD Application Team * @brief CMSIS RTOS2 wrapper for AzureRTOS ThreadX ****************************************************************************** * @attention * * Copyright (c) 2020 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /** * Important note * -------------- * This file is the implementation of functions to wrap CMSIS RTOS2 onto * AzureRTOS ThreadX based on API published by Arm Limited in cmsis_os2.h. * The implementation of these functions is inspired from an original work from * Arm Limited to wrap CMSIS RTOS2 onto FreeRTOS (see copyright and license * information below). * The whole contents of this file is a creation by STMicroelectronics licensed * to you under the License as specified above. However, some functions * originally created by Arm Limited have not been strongly reworked by * STMicroelectronics and are still available under their Apache License, * Version 2.0 original terms; these original functions are: * - osKernelGetInfo * - osKernelStart * - osKernelGetTickCount * - osKernelGetTickFreq * - osKernelGetSysTimerFreq * - osDelay * - osDelayUntil * - osThreadGetId * - osTimerIsRunning *//* ... */ /* -------------------------------------------------------------------------- * Copyright (c) 2013-2019 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Name: cmsis_os2.c * Purpose: CMSIS RTOS2 wrapper for AzureRTOS ThreadX * *---------------------------------------------------------------------------*//* ... */ #include <string.h> /* ::CMSIS:RTOS2 */ #include "cmsis_os2.h" /* CMSIS compiler specific defines */ #include "cmsis_compiler.h" #include "tx_api.h" #include "tx_initialize.h" #include "tx_thread.h" #include "tx_timer.h" #include "tx_byte_pool.h" #include "tx_event_flags.h" #include "tx_mutex.h" #include "tx_semaphore.h" #include "tx_queue.h" 12 includes /*---------------------------------------------------------------------------*/ /* Kernel version and identification string definition (major.minor.rev: mmnnnrrrr dec) */ #define KERNEL_VERSION (((uint32_t)THREADX_MAJOR_VERSION * 10000000UL) + \ ((uint32_t)THREADX_MINOR_VERSION * 10000UL) + \ ((uint32_t)THREADX_PATCH_VERSION * 1UL))... #define KERNEL_ID ("AzureRTOS ThreadX") #define IS_IRQ_MODE() (__get_IPSR() != 0U) /* Default thread stack size */ #define RTOS2_DEFAULT_THREAD_STACK_SIZE 1024 /* Default thread stack size */ #define RTOS2_INTERNAL_BYTE_POOL_SIZE 256 5 defines /* Default stack byte pool memory size */ #ifndef RTOS2_BYTE_POOL_STACK_SIZE #define RTOS2_BYTE_POOL_STACK_SIZE 3 * 1024 #endif /* Default stack byte pool memory size */ #ifndef RTOS2_BYTE_POOL_HEAP_SIZE #define RTOS2_BYTE_POOL_HEAP_SIZE 4 * 1024 #endif /* Default time slice for the created threads */ #ifndef RTOS2_DEFAULT_TIME_SLICE #define RTOS2_DEFAULT_TIME_SLICE 4 #endif /* Default stack byte pool memory type */ #define RTOS2_BYTE_POOL_STACK_TYPE 1 /* Default stack byte pool memory type */ #define RTOS2_BYTE_POOL_HEAP_TYPE 2 #ifndef TX_THREAD_USER_EXTENSION #error "CMSIS RTOS ThreadX Wrapper: TX_THREAD_USER_EXTENSION must be defined as tx_thread_detached_joinable (ULONG) in tx_user.h file" #endif #ifdef TX_DISABLE_ERROR_CHECKING #error "CMSIS RTOS ThreadX Wrapper : TX_DISABLE_ERROR_CHECKING must be undefined" #endif /* Ensure the maximum number of priorities is modified by the user to 64. */ #if(TX_MAX_PRIORITIES != 64) #error "CMSIS RTOS ThreadX Wrapper: TX_MAX_PRIORITIES must be fixed to 64 in tx_user.h file" #endif /*---------------------------------------------------------------------------*/ static osKernelState_t KernelState = osKernelInactive; extern uint32_t SystemCoreClock; TX_BYTE_POOL HeapBytePool; TX_BYTE_POOL StackBytePool; /*---------------------------------------------------------------------------*/ /*-------------------CMSIS RTOS2 Internal Functions--------------------------*/ /*---------------------------------------------------------------------------*/ /** * @brief The function MemAlloc allocates thread, timer, mutex, semaphore, * event flags and message queue block object memory. * Or it allocates the thread or message queue stack memory. * @param [in] memory size to be allocated from BytePool * [in] to be allocated memory type (Heap or Stack) * @retval pointer to the allocated memory or NULL in case of error. *//* ... */ static uint8_t *MemAlloc(uint32_t mem_size, uint8_t pool_type) { /* The output pointer to the allocated memory or NULL in case of error */ uint8_t *mem_ptr; /* Allocated memory size */ uint32_t allocated_mem_size = mem_size; /* Pointer to the BytePool to be used for memory allocation */ TX_BYTE_POOL *byte_pool; /* Check if the memory size is invalid or the BytePool type is wrong */ if ((mem_size == 0) || (pool_type > RTOS2_BYTE_POOL_HEAP_TYPE)) { /* Return NULL in case of error */ mem_ptr = NULL; }if ((mem_size == 0) || (pool_type > RTOS2_BYTE_POOL_HEAP_TYPE)) { ... } else { /* If the memory size the be allocated is less then the TX_BYTE_POOL_MIN */ if (allocated_mem_size < TX_BYTE_POOL_MIN) { /* We should at least allocate TX_BYTE_POOL_MIN */ allocated_mem_size = TX_BYTE_POOL_MIN; }if (allocated_mem_size < TX_BYTE_POOL_MIN) { ... } /* Assign the BytePool to be used (StackBytePool or HeapBytePool) */ if (pool_type == RTOS2_BYTE_POOL_STACK_TYPE) { /* Point to the Stack BytePool */ byte_pool = &StackBytePool; }if (pool_type == RTOS2_BYTE_POOL_STACK_TYPE) { ... } else { /* Point to the Heap BytePool */ byte_pool = &HeapBytePool; }else { ... } /* Allocate the mem_ptr */ if (tx_byte_allocate(byte_pool, (void **) &mem_ptr, allocated_mem_size, TX_NO_WAIT) != TX_SUCCESS) { /* Return NULL in case of error */ mem_ptr = NULL; }if (tx_byte_allocate(byte_pool, (void **) &mem_ptr, allocated_mem_size, TX_NO_WAIT) != TX_SUCCESS) { ... } }else { ... } return (mem_ptr); }{ ... } /** * @brief The function MemFree allocates thread, timer, mutex, semaphore, * event flags and message queue block object memory. * Or it allocates the thread or message queue stack memory. * @param [in] memory size to be allocated from BytePool * [in] to be allocated memory type (Heap or Stack) * @retval pointer to the allocated memory or NULL in case of error. *//* ... */ static osStatus_t MemFree(VOID *memory_ptr) { /* The output status code that indicates the execution status */ osStatus_t status = osOK; /* Check if the memory_ptr is invalid */ if (memory_ptr == NULL) { /* Return osError in case of error */ status = osError; }if (memory_ptr == NULL) { ... } else { /* Free the allocated memory_ptr */ if (tx_byte_release(memory_ptr) != TX_SUCCESS) { /* Return osError in case of error */ status = osError; }if (tx_byte_release(memory_ptr) != TX_SUCCESS) { ... } }else { ... } return (status); }{ ... } /** * @brief The function MemInit creates memory pools for stack and heap. * The stack pool is used for threads and queues stacks allocations. * The heap pool is used for threads, timers, mutex, semaphores, * message queues and events flags control block object memory allocations. * The size of stack and heap pools are user configured using the * RTOS2_BYTE_POOL_STACK_SIZE and RTOS2_BYTE_POOL_HEAP_SIZE flags. * @param none. * @retval status code that indicates the execution status of the function. *//* ... */ static osStatus_t MemInit(void) { /* Allocated memory size */ uint32_t bytepool_size = RTOS2_BYTE_POOL_STACK_SIZE; /* Unused memory address */ CHAR *unused_memory = NULL; /* If the memory size the be allocated is less then the TX_BYTE_POOL_MIN */ if (bytepool_size < TX_BYTE_POOL_MIN) { /* We should at least allocate TX_BYTE_POOL_MIN */ bytepool_size = TX_BYTE_POOL_MIN; }if (bytepool_size < TX_BYTE_POOL_MIN) { ... } /* Initialize the Heap BytePool address */ unused_memory = (CHAR *)_tx_initialize_unused_memory; /* Create a byte memory pool from which to allocate the timer control block *//* ... */ if (tx_byte_pool_create(&StackBytePool, "Byte Pool Stack", unused_memory, RTOS2_INTERNAL_BYTE_POOL_SIZE + bytepool_size) != TX_SUCCESS) { /* Return osError in case of error */ return (osError); }if (tx_byte_pool_create(&StackBytePool, "Byte Pool Stack", unused_memory, RTOS2_INTERNAL_BYTE_POOL_SIZE + bytepool_size) != TX_SUCCESS) { ... } else { /* Set the tx_initialize_unused_memory address */ unused_memory += RTOS2_INTERNAL_BYTE_POOL_SIZE + bytepool_size; }else { ... } /* Set bytepool_size to the user configured Heap size */ bytepool_size = RTOS2_BYTE_POOL_HEAP_SIZE; /* If the memory size the be allocated is less then the TX_BYTE_POOL_MIN */ if (bytepool_size < TX_BYTE_POOL_MIN) { /* We should at least allocate TX_BYTE_POOL_MIN */ bytepool_size = TX_BYTE_POOL_MIN; }if (bytepool_size < TX_BYTE_POOL_MIN) { ... } /* Create a byte memory pool from which to allocate the timer control block *//* ... */ if (tx_byte_pool_create(&HeapBytePool, "Byte Pool Heap", unused_memory, RTOS2_INTERNAL_BYTE_POOL_SIZE + bytepool_size) != TX_SUCCESS) { /* Return osError in case of error */ return (osError); }if (tx_byte_pool_create(&HeapBytePool, "Byte Pool Heap", unused_memory, RTOS2_INTERNAL_BYTE_POOL_SIZE + bytepool_size) != TX_SUCCESS) { ... } else { /* Set the tx_initialize_unused_memory address */ unused_memory += RTOS2_INTERNAL_BYTE_POOL_SIZE + bytepool_size; }else { ... } /* Update the _tx_initialize_unused_memory */ _tx_initialize_unused_memory = unused_memory; return (osOK); }{ ... } /*---------------------------------------------------------------------------*/-------------------CMSIS RTOS2 Internal Functions /*---------------------------Kenel Management APIs---------------------------*/ /*---------------------------------------------------------------------------*/ /** * @brief The function osKernelInitialize initializes the RTOS Kernel. Before * it is successfully executed, only the functions osKernelGetInfo and * osKernelGetState may be called. * Note : This function cannot be called from Interrupt Service * Routines. * @param none * @retval status code that indicates the execution status of the function. *//* ... */ osStatus_t osKernelInitialize(void) { /* The output status code that indicates the execution status */ osStatus_t status; /* Check if this API is called from Interrupt Service Routines */ if (IS_IRQ_MODE()) { /* Return osErrorISR in case of error */ status = osErrorISR; }if (IS_IRQ_MODE()) { ... } else { /* Check if the kernel state is osKernelInactive */ if (KernelState == osKernelInactive) { /* Initialize the kernel */ _tx_initialize_kernel_setup(); /* Initialize the Heap and stack memory BytePools */ if (MemInit() == osOK) { /* Set the kernel state to osKernelReady */ KernelState = osKernelReady; /* Return osOK in case of success */ status = osOK; }if (MemInit() == osOK) { ... } else { /* Return osError in case of error */ status = osError; }else { ... } }if (KernelState == osKernelInactive) { ... } else { /* Return osError in case of error */ status = osError; }else { ... } }else { ... } return (status); }{ ... } /** * @brief The function osKernelGetInfo retrieves the API and kernel version * of the underlying RTOS kernel and a human readable identifier string * for the kernel. It can be safely called before the RTOS is * initialized or started (call to osKernelInitialize or osKernelStart) * Note : This function may be called from Interrupt Service * Routines. * @param [out] version pointer to buffer for retrieving version information. * [out] id_buf pointer to buffer for retrieving kernel identification * string. * [in] id_size size of buffer for kernel identification string. * @retval status code that indicates the execution status of the function. *//* ... */ osStatus_t osKernelGetInfo(osVersion_t *version, char *id_buf, uint32_t id_size) { /* The output status code that indicates the execution status */ osStatus_t status = osOK; /* Check if input version pointer is not NULL */ if (version != NULL) { /* Version encoding is major.minor.rev: mmnnnrrrr dec */ version->api = KERNEL_VERSION; version->kernel = KERNEL_VERSION; }if (version != NULL) { ... } else { /* Return osError in case of error */ status = osError; }else { ... } /* Check if input id_buf pointer is not NULL and id_size != 0 */ if ((id_buf != NULL) && (id_size != 0U)) { if (id_size > sizeof(KERNEL_ID)) { id_size = sizeof(KERNEL_ID); }if (id_size > sizeof(KERNEL_ID)) { ... } memcpy(id_buf, KERNEL_ID, id_size); }if ((id_buf != NULL) && (id_size != 0U)) { ... } else { /* Return osError in case of error */ status = osError; }else { ... } return (status); }{ ... } /** * @brief The function osKernelGetState returns the current state of the * kernel and can be safely called before the RTOS is initialized or * started (call to osKernelInitialize or osKernelStart). In case it * fails it will return osKernelError, otherwise it returns the kernel * state (refer to osKernelState_t for the list of kernel states). * Note : This function may be called from Interrupt Service * Routines. * @param none * @retval current RTOS Kernel state. *//* ... */ osKernelState_t osKernelGetState(void) { return (KernelState); }{ ... } /** * @brief The function osKernelStart starts the RTOS kernel and begins thread * switching. It will not return to its calling function in case of * success. Before it is successfully executed, only the functions * osKernelGetInfo, osKernelGetState, and object creation functions * (osXxxNew) may be called. * Note : This function cannot be called from Interrupt Service * Routines. * @param none * @retval status code that indicates the execution status of the function. *//* ... */ osStatus_t osKernelStart(void) { /* The output status code that indicates the execution status */ osStatus_t status; /* Check if this API is called from Interrupt Service Routines */ if (IS_IRQ_MODE()) { /* Return osErrorISR in case of error */ status = osErrorISR; }if (IS_IRQ_MODE()) { ... } else { /* Check if the kernel state is osKernelReady */ if (KernelState == osKernelReady) { /* Set the kernel state to osKernelRunning */ KernelState = osKernelRunning; /* Return osOK in case of success */ status = osOK; /* Start the Kernel */ tx_kernel_enter(); }if (KernelState == osKernelReady) { ... } else { /* Return osError in case of error */ status = osError; }else { ... } }else { ... } return (status); }{ ... } /** * @brief The function osKernelGetTickCount returns the current RTOS kernel * tick count. * Note : This function may be called from Interrupt Service * Routines. * @param none * @retval RTOS kernel current tick count. *//* ... */ uint32_t osKernelGetTickCount(void) { /* The output RTOS kernel current tick count */ uint32_t ticks; /* Get the RTOS kernel current tick count */ ticks = (uint32_t)tx_time_get(); return (ticks); }{ ... } /** * @brief The function osKernelGetTickFreq returns the frequency of the * current RTOS kernel tick. * Note : This function may be called from Interrupt Service * Routines. * @param none * @retval frequency of the kernel tick in hertz, i.e. kernel ticks per second. *//* ... */ uint32_t osKernelGetTickFreq(void) { return (TX_TIMER_TICKS_PER_SECOND); }{ ... } /** * @brief The function osKernelGetSysTimerCount returns the current RTOS * kernel system timer as a 32-bit value. The value is a rolling 32-bit * counter that is composed of the kernel system interrupt timer value * and the counter that counts these interrupts (RTOS kernel ticks). * This function allows the implementation of very short timeout checks * below the RTOS tick granularity. Such checks might be required when * checking for a busy status in a device or peripheral initialization * routine, see code example below. * Note : This function may be called from Interrupt Service * Routines. * @param none * @retval RTOS kernel current system timer count as 32-bit value. *//* ... */ uint32_t osKernelGetSysTimerCount(void) { /* The RTOS kernel current tick count */ uint32_t ticks; /* The output RTOS kernel current system timer count as 32-bit value */ uint32_t val; /* Get the RTOS kernel current tick count */ ticks = (uint32_t)tx_time_get(); /* Compute the RTOS kernel current system timer count */ val = (uint32_t)(ticks * (SystemCoreClock / TX_TIMER_TICKS_PER_SECOND)); return (val); }{ ... } /** * @brief The function osKernelGetSysTimerFreq returns the frequency of the * current RTOS kernel system timer. * Note : This function may be called from Interrupt Service * Routines. * @param none * @retval frequency of the system timer in hertz, i.e. timer ticks per second. *//* ... */ uint32_t osKernelGetSysTimerFreq(void) { return (SystemCoreClock); }{ ... } /*---------------------------------------------------------------------------*/---------------------------Kenel Management APIs /*-----------------------------Generic Wait APIs-----------------------------*/ /*---------------------------------------------------------------------------*/ /** * @brief The function osDelay waits for a time period specified in kernel * ticks. For a value of 1 the system waits until the next timer tick * occurs. The actual time delay may be up to one timer tick less than * specified, i.e. calling osDelay(1) right before the next system tick * occurs the thread is rescheduled immediately. * The delayed thread is put into the BLOCKED state and a context * switch occurs immediately. The thread is automatically put back to * the READY state after the given amount of ticks has elapsed. If the * thread will have the highest priority in READY state it will being * scheduled immediately. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] ticks time ticks value * @retval status code that indicates the execution status of the function. *//* ... */ osStatus_t osDelay(uint32_t ticks) { /* The output status code that indicates the execution status */ osStatus_t status; /* Check if this API is called from Interrupt Service Routines */ if (IS_IRQ_MODE()) { /* Return osErrorISR in case of error */ status = osErrorISR; }if (IS_IRQ_MODE()) { ... } else { /* Return osOK in case of success */ status = osOK; /* Check that the input ticks != 0 */ if (ticks != 0U) { /* Sleep the thread */ tx_thread_sleep(ticks); }if (ticks != 0U) { ... } }else { ... } return (status); }{ ... } /** * @brief The function osDelayUntil waits until an absolute time (specified * in kernel ticks) is reached. * The corner case when the kernel tick counter overflows is handled by * osDelayUntil. Thus it is absolutely legal to provide a value which * is lower than the current tick value, i.e. returned by * osKernelGetTickCount. Typically as a user you do not have to take * care about the overflow. The only limitation you have to have in * mind is that the maximum delay is limited to (231)-1 ticks. * The delayed thread is put into the BLOCKED state and a context * switch occurs immediately. The thread is automatically put back to * the READY state when the given time is reached. If the thread will * have the highest priority in READY state it will being scheduled * immediately. * @param [in] ticks absolute time in ticks * @retval status code that indicates the execution status of the function. *//* ... */ osStatus_t osDelayUntil(uint32_t ticks) { uint32_t tcnt, delay; /* The output status code that indicates the execution status */ osStatus_t status; /* Check if this API is called from Interrupt Service Routines */ if (IS_IRQ_MODE()) { /* Return osErrorISR in case of error */ status = osErrorISR; }if (IS_IRQ_MODE()) { ... } else { /* Return osOK in case of success */ status = osOK; /* Return osOK in case of success */ tcnt = (uint32_t)tx_time_get(); /* Determine remaining number of ticks to delay */ delay = ticks - tcnt; /* Check if target tick has not expired */ if ((delay != 0U) && (0 == (delay >> (8 * sizeof(uint32_t) - 1)))) { /* Sleep the thread */ tx_thread_sleep(delay); }if ((delay != 0U) && (0 == (delay >> (8 * sizeof(uint32_t) - 1)))) { ... } else { /* No delay or already expired */ status = osErrorParameter; }else { ... } }else { ... } return (status); }{ ... } /*---------------------------------------------------------------------------*/-----------------------------Generic Wait APIs /*--------------------------Thread Management APIs---------------------------*/ /*---------------------------------------------------------------------------*/ /** * @brief The function osThreadNew starts a thread function by adding it to * the list of active threads and sets it to state READY. Arguments for * the thread function are passed using the parameter pointer * *argument. When the priority of the created thread function is * higher than the current RUNNING thread, the created thread function * starts instantly and becomes the new RUNNING thread. Thread * attributes are defined with the parameter pointer attr. Attributes * include settings for thread priority, stack size, or memory * allocation. * The function can be safely called before the RTOS is started * (call to osKernelStart), but not before it is initialized (call to * osKernelInitialize). * The function osThreadNew returns the pointer to the thread object * identifier or NULL in case of an error. * Note : This function Cannot be called from Interrupt Service * Routines. * @param [in] func thread function. * [in] argument pointer that is passed to the thread function as * start argument. * [in] attr thread attributes; NULL: default values. * @retval thread ID for reference by other functions or NULL in case of error. *//* ... */ osThreadId_t osThreadNew(osThreadFunc_t func, void *argument, const osThreadAttr_t *attr) { /* For ThreadX the control block pointer is the thread identifier */ TX_THREAD *thread_ptr = NULL; /* Pointer to the thread name */ CHAR *name_ptr = NULL; /* Pointer to start address of the thread stack */ VOID *stack_start; /* The thread stack size */ ULONG stack_size; /* The thread control block size */ ULONG cb_size; /* The thread priority */ UINT priority; /* The thread entry input */ ULONG entry_input = 0; /* Check if this API is called from Interrupt Service Routines or the thread_id is NULL *//* ... */ if (!IS_IRQ_MODE() && (func != NULL)) { /* Initialize the name_ptr to NULL */ name_ptr = NULL; /* Check if the attr is not NULL */ if (attr != NULL) { /* Check if the name_ptr is not NULL */ if (attr->name != NULL) { /* Set the thread name_ptr */ name_ptr = (CHAR *)attr->name; }if (attr->name != NULL) { ... } /* Check the input priority value and attribute bits for osThreadJoinable parameter *//* ... */ if ((attr->priority < osPriorityIdle) || (attr->priority > osPriorityISR)) { /* Return NULL pointer in case of error */ return (NULL); }if ((attr->priority < osPriorityIdle) || (attr->priority > osPriorityISR)) { ... } else { /* Set the thread priority */ priority = osPriorityISR - attr->priority; }else { ... } /* Check if the argument is not NULL */ if (argument != NULL) { /* Set the entry_input */ entry_input = (ULONG) argument; }if (argument != NULL) { ... } /* Check if the stack size is equal to 0 */ if (attr->stack_size == 0U) { /* Set stack size to DEFAULT_THREAD_STACK_SIZE */ stack_size = RTOS2_DEFAULT_THREAD_STACK_SIZE; }if (attr->stack_size == 0U) { ... } else if (attr->stack_size < TX_BYTE_POOL_MIN) { /* Set stack size to TX_BYTE_POOL_MIN */ stack_size = TX_BYTE_POOL_MIN; }else if (attr->stack_size < TX_BYTE_POOL_MIN) { ... } else { /* Set stack size to attr->stack_size */ stack_size = (ULONG)attr->stack_size; }else { ... } /* Check if the input stack pointer is NULL */ if (attr->stack_mem == NULL) { /* Allocate the stack for the thread to be created */ stack_start = MemAlloc(stack_size, RTOS2_BYTE_POOL_STACK_TYPE); if (stack_start == NULL) { /* Return NULL pointer in case of error */ return (NULL); }if (stack_start == NULL) { ... } }if (attr->stack_mem == NULL) { ... } else { if (attr->stack_size == 0U) { /* Return NULL pointer in case of error */ return (NULL); }if (attr->stack_size == 0U) { ... } else { /* Set stack size to the input attr->stack_size */ stack_size = (ULONG)attr->stack_size; }else { ... } /* The stack shall point to the input stack memory address */ stack_start = attr->stack_mem; }else { ... } /* Check if the control block size is equal to 0 */ if (attr->cb_size == 0U) { /* Set control block size to sizeof(TX_THREAD) */ cb_size = sizeof(TX_THREAD); }if (attr->cb_size == 0U) { ... } else if (attr->cb_size < sizeof(TX_THREAD)) { /* Return NULL pointer in case of error */ return (NULL); }else if (attr->cb_size < sizeof(TX_THREAD)) { ... } else { /* Set stack size to attr->cb_size */ cb_size = (ULONG)attr->cb_size; }else { ... } /* Check if the input control block pointer is NULL */ if (attr->cb_mem == NULL) { /* Allocate the thread_ptr structure for the thread to be created */ thread_ptr = (TX_THREAD *)MemAlloc(cb_size, RTOS2_BYTE_POOL_HEAP_TYPE); if (thread_ptr == NULL) { /* Check if the memory for thread stack has been internally allocated *//* ... */ if (attr->stack_mem == NULL) { /* Free the already allocated memory for thread stack */ MemFree(stack_start); }if (attr->stack_mem == NULL) { ... } /* Return NULL pointer in case of error */ return (NULL); }if (thread_ptr == NULL) { ... } }if (attr->cb_mem == NULL) { ... } else { /* The control block shall point to the input cb_mem memory address */ thread_ptr = attr->cb_mem; }else { ... } }if (attr != NULL) { ... } else { /* Set the thread priority to default osPriorityNormal*/ priority = osPriorityISR - osPriorityNormal; /* Initialize the name_ptr to NULL */ name_ptr = NULL; /* Initialize the stack_size to RTOS2_DEFAULT_THREAD_STACK_SIZE */ stack_size = RTOS2_DEFAULT_THREAD_STACK_SIZE; /* Check if the argument is not NULL */ if (argument != NULL) { /* Set the entry_input */ entry_input = (ULONG) argument; }if (argument != NULL) { ... } /* Allocate the stack for the thread to be created */ stack_start = MemAlloc(stack_size, RTOS2_BYTE_POOL_STACK_TYPE); if (stack_start == NULL) { /* Return NULL pointer in case of error */ return (NULL); }if (stack_start == NULL) { ... } /* Allocate the thread_ptr structure for the thread to be created */ thread_ptr = (TX_THREAD *)MemAlloc(sizeof(TX_THREAD), RTOS2_BYTE_POOL_HEAP_TYPE); if (thread_ptr == NULL) { /* Free the already allocated memory for thread stack */ MemFree(stack_start); /* Return NULL pointer in case of error */ return (NULL); }if (thread_ptr == NULL) { ... } }else { ... } /* Call the tx_thread_create function to create the new thread. Note: By default the preempt_threshold shall be deactivated by setting its value to the priority or deactivated using TX_DISABLE_PREEMPTION_THRESHOLD *//* ... */ if (tx_thread_create(thread_ptr, name_ptr, (void(*)(ULONG))func, entry_input, stack_start, stack_size, priority, priority, RTOS2_DEFAULT_TIME_SLICE, TX_AUTO_START) != TX_SUCCESS) { /* Check if the memory for thread control block has been internally allocated *//* ... */ if ((attr->cb_mem == NULL) || (attr == NULL)) { /* Free the already allocated memory for thread control block */ MemFree(thread_ptr); }if ((attr->cb_mem == NULL) || (attr == NULL)) { ... } /* Check if the memory for thread stack has been internally allocated */ if ((attr->stack_mem == NULL) || (attr == NULL)) { /* Free the already allocated memory for thread stack */ MemFree(stack_start); }if ((attr->stack_mem == NULL) || (attr == NULL)) { ... } /* Return NULL pointer in case of error */ thread_ptr = NULL; }if (tx_thread_create(thread_ptr, name_ptr, (void(*)(ULONG))func, entry_input, stack_start, stack_size, priority, priority, RTOS2_DEFAULT_TIME_SLICE, TX_AUTO_START) != TX_SUCCESS) { ... } else { /* Check if the thread shall be created joinable */ if ((attr != NULL) && (attr->attr_bits == osThreadJoinable)) { /* Set the thread to Joinable state */ thread_ptr->tx_thread_detached_joinable = osThreadJoinable; }if ((attr != NULL) && (attr->attr_bits == osThreadJoinable)) { ... } else { /* Set the thread to Detached state */ thread_ptr->tx_thread_detached_joinable = osThreadDetached; }else { ... } }else { ... } }if (!IS_IRQ_MODE() && (func != NULL)) { ... } return ((osThreadId_t)thread_ptr); }{ ... } /** * @brief The function osThreadGetName returns the pointer to the name_ptr * string of the thread identified by parameter thread_id or NULL in * case of an error. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] thread_id thread ID obtained by osThreadNew or osThreadGetId * @retval name_ptr as null-terminated string. *//* ... */ const char *osThreadGetName(osThreadId_t thread_id) { /* For ThreadX the control block pointer is the thread identifier */ TX_THREAD *thread_ptr = (TX_THREAD *)thread_id; /* The output name_ptr as null-terminated string */ CHAR *name_ptr = NULL; /* Check if this API is called from Interrupt Service Routines, the thread_id is NULL or thread_id->tx_thread_id != TX_THREAD_ID *//* ... */ if (IS_IRQ_MODE() || (thread_ptr == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID)) { /* Return NULL in case of an error */ name_ptr = NULL; }if (IS_IRQ_MODE() || (thread_ptr == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID)) { ... } else { /* Call the tx_thread_info_get to get the thread name_ptr */ if (tx_thread_info_get(thread_ptr, &name_ptr, NULL, NULL, NULL, NULL, NULL, NULL, NULL) != TX_SUCCESS) { /* Return NULL in case of an error */ name_ptr = NULL; }if (tx_thread_info_get(thread_ptr, &name_ptr, NULL, NULL, NULL, NULL, NULL, NULL, NULL) != TX_SUCCESS) { ... } }else { ... } return (name_ptr); }{ ... } /** * @brief The function osThreadGetId returns the thread object ID of the * currently running thread or NULL in case of an error. * Note : This function may be called from Interrupt Service Routines. * @param none * @retval thread ID for reference by other functions or NULL in case of error. *//* ... */ osThreadId_t osThreadGetId(void) { /* For ThreadX the control block pointer is the thread identifier */ osThreadId_t thread_id; /* Call the tx_thread_identify to get the control block pointer of the currently executing thread. *//* ... */ thread_id = (osThreadId_t)tx_thread_identify(); return (thread_id); }{ ... } /** * @brief The function osThreadGetState returns the state of the thread * identified by parameter thread_id. In case it fails or if it is * called from an ISR, it will return osThreadError, otherwise it * returns the thread state (refer to osThreadState_t for the list of * thread states). * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] thread_id thread ID obtained by osThreadNew or osThreadGetId * @retval state current thread state of the specified thread. *//* ... */ osThreadState_t osThreadGetState(osThreadId_t thread_id) { /* For ThreadX the control block pointer is the thread identifier */ TX_THREAD *thread_ptr = (TX_THREAD *)thread_id; /* The control block pointer of the current running thread */ TX_THREAD *current_thread = NULL; /* The current thread state of the specified thread. */ osThreadState_t state; /* The current thread state of the specified thread as specified by threadx */ UINT threadx_state; /* Check if this API is called from Interrupt Service Routines, the thread_id is NULL or thread_id->tx_thread_id != TX_THREAD_ID *//* ... */ if (IS_IRQ_MODE() || (thread_ptr == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID)) /* Return osThreadError in case of an error */ { state = osThreadError; ...} else { /* Get the current running thread */ TX_THREAD_GET_CURRENT(current_thread); if (current_thread == thread_id) { /* The state is running */ state = osThreadRunning; }if (current_thread == thread_id) { ... } else { /* Call the tx_thread_info_get to get the thread threadx_state */ if (tx_thread_info_get(thread_ptr, NULL, &threadx_state, NULL, NULL, NULL, NULL, NULL, NULL) != TX_SUCCESS) { /* Return osThreadError in case of an error */ state = osThreadError; }if (tx_thread_info_get(thread_ptr, NULL, &threadx_state, NULL, NULL, NULL, NULL, NULL, NULL) != TX_SUCCESS) { ... } else { /* Link the ThreadX thread states to CMSIS RTOS2 states */ switch (threadx_state) { /* The thread is in READY state */ case TX_READY: { state = osThreadReady; break; ...} /* The thread is in COMPLETED state */case TX_READY: case TX_COMPLETED: { state = osThreadTerminated; break; ...} /* The thread is in TERMINATED state */case TX_COMPLETED: case TX_TERMINATED: { state = osThreadTerminated; break; ...} /* The thread is in SUSPENDED state */case TX_TERMINATED: case TX_SUSPENDED: case TX_QUEUE_SUSP: case TX_SEMAPHORE_SUSP: case TX_EVENT_FLAG: case TX_BLOCK_MEMORY: case TX_BYTE_MEMORY: case TX_IO_DRIVER: case TX_FILE: case TX_TCP_IP: case TX_MUTEX_SUSP: case TX_PRIORITY_CHANGE: { state = osThreadBlocked; break; ...} /* The thread is in SLEEP state */case TX_PRIORITY_CHANGE: case TX_SLEEP: { state = osThreadBlocked; break; ...} /* The thread is in unknown state */case TX_SLEEP: default: { state = osThreadError; break; ...}default }switch (threadx_state) { ... } }else { ... } }else { ... } }else { ... } return (state); }{ ... } /** * @brief The function osThreadGetStackSize returns the stack size of the * thread specified by parameter thread_id. In case of an error, it * returns 0. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] thread_id thread ID obtained by osThreadNew or osThreadGetId. * @retval remaining_stack_space remaining stack space in bytes. *//* ... */ uint32_t osThreadGetStackSize(osThreadId_t thread_id) { /* For ThreadX the control block pointer is the thread identifier */ TX_THREAD *thread_ptr = (TX_THREAD *)thread_id; /* The specific thread stack size in bytes */ unsigned int stack_size; /* Check if this API is called from Interrupt Service Routines, the thread_id is NULL or thread_id->tx_thread_id != TX_THREAD_ID *//* ... */ if (IS_IRQ_MODE() || (thread_ptr == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID)) { /* Return 0 in case of error */ stack_size = 0U; }if (IS_IRQ_MODE() || (thread_ptr == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID)) { ... } else { /* The stack_size get the allocated thread stack size in the thread creation step */ stack_size = thread_ptr->tx_thread_stack_size; }else { ... } return (stack_size); }{ ... } /** * @brief The function osThreadGetStackSpace returns the size of unused stack * space for the thread specified by parameter thread_id. Stack * watermark recording during execution needs to be enabled (refer to * Thread Configuration). In case of an error, it returns 0. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] thread_id thread ID obtained by osThreadNew or osThreadGetId. * @retval remaining_stack_space remaining stack space in bytes. *//* ... */ uint32_t osThreadGetStackSpace(osThreadId_t thread_id) { /* For ThreadX the control block pointer is the thread identifier */ TX_THREAD *thread_ptr = (TX_THREAD *)thread_id; /* Remaining stack space in bytes */ uint32_t remaining_stack_space; /* Check if this API is called from Interrupt Service Routines, the thread_id is NULL or thread_id->tx_thread_id != TX_THREAD_ID *//* ... */ if (IS_IRQ_MODE() || (thread_ptr == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID)) { /* Return 0 in case of error */ remaining_stack_space = 0U; }if (IS_IRQ_MODE() || (thread_ptr == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID)) { ... } else { /* Compute the remaining free stack size for the given thread */ remaining_stack_space = (unsigned int)((CHAR *)thread_ptr->tx_thread_stack_ptr - (CHAR *)thread_ptr->tx_thread_stack_start); }else { ... } return (remaining_stack_space); }{ ... } /** * @brief The function osThreadSetPriority changes the priority of an active * thread specified by the parameter thread_id to the priority * specified by the parameter priority. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] thread_id thread ID obtained by osThreadNew or osThreadGetId. * [in] priority new priority value for the thread function. * @retval status code that indicates the execution status of the function. *//* ... */ osStatus_t osThreadSetPriority(osThreadId_t thread_id, osPriority_t priority) { /* For ThreadX the control block pointer is the thread identifier */ TX_THREAD *thread_ptr = (TX_THREAD *)thread_id; /* Old priority */ UINT old_priority; /* The returned status or error */ osStatus_t status; /* Check if this API is called from Interrupt Service Routines */ if (IS_IRQ_MODE()) { /* Return osErrorISR error */ status = osErrorISR; }if (IS_IRQ_MODE()) { ... } /* Check if thread_ptr is NULL or thread_id->tx_thread_id != TX_THREAD_ID or the input priority is out of range *//* ... */ else if ((thread_ptr == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID) || (priority < osPriorityIdle) || (priority > osPriorityISR)) { /* Return osErrorParameter error */ status = osErrorParameter; }else if ((thread_ptr == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID) || (priority < osPriorityIdle) || (priority > osPriorityISR)) { ... } else { /* Convert input CMSIS osPriority_t to threadX priority */ priority = (osPriority_t)(osPriorityISR - priority); /* Call the tx_thread_priority_change to change the thread priority */ if (tx_thread_priority_change(thread_ptr, priority, &old_priority) == TX_SUCCESS) { /* Return osOK in case of success */ status = osOK; }if (tx_thread_priority_change(thread_ptr, priority, &old_priority) == TX_SUCCESS) { ... } else { /* Return osErrorResource in case of error */ status = osErrorResource; }else { ... } }else { ... } return (status); }{ ... } /** * @brief The function osThreadGetPriority returns the priority of an active * thread specified by the parameter thread_id. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] thread_id thread ID obtained by osThreadNew or osThreadGetId. * @retval priority current priority value of the specified thread. *//* ... */ osPriority_t osThreadGetPriority(osThreadId_t thread_id) { /* For ThreadX the control block pointer is the thread identifier */ TX_THREAD *thread_ptr = (TX_THREAD *)thread_id; /* The returned thread priority or error */ osPriority_t priority; /* Check if this API is called from Interrupt Service Routines or the thread_id is NULL *//* ... */ if (IS_IRQ_MODE() || (thread_ptr == NULL)) { /* Return osPriorityError in case of an error */ priority = osPriorityError; }if (IS_IRQ_MODE() || (thread_ptr == NULL)) { ... } else { /* Call the tx_thread_info_get to get the thread priority */ if (tx_thread_info_get(thread_ptr, NULL, NULL, NULL, (UINT *)&priority, NULL, NULL, NULL, NULL) != TX_SUCCESS) { /* Return osPriorityError in case of an error */ priority = osPriorityError; }if (tx_thread_info_get(thread_ptr, NULL, NULL, NULL, (UINT *)&priority, NULL, NULL, NULL, NULL) != TX_SUCCESS) { ... } else { /* Convert the threadX priority to CMSIS osPriority_t */ priority = (osPriority_t)(osPriorityISR - priority); }else { ... } }else { ... } return (priority); }{ ... } /** * @brief The function osThreadYield passes control to the next thread with * the same priority that is in the READY state. If there is no other * thread with the same priority in state READY, then the current * thread continues execution and no thread switch occurs. * osThreadYield does not set the thread to state BLOCKED. Thus no * thread with a lower priority will be scheduled even if threads in * state READY are available. * Note : This function cannot be called from Interrupt Service * Routines. * @param none. * @retval status code that indicates the execution status of the function. *//* ... */ osStatus_t osThreadYield(void) { /* The returned status or error */ osStatus_t status; /* Check if this API is called from Interrupt Service Routines */ if (IS_IRQ_MODE()) { /* Return osErrorISR error */ status = osErrorISR; }if (IS_IRQ_MODE()) { ... } else { /* Call the tx_thread_relinquish to relinquishes processor control to other ready-to-run threads at the same or higher priority. *//* ... */ tx_thread_relinquish(); /* Return osOK for success */ status = osOK; }else { ... } return (status); }{ ... } /** * @brief The function osThreadSuspend suspends the execution of the thread * identified by parameter thread_id. The thread is put into the * BLOCKED state (osThreadBlocked). Suspending the running thread will * cause a context switch to another thread in READY state immediately. * The suspended thread is not executed until explicitly resumed with * the function osThreadResume. * Threads that are already BLOCKED are removed from any wait list and * become ready when they are resumed. Thus it is not recommended to * suspend an already blocked thread. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] thread_id thread ID obtained by osThreadNew or osThreadGetId. * @retval status code that indicates the execution status of the function. *//* ... */ osStatus_t osThreadSuspend(osThreadId_t thread_id) { /* For ThreadX the control block pointer is the thread identifier */ TX_THREAD *thread_ptr = (TX_THREAD *)thread_id; /* The returned status or error */ osStatus_t status; /* Check if this API is called from Interrupt Service Routines */ if (IS_IRQ_MODE()) { /* Return osErrorISR error */ status = osErrorISR; }if (IS_IRQ_MODE()) { ... } /* Check if the thread ID is NULL or (tx_thread_id != TX_THREAD_ID) */ else if ((thread_id == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID)) { /* Return osErrorParameter error */ status = osErrorParameter; }else if ((thread_id == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID)) { ... } else { /* Call the tx_thread_suspend to suspends the specified application thread. A thread may call this service to suspend itself. *//* ... */ if (tx_thread_suspend(thread_ptr) == TX_SUCCESS) { /* Return osOK for success */ status = osOK; }if (tx_thread_suspend(thread_ptr) == TX_SUCCESS) { ... } else { /* Return osErrorResource in case of error */ status = osErrorResource; }else { ... } }else { ... } return (status); }{ ... } /** * @brief The function osThreadResume puts the thread identified by parameter * thread_id (which has to be in BLOCKED state) back to the READY * state. If the resumed thread has a higher priority than the running * thread a context switch occurs immediately. * The thread becomes ready regardless of the reason why the thread was * blocked. Thus it is not recommended to resume a thread not suspended * by osThreadSuspend. * Functions that will put a thread into BLOCKED state are: * osEventFlagsWait and osThreadFlagsWait, osDelay and osDelayUntil, * osMutexAcquire and osSemaphoreAcquire, osMessageQueueGet, * osMemoryPoolAlloc, osThreadJoin, osThreadSuspend.. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] thread_id thread ID obtained by osThreadNew or osThreadGetId. * @retval status code that indicates the execution status of the function. *//* ... */ osStatus_t osThreadResume(osThreadId_t thread_id) { /* For ThreadX the control block pointer is the thread identifier */ TX_THREAD *thread_ptr = (TX_THREAD *)thread_id; /* The returned status or error */ osStatus_t status; /* Check if this API is called from Interrupt Service Routines */ if (IS_IRQ_MODE()) { /* Return osErrorISR error */ status = osErrorISR; }if (IS_IRQ_MODE()) { ... } /* Check if the thread ID is NULL or (tx_thread_id != TX_THREAD_ID) */ else if ((thread_id == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID)) { /* Return osErrorParameter error */ status = osErrorParameter; }else if ((thread_id == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID)) { ... } else { /* Call the tx_thread_resume to resumes or prepares for execution a thread that was previously suspended by a tx_thread_suspend call. In addition, this service resumes threads that were created without an automatic start. *//* ... */ if (tx_thread_resume(thread_ptr) == TX_SUCCESS) { /* Return osOK for success */ status = osOK; }if (tx_thread_resume(thread_ptr) == TX_SUCCESS) { ... } else { /* Return osErrorResource in case of error */ status = osErrorResource; }else { ... } }else { ... } return (status); }{ ... } /** * @brief The function osThreadExit terminates the calling thread. This allows * the thread to be synchronized with osThreadJoin. * Note : This function cannot be called from Interrupt Service * Routines. * @param none. * @retval none. *//* ... */ __NO_RETURN void osThreadExit(void) { /* For ThreadX the control block pointer is the thread identifier */ TX_THREAD *thread_ptr = NULL; /* Check if this API is called from Interrupt Service Routines */ if (!IS_IRQ_MODE()) { /* Call the tx_thread_identify to get the control block pointer of the currently executing thread. *//* ... */ thread_ptr = tx_thread_identify(); /* Check if the current running thread pointer is not NULL */ if (thread_ptr != NULL) { /* Call the tx_thread_terminate to terminates the specified application thread regardless of whether the thread is suspended or not. A thread may call this service to terminate itself. *//* ... */ tx_thread_terminate(thread_ptr); }if (thread_ptr != NULL) { ... } }if (!IS_IRQ_MODE()) { ... } /* Infinite loop */ for (;;); }{ ... } /** * @brief The function osThreadTerminate removes the thread specified by * parameter thread_id from the list of active threads. If the * thread is currently RUNNING, the thread terminates and the * execution continues with the next READY thread. If no such thread * exists, the function will not terminate the running thread, but * return osErrorResource. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] thread_id thread ID obtained by osThreadNew or osThreadGetId. * @retval status code that indicates the execution status of the function. *//* ... */ osStatus_t osThreadTerminate(osThreadId_t thread_id) { /* For ThreadX the control block pointer is the thread identifier */ TX_THREAD *thread_ptr = (TX_THREAD *)thread_id; /* The returned status or error */ osStatus_t status; /* Check if this API is called from Interrupt Service Routines */ if (IS_IRQ_MODE()) { /* Return osErrorISR error */ status = osErrorISR; }if (IS_IRQ_MODE()) { ... } /* Check if the thread ID is NULL or (tx_thread_id != TX_THREAD_ID) */ else if ((thread_id == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID)) { /* Return osErrorParameter error */ status = osErrorParameter; }else if ((thread_id == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID)) { ... } else { /* Call the tx_thread_terminate to terminates the specified application thread regardless of whether the thread is suspended or not. A thread may call this service to terminate itself. *//* ... */ if (tx_thread_terminate(thread_ptr) == TX_SUCCESS) { /* Free the thread resources if it is Detached */ if (thread_ptr->tx_thread_detached_joinable == osThreadDetached) { /* Delete the thread */ tx_thread_delete(thread_ptr); /* Free the already allocated memory for thread stack */ MemFree(thread_ptr->tx_thread_stack_start); /* Free the already allocated memory for thread control block */ MemFree(thread_ptr); }if (thread_ptr->tx_thread_detached_joinable == osThreadDetached) { ... } /* Return osOK for success */ status = osOK; }if (tx_thread_terminate(thread_ptr) == TX_SUCCESS) { ... } else { /* Return osErrorResource in case of error */ status = osErrorResource; }else { ... } }else { ... } return (status); }{ ... } /** * @brief The function osThreadDetach changes the attribute of a thread * (specified by thread_id) to osThreadDetached. Detached threads are * not joinable with osThreadJoin. When a detached thread is * terminated, all resources are returned to the system. The behavior * of osThreadDetach on an already detached thread is undefined. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] thread_id thread ID obtained by osThreadNew or osThreadGetId. * @retval status code that indicates the execution status of the function. *//* ... */ osStatus_t osThreadDetach(osThreadId_t thread_id) { /* For ThreadX the control block pointer is the thread identifier */ TX_THREAD *thread_ptr = (TX_THREAD *)thread_id; /* The returned status or error */ osStatus_t status; /* Check if this API is called from Interrupt Service Routines */ if (IS_IRQ_MODE()) { /* Return osErrorISR error */ status = osErrorISR; }if (IS_IRQ_MODE()) { ... } /* Check if the thread ID is NULL or (tx_thread_id != TX_THREAD_ID) */ else if ((thread_id == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID)) { /* Return osErrorParameter error */ status = osErrorParameter; }else if ((thread_id == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID)) { ... } else { /* Change the status of the specific thread to Detached */ thread_ptr->tx_thread_detached_joinable = osThreadDetached; /* Return osOK for success */ status = osOK; }else { ... } return (status); }{ ... } /** * @brief The function osThreadJoin waits for the thread specified by * thread_id to terminate. If that thread has already terminated, then * osThreadJoin returns immediately. The thread must be joinable. * By default threads are created with the attribute osThreadDetached. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] thread_id thread ID obtained by osThreadNew or osThreadGetId. * @retval status code that indicates the execution status of the function. *//* ... */ osStatus_t osThreadJoin(osThreadId_t thread_id) { /* For ThreadX the control block pointer is the thread identifier */ TX_THREAD *thread_ptr = (TX_THREAD *)thread_id; /* The control block pointer of the current running thread */ TX_THREAD *current_thread = NULL; /* The current thread state of the specified thread as specified by threadx */ UINT threadx_state; /* The returned status or error */ osStatus_t status; /* Check if this API is called from Interrupt Service Routines */ if (IS_IRQ_MODE()) { /* Return osErrorISR error */ status = osErrorISR; }if (IS_IRQ_MODE()) { ... } /* Check if the thread ID is NULL or (tx_thread_id != TX_THREAD_ID) */ else if ((thread_id == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID)) { /* Return osErrorParameter error */ status = osErrorParameter; }else if ((thread_id == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID)) { ... } else { /* Get the current running thread */ TX_THREAD_GET_CURRENT(current_thread); if (current_thread == thread_id) { /* Return osErrorParameter error */ status = osErrorParameter; }if (current_thread == thread_id) { ... } else { /* Call the tx_thread_info_get to get the thread threadx_state */ if (tx_thread_info_get(thread_ptr, NULL, &threadx_state, NULL, NULL, NULL, NULL, NULL, NULL) == TX_SUCCESS) { /* Check if the thread is joinable */ if (thread_ptr->tx_thread_detached_joinable == osThreadJoinable) { /* Only one thread can Join a thread in the same time so we will detach it momentally until it will be terminated *//* ... */ thread_ptr->tx_thread_detached_joinable = osThreadDetached; /* Wait until the state of the specific thread turn to terminated */ while ((threadx_state != TX_TERMINATED) && (threadx_state != TX_COMPLETED)) { /* Call the tx_thread_info_get to get the thread threadx_state */ tx_thread_info_get(thread_ptr, NULL, &threadx_state, NULL, NULL, NULL, NULL, NULL, NULL); }while ((threadx_state != TX_TERMINATED) && (threadx_state != TX_COMPLETED)) { ... } /* Once the thread is terminated it can be again Joinable */ thread_ptr->tx_thread_detached_joinable = osThreadJoinable; /* Return osOK for success */ status = osOK; }if (thread_ptr->tx_thread_detached_joinable == osThreadJoinable) { ... } else { /* Return osErrorResource error */ status = osErrorResource; }else { ... } }if (tx_thread_info_get(thread_ptr, NULL, &threadx_state, NULL, NULL, NULL, NULL, NULL, NULL) == TX_SUCCESS) { ... } else { /* Return osErrorResource error */ status = osErrorResource; }else { ... } }else { ... } }else { ... } return (status); }{ ... } /** * @brief The function osThreadGetCount returns the number of active threads * or 0 in case of an error. * Note : This function cannot be called from Interrupt Service * Routines. * @param none. * @retval count number of active threads. *//* ... */ uint32_t osThreadGetCount(void) { /* For ThreadX the control block pointer is the thread identifier */ TX_THREAD *thread_ptr = NULL; /* Returned number of active threads */ unsigned int count = 0U; /* Check if this API is called from Interrupt Service Routines */ if (IS_IRQ_MODE()) { /* Return 0 in case of error */ count = 0; }if (IS_IRQ_MODE()) { ... } else { /* thread_ptr = the head pointer of the created thread list */ thread_ptr = _tx_thread_created_ptr; /* Compute the number of active threads */ while (thread_ptr != NULL) { /* Check the next thread validity */ if (thread_ptr->tx_thread_id == TX_THREAD_ID) { /* Increment the number of active threads */ count++; /* Check the state of next created thread */ if ((thread_ptr->tx_thread_created_next != thread_ptr) && (thread_ptr->tx_thread_created_next != _tx_thread_created_ptr)) { thread_ptr = thread_ptr->tx_thread_created_next; }if ((thread_ptr->tx_thread_created_next != thread_ptr) && (thread_ptr->tx_thread_created_next != _tx_thread_created_ptr)) { ... } else { break; }else { ... } }if (thread_ptr->tx_thread_id == TX_THREAD_ID) { ... } else { /* Return 0 in case of error */ count = 0; break; }else { ... } }while (thread_ptr != NULL) { ... } }else { ... } return (count); }{ ... } /** * @brief The function osThreadEnumerate returns the number of enumerated * threads or 0 in case of an error. * Note : This function cannot be called from Interrupt Service * Routines. * @param [out] thread_array pointer to array for retrieving thread IDs. * [in] array_items maximum number of items in array for retrieving * thread IDs. * @retval count number of enumerated threads. *//* ... */ uint32_t osThreadEnumerate(osThreadId_t *thread_array, uint32_t array_items) { /* For ThreadX the control block pointer is the thread identifier */ TX_THREAD *thread_ptr = NULL; /* The number of enumerated threads */ uint32_t count = 0U; /* Check if this API is called from Interrupt Service Routines or if the thread_array is NULL or the array_items is equal to 0 *//* ... */ if (IS_IRQ_MODE() || (thread_array == NULL) || (array_items == 0U)) { /* Return 0 in case of error */ count = 0U; }if (IS_IRQ_MODE() || (thread_array == NULL) || (array_items == 0U)) { ... } else { /* thread_ptr point to the head pointer of the created thread list */ thread_ptr = _tx_thread_created_ptr; /* Compute the number of active threads */ while ((thread_ptr != NULL) && (count < array_items)) { /* Check the next thread validity */ if (thread_ptr->tx_thread_id == TX_THREAD_ID) { /* Retrieve the thread IDs and increment the number of active threads *//* ... */ thread_array[count++] = thread_ptr; /* Check the state of next created thread */ if ((thread_ptr->tx_thread_created_next != thread_ptr) && (thread_ptr->tx_thread_created_next != _tx_thread_created_ptr)) { thread_ptr = thread_ptr->tx_thread_created_next; }if ((thread_ptr->tx_thread_created_next != thread_ptr) && (thread_ptr->tx_thread_created_next != _tx_thread_created_ptr)) { ... } else { break; }else { ... } }if (thread_ptr->tx_thread_id == TX_THREAD_ID) { ... } else { /* Return 0 in case of error */ count = 0; break; }else { ... } }while ((thread_ptr != NULL) && (count < array_items)) { ... } }else { ... } return (count); }{ ... } /*---------------------------------------------------------------------------*/--------------------------Thread Management APIs /*---------------------------Timer Management APIs---------------------------*/ /*---------------------------------------------------------------------------*/ /** * @brief The function osTimerNew creates an one-shot or periodic timer and * associates it with a callback function with argument. The timer is * in stopped state until it is started with osTimerStart. * The function can be safely called before the RTOS is started (call * to osKernelStart), but not before it is initialized (call to * osKernelInitialize). * The function osTimerNew returns the pointer to the timer object * identifier or NULL in case of an error. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] func function pointer to callback function. * [in] type osTimerOnce for one-shot or osTimerPeriodic for periodic * behavior. * [in] argument argument to the timer callback function. * [in] attr timer attributes; NULL: default values. * @retval timer ID for reference by other functions or NULL in case of error. *//* ... */ osTimerId_t osTimerNew(osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr) { /* For TX_TIMER the control block pointer is the timer identifier */ TX_TIMER *timer_ptr = NULL; /* The name_ptr as null-terminated string */ CHAR *name_ptr = NULL; /* The timer expiration input */ ULONG expiration_input = 0U; /* The timer reschedule ticks */ ULONG reschedule_ticks = 0U; /* The size of control block */ ULONG cb_size = sizeof(TX_TIMER); /* Check if this API is called from Interrupt Service Routines, the timer callback function handler is NULL or the type is not valid *//* ... */ if (!IS_IRQ_MODE() && (func != NULL) && (type <= osTimerPeriodic)) { /* Initialize the name_ptr to NULL */ name_ptr = NULL; /* Check if the attr is not NULL */ if (attr != NULL) { /* Check if the name_ptr is not NULL */ if (attr->name != NULL) { /* Set the timer name_ptr */ name_ptr = (CHAR *)attr->name; }if (attr->name != NULL) { ... } /* Check if the control block size is equal to 0 */ if (attr->cb_size == 0U) { /* Set control block size to sizeof(TX_TIMER) */ cb_size = sizeof(TX_TIMER); }if (attr->cb_size == 0U) { ... } else if (attr->cb_size < sizeof(TX_TIMER)) { /* Return NULL pointer in case of error */ return (NULL); }else if (attr->cb_size < sizeof(TX_TIMER)) { ... } else { /* Set control block size to attr->cb_size */ cb_size = (ULONG) attr->cb_size; }else { ... } /* Check if the input control block pointer is NULL */ if (attr->cb_mem == NULL) { /* Allocate the timer_ptr structure for the timer to be created */ timer_ptr = (TX_TIMER *)MemAlloc(cb_size, RTOS2_BYTE_POOL_HEAP_TYPE); if (timer_ptr == NULL) { /* Return NULL pointer in case of error */ return (NULL); }if (timer_ptr == NULL) { ... } }if (attr->cb_mem == NULL) { ... } else { /* The control block shall point to the input cb_mem memory address */ timer_ptr = attr->cb_mem; }else { ... } }if (attr != NULL) { ... } else { /* Allocate the timer_ptr structure for the timer to be created */ timer_ptr = (TX_TIMER *)MemAlloc(cb_size, RTOS2_BYTE_POOL_HEAP_TYPE); }else { ... } /* Check the timer type to set timer periodicity */ if (type == osTimerPeriodic) { /* Specifies the number of ticks for all timer expirations after the first. A zero for this parameter makes the timer a one-shot timer. Otherwise, for periodic timers, legal values range from 1 through 0xFFFFFFFF. For periodic timer the reschedule_ticks is initiated to 1 then set to ticks given as input in osTimerStart APIs *//* ... */ reschedule_ticks = 1; }if (type == osTimerPeriodic) { ... } /* Check if the argument is not NULL */ if (argument != NULL) { /* Set the expiration_input */ expiration_input = (ULONG)argument; }if (argument != NULL) { ... } /* Call the tx_timer_create function to create the new timer */ if (tx_timer_create(timer_ptr, name_ptr, (void(*)(ULONG))func, expiration_input, 1, reschedule_ticks, TX_NO_ACTIVATE) != TX_SUCCESS) { /* Check if the memory for timer control block has been internally allocated *//* ... */ if ((attr->cb_mem == NULL) || (attr == NULL)) { /* Free the already allocated memory for timer control block */ MemFree(timer_ptr); }if ((attr->cb_mem == NULL) || (attr == NULL)) { ... } /* Return NULL pointer in case of error */ timer_ptr = NULL; }if (tx_timer_create(timer_ptr, name_ptr, (void(*)(ULONG))func, expiration_input, 1, reschedule_ticks, TX_NO_ACTIVATE) != TX_SUCCESS) { ... } }if (!IS_IRQ_MODE() && (func != NULL) && (type <= osTimerPeriodic)) { ... } return ((osThreadId_t)timer_ptr); }{ ... } /** * @brief The function osTimerGetName returns the pointer to the name string * of the timer identified by parameter timer_id or NULL in case of an * error. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] timer_id timer ID obtained by osTimerNew. * @retval name as null-terminated string. *//* ... */ const char *osTimerGetName(osTimerId_t timer_id) { /* For TX_TIMER the control block pointer is the timer identifier */ TX_TIMER *timer_ptr = (TX_TIMER *)timer_id; /* The output name_ptr as null-terminated string */ CHAR *name_ptr; /* Check if this API is called from Interrupt Service Routines or the timer_id is NULL *//* ... */ if (IS_IRQ_MODE() || (timer_ptr == NULL)) { /* Return NULL in case of an error */ name_ptr = NULL; }if (IS_IRQ_MODE() || (timer_ptr == NULL)) { ... } else { /* Call the tx_timer_info_get to get the timer name_ptr */ if (tx_timer_info_get(timer_ptr, &name_ptr, NULL, NULL, NULL, NULL) != TX_SUCCESS) { /* Return NULL in case of an error */ name_ptr = NULL; }if (tx_timer_info_get(timer_ptr, &name_ptr, NULL, NULL, NULL, NULL) != TX_SUCCESS) { ... } }else { ... } return ((const char *)name_ptr); }{ ... } /** * @brief The function osTimerIsRunning checks whether a timer specified by * parameter timer_id is running. It returns 1 if the timer is running * and 0 if the timer is stopped or an error occurred. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] timer_id timer ID obtained by osTimerNew. * @retval 0 not running, 1 running. *//* ... */ uint32_t osTimerIsRunning(osTimerId_t timer_id) { /* For TX_TIMER the control block pointer is the timer identifier */ TX_TIMER *timer_ptr = (TX_TIMER *)timer_id; /* The active state of the timer */ UINT active; /* Check if this API is called from Interrupt Service Routines or the input timer_id in NULL *//* ... */ if (IS_IRQ_MODE() || (timer_id == NULL)) { /* Return 0 in case of error */ active = 0U; }if (IS_IRQ_MODE() || (timer_id == NULL)) { ... } else { /* Check if the timer is valid by calling the tx_timer_info_get to get the timer active state *//* ... */ if (tx_timer_info_get(timer_ptr, NULL, &active, NULL, NULL, NULL) != TX_SUCCESS) { /* Return 0 in case of error */ active = 0U; }if (tx_timer_info_get(timer_ptr, NULL, &active, NULL, NULL, NULL) != TX_SUCCESS) { ... } }else { ... } return ((uint32_t)active); }{ ... } /** * @brief The function osTimerStop stops a timer specified by the parameter * timer_id. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] timer_id timer ID obtained by osTimerNew. * @retval status code that indicates the execution status of the function. *//* ... */ osStatus_t osTimerStop(osTimerId_t timer_id) { /* For TX_TIMER the control block pointer is the timer identifier */ TX_TIMER *timer_ptr = (TX_TIMER *)timer_id; /* The returned status or error */ osStatus_t status; /* The active state of the timer */ UINT active; /* Check if this API is called from Interrupt Service Routines */ if (IS_IRQ_MODE()) { /* Return osErrorISR error */ status = osErrorISR; }if (IS_IRQ_MODE()) { ... } /* Check if the timer control block is valid */ else if ((timer_id == NULL) || (timer_ptr->tx_timer_id != TX_TIMER_ID)) { /* Return osErrorParameter error */ status = osErrorParameter; }else if ((timer_id == NULL) || (timer_ptr->tx_timer_id != TX_TIMER_ID)) { ... } else { /* Get the timer running state */ if (tx_timer_info_get(timer_ptr, NULL, &active, NULL, NULL, NULL) == TX_SUCCESS) { /* Check if the timer is running (active) */ if (active == TX_TRUE) { /* Call the tx_timer_deactivate to deactivates the specified application timer. If the timer is already deactivated, this service has no effect. *//* ... */ if (tx_timer_deactivate(timer_ptr) == TX_SUCCESS) { /* Return osOK for success */ status = osOK; }if (tx_timer_deactivate(timer_ptr) == TX_SUCCESS) { ... } else { /* Return osErrorResource in case of error */ status = osErrorResource; }else { ... } }if (active == TX_TRUE) { ... } else { /* Return osErrorResource in case of error */ status = osErrorResource; }else { ... } }if (tx_timer_info_get(timer_ptr, NULL, &active, NULL, NULL, NULL) == TX_SUCCESS) { ... } else { /* Return osErrorResource error */ status = osErrorResource; }else { ... } }else { ... } return (status); }{ ... } /** * @brief The function osTimerStart starts or restarts a timer specified by * the parameter timer_id. The parameter ticks specifies the value of * the timer in time ticks. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] timer_id timer ID obtained by osTimerNew. * [in] ticks time ticks value of the timer. * @retval status code that indicates the execution status of the function. *//* ... */ osStatus_t osTimerStart(osTimerId_t timer_id, uint32_t ticks) { /* For TX_TIMER the control block pointer is the timer identifier */ TX_TIMER *timer_ptr = (TX_TIMER *)timer_id; /* The returned status or error */ osStatus_t status = osOK; /* The active state of the timer */ UINT active; /* The reschedule ticks of the timer */ ULONG reschedule_ticks; /* Check if this API is called from Interrupt Service Routines */ if (IS_IRQ_MODE()) { /* Return osErrorISR error */ status = osErrorISR; }if (IS_IRQ_MODE()) { ... } /* Check if the timer control block is valid */ else if ((timer_id == NULL) || (timer_ptr->tx_timer_id != TX_TIMER_ID)) { /* Return osErrorParameter error */ status = osErrorParameter; }else if ((timer_id == NULL) || (timer_ptr->tx_timer_id != TX_TIMER_ID)) { ... } else { /* Get the timer running state and reschedule ticks parameters */ if (tx_timer_info_get(timer_ptr, NULL, &active, NULL, &reschedule_ticks, NULL) == TX_SUCCESS) { /* Check if the timer is active. If so, it shall be stopped before being activated again *//* ... */ if (active == TX_TRUE) { /* Call the tx_timer_deactivate to deactivates the specified application timer. If the timer is already deactivated, this service has no effect. *//* ... */ if (tx_timer_deactivate(timer_ptr) == TX_SUCCESS) { /* Set status osOK for success */ status = osOK; }if (tx_timer_deactivate(timer_ptr) == TX_SUCCESS) { ... } else { /* Return osErrorResource in case of error */ status = osErrorResource; }else { ... } }if (active == TX_TRUE) { ... } if (status == osOK) { /* Check the timer reschedule_ticks parameter for periodicity */ if (reschedule_ticks > 0) { /* Set the reschedule_ticks to the input ticks */ reschedule_ticks = ticks; }if (reschedule_ticks > 0) { ... } /* An expired one-shot timer must be reset via tx_timer_change before it can be activated again. *//* ... */ if (tx_timer_change(timer_ptr, ticks, reschedule_ticks) == TX_SUCCESS) { /* Call the tx_timer_activate to activates the specified application timer. The expiration routines of timers that expire at the same time are executed in the order they were activated. *//* ... */ if (tx_timer_activate(timer_ptr) == TX_SUCCESS) { /* Return osOK for success */ status = osOK; }if (tx_timer_activate(timer_ptr) == TX_SUCCESS) { ... } else { /* Return osErrorResource in case of error */ status = osErrorResource; }else { ... } }if (tx_timer_change(timer_ptr, ticks, reschedule_ticks) == TX_SUCCESS) { ... } else { /* Return osErrorResource in case of error */ status = osErrorResource; }else { ... } }if (status == osOK) { ... } }if (tx_timer_info_get(timer_ptr, NULL, &active, NULL, &reschedule_ticks, NULL) == TX_SUCCESS) { ... } else { /* Return osErrorResource error */ status = osErrorResource; }else { ... } }else { ... } return (status); }{ ... } /** * @brief The function osTimerDelete deletes the timer specified by parameter * timer_id. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] timer_id timer ID obtained by osTimerNew. * @retval status code that indicates the execution status of the function. *//* ... */ osStatus_t osTimerDelete(osTimerId_t timer_id) { /* For TX_TIMER the control block pointer is the timer identifier */ TX_TIMER *timer_ptr = (TX_TIMER *)timer_id; /* The returned status or error */ osStatus_t status; /* Check if this API is called from Interrupt Service Routines */ if (IS_IRQ_MODE()) { /* Return osErrorISR error */ status = osErrorISR; }if (IS_IRQ_MODE()) { ... } /* Check if the timer control block is valid */ else if ((timer_id == NULL) || (timer_ptr->tx_timer_id != TX_TIMER_ID)) { /* Return osErrorParameter error */ status = osErrorParameter; }else if ((timer_id == NULL) || (timer_ptr->tx_timer_id != TX_TIMER_ID)) { ... } else { /* Call the tx_timer_delete to delete the specified application timer. */ if (tx_timer_delete(timer_ptr) == TX_SUCCESS) { /* Free the already allocated memory for timer control block */ MemFree(timer_ptr); /* Return osOK for success */ status = osOK; }if (tx_timer_delete(timer_ptr) == TX_SUCCESS) { ... } else { /* Return osErrorResource in case of error */ status = osErrorResource; }else { ... } }else { ... } return (status); }{ ... } /*---------------------------------------------------------------------------*/---------------------------Timer Management APIs /*-----------------------------Event flags APIs------------------------------*/ /*---------------------------------------------------------------------------*/ /** * @brief The function osEventFlagsNew creates a new event flags object that * is used to send events across threads and returns the pointer to the * event flags object identifier or NULL in case of an error. It can be * safely called before the RTOS is started (call to osKernelStart), but * not before it is initialized (call to osKernelInitialize). * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] attr event flags attributes; NULL: default values. * @retval event flags ID for reference by other functions or NULL in * case of error. *//* ... */ osEventFlagsId_t osEventFlagsNew(const osEventFlagsAttr_t *attr) { /* For ThreadX the control block pointer is the event flags identifier */ TX_EVENT_FLAGS_GROUP *eventflags_ptr = NULL; /* Pointer to the event flags name */ CHAR *name_ptr = NULL; /* The size of control block */ ULONG cb_size = sizeof(TX_EVENT_FLAGS_GROUP); /* Check if this API is called from Interrupt Service Routines */ if (!IS_IRQ_MODE()) { /* Check if the attr is not NULL */ if (attr != NULL) { /* Check if the name_ptr is not NULL */ if (attr->name != NULL) { /* Set the event flags name_ptr */ name_ptr = (CHAR *)attr->name; }if (attr->name != NULL) { ... } /* Check if the control block size is equal to 0 */ if (attr->cb_size == 0U) { /* Set control block size to sizeof(TX_EVENT_FLAGS_GROUP) */ cb_size = sizeof(TX_EVENT_FLAGS_GROUP); }if (attr->cb_size == 0U) { ... } else if (attr->cb_size < sizeof(TX_EVENT_FLAGS_GROUP)) { /* Return NULL pointer in case of error */ return (NULL); }else if (attr->cb_size < sizeof(TX_EVENT_FLAGS_GROUP)) { ... } else { /* Set control block size to attr->cb_size */ cb_size = (ULONG) attr->cb_size; }else { ... } /* Check if the input control block pointer is NULL */ if (attr->cb_mem == NULL) { /* Allocate the eventflags_ptr structure for the event flags to be created */ eventflags_ptr = (TX_EVENT_FLAGS_GROUP *)MemAlloc(cb_size, RTOS2_BYTE_POOL_HEAP_TYPE); if (eventflags_ptr == NULL) { /* Return NULL pointer in case of error */ return (NULL); }if (eventflags_ptr == NULL) { ... } }if (attr->cb_mem == NULL) { ... } else { /* The control block shall point to the input cb_mem memory address */ eventflags_ptr = attr->cb_mem; }else { ... } }if (attr != NULL) { ... } else { /* Allocate the eventflags_ptr structure for the event flags to be created */ eventflags_ptr = (TX_EVENT_FLAGS_GROUP *)MemAlloc(cb_size, RTOS2_BYTE_POOL_HEAP_TYPE); }else { ... } /* Call the tx_event_flags_create function to create the new event flags */ if (tx_event_flags_create(eventflags_ptr, name_ptr) != TX_SUCCESS) { if ((attr->cb_mem == NULL) || (attr == NULL)) { /* Free the already allocated memory for event flags control block */ MemFree(eventflags_ptr); }if ((attr->cb_mem == NULL) || (attr == NULL)) { ... } }if (tx_event_flags_create(eventflags_ptr, name_ptr) != TX_SUCCESS) { ... } }if (!IS_IRQ_MODE()) { ... } return ((osEventFlagsId_t)eventflags_ptr); }{ ... } /** * @brief The function osEventFlagsGetName returns the pointer to the name * string of the event flags object identified by parameter ef_id or NULL * in case of an error. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] ef_id event flags ID obtained by osEventFlagsNew. * @retval name as null-terminated string. *//* ... */ const char *osEventFlagsGetName(osEventFlagsId_t ef_id) { /* For ThreadX the control block pointer is the event flags identifier */ TX_EVENT_FLAGS_GROUP *eventflags_ptr = (TX_EVENT_FLAGS_GROUP *)ef_id; /* The output name_ptr as null-terminated string */ CHAR *name_ptr; /* Check if this API is called from Interrupt Service Routines or the ef_id is NULL *//* ... */ if (IS_IRQ_MODE() || (eventflags_ptr == NULL)) { /* Return NULL in case of an error */ name_ptr = NULL; }if (IS_IRQ_MODE() || (eventflags_ptr == NULL)) { ... } else { /* Call the tx_event_flags_info_get to get the event flags name_ptr */ if (tx_event_flags_info_get(eventflags_ptr, &name_ptr, NULL, NULL, NULL, NULL) != TX_SUCCESS) { /* Return NULL in case of an error */ name_ptr = NULL; }if (tx_event_flags_info_get(eventflags_ptr, &name_ptr, NULL, NULL, NULL, NULL) != TX_SUCCESS) { ... } }else { ... } return (name_ptr); }{ ... } /** * @brief The function osEventFlagsSet sets the event flags specified by the * parameter flags in an event flags object specified by parameter ef_id. * All threads waiting for the flag set will be notified to resume from * BLOCKED state. The function returns the event flags stored in the event * control block or an error code (highest bit is set, refer to Flags * Functions Error Codes). * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] ef_id event flags ID obtained by osEventFlagsNew. * [in] flags specifies the flags that shall be set. * @retval event flags after setting or error code if highest bit set. *//* ... */ uint32_t osEventFlagsSet(osEventFlagsId_t ef_id, uint32_t flags) { /* For ThreadX the control block pointer is the semaphore identifier */ TX_EVENT_FLAGS_GROUP *eventflags_ptr = (TX_EVENT_FLAGS_GROUP *)ef_id; /* The returned flags_status or error */ uint32_t flags_status; /* Flags to set */ ULONG flags_to_set = (ULONG) flags; /* Check if the event flags ID is NULL or the event flags is invalid */ if ((ef_id == NULL) || (eventflags_ptr -> tx_event_flags_group_id != TX_EVENT_FLAGS_ID)) { /* Return osFlagsErrorParameter error */ flags_status = osFlagsErrorParameter; }if ((ef_id == NULL) || (eventflags_ptr -> tx_event_flags_group_id != TX_EVENT_FLAGS_ID)) { ... } else { /* Call the tx_event_flags_set to set flags */ if (tx_event_flags_set(eventflags_ptr, flags_to_set, TX_OR) == TX_SUCCESS) { /* Call the tx_event_flags_info_get to get the current flags */ if (tx_event_flags_info_get(eventflags_ptr, NULL, (ULONG *) &flags_status, NULL, NULL, NULL) != TX_SUCCESS) { /* Return osFlagsErrorUnknown in case of an error */ flags_status = osFlagsErrorUnknown; }if (tx_event_flags_info_get(eventflags_ptr, NULL, (ULONG *) &flags_status, NULL, NULL, NULL) != TX_SUCCESS) { ... } }if (tx_event_flags_set(eventflags_ptr, flags_to_set, TX_OR) == TX_SUCCESS) { ... } else { /* Return osFlagsErrorResource in case of error */ flags_status = osFlagsErrorResource; }else { ... } }else { ... } return (flags_status); }{ ... } /** * @brief The function osEventFlagsClear clears the event flags specified by * the parameter flags in an event flags object specified by parameter * ef_id. The function returns the event flags before clearing or an error * code (highest bit is set, refer to Flags Functions Error Codes). * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] ef_id event flags ID obtained by osEventFlagsNew. * [in] flags specifies the flags that shall be cleared. * @retval event flags before clearing or error code if highest bit set. *//* ... */ uint32_t osEventFlagsClear(osEventFlagsId_t ef_id, uint32_t flags) { /* For ThreadX the control block pointer is the semaphore identifier */ TX_EVENT_FLAGS_GROUP *eventflags_ptr = (TX_EVENT_FLAGS_GROUP *)ef_id; /* The returned flags_status or error */ uint32_t flags_status; /* Flags to clear */ ULONG flags_to_clear = (ULONG) ~flags; /* Check if the event flags ID is NULL or the event flags is invalid */ if ((ef_id == NULL) || (eventflags_ptr -> tx_event_flags_group_id != TX_EVENT_FLAGS_ID)) { /* Return osFlagsErrorParameter error */ flags_status = osFlagsErrorParameter; }if ((ef_id == NULL) || (eventflags_ptr -> tx_event_flags_group_id != TX_EVENT_FLAGS_ID)) { ... } else { /* Call the tx_event_flags_info_get to get the current flags */ if (tx_event_flags_info_get(eventflags_ptr, NULL, (ULONG *) &flags_status, NULL, NULL, NULL) != TX_SUCCESS) { /* Return osFlagsErrorUnknown in case of an error */ flags_status = osFlagsErrorUnknown; }if (tx_event_flags_info_get(eventflags_ptr, NULL, (ULONG *) &flags_status, NULL, NULL, NULL) != TX_SUCCESS) { ... } else { /* Call the tx_event_flags_set to set flags */ if (tx_event_flags_set(eventflags_ptr, flags_to_clear, TX_AND) != TX_SUCCESS) { /* Return osFlagsErrorResource in case of error */ flags_status = osFlagsErrorResource; }if (tx_event_flags_set(eventflags_ptr, flags_to_clear, TX_AND) != TX_SUCCESS) { ... } }else { ... } }else { ... } return (flags_status); }{ ... } /** * @brief The function osEventFlagsGet returns the event flags currently set * in an event flags object specified by parameter ef_id or 0 in case of * an error. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] ef_id event flags ID obtained by osEventFlagsNew. * @retval current event flags. *//* ... */ uint32_t osEventFlagsGet(osEventFlagsId_t ef_id) { /* For ThreadX the control block pointer is the event flags identifier */ TX_EVENT_FLAGS_GROUP *eventflags_ptr = (TX_EVENT_FLAGS_GROUP *)ef_id; /* The current flags */ uint32_t current_flags = 0; /* Check if the event flags ID is NULL or the event flags is invalid */ if ((ef_id == NULL) || (eventflags_ptr -> tx_event_flags_group_id != TX_EVENT_FLAGS_ID)) { /* Return 0 in case of an error */ current_flags = 0; }if ((ef_id == NULL) || (eventflags_ptr -> tx_event_flags_group_id != TX_EVENT_FLAGS_ID)) { ... } else { /* Call the tx_event_flags_info_get to get the current flags */ if (tx_event_flags_info_get(eventflags_ptr, NULL, (ULONG *) &current_flags, NULL, NULL, NULL) != TX_SUCCESS) { /* Return 0 in case of an error */ current_flags = 0; }if (tx_event_flags_info_get(eventflags_ptr, NULL, (ULONG *) ¤t_flags, NULL, NULL, NULL) != TX_SUCCESS) { ... } }else { ... } return (current_flags); }{ ... } /** * @brief The function osEventFlagsWait suspends the execution of the * currently RUNNING thread until any or all event flags specified by the * parameter flags in the event object specified by parameter ef_id are * set. When these event flags are already set, the function returns * instantly. Otherwise, the thread is put into the state BLOCKED. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] ef_id event flags ID obtained by osEventFlagsNew. * [in] flags specifies the flags to wait for. * [in] options specifies flags options (osFlagsXxxx). * [in] timeout Timeout Value or 0 in case of no time-out. * @retval event flags before clearing or error code if highest bit set. *//* ... */ uint32_t osEventFlagsWait(osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout) { /* For ThreadX the control block pointer is the semaphore identifier */ TX_EVENT_FLAGS_GROUP *eventflags_ptr = (TX_EVENT_FLAGS_GROUP *)ef_id; /* Flags to get */ ULONG requested_flags = (ULONG) flags; /* The ThreadX wait option */ ULONG wait_option = (ULONG) timeout; /* The ThreadX get options */ UINT get_option = 0; /* The actual flags */ ULONG actual_flags = 0; /* ThreadX APIs status */ UINT status; /* Check if the event flags ID is NULL or the event flags is invalid or non-zero timeout specified in an ISR */ if ((IS_IRQ_MODE() && (timeout != 0)) || (ef_id == NULL) || (eventflags_ptr -> tx_event_flags_group_id != TX_EVENT_FLAGS_ID)) { /* Return osFlagsErrorParameter error */ actual_flags = osFlagsErrorParameter; }if ((IS_IRQ_MODE() && (timeout != 0)) || (ef_id == NULL) || (eventflags_ptr -> tx_event_flags_group_id != TX_EVENT_FLAGS_ID)) { ... } else { if (options == osFlagsNoClear) { get_option = TX_AND; }if (options == osFlagsNoClear) { ... } else { get_option = TX_AND_CLEAR; }else { ... } /* Call the tx_event_flags_get to get flags */ status = tx_event_flags_get(eventflags_ptr, requested_flags, get_option, &actual_flags, wait_option); /* Check the status */ if ((status == TX_NO_EVENTS) || (status == TX_WAIT_ERROR)) { /* Return osFlagsErrorTimeout for timeout error */ actual_flags = osFlagsErrorTimeout; }if ((status == TX_NO_EVENTS) || (status == TX_WAIT_ERROR)) { ... } else if (status != TX_SUCCESS) { /* Return osFlagsErrorResource in case of an error */ actual_flags = osFlagsErrorResource ; }else if (status != TX_SUCCESS) { ... } }else { ... } return ((uint32_t)actual_flags); }{ ... } /** * @brief The function osEventFlagsDelete deletes the event flags object * specified by parameter ef_id and releases the internal memory obtained * for the event flags handling. After this call, the ef_id is no longer * valid and cannot be used. This can cause starvation of threads that are * waiting for flags of this event object. The ef_id may be created again * using the function osEventFlagsNew. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] ef_id event flags ID obtained by osEventFlagsNew. * @retval status code that indicates the execution status of the function. *//* ... */ osStatus_t osEventFlagsDelete(osEventFlagsId_t ef_id) { /* For ThreadX the control block pointer is the event flags identifier */ TX_EVENT_FLAGS_GROUP *eventflags_ptr = (TX_EVENT_FLAGS_GROUP *)ef_id; /* The returned status or error */ osStatus_t status; /* Check if this API is called from Interrupt Service Routines */ if (IS_IRQ_MODE()) { /* Return osErrorISR error */ status = osErrorISR; }if (IS_IRQ_MODE()) { ... } /* Check if the event flags ID is NULL or the event flags is invalid */ else if ((ef_id == NULL) || (eventflags_ptr -> tx_event_flags_group_id != TX_EVENT_FLAGS_ID)) { /* Return osErrorParameter error */ status = osErrorParameter; }else if ((ef_id == NULL) || (eventflags_ptr -> tx_event_flags_group_id != TX_EVENT_FLAGS_ID)) { ... } else { /* Call the tx_event_flags_delete to delete the event flags object */ if (tx_event_flags_delete(eventflags_ptr) == TX_SUCCESS) { /* Free the already allocated memory for thread control block */ if (MemFree(eventflags_ptr) == osOK) { /* Return osOK for success */ status = osOK; }if (MemFree(eventflags_ptr) == osOK) { ... } else { /* Return osErrorResource in case of error */ status = osErrorResource; }else { ... } }if (tx_event_flags_delete(eventflags_ptr) == TX_SUCCESS) { ... } else { /* Return osErrorResource in case of error */ status = osErrorResource; }else { ... } }else { ... } return (status); }{ ... } /*---------------------------------------------------------------------------*/-----------------------------Event flags APIs /*---------------------------Mutex Management APIs---------------------------*/ /*---------------------------------------------------------------------------*/ /** * @brief The function osMutexNew creates and initializes a new mutex * object and returns the pointer to the mutex object identifier or * NULL in case of an error. It can be safely called before the RTOS * is started (call to osKernelStart), but not before it is initialized * call to osKernelInitialize). * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] attr mutex attributes; NULL: default values. * @retval mutex ID for reference by other functions or NULL in case of error. *//* ... */ osMutexId_t osMutexNew(const osMutexAttr_t *attr) { /* For ThreadX the control block pointer is the mutex identifier */ TX_MUTEX *mutex_ptr = NULL; /* Pointer to the mutex name */ CHAR *name_ptr = NULL; /* The mutex inherit status */ UINT inherit = TX_INHERIT; /* The size of control block */ ULONG cb_size = sizeof(TX_MUTEX); /* Check if this API is called from Interrupt Service Routines */ if (!IS_IRQ_MODE()) { /* Check if the attr is not NULL */ if (attr != NULL) { /* Check if the name_ptr is not NULL */ if (attr->name != NULL) { /* Set the mutex name_ptr */ name_ptr = (CHAR *)attr->name; }if (attr->name != NULL) { ... } /* Check if the attr_bits is not zero */ if (attr->attr_bits != 0) { /* Check the mutex inherit status */ if ((attr->attr_bits & osMutexPrioInherit) == osMutexPrioInherit) { inherit = TX_INHERIT; }if ((attr->attr_bits & osMutexPrioInherit) == osMutexPrioInherit) { ... } else { inherit = TX_NO_INHERIT; }else { ... } }if (attr->attr_bits != 0) { ... } /* Check if the control block size is equal to 0 */ if (attr->cb_size == 0U) { /* Set control block size to sizeof(TX_MUTEX) */ cb_size = sizeof(TX_MUTEX); }if (attr->cb_size == 0U) { ... } else if (attr->cb_size < sizeof(TX_MUTEX)) { /* Return NULL pointer in case of error */ return (NULL); }else if (attr->cb_size < sizeof(TX_MUTEX)) { ... } else { /* Set control block size to attr->cb_size */ cb_size = (ULONG) attr->cb_size; }else { ... } /* Check if the input control block pointer is NULL */ if (attr->cb_mem == NULL) { /* Allocate the mutex_ptr structure for the mutex to be created */ mutex_ptr = (TX_MUTEX *)MemAlloc(cb_size, RTOS2_BYTE_POOL_HEAP_TYPE); if (mutex_ptr == NULL) { /* Return NULL pointer in case of error */ return (NULL); }if (mutex_ptr == NULL) { ... } }if (attr->cb_mem == NULL) { ... } else { /* The control block shall point to the input cb_mem memory address */ mutex_ptr = attr->cb_mem; }else { ... } }if (attr != NULL) { ... } else { /* Allocate the mutex_ptr structure for the mutex to be created */ mutex_ptr = (TX_MUTEX *)MemAlloc(cb_size, RTOS2_BYTE_POOL_HEAP_TYPE); }else { ... } /* Call the tx_mutex_create function to create the new mutex */ if (tx_mutex_create(mutex_ptr, name_ptr, inherit) != TX_SUCCESS) { if ((attr->cb_mem == NULL) || (attr == NULL)) { /* Free the already allocated memory for mutex control block */ MemFree(mutex_ptr); }if ((attr->cb_mem == NULL) || (attr == NULL)) { ... } }if (tx_mutex_create(mutex_ptr, name_ptr, inherit) != TX_SUCCESS) { ... } }if (!IS_IRQ_MODE()) { ... } return ((osMutexId_t)mutex_ptr); }{ ... } /** * @brief The function osMutexGetName returns the pointer to the name string * of the mutex identified by parameter mutex_id or NULL in case of * an error. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] mutex_id mutex ID obtained by osMutexNew. * @retval name as null-terminated string. *//* ... */ const char *osMutexGetName(osMutexId_t mutex_id) { /* For ThreadX the control block pointer is the mutex identifier */ TX_MUTEX *mutex_ptr = (TX_MUTEX *)mutex_id; /* The output name_ptr as null-terminated string */ CHAR *name_ptr; /* Check if this API is called from Interrupt Service Routines or the mutex_id is NULL or the mutex is invalid *//* ... */ if (IS_IRQ_MODE() || (mutex_ptr == NULL) || (mutex_ptr -> tx_mutex_id != TX_MUTEX_ID)) { /* Return NULL in case of an error */ name_ptr = NULL; }if (IS_IRQ_MODE() || (mutex_ptr == NULL) || (mutex_ptr -> tx_mutex_id != TX_MUTEX_ID)) { ... } else { /* Call the tx_mutex_info_get to get the mutex name_ptr */ if (tx_mutex_info_get(mutex_ptr, &name_ptr, NULL, NULL, NULL, NULL, NULL) != TX_SUCCESS) { /* Return NULL in case of an error */ name_ptr = NULL; }if (tx_mutex_info_get(mutex_ptr, &name_ptr, NULL, NULL, NULL, NULL, NULL) != TX_SUCCESS) { ... } }else { ... } return (name_ptr); }{ ... } /** * @brief The blocking function osMutexAcquire waits until a mutex object * specified by parameter mutex_id becomes available. If no other thread * has obtained the mutex, the function instantly returns and blocks * the mutex object. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] mutex_id mutex ID obtained by osMutexNew. * [in] timeout Timeout Value or 0 in case of no time-out. * @retval status code that indicates the execution status of the function. *//* ... */ osStatus_t osMutexAcquire(osMutexId_t mutex_id, uint32_t timeout) { /* For ThreadX the control block pointer is the mutex identifier */ TX_MUTEX *mutex_ptr = (TX_MUTEX *)mutex_id; /* The returned status or error */ osStatus_t status; /* The ThreadX wait option */ ULONG wait_option = (ULONG) timeout; /* The tx_mutex_get returned status */ UINT tx_status; /* Check if this API is called from Interrupt Service Routines */ if (IS_IRQ_MODE()) { /* Return osErrorISR error */ status = osErrorISR; }if (IS_IRQ_MODE()) { ... } /* Check if the mutex ID is NULL or the mutex is invalid */ else if ((mutex_id == NULL) || (mutex_ptr -> tx_mutex_id != TX_MUTEX_ID)) { /* Return osErrorParameter error */ status = osErrorParameter; }else if ((mutex_id == NULL) || (mutex_ptr -> tx_mutex_id != TX_MUTEX_ID)) { ... } else { /* Call the tx_mutex_get to get the mutex object */ tx_status = tx_mutex_get(mutex_ptr, wait_option); if (tx_status == TX_SUCCESS) { /* Return osOK for success */ status = osOK; }if (tx_status == TX_SUCCESS) { ... } else if (tx_status == TX_WAIT_ABORTED) { /* Return osErrorTimeout when the mutex is not obtained in the given time */ status = osErrorTimeout; }else if (tx_status == TX_WAIT_ABORTED) { ... } else { /* Return osErrorResource in case of error */ status = osErrorResource; }else { ... } }else { ... } return (status); }{ ... } /** * @brief The function osMutexRelease releases a mutex specified by parameter * mutex_id. Other threads that currently wait for this mutex will be * put into the READY state. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] mutex_id mutex ID obtained by osMutexNew. * @retval status code that indicates the execution status of the function. *//* ... */ osStatus_t osMutexRelease(osMutexId_t mutex_id) { /* For ThreadX the control block pointer is the mutex identifier */ TX_MUTEX *mutex_ptr = (TX_MUTEX *)mutex_id; /* The returned status or error */ osStatus_t status; /* Check if this API is called from Interrupt Service Routines */ if (IS_IRQ_MODE()) { /* Return osErrorISR error */ status = osErrorISR; }if (IS_IRQ_MODE()) { ... } /* Check if the mutex ID is NULL or the mutex is invalid */ else if ((mutex_id == NULL) || (mutex_ptr -> tx_mutex_id != TX_MUTEX_ID)) { /* Return osErrorParameter error */ status = osErrorParameter; }else if ((mutex_id == NULL) || (mutex_ptr -> tx_mutex_id != TX_MUTEX_ID)) { ... } else { /* Call the tx_mutex_put to put the mutex object */ if (tx_mutex_put(mutex_ptr) == TX_SUCCESS) { /* Return osOK for success */ status = osOK; }if (tx_mutex_put(mutex_ptr) == TX_SUCCESS) { ... } else { /* Return osErrorResource in case of error */ status = osErrorResource; }else { ... } }else { ... } return (status); }{ ... } /** * @brief The function osMutexGetOwner returns the thread ID of the thread * that acquired a mutex specified by parameter mutex_id. In case of an * error or if the mutex is not blocked by any thread, it returns NULL. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] mutex_id mutex ID obtained by osMutexNew. * @retval thread ID of owner thread or NULL when mutex was not acquired. *//* ... */ osThreadId_t osMutexGetOwner(osMutexId_t mutex_id) { /* For ThreadX the control block pointer is the mutex identifier */ TX_MUTEX *mutex_ptr = (TX_MUTEX *)mutex_id; /* The owner thread of the mutex object */ TX_THREAD *thread_ptr = NULL; /* Check if this API is called from Interrupt Service Routines */ if (IS_IRQ_MODE()) { /* Return NULL when the API is called from ISR */ thread_ptr = NULL; }if (IS_IRQ_MODE()) { ... } /* Check if the mutex ID is NULL or the mutex is invalid */ else if ((mutex_id == NULL) || (mutex_ptr -> tx_mutex_id != TX_MUTEX_ID)) { /* Return NULL when mutex_id is NULL */ thread_ptr = NULL; }else if ((mutex_id == NULL) || (mutex_ptr -> tx_mutex_id != TX_MUTEX_ID)) { ... } else { /* Call the tx_mutex_info_get to get the mutex thread owner */ if (tx_mutex_info_get(mutex_ptr, NULL, NULL, &thread_ptr, NULL, NULL, NULL) == TX_SUCCESS) { if (thread_ptr == TX_NULL) { /* Return NULL when mutex object is not acquired */ thread_ptr = NULL; }if (thread_ptr == TX_NULL) { ... } }if (tx_mutex_info_get(mutex_ptr, NULL, NULL, &thread_ptr, NULL, NULL, NULL) == TX_SUCCESS) { ... } else { /* Return NULL when mutex_id is invalid */ thread_ptr = NULL; }else { ... } }else { ... } return ((osThreadId_t)thread_ptr); }{ ... } /** * @brief The function osMutexDelete deletes a mutex object specified by * parameter mutex_id. It releases internal memory obtained for mutex * handling. After this call, the mutex_id is no longer valid and cannot * be used. The mutex may be created again using the function osMutexNew. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] mutex_id mutex ID obtained by osMutexNew. * @retval status code that indicates the execution status of the function. *//* ... */ osStatus_t osMutexDelete(osMutexId_t mutex_id) { /* For ThreadX the control block pointer is the mutex identifier */ TX_MUTEX *mutex_ptr = (TX_MUTEX *)mutex_id; /* The returned status or error */ osStatus_t status; /* Check if this API is called from Interrupt Service Routines */ if (IS_IRQ_MODE()) { /* Return osErrorISR error */ status = osErrorISR; }if (IS_IRQ_MODE()) { ... } /* Check if the mutex ID is NULL or the mutex is invalid*/ else if ((mutex_id == NULL) || (mutex_ptr -> tx_mutex_id != TX_MUTEX_ID)) { /* Return osErrorParameter error */ status = osErrorParameter; }else if ((mutex_id == NULL) || (mutex_ptr -> tx_mutex_id != TX_MUTEX_ID)) { ... } else { /* Call the tx_mutex_delete to delete the mutex object */ if (tx_mutex_delete(mutex_ptr) == TX_SUCCESS) { /* Free the already allocated memory for mutex control block */ if (MemFree(mutex_ptr) == osOK) { /* Return osOK for success */ status = osOK; }if (MemFree(mutex_ptr) == osOK) { ... } else { /* Return osErrorResource in case of error */ status = osErrorResource; }else { ... } }if (tx_mutex_delete(mutex_ptr) == TX_SUCCESS) { ... } else { /* Return osErrorResource in case of error */ status = osErrorResource; }else { ... } }else { ... } return (status); }{ ... } /*---------------------------------------------------------------------------*/---------------------------Mutex Management APIs /*------------------------------Semaphores APIs------------------------------*/ /*---------------------------------------------------------------------------*/ /** * @brief The function osSemaphoreNew creates and initializes a semaphore * object that is used to manage access to shared resources and returns * the pointer to the semaphore object identifier or NULL in case of an * error. It can be safely called before the RTOS is started * (call to osKernelStart), but not before it is initialized * (call to osKernelInitialize). * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] max_count maximum number of available tokens. * [in] initial_count initial number of available tokens. * [in] attr semaphore attributes; NULL: default values. * @retval semaphore ID for reference by other functions or NULL in case of error. *//* ... */ osSemaphoreId_t osSemaphoreNew(uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr) { /* For ThreadX the control block pointer is the semaphore identifier */ TX_SEMAPHORE *semaphore_ptr = NULL; /* Pointer to the semaphore name */ CHAR *name_ptr = NULL; /* The semaphore initial count */ ULONG init_count = (ULONG) initial_count; /* The size of control block */ ULONG cb_size = sizeof(TX_SEMAPHORE); /* Check if this API is called from Interrupt Service Routines */ if (!IS_IRQ_MODE()) { /* Check if the attr is not NULL */ if (attr != NULL) { /* Check if the name_ptr is not NULL */ if (attr->name != NULL) { /* Set the semaphore name_ptr */ name_ptr = (CHAR *)attr->name; }if (attr->name != NULL) { ... } /* Check if the control block size is equal to 0 */ if (attr->cb_size == 0U) { /* Set control block size to sizeof(TX_SEMAPHORE) */ cb_size = sizeof(TX_SEMAPHORE); }if (attr->cb_size == 0U) { ... } else if (attr->cb_size < sizeof(TX_SEMAPHORE)) { /* Return NULL pointer in case of error */ return (NULL); }else if (attr->cb_size < sizeof(TX_SEMAPHORE)) { ... } else { /* Set control block size to attr->cb_size */ cb_size = (ULONG) attr->cb_size; }else { ... } /* Check if the input control block pointer is NULL */ if (attr->cb_mem == NULL) { /* Allocate the semaphore_ptr structure for the semaphore to be created */ semaphore_ptr = (TX_SEMAPHORE *)MemAlloc(cb_size, RTOS2_BYTE_POOL_HEAP_TYPE); if (semaphore_ptr == NULL) { /* Return NULL pointer in case of error */ return (NULL); }if (semaphore_ptr == NULL) { ... } }if (attr->cb_mem == NULL) { ... } else { /* The control block shall point to the input cb_mem memory address */ semaphore_ptr = attr->cb_mem; }else { ... } }if (attr != NULL) { ... } else { /* Allocate the semaphore_ptr structure for the semaphore to be created */ semaphore_ptr = (TX_SEMAPHORE *)MemAlloc(cb_size, RTOS2_BYTE_POOL_HEAP_TYPE); }else { ... } /* Call the tx_semaphore_create function to create the new semaphore */ if (tx_semaphore_create(semaphore_ptr, name_ptr, init_count) != TX_SUCCESS) { if ((attr->cb_mem == NULL) || (attr == NULL)) { /* Free the already allocated memory for semaphore control block */ MemFree(semaphore_ptr); }if ((attr->cb_mem == NULL) || (attr == NULL)) { ... } }if (tx_semaphore_create(semaphore_ptr, name_ptr, init_count) != TX_SUCCESS) { ... } }if (!IS_IRQ_MODE()) { ... } return ((osSemaphoreId_t)semaphore_ptr); }{ ... } /** * @brief The function osSemaphoreGetName returns the pointer to the name * string of the semaphore identified by parameter semaphore_id or NULL * in case of an error. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] semaphore_id semaphore ID obtained by osSemaphoreNew. * @retval name as null-terminated string. *//* ... */ const char *osSemaphoreGetName(osSemaphoreId_t semaphore_id) { /* For ThreadX the control block pointer is the semaphore identifier */ TX_SEMAPHORE *semaphore_ptr = (TX_SEMAPHORE *)semaphore_id; /* The output name_ptr as null-terminated string */ CHAR *name_ptr; /* Check if this API is called from Interrupt Service Routines or the semaphore_id is NULL and the semaphore is invalid *//* ... */ if (IS_IRQ_MODE() || (semaphore_ptr == NULL) || (semaphore_ptr -> tx_semaphore_id != TX_SEMAPHORE_ID)) { /* Return NULL in case of an error */ name_ptr = NULL; }if (IS_IRQ_MODE() || (semaphore_ptr == NULL) || (semaphore_ptr -> tx_semaphore_id != TX_SEMAPHORE_ID)) { ... } else { /* Call the tx_semaphore_info_get to get the semaphore name_ptr */ if (tx_semaphore_info_get(semaphore_ptr, &name_ptr, NULL, NULL, NULL, NULL) != TX_SUCCESS) { /* Return NULL in case of an error */ name_ptr = NULL; }if (tx_semaphore_info_get(semaphore_ptr, &name_ptr, NULL, NULL, NULL, NULL) != TX_SUCCESS) { ... } }else { ... } return (name_ptr); }{ ... } /** * @brief The blocking function osSemaphoreAcquire waits until a token of the * semaphore object specified by parameter semaphore_id becomes available. * If a token is available, the function instantly returns and decrements * the token count. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] semaphore_id semaphore ID obtained by osSemaphoreNew. * [in] timeout Timeout Value or 0 in case of no time-out. * @retval status code that indicates the execution status of the function. *//* ... */ osStatus_t osSemaphoreAcquire(osSemaphoreId_t semaphore_id, uint32_t timeout) { /* For ThreadX the control block pointer is the semaphore identifier */ TX_SEMAPHORE *semaphore_ptr = (TX_SEMAPHORE *)semaphore_id; /* The returned status or error */ osStatus_t status; /* The ThreadX wait option */ ULONG wait_option = (ULONG) timeout; /* The tx_semaphore_get returned status */ UINT tx_status; /* Check if the semaphore ID is NULL or the semaphore is invalid or non-zero timeout specified in an ISR */ if ((IS_IRQ_MODE() && (timeout != 0)) || (semaphore_id == NULL) || (semaphore_ptr -> tx_semaphore_id != TX_SEMAPHORE_ID)) { /* Return osErrorParameter error */ status = osErrorParameter; }if ((IS_IRQ_MODE() && (timeout != 0)) || (semaphore_id == NULL) || (semaphore_ptr -> tx_semaphore_id != TX_SEMAPHORE_ID)) { ... } else { /* Call the tx_semaphore_get to get the semaphore object */ tx_status = tx_semaphore_get(semaphore_ptr, wait_option); if (tx_status == TX_SUCCESS) { /* Return osOK for success */ status = osOK; }if (tx_status == TX_SUCCESS) { ... } else if (tx_status == TX_WAIT_ABORTED) { /* Return osErrorTimeout when the semaphore is not obtained in the given time *//* ... */ status = osErrorTimeout; }else if (tx_status == TX_WAIT_ABORTED) { ... } else { /* Return osErrorResource in case of error */ status = osErrorResource; }else { ... } }else { ... } return (status); }{ ... } /** * @brief The function osSemaphoreRelease releases a token of the semaphore * object specified by parameter semaphore_id. Tokens can only be released * up to the maximum count specified at creation time, see osSemaphoreNew. * Other threads that currently wait for a token of this semaphore object * will be put into the READY state. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] semaphore_id semaphore ID obtained by osSemaphoreNew. * @retval status code that indicates the execution status of the function. *//* ... */ osStatus_t osSemaphoreRelease(osSemaphoreId_t semaphore_id) { /* For ThreadX the control block pointer is the semaphore identifier */ TX_SEMAPHORE *semaphore_ptr = (TX_SEMAPHORE *)semaphore_id; /* The returned status or error */ osStatus_t status; /* Check if the semaphore ID is NULL or the semaphore is invalid */ if ((semaphore_id == NULL) || (semaphore_ptr -> tx_semaphore_id != TX_SEMAPHORE_ID)) { /* Return osErrorParameter error */ status = osErrorParameter; }if ((semaphore_id == NULL) || (semaphore_ptr -> tx_semaphore_id != TX_SEMAPHORE_ID)) { ... } else { /* Call the tx_semaphore_put to put the semaphore object */ if (tx_semaphore_put(semaphore_ptr) == TX_SUCCESS) { /* Return osOK for success */ status = osOK; }if (tx_semaphore_put(semaphore_ptr) == TX_SUCCESS) { ... } else { /* Return osErrorResource in case of error */ status = osErrorResource; }else { ... } }else { ... } return (status); }{ ... } /** * @brief The function osSemaphoreDelete deletes a semaphore object specified * by parameter semaphore_id. It releases internal memory obtained for * semaphore handling. After this call, the semaphore_id is no longer * valid and cannot be used. The semaphore may be created again using * the function osSemaphoreNew. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] semaphore_id semaphore ID obtained by osSemaphoreNew. * @retval status code that indicates the execution status of the function. *//* ... */ osStatus_t osSemaphoreDelete(osSemaphoreId_t semaphore_id) { /* For ThreadX the control block pointer is the semaphore identifier */ TX_SEMAPHORE *semaphore_ptr = (TX_SEMAPHORE *)semaphore_id; /* The returned status or error */ osStatus_t status; /* Check if this API is called from Interrupt Service Routines */ if (IS_IRQ_MODE()) { /* Return osErrorISR error */ status = osErrorISR; }if (IS_IRQ_MODE()) { ... } /* Check if the semaphore ID is NULL or the semaphore is invalid */ else if ((semaphore_id == NULL) || (semaphore_ptr -> tx_semaphore_id != TX_SEMAPHORE_ID)) { /* Return osErrorParameter error */ status = osErrorParameter; }else if ((semaphore_id == NULL) || (semaphore_ptr -> tx_semaphore_id != TX_SEMAPHORE_ID)) { ... } else { /* Call the tx_semaphore_delete to delete the semaphore object */ if (tx_semaphore_delete(semaphore_ptr) == TX_SUCCESS) { /* Free the already allocated memory for semaphore control block */ if (MemFree(semaphore_ptr) == osOK) { /* Return osOK for success */ status = osOK; }if (MemFree(semaphore_ptr) == osOK) { ... } else { /* Return osErrorResource in case of error */ status = osErrorResource; }else { ... } }if (tx_semaphore_delete(semaphore_ptr) == TX_SUCCESS) { ... } else { /* Return osErrorResource in case of error */ status = osErrorResource; }else { ... } }else { ... } return (status); }{ ... } /*---------------------------------------------------------------------------*/------------------------------Semaphores APIs /*------------------------------Message Queue APIs---------------------------*/ /*---------------------------------------------------------------------------*/ /** * @brief The function osMessageQueueNew creates and initializes a message queue * object. The function returns a message queue object identifier * or NULL in case of an error. * The function can be called after kernel initialization with osKernelInitialize. * It is possible to create message queue objects before the RTOS kernel is * started with osKernelStart. * The total amount of memory required for the message queue data is at least * msg_count * msg_size. The msg_size is rounded up to a double even number to * ensure 32-bit alignment of the memory blocks. * The memory blocks allocated from the message queue have a fixed size defined * with the parameter msg_size. * Note : This function Cannot be called from Interrupt Service * Routines. * @param [in] msg_count maximum number of messages in queue. * [in] msg_size maximum message size in bytes. * [in] attr message queue attributes; NULL: default values. * @retval message queue ID for reference by other functions or NULL in case of error. *//* ... */ osMessageQueueId_t osMessageQueueNew(uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr) { /* For TX_QUEUE the control block pointer is the queue identifier */ TX_QUEUE *queue_ptr = NULL; /* Pointer to the message queue name */ CHAR *name_ptr = NULL; /* Pointer to start address of the message queue data */ VOID *queue_start = NULL; /* The message queue data size */ ULONG queue_size = 0U; /* The message queue control block size */ ULONG cb_size = 0U; /* Check if this API is called from Interrupt Service Routines or the msg_count is equal to 0 or msg_size is equal to 0 *//* ... */ if (!IS_IRQ_MODE() && (msg_count > 0) && (msg_size > 0)) { /* Initialize the name_ptr to NULL */ name_ptr = NULL; /* The msg_size is rounded up to a double even number to ensure 32-bit alignment of the memory blocks. */ msg_size = msg_size + (msg_size % sizeof(ULONG)); /* Check if the attr is not NULL */ if (attr != NULL) { /* Check if the name_ptr is not NULL */ if (attr->name != NULL) { /* Set the message queue name_ptr */ name_ptr = (CHAR *)attr->name; }if (attr->name != NULL) { ... } /* Check if the message queue data size is equal to 0 */ if (attr->mq_size == 0U) { /* Set message queue data size to msg_count * msg_size (The total amount of memory required for the message queue data) *//* ... */ queue_size = msg_count * msg_size; }if (attr->mq_size == 0U) { ... } else if (attr->mq_size < (msg_count * msg_size)) { /* Return NULL pointer in case of error */ return (NULL); }else if (attr->mq_size < (msg_count * msg_size)) { ... } else if (attr->mq_size < TX_BYTE_POOL_MIN) { /* Set message queue data size to TX_BYTE_POOL_MIN */ queue_size = TX_BYTE_POOL_MIN; }else if (attr->mq_size < TX_BYTE_POOL_MIN) { ... } else { /* Set message queue data size to attr->mq_size */ queue_size = (ULONG)attr->mq_size; }else { ... } /* Check if the input message queue data pointer is NULL */ if (attr->mq_mem == NULL) { /* Allocate the data for the message queue to be created */ queue_start = MemAlloc(queue_size, RTOS2_BYTE_POOL_STACK_TYPE); if (queue_start == NULL) { /* Return NULL pointer in case of error */ return (NULL); }if (queue_start == NULL) { ... } }if (attr->mq_mem == NULL) { ... } else { if (attr->mq_size == 0U) { /* Return NULL pointer in case of error */ return (NULL); }if (attr->mq_size == 0U) { ... } else { /* Set message queue data size to attr->mq_size */ queue_size = (ULONG)attr->mq_size; }else { ... } /* The message queue data shall point to the input message queue data memory address */ queue_start = attr->mq_mem; }else { ... } /* Check if the control block size is equal to 0 */ if (attr->cb_size == 0U) { /* Set control block size to sizeof(TX_QUEUE) */ cb_size = sizeof(TX_QUEUE); }if (attr->cb_size == 0U) { ... } else if (attr->cb_size < sizeof(TX_QUEUE)) { /* Return NULL pointer in case of error */ return (NULL); }else if (attr->cb_size < sizeof(TX_QUEUE)) { ... } else { /* Set message queue data size to attr->cb_size */ cb_size = (ULONG)attr->cb_size; }else { ... } /* Check if the input control block pointer is NULL */ if (attr->cb_mem == NULL) { /* Allocate the queue_ptr structure for the message queue to be created */ queue_ptr = (TX_QUEUE *)MemAlloc(cb_size, RTOS2_BYTE_POOL_HEAP_TYPE); if (queue_ptr == NULL) { /* Check if the memory for message queue data has been internally allocated */ if (attr->mq_mem == NULL) { /* Free the already allocated memory for message queue data */ MemFree(queue_start); }if (attr->mq_mem == NULL) { ... } /* Return NULL pointer in case of error */ return (NULL); }if (queue_ptr == NULL) { ... } }if (attr->cb_mem == NULL) { ... } else { /* The control block shall point to the input cb_mem memory address */ queue_ptr = attr->cb_mem; }else { ... } }if (attr != NULL) { ... } else { /* Initialize the name_ptr to NULL */ name_ptr = NULL; /* Initialize the message queue data size to msg_count * msg_size (The total amount of memory required for the message queue data) *//* ... */ queue_size = msg_count * msg_size; /* Allocate the data for the message queue to be created */ queue_start = MemAlloc(queue_size, RTOS2_BYTE_POOL_STACK_TYPE); if (queue_start == NULL) { /* Return NULL pointer in case of error */ return (NULL); }if (queue_start == NULL) { ... } /* Allocate the queue_ptr structure for the message queue to be created */ queue_ptr = (TX_QUEUE *)MemAlloc(sizeof(TX_QUEUE), RTOS2_BYTE_POOL_HEAP_TYPE); if (queue_ptr == NULL) { /* Free the already allocated memory for message queue data */ MemFree(queue_start); /* Return NULL pointer in case of error */ return (NULL); }if (queue_ptr == NULL) { ... } }else { ... } /* For threadX the message size is in 32-Bits */ msg_size = msg_size / sizeof(ULONG); /* Call the tx_queue_create function to create the new message queue */ if (tx_queue_create(queue_ptr, name_ptr, msg_size, queue_start, queue_size) != TX_SUCCESS) { /* Check if the memory for message queue control block has been internally allocated *//* ... */ if ((attr->cb_mem == NULL) || (attr == NULL)) { /* Free the already allocated memory for message queue control block */ MemFree(queue_ptr); }if ((attr->cb_mem == NULL) || (attr == NULL)) { ... } /* Check if the memory for message queue data has been internally allocated */ if ((attr->mq_mem == NULL) || (attr == NULL)) { /* Free the already allocated memory for message queue data */ MemFree(queue_start); }if ((attr->mq_mem == NULL) || (attr == NULL)) { ... } /* Return NULL pointer in case of error */ queue_ptr = NULL; }if (tx_queue_create(queue_ptr, name_ptr, msg_size, queue_start, queue_size) != TX_SUCCESS) { ... } }if (!IS_IRQ_MODE() && (msg_count > 0) && (msg_size > 0)) { ... } return ((osMessageQueueId_t)queue_ptr); }{ ... } /** * @brief The function osMessageQueueGetName returns the pointer to the name * string of the message queue identified by parameter mq_id or NULL in * case of an error. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] mq_id message queue ID obtained by osMessageQueueNew. * @retval name_ptr as null-terminated string. *//* ... */ const char *osMessageQueueGetName(osMessageQueueId_t mq_id) { /* For TX_QUEUE the control block pointer is the queue identifier */ TX_QUEUE *queue_ptr = (TX_QUEUE *)mq_id; /* The output name_ptr as null-terminated string */ CHAR *name_ptr = NULL; /* Check if this API is called from Interrupt Service Routines, the mq_id is NULL or mq_id->tx_queue_id != TX_QUEUE_ID *//* ... */ if (IS_IRQ_MODE() || (queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID)) { /* Return NULL in case of an error */ name_ptr = NULL; }if (IS_IRQ_MODE() || (queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID)) { ... } else { /* Call the tx_queue_info_get to get the queue name_ptr */ if (tx_queue_info_get(queue_ptr, &name_ptr, NULL, NULL, NULL, NULL, NULL) != TX_SUCCESS) { /* Return NULL in case of an error */ name_ptr = NULL; }if (tx_queue_info_get(queue_ptr, &name_ptr, NULL, NULL, NULL, NULL, NULL) != TX_SUCCESS) { ... } }else { ... } return (name_ptr); }{ ... } /** * @brief The function osMessageQueueGetCapacity returns the maximum number of * messages in the message queue object specified by parameter mq_id or * 0 in case of an error. * Note : This function may be called from Interrupt Service * Routines. * @param [in] mq_id message queue ID obtained by osMessageQueueNew. * @retval maximum number of messages. *//* ... */ uint32_t osMessageQueueGetCapacity(osMessageQueueId_t mq_id) { /* For TX_QUEUE the control block pointer is the queue identifier */ TX_QUEUE *queue_ptr = (TX_QUEUE *)mq_id; /* The specific maximum number of messages */ uint32_t max_messages_number; /* Check if the mq_id is NULL or queue_ptr->tx_queue_id != TX_QUEUE_ID */ if ((queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID)) { /* Return 0 in case of error */ max_messages_number = 0U; }if ((queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID)) { ... } else { /* Return the total number of messages in the queue */ max_messages_number = queue_ptr->tx_queue_capacity; }else { ... } return (max_messages_number); }{ ... } /** * @brief The function osMessageQueueGetMsgSize returns the maximum message * size in bytes for the message queue object specified by parameter * mq_id or 0 in case of an error. * Note : This function may be called from Interrupt Service * Routines. * @param [in] mq_id message queue ID obtained by osMessageQueueNew. * @retval maximum message size in bytes. *//* ... */ uint32_t osMessageQueueGetMsgSize(osMessageQueueId_t mq_id) { /* For TX_QUEUE the control block pointer is the queue identifier */ TX_QUEUE *queue_ptr = (TX_QUEUE *)mq_id; /* The specific maximum message size in bytes */ uint32_t max_messages_size; /* Check if the mq_id is NULL or queue_ptr->tx_queue_id != TX_QUEUE_ID */ if ((queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID)) { /* Return 0 in case of error */ max_messages_size = 0U; }if ((queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID)) { ... } else { /* Return the message size that was specified in queue creation */ max_messages_size = queue_ptr->tx_queue_message_size * sizeof(ULONG); }else { ... } return (max_messages_size); }{ ... } /** * @brief The function osMessageQueueGetCount returns the number of queued * messages in the message queue object specified by parameter mq_id or * 0 in case of an error. * Note : This function may be called from Interrupt Service * Routines. * @param [in] mq_id message queue ID obtained by osMessageQueueNew. * @retval number of queued messages. *//* ... */ uint32_t osMessageQueueGetCount(osMessageQueueId_t mq_id) { /* For TX_QUEUE the control block pointer is the queue identifier */ TX_QUEUE *queue_ptr = (TX_QUEUE *)mq_id; /* The specific number of queued messages */ uint32_t queued_messages_number = 0U; /* Check if the mq_id is NULL or queue_ptr->tx_queue_id != TX_QUEUE_ID */ if ((queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID)) { /* Return 0 in case of error */ queued_messages_number = 0U; }if ((queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID)) { ... } else { /* Call the tx_queue_info_get to get the number of queued messages */ if (tx_queue_info_get(queue_ptr, NULL, (ULONG *)&queued_messages_number, NULL, NULL, NULL, NULL) != TX_SUCCESS) { /* Return 0 in case of error */ queued_messages_number = 0U; }if (tx_queue_info_get(queue_ptr, NULL, (ULONG *)&queued_messages_number, NULL, NULL, NULL, NULL) != TX_SUCCESS) { ... } }else { ... } return (queued_messages_number); }{ ... } /** * @brief The function osMessageQueueGetSpace returns the number available * slots for messages in the message queue object specified by * parameter mq_id or 0 in case of an error. * Note : This function may be called from Interrupt Service * Routines. * @param [in] mq_id message queue ID obtained by osMessageQueueNew. * @retval number of available slots for messages. *//* ... */ uint32_t osMessageQueueGetSpace(osMessageQueueId_t mq_id) { /* For TX_QUEUE the control block pointer is the queue identifier */ TX_QUEUE *queue_ptr = (TX_QUEUE *)mq_id; /* The specific number of queued messages */ uint32_t queue_messages_free_slots = 0U; /* Check if the mq_id is NULL or queue_ptr->tx_queue_id != TX_QUEUE_ID */ if ((queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID)) { /* Return 0 in case of error */ queue_messages_free_slots = 0U; }if ((queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID)) { ... } else { /* Call the tx_queue_info_get to get the number of available slots for messages *//* ... */ if (tx_queue_info_get(queue_ptr, NULL, NULL, (ULONG *)&queue_messages_free_slots, NULL, NULL, NULL) != TX_SUCCESS) { /* Return 0 in case of error */ queue_messages_free_slots = 0U; }if (tx_queue_info_get(queue_ptr, NULL, NULL, (ULONG *)&queue_messages_free_slots, NULL, NULL, NULL) != TX_SUCCESS) { ... } }else { ... } return (queue_messages_free_slots); }{ ... } /** * @brief The function osMessageQueueReset resets the message queue specified * by the parameter mq_id. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] mq_id message queue ID obtained by osMessageQueueNew. * @retval status code that indicates the execution status of the function. *//* ... */ osStatus_t osMessageQueueReset(osMessageQueueId_t mq_id) { /* For TX_QUEUE the control block pointer is the queue identifier */ TX_QUEUE *queue_ptr = (TX_QUEUE *)mq_id; /* The returned status or error */ osStatus_t status; /* Check if this API is called from Interrupt Service Routines */ if (IS_IRQ_MODE()) { /* Return osErrorISR error */ status = osErrorISR; }if (IS_IRQ_MODE()) { ... } /* Check if the mq_id is NULL or queue_ptr->tx_queue_id != TX_QUEUE_ID */ else if ((queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID)) { /* Return osErrorParameter error */ status = osErrorParameter; }else if ((queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID)) { ... } else { /* Call the tx_queue_flush deletes all messages stored in the specified message queue *//* ... */ if (tx_queue_flush(queue_ptr) == TX_SUCCESS) { /* Return osOK in case of success */ status = osOK; }if (tx_queue_flush(queue_ptr) == TX_SUCCESS) { ... } else { /* Return osErrorResource in case of error */ status = osErrorResource; }else { ... } }else { ... } return (status); }{ ... } /** * @brief The function osMessageQueueDelete deletes a message queue object * specified by parameter mq_id. It releases internal memory obtained * for message queue handling. After this call, the mq_id is no longer * valid and cannot be used. The message queue may be created again * using the function osMessageQueueNew. * Note : This function cannot be called from Interrupt Service * Routines. * @param [in] mq_id message queue ID obtained by osMessageQueueNew. * @retval status code that indicates the execution status of the function. *//* ... */ osStatus_t osMessageQueueDelete(osMessageQueueId_t mq_id) { /* For TX_QUEUE the control block pointer is the queue identifier */ TX_QUEUE *queue_ptr = (TX_QUEUE *)mq_id; /* The returned status or error */ osStatus_t status; /* Check if this API is called from Interrupt Service Routines */ if (IS_IRQ_MODE()) { /* Return osErrorISR error */ status = osErrorISR; }if (IS_IRQ_MODE()) { ... } /* Check if the mq_id is NULL or queue_ptr->tx_queue_id != TX_QUEUE_ID */ else if ((queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID)) { /* Return osErrorParameter error */ status = osErrorParameter; }else if ((queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID)) { ... } else { /* Call the tx_queue_delete deletes the specified message queue */ if (tx_queue_delete(queue_ptr) == TX_SUCCESS) { /* Free the already allocated memory for message queue data */ MemFree(queue_ptr->tx_queue_start); /* Free the already allocated memory for message queue control block */ MemFree(queue_ptr); /* Return osOK in case of success */ status = osOK; }if (tx_queue_delete(queue_ptr) == TX_SUCCESS) { ... } else { /* Return osErrorResource in case of error */ status = osErrorResource; }else { ... } }else { ... } return (status); }{ ... } /** * @brief The blocking function osMessageQueuePut puts the message pointed to * by msg_ptr into the the message queue specified by parameter mq_id. * The parameter msg_prio is used to sort message according their * priority (higher numbers indicate a higher priority) on insertion. * The parameter timeout specifies how long the system waits to put the * message into the queue. While the system waits, the thread that is * calling this function is put into the BLOCKED state. The parameter * timeout can have the following values: * * when timeout is 0, the function returns instantly (i.e. try * semantics). * * when timeout is set to osWaitForever the function will wait for an * infinite time until the message is delivered (i.e. wait semantics). * * all other values specify a time in kernel ticks for a timeout * (i.e. timed-wait semantics). * Note : This function may be called from Interrupt Service * Routines. * @param [in] mq_id message queue ID obtained by osMessageQueueNew. * [in] msg_ptr pointer to buffer with message to put into a queue. * [in] msg_prio message priority. * [in] timeout Timeout Value or 0 in case of no time-out. * @retval status code that indicates the execution status of the function. *//* ... */ osStatus_t osMessageQueuePut(osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout) { /* For TX_QUEUE the control block pointer is the queue identifier */ TX_QUEUE *queue_ptr = (TX_QUEUE *)mq_id; /* The returned value from ThreadX call */ UINT tx_status; /* The returned status or error */ osStatus_t status; /* Check if the mq_id is NULL or queue_ptr->tx_queue_id != TX_QUEUE_ID or non-zero timeout specified in an ISR */ if ((IS_IRQ_MODE() && (timeout != 0)) || (queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID) || (msg_ptr == NULL)) { /* Return osErrorParameter error */ status = osErrorParameter; }if ((IS_IRQ_MODE() && (timeout != 0)) || (queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID) || (msg_ptr == NULL)) { ... } else { /* Call the tx_queue_send to send a message to the specified message queue */ tx_status = tx_queue_send(queue_ptr, (void *)msg_ptr, timeout); if (tx_status == TX_SUCCESS) { /* Return osOK in case of success */ status = osOK; }if (tx_status == TX_SUCCESS) { ... } else if (tx_status == TX_QUEUE_FULL) { /* Return osErrorResource in case of error */ status = osErrorResource; }else if (tx_status == TX_QUEUE_FULL) { ... } else { /* Return osErrorTimeout in case of error */ status = osErrorTimeout; }else { ... } }else { ... } return (status); }{ ... } /** * @brief The function osMessageQueueGet retrieves a message from the message * queue specified by the parameter mq_id and saves it to the buffer pointed * to by the parameter msg_ptr. The message priority is stored to parameter * msg_prio if not token{NULL}. * The parameter timeout specifies how long the system waits to retrieve * the message from the queue. While the system waits, the thread that is * calling this function is put into the BLOCKED state. * The parameter timeout can have the following values: * * when timeout is 0, the function returns instantly (i.e. try * semantics). * * when timeout is set to osWaitForever the function will wait for an * infinite time until the message is delivered (i.e. wait semantics). * * all other values specify a time in kernel ticks for a timeout * (i.e. timed-wait semantics). * Note : This function may be called from Interrupt Service * Routines. * @param [in] mq_id message queue ID obtained by osMessageQueueNew. * [out] msg_ptr pointer to buffer for message to get from a queue. * [out] msg_prio pointer to buffer for message priority or NULL. * [in] timeout Timeout Value or 0 in case of no time-out. * @retval status code that indicates the execution status of the function. *//* ... */ osStatus_t osMessageQueueGet(osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout) { /* For TX_QUEUE the control block pointer is the queue identifier */ TX_QUEUE *queue_ptr = (TX_QUEUE *)mq_id; /* The returned value from ThreadX call */ UINT tx_status; /* The returned status or error */ osStatus_t status; /* Check if the mq_id is NULL or queue_ptr->tx_queue_id != TX_QUEUE_ID or non-zero timeout specified in an ISR */ if ((IS_IRQ_MODE() && (timeout != 0)) || (queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID) || (msg_ptr == NULL)) { /* Return osErrorParameter error */ status = osErrorParameter; }if ((IS_IRQ_MODE() && (timeout != 0)) || (queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID) || (msg_ptr == NULL)) { ... } else { /* Call the tx_queue_receive to retrieves a message from the specified message queue */ tx_status = tx_queue_receive(queue_ptr, msg_ptr, timeout); if (tx_status == TX_SUCCESS) { /* Return osOK in case of success */ status = osOK; }if (tx_status == TX_SUCCESS) { ... } else if (tx_status == TX_QUEUE_EMPTY) { /* Return osErrorTimeout in case of error */ status = osErrorTimeout; }else if (tx_status == TX_QUEUE_EMPTY) { ... } else if (tx_status == TX_WAIT_ERROR) { /* Return osErrorParameter when a non-zero timeout is used in ISR context */ status = osErrorParameter; }else if (tx_status == TX_WAIT_ERROR) { ... } else { /* Return osErrorResource in case of error */ status = osErrorResource; }else { ... } }else { ... } return (status); }{ ... } /*---------------------------------------------------------------------------*/------------------------------Message Queue APIs /*------------------------tx_application_define API--------------------------*/ /*---------------------------------------------------------------------------*/ __WEAK VOID tx_application_define(VOID *first_unused_memory) { /* Empty tx_application_define() */ }{ ... }
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.