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
164
165
166
167
172
173
174
179
184
185
186
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
215
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
251
252
253
254
255
257
263
268
269
270
271
272
273
278
279
281
287
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
345
346
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
381
386
387
388
396
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
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
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
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
573
574
575
576
577
578
579
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
618
619
620
621
622
623
624
625
626
627
628
629
630
635
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
690
691
692
693
694
695
696
697
698
699
704
705
707
712
717
718
719
724
725
726
731
736
741
742
743
753
754
755
760
765
766
767
768
769
770
771
776
781
786
787
788
805
810
811
812
813
814
815
816
817
818
819
820
821
822
823
828
829
830
831
836
837
838
839
840
841
842
843
844
845
846
847
848
849
853
854
855
856
858
863
864
865
870
871
872
873
874
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
911
916
925
926
927
928
929
936
937
938
939
940
941
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
972
973
974
977
978
979
980
981
986
987
988
989
994
995
996
997
998
999
1000
1006
1012
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1034
1040
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
1071
1076
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1104
1109
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
1144
1146
1152
1153
1154
1155
1156
1157
1158
1163
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1190
1195
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1237
1238
1239
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
1278
1279
1284
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
1333
1334
1339
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1378
1379
1380
1381
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
1418
1419
1424
1425
1426
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
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
1481
1482
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
1527
1528
1533
1534
1535
1536
1537
1542
1543
1544
1545
1546
1547
1548
1549
1550
1552
1553
1554
1555
1560
1561
1562
1563
1564
1565
1566
1571
1572
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1624
1628
1629
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1660
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1678
1679
1680
1681
1686
1690
1691
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
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1754
1755
1756
1761
1766
1771
1772
1773
1783
1788
1789
1794
1795
1796
1806
1807
1808
1813
1814
1815
1816
1817
1818
1820
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
1852
1857
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1888
1893
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1930
1931
1936
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
2001
2002
2007
2008
2009
2010
2011
2012
2014
2030
2031
2032
2033
2034
2039
2040
2042
2058
2063
2064
2065
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2096
2097
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
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
2160
2161
2162
2167
2172
2177
2178
2179
2189
2194
2195
2200
2201
2202
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2233
2238
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
2279
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
2327
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2371
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
2421
2422
2423
2427
2431
2432
2433
2434
2439
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
2474
2475
2480
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
2544
2545
2557
2558
2559
2564
2569
2574
2575
2576
2586
2591
2592
2597
2598
2599
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2630
2635
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
2676
2677
2682
2683
2684
2685
2686
2691
2696
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2728
2729
2734
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2774
2775
2780
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2824
2825
2830
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
2898
2899
2900
2905
2910
2915
2916
2917
2927
2932
2933
2938
2939
2940
2941
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2972
2977
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
3019
3020
3021
3022
3023
3028
3034
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
3068
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3110
3111
3116
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
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3197
3198
3199
3205
3210
3215
3220
3221
3222
3232
3233
3234
3239
3244
3245
3246
3247
3248
3249
3250
3255
3260
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3279
3280
3281
3282
3283
3288
3289
3290
3291
3292
3293
3294
3296
3297
3298
3299
3300
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3326
3331
3332
3333
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
3365
3370
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3405
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3436
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3467
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3502
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3537
3538
3543
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3586
3587
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
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
3655
3656
3657
3658
3659
3664
3669
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
3718
3719
3720
3721
3722
3727
3732
3737
3742
3743
3744
3745
3746
3747
3748
/* ... */
/* ... */
/* ... */
#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"
12 includes
#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)
#define RTOS2_DEFAULT_THREAD_STACK_SIZE 1024
#define RTOS2_INTERNAL_BYTE_POOL_SIZE 256
5 defines
#ifndef RTOS2_BYTE_POOL_STACK_SIZE
#define RTOS2_BYTE_POOL_STACK_SIZE 3 * 1024
#endif
#ifndef RTOS2_BYTE_POOL_HEAP_SIZE
#define RTOS2_BYTE_POOL_HEAP_SIZE 4 * 1024
#endif
#ifndef RTOS2_DEFAULT_TIME_SLICE
#define RTOS2_DEFAULT_TIME_SLICE 4
#endif
#define RTOS2_BYTE_POOL_STACK_TYPE 1
#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
#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;
/* ... */
static uint8_t *MemAlloc(uint32_t mem_size, uint8_t pool_type)
{
uint8_t *mem_ptr;
uint32_t allocated_mem_size = mem_size;
TX_BYTE_POOL *byte_pool;
if ((mem_size == 0) || (pool_type > RTOS2_BYTE_POOL_HEAP_TYPE))
{
mem_ptr = NULL;
}if ((mem_size == 0) || (pool_type > RTOS2_BYTE_POOL_HEAP_TYPE)) { ... }
else
{
if (allocated_mem_size < TX_BYTE_POOL_MIN)
{
allocated_mem_size = TX_BYTE_POOL_MIN;
}if (allocated_mem_size < TX_BYTE_POOL_MIN) { ... }
if (pool_type == RTOS2_BYTE_POOL_STACK_TYPE)
{
byte_pool = &StackBytePool;
}if (pool_type == RTOS2_BYTE_POOL_STACK_TYPE) { ... }
else
{
byte_pool = &HeapBytePool;
}else { ... }
if (tx_byte_allocate(byte_pool, (void **) &mem_ptr, allocated_mem_size, TX_NO_WAIT) != TX_SUCCESS)
{
mem_ptr = NULL;
}if (tx_byte_allocate(byte_pool, (void **) &mem_ptr, allocated_mem_size, TX_NO_WAIT) != TX_SUCCESS) { ... }
}else { ... }
return (mem_ptr);
}{ ... }
/* ... */
static osStatus_t MemFree(VOID *memory_ptr)
{
osStatus_t status = osOK;
if (memory_ptr == NULL)
{
status = osError;
}if (memory_ptr == NULL) { ... }
else
{
if (tx_byte_release(memory_ptr) != TX_SUCCESS)
{
status = osError;
}if (tx_byte_release(memory_ptr) != TX_SUCCESS) { ... }
}else { ... }
return (status);
}{ ... }
/* ... */
static osStatus_t MemInit(void)
{
uint32_t bytepool_size = RTOS2_BYTE_POOL_STACK_SIZE;
CHAR *unused_memory = NULL;
if (bytepool_size < TX_BYTE_POOL_MIN)
{
bytepool_size = TX_BYTE_POOL_MIN;
}if (bytepool_size < TX_BYTE_POOL_MIN) { ... }
unused_memory = (CHAR *)_tx_initialize_unused_memory;
/* ... */
if (tx_byte_pool_create(&StackBytePool, "Byte Pool Stack", unused_memory,
RTOS2_INTERNAL_BYTE_POOL_SIZE + bytepool_size) != TX_SUCCESS)
{
return (osError);
}if (tx_byte_pool_create(&StackBytePool, "Byte Pool Stack", unused_memory, RTOS2_INTERNAL_BYTE_POOL_SIZE + bytepool_size) != TX_SUCCESS) { ... }
else
{
unused_memory += RTOS2_INTERNAL_BYTE_POOL_SIZE + bytepool_size;
}else { ... }
bytepool_size = RTOS2_BYTE_POOL_HEAP_SIZE;
if (bytepool_size < TX_BYTE_POOL_MIN)
{
bytepool_size = TX_BYTE_POOL_MIN;
}if (bytepool_size < TX_BYTE_POOL_MIN) { ... }
/* ... */
if (tx_byte_pool_create(&HeapBytePool, "Byte Pool Heap", unused_memory,
RTOS2_INTERNAL_BYTE_POOL_SIZE + bytepool_size) != TX_SUCCESS)
{
return (osError);
}if (tx_byte_pool_create(&HeapBytePool, "Byte Pool Heap", unused_memory, RTOS2_INTERNAL_BYTE_POOL_SIZE + bytepool_size) != TX_SUCCESS) { ... }
else
{
unused_memory += RTOS2_INTERNAL_BYTE_POOL_SIZE + bytepool_size;
}else { ... }
_tx_initialize_unused_memory = unused_memory;
return (osOK);
}{ ... }
-------------------CMSIS RTOS2 Internal Functions
/* ... */
osStatus_t osKernelInitialize(void)
{
osStatus_t status;
if (IS_IRQ_MODE())
{
status = osErrorISR;
}if (IS_IRQ_MODE()) { ... }
else
{
if (KernelState == osKernelInactive)
{
_tx_initialize_kernel_setup();
if (MemInit() == osOK)
{
KernelState = osKernelReady;
status = osOK;
}if (MemInit() == osOK) { ... }
else
{
status = osError;
}else { ... }
}if (KernelState == osKernelInactive) { ... }
else
{
status = osError;
}else { ... }
}else { ... }
return (status);
}{ ... }
/* ... */
osStatus_t osKernelGetInfo(osVersion_t *version, char *id_buf, uint32_t id_size)
{
osStatus_t status = osOK;
if (version != NULL)
{
version->api = KERNEL_VERSION;
version->kernel = KERNEL_VERSION;
}if (version != NULL) { ... }
else
{
status = osError;
}else { ... }
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
{
status = osError;
}else { ... }
return (status);
}{ ... }
/* ... */
osKernelState_t osKernelGetState(void)
{
return (KernelState);
}{ ... }
/* ... */
osStatus_t osKernelStart(void)
{
osStatus_t status;
if (IS_IRQ_MODE())
{
status = osErrorISR;
}if (IS_IRQ_MODE()) { ... }
else
{
if (KernelState == osKernelReady)
{
KernelState = osKernelRunning;
status = osOK;
tx_kernel_enter();
}if (KernelState == osKernelReady) { ... }
else
{
status = osError;
}else { ... }
}else { ... }
return (status);
}{ ... }
/* ... */
uint32_t osKernelGetTickCount(void)
{
uint32_t ticks;
ticks = (uint32_t)tx_time_get();
return (ticks);
}{ ... }
/* ... */
uint32_t osKernelGetTickFreq(void)
{
return (TX_TIMER_TICKS_PER_SECOND);
}{ ... }
/* ... */
uint32_t osKernelGetSysTimerCount(void)
{
uint32_t ticks;
uint32_t val;
ticks = (uint32_t)tx_time_get();
val = (uint32_t)(ticks * (SystemCoreClock / TX_TIMER_TICKS_PER_SECOND));
return (val);
}{ ... }
/* ... */
uint32_t osKernelGetSysTimerFreq(void)
{
return (SystemCoreClock);
}{ ... }
---------------------------Kenel Management APIs
/* ... */
osStatus_t osDelay(uint32_t ticks)
{
osStatus_t status;
if (IS_IRQ_MODE())
{
status = osErrorISR;
}if (IS_IRQ_MODE()) { ... }
else
{
status = osOK;
if (ticks != 0U)
{
tx_thread_sleep(ticks);
}if (ticks != 0U) { ... }
}else { ... }
return (status);
}{ ... }
/* ... */
osStatus_t osDelayUntil(uint32_t ticks)
{
uint32_t tcnt, delay;
osStatus_t status;
if (IS_IRQ_MODE())
{
status = osErrorISR;
}if (IS_IRQ_MODE()) { ... }
else
{
status = osOK;
tcnt = (uint32_t)tx_time_get();
delay = ticks - tcnt;
if ((delay != 0U) && (0 == (delay >> (8 * sizeof(uint32_t) - 1))))
{
tx_thread_sleep(delay);
}if ((delay != 0U) && (0 == (delay >> (8 * sizeof(uint32_t) - 1)))) { ... }
else
{
status = osErrorParameter;
}else { ... }
}else { ... }
return (status);
}{ ... }
-----------------------------Generic Wait APIs
/* ... */
osThreadId_t osThreadNew(osThreadFunc_t func, void *argument, const osThreadAttr_t *attr)
{
TX_THREAD *thread_ptr = NULL;
CHAR *name_ptr = NULL;
VOID *stack_start;
ULONG stack_size;
ULONG cb_size;
UINT priority;
ULONG entry_input = 0;
/* ... */
if (!IS_IRQ_MODE() && (func != NULL))
{
name_ptr = NULL;
if (attr != NULL)
{
if (attr->name != NULL)
{
name_ptr = (CHAR *)attr->name;
}if (attr->name != NULL) { ... }
/* ... */
if ((attr->priority < osPriorityIdle) || (attr->priority > osPriorityISR))
{
return (NULL);
}if ((attr->priority < osPriorityIdle) || (attr->priority > osPriorityISR)) { ... }
else
{
priority = osPriorityISR - attr->priority;
}else { ... }
if (argument != NULL)
{
entry_input = (ULONG) argument;
}if (argument != NULL) { ... }
if (attr->stack_size == 0U)
{
stack_size = RTOS2_DEFAULT_THREAD_STACK_SIZE;
}if (attr->stack_size == 0U) { ... }
else if (attr->stack_size < TX_BYTE_POOL_MIN)
{
stack_size = TX_BYTE_POOL_MIN;
}else if (attr->stack_size < TX_BYTE_POOL_MIN) { ... }
else
{
stack_size = (ULONG)attr->stack_size;
}else { ... }
if (attr->stack_mem == NULL)
{
stack_start = MemAlloc(stack_size, RTOS2_BYTE_POOL_STACK_TYPE);
if (stack_start == NULL)
{
return (NULL);
}if (stack_start == NULL) { ... }
}if (attr->stack_mem == NULL) { ... }
else
{
if (attr->stack_size == 0U)
{
return (NULL);
}if (attr->stack_size == 0U) { ... }
else
{
stack_size = (ULONG)attr->stack_size;
}else { ... }
stack_start = attr->stack_mem;
}else { ... }
if (attr->cb_size == 0U)
{
cb_size = sizeof(TX_THREAD);
}if (attr->cb_size == 0U) { ... }
else if (attr->cb_size < sizeof(TX_THREAD))
{
return (NULL);
}else if (attr->cb_size < sizeof(TX_THREAD)) { ... }
else
{
cb_size = (ULONG)attr->cb_size;
}else { ... }
if (attr->cb_mem == NULL)
{
thread_ptr = (TX_THREAD *)MemAlloc(cb_size, RTOS2_BYTE_POOL_HEAP_TYPE);
if (thread_ptr == NULL)
{
/* ... */
if (attr->stack_mem == NULL)
{
MemFree(stack_start);
}if (attr->stack_mem == NULL) { ... }
return (NULL);
}if (thread_ptr == NULL) { ... }
}if (attr->cb_mem == NULL) { ... }
else
{
thread_ptr = attr->cb_mem;
}else { ... }
}if (attr != NULL) { ... }
else
{
priority = osPriorityISR - osPriorityNormal;
name_ptr = NULL;
stack_size = RTOS2_DEFAULT_THREAD_STACK_SIZE;
if (argument != NULL)
{
entry_input = (ULONG) argument;
}if (argument != NULL) { ... }
stack_start = MemAlloc(stack_size, RTOS2_BYTE_POOL_STACK_TYPE);
if (stack_start == NULL)
{
return (NULL);
}if (stack_start == NULL) { ... }
thread_ptr = (TX_THREAD *)MemAlloc(sizeof(TX_THREAD), RTOS2_BYTE_POOL_HEAP_TYPE);
if (thread_ptr == NULL)
{
MemFree(stack_start);
return (NULL);
}if (thread_ptr == NULL) { ... }
}else { ... }
/* ... */
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)
{
/* ... */
if ((attr->cb_mem == NULL) || (attr == NULL))
{
MemFree(thread_ptr);
}if ((attr->cb_mem == NULL) || (attr == NULL)) { ... }
if ((attr->stack_mem == NULL) || (attr == NULL))
{
MemFree(stack_start);
}if ((attr->stack_mem == NULL) || (attr == NULL)) { ... }
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
{
if ((attr != NULL) && (attr->attr_bits == osThreadJoinable))
{
thread_ptr->tx_thread_detached_joinable = osThreadJoinable;
}if ((attr != NULL) && (attr->attr_bits == osThreadJoinable)) { ... }
else
{
thread_ptr->tx_thread_detached_joinable = osThreadDetached;
}else { ... }
}else { ... }
}if (!IS_IRQ_MODE() && (func != NULL)) { ... }
return ((osThreadId_t)thread_ptr);
}{ ... }
/* ... */
const char *osThreadGetName(osThreadId_t thread_id)
{
TX_THREAD *thread_ptr = (TX_THREAD *)thread_id;
CHAR *name_ptr = NULL;
/* ... */
if (IS_IRQ_MODE() || (thread_ptr == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID))
{
name_ptr = NULL;
}if (IS_IRQ_MODE() || (thread_ptr == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID)) { ... }
else
{
if (tx_thread_info_get(thread_ptr, &name_ptr, NULL, NULL, NULL, NULL, NULL, NULL, NULL) != TX_SUCCESS)
{
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);
}{ ... }
/* ... */
osThreadId_t osThreadGetId(void)
{
osThreadId_t thread_id;
/* ... */
thread_id = (osThreadId_t)tx_thread_identify();
return (thread_id);
}{ ... }
/* ... */
osThreadState_t osThreadGetState(osThreadId_t thread_id)
{
TX_THREAD *thread_ptr = (TX_THREAD *)thread_id;
TX_THREAD *current_thread = NULL;
osThreadState_t state;
UINT threadx_state;
/* ... */
if (IS_IRQ_MODE() || (thread_ptr == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID))
{
state = osThreadError;
...}
else
{
TX_THREAD_GET_CURRENT(current_thread);
if (current_thread == thread_id)
{
state = osThreadRunning;
}if (current_thread == thread_id) { ... }
else
{
if (tx_thread_info_get(thread_ptr, NULL, &threadx_state, NULL, NULL, NULL, NULL, NULL, NULL) != TX_SUCCESS)
{
state = osThreadError;
}if (tx_thread_info_get(thread_ptr, NULL, &threadx_state, NULL, NULL, NULL, NULL, NULL, NULL) != TX_SUCCESS) { ... }
else
{
switch (threadx_state)
{
case TX_READY:
{
state = osThreadReady;
break;
...}
case TX_READY:
case TX_COMPLETED:
{
state = osThreadTerminated;
break;
...}
case TX_COMPLETED:
case TX_TERMINATED:
{
state = osThreadTerminated;
break;
...}
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;
...}
case TX_PRIORITY_CHANGE:
case TX_SLEEP:
{
state = osThreadBlocked;
break;
...}
case TX_SLEEP:
default:
{
state = osThreadError;
break;
...}default
}switch (threadx_state) { ... }
}else { ... }
}else { ... }
}else { ... }
return (state);
}{ ... }
/* ... */
uint32_t osThreadGetStackSize(osThreadId_t thread_id)
{
TX_THREAD *thread_ptr = (TX_THREAD *)thread_id;
unsigned int stack_size;
/* ... */
if (IS_IRQ_MODE() || (thread_ptr == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID))
{
stack_size = 0U;
}if (IS_IRQ_MODE() || (thread_ptr == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID)) { ... }
else
{
stack_size = thread_ptr->tx_thread_stack_size;
}else { ... }
return (stack_size);
}{ ... }
/* ... */
uint32_t osThreadGetStackSpace(osThreadId_t thread_id)
{
TX_THREAD *thread_ptr = (TX_THREAD *)thread_id;
uint32_t remaining_stack_space;
/* ... */
if (IS_IRQ_MODE() || (thread_ptr == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID))
{
remaining_stack_space = 0U;
}if (IS_IRQ_MODE() || (thread_ptr == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID)) { ... }
else
{
remaining_stack_space = (unsigned int)((CHAR *)thread_ptr->tx_thread_stack_ptr -
(CHAR *)thread_ptr->tx_thread_stack_start);
}else { ... }
return (remaining_stack_space);
}{ ... }
/* ... */
osStatus_t osThreadSetPriority(osThreadId_t thread_id, osPriority_t priority)
{
TX_THREAD *thread_ptr = (TX_THREAD *)thread_id;
UINT old_priority;
osStatus_t status;
if (IS_IRQ_MODE())
{
status = osErrorISR;
}if (IS_IRQ_MODE()) { ... }
/* ... */
else if ((thread_ptr == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID) || (priority < osPriorityIdle)
|| (priority > osPriorityISR))
{
status = osErrorParameter;
}else if ((thread_ptr == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID) || (priority < osPriorityIdle) || (priority > osPriorityISR)) { ... }
else
{
priority = (osPriority_t)(osPriorityISR - priority);
if (tx_thread_priority_change(thread_ptr, priority, &old_priority) == TX_SUCCESS)
{
status = osOK;
}if (tx_thread_priority_change(thread_ptr, priority, &old_priority) == TX_SUCCESS) { ... }
else
{
status = osErrorResource;
}else { ... }
}else { ... }
return (status);
}{ ... }
/* ... */
osPriority_t osThreadGetPriority(osThreadId_t thread_id)
{
TX_THREAD *thread_ptr = (TX_THREAD *)thread_id;
osPriority_t priority;
/* ... */
if (IS_IRQ_MODE() || (thread_ptr == NULL))
{
priority = osPriorityError;
}if (IS_IRQ_MODE() || (thread_ptr == NULL)) { ... }
else
{
if (tx_thread_info_get(thread_ptr, NULL, NULL, NULL, (UINT *)&priority, NULL, NULL, NULL, NULL) != TX_SUCCESS)
{
priority = osPriorityError;
}if (tx_thread_info_get(thread_ptr, NULL, NULL, NULL, (UINT *)&priority, NULL, NULL, NULL, NULL) != TX_SUCCESS) { ... }
else
{
priority = (osPriority_t)(osPriorityISR - priority);
}else { ... }
}else { ... }
return (priority);
}{ ... }
/* ... */
osStatus_t osThreadYield(void)
{
osStatus_t status;
if (IS_IRQ_MODE())
{
status = osErrorISR;
}if (IS_IRQ_MODE()) { ... }
else
{
/* ... */
tx_thread_relinquish();
status = osOK;
}else { ... }
return (status);
}{ ... }
/* ... */
osStatus_t osThreadSuspend(osThreadId_t thread_id)
{
TX_THREAD *thread_ptr = (TX_THREAD *)thread_id;
osStatus_t status;
if (IS_IRQ_MODE())
{
status = osErrorISR;
}if (IS_IRQ_MODE()) { ... }
else if ((thread_id == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID))
{
status = osErrorParameter;
}else if ((thread_id == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID)) { ... }
else
{
/* ... */
if (tx_thread_suspend(thread_ptr) == TX_SUCCESS)
{
status = osOK;
}if (tx_thread_suspend(thread_ptr) == TX_SUCCESS) { ... }
else
{
status = osErrorResource;
}else { ... }
}else { ... }
return (status);
}{ ... }
/* ... */
osStatus_t osThreadResume(osThreadId_t thread_id)
{
TX_THREAD *thread_ptr = (TX_THREAD *)thread_id;
osStatus_t status;
if (IS_IRQ_MODE())
{
status = osErrorISR;
}if (IS_IRQ_MODE()) { ... }
else if ((thread_id == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID))
{
status = osErrorParameter;
}else if ((thread_id == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID)) { ... }
else
{
/* ... */
if (tx_thread_resume(thread_ptr) == TX_SUCCESS)
{
status = osOK;
}if (tx_thread_resume(thread_ptr) == TX_SUCCESS) { ... }
else
{
status = osErrorResource;
}else { ... }
}else { ... }
return (status);
}{ ... }
/* ... */
__NO_RETURN void osThreadExit(void)
{
TX_THREAD *thread_ptr = NULL;
if (!IS_IRQ_MODE())
{
/* ... */
thread_ptr = tx_thread_identify();
if (thread_ptr != NULL)
{
/* ... */
tx_thread_terminate(thread_ptr);
}if (thread_ptr != NULL) { ... }
}if (!IS_IRQ_MODE()) { ... }
for (;;);
}{ ... }
/* ... */
osStatus_t osThreadTerminate(osThreadId_t thread_id)
{
TX_THREAD *thread_ptr = (TX_THREAD *)thread_id;
osStatus_t status;
if (IS_IRQ_MODE())
{
status = osErrorISR;
}if (IS_IRQ_MODE()) { ... }
else if ((thread_id == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID))
{
status = osErrorParameter;
}else if ((thread_id == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID)) { ... }
else
{
/* ... */
if (tx_thread_terminate(thread_ptr) == TX_SUCCESS)
{
if (thread_ptr->tx_thread_detached_joinable == osThreadDetached)
{
tx_thread_delete(thread_ptr);
MemFree(thread_ptr->tx_thread_stack_start);
MemFree(thread_ptr);
}if (thread_ptr->tx_thread_detached_joinable == osThreadDetached) { ... }
status = osOK;
}if (tx_thread_terminate(thread_ptr) == TX_SUCCESS) { ... }
else
{
status = osErrorResource;
}else { ... }
}else { ... }
return (status);
}{ ... }
/* ... */
osStatus_t osThreadDetach(osThreadId_t thread_id)
{
TX_THREAD *thread_ptr = (TX_THREAD *)thread_id;
osStatus_t status;
if (IS_IRQ_MODE())
{
status = osErrorISR;
}if (IS_IRQ_MODE()) { ... }
else if ((thread_id == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID))
{
status = osErrorParameter;
}else if ((thread_id == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID)) { ... }
else
{
thread_ptr->tx_thread_detached_joinable = osThreadDetached;
status = osOK;
}else { ... }
return (status);
}{ ... }
/* ... */
osStatus_t osThreadJoin(osThreadId_t thread_id)
{
TX_THREAD *thread_ptr = (TX_THREAD *)thread_id;
TX_THREAD *current_thread = NULL;
UINT threadx_state;
osStatus_t status;
if (IS_IRQ_MODE())
{
status = osErrorISR;
}if (IS_IRQ_MODE()) { ... }
else if ((thread_id == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID))
{
status = osErrorParameter;
}else if ((thread_id == NULL) || (thread_ptr->tx_thread_id != TX_THREAD_ID)) { ... }
else
{
TX_THREAD_GET_CURRENT(current_thread);
if (current_thread == thread_id)
{
status = osErrorParameter;
}if (current_thread == thread_id) { ... }
else
{
if (tx_thread_info_get(thread_ptr, NULL, &threadx_state, NULL, NULL, NULL, NULL, NULL, NULL) == TX_SUCCESS)
{
if (thread_ptr->tx_thread_detached_joinable == osThreadJoinable)
{
/* ... */
thread_ptr->tx_thread_detached_joinable = osThreadDetached;
while ((threadx_state != TX_TERMINATED) && (threadx_state != TX_COMPLETED))
{
tx_thread_info_get(thread_ptr, NULL, &threadx_state, NULL, NULL, NULL, NULL, NULL, NULL);
}while ((threadx_state != TX_TERMINATED) && (threadx_state != TX_COMPLETED)) { ... }
thread_ptr->tx_thread_detached_joinable = osThreadJoinable;
status = osOK;
}if (thread_ptr->tx_thread_detached_joinable == osThreadJoinable) { ... }
else
{
status = osErrorResource;
}else { ... }
}if (tx_thread_info_get(thread_ptr, NULL, &threadx_state, NULL, NULL, NULL, NULL, NULL, NULL) == TX_SUCCESS) { ... }
else
{
status = osErrorResource;
}else { ... }
}else { ... }
}else { ... }
return (status);
}{ ... }
/* ... */
uint32_t osThreadGetCount(void)
{
TX_THREAD *thread_ptr = NULL;
unsigned int count = 0U;
if (IS_IRQ_MODE())
{
count = 0;
}if (IS_IRQ_MODE()) { ... }
else
{
thread_ptr = _tx_thread_created_ptr;
while (thread_ptr != NULL)
{
if (thread_ptr->tx_thread_id == TX_THREAD_ID)
{
count++;
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
{
count = 0;
break;
}else { ... }
}while (thread_ptr != NULL) { ... }
}else { ... }
return (count);
}{ ... }
/* ... */
uint32_t osThreadEnumerate(osThreadId_t *thread_array, uint32_t array_items)
{
TX_THREAD *thread_ptr = NULL;
uint32_t count = 0U;
/* ... */
if (IS_IRQ_MODE() || (thread_array == NULL) || (array_items == 0U))
{
count = 0U;
}if (IS_IRQ_MODE() || (thread_array == NULL) || (array_items == 0U)) { ... }
else
{
thread_ptr = _tx_thread_created_ptr;
while ((thread_ptr != NULL) && (count < array_items))
{
if (thread_ptr->tx_thread_id == TX_THREAD_ID)
{
/* ... */
thread_array[count++] = thread_ptr;
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
{
count = 0;
break;
}else { ... }
}while ((thread_ptr != NULL) && (count < array_items)) { ... }
}else { ... }
return (count);
}{ ... }
--------------------------Thread Management APIs
/* ... */
osTimerId_t osTimerNew(osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr)
{
TX_TIMER *timer_ptr = NULL;
CHAR *name_ptr = NULL;
ULONG expiration_input = 0U;
ULONG reschedule_ticks = 0U;
ULONG cb_size = sizeof(TX_TIMER);
/* ... */
if (!IS_IRQ_MODE() && (func != NULL) && (type <= osTimerPeriodic))
{
name_ptr = NULL;
if (attr != NULL)
{
if (attr->name != NULL)
{
name_ptr = (CHAR *)attr->name;
}if (attr->name != NULL) { ... }
if (attr->cb_size == 0U)
{
cb_size = sizeof(TX_TIMER);
}if (attr->cb_size == 0U) { ... }
else if (attr->cb_size < sizeof(TX_TIMER))
{
return (NULL);
}else if (attr->cb_size < sizeof(TX_TIMER)) { ... }
else
{
cb_size = (ULONG) attr->cb_size;
}else { ... }
if (attr->cb_mem == NULL)
{
timer_ptr = (TX_TIMER *)MemAlloc(cb_size, RTOS2_BYTE_POOL_HEAP_TYPE);
if (timer_ptr == NULL)
{
return (NULL);
}if (timer_ptr == NULL) { ... }
}if (attr->cb_mem == NULL) { ... }
else
{
timer_ptr = attr->cb_mem;
}else { ... }
}if (attr != NULL) { ... }
else
{
timer_ptr = (TX_TIMER *)MemAlloc(cb_size, RTOS2_BYTE_POOL_HEAP_TYPE);
}else { ... }
if (type == osTimerPeriodic)
{
/* ... */
reschedule_ticks = 1;
}if (type == osTimerPeriodic) { ... }
if (argument != NULL)
{
expiration_input = (ULONG)argument;
}if (argument != NULL) { ... }
if (tx_timer_create(timer_ptr, name_ptr, (void(*)(ULONG))func, expiration_input, 1, reschedule_ticks,
TX_NO_ACTIVATE) != TX_SUCCESS)
{
/* ... */
if ((attr->cb_mem == NULL) || (attr == NULL))
{
MemFree(timer_ptr);
}if ((attr->cb_mem == NULL) || (attr == NULL)) { ... }
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);
}{ ... }
/* ... */
const char *osTimerGetName(osTimerId_t timer_id)
{
TX_TIMER *timer_ptr = (TX_TIMER *)timer_id;
CHAR *name_ptr;
/* ... */
if (IS_IRQ_MODE() || (timer_ptr == NULL))
{
name_ptr = NULL;
}if (IS_IRQ_MODE() || (timer_ptr == NULL)) { ... }
else
{
if (tx_timer_info_get(timer_ptr, &name_ptr, NULL, NULL, NULL, NULL) != TX_SUCCESS)
{
name_ptr = NULL;
}if (tx_timer_info_get(timer_ptr, &name_ptr, NULL, NULL, NULL, NULL) != TX_SUCCESS) { ... }
}else { ... }
return ((const char *)name_ptr);
}{ ... }
/* ... */
uint32_t osTimerIsRunning(osTimerId_t timer_id)
{
TX_TIMER *timer_ptr = (TX_TIMER *)timer_id;
UINT active;
/* ... */
if (IS_IRQ_MODE() || (timer_id == NULL))
{
active = 0U;
}if (IS_IRQ_MODE() || (timer_id == NULL)) { ... }
else
{
/* ... */
if (tx_timer_info_get(timer_ptr, NULL, &active, NULL, NULL, NULL) != TX_SUCCESS)
{
active = 0U;
}if (tx_timer_info_get(timer_ptr, NULL, &active, NULL, NULL, NULL) != TX_SUCCESS) { ... }
}else { ... }
return ((uint32_t)active);
}{ ... }
/* ... */
osStatus_t osTimerStop(osTimerId_t timer_id)
{
TX_TIMER *timer_ptr = (TX_TIMER *)timer_id;
osStatus_t status;
UINT active;
if (IS_IRQ_MODE())
{
status = osErrorISR;
}if (IS_IRQ_MODE()) { ... }
else if ((timer_id == NULL) || (timer_ptr->tx_timer_id != TX_TIMER_ID))
{
status = osErrorParameter;
}else if ((timer_id == NULL) || (timer_ptr->tx_timer_id != TX_TIMER_ID)) { ... }
else
{
if (tx_timer_info_get(timer_ptr, NULL, &active, NULL, NULL, NULL) == TX_SUCCESS)
{
if (active == TX_TRUE)
{
/* ... */
if (tx_timer_deactivate(timer_ptr) == TX_SUCCESS)
{
status = osOK;
}if (tx_timer_deactivate(timer_ptr) == TX_SUCCESS) { ... }
else
{
status = osErrorResource;
}else { ... }
}if (active == TX_TRUE) { ... }
else
{
status = osErrorResource;
}else { ... }
}if (tx_timer_info_get(timer_ptr, NULL, &active, NULL, NULL, NULL) == TX_SUCCESS) { ... }
else
{
status = osErrorResource;
}else { ... }
}else { ... }
return (status);
}{ ... }
/* ... */
osStatus_t osTimerStart(osTimerId_t timer_id, uint32_t ticks)
{
TX_TIMER *timer_ptr = (TX_TIMER *)timer_id;
osStatus_t status = osOK;
UINT active;
ULONG reschedule_ticks;
if (IS_IRQ_MODE())
{
status = osErrorISR;
}if (IS_IRQ_MODE()) { ... }
else if ((timer_id == NULL) || (timer_ptr->tx_timer_id != TX_TIMER_ID))
{
status = osErrorParameter;
}else if ((timer_id == NULL) || (timer_ptr->tx_timer_id != TX_TIMER_ID)) { ... }
else
{
if (tx_timer_info_get(timer_ptr, NULL, &active, NULL, &reschedule_ticks, NULL) == TX_SUCCESS)
{
/* ... */
if (active == TX_TRUE)
{
/* ... */
if (tx_timer_deactivate(timer_ptr) == TX_SUCCESS)
{
status = osOK;
}if (tx_timer_deactivate(timer_ptr) == TX_SUCCESS) { ... }
else
{
status = osErrorResource;
}else { ... }
}if (active == TX_TRUE) { ... }
if (status == osOK)
{
if (reschedule_ticks > 0)
{
reschedule_ticks = ticks;
}if (reschedule_ticks > 0) { ... }
/* ... */
if (tx_timer_change(timer_ptr, ticks, reschedule_ticks) == TX_SUCCESS)
{
/* ... */
if (tx_timer_activate(timer_ptr) == TX_SUCCESS)
{
status = osOK;
}if (tx_timer_activate(timer_ptr) == TX_SUCCESS) { ... }
else
{
status = osErrorResource;
}else { ... }
}if (tx_timer_change(timer_ptr, ticks, reschedule_ticks) == TX_SUCCESS) { ... }
else
{
status = osErrorResource;
}else { ... }
}if (status == osOK) { ... }
}if (tx_timer_info_get(timer_ptr, NULL, &active, NULL, &reschedule_ticks, NULL) == TX_SUCCESS) { ... }
else
{
status = osErrorResource;
}else { ... }
}else { ... }
return (status);
}{ ... }
/* ... */
osStatus_t osTimerDelete(osTimerId_t timer_id)
{
TX_TIMER *timer_ptr = (TX_TIMER *)timer_id;
osStatus_t status;
if (IS_IRQ_MODE())
{
status = osErrorISR;
}if (IS_IRQ_MODE()) { ... }
else if ((timer_id == NULL) || (timer_ptr->tx_timer_id != TX_TIMER_ID))
{
status = osErrorParameter;
}else if ((timer_id == NULL) || (timer_ptr->tx_timer_id != TX_TIMER_ID)) { ... }
else
{
if (tx_timer_delete(timer_ptr) == TX_SUCCESS)
{
MemFree(timer_ptr);
status = osOK;
}if (tx_timer_delete(timer_ptr) == TX_SUCCESS) { ... }
else
{
status = osErrorResource;
}else { ... }
}else { ... }
return (status);
}{ ... }
---------------------------Timer Management APIs
/* ... */
osEventFlagsId_t osEventFlagsNew(const osEventFlagsAttr_t *attr)
{
TX_EVENT_FLAGS_GROUP *eventflags_ptr = NULL;
CHAR *name_ptr = NULL;
ULONG cb_size = sizeof(TX_EVENT_FLAGS_GROUP);
if (!IS_IRQ_MODE())
{
if (attr != NULL)
{
if (attr->name != NULL)
{
name_ptr = (CHAR *)attr->name;
}if (attr->name != NULL) { ... }
if (attr->cb_size == 0U)
{
cb_size = sizeof(TX_EVENT_FLAGS_GROUP);
}if (attr->cb_size == 0U) { ... }
else if (attr->cb_size < sizeof(TX_EVENT_FLAGS_GROUP))
{
return (NULL);
}else if (attr->cb_size < sizeof(TX_EVENT_FLAGS_GROUP)) { ... }
else
{
cb_size = (ULONG) attr->cb_size;
}else { ... }
if (attr->cb_mem == NULL)
{
eventflags_ptr = (TX_EVENT_FLAGS_GROUP *)MemAlloc(cb_size, RTOS2_BYTE_POOL_HEAP_TYPE);
if (eventflags_ptr == NULL)
{
return (NULL);
}if (eventflags_ptr == NULL) { ... }
}if (attr->cb_mem == NULL) { ... }
else
{
eventflags_ptr = attr->cb_mem;
}else { ... }
}if (attr != NULL) { ... }
else
{
eventflags_ptr = (TX_EVENT_FLAGS_GROUP *)MemAlloc(cb_size, RTOS2_BYTE_POOL_HEAP_TYPE);
}else { ... }
if (tx_event_flags_create(eventflags_ptr, name_ptr) != TX_SUCCESS)
{
if ((attr->cb_mem == NULL) || (attr == NULL))
{
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);
}{ ... }
/* ... */
const char *osEventFlagsGetName(osEventFlagsId_t ef_id)
{
TX_EVENT_FLAGS_GROUP *eventflags_ptr = (TX_EVENT_FLAGS_GROUP *)ef_id;
CHAR *name_ptr;
/* ... */
if (IS_IRQ_MODE() || (eventflags_ptr == NULL))
{
name_ptr = NULL;
}if (IS_IRQ_MODE() || (eventflags_ptr == NULL)) { ... }
else
{
if (tx_event_flags_info_get(eventflags_ptr, &name_ptr, NULL, NULL, NULL, NULL) != TX_SUCCESS)
{
name_ptr = NULL;
}if (tx_event_flags_info_get(eventflags_ptr, &name_ptr, NULL, NULL, NULL, NULL) != TX_SUCCESS) { ... }
}else { ... }
return (name_ptr);
}{ ... }
/* ... */
uint32_t osEventFlagsSet(osEventFlagsId_t ef_id, uint32_t flags)
{
TX_EVENT_FLAGS_GROUP *eventflags_ptr = (TX_EVENT_FLAGS_GROUP *)ef_id;
uint32_t flags_status;
ULONG flags_to_set = (ULONG) flags;
if ((ef_id == NULL) || (eventflags_ptr -> tx_event_flags_group_id != TX_EVENT_FLAGS_ID))
{
flags_status = osFlagsErrorParameter;
}if ((ef_id == NULL) || (eventflags_ptr -> tx_event_flags_group_id != TX_EVENT_FLAGS_ID)) { ... }
else
{
if (tx_event_flags_set(eventflags_ptr, flags_to_set, TX_OR) == TX_SUCCESS)
{
if (tx_event_flags_info_get(eventflags_ptr, NULL, (ULONG *) &flags_status, NULL, NULL, NULL) != TX_SUCCESS)
{
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
{
flags_status = osFlagsErrorResource;
}else { ... }
}else { ... }
return (flags_status);
}{ ... }
/* ... */
uint32_t osEventFlagsClear(osEventFlagsId_t ef_id, uint32_t flags)
{
TX_EVENT_FLAGS_GROUP *eventflags_ptr = (TX_EVENT_FLAGS_GROUP *)ef_id;
uint32_t flags_status;
ULONG flags_to_clear = (ULONG) ~flags;
if ((ef_id == NULL) || (eventflags_ptr -> tx_event_flags_group_id != TX_EVENT_FLAGS_ID))
{
flags_status = osFlagsErrorParameter;
}if ((ef_id == NULL) || (eventflags_ptr -> tx_event_flags_group_id != TX_EVENT_FLAGS_ID)) { ... }
else
{
if (tx_event_flags_info_get(eventflags_ptr, NULL, (ULONG *) &flags_status, NULL, NULL, NULL) != TX_SUCCESS)
{
flags_status = osFlagsErrorUnknown;
}if (tx_event_flags_info_get(eventflags_ptr, NULL, (ULONG *) &flags_status, NULL, NULL, NULL) != TX_SUCCESS) { ... }
else
{
if (tx_event_flags_set(eventflags_ptr, flags_to_clear, TX_AND) != TX_SUCCESS)
{
flags_status = osFlagsErrorResource;
}if (tx_event_flags_set(eventflags_ptr, flags_to_clear, TX_AND) != TX_SUCCESS) { ... }
}else { ... }
}else { ... }
return (flags_status);
}{ ... }
/* ... */
uint32_t osEventFlagsGet(osEventFlagsId_t ef_id)
{
TX_EVENT_FLAGS_GROUP *eventflags_ptr = (TX_EVENT_FLAGS_GROUP *)ef_id;
uint32_t current_flags = 0;
if ((ef_id == NULL) || (eventflags_ptr -> tx_event_flags_group_id != TX_EVENT_FLAGS_ID))
{
current_flags = 0;
}if ((ef_id == NULL) || (eventflags_ptr -> tx_event_flags_group_id != TX_EVENT_FLAGS_ID)) { ... }
else
{
if (tx_event_flags_info_get(eventflags_ptr, NULL, (ULONG *) ¤t_flags, NULL, NULL, NULL) != TX_SUCCESS)
{
current_flags = 0;
}if (tx_event_flags_info_get(eventflags_ptr, NULL, (ULONG *) ¤t_flags, NULL, NULL, NULL) != TX_SUCCESS) { ... }
}else { ... }
return (current_flags);
}{ ... }
/* ... */
uint32_t osEventFlagsWait(osEventFlagsId_t ef_id, uint32_t flags,
uint32_t options, uint32_t timeout)
{
TX_EVENT_FLAGS_GROUP *eventflags_ptr = (TX_EVENT_FLAGS_GROUP *)ef_id;
ULONG requested_flags = (ULONG) flags;
ULONG wait_option = (ULONG) timeout;
UINT get_option = 0;
ULONG actual_flags = 0;
UINT status;
if ((IS_IRQ_MODE() && (timeout != 0)) || (ef_id == NULL) ||
(eventflags_ptr -> tx_event_flags_group_id != TX_EVENT_FLAGS_ID))
{
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 { ... }
status = tx_event_flags_get(eventflags_ptr, requested_flags, get_option, &actual_flags, wait_option);
if ((status == TX_NO_EVENTS) || (status == TX_WAIT_ERROR))
{
actual_flags = osFlagsErrorTimeout;
}if ((status == TX_NO_EVENTS) || (status == TX_WAIT_ERROR)) { ... }
else if (status != TX_SUCCESS)
{
actual_flags = osFlagsErrorResource ;
}else if (status != TX_SUCCESS) { ... }
}else { ... }
return ((uint32_t)actual_flags);
}{ ... }
/* ... */
osStatus_t osEventFlagsDelete(osEventFlagsId_t ef_id)
{
TX_EVENT_FLAGS_GROUP *eventflags_ptr = (TX_EVENT_FLAGS_GROUP *)ef_id;
osStatus_t status;
if (IS_IRQ_MODE())
{
status = osErrorISR;
}if (IS_IRQ_MODE()) { ... }
else if ((ef_id == NULL) || (eventflags_ptr -> tx_event_flags_group_id != TX_EVENT_FLAGS_ID))
{
status = osErrorParameter;
}else if ((ef_id == NULL) || (eventflags_ptr -> tx_event_flags_group_id != TX_EVENT_FLAGS_ID)) { ... }
else
{
if (tx_event_flags_delete(eventflags_ptr) == TX_SUCCESS)
{
if (MemFree(eventflags_ptr) == osOK)
{
status = osOK;
}if (MemFree(eventflags_ptr) == osOK) { ... }
else
{
status = osErrorResource;
}else { ... }
}if (tx_event_flags_delete(eventflags_ptr) == TX_SUCCESS) { ... }
else
{
status = osErrorResource;
}else { ... }
}else { ... }
return (status);
}{ ... }
-----------------------------Event flags APIs
/* ... */
osMutexId_t osMutexNew(const osMutexAttr_t *attr)
{
TX_MUTEX *mutex_ptr = NULL;
CHAR *name_ptr = NULL;
UINT inherit = TX_INHERIT;
ULONG cb_size = sizeof(TX_MUTEX);
if (!IS_IRQ_MODE())
{
if (attr != NULL)
{
if (attr->name != NULL)
{
name_ptr = (CHAR *)attr->name;
}if (attr->name != NULL) { ... }
if (attr->attr_bits != 0)
{
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) { ... }
if (attr->cb_size == 0U)
{
cb_size = sizeof(TX_MUTEX);
}if (attr->cb_size == 0U) { ... }
else if (attr->cb_size < sizeof(TX_MUTEX))
{
return (NULL);
}else if (attr->cb_size < sizeof(TX_MUTEX)) { ... }
else
{
cb_size = (ULONG) attr->cb_size;
}else { ... }
if (attr->cb_mem == NULL)
{
mutex_ptr = (TX_MUTEX *)MemAlloc(cb_size, RTOS2_BYTE_POOL_HEAP_TYPE);
if (mutex_ptr == NULL)
{
return (NULL);
}if (mutex_ptr == NULL) { ... }
}if (attr->cb_mem == NULL) { ... }
else
{
mutex_ptr = attr->cb_mem;
}else { ... }
}if (attr != NULL) { ... }
else
{
mutex_ptr = (TX_MUTEX *)MemAlloc(cb_size, RTOS2_BYTE_POOL_HEAP_TYPE);
}else { ... }
if (tx_mutex_create(mutex_ptr, name_ptr, inherit) != TX_SUCCESS)
{
if ((attr->cb_mem == NULL) || (attr == NULL))
{
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);
}{ ... }
/* ... */
const char *osMutexGetName(osMutexId_t mutex_id)
{
TX_MUTEX *mutex_ptr = (TX_MUTEX *)mutex_id;
CHAR *name_ptr;
/* ... */
if (IS_IRQ_MODE() || (mutex_ptr == NULL) || (mutex_ptr -> tx_mutex_id != TX_MUTEX_ID))
{
name_ptr = NULL;
}if (IS_IRQ_MODE() || (mutex_ptr == NULL) || (mutex_ptr -> tx_mutex_id != TX_MUTEX_ID)) { ... }
else
{
if (tx_mutex_info_get(mutex_ptr, &name_ptr, NULL, NULL, NULL, NULL, NULL) != TX_SUCCESS)
{
name_ptr = NULL;
}if (tx_mutex_info_get(mutex_ptr, &name_ptr, NULL, NULL, NULL, NULL, NULL) != TX_SUCCESS) { ... }
}else { ... }
return (name_ptr);
}{ ... }
/* ... */
osStatus_t osMutexAcquire(osMutexId_t mutex_id, uint32_t timeout)
{
TX_MUTEX *mutex_ptr = (TX_MUTEX *)mutex_id;
osStatus_t status;
ULONG wait_option = (ULONG) timeout;
UINT tx_status;
if (IS_IRQ_MODE())
{
status = osErrorISR;
}if (IS_IRQ_MODE()) { ... }
else if ((mutex_id == NULL) || (mutex_ptr -> tx_mutex_id != TX_MUTEX_ID))
{
status = osErrorParameter;
}else if ((mutex_id == NULL) || (mutex_ptr -> tx_mutex_id != TX_MUTEX_ID)) { ... }
else
{
tx_status = tx_mutex_get(mutex_ptr, wait_option);
if (tx_status == TX_SUCCESS)
{
status = osOK;
}if (tx_status == TX_SUCCESS) { ... }
else if (tx_status == TX_WAIT_ABORTED)
{
status = osErrorTimeout;
}else if (tx_status == TX_WAIT_ABORTED) { ... }
else
{
status = osErrorResource;
}else { ... }
}else { ... }
return (status);
}{ ... }
/* ... */
osStatus_t osMutexRelease(osMutexId_t mutex_id)
{
TX_MUTEX *mutex_ptr = (TX_MUTEX *)mutex_id;
osStatus_t status;
if (IS_IRQ_MODE())
{
status = osErrorISR;
}if (IS_IRQ_MODE()) { ... }
else if ((mutex_id == NULL) || (mutex_ptr -> tx_mutex_id != TX_MUTEX_ID))
{
status = osErrorParameter;
}else if ((mutex_id == NULL) || (mutex_ptr -> tx_mutex_id != TX_MUTEX_ID)) { ... }
else
{
if (tx_mutex_put(mutex_ptr) == TX_SUCCESS)
{
status = osOK;
}if (tx_mutex_put(mutex_ptr) == TX_SUCCESS) { ... }
else
{
status = osErrorResource;
}else { ... }
}else { ... }
return (status);
}{ ... }
/* ... */
osThreadId_t osMutexGetOwner(osMutexId_t mutex_id)
{
TX_MUTEX *mutex_ptr = (TX_MUTEX *)mutex_id;
TX_THREAD *thread_ptr = NULL;
if (IS_IRQ_MODE())
{
thread_ptr = NULL;
}if (IS_IRQ_MODE()) { ... }
else if ((mutex_id == NULL) || (mutex_ptr -> tx_mutex_id != TX_MUTEX_ID))
{
thread_ptr = NULL;
}else if ((mutex_id == NULL) || (mutex_ptr -> tx_mutex_id != TX_MUTEX_ID)) { ... }
else
{
if (tx_mutex_info_get(mutex_ptr, NULL, NULL, &thread_ptr, NULL, NULL, NULL) == TX_SUCCESS)
{
if (thread_ptr == TX_NULL)
{
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
{
thread_ptr = NULL;
}else { ... }
}else { ... }
return ((osThreadId_t)thread_ptr);
}{ ... }
/* ... */
osStatus_t osMutexDelete(osMutexId_t mutex_id)
{
TX_MUTEX *mutex_ptr = (TX_MUTEX *)mutex_id;
osStatus_t status;
if (IS_IRQ_MODE())
{
status = osErrorISR;
}if (IS_IRQ_MODE()) { ... }
else if ((mutex_id == NULL) || (mutex_ptr -> tx_mutex_id != TX_MUTEX_ID))
{
status = osErrorParameter;
}else if ((mutex_id == NULL) || (mutex_ptr -> tx_mutex_id != TX_MUTEX_ID)) { ... }
else
{
if (tx_mutex_delete(mutex_ptr) == TX_SUCCESS)
{
if (MemFree(mutex_ptr) == osOK)
{
status = osOK;
}if (MemFree(mutex_ptr) == osOK) { ... }
else
{
status = osErrorResource;
}else { ... }
}if (tx_mutex_delete(mutex_ptr) == TX_SUCCESS) { ... }
else
{
status = osErrorResource;
}else { ... }
}else { ... }
return (status);
}{ ... }
---------------------------Mutex Management APIs
/* ... */
osSemaphoreId_t osSemaphoreNew(uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr)
{
TX_SEMAPHORE *semaphore_ptr = NULL;
CHAR *name_ptr = NULL;
ULONG init_count = (ULONG) initial_count;
ULONG cb_size = sizeof(TX_SEMAPHORE);
if (!IS_IRQ_MODE())
{
if (attr != NULL)
{
if (attr->name != NULL)
{
name_ptr = (CHAR *)attr->name;
}if (attr->name != NULL) { ... }
if (attr->cb_size == 0U)
{
cb_size = sizeof(TX_SEMAPHORE);
}if (attr->cb_size == 0U) { ... }
else if (attr->cb_size < sizeof(TX_SEMAPHORE))
{
return (NULL);
}else if (attr->cb_size < sizeof(TX_SEMAPHORE)) { ... }
else
{
cb_size = (ULONG) attr->cb_size;
}else { ... }
if (attr->cb_mem == NULL)
{
semaphore_ptr = (TX_SEMAPHORE *)MemAlloc(cb_size, RTOS2_BYTE_POOL_HEAP_TYPE);
if (semaphore_ptr == NULL)
{
return (NULL);
}if (semaphore_ptr == NULL) { ... }
}if (attr->cb_mem == NULL) { ... }
else
{
semaphore_ptr = attr->cb_mem;
}else { ... }
}if (attr != NULL) { ... }
else
{
semaphore_ptr = (TX_SEMAPHORE *)MemAlloc(cb_size, RTOS2_BYTE_POOL_HEAP_TYPE);
}else { ... }
if (tx_semaphore_create(semaphore_ptr, name_ptr, init_count) != TX_SUCCESS)
{
if ((attr->cb_mem == NULL) || (attr == NULL))
{
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);
}{ ... }
/* ... */
const char *osSemaphoreGetName(osSemaphoreId_t semaphore_id)
{
TX_SEMAPHORE *semaphore_ptr = (TX_SEMAPHORE *)semaphore_id;
CHAR *name_ptr;
/* ... */
if (IS_IRQ_MODE() || (semaphore_ptr == NULL) || (semaphore_ptr -> tx_semaphore_id != TX_SEMAPHORE_ID))
{
name_ptr = NULL;
}if (IS_IRQ_MODE() || (semaphore_ptr == NULL) || (semaphore_ptr -> tx_semaphore_id != TX_SEMAPHORE_ID)) { ... }
else
{
if (tx_semaphore_info_get(semaphore_ptr, &name_ptr, NULL, NULL, NULL, NULL) != TX_SUCCESS)
{
name_ptr = NULL;
}if (tx_semaphore_info_get(semaphore_ptr, &name_ptr, NULL, NULL, NULL, NULL) != TX_SUCCESS) { ... }
}else { ... }
return (name_ptr);
}{ ... }
/* ... */
osStatus_t osSemaphoreAcquire(osSemaphoreId_t semaphore_id, uint32_t timeout)
{
TX_SEMAPHORE *semaphore_ptr = (TX_SEMAPHORE *)semaphore_id;
osStatus_t status;
ULONG wait_option = (ULONG) timeout;
UINT tx_status;
if ((IS_IRQ_MODE() && (timeout != 0)) || (semaphore_id == NULL) ||
(semaphore_ptr -> tx_semaphore_id != TX_SEMAPHORE_ID))
{
status = osErrorParameter;
}if ((IS_IRQ_MODE() && (timeout != 0)) || (semaphore_id == NULL) || (semaphore_ptr -> tx_semaphore_id != TX_SEMAPHORE_ID)) { ... }
else
{
tx_status = tx_semaphore_get(semaphore_ptr, wait_option);
if (tx_status == TX_SUCCESS)
{
status = osOK;
}if (tx_status == TX_SUCCESS) { ... }
else if (tx_status == TX_WAIT_ABORTED)
{
/* ... */
status = osErrorTimeout;
}else if (tx_status == TX_WAIT_ABORTED) { ... }
else
{
status = osErrorResource;
}else { ... }
}else { ... }
return (status);
}{ ... }
/* ... */
osStatus_t osSemaphoreRelease(osSemaphoreId_t semaphore_id)
{
TX_SEMAPHORE *semaphore_ptr = (TX_SEMAPHORE *)semaphore_id;
osStatus_t status;
if ((semaphore_id == NULL) || (semaphore_ptr -> tx_semaphore_id != TX_SEMAPHORE_ID))
{
status = osErrorParameter;
}if ((semaphore_id == NULL) || (semaphore_ptr -> tx_semaphore_id != TX_SEMAPHORE_ID)) { ... }
else
{
if (tx_semaphore_put(semaphore_ptr) == TX_SUCCESS)
{
status = osOK;
}if (tx_semaphore_put(semaphore_ptr) == TX_SUCCESS) { ... }
else
{
status = osErrorResource;
}else { ... }
}else { ... }
return (status);
}{ ... }
/* ... */
osStatus_t osSemaphoreDelete(osSemaphoreId_t semaphore_id)
{
TX_SEMAPHORE *semaphore_ptr = (TX_SEMAPHORE *)semaphore_id;
osStatus_t status;
if (IS_IRQ_MODE())
{
status = osErrorISR;
}if (IS_IRQ_MODE()) { ... }
else if ((semaphore_id == NULL) || (semaphore_ptr -> tx_semaphore_id != TX_SEMAPHORE_ID))
{
status = osErrorParameter;
}else if ((semaphore_id == NULL) || (semaphore_ptr -> tx_semaphore_id != TX_SEMAPHORE_ID)) { ... }
else
{
if (tx_semaphore_delete(semaphore_ptr) == TX_SUCCESS)
{
if (MemFree(semaphore_ptr) == osOK)
{
status = osOK;
}if (MemFree(semaphore_ptr) == osOK) { ... }
else
{
status = osErrorResource;
}else { ... }
}if (tx_semaphore_delete(semaphore_ptr) == TX_SUCCESS) { ... }
else
{
status = osErrorResource;
}else { ... }
}else { ... }
return (status);
}{ ... }
------------------------------Semaphores APIs
/* ... */
osMessageQueueId_t osMessageQueueNew(uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr)
{
TX_QUEUE *queue_ptr = NULL;
CHAR *name_ptr = NULL;
VOID *queue_start = NULL;
ULONG queue_size = 0U;
ULONG cb_size = 0U;
/* ... */
if (!IS_IRQ_MODE() && (msg_count > 0) && (msg_size > 0))
{
name_ptr = NULL;
msg_size = msg_size + (msg_size % sizeof(ULONG));
if (attr != NULL)
{
if (attr->name != NULL)
{
name_ptr = (CHAR *)attr->name;
}if (attr->name != NULL) { ... }
if (attr->mq_size == 0U)
{
/* ... */
queue_size = msg_count * msg_size;
}if (attr->mq_size == 0U) { ... }
else if (attr->mq_size < (msg_count * msg_size))
{
return (NULL);
}else if (attr->mq_size < (msg_count * msg_size)) { ... }
else if (attr->mq_size < TX_BYTE_POOL_MIN)
{
queue_size = TX_BYTE_POOL_MIN;
}else if (attr->mq_size < TX_BYTE_POOL_MIN) { ... }
else
{
queue_size = (ULONG)attr->mq_size;
}else { ... }
if (attr->mq_mem == NULL)
{
queue_start = MemAlloc(queue_size, RTOS2_BYTE_POOL_STACK_TYPE);
if (queue_start == NULL)
{
return (NULL);
}if (queue_start == NULL) { ... }
}if (attr->mq_mem == NULL) { ... }
else
{
if (attr->mq_size == 0U)
{
return (NULL);
}if (attr->mq_size == 0U) { ... }
else
{
queue_size = (ULONG)attr->mq_size;
}else { ... }
queue_start = attr->mq_mem;
}else { ... }
if (attr->cb_size == 0U)
{
cb_size = sizeof(TX_QUEUE);
}if (attr->cb_size == 0U) { ... }
else if (attr->cb_size < sizeof(TX_QUEUE))
{
return (NULL);
}else if (attr->cb_size < sizeof(TX_QUEUE)) { ... }
else
{
cb_size = (ULONG)attr->cb_size;
}else { ... }
if (attr->cb_mem == NULL)
{
queue_ptr = (TX_QUEUE *)MemAlloc(cb_size, RTOS2_BYTE_POOL_HEAP_TYPE);
if (queue_ptr == NULL)
{
if (attr->mq_mem == NULL)
{
MemFree(queue_start);
}if (attr->mq_mem == NULL) { ... }
return (NULL);
}if (queue_ptr == NULL) { ... }
}if (attr->cb_mem == NULL) { ... }
else
{
queue_ptr = attr->cb_mem;
}else { ... }
}if (attr != NULL) { ... }
else
{
name_ptr = NULL;
/* ... */
queue_size = msg_count * msg_size;
queue_start = MemAlloc(queue_size, RTOS2_BYTE_POOL_STACK_TYPE);
if (queue_start == NULL)
{
return (NULL);
}if (queue_start == NULL) { ... }
queue_ptr = (TX_QUEUE *)MemAlloc(sizeof(TX_QUEUE), RTOS2_BYTE_POOL_HEAP_TYPE);
if (queue_ptr == NULL)
{
MemFree(queue_start);
return (NULL);
}if (queue_ptr == NULL) { ... }
}else { ... }
msg_size = msg_size / sizeof(ULONG);
if (tx_queue_create(queue_ptr, name_ptr, msg_size, queue_start, queue_size) != TX_SUCCESS)
{
/* ... */
if ((attr->cb_mem == NULL) || (attr == NULL))
{
MemFree(queue_ptr);
}if ((attr->cb_mem == NULL) || (attr == NULL)) { ... }
if ((attr->mq_mem == NULL) || (attr == NULL))
{
MemFree(queue_start);
}if ((attr->mq_mem == NULL) || (attr == NULL)) { ... }
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);
}{ ... }
/* ... */
const char *osMessageQueueGetName(osMessageQueueId_t mq_id)
{
TX_QUEUE *queue_ptr = (TX_QUEUE *)mq_id;
CHAR *name_ptr = NULL;
/* ... */
if (IS_IRQ_MODE() || (queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID))
{
name_ptr = NULL;
}if (IS_IRQ_MODE() || (queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID)) { ... }
else
{
if (tx_queue_info_get(queue_ptr, &name_ptr, NULL, NULL, NULL, NULL, NULL) != TX_SUCCESS)
{
name_ptr = NULL;
}if (tx_queue_info_get(queue_ptr, &name_ptr, NULL, NULL, NULL, NULL, NULL) != TX_SUCCESS) { ... }
}else { ... }
return (name_ptr);
}{ ... }
/* ... */
uint32_t osMessageQueueGetCapacity(osMessageQueueId_t mq_id)
{
TX_QUEUE *queue_ptr = (TX_QUEUE *)mq_id;
uint32_t max_messages_number;
if ((queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID))
{
max_messages_number = 0U;
}if ((queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID)) { ... }
else
{
max_messages_number = queue_ptr->tx_queue_capacity;
}else { ... }
return (max_messages_number);
}{ ... }
/* ... */
uint32_t osMessageQueueGetMsgSize(osMessageQueueId_t mq_id)
{
TX_QUEUE *queue_ptr = (TX_QUEUE *)mq_id;
uint32_t max_messages_size;
if ((queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID))
{
max_messages_size = 0U;
}if ((queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID)) { ... }
else
{
max_messages_size = queue_ptr->tx_queue_message_size * sizeof(ULONG);
}else { ... }
return (max_messages_size);
}{ ... }
/* ... */
uint32_t osMessageQueueGetCount(osMessageQueueId_t mq_id)
{
TX_QUEUE *queue_ptr = (TX_QUEUE *)mq_id;
uint32_t queued_messages_number = 0U;
if ((queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID))
{
queued_messages_number = 0U;
}if ((queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID)) { ... }
else
{
if (tx_queue_info_get(queue_ptr, NULL, (ULONG *)&queued_messages_number, NULL, NULL, NULL, NULL) != TX_SUCCESS)
{
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);
}{ ... }
/* ... */
uint32_t osMessageQueueGetSpace(osMessageQueueId_t mq_id)
{
TX_QUEUE *queue_ptr = (TX_QUEUE *)mq_id;
uint32_t queue_messages_free_slots = 0U;
if ((queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID))
{
queue_messages_free_slots = 0U;
}if ((queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID)) { ... }
else
{
/* ... */
if (tx_queue_info_get(queue_ptr, NULL, NULL, (ULONG *)&queue_messages_free_slots, NULL, NULL, NULL) != TX_SUCCESS)
{
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);
}{ ... }
/* ... */
osStatus_t osMessageQueueReset(osMessageQueueId_t mq_id)
{
TX_QUEUE *queue_ptr = (TX_QUEUE *)mq_id;
osStatus_t status;
if (IS_IRQ_MODE())
{
status = osErrorISR;
}if (IS_IRQ_MODE()) { ... }
else if ((queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID))
{
status = osErrorParameter;
}else if ((queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID)) { ... }
else
{
/* ... */
if (tx_queue_flush(queue_ptr) == TX_SUCCESS)
{
status = osOK;
}if (tx_queue_flush(queue_ptr) == TX_SUCCESS) { ... }
else
{
status = osErrorResource;
}else { ... }
}else { ... }
return (status);
}{ ... }
/* ... */
osStatus_t osMessageQueueDelete(osMessageQueueId_t mq_id)
{
TX_QUEUE *queue_ptr = (TX_QUEUE *)mq_id;
osStatus_t status;
if (IS_IRQ_MODE())
{
status = osErrorISR;
}if (IS_IRQ_MODE()) { ... }
else if ((queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID))
{
status = osErrorParameter;
}else if ((queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID)) { ... }
else
{
if (tx_queue_delete(queue_ptr) == TX_SUCCESS)
{
MemFree(queue_ptr->tx_queue_start);
MemFree(queue_ptr);
status = osOK;
}if (tx_queue_delete(queue_ptr) == TX_SUCCESS) { ... }
else
{
status = osErrorResource;
}else { ... }
}else { ... }
return (status);
}{ ... }
/* ... */
osStatus_t osMessageQueuePut(osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout)
{
TX_QUEUE *queue_ptr = (TX_QUEUE *)mq_id;
UINT tx_status;
osStatus_t status;
if ((IS_IRQ_MODE() && (timeout != 0)) || (queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID) ||
(msg_ptr == NULL))
{
status = osErrorParameter;
}if ((IS_IRQ_MODE() && (timeout != 0)) || (queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID) || (msg_ptr == NULL)) { ... }
else
{
tx_status = tx_queue_send(queue_ptr, (void *)msg_ptr, timeout);
if (tx_status == TX_SUCCESS)
{
status = osOK;
}if (tx_status == TX_SUCCESS) { ... }
else if (tx_status == TX_QUEUE_FULL)
{
status = osErrorResource;
}else if (tx_status == TX_QUEUE_FULL) { ... }
else
{
status = osErrorTimeout;
}else { ... }
}else { ... }
return (status);
}{ ... }
/* ... */
osStatus_t osMessageQueueGet(osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout)
{
TX_QUEUE *queue_ptr = (TX_QUEUE *)mq_id;
UINT tx_status;
osStatus_t status;
if ((IS_IRQ_MODE() && (timeout != 0)) || (queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID) ||
(msg_ptr == NULL))
{
status = osErrorParameter;
}if ((IS_IRQ_MODE() && (timeout != 0)) || (queue_ptr == NULL) || (queue_ptr->tx_queue_id != TX_QUEUE_ID) || (msg_ptr == NULL)) { ... }
else
{
tx_status = tx_queue_receive(queue_ptr, msg_ptr, timeout);
if (tx_status == TX_SUCCESS)
{
status = osOK;
}if (tx_status == TX_SUCCESS) { ... }
else if (tx_status == TX_QUEUE_EMPTY)
{
status = osErrorTimeout;
}else if (tx_status == TX_QUEUE_EMPTY) { ... }
else if (tx_status == TX_WAIT_ERROR)
{
status = osErrorParameter;
}else if (tx_status == TX_WAIT_ERROR) { ... }
else
{
status = osErrorResource;
}else { ... }
}else { ... }
return (status);
}{ ... }
------------------------------Message Queue APIs
__WEAK VOID tx_application_define(VOID *first_unused_memory)
{
}{ ... }