1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
|
<!-- {{{ Banner -->
<!-- =============================================================== -->
<!-- -->
<!-- io.sgml -->
<!-- -->
<!-- Generic I/O subsystem documentation -->
<!-- -->
<!-- =============================================================== -->
<!-- ####ECOSDOCCOPYRIGHTBEGIN#### -->
<!-- =============================================================== -->
<!-- Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. -->
<!-- This material may be distributed only subject to the terms -->
<!-- and conditions set forth in the Open Publication License, v1.0 -->
<!-- or later (the latest version is presently available at -->
<!-- http://www.opencontent.org/openpub/) -->
<!-- Distribution of the work or derivative of the work in any -->
<!-- standard (paper) book form is prohibited unless prior -->
<!-- permission obtained from the copyright holder -->
<!-- =============================================================== -->
<!-- ####ECOSDOCCOPYRIGHTEND#### -->
<!-- =============================================================== -->
<!-- #####DESCRIPTIONBEGIN#### -->
<!-- -->
<!-- ####DESCRIPTIONEND#### -->
<!-- =============================================================== -->
<!-- }}} -->
<PART id="io">
<TITLE>I/O Package (Device Drivers)</TITLE>
<!-- {{{ Intro -->
<CHAPTER id="io-package-intro">
<TITLE>Introduction</TITLE>
<PARA>
The I/O package is designed as a general purpose framework for
supporting device drivers. This includes all classes of
drivers from simple serial to networking stacks and beyond.
</PARA>
<PARA>
Components of the I/O package, such as device drivers, are
configured into the system just like all other components.
Additionally, end users may add their own drivers to this set.
</PARA>
<PARA>
While the set of drivers (and the devices they represent) may be
considered static, they must be accessed via an opaque
“handle”. Each device in the system has a unique name and
the <FUNCTION>cyg_io_lookup()</FUNCTION> function is used to map that
name onto the handle for the device. This “hiding” of the
device implementation allows for generic, named devices, as well as
more flexibility. Also, the <FUNCTION>cyg_io_lookup()</FUNCTION>
function provides drivers the opportunity to initialize the device
when usage actually starts.
</PARA>
<PARA>
All devices have a name. The standard provided devices use names such
as <filename>“/dev/console”</filename> and
<filename>“/dev/serial0”</filename>, where the
<filename>“/dev/”</filename> prefix indicates that this is
the name of a device.
</PARA>
<PARA>The entire I/O package API, as well as the standard
set of provided drivers, is written in C. </PARA>
<PARA>Basic functions are provided to send data to and receive data
from a device. The details of how this is done is left to the device [class] itself.
For example, writing data to a block device like a disk drive may
have different semantics than writing to a serial port. </PARA>
<PARA>Additional functions are provided to manipulate the state
of the driver and/or the actual device. These functions
are, by design, quite specific to the actual driver. </PARA>
<PARA>This driver model supports layering; in other words, a device
may actually be created “on top of” another device.
For example, the “tty” (terminal-like) devices are
built on top of simple serial devices. The upper layer then has
the flexibility to add features and functions not found at the lower
layers. In this case the “tty” device provides
for line buffering and editing not available from the simple serial
drivers.
</PARA>
<PARA>Some drivers will support visibility of the layers they depend
upon. The “tty” driver allows information about
the actual serial device to be manipulated by passing get/set
config calls that use a serial driver “key” down
to the serial driver itself. </PARA>
</CHAPTER>
<!-- }}} -->
<!-- {{{ User API -->
<CHAPTER id="io-user-api">
<TITLE><!-- <index></index> -->User API</TITLE>
<PARA>
All functions, except <FUNCTION>cyg_io_lookup()</FUNCTION>
require an I/O “<!-- <index></index> -->handle”.
</PARA>
<PARA>
All functions return a value of the type <type>Cyg_ErrNo</type>. If an
error condition is detected, this value will be negative and the
absolute value indicates the actual error, as specified in
<filename>cyg/error/codes.h</filename>. The only other legal return
value will be <varname>ENOERR</varname>. All other function arguments
are pointers (references). This allows the drivers to pass information
efficiently, both into and out of the driver. The most striking
example of this is the “length” value passed to the read
and write functions. This parameter contains the desired length of
data on input to the function and the actual transferred length on
return.
</PARA>
<PROGRAMLISTING>
// Lookup a device and return its handle
Cyg_ErrNo <FUNCTION><!-- <index></index> -->cyg_io_lookup</function>(
const char <parameter>*name</parameter>,
cyg_io_handle_t <parameter>*handle</parameter> )
</PROGRAMLISTING>
<PARA>
This function maps a device name onto an appropriate handle. If the
named device is not in the system, then the error
<varname>-ENOENT</varname> is returned. If the device is found, then
the handle for the device is returned by way of the handle pointer
<parameter>*handle</parameter>.
</PARA>
<PROGRAMLISTING>
// Write data to a device
Cyg_ErrNo <FUNCTION><!-- <index></index> -->cyg_io_write</function>(
cyg_io_handle_t <parameter>handle</parameter>,
const void <parameter>*buf</parameter>,
cyg_uint32 <parameter>*len</parameter> )
</PROGRAMLISTING>
<PARA>
This function sends data to a device. The size of data to send is
contained in <parameter>*len</parameter> and the actual size sent will
be returned in the same place.
</PARA>
<PROGRAMLISTING>
// Read data from a device
Cyg_ErrNo <!-- <index></index> --><function>cyg_io_read</function>(
cyg_io_handle_t <parameter>handle</parameter>,
void <parameter>*buf</parameter>,
cyg_uint32 <parameter>*len</parameter> )
</PROGRAMLISTING>
<PARA>
This function receives data from a device. The desired size of data to
receive is contained in <parameter>*len</parameter> and the actual
size obtained will be returned in the same place.
</PARA>
<PROGRAMLISTING>
// Get the configuration of a device
Cyg_ErrNo <FUNCTION><!-- <index></index> -->cyg_io_get_config</FUNCTION>(
cyg_io_handle_t <parameter>handle</parameter>,
cyg_uint32 <parameter>key</parameter>,
void *<parameter>buf</parameter>,
cyg_uint32 *<parameter>len</parameter> )
</PROGRAMLISTING>
<PARA>
This function is used to obtain run-time configuration about a
device. The type of information retrieved is specified by the
<parameter>key</parameter>. The data will be returned in the given
buffer. The value of <parameter>*len</parameter> should contain the
amount of data requested, which must be at least as large as the size
appropriate to the selected key. The actual size of data retrieved is
placed in <parameter> *len</parameter>. The appropriate key values
differ for each driver and are all listed in the file
<filename><cyg/io/config_keys.h></filename>.
</PARA>
<PROGRAMLISTING>
// Change the configuration of a device
Cyg_ErrNo <!-- <index></index> --><function>cyg_io_set_config</function>(
cyg_io_handle_t <parameter>handle</parameter>,
cyg_uint32 <parameter>key</parameter>,
const void <parameter>*buf</parameter>,
cyg_uint32 <parameter>*len</parameter> )
</PROGRAMLISTING>
<PARA>
This function is used to manipulate or change the run-time
configuration of a device. The type of information is specified by the
<parameter>key</parameter>. The data will be obtained from the given
buffer. The value of <parameter>*len</parameter> should contain the
amount of data provided, which must match the size appropriate to the
selected key. The appropriate key values differ for each driver and
are all listed in the file
<filename><cyg/io/config_keys.h></filename>.
</PARA>
</CHAPTER>
<!-- }}} -->
<!-- {{{ Serial Drivers -->
<CHAPTER id="io-serial-driver-details">
<TITLE>Serial driver details</TITLE>
<PARA>
Two different classes of serial drivers are provided as a standard
part of the eCos system. These are described as “raw
serial” (serial) and “tty-like” (tty).
</PARA>
<!-- {{{ Raw Serial Drivers -->
<SECTION id="io-simple-serial-driver">
<TITLE>Raw Serial Driver</TITLE>
<PARA>
Use the include file <FILENAME><cyg/io/serialio.h></FILENAME> for
this driver.
</PARA>
<PARA>
The <!-- <index></index> -->raw serial driver is capable of sending
and receiving blocks of raw data to a serial device. Controls are
provided to configure the actual hardware, but there is no manipulation
of the data by this driver.
</PARA>
<PARA>
There may be many instances of this driver in a given system,
one for each serial channel. Each channel corresponds to a physical
device and there will typically be a device module created for this
purpose. The device modules themselves are configurable, allowing
specification of the actual hardware details, as well as such details
as whether the channel should be buffered by the serial driver,
etc.
</PARA>
<!-- {{{ Runtime Configuration -->
<SECTION>
<TITLE>Runtime Configuration</TITLE>
<para>
Runtime configuration is achieved by exchanging data structures with
the driver via the <function>cyg_io_set_config()</function> and
<function>cyg_io_get_config()</function> functions.
</para>
<PROGRAMLISTING>
typedef struct {
cyg_serial_baud_rate_t baud;
cyg_serial_stop_bits_t stop;
cyg_serial_parity_t parity;
cyg_serial_word_length_t word_length;
cyg_uint32 flags;
} cyg_serial_info_t;
</PROGRAMLISTING>
<PARA>
The field <structfield><!-- <index></index>
-->word_length</structfield> contains the number of data bits per word
(character). This must be one of the values:
</PARA>
<PROGRAMLISTING>
CYGNUM_SERIAL_WORD_LENGTH_5
CYGNUM_SERIAL_WORD_LENGTH_6
CYGNUM_SERIAL_WORD_LENGTH_7
CYGNUM_SERIAL_WORD_LENGTH_8
</PROGRAMLISTING>
<PARA>
The field <structfield><!-- <index></index>
-->baud</structfield> contains a baud rate selection. This must be
one of the values:
</PARA>
<PROGRAMLISTING>
CYGNUM_SERIAL_BAUD_50
CYGNUM_SERIAL_BAUD_75
CYGNUM_SERIAL_BAUD_110
CYGNUM_SERIAL_BAUD_134_5
CYGNUM_SERIAL_BAUD_150
CYGNUM_SERIAL_BAUD_200
CYGNUM_SERIAL_BAUD_300
CYGNUM_SERIAL_BAUD_600
CYGNUM_SERIAL_BAUD_1200
CYGNUM_SERIAL_BAUD_1800
CYGNUM_SERIAL_BAUD_2400
CYGNUM_SERIAL_BAUD_3600
CYGNUM_SERIAL_BAUD_4800
CYGNUM_SERIAL_BAUD_7200
CYGNUM_SERIAL_BAUD_9600
CYGNUM_SERIAL_BAUD_14400
CYGNUM_SERIAL_BAUD_19200
CYGNUM_SERIAL_BAUD_38400
CYGNUM_SERIAL_BAUD_57600
CYGNUM_SERIAL_BAUD_115200
CYGNUM_SERIAL_BAUD_234000
</PROGRAMLISTING>
<PARA>The field <structfield><!-- <index></index>
-->stop</structfield> contains the number of stop bits. This must be
one of the values:</PARA>
<PROGRAMLISTING>
CYGNUM_SERIAL_STOP_1
CYGNUM_SERIAL_STOP_1_5
CYGNUM_SERIAL_STOP_2
</PROGRAMLISTING>
<NOTE>
<title>Note</title>
<PARA>
On most hardware, a selection of 1.5 stop bits is only valid
if the word (character) length is 5.
</PARA>
</NOTE>
<PARA>The field <structfield><!-- <index></index>
-->parity</structfield> contains the parity mode. This must be one of
the values: </PARA>
<PROGRAMLISTING>
CYGNUM_SERIAL_PARITY_NONE
CYGNUM_SERIAL_PARITY_EVEN
CYGNUM_SERIAL_PARITY_ODD
CYGNUM_SERIAL_PARITY_MARK
CYGNUM_SERIAL_PARITY_SPACE
</PROGRAMLISTING>
<PARA>The field <structfield><!-- <index></index>
-->flags</structfield> is a bitmask which controls the behavior of the
serial device driver. It should be built from the values
<literal>CYG_SERIAL_FLAGS_xxx</literal> defined below:
</PARA>
<PROGRAMLISTING>
#define CYG_SERIAL_FLAGS_RTSCTS 0x0001
</PROGRAMLISTING>
<PARA>If this bit is set then the port is placed in “hardware
handshake” mode. In this mode, the CTS and RTS pins control
when data is allowed to be sent/received at the port. This
bit is ignored if the hardware does not support this level of
handshake.
</PARA>
<PROGRAMLISTING>
typedef struct {
cyg_int32 rx_bufsize;
cyg_int32 rx_count;
cyg_int32 tx_bufsize;
cyg_int32 tx_count;
} cyg_serial_buf_info_t;
</PROGRAMLISTING>
<PARA>The field <structfield>rx_bufsize</structfield> contains
the total size of the incoming data buffer. This is set to zero on
devices that do not support buffering (i.e. polled devices).</PARA>
<PARA>The field <structfield>rx_count</structfield> contains the
number of bytes currently occupied in the incoming data buffer.
This is set to zero on devices that do not support buffering (i.e. polled
devices).</PARA>
<PARA>The field <structfield>tx_bufsize</structfield> contains the
total size of the transmit data buffer. This is set to zero on devices
that do not support buffering (i.e. polled devices).</PARA>
<PARA>The field <structfield>tx_count</structfield> contains the
number of bytes currently occupied in the transmit data buffer. This
is set to zero on devices that do not support buffering (i.e. polled
devices).</PARA>
</SECTION>
<!-- }}} -->
<!-- {{{ API Details -->
<SECTION>
<TITLE><!-- <index></index> -->API Details</TITLE>
<!-- {{{ cyg_io_write -->
<section id="io-serial-cyg-io-write">
<title>cyg_io_write</title>
<PROGRAMLISTING>
cyg_io_write(handle, buf, len)
</PROGRAMLISTING>
<PARA>
Send the data from <parameter>buf</parameter> to the device. The
driver maintains a buffer to hold the data. The size of the
intermediate buffer is configurable within the interface module. The
data is not modified at all while it is being buffered. On return,
<parameter>*len</parameter> contains the amount of characters actually
consumed .</PARA>
<PARA>
It is possible to configure the write call to be blocking
(default) or non-blocking. Non-blocking mode requires both the configuration
option <literal>CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING</literal>
to be enabled, and the specific device to be set to non-blocking
mode for writes (see <function>cyg_io_set_config()</function>).
</para>
<para>
In blocking mode, the call will not return until there is space in the
buffer and the entire contents of <parameter>buf</parameter> have been
consumed.
</PARA>
<PARA>
In non-blocking mode, as much as possible gets consumed from
<parameter>buf</parameter>. If everything was consumed, the call
returns <literal>ENOERR</literal>. If only part of the
<parameter>buf</parameter> contents was consumed,
<literal>-EAGAIN</literal> is returned and the caller must try
again. On return, <parameter>*len</parameter> contains the number of characters actually
consumed .</PARA>
<PARA>
The call can also return <literal>-EINTR</literal> if interrupted
via the <function>cyg_io_get_config()</function>/<literal>ABORT</literal> key.
</para>
</section>
<!-- }}} -->
<!-- {{{ cyg_io_read -->
<section id="io-serial-cyg-io-read">
<title>cyg_io_read</title>
<programlisting>
cyg_io_read(handle, buf, len)
</programlisting>
<PARA>
Receive data into the buffer, <parameter>buf</parameter>, from the
device. No manipulation of the data is performed before being
transferred. An interrupt driven interface module will support data
arriving when no read is pending by buffering the data in the serial
driver. Again, this buffering is completely configurable. On return,
<parameter>*len</parameter> contains the number of characters actually
received.</PARA>
<PARA>
It is possible to configure the read call to be blocking (default)
or non-blocking. Non-blocking mode requires both the configuration
option <literal>CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING</literal>
to be enabled, and the specific device to be set to non-blocking
mode for reads (see <function>cyg_io_set_config()</function>).
</PARA>
<PARA>
In blocking mode, the call will not return until the requested
amount of data has been read.</PARA>
<PARA>
In non-blocking mode, data waiting in the device buffer is copied to
<parameter>buf</parameter>, and the call returns immediately. If there
was enough data in the buffer to fulfill the request,
<literal>ENOERR</literal> is returned. If only part of the request
could be fulfilled, <literal>-EAGAIN</literal> is returned and the
caller must try again. On return, <parameter>*len</parameter> contains
the number of characters actually received.</PARA>
<PARA>
The call can also return <literal>-EINTR</literal> if interrupted via
the <function>cyg_io_get_config()</function>/<literal>ABORT</literal>
key.
</PARA>
</section>
<!-- }}} -->
<!-- {{{ cyg_io_get_config -->
<section id="io-serial-cyg-get-config">
<title>cyg_io_get_config</title>
<PROGRAMLISTING>
cyg_io_get_config(handle, key, buf, len)
</PROGRAMLISTING>
<PARA>This function returns current [runtime] information
about the device and/or driver. </PARA>
<VARIABLELIST>
<VARLISTENTRY>
<TERM><literal>CYG_IO_GET_CONFIG_SERIAL_INFO</literal></TERM>
<LISTITEM>
<variablelist>
<VARLISTENTRY>
<TERM>Buf type:</TERM>
<LISTITEM>
<PARA>cyg_serial_info_t</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Function:</TERM>
<LISTITEM>
<PARA>
This function retrieves the current state of the driver
and hardware. This information contains fields for
hardware baud rate, number of stop bits, and parity
mode. It also includes a set of flags that control the
port, such as hardware flow control.
</PARA>
</LISTITEM>
</VARLISTENTRY>
</variablelist>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM><literal>CYG_IO_GET_CONFIG_SERIAL_BUFFER_INFO</literal></TERM>
<LISTITEM>
<variablelist>
<VARLISTENTRY>
<TERM>Buf type:</TERM>
<LISTITEM>
<PARA>cyg_serial_buf_info_t</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Function:</TERM>
<LISTITEM>
<PARA>
This function retrieves the current state of the
software buffers in the serial drivers. For both
receive and transmit buffers it returns the total
buffer size and the current number of bytes occupied in
the buffer. It does not take into account any buffering
such as FIFOs or holding registers that the serial
device itself may have.
</PARA>
</LISTITEM>
</VARLISTENTRY>
</variablelist>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM><literal>CYG_IO_GET_CONFIG_SERIAL_OUTPUT_DRAIN</literal></TERM>
<LISTITEM>
<variablelist>
<VARLISTENTRY>
<TERM>Buf type:</TERM>
<LISTITEM>
<PARA>void *</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Function:</TERM>
<LISTITEM>
<PARA>
This function waits for any buffered output to
complete. This function only completes when there is no
more data remaining to be sent to the device.
</PARA>
</LISTITEM>
</VARLISTENTRY>
</variablelist>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM><literal>CYG_IO_GET_CONFIG_SERIAL_OUTPUT_FLUSH</literal></TERM>
<LISTITEM>
<variablelist>
<VARLISTENTRY>
<TERM>Buf type:</TERM>
<LISTITEM>
<PARA>void *</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Function:</TERM>
<LISTITEM>
<PARA>
This function discards any buffered output for the
device.
</PARA>
</LISTITEM>
</VARLISTENTRY>
</variablelist>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM><literal>CYG_IO_GET_CONFIG_SERIAL_INPUT_DRAIN</literal></term>
<LISTITEM>
<variablelist>
<VARLISTENTRY>
<TERM>Buf type:</TERM>
<LISTITEM>
<PARA>void *</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Function: </TERM>
<LISTITEM>
<PARA>This function discards any buffered input for the
device.</PARA>
</LISTITEM>
</VARLISTENTRY>
</variablelist>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM><literal>CYG_IO_GET_CONFIG_SERIAL_ABORT</literal></TERM>
<LISTITEM>
<variablelist>
<VARLISTENTRY>
<TERM>Buf type:</TERM>
<LISTITEM>
<PARA> void*</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Function:</TERM>
<LISTITEM>
<PARA>This function will cause any pending read or write calls on
this device to return with <literal>-EABORT</literal>.</PARA>
</LISTITEM>
</VARLISTENTRY>
</variablelist>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM><literal>CYG_IO_GET_CONFIG_SERIAL_READ_BLOCKING</literal></TERM>
<LISTITEM>
<variablelist>
<VARLISTENTRY>
<TERM>Buf type:</TERM>
<LISTITEM>
<PARA> cyg_uint32 (values 0 or 1)</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Function:</TERM>
<LISTITEM>
<PARA>This function will read back the blocking-mode
setting for read calls on this device. This call is only
available if the configuration option
<literal>CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING</literal> is
enabled.</PARA>
</LISTITEM>
</VARLISTENTRY>
</variablelist>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM><literal>CYG_IO_GET_CONFIG_SERIAL_WRITE_BLOCKING</literal></TERM>
<LISTITEM>
<variablelist>
<VARLISTENTRY>
<TERM>Buf type:</TERM>
<LISTITEM>
<PARA> cyg_uint32 (values 0 or 1)</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Function:</TERM>
<LISTITEM>
<PARA>
This function will read back the blocking-mode
setting for write calls on this device. This call is only
available if the configuration option
<literal>CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING</literal> is enabled.</PARA>
</listitem>
</varlistentry>
</variablelist>
</listitem>
</varlistentry>
</variablelist>
</section>
<!-- }}} -->
<!-- {{{ cyg_io_set_config -->
<section id="io-serial-cyg-set-config">
<title>cyg_io_set_config</title>
<PROGRAMLISTING>
cyg_io_set_config(handle, key, buf,len)
</PROGRAMLISTING>
<PARA>This function is used to update or change runtime configuration
of a port. </PARA>
<variablelist>
<VARLISTENTRY>
<TERM><literal>CYG_IO_SET_CONFIG_SERIAL_INFO</literal></TERM>
<LISTITEM>
<variablelist>
<VARLISTENTRY>
<TERM>Buf type:</TERM>
<LISTITEM>
<PARA>cyg_serial_info_t</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Function:</TERM>
<LISTITEM>
<PARA>This function updates the information for the driver
and hardware. The information contains fields for
hardware baud rate, number of stop bits, and parity
mode. It also includes a set of flags that control the
port, such as hardware flow control.
</PARA>
</LISTITEM>
</VARLISTENTRY>
</variablelist>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM><literal>CYG_IO_SET_CONFIG_SERIAL_READ_BLOCKING</literal></TERM>
<LISTITEM>
<variablelist>
<VARLISTENTRY>
<TERM>Buf type:</TERM>
<LISTITEM>
<PARA> cyg_uint32 (values 0 or 1)</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Function:</TERM>
<LISTITEM>
<PARA>This function will set the blocking-mode for read
calls on this device. This call is only available if the
configuration option <literal>CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING</literal>
is enabled.
</PARA>
</LISTITEM>
</VARLISTENTRY>
</variablelist>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM><literal>CYG_IO_SET_CONFIG_SERIAL_WRITE_BLOCKING</literal></TERM>
<LISTITEM>
<variablelist>
<VARLISTENTRY>
<TERM>Buf type:</TERM>
<LISTITEM>
<PARA>cyg_uint32 (values 0 or 1)</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Function:</TERM>
<LISTITEM>
<PARA>This function will set the blocking-mode for write
calls on this device. This call is only available if the
configuration option <literal>CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING</literal>
is enabled.
</PARA>
</LISTITEM>
</VARLISTENTRY>
</variablelist>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</section>
<!-- }}} -->
</SECTION>
<!-- }}} -->
</SECTION>
<!-- }}} -->
<!-- {{{ TTY Drivers -->
<SECTION id="io-tty-driver">
<TITLE> TTY driver</TITLE>
<PARA>
Use the include file <filename><cyg/io/ttyio.h></filename> for
this driver.
</PARA>
<PARA>
This <!-- <index></index> -->driver is built on top of the simple
serial driver and is typically used for a device that interfaces with
humans such as a terminal. It provides some minimal formatting of data
on output and allows for line-oriented editing on input.
</PARA>
<!-- {{{ Runtime Configuration -->
<SECTION>
<TITLE>Runtime configuration</TITLE>
<para>
Runtime configuration is achieved by exchanging data structures with
the driver via the <function>cyg_io_set_config()</function> and
<function>cyg_io_get_config()</function> functions.
</para>
<PROGRAMLISTING>
typedef struct {
cyg_uint32 tty_out_flags;
cyg_uint32 tty_in_flags;
} cyg_tty_info_t;
</PROGRAMLISTING>
<PARA>The field <structfield><!-- <index></index> -->tty_out_flags</structfield>
is used to control what happens to data as it is send to the serial
port. It contains a bitmap comprised of the bits as defined by the
<literal>CYG_TTY_OUT_FLAGS_xxx</literal> values below. </PARA>
<PROGRAMLISTING>
#define CYG_TTY_OUT_FLAGS_CRLF 0x0001 // Map '\n' => '\r\n' on output
</PROGRAMLISTING>
<PARA>If this bit is set in <structfield>tty_out_flags</structfield>,
any occurrence of the character "\n" will
be replaced by the sequence "\r\n" before
being sent to the device.</PARA>
<PARA>The field <structfield><!-- <index></index> -->tty_in_flags</structfield>
is used to control how data is handled as it comes from the serial
port. It contains a bitmap comprised of the bits as defined by the
<literal>CYG_TTY_IN_FLAGS_xxx</literal> values below. </PARA>
<PROGRAMLISTING>
#define CYG_TTY_IN_FLAGS_CR 0x0001 // Map '\r' => '\n' on input
</PROGRAMLISTING>
<PARA>If this bit is set in <structfield>tty_in_flags</structfield>, the
character "\r" (“return” or “enter” on
most keyboards) will be mapped to "\n".</PARA>
<PROGRAMLISTING>
#define CYG_TTY_IN_FLAGS_CRLF 0x0002 // Map '\r\n' => '\n' on input
</PROGRAMLISTING>
<PARA>
If this bit is set in <structfield>tty_in_flags</structfield>, the
character sequence "\r\n" (often sent by DOS/Windows
based terminals) will be mapped to "\n". </PARA>
<PROGRAMLISTING>
#define CYG_TTY_IN_FLAGS_ECHO 0x0004 // Echo characters as processed
</PROGRAMLISTING>
<PARA>
If this bit is set in <structfield>tty_in_flags</structfield>, characters
will be echoed back to the serial port as they are processed. </PARA>
<PROGRAMLISTING>
#define CYG_TTY_IN_FLAGS_BINARY 0x0008 // No input processing
</PROGRAMLISTING>
<PARA>If this bit is set in <structfield>tty_in_flags</structfield>, the
input will not be manipulated in any way before being placed in
the user’s buffer. </PARA>
</SECTION>
<!-- }}} -->
<!-- {{{ API Details -->
<SECTION>
<TITLE><!-- <index></index> -->API details</TITLE>
<PROGRAMLISTING>
cyg_io_read(handle, buf, len)
</PROGRAMLISTING>
<PARA>This function is used to read data from the device. In the
default case, data is read until an end-of-line character ("\n"
or "\r") is read. Additionally, the characters are echoed
back to the [terminal] device. Minimal editing
of the input is also supported. </PARA>
<NOTE>
<PARA>When connecting to a remote target via GDB it is not possible
to provide console input while GDB is connected. The GDB remote
protocol does not support input. Users must disconnect from GDB
if this functionality is required.</PARA>
</NOTE>
<PROGRAMLISTING>
cyg_io_write(handle, buf, len)
</PROGRAMLISTING>
<PARA>This function is used to send data to the device. In the default
case, the end-of-line character "\n" is replaced by the
sequence "\r\n". </PARA>
<PROGRAMLISTING>
cyg_io_get_config(handle, key, buf, len)
</PROGRAMLISTING>
<PARA>This function is used to get information about the channel’s
configuration at runtime. </PARA>
<VARIABLELIST>
<VARLISTENTRY>
<TERM><literal>CYG_IO_GET_CONFIG_TTY_INFO</literal></TERM>
<LISTITEM>
<variablelist>
<VARLISTENTRY>
<TERM>Buf type:</TERM>
<LISTITEM>
<PARA>cyg_tty_info_t</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Function:</TERM>
<LISTITEM>
<PARA>This function retrieves the current state of the
driver.
</PARA>
</listitem>
</varlistentry>
</variablelist>
</listitem>
</varlistentry>
</variablelist>
<PARA>Serial driver keys (see above) may also be specified
in which case the call is passed directly to the serial
driver. </PARA>
<PROGRAMLISTING>
cyg_io_set_config(handle, key, buf, len)
</PROGRAMLISTING>
<PARA>This function is used to modify the channel’s configuration
at runtime. </PARA>
<VARIABLELIST>
<VARLISTENTRY>
<TERM><literal>CYG_IO_SET_CONFIG_TTY_INFO</literal></term>
<LISTITEM>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Buf type:</TERM>
<LISTITEM>
<PARA>cyg_tty_info_t</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Function: </TERM>
<LISTITEM>
<PARA>This function changes the current state of the
driver.</PARA>
</LISTITEM>
</VARLISTENTRY>
</variablelist>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
<PARA>Serial driver
keys (see above) may also be specified in which case the
call is passed directly to the serial driver. </PARA>
</SECTION>
<!-- }}} -->
</SECTION>
<!-- }}} -->
<!-- {{{ DSP Driver -->
<!-- }}} -->
</CHAPTER>
<!-- }}} -->
<!-- {{{ How to Write a Driver -->
<CHAPTER id="io-how-to-write-a-driver">
<TITLE>How to Write a Driver</TITLE>
<!-- {{{ Intro -->
<PARA>
A <!-- <index></index> -->device driver is nothing more than a
named entity that supports the basic I/O functions - read, write, get
config, and set config. Typically a device driver also uses and
manages interrupts from the device. While the interface is generic and
device driver independent, the actual driver implementation is
completely up to the device driver designer. </PARA>
<PARA>That said, the reason for using a device driver is to provide
access to a device from application code in as general purpose a
fashion as reasonable. Most driver writers are also concerned with
making this access as simple as possible while being as efficient
as possible. </PARA>
<PARA>Most device drivers are concerned with the movement of information,
for example data bytes along a serial interface, or packets in a
network. In order to make the most efficient use of system resources,
interrupts are used. This will allow other application processing
to take place while the data transfers are under way, with interrupts
used to indicate when various events have occurred. For example,
a serial port typically generates an interrupt after a character
has been sent “down the wire” and the interface
is ready for another. It makes sense to allow further application
processing while the data is being sent since this can take quite
a long time. The interrupt can be used to allow the driver to send
a character as soon as the current one is complete, without any
active participation by the application code. </PARA>
<PARA>The main building blocks for device drivers are found in the
include file: <filename><cyg/io/devtab.h></filename></PARA>
<PARA>All device drivers in <EMPHASIS>eCos</EMPHASIS> are described
by a device table entry, using the <type>cyg_devtab_entry_t</type> type.
The entry should be created using the <FUNCTION>DEVTAB_ENTRY()</FUNCTION> macro,
like this:</PARA>
<PROGRAMLISTING><function>
DEVTAB_ENTRY</function>(l, name, dep_name, handlers, init, lookup, priv)
</PROGRAMLISTING>
<variablelist>
<title>Arguments</title>
<varlistentry>
<term><parameter>l</parameter></term>
<listitem><para>The "C" label for this device table entry.</para></listitem>
</varlistentry>
<varlistentry>
<term><parameter>name</parameter></term>
<listitem><para>The "C" string name for the device.</para></listitem>
</varlistentry>
<varlistentry>
<term><parameter>dep_name</parameter></term>
<listitem><para>For a layered device, the "C" string name of the
device this device is built upon.</para></listitem>
</varlistentry>
<varlistentry>
<term><parameter>handlers</parameter></term>
<listitem><para>A pointer to the I/O function "handlers" (see below).</para></listitem>
</varlistentry>
<varlistentry>
<term><parameter>init</parameter></term>
<listitem><para>A function called when eCos is initialized. This
function can query the device, setup hardware, etc.</para></listitem>
</varlistentry>
<varlistentry>
<term><parameter>lookup</parameter></term>
<listitem><para>A function called when <function>cyg_io_lookup()</function> is called
for this device. </para></listitem>
</varlistentry>
<varlistentry>
<term><parameter>priv</parameter></term>
<listitem><para>A placeholder for any device specific data
required by the driver.</para></listitem>
</varlistentry>
</variablelist>
<PARA>The interface to the driver is through the <structfield><!--
<index></index> -->handlers</structfield> field. This is a pointer to
a set of functions which implement the various <function>cyg_io_XXX()</function>
routines. This table is defined by the macro:</PARA>
<PROGRAMLISTING>
DEVIO_TABLE(l, write, read, select, get_config, set_config)
</PROGRAMLISTING>
<variablelist>
<title>Arguments</title>
<varlistentry>
<term><parameter>l</parameter></term>
<listitem><para>The "C" label for this table of handlers.</para></listitem>
</varlistentry>
<varlistentry>
<term>write</term>
<listitem><para>The function called as a result of
<function>cyg_io_write()</function>.</para></listitem>
</varlistentry>
<varlistentry>
<term>read</term>
<listitem><para>The function called as a result of
<function>cyg_io_read()</function>. </para></listitem>
</varlistentry>
<varlistentry>
<term>select</term>
<listitem><para>The function called as a result of
<function>cyg_io_select()</function>. </para></listitem>
</varlistentry>
<varlistentry>
<term>get_config</term>
<listitem><para>The function called as a result of
<function>cyg_io_get_config()</function>.</para></listitem>
</varlistentry>
<varlistentry>
<term>set_config</term>
<listitem><para>The function called as a result of
<function>cyg_io_set_config()</function>. </para></listitem>
</varlistentry>
</variablelist>
<PARA>
When <EMPHASIS>eCos</EMPHASIS> is initialized (sometimes called
“boot” time), the <function>init()</function> function is called
for all devices in the system. The <function>init()</function> function is
allowed to return an error in which case the device will be placed
“off line” and all I/O requests to that device will be
considered in error.
</PARA>
<PARA>
The <function>lookup()</function> function is called whenever
the <FUNCTION>cyg_io_lookup()</FUNCTION> function
is called with this device name. The lookup function may cause the device
to come “on line” which would then allow I/O
operations to proceed. Future versions of the I/O system
will allow for other states, including power saving modes,
etc.
</PARA>
<!-- }}} -->
<!-- {{{ How to Write a Serial Hardware Interface Driver -->
<SECTION id="io-how-to-write-serial-interface-driver">
<TITLE>How to Write a Serial Hardware Interface Driver</TITLE>
<PARA>The standard serial driver supplied with
<EMPHASIS>eCos</EMPHASIS> is structured as a hardware independent
portion and a hardware dependent interface module. To add support for
a new serial port, the user should be able to use the existing
hardware independent portion and just add their own <!--
<index></index> -->interface driver which handles the details of the
actual device. The user should have no need to change the hardware
independent portion. </PARA>
<PARA>The interfaces used by the serial driver and serial implementation
modules are contained in the file <filename><cyg/io/serial.h></filename>
</PARA>
<NOTE>
<PARA>In the sections below we use the notation <<xx>> to
mean a module specific value, referred to as “xx” below.</PARA>
</NOTE>
<!-- {{{ DevTab Entry -->
<section>
<title>DevTab Entry</title>
<PARA>The interface module contains the devtab entry (or entries
if a single module supports more than one interface). This entry
should have the form: </PARA>
<PROGRAMLISTING>
DEVTAB_ENTRY(<<module_name>>,
<<device_name>>,
0,
&serial_devio,
<<module_init>>,
<<module_lookup>>,
&<<serial_channel>>
);
</PROGRAMLISTING>
<variablelist>
<title>Arguments</title>
<varlistentry>
<term><parameter>module_name</parameter></term>
<listitem><para>The "C" label for this devtab entry</para></listitem>
</varlistentry>
<varlistentry>
<term><parameter>device_name</parameter></term>
<listitem><para>The "C" string for the
device. E.g. <filename>/dev/serial0</filename>.</para></listitem>
</varlistentry>
<varlistentry>
<term><parameter>serial_devio</parameter></term>
<listitem><para>The table of I/O functions. This set is defined in
the hardware independent serial driver and should be used.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>module_init</parameter></term>
<listitem><para>The module initialization function.</para></listitem>
</varlistentry>
<varlistentry>
<term><parameter>module_lookup</parameter></term>
<listitem><para>The device lookup function. This function
typically sets up the device for actual use, turning on
interrupts, configuring the port, etc.</para></listitem>
</varlistentry>
<varlistentry>
<term><parameter>serial_channel</parameter></term>
<listitem><para>This table (defined below) contains the interface
between the interface module and the serial driver proper.</para></listitem>
</varlistentry>
</variablelist>
</section>
<!-- }}} -->
<!-- {{{ Serial Channel Structure -->
<section>
<title>Serial Channel Structure</title>
<PARA>Each serial device must have a “serial channel”.
This is a set of data which describes all operations on the device.
It also contains buffers, etc., if the device is to be buffered.
The serial channel is created by the macro: </PARA>
<PROGRAMLISTING>
SERIAL_CHANNEL_USING_INTERRUPTS(l, funs, dev_priv, baud,stop, parity, word_length,
flags, out_buf, out_buflen, in_buf, in_buflen)
</PROGRAMLISTING>
<variablelist>
<title>Arguments</title>
<varlistentry>
<term><parameter>l</parameter></term>
<listitem><para>The "C" label for this structure.</para></listitem>
</varlistentry>
<varlistentry>
<term><parameter>funs</parameter></term>
<listitem><para>The set of interface functions (see below).</para></listitem>
</varlistentry>
<varlistentry>
<term><structfield>dev_priv</structfield></term>
<listitem><para>A placeholder for any device specific data for
this channel.</para></listitem>
</varlistentry>
<varlistentry>
<term><structfield>baud</structfield></term>
<listitem><para>The initial baud rate value
(<type>cyg_serial_baud_t</type>).</para></listitem>
</varlistentry>
<varlistentry>
<term><structfield>stop</structfield></term>
<listitem><para>The initial stop bits value
(<type>cyg_serial_stop_bits_t</type>).</para></listitem>
</varlistentry>
<varlistentry>
<term><structfield>parity</structfield></term>
<listitem><para>The initial parity mode value
(<type>cyg_serial_parity_t</type>).</para></listitem>
</varlistentry>
<varlistentry>
<term><structfield>word_length</structfield></term>
<listitem><para>The initial word length value
(<type>cyg_serial_word_length_t</type>).</para></listitem>
</varlistentry>
<varlistentry>
<term><structfield>flags</structfield></term>
<listitem><para>The initial driver flags value.</para></listitem>
</varlistentry>
<varlistentry>
<term><structfield>out_buf</structfield></term>
<listitem><para>Pointer to the output
buffer. <literal>NULL</literal> if none required.</para></listitem>
</varlistentry>
<varlistentry>
<term><structfield>out_buflen</structfield></term>
<listitem><para>The length of the output buffer.</para></listitem>
</varlistentry>
<varlistentry>
<term><structfield>in_buf</structfield></term>
<listitem><para>pointer to the input
buffer. <literal>NULL</literal> if none required.</para></listitem>
</varlistentry>
<varlistentry>
<term><structfield>in_buflen</structfield></term>
<listitem><para>The length of the input buffer. </PARA></listitem>
</varlistentry>
</variablelist>
<PARA>
If either buffer length is zero, no buffering will take place
in that direction and only polled mode functions will be used.
</PARA>
<PARA>
The interface from the hardware independent driver into the
hardware interface module is contained in the <structfield>funs</structfield> table.
This is defined by the macro:
</PARA>
</section>
<!-- }}} -->
<!-- {{{ Serial Functions Structure -->
<section>
<title>Serial Functions Structure</title>
<PROGRAMLISTING>
SERIAL_FUNS(l, putc, getc, set_config, start_xmit, stop_xmit)
</PROGRAMLISTING>
<variablelist>
<title>Arguments</title>
<varlistentry>
<term><structfield>l</structfield></term>
<listitem><para>The "C" label for this structure.</para></listitem>
</varlistentry>
<varlistentry>
<term><structfield>putc</structfield></term>
<listitem>
<para><literal>bool (*putc)(serial_channel *priv, unsigned char
c)</literal></para>
<para>
This function sends one character to the interface. It should
return <literal>true</literal> if the character is actually consumed. It should
return <literal>false</literal> if there is no space in the interface
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><structfield>getc</structfield></term>
<listitem>
<para><literal>unsigned char (*getc)(serial_channel *priv)</literal></para>
<para>
This function fetches one character from the interface. It will
be only called in a non-interrupt driven mode, thus it should
wait for a character by polling the device until ready.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><structfield>set_config</structfield></term>
<listitem>
<para><literal>bool (*set_config)(serial_channel
*priv,cyg_serial_info_t *config)</literal></para>
<para>
This function is used to configure the port. It should return
<literal>true</literal> if the hardware is updated to match the desired
configuration. It should return <literal>false</literal> if the port cannot
support some parameter specified by the given
configuration. E.g. selecting 1.5 stop bits and 8 data bits is
invalid for most serial devices and should not be allowed.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>start_xmit</parameter></term>
<listitem><para><literal>void (*start_xmit)(serial_channel *priv)</literal></para>
<para>
In interrupt mode, turn on the transmitter and allow for
transmit interrupts.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>stop_xmit</parameter></term>
<listitem>
<para><literal>void (*stop_xmit)(serial_channel *priv)</literal></para>
<para>In interrupt mode, turn off the transmitter.</PARA>
</listitem>
</varlistentry>
</variablelist>
</section>
<!-- }}} -->
<!-- {{{ Callbacks -->
<section>
<title>Callbacks</title>
<PARA>
The device interface module can execute functions in the
hardware independent driver via <literal>chan->callbacks</literal>.
These functions are available:
</PARA>
<PROGRAMLISTING>
void (*serial_init)( serial_channel *chan )
</PROGRAMLISTING>
<PARA>This function is used to initialize the serial channel. It
is only required if the channel is being used in interrupt
mode.</PARA>
<PROGRAMLISTING>
void (*xmt_char)( serial_channel *chan )
</PROGRAMLISTING>
<PARA>
This function would be called from an interrupt handler after a
transmit interrupt indicating that additional characters may be
sent. The upper driver will call the <function>putc</function>
function as appropriate to send more data to the device.</PARA>
<PROGRAMLISTING>
void (*rcv_char)( serial_channel *chan, unsigned char c )
</PROGRAMLISTING>
<PARA>
This function is used to tell the driver that a character has arrived
at the interface. This function is typically called from the interrupt
handler. </PARA>
<PARA>
Furthermore, if the device has a FIFO it should require the hardware
independent driver to provide block transfer functionality (driver CDL
should include "implements
CYGINT_IO_SERIAL_BLOCK_TRANSFER"). In that case, the following
functions are available as well:</PARA>
<PROGRAMLISTING>
xmt_req_reply_t (*data_xmt_req)(serial_channel *chan,
int space,
int* chars_avail,
unsigned char** chars)
void (*data_xmt_done)(serial_channel *chan, int chars_sent)
</PROGRAMLISTING>
<PARA>
Instead of calling <function>xmt_char()</function> to get a single
character for transmission at a time, the driver should call
<function>data_xmt_req()</function> in a loop, requesting character
blocks for transfer. Call with a <parameter>space</parameter> argument of how much space
there is available in the FIFO.</PARA>
<PARA>If the call returns <literal>true</literal>, the driver can read
<parameter>chars_avail</parameter> characters from
<parameter>chars</parameter> and copy them into the FIFO.</PARA>
<PARA>If the call returns <literal>false</literal>, there are
no more buffered characters and the driver should continue without
filling up the FIFO.</PARA>
<PARA>When all data has been unloaded, the
driver must call <function>data_xmt_done()</function>.</PARA>
<PROGRAMLISTING>
rcv_req_reply_t (*data_rcv_req)(serial_channel *chan,
int avail,
int* space_avail,
unsigned char** space)
void (*data_rcv_done)(serial_channel *chan, int chars_rcvd)
</PROGRAMLISTING>
<PARA>Instead of calling <function>rcv_char()</function> with a single
character at a time, the driver should call
<function>data_rcv_req()</function> in a loop, requesting space to
unload the FIFO to. <parameter>avail</parameter> is the number of
characters the driver wishes to unload.</PARA>
<PARA>If the call returns <literal>true</literal>, the driver can copy
<parameter>space_avail</parameter> characters to
<parameter>space</parameter>. </PARA>
<PARA>If the call returns <literal>false</literal>, the input buffer is
full. It is up to the driver to decide what to do in that case
(callback functions for registering overflow are being planned for
later versions of the serial driver).
</PARA>
<PARA>When all data has been unloaded, the driver must call
<function>data_rcv_done()</function>.</PARA>
</section>
<!-- }}} -->
</SECTION>
<!-- }}} -->
<!-- {{{ Serial Testing -->
<section id="io-serial-testing-with-serfilter">
<title>Serial testing with ser_filter</title>
<!-- {{{ Rationale -->
<section id="io-serfilter-rationale">
<title>Rationale</title>
<para>
Since some targets only have one serial connection, a serial testing harness
needs to be able to share the connection with <application>GDB</application>
(however, the test and <application>GDB</application> can also run on separate
lines).
</para>
<para>
The <firstterm>serial filter</firstterm> (<application>ser_filter</application>)
sits between the serial port and <application>GDB</application> and monitors
the exchange of data between <application>GDB</application> and the target.
Normally, no changes are made to the data.
</para>
<para>
When a test request packet is sent from the test on the target, it is
intercepted by the filter.
</para>
<para>
The filter and target then enter a loop, exchanging protocol data between
them which <application>GDB</application> never sees.
</para>
<para>
In the event of a timeout, or a crash on the target, the filter falls
back into its pass-through mode. If this happens due to a crash it should be
possible to start regular debugging with <application>GDB</application>. The
filter will stay in the pass-though mode until <application>GDB</application>
disconnects.
</para>
</section>
<!-- }}} -->
<!-- {{{ The Protocol -->
<section id="io-serfilter-protocol">
<title>The Protocol</title>
<para>The protocol commands are prefixed with an <literal>"@"</literal>
character which the serial filter is looking for. The protocol
commands include:
</para>
<variablelist>
<varlistentry>
<term><literal>PING</literal></term>
<listitem>
<para>Allows the test on the target to probe for the filter. The
filter responds with <literal>OK</literal>, while
<application>GDB</application> would just ignore the
command. This allows the tests to do nothing if they require the
filter and it is not present.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>CONFIG</literal></term>
<listitem>
<para>Requests a change of serial line configuration. Arguments
to the command specify baud rate, data bits, stop bits, and
parity. [This command is not fully implemented yet - there is no
attempt made to recover if the new configuration turns out to
cause loss of data.]</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>BINARY</literal></term>
<listitem>
<para>Requests data to be sent from the filter to the
target. The data is checksummed, allowing errors in the transfer
to be detected. Sub-options of this command control how the
data transfer is made:</para>
<variablelist>
<varlistentry>
<term><literal>NO_ECHO</literal></term>
<listitem>
<para>(serial driver receive test) Just send data from the
filter to the target. The test verifies the checksum and
PASS/FAIL depending on the result. </para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>EOP_ECHO</literal></term>
<listitem>
<para>(serial driver half-duplex receive and send test) As
<literal>NO_ECHO</literal> but the test echoes back the
data to the filter. The filter does a checksum on the
received data and sends the result to the target. The test
PASS/FAIL depending on the result of both checksum
verifications.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>DUPLEX_ECHO</literal></term>
<listitem>
<para>(serial driver duplex receive and send test) Smaller
packets of data are sent back and forth in a pattern that
ensures that the serial driver will be both sending and
receiving at the same time. Again, checksums are computed
and verified resulting in PASS/FAIL.
</para>
</listitem>
</varlistentry>
</variablelist>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>TEXT</literal></term>
<listitem>
<para> This is a test of the text translations in the TTY layer.
Requests a transfer of text data from the target to the filter
and possibly back again. The filter treats this as a binary
transfer, while the target ma be doing translations on the
data. The target provides the filter with checksums for what it
should expect to see. This test is not implemented yet.
</para>
</listitem>
</varlistentry>
</variablelist>
<para>The above commands may be extended, and new commands added, as
required to test (new) parts of the serial drivers in
<productname>eCos</productname>.
</para>
</section>
<!-- }}} -->
<!-- {{{ The Serial Tests -->
<section id="io-serfilter-serial-tests">
<title>The Serial Tests</title>
<para>
The serial tests are built as any other eCos test. After running the
<command>make tests</command> command, the tests can be found in
<filename>install/tests/io_serial/</filename></para>
<variablelist>
<varlistentry>
<term><filename>serial1</filename></term>
<listitem><para>A simple API test.</para></listitem>
</varlistentry>
<varlistentry>
<term><filename>serial2</filename></term>
<listitem>
<para>A simple serial send test. It writes out two strings, one
raw and one encoded as a <application>GDB</application>
O-packet</para>
</listitem>
</varlistentry>
<varlistentry>
<term><filename>serial3</filename> [ requires the serial filter ]</term>
<listitem>
<para>This tests the half-duplex send and receive capabilities
of the serial driver. </para>
</listitem>
</varlistentry>
<varlistentry>
<term><filename>serial4</filename> [ requires the serial filter ]</term>
<listitem>
<para>This test attempts to use a few different serial
configurations, testing the driver's configuration/setup
functionality. </para>
</listitem>
</varlistentry>
<varlistentry>
<term><filename>serial5</filename> [ requires the serial filter ]</term>
<listitem>
<para>This tests the duplex send and receive capabilities of the
serial driver. </para>
</listitem>
</varlistentry>
</variablelist>
<para>All tests should complete in less than 30 seconds.</para>
</section>
<!-- }}} -->
<!-- {{{ Serial Filter Usage-->
<section id="io-serfilter-usage">
<title>Serial Filter Usage</title>
<para>Running the ser_filter program with no (or wrong) arguments results in
the following output:
</para>
<screen>
Usage: ser_filter [-t -S] TcpIPport SerialPort BaudRate
or: ser_filter -n [-t -S] SerialPort BaudRate
-t: Enable tracing.
-S: Output data read from serial line.
-c: Output data on console instead of via GDB.
-n: No GDB.
</screen>
<para>The normal way to use it with GDB is to start the filter:</para>
<screen>
$ <userinput>ser_filter -t 9000 com1 38400</userinput>
</screen>
<para>
In this case, the filter will be listening on port 9000 and connect to the
target via the serial port <literal>COM1</literal> at 38400 baud. On a UNIX
host, replace "<literal>COM1</literal>" with a device such as
"<filename>/dev/ttyS0</filename>".
</para>
<para>
The <option>-t</option> option enables tracing which will cause the
filter to describe its actions on the console.
</para>
<para>Now start <application>GDB</application> with one of the tests as an
argument:
</para>
<screen>
$ <userinput>mips-tx39-elf-gdb -nw install/tests/io_serial/serial3</userinput>
</screen>
<para>Then connect to the filter:</para>
<screen>
(gdb) <userinput>target remote localhost:9000</userinput>
</screen>
<para>
This should result in a connection in exactly the same way as if you
had connected directly to the target on the serial line.
</para>
<screen>
(gdb) <userinput>c</userinput>
</screen>
<para>
Which should result in output similar to the below:
</para>
<screen>
Continuing.
INFO: <BINARY:16:1!>
PASS: <Binary test completed>
INFO: <BINARY:128:1!>
PASS: <Binary test completed>
INFO: <BINARY:256:1!>
PASS: <Binary test completed>
INFO: <BINARY:1024:1!>
PASS: <Binary test completed>
INFO: <BINARY:512:0!>
PASS: <Binary test completed>
...
PASS: <Binary test completed>
INFO: <BINARY:16384:0!>
PASS: <Binary test completed>
PASS: <serial13 test OK>
EXIT: <done>
</screen>
<para>
If any of the individual tests fail the testing will terminate with a
<computeroutput>FAIL</computeroutput>.
</para>
<para>
With tracing enabled, you would also see the filter's status output:
</para>
<para>
The <literal>PING</literal> command sent from the target to determine the
presence of the filter:
</para>
<screen>
[400 11:35:16] Dispatching command PING
[400 11:35:16] Responding with status OK
</screen>
<para>Each of the binary commands result in output similar to:</para>
<screen>
[400 11:35:16] Dispatching command BINARY
[400 11:35:16] Binary data (Size:16, Flags:1).
[400 11:35:16] Sending CRC: '170231!', len: 7.
[400 11:35:16] Reading 16 bytes from target.
[400 11:35:16] Done. in_crc 170231, out_crc 170231.
[400 11:35:16] Responding with status OK
[400 11:35:16] Received DONE from target.
</screen>
<para>
This tracing output is normally sent as O-packets to <application>GDB
</application> which will display the tracing text. By using the
<option>-c </option> option, the tracing text can be redirected to the
console from which ser_filter was started.
</para>
</section>
<!-- }}} -->
<!-- {{{ A Note on Failures -->
<section id="io-serfilter-failures">
<title>A Note on Failures</title>
<para>
A serial connection (especially when driven at a high baud rate) can garble the
transmitted data because of noise from the environment. It is not the job of
the serial driver to ensure data integrity - that is the job of protocols
layering on top of the serial driver. </para>
<para>In the current implementation the serial tests and the serial filter are
not resilient to such data errors. This means that the test may crash or hang
(possibly without reporting a <computeroutput>FAIL</computeroutput>). It also
means that you should be aware of random errors - a <computeroutput>FAIL
</computeroutput> is not necessarily caused by a bug in the serial driver.
</para>
<para>Ideally, the serial testing infrastructure should be able to distinguish
random errors from consistent errors - the former are most likely due to noise
in the transfer medium, while the latter are more likely to be caused by faulty
drivers. The current implementation of the infrastructure does not have this
capability.</para>
</section>
<!-- }}} -->
<!-- {{{ Debugging -->
<section id="io-serfilter-debugging">
<title>Debugging</title>
<para>If a test fails, the serial filter's output may provide some hints about
what the problem is. If the option <option>-S</option> is used when starting
the filter, data received from the target is printed out:
</para>
<screen>
[400 11:35:16] 0000 50 41 53 53 3a 3c 42 69 'PASS:<Bi'
[400 11:35:16] 0008 6e 61 72 79 20 74 65 73 'nary.tes'
[400 11:35:16] 0010 74 20 63 6f 6d 70 6c 65 't.comple'
[400 11:35:16] 0018 74 65 64 3e 0d 0a 49 4e 'ted>..IN'
[400 11:35:16] 0020 46 4f 3a 3c 42 49 4e 41 'FO:<BINA'
[400 11:35:16] 0028 52 59 3a 31 32 38 3a 31 'RY:128:1'
[400 11:35:16] 0030 21 3e 0d 0a 40 42 49 4e '!..@BIN'
[400 11:35:16] 0038 41 52 59 3a 31 32 38 3a 'ARY:128:'
[400 11:35:16] 0040 31 21 .. .. .. .. .. .. '1!'
</screen>
<para>In the case of an error during a testing command the data received by the
filter will be printed out, as will the data that was expected. This allows
the two data sets to be compared which may give some idea of what the problem
is.</para>
</section>
<!-- }}} -->
</section>
<!-- }}} -->
</chapter>
<!-- }}} -->
<!-- {{{ Device Driver API -->
<CHAPTER id="devapi-device-driver-interface-to-the-kernel">
<TITLE>Device Driver Interface to the Kernel</TITLE>
<PARA>
This chapter describes the API that device drivers may use
to interact with the kernel and HAL. It is primarily concerned with
the control and management of interrupts and the synchronization of
ISRs, DSRs and threads.
</PARA>
<PARA>
The same API will be present in configurations where the kernel
is not present. In this case the functions will be supplied by code
acting directly on the HAL.
</PARA>
<!-- {{{ Interrupt Model -->
<SECTION id="devapi-interrupt-model">
<TITLE>Interrupt Model</TITLE>
<PARA>
<EMPHASIS>eCos</EMPHASIS> presents a three level interrupt model to
<!-- <index></index> -->device drivers. This consists of <!--
<index></index> -->Interrupt Service Routines (ISRs) that are invoked
in response to a hardware interrupt; <!-- <index></index> -->Deferred
Service Routines (DSRs) that are invoked in response to a request by
an ISR; and threads that are the clients of the driver. </PARA>
<PARA>
Hardware interrupts are delivered with minimal intervention to an
ISR. The HAL decodes the hardware source of the interrupt and calls
the ISR of the attached interrupt object. This ISR may manipulate the
hardware but is only allowed to make a restricted set of calls on the
driver API. When it returns, an ISR may request that its DSR should be
scheduled to run.
</PARA>
<PARA>
A DSR will be run when it is safe to do so without interfering with
the scheduler. Most of the time the DSR will run immediately after the
ISR, but if the current thread is in the scheduler, it will be delayed
until the thread is finished. A DSR is allowed to make a larger set of
driver API calls, including, in particular, being able to call
<FUNCTION>cyg_drv_cond_signal()</FUNCTION> to wake up waiting
threads.
</PARA>
<PARA>
Finally, threads are able to make all API calls and in particular are
allowed to wait on mutexes and condition variables. </PARA>
<PARA>
For a device driver to receive interrupts it must first define ISR and
DSR routines as shown below, and then call
<FUNCTION>cyg_drv_interrupt_create()</FUNCTION>. Using the handle
returned, the driver must then call
<FUNCTION>cyg_drv_interrupt_attach()</FUNCTION> to actually attach the
interrupt to the hardware vector.
</PARA>
</SECTION>
<!-- }}} -->
<!-- {{{ Synchronization -->
<SECTION id="devapi-synchronization">
<TITLE><!-- <index></index> -->Synchronization</TITLE>
<PARA>There are three levels of synchronization supported:</PARA>
<ORDEREDLIST>
<LISTITEM>
<PARA>
Synchronization with ISRs. This normally means disabling
interrupts to prevent the ISR running during a critical
section. In an SMP environment, this will also require the use of
a spinlock to synchronize with ISRs, DSRs or threads running on
other CPUs. This is implemented by the
<FUNCTION>cyg_drv_isr_lock()</FUNCTION> and
<FUNCTION>cyg_drv_isr_unlock()</FUNCTION> functions. This
mechanism should be used sparingly and for short periods only.
For finer grained synchronization, individual spinlocks are also
supplied.
</PARA>
</LISTITEM>
<LISTITEM>
<PARA>
Synchronization with DSRs. This will be implemented in the kernel
by taking the scheduler lock to prevent DSRs running during
critical sections. In non-kernel configurations it will be
implemented by non-kernel code. This is implemented by the
<FUNCTION>cyg_drv_dsr_lock()</FUNCTION> and
<FUNCTION>cyg_drv_dsr_unlock()</FUNCTION> functions. As with ISR
synchronization, this mechanism should be used sparingly. Only
DSRs and threads may use this synchronization mechanism, ISRs are
not allowed to do this.
</PARA>
</LISTITEM>
<LISTITEM>
<PARA>
Synchronization with threads. This is implemented with mutexes
and condition variables. Only threads may lock the mutexes and
wait on the condition variables, although DSRs may signal
condition variables.
</PARA>
</LISTITEM>
</ORDEREDLIST>
<PARA>
Any data that is accessed from more than one level must be protected
against concurrent access. Data that is accessed by ISRs must be
protected with the ISR lock, or a spinlock at all times,
<emphasis>even in ISRs</emphasis>. Data that is shared between DSRs
and threads should be protected with the DSR lock. Data that is only
accessed by threads must be protected with mutexes.
</PARA>
</SECTION>
<!-- }}} -->
<!-- {{{ SMP Support -->
<SECTION id="devapi-smp-support">
<TITLE><!-- <index></index> -->SMP Support</TITLE>
<para>
Some eCos targets contain support for Symmetric Multi-Processing (SMP)
configurations, where more than one CPU may be present. This option
has a number of ramifications for the way in which device drivers must
be written if they are to be SMP-compatible.
</para>
<para>
Since it is possible for the ISR, DSR and thread components of a
device driver to execute on different CPUs, it is important that
SMP-compatible device drivers use the driver API routines correctly.
</para>
<para>
Synchronization between threads and DSRs continues to require that the
thread-side code use <function>cyg_drv_dsr_lock()</function> and
<function>cyg_drv_dsr_unlock()</function> to protect access to shared
data. While it is not strictly necessary for DSR code to claim the DSR
lock, since DSRs are run with it claimed already, it is good practice
to do so.
</para>
<para>
Synchronization between ISRs and DSRs or threads requires that access
to sensitive data be protected, in all places, by calls to
<function>cyg_drv_isr_lock()</function> and
<function>cyg_drv_isr_unlock()</function>. Disabling or masking
interrupts is not adequate, since the thread or DSR may be running on
a different CPU and interrupt enable/disable only work on the current
CPU.
</para>
<para>
The ISR lock, for SMP systems, not only disables local interrupts, but
also acquires a spinlock to protect against concurrent access from
other CPUs. This is necessary because ISRs are not run with the
scheduler lock claimed. Hence they can run in parallel with the other
components of the device driver.
</para>
<para>
The ISR lock provided by the driver API is just a shared spinlock that
is available for use by all drivers. If a driver needs to implement a
finer grain of locking, it can use private spinlocks, accessed via the
<function>cyg_drv_spinlock_*()</function> functions.
</para>
</section>
<!-- }}} -->
<!-- {{{ Device Driver Models -->
<SECTION id="devapi-device-driver-models">
<TITLE>Device Driver Models</TITLE>
<PARA>
There are several ways in which <!-- <index></index> -->device drivers
may be built. The exact model chosen will depend on the properties of
the device and the behavior desired. There are three basic models that
may be adopted.
</PARA>
<PARA>
The first model is to do all device processing in the ISR. When it is
invoked the ISR programs the device hardware directly and accesses
data to be transferred directly in memory. The ISR should also call
<FUNCTION>cyg_drv_interrupt_acknowledge()</FUNCTION>. When it is
finished it may optionally request that its DSR be invoked. The DSR
does nothing but call <FUNCTION>cyg_drv_cond_signal()</FUNCTION> to
cause a thread to be woken up. Thread level code must call
<FUNCTION>cyg_drv_isr_lock()</FUNCTION>, or
<FUNCTION>cyg_drv_interrupt_mask()</FUNCTION> to prevent ISRs running
while it manipulates shared memory.
</PARA>
<PARA>
The second model is to defer device processing to the DSR. The ISR
simply prevents further delivery of interrupts by either programming
the device, or by calling
<FUNCTION>cyg_drv_interrupt_mask()</FUNCTION>. It must then call
<FUNCTION>cyg_drv_interrupt_acknowledge()</FUNCTION> to allow other
interrupts to be delivered and then request that its DSR be
called. When the DSR runs it does the majority of the device handling,
optionally signals a condition variable to wake a thread, and finishes
by calling <FUNCTION>cyg_drv_interrupt_unmask()</FUNCTION> to re-allow
device interrupts. Thread level code uses
<FUNCTION>cyg_drv_dsr_lock()</FUNCTION> to prevent DSRs running while
it manipulates shared memory. The eCos serial device drivers use this
approach.
</PARA>
<PARA>
The third model is to defer device processing even further to a
thread. The ISR behaves exactly as in the previous model and simply
blocks and acknowledges the interrupt before request that the DSR
run. The DSR itself only calls
<FUNCTION>cyg_drv_cond_signal()</FUNCTION> to wake the thread. When
the thread awakens it performs all device processing, and has full
access to all kernel facilities while it does so. It should finish by
calling <FUNCTION>cyg_drv_interrupt_unmask()</FUNCTION> to re-allow
device interrupts. The eCos ethernet device drivers are written to
this model.
</PARA>
<PARA>
The first model is good for devices that need immediate processing and
interact infrequently with thread level. The second model trades a
little latency in dealing with the device for a less intrusive
synchronization mechanism. The last model allows device processing to
be scheduled with other threads and permits more complex device
handling.
</PARA>
</SECTION>
<!-- }}} -->
<!-- {{{ Synchronization Levels -->
<SECTION id="devapi-synchronization-levels">
<TITLE>Synchronization Levels</TITLE>
<PARA>
Since it would be dangerous for an ISR or DSR to make a call
that might reschedule the current thread (by trying to lock a mutex
for example) all functions in this API have an associated synchronization
level. These levels are:
</PARA>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Thread</TERM>
<LISTITEM>
<PARA>
This function may only be called from within threads. This is
usually the client code that makes calls into the device driver.
In a non-kernel configuration, this will be code running at the
default non-interrupt level.
</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>DSR</TERM>
<LISTITEM>
<PARA>
This function may be called by either DSR or thread code.
</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>ISR</TERM>
<LISTITEM>
<PARA>
This function may be called from ISR, DSR or thread code.
</PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
<PARA>
The following table shows, for each API function, the levels
at which is may be called:
</PARA>
<PROGRAMLISTING role="ascii-art">
Callable from:
Function ISR DSR Thread
-------------------------------------------------------------------------
cyg_drv_isr_lock X X X
cyg_drv_isr_unlock X X X
cyg_drv_spinlock_init X
cyg_drv_spinlock_destroy X
cyg_drv_spinlock_spin X X X
cyg_drv_spinlock_clear X X X
cyg_drv_spinlock_try X X X
cyg_drv_spinlock_test X X X
cyg_drv_spinlock_spin_intsave X X X
cyg_drv_spinlock_clear_intsave X X X
cyg_drv_dsr_lock X X
cyg_drv_dsr_unlock X X
cyg_drv_mutex_init X
cyg_drv_mutex_destroy X
cyg_drv_mutex_lock X
cyg_drv_mutex_trylock X
cyg_drv_mutex_unlock X
cyg_drv_mutex_release X
cyg_drv_cond_init X
cyg_drv_cond_destroy X
cyg_drv_cond_wait X
cyg_drv_cond_signal X X
cyg_drv_cond_broadcast X X
cyg_drv_interrupt_create X
cyg_drv_interrupt_delete X
cyg_drv_interrupt_attach X X X
cyg_drv_interrupt_detach X X X
cyg_drv_interrupt_mask X X X
cyg_drv_interrupt_unmask X X X
cyg_drv_interrupt_acknowledge X X X
cyg_drv_interrupt_configure X X X
cyg_drv_interrupt_level X X X
cyg_drv_interrupt_set_cpu X X X
cyg_drv_interrupt_get_cpu X X X
</PROGRAMLISTING>
</SECTION>
<!-- }}} -->
<!-- {{{ The API -->
<SECTION id="devapi-api">
<TITLE>The API</TITLE>
<PARA>
This section details the <!-- <index></index> -->Driver Kernel
Interface. Note that most of these functions are identical to Kernel C
API calls, and will in most configurations be wrappers for them. In
non-kernel configurations they will be supported directly by the HAL,
or by code to emulate the required behavior.
</PARA>
<PARA>This API is defined in the header file
<FILENAME><cyg/hal/drv_api.h></FILENAME>.
</PARA>
<!-- {{{ cyg_drv_isr_lock -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_isr_lock</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function:</TERM>
<LISTITEM>
<programlisting>void cyg_drv_isr_lock()</programlisting>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA>None</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result:</TERM>
<LISTITEM>
<PARA>None </PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level:</TERM>
<LISTITEM>
<PARA>ISR</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description:</TERM>
<LISTITEM>
<PARA>
Disables delivery of interrupts, preventing all ISRs running. This
function maintains a counter of the number of times it is
called.
</PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_isr_unlock -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_isr_unlock</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function: </TERM>
<LISTITEM>
<programlisting>void cyg_drv_isr_unlock()</programlisting>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA>None</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result: </TERM>
<LISTITEM>
<PARA>None </PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level: </TERM>
<LISTITEM>
<PARA>ISR</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description: </TERM>
<LISTITEM>
<PARA>Re-enables delivery of interrupts, allowing ISRs to
run. This function decrements the counter maintained by
<FUNCTION>cyg_drv_isr_lock()</FUNCTION>, and only re-allows
interrupts when it goes to zero. </PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_spinlock_init -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_spinlock_init</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function:</TERM>
<LISTITEM>
<programlisting>
void cyg_drv_spinlock_init(cyg_spinlock_t *lock, cyg_bool_t locked )
</programlisting>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>lock</parameter> - pointer to spinlock to initialize</PARA>
<PARA><parameter>locked</parameter> - initial state of lock</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result:</TERM>
<LISTITEM>
<PARA>None</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level:</TERM>
<LISTITEM>
<PARA>Thread</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description:</TERM>
<LISTITEM>
<para>
Initialize a spinlock. The <parameter>locked</parameter>
argument indicates how the spinlock should be initialized:
<literal>TRUE</literal> for locked or <literal>FALSE</literal>
for unlocked state.
</para>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_spinlock_destroy -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_spinlock_destroy</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function:</TERM>
<LISTITEM>
<programlisting>void cyg_drv_spinlock_destroy(cyg_spinlock_t *lock )</programlisting>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>lock</parameter> - pointer to spinlock destroy</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result:</TERM>
<LISTITEM>
<PARA>None</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level:</TERM>
<LISTITEM>
<PARA>Thread</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description:</TERM>
<LISTITEM>
<para>
Destroy a spinlock that is no longer of use. There should be no
CPUs attempting to claim the lock at the time this function is
called, otherwise the behavior is undefined.
</para>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_spinlock_spin -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_spinlock_spin</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function:</TERM>
<LISTITEM>
<programlisting>void cyg_drv_spinlock_spin(cyg_spinlock_t *lock )</programlisting>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>lock</parameter> - pointer to spinlock to claim</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result:</TERM>
<LISTITEM>
<PARA>None</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level:</TERM>
<LISTITEM>
<PARA>ISR</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description:</TERM>
<LISTITEM>
<para>
Claim a spinlock, waiting in a busy loop until it is
available. Wherever this is called from, this operation
effectively pauses the CPU until it succeeds. This operations
should therefore be used sparingly, and in situations where
deadlocks/livelocks cannot occur. Also see
<function>cyg_drv_spinlock_spin_intsave()</function>.
</para>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_spinlock_clear -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_spinlock_clear</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function:</TERM>
<LISTITEM>
<programlisting>void cyg_drv_spinlock_clear(cyg_spinlock_t *lock )</programlisting>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>lock</parameter> - pointer to spinlock to clear </PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result:</TERM>
<LISTITEM>
<PARA>None</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level:</TERM>
<LISTITEM>
<PARA>ISR</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description:</TERM>
<LISTITEM>
<para>
Clear a spinlock. This clears the spinlock and allows another
CPU to claim it. If there is more than one CPU waiting in
<function>cyg_drv_spinlock_spin()</function> then just one of
them will be allowed to proceed.
</para>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_spinlock_try -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_spinlock_try</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function:</TERM>
<LISTITEM>
<programlisting>cyg_bool_t cyg_drv_spinlock_try(cyg_spinlock_t *lock )</programlisting>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>lock</parameter> - pointer to spinlock to try</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result:</TERM>
<LISTITEM>
<PARA><literal>TRUE</literal> if the spinlock was claimed,
<literal>FALSE</literal> otherwise.</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level:</TERM>
<LISTITEM>
<PARA>ISR</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description:</TERM>
<LISTITEM>
<para>
Try to claim the spinlock without waiting. If the spinlock could
be claimed immediately then <literal>TRUE</literal> is
returned. If the spinlock is already claimed then the result is
<literal>FALSE</literal>.
</para>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_spinlock_test -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_spinlock_test</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function:</TERM>
<LISTITEM>
<programlisting>cyg_bool_t cyg_drv_spinlock_test(cyg_spinlock_t *lock )</programlisting>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>lock</parameter> - pointer to spinlock to test</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result:</TERM>
<LISTITEM>
<PARA><literal>TRUE</literal> if the spinlock is available,
<literal>FALSE</literal> otherwise.</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level:</TERM>
<LISTITEM>
<PARA>ISR</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description:</TERM>
<LISTITEM>
<para>
Inspect the state of the spinlock. If the spinlock is not locked
then the result is <literal>TRUE</literal>. If it is locked then
the result will be <literal>FALSE</literal>.
</para>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_spinlock_spin_intsave -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_spinlock_spin_intsave</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function:</TERM>
<LISTITEM>
<programlisting>
void cyg_drv_spinlock_spin_intsave(cyg_spinlock_t *lock,
cyg_addrword_t *istate )
</programlisting>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>lock</parameter> - pointer to spinlock to claim</PARA>
<PARA><parameter>istate</parameter> - pointer to interrupt state save location</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result:</TERM>
<LISTITEM>
<PARA>None</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level:</TERM>
<LISTITEM>
<PARA>ISR</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description:</TERM>
<LISTITEM>
<para>
This function behaves exactly like
<function>cyg_drv_spinlock_spin()</function> except that it also
disables interrupts before attempting to claim the lock. The
current interrupt enable state is saved in
<parameter>*istate</parameter>. Interrupts remain disabled once
the spinlock had been claimed and must be restored by calling
<function>cyg_drv_spinlock_clear_intsave()</function>.
</para>
<para>
In general, device drivers should use this function to claim and
release spinlocks rather than the
non-<function>_intsave()</function> variants, to ensure proper
exclusion with code running on both other CPUs and this CPU.
</para>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_spinlock_clear_intsave -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_spinlock_clear_intsave</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function:</TERM>
<LISTITEM>
<programlisting>
void cyg_drv_spinlock_clear_intsave( cyg_spinlock_t *lock,
cyg_addrword_t istate )
</programlisting>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>lock</parameter> - pointer to spinlock to clear </PARA>
<PARA><parameter>istate</parameter> - interrupt state to restore </PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result:</TERM>
<LISTITEM>
<PARA>None</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level:</TERM>
<LISTITEM>
<PARA>ISR</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description:</TERM>
<LISTITEM>
<para>
This function behaves exactly like
<function>cyg_drv_spinlock_clear()</function> except that it
also restores an interrupt state saved by
<function>cyg_drv_spinlock_spin_intsave()</function>. The
<parameter>istate</parameter> argument must have been
initialized by a previous call to
<function>cyg_drv_spinlock_spin_intsave()</function>.
</para>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_dsr_lock -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_dsr_lock</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function:</TERM>
<LISTITEM>
<programlisting>void cyg_drv_dsr_lock()</programlisting>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA>None</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result: </TERM>
<LISTITEM>
<PARA>None </PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level: </TERM>
<LISTITEM>
<PARA>DSR</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description: </TERM>
<LISTITEM>
<PARA>Disables scheduling of DSRs. This function maintains a
counter of the number of times it has been called. </PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_dsr_unlock -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_dsr_unlock</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function: </TERM>
<LISTITEM>
<programlisting>void cyg_drv_dsr_unlock()</programlisting>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA>None</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result:</TERM>
<LISTITEM>
<PARA> </PARA>
<PARA>None </PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level:</TERM>
<LISTITEM>
<PARA>DSR</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description: </TERM>
<LISTITEM>
<PARA>Re-enables scheduling of DSRs. This function decrements
the counter incremented by
<FUNCTION>cyg_drv_dsr_lock()</FUNCTION>. DSRs are only allowed
to be delivered when the counter goes to zero. </PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_mutex_init -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_mutex_init</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function: </TERM>
<LISTITEM>
<programlisting>void cyg_drv_mutex_init(cyg_drv_mutex_t *mutex)</programlisting>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>mutex</parameter> - pointer to mutex to initialize</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result: </TERM>
<LISTITEM>
<PARA>None </PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level: </TERM>
<LISTITEM>
<PARA>Thread</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description: </TERM>
<LISTITEM>
<PARA>Initialize the mutex pointed to by the
<literal>mutex</literal> argument. </PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_mutex_destroy -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_mutex_destroy</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function: </TERM>
<LISTITEM>
<programlisting>void cyg_drv_mutex_destroy( cyg_drv_mutex_t *mutex )</programlisting>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>mutex</parameter> - pointer to mutex to destroy</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result: </TERM>
<LISTITEM>
<PARA>None </PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level: </TERM>
<LISTITEM>
<PARA>Thread</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description: </TERM>
<LISTITEM>
<PARA>Destroy the mutex pointed to by the
<parameter>mutex</parameter> argument. The mutex should be unlocked
and there should be no threads waiting to lock it when this call
in made.</PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_mutex_lock -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_mutex_lock</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function: </TERM>
<LISTITEM>
<programlisting>cyg_bool cyg_drv_mutex_lock( cyg_drv_mutex_t *mutex )</programlisting>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>mutex</parameter> - pointer to mutex to lock</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result:</TERM>
<LISTITEM>
<PARA><literal>TRUE</literal> it the thread has claimed the
lock, <literal>FALSE</literal> otherwise.</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level:</TERM>
<LISTITEM>
<PARA>Thread</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description: </TERM>
<LISTITEM>
<PARA>Attempt to lock the mutex pointed to by the
<parameter>mutex</parameter> argument. If the mutex is already
locked by another thread then this thread will wait until that
thread is finished. If the result from this function is
<literal>FALSE</literal> then the thread was broken out of its
wait by some other thread. In this case the mutex will not have
been locked. </PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_mutex_trylock -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_mutex_trylock</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function:</TERM>
<LISTITEM>
<PARA><programlisting>cyg_bool cyg_drv_mutex_trylock( cyg_drv_mutex_t *mutex )</programlisting></PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>mutex</parameter> - pointer to mutex to lock</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result:</TERM>
<LISTITEM>
<PARA><literal>TRUE</literal> if the mutex has been locked,
<literal>FALSE</literal> otherwise. </PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level:</TERM>
<LISTITEM>
<PARA>Thread</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description:</TERM>
<LISTITEM>
<PARA>Attempt to lock the mutex pointed to by the
<parameter>mutex</parameter> argument without waiting. If the
mutex is already locked by some other thread then this function
returns <literal>FALSE</literal>. If the function can lock the
mutex without waiting, then <literal>TRUE</literal> is
returned. </PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_mutex_unlock -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_mutex_unlock</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function: </TERM>
<LISTITEM>
<programlisting>void cyg_drv_mutex_unlock( cyg_drv_mutex_t *mutex )</programlisting>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>mutex</parameter> - pointer to mutex to unlock</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result: </TERM>
<LISTITEM>
<PARA>None </PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level: </TERM>
<LISTITEM>
<PARA>Thread</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description: </TERM>
<LISTITEM>
<PARA>Unlock the mutex pointed to by the
<parameter>mutex</parameter> argument. If there are any threads
waiting to claim the lock, one of them is woken up to try and
claim it. </PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_mutex_release -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_mutex_release</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function: </TERM>
<LISTITEM>
<programlisting>void cyg_drv_mutex_release( cyg_drv_mutex_t *mutex )</programlisting>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><literal>mutex</literal> - pointer to mutex to release</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result: </TERM>
<LISTITEM>
<PARA>None </PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level: </TERM>
<LISTITEM>
<PARA>Thread</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description: </TERM>
<LISTITEM>
<PARA>Release all threads waiting on the mutex pointed to by the
<parameter>mutex</parameter> argument. These threads will return
from <FUNCTION>cyg_drv_mutex_lock()</FUNCTION> with a
<literal>FALSE</literal> result and will not have claimed the
mutex. This function has no effect on any thread that may have
the mutex claimed. </PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_cond_init -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_cond_init</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function: </TERM>
<LISTITEM>
<programlisting> void cyg_drv_cond_init( cyg_drv_cond_t *cond, cyg_drv_mutex_t *mutex )
</programlisting>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>cond</parameter> - condition variable to initialize</PARA>
<PARA><parameter>mutex</parameter> - mutex to associate with this condition variable</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result: </TERM>
<LISTITEM>
<PARA>None</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level: </TERM>
<LISTITEM>
<PARA>Thread </PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description: </TERM>
<LISTITEM>
<PARA>Initialize the condition variable pointed to by the
<parameter>cond</parameter> argument. The
<parameter>mutex</parameter> argument must point to a mutex with
which this condition variable is associated. A thread may only
wait on this condition variable when it has already locked the
associated mutex. Waiting will cause the mutex to be unlocked,
and when the thread is reawakened, it will automatically claim
the mutex before continuing. </PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_cond_destroy -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_cond_destroy</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function: </TERM>
<LISTITEM>
<programlisting> void cyg_drv_cond_destroy( cyg_drv_cond_t *cond )</programlisting>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>cond</parameter> - condition variable to destroy</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result: </TERM>
<LISTITEM>
<PARA>None </PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level: </TERM>
<LISTITEM>
<PARA>Thread</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description: </TERM>
<LISTITEM>
<PARA>Destroy the condition variable pointed to by the
<parameter>cond</parameter> argument. </PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_cond_wait -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_cond_wait</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function: </TERM>
<LISTITEM>
<programlisting>void cyg_drv_cond_wait( cyg_drv_cond_t *cond )</programlisting>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>cond</parameter> - condition variable to wait on</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result: </TERM>
<LISTITEM>
<PARA>None </PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level: </TERM>
<LISTITEM>
<PARA>Thread</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description: </TERM>
<LISTITEM>
<PARA>Wait for a signal on the condition variable pointed to by
the <parameter>cond</parameter> argument. The thread must have
locked the associated mutex, supplied in
<function>cyg_drv_cond_init()</function>, before waiting on this
condition variable. While the thread waits, the mutex will be
unlocked, and will be re-locked before this function returns. It
is possible for threads waiting on a condition variable to
occasionally wake up spuriously. For this reason it is necessary
to use this function in a loop that re-tests the condition each
time it returns. Note that this function performs an implicit
scheduler unlock/relock sequence, so that it may be used within
an explicit
<literal>cyg_drv_dsr_lock()...cyg_drv_dsr_unlock()</literal>
structure.</PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_cond_signal -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_cond_signal</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function: </TERM>
<LISTITEM>
<programlisting>void cyg_drv_cond_signal( cyg_drv_cond_t *cond )</programlisting>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>cond</parameter> - condition variable to signal</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result: </TERM>
<LISTITEM>
<PARA>None </PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level: </TERM>
<LISTITEM>
<PARA>DSR</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description: </TERM>
<LISTITEM>
<PARA>Signal the condition variable pointed to by the <parameter>cond</parameter>
argument. If there are any threads waiting on this variable at
least one of them will be awakened. Note that in some
configurations there may not be any difference between this
function and <FUNCTION>cyg_drv_cond_broadcast()</FUNCTION>.
</PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_cond_broadcast -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_cond_broadcast</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function: </TERM>
<LISTITEM>
<programlisting>void cyg_drv_cond_broadcast( cyg_drv_cond_t *cond )</programlisting>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>cond</parameter> - condition variable to broadcast to</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result: </TERM>
<LISTITEM>
<PARA>None </PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level: </TERM>
<LISTITEM>
<PARA>DSR</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description: </TERM>
<LISTITEM>
<PARA>Signal the condition variable pointed to by the
<parameter>cond</parameter> argument. If there are any threads
waiting on this variable they will all be awakened. </PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_interrupt_create -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_interrupt_create</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function: </TERM>
<LISTITEM>
<PROGRAMLISTING>
void cyg_drv_interrupt_create( cyg_vector_t vector,
cyg_priority_t priority,
cyg_addrword_t data,
cyg_ISR_t *isr,
cyg_DSR_t *dsr,
cyg_handle_t *handle,
cyg_interrupt *intr
)
</PROGRAMLISTING>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>vector</parameter> - vector to attach to</PARA>
<PARA><parameter>priority</parameter> - queuing priority</PARA>
<PARA><parameter>data</parameter> - data pointer</PARA>
<PARA><parameter>isr</parameter> - interrupt service routine</PARA>
<PARA><parameter>dsr</parameter> - deferred service routine</PARA>
<PARA><parameter>handle</parameter> - returned handle</PARA>
<PARA><parameter>intr</parameter> - put interrupt object here</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result: </TERM>
<LISTITEM>
<PARA>None</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level: </TERM>
<LISTITEM>
<PARA>Thread</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description: </TERM>
<LISTITEM>
<PARA>Create an interrupt object and returns a handle to it. The
object contains information about which interrupt vector to use
and the ISR and DSR that will be called after the interrupt
object is attached to the vector. The interrupt object will be
allocated in the memory passed in the
<parameter>intr</parameter> parameter. The interrupt object is
not immediately attached; it must be attached with the
<FUNCTION>cyg_interrupt_attach()</FUNCTION> call. </PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_interrupt_delete -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_interrupt_delete</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function: </TERM>
<LISTITEM>
<programlisting> void cyg_drv_interrupt_delete( cyg_handle_t interrupt )</programlisting>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>interrupt</parameter> - interrupt to delete</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result: </TERM>
<LISTITEM>
<PARA>None </PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level: </TERM>
<LISTITEM>
<PARA>Thread</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description: </TERM>
<LISTITEM>
<PARA>Detach the interrupt from the vector and free the memory
passed in the <parameter>intr</parameter> argument to
<FUNCTION>cyg_drv_interrupt_create()</FUNCTION> for
reuse. </PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_interrupt_attach -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_interrupt_attach</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function: </TERM>
<LISTITEM>
<programlisting>void cyg_drv_interrupt_attach( cyg_handle_t interrupt )</programlisting>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>interrupt</parameter> - interrupt to attach</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result: </TERM>
<LISTITEM>
<PARA>None </PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level: </TERM>
<LISTITEM>
<PARA>ISR</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description: </TERM>
<LISTITEM>
<PARA>Attach the interrupt to the vector so that interrupts will
be delivered to the ISR when the interrupt occurs. </PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_interrupt_detach -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_interrupt_detach</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function: </TERM>
<LISTITEM>
<programlisting>void cyg_drv_interrupt_detach( cyg_handle_t interrupt )</programlisting>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>interrupt</parameter> - interrupt to detach</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result: </TERM>
<LISTITEM>
<PARA>None </PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level: </TERM>
<LISTITEM>
<PARA>ISR</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description: </TERM>
<LISTITEM>
<PARA>Detach the interrupt from the vector so that interrupts
will no longer be delivered to the ISR. </PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_interrupt_mask -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_interrupt_mask</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function: </TERM>
<LISTITEM>
<programlisting>void cyg_drv_interrupt_mask(cyg_vector_t vector )</programlisting>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>vector</parameter> - vector to mask</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result: </TERM>
<LISTITEM>
<PARA>None </PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level: </TERM>
<LISTITEM>
<PARA>ISR</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description: </TERM>
<LISTITEM>
<PARA>Program the interrupt controller to stop delivery of
interrupts on the given vector. On architectures which implement
interrupt priority levels this may also disable all lower
priority interrupts. </PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_interrupt_mask_intunsafe -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_interrupt_mask_intunsafe</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function: </TERM>
<LISTITEM>
<programlisting>void cyg_drv_interrupt_mask_intunsafe(cyg_vector_t vector )</programlisting>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>vector</parameter> - vector to mask</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result: </TERM>
<LISTITEM>
<PARA>None </PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level: </TERM>
<LISTITEM>
<PARA>ISR</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description: </TERM>
<LISTITEM>
<PARA>Program the interrupt controller to stop delivery of
interrupts on the given vector. On architectures which implement
interrupt priority levels this may also disable all lower
priority interrupts. This version differs from
<function>cyg_drv_interrupt_mask()</function> in not being
interrupt safe. So in situations where, for example, interrupts
are already known to be disabled, this may be called to avoid
the extra overhead.</PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_interrupt_unmask -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_interrupt_unmask</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function: </TERM>
<LISTITEM>
<programlisting>void cyg_drv_interrupt_unmask(cyg_vector_t vector )</programlisting>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>vector</parameter> - vector to unmask</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result: </TERM>
<LISTITEM>
<PARA>None </PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level: </TERM>
<LISTITEM>
<PARA>ISR</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description: </TERM>
<LISTITEM>
<PARA>Program the interrupt controller to re-allow delivery of
interrupts on the given <parameter>vector</parameter>. </PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_interrupt_unmask_intunsafe -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_interrupt_unmask_intunsafe</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function: </TERM>
<LISTITEM>
<programlisting>void cyg_drv_interrupt_unmask_intunsafe(cyg_vector_t vector )</programlisting>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>vector</parameter> - vector to unmask</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result: </TERM>
<LISTITEM>
<PARA>None </PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level: </TERM>
<LISTITEM>
<PARA>ISR</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description: </TERM>
<LISTITEM>
<PARA>Program the interrupt controller to re-allow delivery of
interrupts on the given <parameter>vector</parameter>. This
version differs from
<function>cyg_drv_interrupt_unmask()</function> in not being
interrupt safe.</PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_interrupt_acknowledge -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_interrupt_acknowledge</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function: </TERM>
<LISTITEM>
<programlisting>void cyg_drv_interrupt_acknowledge( cyg_vector_t vector )</programlisting>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>vector</parameter> - vector to acknowledge</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result: </TERM>
<LISTITEM>
<PARA>None </PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level: </TERM>
<LISTITEM>
<PARA>ISR</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description: </TERM>
<LISTITEM>
<PARA>Perform any processing required at the interrupt
controller and in the CPU to cancel the current interrupt
request on the <parameter>vector</parameter>. An ISR may also
need to program the hardware of the device to prevent an
immediate re-triggering of the interrupt. </PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_interrupt_configure -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_interrupt_configure</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function: </TERM>
<LISTITEM>
<PROGRAMLISTING>
void cyg_drv_interrupt_configure( cyg_vector_t vector,
cyg_bool_t level,
cyg_bool_t up
)
</PROGRAMLISTING>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>vector</parameter> - vector to configure</PARA>
<PARA><parameter>level</parameter> - level or edge triggered</PARA>
<PARA><parameter>up</parameter> - rising/falling edge, high/low level</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result: </TERM>
<LISTITEM>
<PARA>None</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level: </TERM>
<LISTITEM>
<PARA>ISR</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description: </TERM>
<LISTITEM>
<PARA>Program the interrupt controller with the characteristics
of the interrupt source. The <parameter>level</parameter>
argument chooses between level- or edge-triggered
interrupts. The <parameter>up</parameter> argument chooses
between high and low level for level triggered interrupts or
rising and falling edges for edge triggered interrupts. This
function only works with interrupt controllers that can control
these parameters. </PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_interrupt_level -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_interrupt_level</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function: </TERM>
<LISTITEM>
<PROGRAMLISTING>
void cyg_drv_interrupt_level( cyg_vector_t vector,
cyg_priority_t level
)
</PROGRAMLISTING>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>vector</parameter> - vector to configure</PARA>
<PARA><parameter>level</parameter> - level to set</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result: </TERM>
<LISTITEM>
<PARA>None </PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level: </TERM>
<LISTITEM>
<PARA>ISR</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description: </TERM>
<LISTITEM>
<PARA>Program the interrupt controller to deliver the given
interrupt at the supplied priority level. This function only
works with interrupt controllers that can control this
parameter.</PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_interrupt_set_cpu -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_interrupt_set_cpu</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function:</TERM>
<LISTITEM>
<PROGRAMLISTING>
void cyg_drv_interrupt_set_cpu( cyg_vector_t vector,
cyg_cpu_t cpu
)
</PROGRAMLISTING>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>vector</parameter> - interrupt vector to route</PARA>
<PARA><parameter>cpu</parameter> - destination CPU</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result:</TERM>
<LISTITEM>
<PARA>None</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level:</TERM>
<LISTITEM>
<PARA>ISR</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description: </TERM>
<LISTITEM>
<PARA>
This function causes all interrupts on the given vector to be
routed to the specified CPU. Subsequently, all such interrupts
will be handled by that CPU. This only works if the underlying
hardware is capable of performing this kind of routing. This
function does nothing on a single CPU system.
</PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_drv_interrupt_get_cpu -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_drv_interrupt_get_cpu</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Function:</TERM>
<LISTITEM>
<PROGRAMLISTING>
cyg_cpu_t cyg_drv_interrupt_set_cpu( cyg_vector_t vector )
</PROGRAMLISTING>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Arguments:</TERM>
<LISTITEM>
<PARA><parameter>vector</parameter> - interrupt vector to query</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result:</TERM>
<LISTITEM>
<PARA>The CPU to which this vector is routed</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Level:</TERM>
<LISTITEM>
<PARA>ISR</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description: </TERM>
<LISTITEM>
<PARA>
In multi-processor systems this function returns the id of the
CPU to which interrupts on the given vector are current being
delivered. In single CPU systems this function returns zero.
</PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_ISR_t -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_ISR_t</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Type: </TERM>
<LISTITEM>
<PROGRAMLISTING>
typedef cyg_uint32 cyg_ISR_t( cyg_vector_t vector,
cyg_addrword_t data
)
</PROGRAMLISTING>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Fields:</TERM>
<LISTITEM>
<PARA><parameter>vector</parameter> - vector being delivered</PARA>
<PARA><parameter>data</parameter> - data value supplied by client</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result: </TERM>
<LISTITEM>
<PARA>Bit mask indicating whether interrupt was handled and
whether the DSR should be called. </PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description: </TERM>
<LISTITEM>
<PARA>Interrupt Service Routine definition. A pointer to a
function with this prototype is passed to
<FUNCTION>cyg_interrupt_create()</FUNCTION> when an interrupt
object is created. When an interrupt is delivered the function
will be called with the vector number and the data value that
was passed to <FUNCTION>cyg_interrupt_create()</FUNCTION>.
</PARA>
<PARA>The return value is a bit mask containing one or both of the
following bits: </PARA>
<variablelist>
<VARLISTENTRY>
<TERM>CYG_ISR_HANDLED </TERM>
<LISTITEM>
<PARA>indicates that the interrupt was handled by this
ISR. It is a configuration option whether this will
prevent further ISR being run. </PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>CYG_ISR_CALL_DSR </TERM>
<LISTITEM>
<PARA>causes the DSR that was passed to
<FUNCTION>cyg_interrupt_create()</FUNCTION> to be
scheduled to be called.</PARA>
</LISTITEM>
</VARLISTENTRY>
</variablelist>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
<!-- {{{ cyg_DSR_t -->
<SECTION>
<TITLE><!-- <index></index> -->cyg_DSR_t</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>Type: </TERM>
<LISTITEM>
<PROGRAMLISTING>
typedef void cyg_DSR_t( cyg_vector_t vector,
cyg_ucount32 count,
cyg_addrword_t data
)
</PROGRAMLISTING>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Fields:</TERM>
<LISTITEM>
<PARA><parameter>vector</parameter> - vector being delivered</PARA>
<PARA><parameter>count</parameter> - number of times DSR has been scheduled</PARA>
<PARA><parameter>data</parameter> - data value supplied by client</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Result: </TERM>
<LISTITEM>
<PARA>None</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM>Description: </TERM>
<LISTITEM>
<PARA>Deferred Service Routine prototype. A pointer to a
function with this prototype is passed to
<FUNCTION>cyg_interrupt_create()</FUNCTION> when an interrupt
object is created. When the ISR requests the scheduling of its
DSR, this function will be called at some later point. In
addition to the <parameter>vector</parameter> and
<parameter>data</parameter> arguments, which will be the same as
those passed to the ISR, this routine is also passed a
<parameter>count</parameter> of the number of times the ISR has
requested that this DSR be scheduled. This counter is zeroed
each time the DSR actually runs, so it indicates how many
interrupts have occurred since it last ran.</PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECTION>
<!-- }}} -->
</SECTION>
<!-- }}} -->
</CHAPTER>
<!-- }}} -->
</PART>
|