Boot Linux faster!

Check our new training course

Boot Linux faster!

Check our new training course
and Creative Commons CC-BY-SA
lecture and lab materials

Bootlin logo

Elixir Cross Referencer

   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
/*
 * Copyright (c) 2016, Wind River Systems, Inc.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

/**
 * @file
 *
 * @brief Public legacy kernel APIs.
 */

#ifndef _legacy__h_
#define _legacy__h_

#include <stdint.h>
#include <errno.h>
#include <limits.h>
#include <misc/util.h>
#include <misc/__assert.h>
#include <drivers/rand32.h>

/* nanokernel/microkernel execution context types */
#define NANO_CTX_ISR (K_ISR)
#define NANO_CTX_FIBER (K_COOP_THREAD)
#define NANO_CTX_TASK (K_PREEMPT_THREAD)

/* timeout special values */
#define TICKS_UNLIMITED (K_FOREVER)
#define TICKS_NONE (K_NO_WAIT)

/* microkernel object return codes */
#define RC_OK 0
#define RC_FAIL 1
#define RC_TIME 2
#define RC_ALIGNMENT 3
#define RC_INCOMPLETE 4

#define ANYTASK K_ANY

/* end-of-list, mostly used for semaphore groups */
#define ENDLIST K_END

/* pre-defined task groups */
#define K_TASK_GROUP_EXE 0x1
#define K_TASK_GROUP_SYS 0x2
#define K_TASK_GROUP_FPU 0x4
/* the following is for x86 architecture only */
#define K_TASK_GROUP_SSE 0x8

/* pipe amount of content to receive (0+, 1+, all) */
typedef enum {
	_0_TO_N = 0x0,
	_1_TO_N = 0x1,
	_ALL_N  = 0x2,
} K_PIPE_OPTION;

#define kpriority_t uint32_t

static inline int32_t _ticks_to_ms(int32_t ticks)
{
	return (ticks == TICKS_UNLIMITED) ? K_FOREVER : __ticks_to_ms(ticks);
}

static inline int _error_to_rc(int err)
{
	return err == 0 ? RC_OK : err == -EAGAIN ? RC_TIME : RC_FAIL;
}

static inline int _error_to_rc_no_timeout(int err)
{
	return err == 0 ? RC_OK : RC_FAIL;
}

/* tasks/fibers/scheduler */

#define ktask_t k_tid_t
#define nano_thread_id_t k_tid_t
typedef void (*nano_fiber_entry_t)(int i1, int i2);
typedef int nano_context_type_t;

#define _MDEF_THREAD_DEFINE(name, stack_size,                              \
			    entry, p1, p2, p3,                             \
			    abort, prio, groups)                           \
	char __noinit __stack _k_thread_obj_##name[stack_size];            \
	struct _static_thread_data _k_thread_data_##name __aligned(4)      \
		_GENERIC_SECTION(._static_thread_data.static.mdef) =       \
		_THREAD_INITIALIZER(_k_thread_obj_##name, stack_size,      \
				    entry, p1, p2, p3, prio, 0, K_FOREVER, \
				    abort, groups)

/**
 * @defgroup legacy_apis Legacy API
 * @ingroup kernel_apis
 * @{
 */

/**
 * @brief Define a private microkernel task.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This declares and initializes a private task. The new task
 * can be passed to the microkernel task functions.
 *
 * @param name Name of the task.
 * @param priority Priority of task.
 * @param entry Entry function.
 * @param stack_size Size of stack (in bytes)
 * @param groups Groups this task belong to.
 */
#define DEFINE_TASK(name, priority, entry, stack_size, groups)        \
	extern void entry(void);                                      \
	char __noinit __stack _k_thread_obj_##name[stack_size];       \
	struct _static_thread_data _k_thread_data_##name __aligned(4) \
		__in_section(_static_thread_data, static, name) =     \
		_THREAD_INITIALIZER(_k_thread_obj_##name, stack_size, \
				    entry, NULL, NULL, NULL,          \
				    priority, 0, K_FOREVER,           \
				    NULL, (uint32_t)(groups));        \
	k_tid_t const name = (k_tid_t)_k_thread_obj_##name

/**
 * @brief Return the ID of the currently executing thread.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine returns a pointer to the thread control block of the currently
 * executing thread. It is cast to a nano_thread_id_t for public use.
 *
 * @return The ID of the currently executing thread.
 */
static inline __deprecated nano_thread_id_t sys_thread_self_get(void)
{
	return k_current_get();
}

/**
 * @brief Cause the currently executing thread to busy wait.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine causes the current task or fiber to execute a "do nothing"
 * loop for a specified period of time.
 *
 * @warning This routine utilizes the system clock, so it must not be invoked
 * until the system clock is fully operational or while interrupts
 * are locked.
 *
 * @param usec_to_wait Number of microseconds to busy wait.
 *
 * @return N/A
 */
static inline __deprecated void sys_thread_busy_wait(uint32_t usec_to_wait)
{
	k_busy_wait(usec_to_wait);
}

/**
 * @brief Return the type of the current execution context.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine returns the type of execution context currently executing.
 *
 * @return The type of the current execution context.
 * @retval NANO_CTX_ISR (0): executing an interrupt service routine.
 * @retval NANO_CTX_FIBER (1): current thread is a fiber.
 * @retval NANO_CTX_TASK (2): current thread is a task.
 */
extern __deprecated int sys_execution_context_type_get(void);

/**
 * @brief Initialize and start a fiber.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine initializes and starts a fiber. It can be called from
 * either a fiber or a task. When this routine is called from a
 * task, the newly created fiber will start executing immediately.
 *
 * @internal
 * Given that this routine is _not_ ISR-callable, the following code is used
 * to differentiate between a task and fiber:
 *
 * if ((_kernel.current->flags & TASK) == TASK)
 *
 * Given that the _fiber_start() primitive is not considered real-time
 * performance critical, a runtime check to differentiate between a calling
 * task or fiber is performed to conserve footprint.
 * @endinternal
 *
 * @param stack Pointer to the stack space.
 * @param stack_size Stack size in bytes.
 * @param entry Fiber entry.
 * @param arg1 1st entry point parameter.
 * @param arg2 2nd entry point parameter.
 * @param prio The fiber's priority.
 * @param options Not used currently.
 *
 * @return nanokernel thread identifier
 */
static inline __deprecated nano_thread_id_t
fiber_start(char *stack, unsigned stack_size, nano_fiber_entry_t entry,
	    int arg1, int arg2, unsigned prio, unsigned options)
{
	return k_thread_spawn(stack, stack_size, (k_thread_entry_t)entry,
				(void *)(intptr_t)arg1, (void *)(intptr_t)arg2,
				NULL, K_PRIO_COOP(prio), options, 0);
}

/**
 * @brief Initialize and start a fiber from a fiber.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like fiber_start(), but may only be called from a fiber.
 *
 * @sa fiber_start
 */
#define fiber_fiber_start fiber_start

/**
 * @brief Initialize and start a fiber from a task.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like fiber_start(), but may only be called from a task.
 *
 * @sa fiber_start
 */
#define task_fiber_start fiber_start

/**
 * @brief Fiber configuration structure.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Parameters such as stack size and fiber priority are often
 * user configurable. This structure makes it simple to specify such a
 * configuration.
 */
struct fiber_config {
	char *stack;
	unsigned stack_size;
	unsigned prio;
};

/**
 * @brief Start a fiber based on a @ref fiber_config.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine can be called from either a fiber or a task.
 *
 * @param config Pointer to fiber configuration structure
 * @param entry Fiber entry.
 * @param arg1 1st entry point parameter.
 * @param arg2 2nd entry point parameter.
 * @param options Not used currently.
 *
 * @return thread ID
 */
#define fiber_start_config(config, entry, arg1, arg2, options) \
	fiber_start(config->stack, config->stack_size, \
		    entry, arg1, arg2, \
		    config->prio, options)

/**
 * @brief Start a fiber based on a @ref fiber_config, from fiber context.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like fiber_start_config(), but may only be called from a fiber.
 *
 * @sa fiber_start_config()
 */
#define fiber_fiber_start_config fiber_start_config

/**
 * @brief Start a fiber based on a @ref fiber_config, from task context.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like fiber_start_config(), but may only be called from a task.
 *
 * @sa fiber_start_config()
 */
#define task_fiber_start_config fiber_start_config

/**
 * @brief Start a fiber while delaying its execution.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @param stack Pointer to the stack space.
 * @param stack_size_in_bytes Stack size in bytes.
 * @param entry_point The fiber's entry point.
 * @param param1 1st entry point parameter.
 * @param param2 2nd entry point parameter.
 * @param priority The fiber's priority.
 * @param options Not used currently.
 * @param timeout_in_ticks Timeout duration in ticks.
 *
 * @return A handle potentially used to cancel the delayed start.
 */
static inline __deprecated nano_thread_id_t
fiber_delayed_start(char *stack, unsigned int stack_size_in_bytes,
			nano_fiber_entry_t entry_point, int param1,
			int param2, unsigned int priority,
			unsigned int options, int32_t timeout_in_ticks)
{
	return k_thread_spawn(stack, stack_size_in_bytes,
			      (k_thread_entry_t)entry_point,
			      (void *)(intptr_t)param1,
			      (void *)(intptr_t)param2, NULL,
			      K_PRIO_COOP(priority), options,
			      _ticks_to_ms(timeout_in_ticks));
}

/**
 * @brief Start a fiber while delaying its execution.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like fiber_delayed_start(), but may only be called from a fiber.
 *
 * @sa fiber_delayed_start
 */
#define fiber_fiber_delayed_start fiber_delayed_start

/**
 * @brief Start a fiber while delaying its execution.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like fiber_delayed_start(), but may only be called from a task.
 *
 * @sa fiber_delayed_start
 */
#define task_fiber_delayed_start fiber_delayed_start

/**
 * @brief Cancel a delayed fiber start.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @param handle The handle returned when starting the delayed fiber.
 *
 * @return N/A
 */
static inline __deprecated void
fiber_delayed_start_cancel(nano_thread_id_t handle)
{
	k_thread_cancel(handle);
}

/**
 * @brief Cancel a delayed fiber start from a fiber
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like fiber_delayed_start_cancel(), but may only be called from a fiber.
 *
 * @sa fiber_delayed_start_cancel
 */
#define fiber_fiber_delayed_start_cancel fiber_delayed_start_cancel

/**
 * @brief Cancel a delayed fiber start from a task
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like fiber_delayed_start_cancel(), but may only be called from a fiber.
 *
 * @sa fiber_delayed_start_cancel
 */
#define task_fiber_delayed_start_cancel fiber_delayed_start_cancel

/**
 * @brief Yield the current fiber.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Calling this routine results in the current fiber yielding to
 * another fiber of the same or higher priority. If there are no
 * other runnable fibers of the same or higher priority, the
 * routine will return immediately.
 *
 * This routine can only be called from a fiber.
 *
 * @return N/A
 */
static inline __deprecated void fiber_yield(void)
{
	k_yield();
}

/**
 * @brief Abort the currently executing fiber.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine aborts the currently executing fiber. An abort can occur
 * because of one of three reasons:
 * - The fiber has explicitly aborted itself by calling this routine.
 * - The fiber has implicitly aborted itself by returning from its entry point.
 * - The fiber has encountered a fatal exception.
 *
 * This routine can only be called from a fiber.
 *
 * @return N/A
 */
static inline __deprecated void fiber_abort(void)
{
	k_thread_abort(k_current_get());
}

extern void __deprecated _legacy_sleep(int32_t ticks);

/**
 * @brief Put the current fiber to sleep.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine puts the currently running fiber to sleep
 * for the number of system ticks passed in the
 * @a timeout_in_ticks parameter.
 *
 * @param timeout_in_ticks Number of system ticks the fiber sleeps.
 *
 * @return N/A
 */
#define fiber_sleep _legacy_sleep

/**
 * @brief Put the task to sleep.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine puts the currently running task to sleep for the number
 * of system ticks passed in the @a timeout_in_ticks parameter.
 *
 * @param timeout_in_ticks Number of system ticks the task sleeps.
 *
 * @warning A value of TICKS_UNLIMITED is considered invalid and may result in
 * unexpected behavior.
 *
 * @return N/A
 *
 * @sa TICKS_UNLIMITED
 */
#define task_sleep _legacy_sleep

/**
 * @brief Wake the specified fiber from sleep
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine is a convenience wrapper for the execution of context-specific
 * APIs. It is helpful when the exact execution context is not known. However,
 * it should be avoided when the context is known up-front to avoid
 * unnecessary overhead.
 *
 * @param fiber Identifies fiber to wake
 *
 * @return N/A
 */
static inline __deprecated void fiber_wakeup(nano_thread_id_t fiber)
{
	k_wakeup(fiber);
}

/**
 * @brief Wake the specified fiber from sleep
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like fiber_wakeup(), but may only be called from an ISR.
 *
 * @sa fiber_wakeup
 */
#define isr_fiber_wakeup fiber_wakeup

/**
 * @brief Wake the specified fiber from sleep
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like fiber_wakeup, but may only be called from a fiber.
 *
 * @sa fiber_wakeup
 */
#define fiber_fiber_wakeup fiber_wakeup

/**
 * @brief Wake the specified fiber from sleep
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like fiber_wakeup, but may only be called from a task.
 *
 * @sa fiber_wakeup
 */
#define task_fiber_wakeup fiber_wakeup

/**
 * @brief Yield the CPU to another task.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine yields the processor to the next-equal priority runnable
 * task. With task_yield(), the effect of round-robin scheduling is
 * possible. When no task of equal priority is runnable, no task switch
 * occurs, and the calling task resumes execution.
 *
 * @return N/A
 */
#define task_yield fiber_yield

/**
 * @brief Set the priority of a task.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine changes the priority of the specified task.
 *
 * The call has immediate effect. When the calling task no longer is the
 * highest-priority runnable task, a task switch occurs.
 *
 * Priority can be assigned in the range 0 to 62, where 0 is the
 * highest priority.
 *
 * @param task Task whose priority is to be set.
 * @param prio New priority.
 *
 * @return N/A
 */
static inline __deprecated void task_priority_set(ktask_t task,
						  kpriority_t prio)
{
	k_thread_priority_set(task, (int)prio);
}

/**
 * @brief Set the entry point of a task.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine sets the entry point of a task to a given routine. It is
 * needed only when an entry point differs from what is set in the project
 * file. To have any effect, it must be called before task_start(), and it
 * cannot work with members of the EXE group or with any group that starts
 * automatically on application loading.
 *
 * The routine is executed when the task is started.
 *
 * @param task Task to operate on.
 * @param entry Entry point.
 *
 * @return N/A
 */
static inline __deprecated void
task_entry_set(ktask_t task, void (*entry)(void))
{
	__ASSERT(0, "task_entry_set is unsupported");
	ARG_UNUSED(task);
	ARG_UNUSED(entry);

	/* This is impractical to implement in the new kernel and there are
	 * workarounds.
	 * 1) Set entry point in MDEF files
	 * 2) Set entry point in DEFINE_TASK macro
	 * 3) Set entry point in k_thread_spawn() invocation
	 */
}

/**
 * @brief Install an abort handler.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine installs an abort handler for the calling task.
 *
 * The abort handler runs when the calling task is aborted by a _TaskAbort()
 * or task_group_abort() call.
 *
 * Each call to task_abort_handler_set() replaces the previously-installed
 * handler.
 *
 * To remove an abort handler, set the parameter to NULL as below:
 *      task_abort_handler_set (NULL)
 *
 * @param handler Abort handler.
 *
 * @return N/A
 */
extern void __deprecated task_abort_handler_set(void (*handler)(void));

/**
 * @brief Process an "offload" request
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * The routine places the @a func into the work queue. This allows
 * the task to execute a routine uninterrupted by other tasks.
 *
 * Note: this routine can be invoked only from a task.
 * For the routine to work, the scheduler must be unlocked.
 *
 * @param func function to call
 * @param argp function arguments
 *
 * @return result of @a func call
 */
extern int __deprecated task_offload_to_fiber(int (*func)(), void *argp);

/**
 * @brief Gets task identifier
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @return identifier for current task
 */
static inline __deprecated ktask_t task_id_get(void)
{
	return k_current_get();
}

/**
 * @brief Gets task priority
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @return priority of current task
 */
static inline __deprecated kpriority_t task_priority_get(void)
{
	return (kpriority_t)(k_thread_priority_get(k_current_get()));
}

/**
 * @brief Abort a task
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @param task Task to abort
 *
 * @return N/A
 */
static inline __deprecated void task_abort(ktask_t task)
{
	k_thread_abort(task);
}

/**
 * @brief Suspend a task
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @param task Task to suspend
 *
 * @return N/A
 */
static inline __deprecated void task_suspend(ktask_t task)
{
	k_thread_suspend(task);
}

/**
 * @brief Resume a task
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @param task Task to resume
 *
 * @return N/A
 */
static inline __deprecated void task_resume(ktask_t task)
{
	k_thread_resume(task);
}

/**
 * @brief Start a task
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @param task Task to start
 *
 * @return N/A
 */
extern void __deprecated task_start(ktask_t task);

/**
 * @brief Set time-slicing period and scope
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine controls how task time slicing is performed by the task
 * scheduler; it specifes the maximum time slice length (in ticks) and
 * the highest priority task level for which time slicing is performed.
 *
 * To enable time slicing, a non-zero time slice length must be specified.
 * The task scheduler then ensures that no executing task runs for more than
 * the specified number of ticks before giving other tasks of that priority
 * a chance to execute. (However, any task whose priority is higher than the
 * specified task priority level is exempted, and may execute as long as
 * desired without being pre-empted due to time slicing.)
 *
 * Time slicing limits only the maximum amount of time a task may continuously
 * execute. Once the scheduler selects a task for execution, there is no minimum
 * guaranteed time the task will execute before tasks of greater or equal
 * priority are scheduled.
 *
 * When the currently-executing task is the only one of that priority eligible
 * for execution, this routine has no effect; the task is immediately
 * rescheduled after the slice period expires.
 *
 * To disable timeslicing, call the API with both parameters set to zero.
 *
 * @param ticks Maximum time slice length in ticks
 * @param priority Highest priority task level for which time slicing is
 *        performed
 *
 * @return N/A
 */
static inline void __deprecated sys_scheduler_time_slice_set(int32_t ticks,
						kpriority_t priority)
{
	k_sched_time_slice_set(_ticks_to_ms(ticks), (int)priority);
}

extern void _k_thread_group_op(uint32_t groups, void (*func)(struct tcs *));

/**
 * @brief Get task groups for task
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @return task groups associated with current task
 */
static inline __deprecated uint32_t task_group_mask_get(void)
{
	extern uint32_t _k_thread_group_mask_get(struct tcs *thread);

	return _k_thread_group_mask_get(k_current_get());
}

/**
 * @brief Get task groups for task
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @return task groups associated with current task
 */
#define isr_task_group_mask_get  task_group_mask_get

/**
 * @brief Add task to task group(s)
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @param groups Task Groups
 *
 * @return N/A
 */
static inline __deprecated void task_group_join(uint32_t groups)
{
	extern void _k_thread_group_join(uint32_t groups, struct tcs *thread);

	_k_thread_group_join(groups, k_current_get());
}

/**
 * @brief Remove task from task group(s)
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @param groups Task Groups
 *
 * @return N/A
 */
static inline __deprecated void task_group_leave(uint32_t groups)
{
	extern void _k_thread_group_leave(uint32_t groups, struct tcs *thread);

	_k_thread_group_leave(groups, k_current_get());
}

/**
 * @brief Start one or more task groups
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @param groups Task groups to start
 *
 * @return N/A
 */
static inline __deprecated void task_group_start(uint32_t groups)
{
	extern void _k_thread_single_start(struct tcs *thread);

	return _k_thread_group_op(groups, _k_thread_single_start);
}

/**
 * @brief Suspend one or more task groups
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @param groups Task groups to suspend
 *
 * @return N/A
 */
static inline __deprecated void task_group_suspend(uint32_t groups)
{
	extern void _k_thread_single_suspend(struct tcs *thread);

	return _k_thread_group_op(groups, _k_thread_single_suspend);
}

/**
 * @brief Resume one or more task groups
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @param groups Task groups to resume
 *
 * @return N/A
 */
static inline __deprecated void task_group_resume(uint32_t groups)
{
	extern void _k_thread_single_resume(struct tcs *thread);

	return _k_thread_group_op(groups, _k_thread_single_resume);
}

/**
 * @brief Abort one or more task groups
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @param groups Task groups to abort
 *
 * @return N/A
 */
static inline __deprecated void task_group_abort(uint32_t groups)
{
	extern void _k_thread_single_abort(struct tcs *thread);

	return _k_thread_group_op(groups, _k_thread_single_abort);
}

/**
 * @brief Get task identifier
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @return identifier for current task
 */
#define isr_task_id_get task_id_get

/**
 * @brief Get task priority
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @return priority of current task
 */
#define isr_task_priority_get task_priority_get

/* mutexes */

#define kmutex_t struct k_mutex *

/**
 * @brief Lock mutex.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine locks mutex @a mutex. When the mutex is locked by another task,
 * the routine will either wait until it becomes available, or until a specified
 * time limit is reached.
 *
 * A task is permitted to lock a mutex it has already locked; in such a case,
 * this routine immediately succeeds.
 *
 * @param mutex Mutex name.
 * @param timeout Determine the action to take when the mutex is already locked.
 *   For TICKS_NONE, return immediately.
 *   For TICKS_UNLIMITED, wait as long as necessary.
 *   Otherwise, wait up to the specified number of ticks before timing out.
 *
 * @retval RC_OK Successfully locked mutex.
 * @retval RC_TIME Timed out while waiting for mutex.
 * @retval RC_FAIL Failed to immediately lock mutex when
 * @a timeout = TICKS_NONE.
 *
 * @sa TICKS_NONE, TICKS_UNLIMITED
 */
static inline __deprecated int task_mutex_lock(kmutex_t mutex, int32_t timeout)
{
	return _error_to_rc(k_mutex_lock(mutex, _ticks_to_ms(timeout)));
}

/**
 * @brief Unlock mutex.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine unlocks mutex @a mutex. The mutex must already be locked by the
 * requesting task.
 *
 * The mutex cannot be claimed by another task until it has been unlocked by
 * the requesting task as many times as it was locked by that task.
 *
 * @param mutex Mutex name.
 *
 * @return N/A
 */
static inline __deprecated void task_mutex_unlock(kmutex_t mutex)
{
	k_mutex_unlock(mutex);
}

/**
 * @brief Define a private mutex.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @param name Mutex name.
 */
#define DEFINE_MUTEX(name) \
	K_MUTEX_DEFINE(_k_mutex_obj_##name); \
	struct k_mutex * const name = &_k_mutex_obj_##name

/* semaphores */

#define nano_sem k_sem
#define ksem_t struct k_sem *

/**
 * @brief Initialize a nanokernel semaphore object.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This function initializes a nanokernel semaphore object structure. After
 * initialization, the semaphore count is 0.
 *
 * It can be called from either a fiber or task.
 *
 * @param sem Pointer to a nano_sem structure.
 *
 * @return N/A
 */
static inline __deprecated void nano_sem_init(struct nano_sem *sem)
{
	k_sem_init(sem, 0, UINT_MAX);
}

/**
 * @brief Give a nanokernel semaphore.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine performs a "give" operation on a nanokernel sempahore object.
 *
 * It is also a convenience wrapper for the execution of context-specific
 * APIs and helpful when the exact execution context is not known. However,
 * it should be avoided when the context is known up-front to avoid unnecessary
 * overhead.
 *
 * @param sem Pointer to a nano_sem structure.
 *
 * @return N/A
 */

static inline __deprecated void nano_sem_give(struct nano_sem *sem)
{
	k_sem_give(sem);
}

/**
 * @brief Give a nanokernel semaphore (no context switch).
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_sem_give(), but may only be called from an ISR. A fiber
 * pending on the semaphore object will be made ready, but will NOT be
 * scheduled to execute.
 *
 * @param sem Pointer to a nano_sem structure.
 *
 * @sa nano_sem_give
 */

#define nano_isr_sem_give nano_sem_give

/**
 * @brief Give a nanokernel semaphore (no context switch).
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_sem_give(), but may only be called from a fiber.
 *
 * @param sem Pointer to a nano_sem structure.
 *
 * @sa nano_sem_give
 */

#define nano_fiber_sem_give nano_sem_give

/**
 * @brief Give a nanokernel semaphore.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_sem_give(), but may only be called from a task. A fiber pending
 * on the semaphore object will be made ready, and will preempt the running
 * task immediately.
 *
 * @param sem Pointer to a nano_sem structure.
 *
 * @sa nano_sem_give
 */

#define nano_task_sem_give nano_sem_give

/**
 * @brief Take a nanokernel semaphore, poll/pend if not available.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine performs a "give" operation on a nanokernel sempahore object.
 *
 * It is also a convenience wrapper for the execution of context-specific
 * APIs and is helpful when the exact execution context is not known. However,
 * it should be avoided when the context is known up-front to avoid unnecessary
 * overhead.
 *
 * @param sem Pointer to a nano_sem structure.
 * @param timeout_in_ticks Determines the action to take when the semaphore is
 *        unavailable.
 *        For TICKS_NONE, return immediately.
 *        For TICKS_UNLIMITED, wait as long as necessary.
 *        Otherwise, wait up to the specified number of ticks before timing
 *        out.
 *
 * @warning If it is to be called from the context of an ISR, then @a
 * timeout_in_ticks must be set to TICKS_NONE.
 *
 * @retval 1 When semaphore is available
 * @retval 0 Otherwise
 *
 * @sa TICKS_NONE, TICKS_UNLIMITED
 */
static inline __deprecated int nano_sem_take(struct nano_sem *sem,
					     int32_t timeout_in_ticks)
{
	int32_t ms = _ticks_to_ms(timeout_in_ticks);

	return k_sem_take((struct k_sem *)sem, ms) == 0 ? 1 : 0;
}

/**
 * @brief Take a nanokernel semaphore, fail if unavailable.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_sem_take(), but must only be called from an ISR with a timeout
 * of TICKS_NONE.
 *
 * @sa nano_sem_take
 */
#define nano_isr_sem_take  nano_sem_take

/**
 * @brief Take a nanokernel semaphore, wait or fail if unavailable.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_sem_take(), but may only be called from a fiber.
 *
 * @sa nano_sem_take
 */
#define nano_fiber_sem_take  nano_sem_take

/**
 * @brief Take a nanokernel semaphore, fail if unavailable.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_sem_take(), but may only be called from a task.
 *
 * @sa nano_sem_take
 */
#define nano_task_sem_take  nano_sem_take

/**
 * @brief Give semaphore from an ISR.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine gives semaphore @a sem from an ISR, rather than a task.
 *
 * @param sem Semaphore name.
 *
 * @return N/A
 */
#define isr_sem_give nano_sem_give

/**
 * @brief Give semaphore from a fiber.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine gives semaphore @a sem from a fiber, rather than a task.
 *
 * @param sem Semaphore name.
 *
 * @return N/A
 */
#define fiber_sem_give nano_sem_give

/**
 * @brief Give semaphore.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine gives semaphore @a sem.
 *
 * @param sem Semaphore name.
 *
 * @return N/A
 */
#define task_sem_give nano_sem_give

/**
 *
 * @brief Take a semaphore or fail.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine takes the semaphore @a sem. If the semaphore's count is
 * zero the routine immediately returns a failure indication.
 *
 * @param sem Semaphore name.
 * @param timeout Determines the action to take when the semaphore is
 *        unavailable.
 *        For TICKS_NONE, return immediately.
 *        For TICKS_UNLIMITED, wait as long as necessary.
 *        Otherwise, wait up to the specified number of ticks before timing out.
 *
 * @retval RC_OK Successfully took semaphore
 * @retval RC_TIME Timed out while waiting for semaphore
 * @retval RC_FAIL Failed to immediately take semaphore when
 *         @a timeout = TICKS_NONE
 *
 * @sa TICKS_NONE, TICKS_UNLIMITED
 */
static inline __deprecated int task_sem_take(ksem_t sem, int32_t timeout)
{
	return _error_to_rc(k_sem_take(sem, _ticks_to_ms(timeout)));
}

/**
 * @brief Reset the semaphore's count.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine resets the count of the semaphore @a sem to zero.
 *
 * @param sem Semaphore name.
 *
 * @return N/A
 */
static inline __deprecated void task_sem_reset(ksem_t sem)
{
	k_sem_reset(sem);
}

/**
 * @brief Read a semaphore's count.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine reads the current count of the semaphore @a sem.
 *
 * @param sem Semaphore name.
 *
 * @return Semaphore count.
 */
static inline __deprecated int task_sem_count_get(ksem_t sem)
{
	return k_sem_count_get(sem);
}

/**
 * @brief Read a nanokernel semaphore's count.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine reads the current count of the semaphore @a sem.
 *
 * @param sem Pointer to a nano_sem structure.
 *
 * @return Semaphore count.
 */
static inline __deprecated int nano_sem_count_get(ksem_t sem)
{
	return k_sem_count_get(sem);
}

#ifdef CONFIG_SEMAPHORE_GROUPS
/*
 * @internal Take the first available semaphore
 *
 * Given a list of semaphore pointers, this routine will attempt to take one
 * of them, waiting up to a maximum of @a timeout ms to do so. The taken
 * semaphore is identified by @a sem (set to NULL on error).
 *
 * Be aware that the more semaphores specified in the group, the more stack
 * space is required by the waiting thread.
 *
 * @param sem_array Array of semaphore pointers terminated by a K_END entry
 * @param sem Identifies the semaphore that was taken
 * @param timeout Number of milliseconds to wait if semaphores are unavailable,
 *                or one of the special values K_NO_WAIT and K_FOREVER.
 *
 * @retval 0 A semaphore was successfully taken
 * @retval -EBUSY No semaphore was available (@a timeout = K_NO_WAIT)
 * @retval -EAGAIN Time out occurred while waiting for semaphore
 */

extern int k_sem_group_take(struct k_sem *sem_array[], struct k_sem **sem,
			    int32_t timeout);

/*
 * @internal Give all the semaphores in the group
 *
 * This routine will give each semaphore in the array of semaphore pointers.
 *
 * @param sem_array Array of semaphore pointers terminated by a K_END entry
 *
 * @return N/A
 */
extern void k_sem_group_give(struct k_sem *sem_array[]);

/*
 * @internal Reset the count to zero on each semaphore in the array
 *
 * This routine resets the count of each semaphore in the group to zero.
 * Note that it does NOT have any impact on any thread that might have
 * been previously pending on any of the semaphores.
 *
 * @param sem_array Array of semaphore pointers terminated by a K_END entry
 *
 * @return N/A
 */
extern void k_sem_group_reset(struct k_sem *sem_array[]);

typedef ksem_t *ksemg_t;

/**
 * @brief Wait for a semaphore from the semaphore group.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine waits for the @a timeout ticks to take a semaphore from the
 * semaphore group @a group.
 *
 * @param group Array of semaphore names - terminated by ENDLIST.
 * @param timeout Determines the action to take when the semaphore is
 *        unavailable.
 *        For TICKS_NONE, return immediately.
 *        For TICKS_UNLIMITED, wait as long as necessary.
 *        Otherwise, wait up to the specified number of ticks before timing out.
 *
 * @retval Name of the semaphore that was taken if successful.
 * @retval ENDLIST Otherwise.
 *
 * @sa TICKS_NONE, TICKS_UNLIMITED
 */
static inline __deprecated ksem_t task_sem_group_take(ksemg_t group,
						      int32_t timeout)
{
	struct k_sem *sem;

	(void)k_sem_group_take(group, &sem, _ticks_to_ms(timeout));

	return sem;
}

/**
 * @brief Give a group of semaphores.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine gives each semaphore in a semaphore group @a semagroup.
 * This method is faster than giving the semaphores individually, and
 * ensures that all the semaphores are given before any waiting tasks run.
 *
 * @param semagroup Array of semaphore names - terminated by ENDLIST.
 *
 * @return N/A
 */
static inline __deprecated void task_sem_group_give(ksemg_t group)
{
	k_sem_group_give(group);
}

/**
 * @brief Reset a group of semaphores.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine resets the count for each semaphore in the sempahore group
 * @a semagroup to zero. This method is faster than resetting the semaphores
 * individually.
 *
 * @param semagroup Array of semaphore names - terminated by ENDLIST.
 *
 * @return N/A
 */
static inline __deprecated void task_sem_group_reset(ksemg_t group)
{
	k_sem_group_reset(group);
}
#endif

/**
 * @brief Define a private microkernel semaphore
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @param name Semaphore name.
 */
#define DEFINE_SEMAPHORE(name) \
	K_SEM_DEFINE(_k_sem_obj_##name, 0, UINT_MAX); \
	struct k_sem * const name = &_k_sem_obj_##name

/* workqueues */

#define nano_work k_work
#define work_handler_t k_work_handler_t

/**
 * A workqueue is a fiber that executes @ref nano_work items that are
 * queued to it.  This is useful for drivers which need to schedule
 * execution of code which might sleep from ISR context.  The actual
 * fiber identifier is not stored in the structure in order to save
 * space.
 */
#define nano_workqueue k_work_q

/**
 * @brief An item which can be scheduled on a @ref nano_workqueue with a delay
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 */
#define nano_delayed_work k_delayed_work

/**
 * @brief Initialize work item
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @param work  Work item to initialize
 * @param handler Handler to process work item
 *
 * @return N/A
 */
static inline void nano_work_init(struct nano_work *work,
				  work_handler_t handler)
{
	k_work_init(work, handler);
}

/**
 * @brief Submit a work item to a workqueue.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This procedure schedules a work item to be processed.
 * In the case where the work item has already been submitted and is pending
 * execution, calling this function will result in a no-op. In this case, the
 * work item must not be modified externally (e.g. by the caller of this
 * function), since that could cause the work item to be processed in a
 * corrupted state.
 *
 * @param wq Work queue
 * @param work Work item
 *
 * @return N/A
 */
static inline __deprecated void
nano_work_submit_to_queue(struct nano_workqueue *wq, struct nano_work *work)
{
	k_work_submit_to_queue(wq, work);
}

/**
 * @brief Start a new workqueue.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine can be called from either fiber or task context.
 *
 * @param wq Work queue
 * @param config Fiber configuration structure
 *
 * @return N/A
 */
static inline __deprecated void
nano_workqueue_start(struct nano_workqueue *wq,
		     const struct fiber_config *config)
{
	k_work_q_start(wq, config->stack, config->stack_size, config->prio);
}

/**
 * @brief Start a new workqueue.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Call this from task context.
 *
 * @sa nano_workqueue_start
 */
#define nano_task_workqueue_start nano_workqueue_start

/**
 * @brief Start a new workqueue.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Call this from fiber context.
 *
 * @sa nano_workqueue_start
 */
#define nano_fiber_workqueue_start nano_workqueue_start

#if CONFIG_SYS_CLOCK_EXISTS
/**
 * @brief Initialize delayed work
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @param work Work item
 * @param handler Handler to process work item
 *
 * @return N/A
 */
static inline __deprecated void
nano_delayed_work_init(struct nano_delayed_work *work, work_handler_t handler)
{
	k_delayed_work_init(work, handler);
}

/**
 * @brief Submit a delayed work item to a workqueue.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This procedure schedules a work item to be processed after a delay.
 * Once the delay has passed, the work item is submitted to the work queue:
 * at this point, it is no longer possible to cancel it. Once the work item's
 * handler is about to be executed, the work is considered complete and can be
 * resubmitted.
 *
 * Care must be taken if the handler blocks or yield as there is no implicit
 * mutual exclusion mechanism. Such usage is not recommended and if necessary,
 * it should be explicitly done between the submitter and the handler.
 *
 * @param wq Workqueue to schedule the work item
 * @param work Delayed work item
 * @param ticks Ticks to wait before scheduling the work item
 *
 * @return 0 in case of success or negative value in case of error.
 */
static inline __deprecated int
nano_delayed_work_submit_to_queue(struct nano_workqueue *wq,
				  struct nano_delayed_work *work, int ticks)
{
	return k_delayed_work_submit_to_queue(wq, work, _ticks_to_ms(ticks));
}

/**
 * @brief Cancel a delayed work item
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This procedure cancels a scheduled work item. If the work has been completed
 * or is idle, this will do nothing. The only case where this can fail is when
 * the work has been submitted to the work queue, but the handler has not run
 * yet.
 *
 * @param work Delayed work item to be canceled
 *
 * @return 0 in case of success or negative value in case of error.
 */
static inline __deprecated int
nano_delayed_work_cancel(struct nano_delayed_work *work)
{
	return k_delayed_work_cancel(work);
}
#endif

/**
 * @brief Submit a work item to the system workqueue.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @ref nano_work_submit_to_queue
 *
 * When using the system workqueue it is not recommended to block or yield
 * on the handler since its fiber is shared system wide it may cause
 * unexpected behavior.
 */
static inline __deprecated void nano_work_submit(struct nano_work *work)
{
	k_work_submit(work);
}

#if CONFIG_SYS_CLOCK_EXISTS
/**
 * @brief Submit a delayed work item to the system workqueue.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @ref nano_delayed_work_submit_to_queue
 *
 * When using the system workqueue it is not recommended to block or yield
 * on the handler since its fiber is shared system wide it may cause
 * unexpected behavior.
 */
#define nano_delayed_work_submit(work, ticks) \
	nano_delayed_work_submit_to_queue(&k_sys_work_q, work, ticks)
#endif
/** @cond INTERNAL_HIDDEN */
/* events */

#define kevent_t const struct k_alert *
typedef int (*kevent_handler_t)(int event);

/** @endcond */

/**
 * @brief Signal an event from an ISR.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine does @em not validate the specified event number.
 *
 * @param event Event to signal.
 *
 * @return N/A
 */
#define isr_event_send task_event_send

/**
 * @brief Signal an event from a fiber.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine does @em not validate the specified event number.
 *
 * @param event Event to signal.
 *
 * @return N/A
 */
#define fiber_event_send task_event_send

/**
 * @brief Set event handler request.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine specifies the event handler that runs in the context of the
 * microkernel server fiber when the associated event is signaled. Specifying
 * a non-NULL handler installs a new handler, while specifying a NULL event
 * handler removes the existing event handler.
 *
 * A new event handler cannot be installed if one already exists for that event.
 * The old handler must be removed first. However, the NULL event handler can be
 * replaced with itself.
 *
 * @param legacy_event Event upon which to register.
 * @param handler Function pointer to handler.
 *
 * @retval RC_FAIL If an event handler exists or the event number is invalid.
 * @retval RC_OK Otherwise.
 */
static inline __deprecated int
task_event_handler_set(kevent_t legacy_event, kevent_handler_t handler)
{
	struct k_alert *alert = (struct k_alert *)legacy_event;

	if ((alert->handler != NULL) && (handler != NULL)) {
		/* can't overwrite an existing event handler */
		return RC_FAIL;
	}

	alert->handler = (k_alert_handler_t)handler;
	return RC_OK;
}

/**
 * @brief Signal an event request.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine signals the specified event from a task. If an event handler
 * is installed for that event, it will run. If no event handler is installed,
 * any task waiting on the event is released.
 *
 * @param legacy_event Event to signal.
 *
 * @retval RC_FAIL If the event number is invalid.
 * @retval RC_OK Otherwise.
 */
static inline __deprecated int task_event_send(kevent_t legacy_event)
{
	k_alert_send((struct k_alert *)legacy_event);
	return RC_OK;
}

/**
 * @brief Test for an event request with timeout.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine tests an event to see if it has been signaled.
 *
 * @param legacy_event Event to test.
 * @param timeout Determines the action to take when the event has not yet
 *        been signaled.
 *        For TICKS_NONE, return immediately.
 *        For TICKS_UNLIMITED, wait as long as necessary.
 *        Otherwise, wait up to the specified number of ticks before
 *        timing out.
 *
 * @retval RC_OK Successfully received signaled event
 * @retval RC_TIME Timed out while waiting for signaled event
 * @retval RC_FAIL Failed to immediately receive signaled event when
 *                 timeout = TICKS_NONE
 */
static inline __deprecated int task_event_recv(kevent_t legacy_event,
					       int32_t timeout)
{
	return _error_to_rc(k_alert_recv((struct k_alert *)legacy_event,
					 _ticks_to_ms(timeout)));
}

/**
 * @brief Define a private microkernel event
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This declares and initializes a private event. The new event
 * can be passed to the microkernel event functions.
 *
 * @param name Name of the event
 * @param event_handler Function to handle the event (can be NULL)
 */
#define DEFINE_EVENT(name, event_handler) \
	K_ALERT_DEFINE(_k_event_obj_##name, event_handler, 1); \
	struct k_alert * const name = &(_k_event_obj_##name)

/* memory maps */

#define kmemory_map_t struct k_mem_slab *

/**
 * @brief Allocate memory map block.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine allocates a block from memory map @a map, and saves the
 * block's address in the area indicated by @a mptr. When no block is available,
 * the routine waits until either one can be allocated, or until the specified
 * time limit is reached.
 *
 * @param map Memory map name.
 * @param mptr Pointer to memory block address area.
 * @param timeout Determines the action to take when the memory map is
 *   exhausted.
 *   For TICKS_NONE, return immediately.
 *   For TICKS_UNLIMITED, wait as long as necessary.
 *   Otherwise, wait up to the specified number of ticks before timing out.
 *
 * @retval RC_OK Successfully allocated memory block.
 * @retval RC_TIME Timed out while waiting for memory block.
 * @retval RC_FAIL Failed to immediately allocate memory block when
 * @a timeout = TICKS_NONE.
 *
 * @sa TICKS_NONE, TICKS_UNLIMITED
 */
static inline __deprecated int
task_mem_map_alloc(kmemory_map_t map, void **mptr, int32_t timeout)
{
	return _error_to_rc(k_mem_slab_alloc(map, mptr,
			    _ticks_to_ms(timeout)));
}

/**
 * @brief Return memory slab block.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine returns a block to the specified memory slab.
 *
 * @param m Memory slab name.
 * @param p Memory block address.
 *
 * @return N/A
 */
static inline __deprecated void
task_mem_map_free(kmemory_map_t m, void **p)
{
	k_mem_slab_free(m, p);
}


/**
 * @brief Read the number of used blocks in a memory map.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine returns the number of blocks in use for the memory map.
 *
 * @param map Memory map name.
 *
 * @return Number of used blocks.
 */
static inline __deprecated int task_mem_map_used_get(kmemory_map_t map)
{
	return (int)k_mem_slab_num_used_get(map);
}

/**
 * @brief Define a private microkernel memory map.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @param name Memory map name.
 * @param map_num_blocks Number of blocks.
 * @param map_block_size Size of each block, in bytes.
 */
#define DEFINE_MEM_MAP(name, map_num_blocks, map_block_size) \
	K_MEM_SLAB_DEFINE(_k_mem_map_obj_##name, map_block_size, \
			  map_num_blocks, 4); \
	struct k_mem_slab *const name = &_k_mem_map_obj_##name


/* memory pools */

#define k_block k_mem_block
#define kmemory_pool_t struct k_mem_pool *
#define pool_struct k_mem_pool

/**
 * @brief Allocate memory pool block.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine allocates a block of at least @a reqsize bytes from memory pool
 * @a pool_id, and saves its information in block descriptor @a blockptr. When
 * no such block is available, the routine waits either until one can be
 * allocated, or until the specified time limit is reached.
 *
 * @param blockptr Pointer to block descriptor.
 * @param pool_id Memory pool name.
 * @param reqsize Requested block size, in bytes.
 * @param timeout Determines the action to take when the memory pool is
 *   exhausted.
 *   For TICKS_NONE, return immediately.
 *   For TICKS_UNLIMITED, wait as long as necessary.
 *   Otherwise, wait up to the specified number of ticks before timing out.
 *
 * @retval RC_OK Successfully allocated memory block
 * @retval RC_TIME Timed out while waiting for memory block
 * @retval RC_FAIL Failed to immediately allocate memory block when
 * @a timeout = TICKS_NONE
 *
 * @sa TICKS_NONE, TICKS_UNLIMITED
 */
static inline __deprecated int
task_mem_pool_alloc(struct k_block *blockptr, kmemory_pool_t pool_id,
		    int reqsize, int32_t timeout)
{
	return _error_to_rc(k_mem_pool_alloc(pool_id, blockptr, reqsize,
						_ticks_to_ms(timeout)));
}

/**
 * @brief Return memory pool block.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine returns a block to the memory pool from which it was allocated.
 *
 * @param block Pointer to block descriptor.
 *
 * @return N/A
 */
static inline __deprecated void task_mem_pool_free(struct k_block *block)
{
	k_mem_pool_free(block);
}

/**
 * @brief Defragment memory pool.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine concatenates unused blocks that can be merged in memory pool
 * @a p.
 *
 * Doing a full defragmentation of a memory pool before allocating a set
 * of blocks may be more efficient than having the pool do an implicit
 * partial defragmentation each time a block is allocated.
 *
 * @param pool Memory pool name.
 *
 * @return N/A
 */
static inline __deprecated void task_mem_pool_defragment(kmemory_pool_t pool)
{
	k_mem_pool_defrag(pool);
}

/**
 * @brief Allocate memory
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine  provides traditional malloc semantics and is a wrapper on top
 * of microkernel pool alloc API. It returns an aligned memory address which
 * points to the start of a memory block of at least \p size bytes.
 * This memory comes from heap memory pool, consequently the app should
 * specify its intention to use a heap pool via the HEAP_SIZE keyword in
 * MDEF file, if it uses this API.
 * When not enough free memory is available in the heap pool, it returns NULL
 *
 * @param size Size of memory requested by the caller.
 *
 * @retval address of the block if successful otherwise returns NULL
 */
static inline __deprecated void *task_malloc(uint32_t size)
{
	return k_malloc(size);
}

/**
 * @brief Free memory allocated through task_malloc
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine provides traditional free semantics and is intended to free
 * memory allocated using task_malloc API.
 *
 * @param ptr pointer to be freed
 *
 * @return NA
 */
static inline __deprecated void task_free(void *ptr)
{
	k_free(ptr);
}
/* message queues */

#define kfifo_t struct k_msgq *

/**
 * @brief FIFO enqueue request.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine adds an item to the FIFO queue. When the FIFO is full,
 * the routine will wait either for space to become available, or until the
 * specified time limit is reached.
 *
 * @param queue FIFO queue.
 * @param data Pointer to data to add to queue.
 * @param timeout Determines the action to take when the FIFO is full.
 * For TICKS_NONE, return immediately.
 * For TICKS_UNLIMITED, wait as long as necessary.
 * Otherwise, wait up to the specified number of ticks before timing out.
 *
 * @retval RC_OK Successfully added item to FIFO.
 * @retval RC_TIME Timed out while waiting to add item to FIFO.
 * @retval RC_FAIL Failed to immediately add item to FIFO when
 * @a timeout = TICKS_NONE.
 *
 * @sa TICKS_NONE, TICKS_UNLIMITED
 */
static inline __deprecated int task_fifo_put(kfifo_t queue, void *data,
					     int32_t timeout)
{
	return _error_to_rc(k_msgq_put(queue, data, _ticks_to_ms(timeout)));
}

/**
 * @brief FIFO dequeue request.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine fetches the oldest item from the FIFO queue. When the FIFO is
 * found empty, the routine will wait either until an item is added to the FIFO
 * queue or until the specified time limit is reached.
 *
 * @param queue FIFO queue.
 * @param data Pointer to storage location of the FIFO entry.
 * @param timeout Affects the action to take when the FIFO is empty.
 * For TICKS_NONE, return immediately.
 * For TICKS_UNLIMITED, wait as long as necessary.
 * Otherwise wait up to the specified number of ticks before timing out.
 *
 * @retval RC_OK Successfully fetched item from FIFO.
 * @retval RC_TIME Timed out while waiting to fetch item from FIFO.
 * @retval RC_FAIL Failed to immediately fetch item from FIFO when
 * @a timeout = TICKS_NONE.
 *
 * @sa TICKS_NONE, TICKS_UNLIMITED
 */
static inline __deprecated int task_fifo_get(kfifo_t queue, void *data,
					     int32_t timeout)
{
	return _error_to_rc(k_msgq_get(queue, data, _ticks_to_ms(timeout)));
}

/**
 * @brief Purge the FIFO of all its entries.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @param queue FIFO queue.
 *
 * @return RC_OK on purge.
 */
static inline __deprecated int task_fifo_purge(kfifo_t queue)
{
	k_msgq_purge(queue);
	return RC_OK;
}

/**
 * @brief Query the number of FIFO entries.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @param queue FIFO queue.
 *
 * @return # of FIFO entries on query.
 */
static inline __deprecated int task_fifo_size_get(kfifo_t queue)
{
	return queue->used_msgs;
}

/**
 * @brief Define a private microkernel FIFO.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This declares and initializes a private FIFO. The new FIFO
 * can be passed to the microkernel FIFO functions.
 *
 * @param name Name of the FIFO.
 * @param q_depth Depth of the FIFO.
 * @param q_width Width of the FIFO.
 */
#define DEFINE_FIFO(name, q_depth, q_width) \
	K_MSGQ_DEFINE(_k_fifo_obj_##name, q_width, q_depth, 4); \
	struct k_msgq * const name = &_k_fifo_obj_##name

/* mailboxes */

#define kmbox_t struct k_mbox *

struct k_msg {
	/** Mailbox ID */
	kmbox_t mailbox;
	/** size of message (bytes) */
	uint32_t size;
	/** information field, free for user   */
	uint32_t info;
	/** pointer to message data at sender side */
	void *tx_data;
	/** pointer to message data at receiver    */
	void *rx_data;
	/** for async message posting   */
	struct k_block tx_block;
	/** sending task */
	ktask_t tx_task;
	/** receiving task */
	ktask_t rx_task;
	/** internal use only */
	union {
		/** for 2-steps data transfer operation */
		struct k_args *transfer;
		/** semaphore to signal when asynchr. call */
		ksem_t sema;
	} extra;
};

/**
 * @brief Send a message to a mailbox.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine sends a message to a mailbox and looks for a matching receiver.
 *
 * @param mbox Mailbox.
 * @param prio Priority of data transfer.
 * @param msg Pointer to message to send.
 * @param timeout Determines the action to take when there is no waiting
 * receiver.
 * For TICKS_NONE, return immediately.
 * For TICKS_UNLIMITED, wait as long as necessary.
 * Otherwise, wait up to the specified number of ticks before timing out.
 *
 * @return RC_OK Successfully delivered message.
 * @return RC_TIME Timed out while waiting to deliver message.
 * @return RC_FAIL Failed to immediately deliver message when
 * @a timeout = TICKS_NONE.
 *
 * @sa TICKS_NONE, TICKS_UNLIMITED
 */
__deprecated int task_mbox_put(kmbox_t mbox, kpriority_t prio,
			       struct k_msg *msg, int32_t timeout);

/**
 * @brief Send a message asynchronously to a mailbox.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine sends a message to a mailbox and does not wait for a matching
 * receiver. No exchange header is returned to the sender. When the data
 * has been transferred to the receiver, the semaphore signaling is performed.
 *
 * @param mbox Mailbox to which to send message.
 * @param prio Priority of data transfer.
 * @param msg Pointer to message to send.
 * @param sema Semaphore to signal when transfer is complete.
 *
 * @return N/A
 */
__deprecated void task_mbox_block_put(kmbox_t mbox, kpriority_t prio,
				      struct k_msg *msg, ksem_t sema);

/**
 * @brief Get @b struct @b k_msg message header structure information from
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 * a mailbox and wait with timeout.
 *
 * @param mbox Mailbox.
 * @param msg Pointer to message.
 * @param timeout Determines the action to take when there is no waiting
 * receiver.
 * For TICKS_NONE, return immediately.
 * For TICKS_UNLIMITED, wait as long as necessary.
 * Otherwise, wait up to the specified number of ticks before timing out.
 *
 * @return RC_OK Successfully received message.
 * @return RC_TIME Timed out while waiting to receive message.
 * @return RC_FAIL Failed to immediately receive message when
 * @a timeout = TICKS_NONE.
 *
 * @sa TICKS_NONE, TICKS_UNLIMITED
 */
__deprecated int task_mbox_get(kmbox_t mbox, struct k_msg *msg,
			       int32_t timeout);

/**
 * @brief Get message data.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Call this routine for one of two reasons:
 * 1. To transfer data when the call to @b task_mbox_get() yields an existing
 *    field in the @b struct @b k_msg header structure.
 * 2. To wake up and release a transmitting task currently blocked from calling
 *    @b task_mbox_put().
 *
 * @param msg Message from which to get data.
 *
 * @return N/A
 */
__deprecated void task_mbox_data_get(struct k_msg *msg);

/**
 * @brief Retrieve message data into a block, with time-limited waiting.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @param msg Message from which to get data.
 * @param block Block.
 * @param pool_id Memory pool name.
 * @param timeout Determines the action to take when no waiting sender exists.
 * For TICKS_NONE, return immediately.
 * For TICKS_UNLIMITED, wait as long as necessary.
 * Otherwise, wait up to the specified number of ticks before timing out.
 *
 * @retval RC_OK Successful retrieval of message data.
 * @retval RC_TIME Timed out while waiting to receive message data.
 * @retval RC_FAIL Failed to immediately receive message data when
 * @a timeout = TICKS_NONE.
 *
 * @sa TICKS_NONE, TICKS_UNLIMITED
 */
__deprecated int
task_mbox_data_block_get(struct k_msg *msg, struct k_block *block,
			 kmemory_pool_t pool_id, int32_t timeout);

/**
 * @brief Define a private microkernel mailbox.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine declares and initializes a private mailbox. The new mailbox
 * can be passed to the microkernel mailbox functions.
 *
 * @param name Name of the mailbox
 */
#define DEFINE_MAILBOX(name) \
	K_MBOX_DEFINE(_k_mbox_obj_##name); \
	struct k_mbox * const name = &_k_mbox_obj_##name

/* pipes */

#define kpipe_t struct k_pipe *

/**
 * @brief Pipe write request.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Attempt to write data from a memory-buffer area to the
 * specified pipe with a timeout option.
 *
 * @param id Pipe ID.
 * @param buffer Buffer.
 * @param bytes_to_write Number of bytes to write.
 * @param bytes_written Pointer to number of bytes written.
 * @param options Pipe options.
 * @param timeout Determines the action to take when the pipe is already full.
 *  For TICKS_NONE, return immediately.
 *  For TICKS_UNLIMITED, wait as long as necessary.
 *  Otherwise, wait up to the specified number of ticks before timing out.
 *
 * @retval RC_OK Successfully wrote data to pipe.
 * @retval RC_ALIGNMENT Data is improperly aligned.
 * @retval RC_INCOMPLETE Only some of the data was written to the pipe when
 * @a options = _ALL_N.
 * @retval RC_TIME Timed out while waiting to write to pipe.
 * @retval RC_FAIL Failed to immediately write to pipe when
 * @a timeout = TICKS_NONE
 *
 * @sa TICKS_NONE, TICKS_UNLIMITED
 */
static inline __deprecated int
task_pipe_put(kpipe_t id, void *buffer, int bytes_to_write, int *bytes_written,
	      K_PIPE_OPTION options, int32_t timeout)
{
	size_t  min_xfer = (size_t)options;

	__ASSERT((options == _0_TO_N) ||
		 (options == _1_TO_N) ||
		 (options == _ALL_N), "Invalid pipe option");

	*bytes_written = 0;

	if (bytes_to_write == 0) {
		return RC_FAIL;
	}

	if ((options == _0_TO_N) && (timeout != K_NO_WAIT)) {
		return RC_FAIL;
	}

	if (options == _ALL_N) {
		min_xfer = bytes_to_write;
	}

	return _error_to_rc(k_pipe_put(id, buffer, bytes_to_write,
					(size_t *)bytes_written, min_xfer,
					_ticks_to_ms(timeout)));
}

/**
 * @brief Pipe read request.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Attempt to read data into a memory buffer area from the
 * specified pipe with a timeout option.
 *
 * @param id Pipe ID.
 * @param buffer Buffer.
 * @param bytes_to_read Number of bytes to read.
 * @param bytes_read Pointer to number of bytes read.
 * @param options Pipe options.
 * @param timeout Determines the action to take when the pipe is already full.
 *  For TICKS_NONE, return immediately.
 *  For TICKS_UNLIMITED, wait as long as necessary.
 *  Otherwise, wait up to the specified number of ticks before timing out.
 *
 * @retval RC_OK Successfully read data from pipe.
 * @retval RC_ALIGNMENT Data is improperly aligned.
 * @retval RC_INCOMPLETE Only some of the data was read from the pipe when
 * @a options = _ALL_N.
 * @retval RC_TIME Timed out waiting to read from pipe.
 * @retval RC_FAIL Failed to immediately read from pipe when
 * @a timeout = TICKS_NONE.
 *
 * @sa TICKS_NONE, TICKS_UNLIMITED
 */
static inline __deprecated int
task_pipe_get(kpipe_t id, void *buffer, int bytes_to_read, int *bytes_read,
	      K_PIPE_OPTION options, int32_t timeout)
{
	size_t  min_xfer = (size_t)options;

	__ASSERT((options == _0_TO_N) ||
		 (options == _1_TO_N) ||
		 (options == _ALL_N), "Invalid pipe option");

	*bytes_read = 0;

	if (bytes_to_read == 0) {
		return RC_FAIL;
	}

	if ((options == _0_TO_N) && (timeout != K_NO_WAIT)) {
		return RC_FAIL;
	}

	if (options == _ALL_N) {
		min_xfer = bytes_to_read;
	}

	return _error_to_rc(k_pipe_get(id, buffer, bytes_to_read,
					(size_t *)bytes_read, min_xfer,
					_ticks_to_ms(timeout)));
}

#if CONFIG_NUM_PIPE_ASYNC_MSGS > 0
/**
 * @brief Send a block of data asynchronously to a pipe
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine asynchronously sends a message from the pipe specified by
 * @a id. Once all @a size bytes have been accepted by the pipe, it will
 * free the memory block @a block and give the semaphore @a sem (if specified).
 *
 * @param id Pipe ID.
 * @param block Memory block containing data to send
 * @param size Number of data bytes in memory block to send
 * @param sem Semaphore to signal upon completion
 *
 * @retval RC_OK Successfully sent data to the pipe.
 * @retval RC_FAIL Block size is zero
 */
static inline __deprecated int
task_pipe_block_put(kpipe_t id, struct k_block block, int size, ksem_t sem)
{
	if (size == 0) {
		return RC_FAIL;
	}

	k_pipe_block_put(id, &block, size, sem);

	return RC_OK;
}
#endif /* CONFIG_NUM_PIPE_ASYNC_MSGS > 0 */

/**
 * @brief Define a private microkernel pipe.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @param name Name of the pipe.
 * @param pipe_buffer_size Size of the pipe buffer (in bytes)
 */
#define DEFINE_PIPE(name, pipe_buffer_size) \
	K_PIPE_DEFINE(_k_pipe_obj_##name, pipe_buffer_size, 4); \
	struct k_pipe * const name = &_k_pipe_obj_##name

#define nano_fifo k_fifo

/**
 * @brief Initialize a nanokernel FIFO (fifo) object.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This function initializes a nanokernel FIFO (fifo) object
 * structure.
 *
 * It can be called from either a fiber or task.
 *
 * @param fifo FIFO to initialize.
 *
 * @return N/A
 */
static inline __deprecated void nano_fifo_init(struct nano_fifo *fifo)
{
	k_fifo_init(fifo);
}

/* nanokernel fifos */

/**
 * @brief Add an element to the end of a FIFO.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine is a convenience wrapper for the execution of context-specific
 * APIs. It is helpful when the exact execution context is not known. However,
 * it should be avoided when the context is known up-front to avoid unnecessary
 * overhead.
 *
 * FIFO data items must be aligned on a 4-byte boundary, as the kernel reserves
 * the first 32 bits of each item for use as a pointer to the next data item in
 * the FIFO's link list.  Each data item added to the FIFO must include and
 * reserve these first 32 bits.
 *
 * @param fifo FIFO on which to interact.
 * @param data Data to send.
 *
 * @return N/A
 */
static inline __deprecated void nano_fifo_put(struct nano_fifo *fifo,
					      void *data)
{
	k_fifo_put(fifo, data);
}

/**
 * @brief Add an element to the end of a FIFO from an ISR context.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_fifo_put(), but may only be called from an ISR.
 *
 * @sa nano_fifo_put
 */
#define nano_isr_fifo_put nano_fifo_put

/**
 * @brief Add an element to the end of a FIFO from a fiber.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_fifo_put(), but may only be called from a fiber.
 *
 * @sa nano_fifo_put
 */
#define nano_fiber_fifo_put nano_fifo_put

/**
 * @brief Add an element to the end of a FIFO.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_fifo_put(), but may only be called from a task.
 *
 * @sa nano_fifo_put
 */
#define nano_task_fifo_put nano_fifo_put

#ifdef KERNEL /* XXX ztest layer redefines to a different function */
/**
 * @brief Atomically add a list of elements to the end of a FIFO.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine adds a list of elements in one shot to the end of a FIFO
 * object. If fibers are pending on the FIFO object, they become ready to run.
 * If this API is called from a task, the highest priority one will preempt the
 * running task once the put operation is complete.
 *
 * If enough fibers are waiting on the FIFO, the address of each element given
 * to fibers is returned to the waiting fiber. The remaining elements are
 * linked to the end of the list.
 *
 * The list must be a singly-linked list, where each element only has a pointer
 * to the next one. The list must be NULL-terminated.
 *
 * Unlike the fiber/ISR versions of this API which is not much different
 * conceptually than calling nano_fifo_put once for each element to queue, the
 * behaviour is indeed different for tasks. There is no context switch being
 * done for each element queued, so the task can enqueue all elements without
 * being interrupted by a fiber being woken up.
 *
 * This routine is a convenience wrapper for the execution of context-specific
 * APIs. It is helpful when the exact execution context is not known. However,
 * it should be avoided when the context is known up-front to avoid unnecessary
 * overhead.
 *
 * @param fifo FIFO on which to interact.
 * @param head head of singly-linked list
 * @param tail tail of singly-linked list
 *
 * @return N/A
 *
 * @sa nano_fifo_put_slist, nano_isr_fifo_put_list, nano_fiber_fifo_put_list,
 *     nano_task_fifo_put_list
 */
static inline __deprecated void
nano_fifo_put_list(struct nano_fifo *fifo, void *head, void *tail)
{
	k_fifo_put_list(fifo, head, tail);
}
#else
void nano_fifo_put_list(struct nano_fifo *fifo, void *head, void *tail);
#endif

/**
 * @brief Atomically add a list of elements to the end of a FIFO from an ISR.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_fifo_put_list(), but may only be called from an ISR.
 *
 * @sa nano_fifo_put_list
 */
#define nano_isr_fifo_put_list nano_fifo_put_list

/**
 *
 * @brief Atomically add a list of elements to the end of a FIFO from a fiber.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_fifo_put_list(), but may only be called from a fiber.
 *
 * @sa nano_fifo_put_list
 */
#define nano_fiber_fifo_put_list nano_fifo_put_list

/**
 * @brief Atomically add a list of elements to the end of a FIFO from a fiber.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_fifo_put_list(), but may only be called from a task.
 *
 * @sa nano_fifo_put_list
 */
#define nano_task_fifo_put_list nano_fifo_put_list

/**
 * @brief Atomically add a list of elements to the end of a FIFO.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * See nano_fifo_put_list for the description of the behaviour.
 *
 * It takes a pointer to a sys_slist_t object instead of the head and tail of a
 * custom singly-linked list. The sys_slist_t object is invalid afterwards and
 * must be re-initialized via sys_slist_init().
 *
 * This routine is a convenience wrapper for the execution of context-specific
 * APIs. It is helpful when the exact execution context is not known. However,
 * it should be avoided when the context is known up-front to avoid unnecessary
 * overhead.
 *
 * @param fifo FIFO on which to interact.
 * @param list pointer to singly-linked list
 *
 * @return N/A
 *
 * @sa nano_fifo_put_list, nano_isr_fifo_put_slist, nano_fiber_fifo_put_slist,
 *     nano_task_fifo_put_slist
 */
static inline __deprecated void
nano_fifo_put_slist(struct nano_fifo *fifo, sys_slist_t *list)
{
	k_fifo_put_slist(fifo, list);
}

/**
 * @brief Atomically add a list of elements to the end of a FIFO from an ISR.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_fifo_put_slist(), but may only be called from an ISR.
 *
 * @sa nano_fifo_put_slist
 */
#define nano_isr_fifo_put_slist nano_fifo_put_slist

/**
 * @brief Atomically add a list of elements to the end of a FIFO from a fiber.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_fifo_put_slist(), but may only be called from a fiber.
 *
 * @sa nano_fifo_put_slist
 */
#define nano_fiber_fifo_put_slist nano_fifo_put_slist

/**
 * @brief Atomically add a list of elements to the end of a FIFO from a fiber.
 *
 * Like nano_fifo_put_slist(), but may only be called from a fiber.
 *
 * @sa nano_fifo_put_slist
 */
#define nano_task_fifo_put_slist nano_fifo_put_slist

#ifdef KERNEL /* ztest layer redefines to a different function */
/**
 * @brief Get an element from the head a FIFO.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine is a convenience wrapper for the execution of context-specific
 * APIs. It is helpful when the exact execution context is not known. However,
 * it should be avoided when the context is known up-front to avoid unnecessary
 * overhead.
 *
 * If no element is available, the function returns NULL. The first word in
 * the element contains invalid data because its memory location was used to
 * store a pointer to the next element in the linked list.
 *
 * @param fifo FIFO on which to interact.
 * @param timeout_in_ticks Affects the action taken should the FIFO be empty.
 * If TICKS_NONE, then return immediately. If TICKS_UNLIMITED, then wait as
 * long as necessary. Otherwise, wait up to the specified number of ticks
 * before timing out.
 *
 * @warning If it is to be called from the context of an ISR, then @a
 * timeout_in_ticks must be set to TICKS_NONE.
 *
 * @return Pointer to head element in the list when available.
 *         NULL Otherwise.
 *
 * @sa TICKS_NONE, TICKS_UNLIMITED
 */
static inline __deprecated void *nano_fifo_get(struct nano_fifo *fifo,
					       int32_t timeout_in_ticks)
{
	return k_fifo_get((struct k_fifo *)fifo,
			  _ticks_to_ms(timeout_in_ticks));
}
#else
void __deprecated *nano_fifo_get(struct nano_fifo *fifo,
				 int32_t timeout_in_ticks);
#endif /* KERNEL */

/**
 * @brief Get an element from the head of a FIFO from an ISR context.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_fifo_get(), but may only be called from an ISR with a timeout
 * of TICKS_NONE.
 *
 * @sa nano_fifo_get
 */
#define nano_isr_fifo_get nano_fifo_get

/**
 * @brief Get an element from the head of a FIFO from a fiber.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_fifo_get(), but may only be called from a fiber.
 *
 * @sa nano_fifo_get
 */
#define nano_fiber_fifo_get nano_fifo_get

/**
 * @brief Get an element from a FIFO's head that comes from a task, poll if
 * empty.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_fifo_get(), but may only be called from a task.
 *
 * @sa nano_fifo_get
 */
#define nano_task_fifo_get nano_fifo_get

/* nanokernel lifos */

#define nano_lifo k_lifo

/**
 * @brief Initialize a nanokernel linked list LIFO (lifo) object.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This function initializes a nanokernel system-level linked list LIFO
 * (lifo) object structure.
 *
 * It is called from either a fiber or task.
 *
 * @param lifo LIFO to initialize.
 *
 * @return N/A
 */
static inline __deprecated void nano_lifo_init(struct nano_lifo *lifo)
{
	k_lifo_init(lifo);
}

/**
 * @brief Prepend an element to a LIFO.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine adds an element to the LIFOs' object head
 *
 * This routine is a convenience wrapper for the execution of context-specific
 * APIs. It is helpful when the exact execution context is not known. However,
 * it should be avoided when the context is known up-front to avoid unnecessary
 * overhead.
 *
 * @param lifo LIFO on which to put.
 * @param data Data to insert.
 *
 * @return N/A
 */
static inline __deprecated void
nano_lifo_put(struct nano_lifo *lifo, void *data)
{
	k_lifo_put(lifo, data);
}

/**
 * @brief Prepend an element to a LIFO without a context switch.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_lifo_put(), but may only be called from an ISR. A fiber
 * pending on the LIFO object will be made ready, but will NOT be scheduled
 * to execute.
 *
 * @sa nano_lifo_put
 */
#define nano_isr_lifo_put nano_lifo_put

/**
 * @brief Prepend an element to a LIFO without a context switch.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_lifo_put(), but may only be called from a fiber. A fiber
 * pending on the LIFO object will be made ready, but will NOT be scheduled
 * to execute.
 *
 * @sa nano_lifo_put
 */
#define nano_fiber_lifo_put nano_lifo_put

/**
 * @brief Add an element to the LIFO's linked list head.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_lifo_put(), but may only be called from a task. A fiber
 * pending on the LIFO object will be made ready, and will preempty the
 * running task immediately.
 *
 * @sa nano_lifo_put
 */
#define nano_task_lifo_put nano_lifo_put

/**
 * @brief Get the first element from a LIFO.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine is a convenience wrapper for the execution of context-specific
 * APIs. It is helpful when the exact execution context is not known. However,
 * it should be avoided when the context is known up-front to avoid unnecessary
 * overhead.
 *
 * @param lifo LIFO on which to receive.
 * @param timeout_in_ticks Affects the action taken should the LIFO be empty.
 * If TICKS_NONE, then return immediately. If TICKS_UNLIMITED, then wait as
 * long as necesssary. Otherwise wait up to the specified number of ticks
 * before timing out.
 *
 * @warning If it is to be called from the context of an ISR, then @a
 * timeout_in_ticks must be set to TICKS_NONE.
 *
 * @return Pointer to head element in the list when available.
 *         NULL Otherwise.
 *
 * @sa TICKS_NONE, TICKS_UNLIMITED
 */
static inline __deprecated void *nano_lifo_get(struct nano_lifo *lifo,
					       int32_t timeout_in_ticks)
{
	return k_lifo_get((struct k_lifo *)lifo,
			  _ticks_to_ms(timeout_in_ticks));
}

/**
 * @brief Remove the first element from a LIFO linked list.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_lifo_get(), but may only be called from an ISR with a timeout
 * of TICKS_NONE.
 *
 * @sa nano_lifo_get
 */
#define nano_isr_lifo_get nano_lifo_get

/**
 * @brief Prepend an element to a LIFO without a context switch.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_lifo_get(), but may only be called from a fiber.
 *
 * @sa nano_lifo_get
 */
#define nano_fiber_lifo_get nano_lifo_get

/**
 * @brief Remove the first element from a LIFO linked list.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_lifo_get(), but may only be called from a task.
 *
 * @sa nano_lifo_get
 */
#define nano_task_lifo_get nano_lifo_get

/* nanokernel stacks */

#define nano_stack k_stack

/**
 * @brief Initialize a nanokernel stack object.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This function initializes a nanokernel stack object structure.
 *
 * It is called from either a fiber or a task.
 *
 * @return N/A
 */
static inline __deprecated void nano_stack_init(struct nano_stack *stack,
						uint32_t *data)
{
	int entries;

	/* use max possible number of entries */
	entries = min(INT_MAX, UINTPTR_MAX - (uint32_t)data) / sizeof(*data);

	k_stack_init(stack, data, entries);
}

/**
 * @brief Push data onto a stack.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine pushes a data item onto a stack object. It is a convenience
 * wrapper for the execution of context-specific APIs and is helpful when
 * the exact execution context is not known. However, it should be avoided
 * when the context is known up-front to avoid unnecessary overhead.
 *
 * @param stack Stack on which to interact.
 * @param data Data to push on stack.
 *
 * @return N/A
 */
static inline __deprecated void
nano_stack_push(struct nano_stack *stack, uint32_t data)
{
	k_stack_push(stack, data);
}

/**
 * @brief Push data onto a stack (no context switch).
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_stack_push(), but may only be called from an ISR. A fiber that
 * pends on the stack object becomes ready but will NOT be scheduled to execute.
 *
 * @sa nano_stack_push
 */
#define nano_isr_stack_push nano_stack_push

/**
 * @brief Push data onto a stack (no context switch).
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_stack_push(), but may only be called from a fiber. A fiber that
 * pends on the stack object becomes ready but will NOT be scheduled to execute.
 *
 * @sa nano_stack_push
 */
#define nano_fiber_stack_push nano_stack_push

/**
 * @brief Push data onto a nanokernel stack.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_stack_push(), but may only be called from a task. A fiber that
 * pends on the stack object becomes ready and preempts the running task
 * immediately.
 *
 * @sa nano_stack_push
 */
#define nano_task_stack_push nano_stack_push

/**
 * @brief Pop data off a stack.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine pops the first data word from a nanokernel stack object.
 * It is a convenience wrapper for the execution of context-specific APIs
 * and is helpful when the exact execution context is not known. However,
 * it should be avoided when the context is known up-front to avoid unnecessary
 * overhead.
 *
 * When the stack is not empty, a data word is popped and copied to the
 * provided address @a data and a non-zero value is returned. When the routine
 * finds an empty stack, zero is returned.
 *
 * @param stack Stack on which to interact.
 * @param data Container for data to pop
 * @param timeout_in_ticks Determines the action to take when the FIFO
 *        is empty.
 *        For TICKS_NONE, return immediately.
 *        For TICKS_UNLIMITED, wait as long as necessary.
 *        Otherwise, wait up to the specified number of ticks before timing
 *        out.
 *
 * @retval 1 When data is popped from the stack.
 * @retval 0 Otherwise.
 */
static inline __deprecated int
nano_stack_pop(struct nano_stack *stack, uint32_t *data,
	       int32_t timeout_in_ticks)
{
	return k_stack_pop((struct k_stack *)stack, data,
			   _ticks_to_ms(timeout_in_ticks)) == 0 ? 1 : 0;
}

/**
 * @brief Pop data from a nanokernel stack.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_stack_pop(), but may only be called from an ISR.
 *
 * @sa nano_stack_pop
 */
#define nano_isr_stack_pop nano_stack_pop

/**
 * @brief Pop data from a nanokernel stack.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_stack_pop(), but may only be called from a fiber.
 *
 * @sa nano_stack_pop
 */
#define nano_fiber_stack_pop nano_stack_pop

/**
 * @brief Pop data from a nanokernel stack.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_stack_pop(), but may only be called from a task.
 *
 * @sa nano_stack_pop
 */
#define nano_task_stack_pop nano_stack_pop

/**
 * @brief Return the current system tick count.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @return The current system tick count.
 */
extern __deprecated int64_t sys_tick_get(void);

/**
 * @brief Return the lower part of the current system tick count.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @return The current system tick count.
 */
extern __deprecated uint32_t sys_tick_get_32(void);

/**
 * @brief Return number of ticks elapsed since a reference time.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @param reftime Reference time.
 *
 * @return The tick count since reference time; undefined for first invocation.
 */
extern __deprecated int64_t sys_tick_delta(int64_t *reftime);

/**
 *
 * @brief Return 32-bit number of ticks since a reference time.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @param reftime Reference time.
 *
 * @return A 32-bit tick count since reference time. Undefined for first
 *         invocation.
 */
extern __deprecated uint32_t sys_tick_delta_32(int64_t *reftime);

/**
 * @brief Return a time stamp in high-resolution format.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine reads the counter register on the processor's high precision
 * timer device. This counter register increments at a relatively high rate
 * (e.g. 20 MHz), and is thus considered a high-resolution timer. This is
 * in contrast to sys_tick_get_32() which returns the value of the system
 * ticks variable.
 *
 * @return The current high-precision clock value.
 */
#define sys_cycle_get_32 k_cycle_get_32

/* microkernel timers */

#if (CONFIG_NUM_DYNAMIC_TIMERS > 0)

#define CONFIG_NUM_TIMER_PACKETS CONFIG_NUM_DYNAMIC_TIMERS

#define ktimer_t struct k_timer *

/**
 * @brief Allocate a timer and return its object identifier.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * @return timer identifier
 */
extern __deprecated ktimer_t task_timer_alloc(void);

/**
 * @brief Deallocate a timer
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine frees the resources associated with the timer.  If a timer was
 * started, it has to be stopped using task_timer_stop() before it can be freed.
 *
 * @param timer   Timer to deallocate.
 *
 * @return N/A
 */
extern __deprecated void task_timer_free(ktimer_t timer);

/**
 * @brief Start or restart the specified low-resolution timer
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine starts or restarts the specified low-resolution timer.
 *
 * Signals the semaphore after a specified number of ticks set by
 * @a duration expires. The timer repeats the expiration/signal cycle
 * each time @a period ticks elapses.
 *
 * Setting @a period to 0 stops the timer at the end of the initial delay.

 * If either @a duration or @a period is passed an invalid value
 * (@a duration <= 0, * @a period < 0), this kernel API acts like a
 * task_timer_stop(): if the allocated timer was still running (from a
 * previous call), it will be cancelled; if not, nothing will happen.
 *
 * @param timer      Timer to start.
 * @param duration   Initial delay in ticks.
 * @param period     Repetition interval in ticks.
 * @param sema       Semaphore to signal.
 *
 * @return N/A
 */
extern __deprecated void
task_timer_start(ktimer_t timer, int32_t duration, int32_t period, ksem_t sema);

/**
 * @brief Restart a timer
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine restarts the timer specified by @a timer. The timer must
 * have previously been started by a call to task_timer_start().
 *
 * @param timer      Timer to restart.
 * @param duration   Initial delay.
 * @param period     Repetition interval.
 *
 * @return N/A
 */
static inline __deprecated void
task_timer_restart(ktimer_t timer, int32_t duration, int32_t period)
{
	k_timer_start(timer, _ticks_to_ms(duration), _ticks_to_ms(period));
}

/**
 * @brief Stop a timer
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine stops the specified timer. If the timer period has already
 * elapsed, the call has no effect.
 *
 * @param timer   Timer to stop.
 *
 * @return N/A
 */
static inline __deprecated void task_timer_stop(ktimer_t timer)
{
	k_timer_stop(timer);
}

#endif /* CONFIG_NUM_DYNAMIC_TIMERS > 0 */

/* nanokernel timers */

#define nano_timer k_timer

/**
 * @brief Initialize a nanokernel timer object.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This function initializes a nanokernel timer object structure.
 *
 * It can be called from either a fiber or task.
 *
 * The @a data passed to this function is a pointer to a data structure defined
 * by the user. It contains data that the user wishes to store when initializing
 * the timer and recover when the timer expires. However, the first field of
 * this data structure must be a pointer reserved for the API's use that can be
 * overwritten by the API and, as such, should not contain user data.
 *
 * @param timer Timer.
 * @param data User Data.
 *
 * @return N/A
 */
static inline __deprecated void
nano_timer_init(struct k_timer *timer, void *data)
{
	k_timer_init(timer, NULL, NULL);
	timer->user_data = data;
}

/**
 * @brief Start a nanokernel timer.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine starts a previously initialized nanokernel timer object. The
 * timer will expire in @a ticks system clock ticks. It is also a convenience
 * wrapper for the execution of context-specific APIs and is helpful when the
 * the exact execution context is not known. However, it should be avoided when
 * the context is known up-front to avoid unnecessary overhead.
 *
 * @param timer Timer.
 * @param ticks Number of ticks.
 *
 * @return N/A
 */
static inline __deprecated void
nano_timer_start(struct nano_timer *timer, int ticks)
{
	k_timer_start(timer, _ticks_to_ms(ticks), 0);
}

/**
 * @brief Start a nanokernel timer from an ISR.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_timer_start(), but may only be called from an ISR with a
 * timeout of TICKS_NONE.
 *
 * @sa nano_timer_start
 */
#define nano_isr_timer_start nano_timer_start

/**
 * @brief Start a nanokernel timer from a fiber.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_timer_start(), but may only be called from a fiber.
 *
 * @sa nano_timer_start
 */
#define nano_fiber_timer_start nano_timer_start

/**
 * @brief Start a nanokernel timer from a task.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_timer_start(), but may only be called from a task.
 *
 * @sa nano_timer_start
 */
#define nano_task_timer_start nano_timer_start

/**
 * @brief Wait for a nanokernel timer to expire.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine checks if a previously started nanokernel timer object has
 * expired. It is also a convenience wrapper for the execution of context-
 * specific APIs. It is helpful when the exact execution context is not known.
 * However, it should be avoided when the context is known up-front to avoid
 * unnecessary overhead.
 *
 * @param timer Timer.
 * @param timeout_in_ticks Determines the action to take when the timer has
 *        not expired.
 *        For TICKS_NONE, return immediately.
 *        For TICKS_UNLIMITED, wait as long as necessary.
 *
 * @retval Pointer to timer initialization data.
 * @retval NULL If timer not expired.
 *
 * @warning If called from an ISR, then @a timeout_in_ticks must be TICKS_NONE.
 *
 * @sa TICKS_NONE, TICKS_UNLIMITED
 */
extern __deprecated void *nano_timer_test(struct nano_timer *timer,
					  int32_t timeout_in_ticks);

/**
 * @brief Make the current ISR check for a timer expiry.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_timer_test(), but may only be called from an ISR with a timeout
 * of TICKS_NONE.
 *
 * @sa nano_timer_test
 */
#define nano_isr_timer_test nano_timer_test

/**
 * @brief Make the current fiber check for a timer expiry.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_timer_test(), but may only be called from a fiber.
 *
 * @sa nano_timer_test
 */
#define nano_fiber_timer_test nano_timer_test

/**
 * @brief Make the current task check for a timer expiry.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_timer_test(), but may only be called from a task.
 *
 * @sa nano_timer_test
 */
#define nano_task_timer_test nano_timer_test

/**
 * @brief Stop a nanokernel timer
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine stops a previously started nanokernel timer object. It is also
 * a convenience wrapper for the execution of context-specific APIs. It is
 * helpful when the exact execution context is not known. However, it should be
 * avoided when the context is known up-front to avoid unnecessary overhead.
 *
 * @param timer Timer to stop.
 *
 * @return N/A
 */

static inline __deprecated void nano_timer_stop(struct nano_timer *timer)
{
	k_timer_stop(timer);
}

/**
 * @brief Stop a timer.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine stops the specified timer. If the timer period has already
 * elapsed, the call has no effect.
 *
 * @param timer Timer to stop.
 *
 * @return N/A
 */

#define task_timer_stop nano_timer_stop

/**
 * @brief Stop a nanokernel timer from an ISR.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_timer_stop(), but may only be called from an ISR.
 *
 * @sa nano_timer_stop
 */

#define nano_isr_timer_stop nano_timer_stop

/**
 * @brief Stop a nanokernel timer.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_timer_stop(), but may only be called from a fiber.
 *
 * @sa nano_timer_stop
 */

#define nano_fiber_timer_stop nano_timer_stop

/**
 * @brief Stop a nanokernel timer from a task.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Like nano_timer_stop(), but may only be called from a task.
 *
 * @sa nano_timer_stop
 */

#define nano_task_timer_stop nano_timer_stop

/**
 * @brief Get nanokernel timer remaining ticks.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This function returns the remaining ticks of the previously
 * started nanokernel timer object.
 *
 * @param timer Timer to query
 *
 * @return remaining ticks or 0 if the timer has expired
 */
static inline __deprecated int32_t
nano_timer_ticks_remain(struct nano_timer *timer)
{
	return _ms_to_ticks(k_timer_remaining_get(timer));
}

/**
 * @brief Make the CPU idle.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This function makes the CPU idle until an event wakes it up.
 *
 * @return N/A
 */
static inline __deprecated void nano_cpu_idle(void)
{
	k_cpu_idle();
}

/**
 * @brief Make the CPU idle in an atomic fashion.
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * Similar to k_cpu_idle(), but called with interrupts locked if operations
 * must be done atomically before making the CPU idle.
 *
 * @param key Interrupt locking key obtained from irq_lock().
 *
 * @return N/A
 */
static inline __deprecated void nano_cpu_atomic_idle(unsigned int key)
{
	k_cpu_atomic_idle(key);
}

#if CONFIG_X86
#if CONFIG_FP_SHARING

#include <arch/cpu.h>

/* floating point services */

#define USE_FP  K_FP_REGS
#define USE_SSE K_SSE_REGS

/**
 * @brief Enable floating point hardware resources sharing
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine dynamically enables the capability of a thread to share floating
 * point hardware resources. The same "floating point" options accepted by
 * fiber_fiber_start() are accepted by this API (i.e. USE_FP and USE_SSE).
 *
 * @param thread_id ID of thread that may share the floating point hardware
 * @param options USE_FP or USE_SSE
 *
 * @return N/A
 */
static inline __deprecated void
fiber_float_enable(struct tcs *tcs, unsigned int options)
{
	k_float_enable(tcs, options);
}

/**
 * @brief Enable floating point hardware resources sharing
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine dynamically enables the capability of a thread to share
 * floating point hardware resources. The same "floating point" options
 * accepted by fiber_fiber_start() are accepted by this API
 * (i.e. USE_FP and USE_SSE).
 *
 * @param thread_id ID of thread that may share the floating point hardware
 * @param options USE_FP or USE_SSE
 *
 * @return N/A
 */

#define task_float_enable fiber_float_enable

/**
 * @brief Disable floating point hardware resources sharing
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine dynamically disables the capability of a thread to share
 * floating point hardware resources. The same "floating point" options
 * accepted by fiber_fiber_start() are accepted by this API
 * (i.e. USE_FP and USE_SSE).
 *
 * @param thread_id ID of thread that may not share the floating point hardware
 *
 * @return N/A
 */
static inline __deprecated void fiber_float_disable(struct tcs *tcs)
{
	k_float_disable(tcs);
}

/**
 * @brief Enable floating point hardware resources sharing
 *
 * <b> Legacy API: Will be deprecated in Zephyr 1.9 </b>
 * @deprecated This API will be deprecated.
 *
 * This routine dynamically disables the capability of a thread to share
 * floating point hardware resources. The same "floating point" options
 * accepted by fiber_fiber_start() are accepted by this API
 * (i.e. USE_FP and USE_SSE).
 *
 * @param thread_id ID of thread that may not share the floating point hardware
 *
 * @return N/A
 */

#define task_float_disable fiber_float_disable

#endif /* CONFIG_FP_SHARING */
#endif /* CONFIG_X86 */

/**
 * @} end legacy_apis
 */


#endif /* _legacy__h_ */