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
|
/***************************************************************************/
/* Copyright (c) 2024 Microsoft Corporation */
/* Copyright (c) 2026 Eclipse ThreadX contributors */
/* */
/* This program and the accompanying materials are made available under */
/* the terms of the MIT License which is available at */
/* https://opensource.org/licenses/MIT. */
/* */
/* SPDX-License-Identifier: MIT */
/***************************************************************************/
/* This test is designed to test the simple dpump host/device class operation. */
#include <stdio.h>
#include "tx_api.h"
#include "ux_api.h"
#include "ux_system.h"
#include "ux_utility.h"
#include "ux_hcd_sim_host.h"
#include "fx_api.h"
#include "ux_device_class_cdc_acm.h"
#include "ux_device_stack.h"
#include "ux_host_class_cdc_acm.h"
#include "ux_test_dcd_sim_slave.h"
#include "ux_test_hcd_sim_host.h"
#include "ux_test_utility_sim.h"
#define UX_DEMO_REQUEST_MAX_LENGTH \
((UX_HCD_SIM_HOST_MAX_PAYLOAD) > (UX_SLAVE_REQUEST_DATA_MAX_LENGTH) ? \
(UX_HCD_SIM_HOST_MAX_PAYLOAD) : (UX_SLAVE_REQUEST_DATA_MAX_LENGTH))
/* Define constants. */
#define UX_CDC_ACM_CONNECTION_DELAY ((UX_RH_ENUMERATION_RETRY + 1)*UX_HOST_CLASS_CDC_ACM_DEVICE_INIT_DELAY)
#define UX_DEMO_DEBUG_SIZE (4096*8)
#define UX_DEMO_STACK_SIZE 1024
#define UX_DEMO_BUFFER_SIZE (UX_DEMO_REQUEST_MAX_LENGTH + 1)
#define UX_DEMO_XMIT_BUFFER_SIZE 512
#define UX_DEMO_RECEPTION_BUFFER_SIZE 512
#define UX_DEMO_FILE_BUFFER_SIZE 512
#define UX_DEMO_RECEPTION_BLOCK_SIZE 64
#define UX_DEMO_MEMORY_SIZE (128*1024)
#define UX_DEMO_FILE_SIZE (128 * 1024)
#define UX_RAM_DISK_MEMORY (256 * 1024)
/* Define local/extern function prototypes. */
static void test_thread_entry(ULONG);
static TX_THREAD tx_test_thread_host_simulation;
static TX_THREAD tx_test_thread_slave_simulation;
static void tx_test_thread_host_simulation_entry(ULONG);
static void tx_test_thread_slave_simulation_entry(ULONG);
static void test_thread_host_reception_callback(UX_HOST_CLASS_CDC_ACM *cdc_acm, UINT status, UCHAR *reception_buffer, ULONG reception_size);
static VOID demo_cdc_instance_activate(VOID *cdc_instance);
static VOID demo_cdc_instance_deactivate(VOID *cdc_instance);
static VOID demo_cdc_instance_parameter_change(VOID *cdc_instance);
static UINT test_usbx_simulator_cdc_acm_host_send_command(UCHAR *string, ULONG length, ULONG no_ack);
static UINT tx_test_thread_slave_simulation_response(UCHAR *string, ULONG length);
static UINT ux_test_host_class_cdc_acm_command(UX_HOST_CLASS_CDC_ACM *cdc_acm, ULONG command, ULONG value, UCHAR *data_buffer, ULONG data_length, ULONG *actual_length);
static VOID ux_test_host_class_cdc_acm_device_status_change_callback(struct UX_HOST_CLASS_CDC_ACM_STRUCT *cdc_acm,
ULONG notification_type, ULONG notification_value);
static VOID ux_test_hcd_entry_set_cfg(UX_TEST_ACTION *action, VOID *params);
static VOID ux_test_hcd_entry_interaction_request_sem_put(UX_TEST_ACTION *action, VOID *params);
static VOID ux_test_hcd_entry_interaction_invoked(UX_TEST_ACTION *action, VOID *params);
static VOID ux_test_hcd_entry_interaction_wait_transfer_disconnection(UX_TEST_ACTION *action, VOID *params);
#define test_usbx_simulator_cdc_acm_host_send_at_command(s,l) test_usbx_simulator_cdc_acm_host_send_command(s,l,UX_FALSE)
#define test_usbx_simulator_cdc_acm_host_send_string(s,l) test_usbx_simulator_cdc_acm_host_send_command(s,l,UX_TRUE)
/* Define global data structures. */
static UCHAR usbx_memory[UX_DEMO_MEMORY_SIZE + (UX_DEMO_STACK_SIZE * 2)];
static UX_HOST_CLASS *class_driver;
static UX_HOST_CLASS_CDC_ACM *cdc_acm_host_control;
static UX_HOST_CLASS_CDC_ACM *cdc_acm_host_data;
static ULONG notification_count;
static ULONG command_received_count;
static UCHAR cdc_acm_reception_buffer[UX_DEMO_RECEPTION_BUFFER_SIZE];
static UCHAR cdc_acm_xmit_buffer[UX_DEMO_XMIT_BUFFER_SIZE];
static UX_HOST_CLASS_CDC_ACM_RECEPTION cdc_acm_reception;
static UCHAR *global_reception_buffer;
static ULONG global_reception_size;
static UCHAR cdc_acm_reception_overflow = UX_FALSE;
static UX_SLAVE_CLASS_CDC_ACM *cdc_acm_slave;
static UCHAR cdc_acm_slave_change;
static UX_SLAVE_CLASS_CDC_ACM_PARAMETER parameter;
static UCHAR buffer[UX_DEMO_BUFFER_SIZE * 4]; /* Large enough to avoid memory access exception. */
static UCHAR cdc_acm_slave_bulk_read_write = UX_TRUE;
static ULONG error_counter;
static ULONG set_cfg_counter;
static ULONG rsc_mem_free_on_set_cfg;
static ULONG rsc_sem_on_set_cfg;
static ULONG rsc_sem_get_on_set_cfg;
static ULONG rsc_mutex_on_set_cfg;
static ULONG rsc_enum_sem_usage;
static ULONG rsc_enum_sem_get_count;
static ULONG rsc_enum_mutex_usage;
static ULONG rsc_enum_mem_usage;
static ULONG rsc_cdc_sem_usage;
static ULONG rsc_cdc_sem_get_count;
static ULONG rsc_cdc_mutex_usage;
static ULONG rsc_cdc_mem_usage;
static ULONG interaction_count;
static UCHAR error_callback_ignore = UX_TRUE;
static ULONG error_callback_counter;
static UCHAR _rsp_ok[UX_DEMO_BUFFER_SIZE] = {'O', 'K', '\r', '\n', '\0'};
/* Define device framework. */
#define DEVICE_FRAMEWORK_LENGTH_FULL_SPEED (93 + 7)
#define DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED (103 + 7)
#define STRING_FRAMEWORK_LENGTH 47
#define LANGUAGE_ID_FRAMEWORK_LENGTH 2
static unsigned char device_framework_full_speed[] = {
/* Device descriptor 18 bytes
0x02 bDeviceClass: CDC class code
0x00 bDeviceSubclass: CDC class sub code
0x00 bDeviceProtocol: CDC Device protocol
idVendor & idProduct - http://www.linux-usb.org/usb.ids
*/
0x12, 0x01, 0x10, 0x01,
0xEF, 0x02, 0x01,
0x08,
0x84, 0x84, 0x00, 0x00,
0x00, 0x01,
0x01, 0x02, 03,
0x01,
/* Configuration 1 descriptor 9 bytes */
0x09, 0x02, 0x52, 0x00,
0x02, 0x01, 0x00,
0x40, 0x00,
/* Interface association descriptor. 8 bytes. */
0x08, 0x0b, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00,
/* Communication Class Interface Descriptor Requirement. 9 bytes. */
0x09, 0x04, 0x00,
0x00,
0x02,
0x02, 0x02, 0x01,
0x00,
/* Header Functional Descriptor 5 bytes */
0x05, 0x24, 0x00,
0x10, 0x01,
/* ACM Functional Descriptor 4 bytes */
0x04, 0x24, 0x02,
0x0f,
/* Union Functional Descriptor 5 bytes */
0x05, 0x24, 0x06,
0x00, /* Master interface */
0x01, /* Slave interface */
/* Call Management Functional Descriptor 5 bytes */
0x05, 0x24, 0x01,
0x03,
0x01, /* Data interface */
/* Endpoint 0x04 descriptor 7 bytes */
0x07, 0x05, 0x04,
0x03,
0x08, 0x00,
15,
/* Endpoint 0x83 descriptor 7 bytes */
0x07, 0x05, 0x83,
0x03,
0x08, 0x00,
0xFF,
/* Data Class Interface Descriptor Requirement 9 bytes */
0x09, 0x04, 0x01,
0x00,
0x02,
0x0A, 0x00, 0x00,
0x00,
/* Endpoint 0x02 descriptor 7 bytes */
0x07, 0x05, 0x02, /* @ 93 - 14 + 2 = 81 */
0x02,
0x40, 0x00,
0x00,
/* Endpoint 0x81 descriptor 7 bytes */
0x07, 0x05, 0x81, /* @ 93 - 7 + 2 = 88 */
0x02,
0x40, 0x00,
0x00,
};
#define DEVICE_FRAMEWORK_EPA_POS_1_FS (DEVICE_FRAMEWORK_LENGTH_FULL_SPEED - 14 + 2)
#define DEVICE_FRAMEWORK_EPA_POS_2_FS (DEVICE_FRAMEWORK_LENGTH_FULL_SPEED - 7 + 2)
static unsigned char device_framework_high_speed[] = {
/* Device descriptor
0x02 bDeviceClass: CDC class code
0x00 bDeviceSubclass: CDC class sub code
0x00 bDeviceProtocol: CDC Device protocol
idVendor & idProduct - http://www.linux-usb.org/usb.ids
*/
0x12, 0x01, 0x00, 0x02,
0xEF, 0x02, 0x01,
0x40,
0x84, 0x84, 0x00, 0x00,
0x00, 0x01,
0x01, 0x02, 03,
0x01,
/* Device qualifier descriptor */
0x0a, 0x06, 0x00, 0x02,
0x02, 0x00, 0x00,
0x40,
0x01,
0x00,
/* Configuration 1 descriptor */
0x09, 0x02, 0x52, 0x00,
0x02, 0x01, 0x00,
0x40, 0x00,
/* Interface association descriptor. */
0x08, 0x0b, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00,
/* Communication Class Interface Descriptor Requirement */
0x09, 0x04, 0x00,
0x00,
0x02,
0x02, 0x02, 0x01,
0x00,
/* Header Functional Descriptor */
0x05, 0x24, 0x00,
0x10, 0x01,
/* ACM Functional Descriptor */
0x04, 0x24, 0x02,
0x0f,
/* Union Functional Descriptor */
0x05, 0x24, 0x06,
0x00,
0x01,
/* Call Management Functional Descriptor */
0x05, 0x24, 0x01,
0x00,
0x01,
/* Endpoint 0x04 descriptor */
0x07, 0x05, 0x04,
0x03,
0x08, 0x00,
10,
/* Endpoint 0x83 descriptor */
0x07, 0x05, 0x83,
0x03,
0x08, 0x00,
10,
/* Data Class Interface Descriptor Requirement */
0x09, 0x04, 0x01,
0x00,
0x02,
0x0A, 0x00, 0x00,
0x00,
/* Endpoint 0x02 descriptor */
0x07, 0x05, 0x02, /* @ 103 - 14 + 2 = 91 */
0x02,
0x40, 0x00,
0x00,
/* Endpoint 0x81 descriptor */
0x07, 0x05, 0x81, /* @ 103 - 7 + 2 = 98 */
0x02,
0x40, 0x00,
0x00,
};
#define DEVICE_FRAMEWORK_EPA_POS_1_HS (DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED - 14 + 2)
#define DEVICE_FRAMEWORK_EPA_POS_2_HS (DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED - 7 + 2)
static unsigned char string_framework[] = {
/* Manufacturer string descriptor : Index 1 - "Express Logic" */
0x09, 0x04, 0x01, 0x0c,
0x45, 0x78, 0x70, 0x72,0x65, 0x73, 0x20, 0x4c,
0x6f, 0x67, 0x69, 0x63,
/* Product string descriptor : Index 2 - "EL Composite device" */
0x09, 0x04, 0x02, 0x13,
0x45, 0x4c, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x6f,
0x73, 0x69, 0x74, 0x65, 0x20, 0x64, 0x65, 0x76,
0x69, 0x63, 0x65,
/* Serial Number string descriptor : Index 3 - "0001" */
0x09, 0x04, 0x03, 0x04,
0x30, 0x30, 0x30, 0x31
};
/* Multiple languages are supported on the device, to add
a language besides english, the unicode language code must
be appended to the language_id_framework array and the length
adjusted accordingly. */
static unsigned char language_id_framework[] = {
/* English. */
0x09, 0x04
};
#define DEVICE_FRAMEWORK1_LENGTH (18 +9 +8 +9+5+4+5+5+ 9+7+7) /* =86 */
#define DEVICE_FRAMEWORK1_CFG_TOTAL_LEN_POS (18+2)
#define DEVICE_FRAMEWORK1_IFC1_N_EPS_POS (86-7-7-9+4)
#define DEVICE_FRAMEWORK1_IFC1_EPA1_POS (86-7-7+2)
#define DEVICE_FRAMEWORK1_IFC1_EPA2_POS (86-7+2)
static unsigned char device_framework_no_interrupt_ep[] = {
/* Device descriptor 18 bytes
0x02 bDeviceClass: CDC class code
0x00 bDeviceSubclass: CDC class sub code
0x00 bDeviceProtocol: CDC Device protocol
idVendor & idProduct - http://www.linux-usb.org/usb.ids
*/
0x12, 0x01, 0x10, 0x01,
0xEF, 0x02, 0x01,
0x08,
0x84, 0x84, 0x00, 0x00,
0x00, 0x01,
0x01, 0x02, 0x03,
0x01,
/* Configuration 1 descriptor 9 bytes */
0x09, 0x02, 0x44, 0x00, /* wTotalLength @ 21 */
0x02, 0x01, 0x00,
0x40, 0x00,
/* Interface association descriptor. 8 bytes. */
0x08, 0x0b, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00,
/* Communication Class Interface Descriptor Requirement. 9 bytes. */
0x09, 0x04, 0x00,
0x00,
0x00,
0x02, 0x02, 0x01,
0x00,
/* Header Functional Descriptor 5 bytes */
0x05, 0x24, 0x00,
0x10, 0x01,
/* ACM Functional Descriptor 4 bytes */
0x04, 0x24, 0x02,
0x0f,
/* Union Functional Descriptor 5 bytes */
0x05, 0x24, 0x06,
0x00, /* Master interface */
0x01, /* Slave interface */
/* Call Management Functional Descriptor 5 bytes */
0x05, 0x24, 0x01,
0x03,
0x01, /* Data interface */
/* Data Class Interface Descriptor Requirement 9 bytes */
0x09, 0x04, 0x01,
0x00,
0x02, /* bNumEndpoints @ 86 - 14 - 9 + 4 = 67 */
0x0A, 0x00, 0x00,
0x00,
/* Endpoint 0x81 descriptor 7 bytes */
0x07, 0x05, 0x81, /* @ 86 - 14 + 2 = 73 */
0x02,
0x40, 0x00,
0x00,
/* Endpoint 0x02 descriptor 7 bytes */
0x07, 0x05, 0x02, /* @ 86 - 7 + 2 = 81 */
0x02,
0x40, 0x00,
0x00,
};
static unsigned char replaced_cfg_descriptor[] =
{
/* Configuration 1 descriptor 9 bytes */
0x09, 0x02, 0x52, 0x00,
0x02, 0x01, 0x00,
0x40, 0x00,
/* Interface association descriptor. 8 bytes. */
0x08, 0x0b, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00,
/* Communication Class Interface Descriptor Requirement. 9 bytes. */
0x09, 0x04, 0x00,
0x00,
0x02,
0x02, 0x02, 0x01,
0x00,
/* Header Functional Descriptor 5 bytes */
0x05, 0x24, 0x00,
0x10, 0x01,
/* ACM Functional Descriptor 4 bytes */
0x04, 0x24, 0x02,
0x0f,
/* Union Functional Descriptor 5 bytes */
0x05, 0x24, 0x06,
0x00, /* Master interface */
0x01, /* Slave interface */
/* Call Management Functional Descriptor 5 bytes */
0x05, 0x24, 0x01,
0x03,
0x01, /* Data interface */
/* Endpoint 0x04 descriptor 7 bytes */
0x07, 0x05, 0x04,
0x03,
0x08, 0x00,
10,
/* Endpoint 0x83 descriptor 7 bytes */
0x07, 0x05, 0x83,
0x03,
0x08, 0x00,
10,
/* Data Class Interface Descriptor Requirement 9 bytes */
0x09, 0x04, 0x01,
0x00,
0x02,
0x0A, 0x00, 0x00,
0x00,
/* Endpoint 0x02 descriptor 7 bytes */
0x07, 0x05, 0x02, /* @ 93 - 14 + 2 = 81 */
0x02,
0x40, 0x00,
0x00,
/* Endpoint 0x81 descriptor 7 bytes */
0x07, 0x05, 0x81, /* @ 93 - 7 + 2 = 88 */
0x02,
0x40, 0x00,
0x00,
};
static unsigned char replaced_cfg_descriptor_no_bulk[] =
{
/* Configuration 1 descriptor */
0x09, 0x02, 0x52 - 7, 0x00,
0x02, 0x01, 0x00,
0x40, 0x00,
/* Interface association descriptor. */
0x08, 0x0b, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00,
/* Communication Class Interface Descriptor Requirement */
0x09, 0x04, 0x00,
0x00,
0x02,
0x02, 0x02, 0x01,
0x00,
/* Header Functional Descriptor */
0x05, 0x24, 0x00,
0x10, 0x01,
/* ACM Functional Descriptor */
0x04, 0x24, 0x02,
0x0f,
/* Union Functional Descriptor */
0x05, 0x24, 0x06,
0x00,
0x01,
/* Call Management Functional Descriptor */
0x05, 0x24, 0x01,
0x00,
0x01,
/* Endpoint 0x04 descriptor */
0x07, 0x05, 0x04,
0x03,
0x08, 0x00,
10,
/* Endpoint 0x83 descriptor */
0x07, 0x05, 0x83,
0x03,
0x08, 0x00,
10,
/* Data Class Interface Descriptor Requirement */
0x09, 0x04, 0x01,
0x00,
0x01,
0x0A, 0x00, 0x00,
0x00,
/* Endpoint 0x02 descriptor */
0x07, 0x05, 0x02, /* @ - 7 + 2 */
0x02,
0x40, 0x00,
0x00,
};
/* Setup requests */
static UX_TEST_SETUP _SetConfigure = UX_TEST_SETUP_SetConfigure;
static UX_TEST_SETUP _GetCfgDescr = UX_TEST_SETUP_GetCfgDescr;
static UX_TEST_SETUP _SetAddress = UX_TEST_SETUP_SetAddress;
static UX_TEST_SETUP _GetDeviceDescriptor = UX_TEST_SETUP_GetDevDescr;
static UX_TEST_SETUP _GetConfigDescriptor = UX_TEST_SETUP_GetCfgDescr;
/* Interaction define */
static UX_TEST_HCD_SIM_ACTION check_ignore_next_transfer_request[] = {
/* function, request to match,
port action, port status,
request action, request EP, request data, request actual length, request status,
status, additional callback,
no_return */
{ UX_HCD_TRANSFER_REQUEST, UX_NULL,
UX_FALSE, 0,
0, 0, UX_NULL, 0, 0,
UX_SUCCESS, ux_test_hcd_entry_interaction_invoked},
{ 0 }
};
static UX_TEST_HCD_SIM_ACTION log_on_SetCfg[] = {
/* function, request to match,
port action, port status,
request action, request EP, request data, request actual length, request status,
status, additional callback,
no_return */
{ UX_HCD_TRANSFER_REQUEST, &_SetConfigure,
UX_FALSE, UX_TEST_PORT_STATUS_DISC,
UX_TEST_SETUP_MATCH_REQ, 0, UX_NULL, 0, 0,
UX_SUCCESS, ux_test_hcd_entry_set_cfg,
UX_TRUE}, /* Invoke callback & continue */
{ 0 }
};
static UX_TEST_HCD_SIM_ACTION wait_disconn_on_transfer_0[] = {
/* function, request to match,
port action, port status,
request action, request EP, request data, request actual length, request status,
status, additional callback,
no_return */
{ UX_HCD_TRANSFER_REQUEST, UX_NULL,
UX_FALSE, 0,
0, 0, UX_NULL, 0, 0,
UX_ERROR, ux_test_hcd_entry_interaction_wait_transfer_disconnection},
{ 0 }
};
static UX_TEST_HCD_SIM_ACTION error_on_transfer_0[] = {
/* function, request to match,
port action, port status,
request action, request EP, request data, request actual length, request status,
status, additional callback,
no_return */
{ UX_HCD_TRANSFER_REQUEST, UX_NULL,
UX_FALSE, 0,
UX_TEST_SIM_REQ_ANSWER, 0, UX_NULL, 0, UX_ERROR,
UX_ERROR},
{ 0 }
};
static UX_TEST_HCD_SIM_ACTION error_on_transfer_1[] = {
/* function, request to match,
port action, port status,
request action, request EP, request data, request actual length, request status,
status, additional callback,
no_return */
{ UX_HCD_TRANSFER_REQUEST, UX_NULL,
UX_FALSE, 0,
UX_TEST_SIM_REQ_ANSWER, 0, UX_NULL, ~0, 0,
UX_SUCCESS, ux_test_hcd_entry_interaction_invoked}, /* All requested */
{ UX_HCD_TRANSFER_REQUEST, UX_NULL,
UX_FALSE, 0,
UX_TEST_SIM_REQ_ANSWER, 0, UX_NULL, 0, UX_ERROR,
UX_ERROR, ux_test_hcd_entry_interaction_invoked}, /* Error */
{ 0 }
};
static UX_TEST_HCD_SIM_ACTION good_on_transfer_1[] = {
/* function, request to match,
port action, port status,
request action, request EP, request data, request actual length, request status,
status, additional callback,
no_return */
{ UX_HCD_TRANSFER_REQUEST, UX_NULL,
UX_FALSE, 0,
UX_TEST_SIM_REQ_ANSWER, 0, UX_NULL, ~0, 0, /* Return all required */
UX_SUCCESS, ux_test_hcd_entry_interaction_invoked}, /* All requested */
{ UX_HCD_TRANSFER_REQUEST, UX_NULL,
UX_FALSE, 0,
UX_TEST_SIM_REQ_ANSWER, 0, UX_NULL, 0, 0, /* Return ZLP */
UX_SUCCESS, ux_test_hcd_entry_interaction_invoked}, /* No Error */
{ 0 }
};
static UX_TEST_HCD_SIM_ACTION good_on_transfer_0_ZLP[] = {
/* function, request to match,
port action, port status,
request action, request EP, request data, request actual length, request status,
status, additional callback,
no_return */
{ UX_HCD_TRANSFER_REQUEST, UX_NULL,
UX_FALSE, 0,
UX_TEST_SIM_REQ_ANSWER, 0, UX_NULL, 0, 0, /* Return ZLP */
UX_SUCCESS, ux_test_hcd_entry_interaction_request_sem_put}, /* No Error */
{ 0 }
};
static UX_TEST_HCD_SIM_ACTION error_on_transfer_interruptEP[] = {
/* function, request to match,
port action, port status,
request action, request EP, request data, request actual length, request status,
status, additional callback,
no_return */
{ UX_HCD_TRANSFER_REQUEST, UX_NULL,
UX_FALSE, 0,
UX_TEST_MATCH_EP, 0x83, UX_NULL, 0, 0,
UX_ERROR, ux_test_hcd_entry_interaction_invoked}, /* Error */
{ 0 }
};
static UX_TEST_HCD_SIM_ACTION replaced_GetCfgDescr[] = {
/* function, request to match,
port action, port status,
request action, request EP, request data, request actual length, request status,
status, additional callback,
no_return */
{ UX_HCD_TRANSFER_REQUEST, &_GetCfgDescr,
UX_FALSE, 0,
UX_TEST_SETUP_MATCH_REQ | UX_TEST_SIM_REQ_ANSWER, 0, replaced_cfg_descriptor, 9, 0,
UX_SUCCESS, ux_test_hcd_entry_interaction_invoked}, /* Invoke callback & answer */
{ UX_HCD_TRANSFER_REQUEST, &_GetCfgDescr,
UX_FALSE, 0,
UX_TEST_SETUP_MATCH_REQ | UX_TEST_SIM_REQ_ANSWER, 0, replaced_cfg_descriptor, sizeof(replaced_cfg_descriptor), 0,
UX_SUCCESS, ux_test_hcd_entry_interaction_invoked}, /* Invoke callback & answer */
{ 0 }
};
static UX_TEST_HCD_SIM_ACTION enum_replace_no_bulk[] = {
/* function, request to match,
port action, port status,
request action, request EP, request data, request actual length, request status,
status, additional callback,
no_return */
{ UX_HCD_TRANSFER_REQUEST, &_GetDeviceDescriptor,
UX_FALSE, 0,
UX_TEST_SIM_REQ_ANSWER | UX_TEST_SETUP_MATCH_REQ_V, 0, device_framework_full_speed + 0, 8, 0,
UX_SUCCESS, ux_test_hcd_entry_interaction_invoked},
{ UX_HCD_TRANSFER_REQUEST, &_GetDeviceDescriptor,
UX_FALSE, 0,
UX_TEST_SIM_REQ_ANSWER | UX_TEST_SETUP_MATCH_REQ_V, 0, device_framework_full_speed + 0, 18, 0,
UX_SUCCESS, ux_test_hcd_entry_interaction_invoked},
/* Note: Each enumeration does two GetConfigurations (the second one is in _ux_host_class_cdc_acm_capabilities_get.c) */
/* 1st. */
{ UX_HCD_TRANSFER_REQUEST, &_GetConfigDescriptor,
UX_FALSE, 0,
UX_TEST_SIM_REQ_ANSWER | UX_TEST_SETUP_MATCH_REQ_V, 0, replaced_cfg_descriptor_no_bulk, UX_CONFIGURATION_DESCRIPTOR_LENGTH, 0,
UX_SUCCESS, ux_test_hcd_entry_interaction_invoked},
{ UX_HCD_TRANSFER_REQUEST, &_GetConfigDescriptor,
UX_FALSE, 0,
UX_TEST_SIM_REQ_ANSWER | UX_TEST_SETUP_MATCH_REQ_V, 0, replaced_cfg_descriptor_no_bulk, sizeof(replaced_cfg_descriptor_no_bulk), 0,
UX_SUCCESS, ux_test_hcd_entry_interaction_invoked},
{ UX_HCD_TRANSFER_REQUEST, &_GetConfigDescriptor,
UX_FALSE, 0,
UX_TEST_SIM_REQ_ANSWER | UX_TEST_SETUP_MATCH_REQ_V, 0, replaced_cfg_descriptor_no_bulk, UX_CONFIGURATION_DESCRIPTOR_LENGTH, 0,
UX_SUCCESS, ux_test_hcd_entry_interaction_invoked},
{ UX_HCD_TRANSFER_REQUEST, &_GetConfigDescriptor,
UX_FALSE, 0,
UX_TEST_SIM_REQ_ANSWER | UX_TEST_SETUP_MATCH_REQ_V, 0, replaced_cfg_descriptor_no_bulk, sizeof(replaced_cfg_descriptor_no_bulk), 0,
UX_SUCCESS, ux_test_hcd_entry_interaction_invoked},
/* 2nd. */
{ UX_HCD_TRANSFER_REQUEST, &_GetConfigDescriptor,
UX_FALSE, 0,
UX_TEST_SIM_REQ_ANSWER | UX_TEST_SETUP_MATCH_REQ_V, 0, replaced_cfg_descriptor_no_bulk, UX_CONFIGURATION_DESCRIPTOR_LENGTH, 0,
UX_SUCCESS, ux_test_hcd_entry_interaction_invoked},
{ UX_HCD_TRANSFER_REQUEST, &_GetConfigDescriptor,
UX_FALSE, 0,
UX_TEST_SIM_REQ_ANSWER | UX_TEST_SETUP_MATCH_REQ_V, 0, replaced_cfg_descriptor_no_bulk, sizeof(replaced_cfg_descriptor_no_bulk), 0,
UX_SUCCESS, ux_test_hcd_entry_interaction_invoked},
{ UX_HCD_TRANSFER_REQUEST, &_GetConfigDescriptor,
UX_FALSE, 0,
UX_TEST_SIM_REQ_ANSWER | UX_TEST_SETUP_MATCH_REQ_V, 0, replaced_cfg_descriptor_no_bulk, UX_CONFIGURATION_DESCRIPTOR_LENGTH, 0,
UX_SUCCESS, ux_test_hcd_entry_interaction_invoked},
{ UX_HCD_TRANSFER_REQUEST, &_GetConfigDescriptor,
UX_FALSE, 0,
UX_TEST_SIM_REQ_ANSWER | UX_TEST_SETUP_MATCH_REQ_V, 0, replaced_cfg_descriptor_no_bulk, sizeof(replaced_cfg_descriptor_no_bulk), 0,
UX_SUCCESS, ux_test_hcd_entry_interaction_invoked},
/* 3rd. */
{ UX_HCD_TRANSFER_REQUEST, &_GetConfigDescriptor,
UX_FALSE, 0,
UX_TEST_SIM_REQ_ANSWER | UX_TEST_SETUP_MATCH_REQ_V, 0, replaced_cfg_descriptor_no_bulk, UX_CONFIGURATION_DESCRIPTOR_LENGTH, 0,
UX_SUCCESS, ux_test_hcd_entry_interaction_invoked},
{ UX_HCD_TRANSFER_REQUEST, &_GetConfigDescriptor,
UX_FALSE, 0,
UX_TEST_SIM_REQ_ANSWER | UX_TEST_SETUP_MATCH_REQ_V, 0, replaced_cfg_descriptor_no_bulk, sizeof(replaced_cfg_descriptor_no_bulk), 0,
UX_SUCCESS, ux_test_hcd_entry_interaction_invoked},
{ UX_HCD_TRANSFER_REQUEST, &_GetConfigDescriptor,
UX_FALSE, 0,
UX_TEST_SIM_REQ_ANSWER | UX_TEST_SETUP_MATCH_REQ_V, 0, replaced_cfg_descriptor_no_bulk, UX_CONFIGURATION_DESCRIPTOR_LENGTH, 0,
UX_SUCCESS, ux_test_hcd_entry_interaction_invoked},
{ UX_HCD_TRANSFER_REQUEST, &_GetConfigDescriptor,
UX_FALSE, 0,
UX_TEST_SIM_REQ_ANSWER | UX_TEST_SETUP_MATCH_REQ_V, 0, replaced_cfg_descriptor_no_bulk, sizeof(replaced_cfg_descriptor_no_bulk), 0,
UX_SUCCESS, ux_test_hcd_entry_interaction_invoked},
{ 0 }
};
/* Define the ISR dispatch. */
extern VOID (*test_isr_dispatch)(void);
/* Prototype for test control return. */
void test_control_return(UINT status);
static VOID error_callback(UINT system_level, UINT system_context, UINT error_code)
{
error_callback_counter ++;
if (!error_callback_ignore)
{
{
/* Failed test. */
printf("Error #%d, system_level: %d, system_context: %d, error_code: 0x%x\n", __LINE__, system_level, system_context, error_code);
test_control_return(1);
}
}
}
static UINT sleep_break_on_error(VOID)
{
if (error_callback_counter >= 3)
return error_callback_counter;
return UX_SUCCESS;
}
/* Define the ISR dispatch routine. */
static void test_isr(void)
{
/* For further expansion of interrupt-level testing. */
}
static UINT demo_class_cdc_acm_get(void)
{
UINT status;
UX_HOST_CLASS *class;
UX_HOST_CLASS_CDC_ACM *cdc_acm_host;
/* Find the main cdc_acm container */
status = ux_host_stack_class_get(_ux_system_host_class_cdc_acm_name, &class);
if (status != UX_SUCCESS)
return(status);
/* We get the first instance of the cdc_acm device */
do
{
status = ux_host_stack_class_instance_get(class, 0, (void **) &cdc_acm_host);
tx_thread_sleep(10);
} while (status != UX_SUCCESS);
/* We still need to wait for the cdc_acm status to be live */
while (cdc_acm_host -> ux_host_class_cdc_acm_state != UX_HOST_CLASS_INSTANCE_LIVE)
tx_thread_sleep(10);
/* Isolate both the control and data interfaces. */
if (cdc_acm_host -> ux_host_class_cdc_acm_interface -> ux_interface_descriptor.bInterfaceClass == UX_HOST_CLASS_CDC_DATA_CLASS)
{
/* This is the data interface. */
cdc_acm_host_data = cdc_acm_host;
/* In that case, the second one should be the control interface. */
status = ux_host_stack_class_instance_get(class, 1, (void **) &cdc_acm_host);
/* Check error. */
if (status != UX_SUCCESS)
return(status);
/* Check for the control interfaces. */
if (cdc_acm_host -> ux_host_class_cdc_acm_interface -> ux_interface_descriptor.bInterfaceClass == UX_HOST_CLASS_CDC_CONTROL_CLASS)
{
/* This is the control interface. */
cdc_acm_host_control = cdc_acm_host;
return(UX_SUCCESS);
}
}
else
{
/* Check for the control interfaces. */
if (cdc_acm_host -> ux_host_class_cdc_acm_interface -> ux_interface_descriptor.bInterfaceClass == UX_HOST_CLASS_CDC_CONTROL_CLASS)
{
/* This is the control interface. */
cdc_acm_host_control = cdc_acm_host;
/* In that case, the second one should be the data interface. */
status = ux_host_stack_class_instance_get(class, 1, (void **) &cdc_acm_host);
/* Check error. */
if (status != UX_SUCCESS)
return(status);
/* Check for the data interface. */
if (cdc_acm_host -> ux_host_class_cdc_acm_interface -> ux_interface_descriptor.bInterfaceClass == UX_HOST_CLASS_CDC_DATA_CLASS)
{
/* This is the data interface. */
cdc_acm_host_data = cdc_acm_host;
return(UX_SUCCESS);
}
}
}
/* Return ERROR. */
return(UX_ERROR);
}
static UINT demo_system_host_change_function(ULONG event, UX_HOST_CLASS *cls, VOID *inst)
{
UX_HOST_CLASS_CDC_ACM *cdc_acm = (UX_HOST_CLASS_CDC_ACM *) inst;
switch(event)
{
case UX_DEVICE_INSERTION:
if (cdc_acm -> ux_host_class_cdc_acm_interface -> ux_interface_descriptor.bInterfaceClass == UX_HOST_CLASS_CDC_CONTROL_CLASS)
cdc_acm_host_control = cdc_acm;
else
cdc_acm_host_data = cdc_acm;
break;
case UX_DEVICE_REMOVAL:
if (cdc_acm -> ux_host_class_cdc_acm_interface -> ux_interface_descriptor.bInterfaceClass == UX_HOST_CLASS_CDC_CONTROL_CLASS)
cdc_acm_host_control = UX_NULL;
else
cdc_acm_host_data = UX_NULL;
break;
default:
break;
}
return 0;
}
static VOID demo_cdc_instance_activate(VOID *cdc_instance)
{
/* Save the CDC instance. */
cdc_acm_slave = (UX_SLAVE_CLASS_CDC_ACM *) cdc_instance;
}
static VOID demo_cdc_instance_deactivate(VOID *cdc_instance)
{
/* Reset the CDC instance. */
cdc_acm_slave = UX_NULL;
}
static VOID demo_cdc_instance_parameter_change(VOID *cdc_instance)
{
/* Set CDC parameter change flag. */
cdc_acm_slave_change = UX_TRUE;
}
static VOID test_swap_framework_bulk_ep_descriptors(VOID)
{
UCHAR tmp;
tmp = device_framework_full_speed[DEVICE_FRAMEWORK_EPA_POS_1_FS];
device_framework_full_speed[DEVICE_FRAMEWORK_EPA_POS_1_FS] = device_framework_full_speed[DEVICE_FRAMEWORK_EPA_POS_2_FS];
device_framework_full_speed[DEVICE_FRAMEWORK_EPA_POS_2_FS] = tmp;
tmp = device_framework_high_speed[DEVICE_FRAMEWORK_EPA_POS_1_HS];
device_framework_high_speed[DEVICE_FRAMEWORK_EPA_POS_1_HS] = device_framework_high_speed[DEVICE_FRAMEWORK_EPA_POS_2_HS];
device_framework_high_speed[DEVICE_FRAMEWORK_EPA_POS_2_HS] = tmp;
}
static VOID test_slave_cdc_acm_transfer_disconnect(UX_SLAVE_CLASS_CDC_ACM *cdc_acm, ULONG ep_dir)
{
UX_SLAVE_ENDPOINT *endpoint;
UX_SLAVE_DEVICE *device;
UX_SLAVE_INTERFACE *interface;
UX_SLAVE_TRANSFER *transfer_request;
/* Get the pointer to the device. */
device = &_ux_system_slave -> ux_system_slave_device;
/* This is the first time we are activated. We need the interface to the class. */
interface = cdc_acm -> ux_slave_class_cdc_acm_interface;
/* Locate the endpoints. */
endpoint = interface -> ux_slave_interface_first_endpoint;
/* Check the endpoint direction, if OUT we have the correct endpoint. */
if ((endpoint -> ux_slave_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) != ep_dir)
{
/* So the next endpoint has to be the OUT endpoint. */
endpoint = endpoint -> ux_slave_endpoint_next_endpoint;
}
/* All CDC reading are on the endpoint OUT, from the host. */
transfer_request = &endpoint -> ux_slave_endpoint_transfer_request;
/* Continue transfer. */
transfer_request -> ux_slave_transfer_request_actual_length = endpoint -> ux_slave_endpoint_descriptor.wMaxPacketSize;
/* Change device state. */
device -> ux_slave_device_state = UX_DEVICE_ATTACHED;
/* Inform hcd. */
_ux_utility_semaphore_put(&transfer_request -> ux_slave_transfer_request_semaphore);
/* Wait a while for transfer request handling. */
tx_thread_sleep(50);
/* Change device state. */
device -> ux_slave_device_state = UX_DEVICE_CONFIGURED;
}
static VOID ux_test_hcd_entry_interaction_wait_transfer_disconnection(UX_TEST_ACTION *action, VOID *_params)
{
UX_TEST_OVERRIDE_UX_HCD_SIM_HOST_ENTRY_PARAMS *params = _params;
UX_TRANSFER *transfer_request = (UX_TRANSFER *)params->parameter;
UX_ENDPOINT *endpoint;
UX_DEVICE *device;
endpoint = transfer_request -> ux_transfer_request_endpoint;
device = endpoint -> ux_endpoint_device;
while(device -> ux_device_state > UX_DEVICE_RESET)
tx_thread_sleep(10);
}
static VOID ux_test_hcd_entry_interaction_invoked(UX_TEST_ACTION *action, VOID *params)
{
interaction_count ++;
}
static VOID ux_test_hcd_entry_interaction_request_sem_put(UX_TEST_ACTION *action, VOID *params)
{
interaction_count ++;
}
static VOID ux_test_hcd_entry_set_cfg(UX_TEST_ACTION *action, VOID *params)
{
set_cfg_counter ++;
rsc_mem_free_on_set_cfg = _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_available;
rsc_sem_on_set_cfg = ux_test_utility_sim_sem_create_count();
rsc_mutex_on_set_cfg = ux_test_utility_sim_mutex_create_count();
}
/* Define what the initial system looks like. */
#ifdef CTEST
void test_application_define(void *first_unused_memory)
#else
void usbx_cdc_acm_basic_test_application_define(void *first_unused_memory)
#endif
{
UINT status;
CHAR * stack_pointer;
CHAR * memory_pointer;
ULONG test_n;
/* Inform user. */
printf("Running CDC ACM Basic Functionality Test............................ ");
/* Reset testing counts. */
ux_test_utility_sim_mutex_create_count_reset();
ux_test_utility_sim_sem_create_count_reset();
ux_test_utility_sim_sem_get_count_reset();
/* Reset error generations */
ux_test_utility_sim_sem_error_generation_stop();
ux_test_utility_sim_mutex_error_generation_stop();
ux_test_utility_sim_sem_get_error_generation_stop();
/* Initialize the free memory pointer */
stack_pointer = (CHAR *) usbx_memory;
memory_pointer = stack_pointer + (UX_DEMO_STACK_SIZE * 2);
/* Initialize USBX Memory */
status = ux_system_initialize(memory_pointer, UX_DEMO_MEMORY_SIZE, UX_NULL,0);
/* Check for error. */
if (status != UX_SUCCESS)
{
printf("ERROR #1\n");
test_control_return(1);
}
/* Register the error callback. */
_ux_utility_error_callback_register(error_callback);
/* The code below is required for installing the host portion of USBX */
status = ux_host_stack_initialize(demo_system_host_change_function);
if (status != UX_SUCCESS)
{
printf("ERROR #2\n");
test_control_return(1);
}
/* Register CDC-ACM class. */
status = ux_host_stack_class_register(_ux_system_host_class_cdc_acm_name, ux_host_class_cdc_acm_entry);
if (status != UX_SUCCESS)
{
printf("ERROR #3\n");
test_control_return(1);
}
/* The code below is required for installing the device portion of USBX. No call back for
device status change in this example. */
status = ux_device_stack_initialize(device_framework_high_speed, DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED,
device_framework_full_speed, DEVICE_FRAMEWORK_LENGTH_FULL_SPEED,
string_framework, STRING_FRAMEWORK_LENGTH,
language_id_framework, LANGUAGE_ID_FRAMEWORK_LENGTH,UX_NULL);
if(status!=UX_SUCCESS)
{
printf("ERROR #5\n");
test_control_return(1);
}
/* Set the parameters for callback when insertion/extraction of a CDC device. */
parameter.ux_slave_class_cdc_acm_instance_activate = demo_cdc_instance_activate;
parameter.ux_slave_class_cdc_acm_instance_deactivate = demo_cdc_instance_deactivate;
parameter.ux_slave_class_cdc_acm_parameter_change = demo_cdc_instance_parameter_change;
/* Mutex will be created on initialize to protect CDC Bulk IN/OUT */
for (test_n = 0; test_n < 2; test_n ++)
{
ux_test_utility_sim_mutex_error_generation_start(test_n);
status = ux_device_stack_class_register(_ux_system_slave_class_cdc_acm_name, ux_device_class_cdc_acm_entry,
1,0, ¶meter);
/* Mutex error should be reported */
if(status != UX_MUTEX_ERROR)
{
printf("ERROR #46.%ld\n", test_n);
test_control_return(1);
}
}
ux_test_utility_sim_mutex_error_generation_stop();
/* Initialize the device cdc class. This class owns both interfaces starting with 0. */
status = ux_device_stack_class_register(_ux_system_slave_class_cdc_acm_name, ux_device_class_cdc_acm_entry,
1,0, ¶meter);
if(status!=UX_SUCCESS)
{
printf("ERROR #6\n");
test_control_return(1);
}
/* Initialize the simulated device controller. */
status = _ux_dcd_sim_slave_initialize();
/* Check for error. */
if (status != TX_SUCCESS)
{
printf("ERROR #7\n");
test_control_return(1);
}
/* Register all the USB host controllers available in this system */
status = ux_host_stack_hcd_register(_ux_system_host_hcd_simulator_name, _ux_test_hcd_sim_host_initialize,0,0);
if (status != UX_SUCCESS)
{
printf("ERROR #4\n");
test_control_return(1);
}
/* Create the main host simulation thread. */
status = tx_thread_create(&tx_test_thread_host_simulation, "tx demo host simulation", tx_test_thread_host_simulation_entry, 0,
stack_pointer, UX_DEMO_STACK_SIZE,
20, 20, 1, TX_AUTO_START);
/* Check for error. */
if (status != TX_SUCCESS)
{
printf("ERROR #8\n");
test_control_return(1);
}
/* Create the main slave simulation thread. */
status = tx_thread_create(&tx_test_thread_slave_simulation, "tx demo slave simulation", tx_test_thread_slave_simulation_entry, 0,
stack_pointer + UX_DEMO_STACK_SIZE, UX_DEMO_STACK_SIZE,
20, 20, 1, TX_AUTO_START);
/* Check for error. */
if (status != TX_SUCCESS)
{
printf("ERROR #9\n");
test_control_return(1);
}
}
void tx_test_thread_host_simulation_entry(ULONG arg)
{
UINT status;
UX_HOST_CLASS_CDC_ACM_LINE_CODING line_coding_host;
UX_HOST_CLASS_CDC_ACM_LINE_STATE line_state_host;
ULONG actual_length;
UCHAR at_cmd[16];
UX_SLAVE_CLASS_CDC_ACM * cdc_acm_slave_bak;
UX_HOST_CLASS_CDC_ACM * cdc_acm_host_ctrl_bak;
UX_HOST_CLASS_CDC_ACM * cdc_acm_host_data_bak;
ULONG test_n;
UX_HOST_CLASS_COMMAND command;
UX_HOST_CLASS_COMMAND command1;
ULONG mem_free;
USHORT break_ms;
stepinfo("\n");
/* Find the cdc_acm class and wait for the link to be up. */
status = demo_class_cdc_acm_get();
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #10\n");
test_control_return(1);
}
/* Reception parameter */
cdc_acm_reception.ux_host_class_cdc_acm_reception_block_size = UX_DEMO_RECEPTION_BLOCK_SIZE;
cdc_acm_reception.ux_host_class_cdc_acm_reception_data_buffer = cdc_acm_reception_buffer;
cdc_acm_reception.ux_host_class_cdc_acm_reception_data_buffer_size = UX_DEMO_RECEPTION_BUFFER_SIZE;
cdc_acm_reception.ux_host_class_cdc_acm_reception_callback = test_thread_host_reception_callback;
/* Save slave instance for later tests. */
cdc_acm_slave_bak = cdc_acm_slave;
/* Save host instances for later tests. */
cdc_acm_host_ctrl_bak = cdc_acm_host_control;
cdc_acm_host_data_bak = cdc_acm_host_data;
/* Test disconnect. */
ux_test_dcd_sim_slave_disconnect();
ux_test_hcd_sim_host_disconnect();
/* Test reception on instance inactive */
stepinfo(">>>>>>>>>>>> Start reception when interface is inactive\n");
status = ux_host_class_cdc_acm_reception_start(cdc_acm_host_data_bak, &cdc_acm_reception);
if (status == UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #86: error must be reported when invoking reception while interface is not ready\n");
test_control_return(1);
}
/* Test stop reception on inactive interface */
stepinfo(">>>>>>>>>>>> Stop reception when interface is inactive\n");
status = ux_host_class_cdc_acm_reception_stop(cdc_acm_host_data_bak, &cdc_acm_reception);
if (status == UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #91: error not reported when stop reception on inactive interface\n");
test_control_return(1);
}
/* Reset testing counts. */
ux_test_utility_sim_mutex_create_count_reset();
ux_test_utility_sim_sem_create_count_reset();
ux_test_hcd_sim_host_set_actions(log_on_SetCfg);
/* Save free memory usage. */
mem_free = _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_available;
ux_test_dcd_sim_slave_connect(UX_FULL_SPEED_DEVICE);
ux_test_hcd_sim_host_connect(UX_FULL_SPEED_DEVICE);
tx_thread_sleep(100);
/* Log create counts for further tests. */
rsc_enum_mutex_usage = rsc_mutex_on_set_cfg;
rsc_enum_sem_usage = rsc_sem_on_set_cfg;
rsc_enum_mem_usage = mem_free - rsc_mem_free_on_set_cfg;
/* Log create counts when instances active for further tests. */
rsc_cdc_mutex_usage = ux_test_utility_sim_mutex_create_count() - rsc_enum_mutex_usage;
rsc_cdc_sem_usage = ux_test_utility_sim_sem_create_count() - rsc_enum_sem_usage;
rsc_cdc_mem_usage = rsc_mem_free_on_set_cfg - _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_available;
stepinfo("mem free: %ld\n", _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_available);
/* Start the reception on control interface. */
stepinfo(">>>>>>>>>>>> Start reception on control interface\n");
status = ux_host_class_cdc_acm_reception_start(cdc_acm_host_control, &cdc_acm_reception);
if (status == UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #87: error must be reported when invoking reception on control interface\n");
test_control_return(1);
}
/* Start and stop immediately. */
stepinfo(">>>>>>>>>>>> Start reception and stop it immediately\n");
status = ux_host_class_cdc_acm_reception_start(cdc_acm_host_data, &cdc_acm_reception);
status |= ux_host_class_cdc_acm_reception_stop(cdc_acm_host_data, &cdc_acm_reception);
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #%d: code 0x%x\n", __LINE__, status);
test_control_return(1);
}
/* Transfer error. */
stepinfo(">>>>>>>>>>>> Start reception request error\n");
ux_test_hcd_sim_host_set_actions(error_on_transfer_0);
status = ux_host_class_cdc_acm_reception_start(cdc_acm_host_data, &cdc_acm_reception);
if (status == UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #88: error must be reported when transfer request error\n");
test_control_return(1);
}
/* Start the reception for test. */
status = ux_host_class_cdc_acm_reception_start(cdc_acm_host_data, &cdc_acm_reception);
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #89: Start reception fail\n");
test_control_return(1);
}
/* Test stop reception on wrong interface */
status = ux_host_class_cdc_acm_reception_stop(cdc_acm_host_control, &cdc_acm_reception);
if (status == UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #90: error not reported when stop reception on wrong interface\n");
test_control_return(1);
}
/* Stop reception for test */
status = ux_host_class_cdc_acm_reception_stop(cdc_acm_host_data, &cdc_acm_reception);
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #92: stop reception failed\n");
test_control_return(1);
}
/* Start the reception for cdc_acm. */
status = ux_host_class_cdc_acm_reception_start(cdc_acm_host_data, &cdc_acm_reception);
/* Get the current data rate. */
stepinfo(">>>>>>>>>>>> ATB: get baud\n");
status = test_usbx_simulator_cdc_acm_host_send_at_command("ATB",3);
/* The device may be extracted after we start sending\receiving. */
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #11\n");
test_control_return(1);
}
/* Get the current stop bit rate. */
stepinfo(">>>>>>>>>>>> ATS: get stop bits\n");
status = test_usbx_simulator_cdc_acm_host_send_at_command("ATS",3);
/* The device may be extracted after we start sending\receiving. */
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #12\n");
test_control_return(1);
}
/* Get the current parity rate. */
stepinfo(">>>>>>>>>>>> ATP: get parity\n");
status = test_usbx_simulator_cdc_acm_host_send_at_command("ATP",3);
/* The device may be extracted after we start sending\receiving. */
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #13\n");
test_control_return(1);
}
/* Get the current data bit rate. */
stepinfo(">>>>>>>>>>>> ATD: data bits\n");
status = test_usbx_simulator_cdc_acm_host_send_at_command("ATD",3);
/* The device may be extracted after we start sending\receiving. */
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #14\n");
test_control_return(1);
}
/* Get the current RTS state. */
stepinfo(">>>>>>>>>>>> ATR: RTS\n");
status = test_usbx_simulator_cdc_acm_host_send_at_command("ATR",3);
/* The device may be extracted after we start sending\receiving. */
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #15\n");
test_control_return(1);
}
/* Get the current DTR rate. */
stepinfo(">>>>>>>>>>>> ATT: DTR\n");
status = test_usbx_simulator_cdc_acm_host_send_at_command("ATT",3);
/* The device may be extracted after we start sending\receiving. */
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #16\n");
test_control_return(1);
}
/* Stop after receive. */
stepinfo(">>>>>>>>>>>> Start reception and stop it immediately\n");
status |= ux_host_class_cdc_acm_reception_stop(cdc_acm_host_data, &cdc_acm_reception);
status = ux_host_class_cdc_acm_reception_start(cdc_acm_host_data, &cdc_acm_reception);
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #%d: code 0x%x\n", __LINE__, status);
test_control_return(1);
}
/* Read 64 bytes and next device side expect 64 byte */
stepinfo(">>>>>>>>>>>> ATOP: 64/64\n");
status = test_usbx_simulator_cdc_acm_host_send_at_command("ATOP", 4);
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #%d\n", __LINE__);
test_control_return(1);
}
/* Set the line coding. */
stepinfo(">>>>>>>>>>>> ATL: Set LineCoding\n");
at_cmd[0] = 'A';
at_cmd[1] = 'T';
at_cmd[2] = 'L';
at_cmd[3] = 0x00;
at_cmd[4] = 0xC2;
at_cmd[5] = 0x01;
at_cmd[6] = 0x00; /* 115200: 0x0001C200 */
at_cmd[7] = UX_SLAVE_CLASS_CDC_ACM_LINE_CODING_STOP_BIT;
at_cmd[8] = UX_SLAVE_CLASS_CDC_ACM_LINE_CODING_PARITY;
at_cmd[9] = 7;
status = test_usbx_simulator_cdc_acm_host_send_at_command(at_cmd,62);
/* The device may be extracted after we start sending\receiving. */
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #33\n");
test_control_return(1);
}
/* Change the line coding values. */
stepinfo(">>>>>>>>>>>> IOCTRL: SetLineCoding\n");
line_coding_host.ux_host_class_cdc_acm_line_coding_dter = 9600;
line_coding_host.ux_host_class_cdc_acm_line_coding_stop_bit = UX_HOST_CLASS_CDC_ACM_LINE_CODING_STOP_BIT_15;
line_coding_host.ux_host_class_cdc_acm_line_coding_parity = UX_HOST_CLASS_CDC_ACM_LINE_CODING_PARITY_EVEN;
line_coding_host.ux_host_class_cdc_acm_line_coding_data_bits = 5;
status = _ux_host_class_cdc_acm_ioctl(cdc_acm_host_control, UX_HOST_CLASS_CDC_ACM_IOCTL_SET_LINE_CODING,
&line_coding_host);
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #17\n");
test_control_return(1);
}
/* Slave should invoke parameter change callback */
if (cdc_acm_slave_change != UX_TRUE)
{
/* CDC ACM basic test error. */
printf("ERROR #25\n");
test_control_return(1);
}
/* Reset slave change flag */
cdc_acm_slave_change = UX_FALSE;
/* Change the line state values. */
stepinfo(">>>>>>>>>>>> IOCTRL: SetLineState\n");
line_state_host.ux_host_class_cdc_acm_line_state_rts = 0;
line_state_host.ux_host_class_cdc_acm_line_state_dtr = 0;
status = _ux_host_class_cdc_acm_ioctl(cdc_acm_host_control, UX_HOST_CLASS_CDC_ACM_IOCTL_SET_LINE_STATE,
&line_state_host);
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #18\n");
test_control_return(1);
}
/* Slave should invoke parameter change callback */
if (cdc_acm_slave_change != UX_TRUE)
{
/* CDC ACM basic test error. */
printf("ERROR #26\n");
test_control_return(1);
}
/* Reset slave change flag */
cdc_acm_slave_change = UX_FALSE;
/* Reobtain the cdc acm line values. */
/* Get the current data rate. */
stepinfo(">>>>>>>>>>>> ATB: baud rate\n");
status = test_usbx_simulator_cdc_acm_host_send_at_command("ATB",3);
/* The device may be extracted after we start sending\receiving. */
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #19\n");
test_control_return(1);
}
/* Get the current stop bit rate. */
stepinfo(">>>>>>>>>>>> ATS: stop bits\n");
status = test_usbx_simulator_cdc_acm_host_send_at_command("ATS",3);
/* The device may be extracted after we start sending\receiving. */
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #20\n");
test_control_return(1);
}
/* Get the current parity rate. */
stepinfo(">>>>>>>>>>>> ATP: parity\n");
status = test_usbx_simulator_cdc_acm_host_send_at_command("ATP",3);
/* The device may be extracted after we start sending\receiving. */
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #21\n");
test_control_return(1);
}
/* Get the current data bit rate. */
stepinfo(">>>>>>>>>>>> ATD: data bits\n");
status = test_usbx_simulator_cdc_acm_host_send_at_command("ATD",3);
/* The device may be extracted after we start sending\receiving. */
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #22\n");
test_control_return(1);
}
/* Get the current RTS state. */
stepinfo(">>>>>>>>>>>> ATR: RTS\n");
status = test_usbx_simulator_cdc_acm_host_send_at_command("ATR",3);
/* The device may be extracted after we start sending\receiving. */
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #23\n");
test_control_return(1);
}
/* Test enumeration different descriptors */
/* Initialize to disconnect */
ux_test_dcd_sim_slave_disconnect();
ux_test_hcd_sim_host_disconnect();
/* Test enumeration no interrupt EP */
stepinfo(">>>>>>>>>>>> Enumerate device wihtout interrupt EP\n");
_ux_system_slave->ux_system_slave_device_framework_full_speed = device_framework_no_interrupt_ep;
_ux_system_slave->ux_system_slave_device_framework_length_full_speed = sizeof(device_framework_no_interrupt_ep);
ux_test_dcd_sim_slave_connect(UX_FULL_SPEED_DEVICE);
ux_test_hcd_sim_host_connect(UX_FULL_SPEED_DEVICE);
ux_utility_delay_ms(UX_CDC_ACM_CONNECTION_DELAY);
/* Instances should be ready */
if (!cdc_acm_slave || !cdc_acm_host_control || !cdc_acm_host_data)
{
printf("ERROR #57: instance should ready after reconnect without interrupt EP\n");
test_control_return(1);
}
ux_test_dcd_sim_slave_disconnect();
ux_test_hcd_sim_host_disconnect();
/* Instances should be removed */
if (cdc_acm_slave || cdc_acm_host_control || cdc_acm_host_data)
{
printf("ERROR #60: instance should removed after disconnect without interrupt EP\n");
test_control_return(1);
}
stepinfo(">>>>>>>>>>>> Enumerate device wihtout one of bulk EP\n");
/* Pause bulk read/write since there is no bulk EP. */
cdc_acm_slave_bulk_read_write = UX_FALSE;
/* Test enumeration no bulk EP */
ux_test_hcd_sim_host_set_actions(enum_replace_no_bulk);
ux_test_dcd_sim_slave_connect(UX_FULL_SPEED_DEVICE);
ux_test_hcd_sim_host_connect(UX_FULL_SPEED_DEVICE);
ux_utility_delay_ms(UX_CDC_ACM_CONNECTION_DELAY);
/* Data instances should not be ready */
if (cdc_acm_host_data)
{
printf("ERROR #58: instance should NOT ready after reconnect without one of bulk EP\n");
test_control_return(1);
}
UX_TEST_ASSERT(ux_test_check_actions_empty());
ux_test_dcd_sim_slave_disconnect();
ux_test_hcd_sim_host_disconnect();
if (cdc_acm_slave || cdc_acm_host_control)
{
printf("ERROR #61: instance should be removed after disconnect without one of bulk EP\n");
test_control_return(1);
}
replaced_cfg_descriptor_no_bulk[sizeof(replaced_cfg_descriptor_no_bulk) - 7 + 2] ^= 0x80;
ux_test_hcd_sim_host_set_actions(enum_replace_no_bulk);
ux_test_dcd_sim_slave_connect(UX_FULL_SPEED_DEVICE);
ux_test_hcd_sim_host_connect(UX_FULL_SPEED_DEVICE);
ux_utility_delay_ms(UX_CDC_ACM_CONNECTION_DELAY);
/* Data instances should not be ready */
if (cdc_acm_host_data)
{
printf("ERROR #59: instance should NOT ready after reconnect without one of bulk EP\n");
test_control_return(1);
}
/* Restore frameworks */
ux_test_dcd_sim_slave_disconnect();
ux_test_hcd_sim_host_disconnect();
_ux_system_slave->ux_system_slave_device_framework_full_speed = device_framework_full_speed;
_ux_system_slave->ux_system_slave_device_framework_length_full_speed = DEVICE_FRAMEWORK_LENGTH_FULL_SPEED;
ux_test_hcd_sim_host_set_actions(UX_NULL);
cdc_acm_slave_bulk_read_write = UX_TRUE;
/* Swap EP address for different EP sequence. */
stepinfo(">>>>>>>>>>>> Enumerate device swap bulk EP addresses\n");
ux_test_dcd_sim_slave_disconnect();
ux_test_hcd_sim_host_disconnect();
test_swap_framework_bulk_ep_descriptors();
ux_test_dcd_sim_slave_connect(UX_FULL_SPEED_DEVICE);
ux_test_hcd_sim_host_connect(UX_FULL_SPEED_DEVICE);
ux_utility_delay_ms(UX_CDC_ACM_CONNECTION_DELAY);
/* Instances should be ready */
if (!cdc_acm_slave || !cdc_acm_host_control || !cdc_acm_host_data)
{
printf("ERROR #53: instance not ready after reconnect (%p,%p,%p)\n", cdc_acm_slave, cdc_acm_host_control, cdc_acm_host_data);
test_control_return(1);
}
if (cdc_acm_host_control->ux_host_class_cdc_acm_interrupt_endpoint)
{
stepinfo(">>>>>>>>>>>> Notification reception test\n");
/* Set notification callback */
status = _ux_host_class_cdc_acm_ioctl(cdc_acm_host_control, UX_HOST_CLASS_CDC_ACM_IOCTL_NOTIFICATION_CALLBACK,
(VOID*)ux_test_host_class_cdc_acm_device_status_change_callback);
if (status != UX_SUCCESS)
{
printf("ERROR #55: notification callback set fail\n");
test_control_return(1);
}
interaction_count = 0;
ux_test_hcd_sim_host_set_actions(check_ignore_next_transfer_request);
/* Simulate notification! */
cdc_acm_host_control->ux_host_class_cdc_acm_interrupt_endpoint->ux_endpoint_transfer_request.ux_transfer_request_completion_code = UX_SUCCESS;
_ux_host_class_cdc_acm_transfer_request_completed(&cdc_acm_host_control->ux_host_class_cdc_acm_interrupt_endpoint->ux_endpoint_transfer_request);
/* There should be call of transfer to re-start notification monitoring */
if (interaction_count == 0)
{
printf("ERROR #56: notification monitoring not reactivated\n");
test_control_return(1);
}
}
/* Start the reception for cdc_acm. */
status = ux_host_class_cdc_acm_reception_start(cdc_acm_host_data, &cdc_acm_reception);
if (status != UX_SUCCESS)
{
printf("ERROR #54: reception start error\n");
test_control_return(1);
}
/* Get the current DTR rate. */
stepinfo(">>>>>>>>>>>> ATT: get DTR\n");
status = test_usbx_simulator_cdc_acm_host_send_at_command("ATT",3);
/* The device may be extracted after we start sending\receiving. */
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #24\n");
test_control_return(1);
}
/* Try invalid command on IOCTL. */
stepinfo(">>>>>>>>>>>> ATF: invalid device IOCTRL command\n");
status = test_usbx_simulator_cdc_acm_host_send_at_command("ATF",3);
/* The device may be extracted after we start sending\receiving. */
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #36\n");
test_control_return(1);
}
/* Try slave ABORT command on IOCTL. */
stepinfo(">>>>>>>>>>>> ATA: slave IOCTRL ABORT test\n");
status = test_usbx_simulator_cdc_acm_host_send_at_command("ATA",3);
/* The device may be extracted after we start sending\receiving. */
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #37\n");
test_control_return(1);
}
/* Start reception again if it's aborted */
ux_host_class_cdc_acm_reception_start(cdc_acm_host_data, &cdc_acm_reception);
/* Read until there is no data from slave */
do
{
status = command_received_count;
tx_thread_sleep(20);
} while(status != command_received_count);
/* Try overflow */
stepinfo(">>>>>>>>>>>> Reception overflow test\n");
cdc_acm_reception_overflow = UX_TRUE;
/* Start writing long buffer in device side */
test_usbx_simulator_cdc_acm_host_send_string("ATO\0", 4);
/* Waiting overflow detection */
status = 50;
while(cdc_acm_reception_overflow && status --)
{
tx_thread_sleep(20);
}
if (cdc_acm_reception_overflow)
{
printf("ERROR #93: Reception overflow not detected\n");
cdc_acm_reception_overflow = UX_FALSE;
test_control_return(1);
}
/* Continue reception */
ux_host_class_cdc_acm_reception_start(cdc_acm_host_data, &cdc_acm_reception);
/* GetLineCoding with larger buffer size
response should be OK with correct bytes */
stepinfo(">>>>>>>>>>>> GetLineCoding with larger buffer than line coding data\n");
status = ux_test_host_class_cdc_acm_command(cdc_acm_host_control, UX_HOST_CLASS_CDC_ACM_REQ_GET_LINE_CODING,
0, cdc_acm_reception_buffer, UX_HOST_CLASS_CDC_ACM_LINE_CODING_LENGTH + 1,
&actual_length);
/* The device may be extracted after we start sending\receiving. */
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #27\n");
test_control_return(1);
}
/* Returned number of bytes should be correct */
if (actual_length != UX_HOST_CLASS_CDC_ACM_LINE_CODING_LENGTH)
{
/* CDC ACM basic test error. */
printf("ERROR #28\n");
test_control_return(1);
}
/* Host command test */
/* Undefined command */
stepinfo(">>>>>>>>>>>> Invalid command\n");
status = _ux_host_class_cdc_acm_command(cdc_acm_host_control, UX_HOST_CLASS_CDC_ACM_REQ_GET_LINE_CODING + 7,
0, cdc_acm_reception_buffer, UX_HOST_CLASS_CDC_ACM_LINE_CODING_LENGTH + 1);
/* The device may be extracted after we start sending\receiving. */
if (status == UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #29\n");
test_control_return(1);
}
/* Semaphore protection error test */
stepinfo(">>>>>>>>>>>> Semaphore get error on command\n");
ux_test_utility_sim_sem_get_error_generation_start(0);
status = _ux_host_class_cdc_acm_command(cdc_acm_host_control, UX_HOST_CLASS_CDC_ACM_REQ_GET_LINE_CODING,
0, cdc_acm_reception_buffer, UX_HOST_CLASS_CDC_ACM_LINE_CODING_LENGTH);
if (status == UX_SUCCESS)
{
printf("ERROR #64: no error reported on control semaphore error\n");
test_control_return(1);
}
ux_test_utility_sim_sem_get_error_generation_stop();
/* Host entry test */
/* Invalid command */
stepinfo(">>>>>>>>>>>> Host Entry - Invalid command\n");
command.ux_host_class_command_request = 0xFF;
status = ux_host_class_cdc_acm_entry(&command);
if (status == UX_SUCCESS)
{
printf("ERROR #62: no error report on invalid command entry\n");
test_control_return(1);
}
stepinfo(">>>>>>>>>>>> Host Entry - Query\n");
/* Query test - wrong class */
command.ux_host_class_command_request = UX_HOST_CLASS_COMMAND_QUERY;
command.ux_host_class_command_usage = UX_HOST_CLASS_COMMAND_USAGE_CSP;
command.ux_host_class_command_class = 0xFF;
status = ux_host_class_cdc_acm_entry(&command);
if (status == UX_SUCCESS)
{
printf("ERROR #63: no error report when Query class wrong\n");
test_control_return(1);
}
/* Query test - CTRL & DLC */
command.ux_host_class_command_request = UX_HOST_CLASS_COMMAND_QUERY;
command.ux_host_class_command_usage = UX_HOST_CLASS_COMMAND_USAGE_CSP;
command.ux_host_class_command_class = UX_HOST_CLASS_CDC_CONTROL_CLASS;
command.ux_host_class_command_subclass = UX_HOST_CLASS_CDC_DLC_SUBCLASS;
command.ux_host_class_command_iad_class = 0;
command.ux_host_class_command_iad_subclass = 0;
status = ux_host_class_cdc_acm_entry(&command);
if (status != UX_SUCCESS)
{
printf("ERROR #64: error report when Query class OK\n");
test_control_return(1);
}
/* Query test - wrong IAD */
command.ux_host_class_command_request = UX_HOST_CLASS_COMMAND_QUERY;
command.ux_host_class_command_usage = UX_HOST_CLASS_COMMAND_USAGE_CSP;
command.ux_host_class_command_class = UX_HOST_CLASS_CDC_CONTROL_CLASS;
command.ux_host_class_command_subclass = UX_HOST_CLASS_CDC_DLC_SUBCLASS;
command.ux_host_class_command_iad_class = 0xFE;
status = ux_host_class_cdc_acm_entry(&command);
if (status == UX_SUCCESS)
{
printf("ERROR #65: no error report when Query class IAD wrong");
test_control_return(1);
}
/* Host class deactivate & activate */
stepinfo(">>>>>>>>>>>> Host CDC deactivate & activate\n");
command.ux_host_class_command_container = cdc_acm_host_control->ux_host_class_cdc_acm_interface;
command.ux_host_class_command_class_ptr = cdc_acm_host_control->ux_host_class_cdc_acm_class;
command.ux_host_class_command_instance = cdc_acm_host_control;
command.ux_host_class_command_request = UX_HOST_CLASS_COMMAND_DEACTIVATE;
command1.ux_host_class_command_container = cdc_acm_host_data->ux_host_class_cdc_acm_interface;
command1.ux_host_class_command_class_ptr = cdc_acm_host_data->ux_host_class_cdc_acm_class;
command1.ux_host_class_command_instance = cdc_acm_host_data;
command1.ux_host_class_command_request = UX_HOST_CLASS_COMMAND_DEACTIVATE;
ux_host_class_cdc_acm_entry(&command);
/* Instance should be removed */
if (cdc_acm_host_control)
{
printf("ERROR #67: control instance not deactivate\n");
test_control_return(1);
}
ux_host_class_cdc_acm_entry(&command1);
/* Instance should be removed */
if (cdc_acm_host_data)
{
printf("ERROR #67: control instance not deactivate\n");
test_control_return(1);
}
command.ux_host_class_command_request = UX_HOST_CLASS_COMMAND_ACTIVATE;
ux_host_class_cdc_acm_entry(&command);
/* Instance should be back */
if (!cdc_acm_host_control)
{
printf("ERROR #68: control instance not activate\n");
test_control_return(1);
}
command1.ux_host_class_command_request = UX_HOST_CLASS_COMMAND_ACTIVATE;
ux_host_class_cdc_acm_entry(&command1);
/* Instance should be back */
if (!cdc_acm_host_data)
{
printf("ERROR #68: control instance not activate\n");
test_control_return(1);
}
/* Start the reception for cdc_acm. */
status = ux_host_class_cdc_acm_reception_start(cdc_acm_host_data, &cdc_acm_reception);
if (status != UX_SUCCESS)
{
printf("ERROR #70: reception start error\n");
test_control_return(1);
}
/* Get the current stop bit rate. */
stepinfo(">>>>>>>>>>>> ATS: stop bits\n");
status = test_usbx_simulator_cdc_acm_host_send_at_command("ATS",3);
/* The device may be extracted after we start sending\receiving. */
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #69\n");
test_control_return(1);
}
/* Sim: slave lost configure while reading pending. */
stepinfo(">>>>>>>>>>>> Slave lost connection while reading\n");
ux_utility_memory_set(cdc_acm_xmit_buffer, 0x00, 3);
status = ux_host_class_cdc_acm_write(cdc_acm_host_data, cdc_acm_xmit_buffer, 128, &actual_length);
/* Simulate disconnect after first packet sent */
test_slave_cdc_acm_transfer_disconnect(cdc_acm_slave_bak, UX_ENDPOINT_OUT);
status = ux_host_class_cdc_acm_write(cdc_acm_host_data, cdc_acm_xmit_buffer, 64, &actual_length);
ux_test_dcd_sim_slave_connect(UX_FULL_SPEED_DEVICE);
tx_thread_sleep(50);
/* Sim: slave lost configure while writing pending. */
stepinfo(">>>>>>>>>>>> Slave lost connection while writing\n");
status = test_usbx_simulator_cdc_acm_host_send_string("\0",1);
status = test_usbx_simulator_cdc_acm_host_send_string("ATW",3);
/* The device may be extracted after we start sending\receiving. */
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #42\n");
test_control_return(1);
}
tx_thread_sleep(20);
test_slave_cdc_acm_transfer_disconnect(cdc_acm_slave_bak, UX_ENDPOINT_IN);
/* Now disconnect the device. */
ux_test_dcd_sim_slave_disconnect();
/* Read/write through disconnected slave should return error */
stepinfo(">>>>>>>>>>>> R/W on deactivated slave interface instance\n");
/* Try read, error must be returned */
status = ux_device_class_cdc_acm_read(cdc_acm_slave_bak, buffer, UX_DEMO_BUFFER_SIZE, &actual_length);
if (status == UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #40\n");
test_control_return(1);
}
/* Try write, error must be returned */
status = ux_device_class_cdc_acm_write(cdc_acm_slave_bak, buffer, UX_DEMO_BUFFER_SIZE, &actual_length);
if (status == UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #41\n");
test_control_return(1);
}
stepinfo(">>>>>>>>>>>> R/W on invalid interface instance\n");
/* Try host read on control interface, error must be returned. */
status = ux_host_class_cdc_acm_read(cdc_acm_host_control, buffer, 64, &actual_length);
if (status != UX_HOST_CLASS_INSTANCE_UNKNOWN)
{
/* CDC ACM basic test error. */
printf("ERROR #47\n");
test_control_return(1);
}
/* Try host write, error must be returned. */
status = ux_host_class_cdc_acm_write(cdc_acm_host_control, buffer, 64, &actual_length);
if (status != UX_HOST_CLASS_INSTANCE_UNKNOWN)
{
/* CDC ACM basic test error. */
printf("ERROR #48\n");
test_control_return(1);
}
stepinfo(">>>>>>>>>>>> R/W on deactivated host interface instance\n");
ux_test_hcd_sim_host_disconnect();
tx_thread_sleep(50);
/* Try host read on disconnected interface, error must be returned. */
status = ux_host_class_cdc_acm_read(cdc_acm_host_data_bak, buffer, 64, &actual_length);
if (status != UX_HOST_CLASS_INSTANCE_UNKNOWN)
{
/* CDC ACM basic test error. */
printf("ERROR #49\n");
test_control_return(1);
}
/* Try host write, error must be returned. */
status = ux_host_class_cdc_acm_write(cdc_acm_host_data_bak, buffer, 64, &actual_length);
if (status != UX_HOST_CLASS_INSTANCE_UNKNOWN)
{
/* CDC ACM basic test error. */
printf("ERROR #43\n");
test_control_return(1);
}
stepinfo(">>>>>>>>>>>> IOCTRL on deactivated host interface instance\n");
status = ux_host_class_cdc_acm_ioctl(cdc_acm_host_data_bak, 0, UX_NULL);
if (status == UX_SUCCESS)
{
printf("ERROR #73: IOCTRL on deactivated interface should report error\n");
test_control_return(1);
}
ux_test_dcd_sim_slave_connect(UX_HIGH_SPEED_DEVICE);
ux_test_hcd_sim_host_connect(UX_HIGH_SPEED_DEVICE);
while(!cdc_acm_host_control || !cdc_acm_host_data)
tx_thread_sleep(10);
/* Host IOCTRL tests */
/* Try invalid IOCTRL command */
stepinfo(">>>>>>>>>>>> IOCTRL invalid command\n");
status = ux_host_class_cdc_acm_ioctl(cdc_acm_host_control, 0xFF, UX_NULL);
if (status != UX_FUNCTION_NOT_SUPPORTED)
{
printf("ERROR #74: IOCTRL with invalid command should report UX_FUNCTION_NOT_SUPPORTED\n");
test_control_return(1);
}
/* Try IOCTRL UX_HOST_CLASS_CDC_ACM_IOCTL_GET_DEVICE_STATUS */
stepinfo(">>>>>>>>>>>> IOCTRL UX_HOST_CLASS_CDC_ACM_IOCTL_GET_DEVICE_STATUS\n");
status = ux_host_class_cdc_acm_ioctl(cdc_acm_host_control, UX_HOST_CLASS_CDC_ACM_IOCTL_GET_DEVICE_STATUS, &test_n);
if (status != UX_SUCCESS)
{
printf("ERROR #75: IOCTRL UX_HOST_CLASS_CDC_ACM_IOCTL_GET_DEVICE_STATUS should be OK\n");
test_control_return(1);
}
/* Try IOCTRL UX_HOST_CLASS_CDC_ACM_IOCTL_ABORT_OUT_PIPE */
stepinfo(">>>>>>>>>>>> IOCTRL UX_HOST_CLASS_CDC_ACM_IOCTL_ABORT_OUT_PIPE\n");
status = ux_host_class_cdc_acm_ioctl(cdc_acm_host_data, UX_HOST_CLASS_CDC_ACM_IOCTL_ABORT_OUT_PIPE, UX_NULL);
if (status != UX_SUCCESS)
{
printf("ERROR #76: IOCTRL UX_HOST_CLASS_CDC_ACM_IOCTL_ABORT_OUT_PIPE should be OK\n");
test_control_return(1);
}
/* Try IOCTRL UX_HOST_CLASS_CDC_ACM_IOCTL_ABORT_IN_PIPE */
stepinfo(">>>>>>>>>>>> IOCTRL UX_HOST_CLASS_CDC_ACM_IOCTL_ABORT_IN_PIPE\n");
status = ux_host_class_cdc_acm_ioctl(cdc_acm_host_data, UX_HOST_CLASS_CDC_ACM_IOCTL_ABORT_IN_PIPE, UX_NULL);
if (status != UX_SUCCESS)
{
printf("ERROR #77: IOCTRL UX_HOST_CLASS_CDC_ACM_IOCTL_ABORT_IN_PIPE should be OK\n");
test_control_return(1);
}
/* Try IOCTRL UX_HOST_CLASS_CDC_ACM_IOCTL_SEND_BREAK */
stepinfo(">>>>>>>>>>>> IOCTRL UX_HOST_CLASS_CDC_ACM_IOCTL_SEND_BREAK\n");
break_ms = 0xFFFF;
status = ux_host_class_cdc_acm_ioctl(cdc_acm_host_control, UX_HOST_CLASS_CDC_ACM_IOCTL_SEND_BREAK, &break_ms);
if ((status != UX_SUCCESS) || (cdc_acm_slave -> ux_slave_class_cdc_acm_break_duration != break_ms))
{
printf("ERROR #78: IOCTRL UX_HOST_CLASS_CDC_ACM_IOCTL_SEND_BREAK should fail\n");
test_control_return(1);
}
break_ms = 1000;
status = ux_host_class_cdc_acm_ioctl(cdc_acm_host_control, UX_HOST_CLASS_CDC_ACM_IOCTL_SEND_BREAK, &break_ms);
if ((status != UX_SUCCESS) || (cdc_acm_slave -> ux_slave_class_cdc_acm_break_duration != break_ms))
{
printf("ERROR #78: IOCTRL UX_HOST_CLASS_CDC_ACM_IOCTL_SEND_BREAK should fail\n");
test_control_return(1);
}
break_ms = 0x0000;
status = ux_host_class_cdc_acm_ioctl(cdc_acm_host_control, UX_HOST_CLASS_CDC_ACM_IOCTL_SEND_BREAK, &break_ms);
if ((status != UX_SUCCESS) || (cdc_acm_slave -> ux_slave_class_cdc_acm_break_duration != break_ms))
{
printf("ERROR #78: IOCTRL UX_HOST_CLASS_CDC_ACM_IOCTL_SEND_BREAK should fail\n");
test_control_return(1);
}
/* Try IOCTRL UX_HOST_CLASS_CDC_ACM_IOCTL_GET/SET_LINE_CODING */
stepinfo(">>>>>>>>>>>> IOCTRL UX_HOST_CLASS_CDC_ACM_IOCTL_GET/SET_LINE_CODING without enough memory\n");
/* Use out memories */
ux_test_utility_sim_mem_allocate_until(UX_HOST_CLASS_CDC_ACM_LINE_CODING_LENGTH);
/* UX_HOST_CLASS_CDC_ACM_IOCTL_GET_LINE_CODING */
status = ux_host_class_cdc_acm_ioctl(cdc_acm_host_data, UX_HOST_CLASS_CDC_ACM_IOCTL_GET_LINE_CODING, &test_n);
if (status != UX_MEMORY_INSUFFICIENT)
{
printf("ERROR #80: IOCTRL UX_HOST_CLASS_CDC_ACM_IOCTL_GET_LINE_CODING should be fail if no memory\n");
test_control_return(1);
}
/* UX_HOST_CLASS_CDC_ACM_IOCTL_SET_LINE_CODING */
status = ux_host_class_cdc_acm_ioctl(cdc_acm_host_data, UX_HOST_CLASS_CDC_ACM_IOCTL_SET_LINE_CODING, &line_coding_host);
if (status != UX_MEMORY_INSUFFICIENT)
{
printf("ERROR #81: IOCTRL UX_HOST_CLASS_CDC_ACM_IOCTL_SET_LINE_CODING should be fail if no memory\n");
test_control_return(1);
}
/* Free memory */
ux_test_utility_sim_mem_free_all();
/* Try host read/write with semaphore error. */
stepinfo(">>>>>>>>>>>> R/W semaphore error\n");
/* Try host write, error must be returned. */
ux_test_utility_sim_sem_get_error_exception_add(UX_NULL, UX_WAIT_FOREVER);
ux_test_utility_sim_sem_get_error_generation_start(0);
/* Write small size */
status = ux_host_class_cdc_acm_write(cdc_acm_host_data, buffer, 64, &actual_length);
if (status == UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #52: write semaphore error not reported\n");
test_control_return(1);
}
/* Read large size */
status = ux_host_class_cdc_acm_read(cdc_acm_host_data, buffer, UX_DEMO_BUFFER_SIZE, &actual_length);
if (status == UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #51: read semaphore error not reported\n");
test_control_return(1);
}
ux_test_utility_sim_sem_get_error_generation_stop();
ux_test_utility_sim_sem_get_error_exception_reset();
/* Try host read/write with transfer error. */
stepinfo(">>>>>>>>>>>> R/W transfer error\n");
ux_test_hcd_sim_host_set_actions(error_on_transfer_0);
status = ux_host_class_cdc_acm_write(cdc_acm_host_data, buffer, 64, &actual_length);
if (status == UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #82: write transfer request error not reported\n");
test_control_return(1);
}
/* Stop reception for test */
status = ux_host_class_cdc_acm_reception_stop(cdc_acm_host_data, &cdc_acm_reception);
ux_test_hcd_sim_host_set_actions(error_on_transfer_0);
/* Read large size */
status = ux_host_class_cdc_acm_read(cdc_acm_host_data, buffer, UX_DEMO_BUFFER_SIZE, &actual_length);
if (status == UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #83: read transfer request error not reported\n");
test_control_return(1);
}
/* Error on second transfer request */
ux_test_hcd_sim_host_set_actions(error_on_transfer_1);
/* Put a semaphore for first transfer request. */
_ux_utility_semaphore_put(&cdc_acm_host_data->ux_host_class_cdc_acm_bulk_in_endpoint->ux_endpoint_transfer_request.ux_transfer_request_semaphore);
/* Read large size */
status = ux_host_class_cdc_acm_read(cdc_acm_host_data, buffer, UX_DEMO_BUFFER_SIZE, &actual_length);
if (status == UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #84: read transfer request error not reported\n");
test_control_return(1);
}
if (actual_length == 0)
{
/* CDC ACM basic test error. */
printf("ERROR #85: actual length should not be 0\n");
test_control_return(1);
}
/* Flush device. */
status = ux_host_class_cdc_acm_reception_start(cdc_acm_host_data, &cdc_acm_reception);
status = test_usbx_simulator_cdc_acm_host_send_string("ATO0",4);
status = test_usbx_simulator_cdc_acm_host_send_string("ATO0",4);
_tx_thread_sleep(10);
/* Stop reception for read test. */
status = ux_host_class_cdc_acm_reception_stop(cdc_acm_host_data, &cdc_acm_reception);
stepinfo(">>>>>>>>>>>> Read transfer good\n");
/* ATO1: expect return OK */
status = test_usbx_simulator_cdc_acm_host_send_string("ATO1",4);
/* Read, expect short package. */
status = ux_host_class_cdc_acm_read(cdc_acm_host_data, cdc_acm_reception_buffer, 64, &actual_length);
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #86: read transfer request error should not be reported\n");
test_control_return(1);
}
if (actual_length != 2)
{
/* CDC ACM basic test error. */
printf("ERROR #87: actual length should be 2\n");
test_control_return(1);
}
/* ATO1: expect return OK */
status = test_usbx_simulator_cdc_acm_host_send_string("ATO1",4);
/* Read, expect exact size. */
status = ux_host_class_cdc_acm_read(cdc_acm_host_data, cdc_acm_reception_buffer, 2, &actual_length);
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #86: read transfer request error should not be reported\n");
test_control_return(1);
}
if (actual_length != 2)
{
/* CDC ACM basic test error. */
printf("ERROR #87: actual length should be 2\n");
test_control_return(1);
}
/* ATO0: expect ZLP */
test_usbx_simulator_cdc_acm_host_send_string("ATO0",4);
status = ux_host_class_cdc_acm_read(cdc_acm_host_data, cdc_acm_reception_buffer, 64, &actual_length);
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #94: read transfer request error should not be reported\n");
test_control_return(1);
}
if (actual_length != 0)
{
/* CDC ACM basic test error. */
printf("ERROR #95: actual length should be 0 but not %ld\n", actual_length);
test_control_return(1);
}
#if defined(UX_DEVICE_CLASS_CDC_ACM_WRITE_AUTO_ZLP)
test_usbx_simulator_cdc_acm_host_send_string("ATO2",4);
status = ux_host_class_cdc_acm_read(cdc_acm_host_data, cdc_acm_reception_buffer, UX_DEMO_RECEPTION_BUFFER_SIZE, &actual_length);
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #%d: read transfer request error should not be reported\n", __LINE__);
test_control_return(1);
}
if (actual_length != 64)
{
/* CDC ACM basic test error. */
printf("ERROR #%d: actual length should be 64 but not %ld\n", __LINE__, actual_length);
test_control_return(1);
}
#endif
/* Start the reception for cdc_acm. */
status = ux_host_class_cdc_acm_reception_start(cdc_acm_host_data, &cdc_acm_reception);
/* Swap bulk IN/OUT endpoint position.
Simulate detach and attach for HS enumeration,
and test possible mutex creation error handlings.
*/
if (rsc_cdc_mutex_usage) stepinfo(">>>>>>>>>>>> Enumerate mutex error\n");
for (test_n = 0; test_n < rsc_cdc_mutex_usage; test_n ++)
{
stepinfo("%4ld / %4ld\n", test_n, rsc_cdc_mutex_usage - 1);
/* Disconnect. */
ux_test_dcd_sim_slave_disconnect();
ux_test_hcd_sim_host_disconnect();
/* Swap EP address. */
test_swap_framework_bulk_ep_descriptors();
/* Generate error while the test_n and after mutex are requested */
ux_test_utility_sim_mutex_error_generation_start(test_n + rsc_enum_mutex_usage);
/* Connect. */
ux_test_dcd_sim_slave_connect(UX_HIGH_SPEED_DEVICE);
ux_test_hcd_sim_host_connect(UX_HIGH_SPEED_DEVICE);
tx_thread_sleep(100);
if (cdc_acm_host_control && cdc_acm_host_data)
{
printf("ERROR #97: at least one interface should fail\n");
test_control_return(1);
}
}
ux_test_utility_sim_mutex_error_generation_stop();
/* Simulate detach and attach for FS enumeration,
and test possible semaphore creation error handlings.
*/
ux_test_utility_sim_sem_get_error_exception_add(&_ux_system_host -> ux_system_host_hcd_semaphore, UX_WAIT_FOREVER);
if (rsc_cdc_sem_usage) stepinfo(">>>>>>>>>>>> Enumerate semaphore error\n");
for (test_n = 0; test_n < rsc_cdc_sem_usage; test_n ++)
{
stepinfo("%4ld / %4ld\n", test_n, rsc_cdc_sem_usage - 1);
/* Disconnect. */
ux_test_dcd_sim_slave_disconnect();
ux_test_hcd_sim_host_disconnect();
/* Generate error while the test_n and after semaphore are requested */
ux_test_utility_sim_sem_error_generation_start(test_n + rsc_enum_sem_usage);
/* Connect. */
error_callback_counter = 0;
ux_test_dcd_sim_slave_connect(UX_FULL_SPEED_DEVICE);
ux_test_hcd_sim_host_connect(UX_FULL_SPEED_DEVICE);
#if 0
tx_thread_sleep(100);
#else
/* Wait until error detected. */
ux_test_breakable_sleep(100, sleep_break_on_error);
#endif
if (cdc_acm_host_control && cdc_acm_host_data)
{
printf("ERROR #97: at least one interface should fail\n");
test_control_return(1);
}
}
ux_test_utility_sim_sem_error_generation_stop();
ux_test_utility_sim_sem_get_error_exception_reset();
stepinfo(">>>>>>>>>>>> Enumerate interrupt EP transfer request error\n");
/* Disconnect. */
ux_test_dcd_sim_slave_disconnect();
ux_test_hcd_sim_host_disconnect();
/* Transfer error on interrupt IN 0x83 */
ux_test_hcd_sim_host_set_actions(error_on_transfer_interruptEP);
/* Connect. */
ux_test_dcd_sim_slave_connect(UX_FULL_SPEED_DEVICE);
ux_test_hcd_sim_host_connect(UX_FULL_SPEED_DEVICE);
tx_thread_sleep(100);
if (cdc_acm_host_control)
{
printf("ERROR #96: control interface should fail\n");
test_control_return(1);
}
stepinfo(">>>>>>>>>>>> Capabilities get\n");
/* Confirm connection */
ux_test_dcd_sim_slave_disconnect();
ux_test_hcd_sim_host_disconnect();
ux_test_hcd_sim_host_set_actions(UX_NULL);
ux_test_dcd_sim_slave_connect(UX_FULL_SPEED_DEVICE);
ux_test_hcd_sim_host_connect(UX_FULL_SPEED_DEVICE);
test_n = 10;
while(cdc_acm_host_control == UX_NULL && test_n --)
tx_thread_sleep(10);
if (cdc_acm_host_control == UX_NULL)
{
printf("ERROR #99: CDC ACM control interface is not ready\n");
test_control_return(1);
}
/* Some of descriptor length is too small */
replaced_cfg_descriptor[9+8+9+5] = 0;
ux_test_hcd_sim_host_set_actions(replaced_GetCfgDescr);
status = _ux_host_class_cdc_acm_capabilities_get(cdc_acm_host_control);
if (status != UX_DESCRIPTOR_CORRUPTED)
{
printf("ERROR #100: descriptor error should be reported\n");
test_control_return(1);
}
/* Some of descriptor length is too large */
replaced_cfg_descriptor[9+8+9+5] = sizeof(replaced_cfg_descriptor);
ux_test_hcd_sim_host_set_actions(replaced_GetCfgDescr);
status = _ux_host_class_cdc_acm_capabilities_get(cdc_acm_host_control);
if (status != UX_DESCRIPTOR_CORRUPTED)
{
printf("ERROR #101: no descriptor error reported\n");
test_control_return(1);
}
/* Restore descriptor size */
replaced_cfg_descriptor[9+8+9+5] = device_framework_full_speed[18 + 9+8+9+5];
/* Set descriptor sub class to DLC */
replaced_cfg_descriptor[9+8 + 6] = UX_HOST_CLASS_CDC_DLC_SUBCLASS;
ux_test_hcd_sim_host_set_actions(replaced_GetCfgDescr);
status = _ux_host_class_cdc_acm_capabilities_get(cdc_acm_host_control);
if (status != UX_SUCCESS)
{
printf("ERROR #102: no error expected\n");
test_control_return(1);
}
stepinfo(">>>>>>>>>>>> Deactivate while writing\n");
test_usbx_simulator_cdc_acm_host_send_string("ATK",3); /* Disconnect after 10 tick */
ux_test_hcd_sim_host_set_actions(wait_disconn_on_transfer_0);
status = ux_host_class_cdc_acm_write(cdc_acm_host_data, cdc_acm_xmit_buffer, 16384, &actual_length);
stepinfo(">>>>>>>>>>>> All Done\n");
/* Finally disconnect the device. */
ux_device_stack_disconnect();
/* And deinitialize the class. */
status = ux_device_stack_class_unregister(_ux_system_slave_class_cdc_acm_name, ux_device_class_cdc_acm_entry);
/* Deinitialize the device side of usbx. */
_ux_device_stack_uninitialize();
/* And finally the usbx system resources. */
_ux_system_uninitialize();
/* Successful test. */
printf("SUCCESS!\n");
test_control_return(0);
}
UINT test_usbx_simulator_cdc_acm_host_send_command(UCHAR *string, ULONG length, ULONG no_ack)
{
UINT status;
ULONG actual_length;
/* Perform a write to the modem to echo values. And wait for the answer. */
ux_utility_memory_copy(cdc_acm_xmit_buffer, string,length);
cdc_acm_xmit_buffer[length] = 0x0d;
cdc_acm_xmit_buffer[length+1] = 0x0a;
/* Update the length. */
length += 2;
/* Send the AT command. */
status = ux_host_class_cdc_acm_write(cdc_acm_host_data, cdc_acm_xmit_buffer, length, &actual_length);
/* The device may be extracted after we start sending\receiving. */
if (status != UX_SUCCESS)
return(status);
/* Wait for the answer. */
if (!no_ack)
while(command_received_count == 0)
tx_thread_sleep(10);
/* Reset receive count. */
command_received_count = 0;
/* Return status. */
return(status);
}
void test_thread_host_reception_callback(UX_HOST_CLASS_CDC_ACM *cdc_acm, UINT status, UCHAR *reception_buffer, ULONG reception_size)
{
/* Incase target to test overflow case, buffers are not moved. */
if (!cdc_acm_reception_overflow)
{
/* And move to the next reception buffer. Check if we are at the end of the application buffer. */
if (cdc_acm_reception.ux_host_class_cdc_acm_reception_data_tail + cdc_acm_reception.ux_host_class_cdc_acm_reception_block_size >=
cdc_acm_reception.ux_host_class_cdc_acm_reception_data_buffer + cdc_acm_reception.ux_host_class_cdc_acm_reception_data_buffer_size)
/* We are at the end of the buffer. Move back to the beginning. */
cdc_acm_reception.ux_host_class_cdc_acm_reception_data_tail = cdc_acm_reception.ux_host_class_cdc_acm_reception_data_buffer;
else
/* Program the tail to be after the current buffer. */
cdc_acm_reception.ux_host_class_cdc_acm_reception_data_tail += cdc_acm_reception.ux_host_class_cdc_acm_reception_block_size;
}
if (status == UX_BUFFER_OVERFLOW)
cdc_acm_reception_overflow = UX_FALSE;
/* Keep the buffer pointer and length received. */
global_reception_buffer = reception_buffer;
global_reception_size = reception_size;
/* We have received a response. */
command_received_count++;
return;
}
static VOID ux_test_host_class_cdc_acm_device_status_change_callback(
struct UX_HOST_CLASS_CDC_ACM_STRUCT *cdc_acm,
ULONG notification_type,
ULONG notification_value)
{
/* We received a notification */
notification_count ++;
}
void tx_test_thread_slave_simulation_entry(ULONG arg)
{
UINT status;
ULONG requested_length;
ULONG actual_length;
UX_SLAVE_CLASS_CDC_ACM_LINE_CODING_PARAMETER line_coding;
UX_SLAVE_CLASS_CDC_ACM_LINE_STATE_PARAMETER line_state;
UX_SLAVE_CLASS_COMMAND class_command;
UCHAR data_bit[16];
ULONG read_size = 64;
ULONG write_size;
/* The stack/class code always invoke ux_device_class_cdc_acm_entry correct.
Do a command request error test here. */
class_command.ux_slave_class_command_request = 0xFF;
status = ux_device_class_cdc_acm_entry(&class_command);
/* Error should be reported */
if (status == UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #30\n");
test_control_return(1);
}
/* On CDC ACM driver initialize, there is memory allocation for:
- instance of the device cdc_acm class
- mute for each of endpoint (EP IN and EP OUT)
mute creation never fails so there is no tests.
*/
/* Use out memories */
ux_test_utility_sim_mem_allocate_until(sizeof(UX_SLAVE_CLASS_CDC_ACM));
/* Try initialize CDC ACM instance */
class_command.ux_slave_class_command_request = UX_SLAVE_CLASS_COMMAND_INITIALIZE;
status = ux_device_class_cdc_acm_entry(&class_command);
/* Error should be reported */
if (status == UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #32\n");
test_control_return(1);
}
/* Free memory after test */
ux_test_utility_sim_mem_free_all();
while(1)
{
/* Ensure the CDC class is mounted. */
while(cdc_acm_slave != UX_NULL && cdc_acm_slave_bulk_read_write == UX_TRUE)
{
/* Read from the CDC class. */
status = ux_device_class_cdc_acm_read(cdc_acm_slave, buffer, read_size, &actual_length);
if (status != UX_SUCCESS)
{
break;
}
/* Change read size for different read cases */
if (read_size <= 64)
read_size = UX_SLAVE_REQUEST_DATA_MAX_LENGTH;
/* The actual length becomes the requested length. */
requested_length = actual_length;
/* Check for AT command. */
if (*buffer == 'A' && *(buffer + 1) == 'T')
{
/* This is a AT command. Decode next byte. */
switch (*(buffer + 2))
{
case 'K' : /* Break! */
tx_thread_sleep(10);
ux_test_hcd_sim_host_disconnect();
break;
case 'O' :
/* Start writing. */
switch(*(buffer + 3))
{
case '0': /* ZLP */
write_size = 0;
break;
case '1': /* Short packet of 2 */
write_size = 2;
break;
case '2': /* Full packet of 64 */
write_size = 64;
break;
case '3': /* Full packet of 512 */
write_size = 512;
break;
case '4': /* Full packet of 4096 */
write_size = 4096;
break;
case '5': /* Full packet of 8128 */
write_size = 8128;
break;
case 'P': /* Full packet of 64 */
write_size = 64;
read_size = 64; /* Next read is 64 */
break;
default:
write_size = UX_DEMO_BUFFER_SIZE * 4;
break;
}
status = ux_device_class_cdc_acm_write(cdc_acm_slave, buffer, write_size, &actual_length);
if (status == UX_TRANSFER_BUS_RESET)
status = ux_device_class_cdc_acm_write(cdc_acm_slave, buffer, write_size, &actual_length);
break;
case 'W' :
/* Start writing. */
status = ux_device_class_cdc_acm_write(cdc_acm_slave, buffer, UX_DEMO_BUFFER_SIZE, &actual_length);
if (status == UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #50\n");
test_control_return(1);
}
break;
case 'A' :
/* This is to try abort XMIT. Pending or next XMIT aborted. */
status = _ux_device_class_cdc_acm_ioctl(cdc_acm_slave, UX_SLAVE_CLASS_CDC_ACM_IOCTL_ABORT_PIPE, (VOID*)UX_SLAVE_CLASS_CDC_ACM_ENDPOINT_XMIT);
/* Error should not be reported */
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #35\n");
test_control_return(1);
}
/* This is to try abort RCV. */
status = _ux_device_class_cdc_acm_ioctl(cdc_acm_slave, UX_SLAVE_CLASS_CDC_ACM_IOCTL_ABORT_PIPE, (VOID*)UX_SLAVE_CLASS_CDC_ACM_ENDPOINT_RCV);
/* Error should not be reported */
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #39\n");
test_control_return(1);
}
/* This is to try abort unknown. */
status = _ux_device_class_cdc_acm_ioctl(cdc_acm_slave, UX_SLAVE_CLASS_CDC_ACM_IOCTL_ABORT_PIPE, (VOID*)0xFF);
/* Error should be reported */
if (status == UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #47\n");
test_control_return(1);
}
status = tx_test_thread_slave_simulation_response(_rsp_ok, UX_DEMO_BUFFER_SIZE - 2);
if (status != UX_SUCCESS)
{
/* Try again if it's aborted */
status = tx_test_thread_slave_simulation_response(_rsp_ok, UX_DEMO_BUFFER_SIZE - 2);
}
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #44: response sent error %x\n", status);
test_control_return(1);
}
break;
case 'F' :
/* This is to try invalid IOCTRL code */
status = _ux_device_class_cdc_acm_ioctl(cdc_acm_slave, 0xFF, 0);
/* Error should be reported */
if (status == UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #34\n");
test_control_return(1);
}
/* Send response any case */
status = tx_test_thread_slave_simulation_response("OK", 2);
if (status == UX_TRANSFER_BUS_RESET)
status = tx_test_thread_slave_simulation_response("OK", 2);
/* Send ZLP */
ux_device_class_cdc_acm_write(cdc_acm_slave, buffer, 0, &actual_length);
break;
case 'L' :
/* This is to set line coding. */
line_coding.ux_slave_class_cdc_acm_parameter_baudrate = buffer[3] + (buffer[4] << 8) + (buffer[5] << 16) + (buffer[6] << 24);
line_coding.ux_slave_class_cdc_acm_parameter_stop_bit = *(buffer + 7);
line_coding.ux_slave_class_cdc_acm_parameter_parity = *(buffer + 8);
line_coding.ux_slave_class_cdc_acm_parameter_data_bit = *(buffer + 9);
status = _ux_device_class_cdc_acm_ioctl(cdc_acm_slave, UX_SLAVE_CLASS_CDC_ACM_IOCTL_SET_LINE_CODING, &line_coding);
if (status != UX_SUCCESS)
{
/* CDC ACM basic test error. */
printf("ERROR #38\n");
test_control_return(1);
}
/* Send response any case */
status = tx_test_thread_slave_simulation_response("OK", 2);
break;
case 'B' :
/* This is to retrieve BAUD rate. */
status = _ux_device_class_cdc_acm_ioctl(cdc_acm_slave, UX_SLAVE_CLASS_CDC_ACM_IOCTL_GET_LINE_CODING, &line_coding);
/* Any error ? */
if (status == UX_SUCCESS)
{
/* Decode BAUD rate. */
switch (line_coding.ux_slave_class_cdc_acm_parameter_baudrate)
{
case 300 :
status = tx_test_thread_slave_simulation_response("300", 3);
break;
case 1200 :
status = tx_test_thread_slave_simulation_response("1200", 4);
break;
case 2400 :
status = tx_test_thread_slave_simulation_response("2400", 4);
break;
case 4800 :
status = tx_test_thread_slave_simulation_response("4800", 4);
break;
case 9600 :
status = tx_test_thread_slave_simulation_response("9600", 4);
break;
case 14400 :
status = tx_test_thread_slave_simulation_response("14400", 5);
break;
case 19200 :
status = tx_test_thread_slave_simulation_response("19200", 5);
break;
case 28800 :
status = tx_test_thread_slave_simulation_response("28800", 5);
break;
case 38400 :
status = tx_test_thread_slave_simulation_response("38400", 5);
break;
case 57600 :
status = tx_test_thread_slave_simulation_response("57600", 5);
break;
case 115200 :
status = tx_test_thread_slave_simulation_response("115200", 6);
break;
case 230400 :
status = tx_test_thread_slave_simulation_response("230400", 6);
break;
}
}
break;
case 'S' :
/* This is to retrieve stop bit rate. */
status = _ux_device_class_cdc_acm_ioctl(cdc_acm_slave, UX_SLAVE_CLASS_CDC_ACM_IOCTL_GET_LINE_CODING, &line_coding);
/* Any error ? */
if (status == UX_SUCCESS)
{
/* Decode stop bit. */
switch (line_coding.ux_slave_class_cdc_acm_parameter_stop_bit)
{
case 0 :
status = tx_test_thread_slave_simulation_response("0 Stop bit", 10);
break;
case 1 :
status = tx_test_thread_slave_simulation_response("1.5 Stop bit", 12);
break;
case 2 :
status = tx_test_thread_slave_simulation_response("2 Stop bit", 10);
break;
}
}
break;
case 'P' :
/* This is to retrieve parity rate. */
status = _ux_device_class_cdc_acm_ioctl(cdc_acm_slave, UX_SLAVE_CLASS_CDC_ACM_IOCTL_GET_LINE_CODING, &line_coding);
/* Any error ? */
if (status == UX_SUCCESS)
{
/* Decode Parity bit. */
switch (line_coding.ux_slave_class_cdc_acm_parameter_parity)
{
case 0 :
status = tx_test_thread_slave_simulation_response("Parity none", 11);
break;
case 1 :
status = tx_test_thread_slave_simulation_response("Parity odd", 10);
break;
case 2 :
status = tx_test_thread_slave_simulation_response("Parity even", 11);
break;
case 3 :
status = tx_test_thread_slave_simulation_response("Parity mark", 11);
break;
case 4 :
status = tx_test_thread_slave_simulation_response("Parity space", 12);
break;
}
}
break;
case 'D' :
/* This is to retrieve Data Bit. */
status = _ux_device_class_cdc_acm_ioctl(cdc_acm_slave, UX_SLAVE_CLASS_CDC_ACM_IOCTL_GET_LINE_CODING, &line_coding);
/* Any error ? */
if (status == UX_SUCCESS)
{
/* Copy generic string. */
ux_utility_memory_copy(data_bit, "Data Bit x",10);
/* Put data bit value. */
data_bit[9] = line_coding.ux_slave_class_cdc_acm_parameter_data_bit + '0';
/* Send data. */
status = tx_test_thread_slave_simulation_response(data_bit, 10);
}
break;
case 'R' :
/* This is to retrieve RTS state. */
status = _ux_device_class_cdc_acm_ioctl(cdc_acm_slave, UX_SLAVE_CLASS_CDC_ACM_IOCTL_GET_LINE_STATE, &line_state);
/* Any error ? */
if (status == UX_SUCCESS)
{
/* Check state. */
if (line_state.ux_slave_class_cdc_acm_parameter_rts == UX_TRUE)
/* State is ON. */
status = tx_test_thread_slave_simulation_response("RTS ON", 6);
else
/* State is OFF. */
status = tx_test_thread_slave_simulation_response("RTS OFF", 7);
}
break;
case 'T' :
/* This is to retrieve DTR state. */
status = _ux_device_class_cdc_acm_ioctl(cdc_acm_slave, UX_SLAVE_CLASS_CDC_ACM_IOCTL_GET_LINE_STATE, &line_state);
/* Any error ? */
if (status == UX_SUCCESS)
{
/* Check state. */
if (line_state.ux_slave_class_cdc_acm_parameter_dtr == UX_TRUE)
/* State is ON. */
status = tx_test_thread_slave_simulation_response("DTR ON", 6);
else
/* State is OFF. */
status = tx_test_thread_slave_simulation_response("DTR OFF", 7);
}
break;
}
}
else
{
/* Not an AT command, just echo back. */
/* Check the status. If OK, we will write to the CDC instance. */
status = ux_device_class_cdc_acm_write(cdc_acm_slave, buffer, requested_length, &actual_length);
/* Check for CR/LF. */
if (buffer[requested_length - 1] == '\r')
{
/* Copy LF value into user buffer. */
ux_utility_memory_copy(buffer, "\n", 1);
/* And send it again. */
status = ux_device_class_cdc_acm_write(cdc_acm_slave, buffer, 1, &actual_length);
}
}
}
/* Sleep so ThreadX on Win32 will delete this thread. */
tx_thread_sleep(10);
}
}
UINT tx_test_thread_slave_simulation_response(UCHAR *string, ULONG length)
{
UINT status;
ULONG actual_length;
/* Perform a write to the modem to echo values. And wait for the answer. */
ux_utility_memory_copy(buffer, string,length);
buffer[length] = 0x0d;
buffer[length+1] = 0x0a;
/* Update the length. */
length += 2;
/* Check the status. If OK, we will write to the CDC instance. */
status = ux_device_class_cdc_acm_write(cdc_acm_slave, buffer, length, &actual_length);
/* Return status. */
return(status);
}
static UINT ux_test_host_class_cdc_acm_command(UX_HOST_CLASS_CDC_ACM *cdc_acm, ULONG command,
ULONG value, UCHAR *data_buffer, ULONG data_length,
ULONG *actual_length)
{
UX_ENDPOINT *control_endpoint;
UX_TRANSFER *transfer_request;
UINT status;
ULONG request_direction;
/* We need to get the default control endpoint transfer request pointer. */
control_endpoint = &cdc_acm -> ux_host_class_cdc_acm_device -> ux_device_control_endpoint;
transfer_request = &control_endpoint -> ux_endpoint_transfer_request;
switch(command)
{
case UX_HOST_CLASS_CDC_ACM_REQ_GET_ENCAPSULATED_COMMAND:
case UX_HOST_CLASS_CDC_ACM_REQ_GET_COMM_FEATURE:
case UX_HOST_CLASS_CDC_ACM_REQ_GET_LINE_CODING:
case UX_HOST_CLASS_CDC_ACM_REQ_GET_RINGER_PARMS:
case UX_HOST_CLASS_CDC_ACM_REQ_GET_OPERATION_PARMS:
case UX_HOST_CLASS_CDC_ACM_REQ_GET_LINE_PARMS:
request_direction = UX_REQUEST_IN;
break;
default:
request_direction = UX_REQUEST_OUT;
}
/* Protect the control endpoint semaphore here. It will be unprotected in the
transfer request function. */
status = _ux_utility_semaphore_get(&cdc_acm -> ux_host_class_cdc_acm_device -> ux_device_protection_semaphore, UX_WAIT_FOREVER);
/* Check for status. */
if (status != UX_SUCCESS)
/* Something went wrong. */
return(status);
/* Create a transfer_request for the request. */
transfer_request -> ux_transfer_request_data_pointer = data_buffer;
transfer_request -> ux_transfer_request_requested_length = data_length;
transfer_request -> ux_transfer_request_function = command;
transfer_request -> ux_transfer_request_type = request_direction | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE;
transfer_request -> ux_transfer_request_value = value;
transfer_request -> ux_transfer_request_index = cdc_acm -> ux_host_class_cdc_acm_interface -> ux_interface_descriptor.bInterfaceNumber;
/* Send request to HCD layer. */
status = ux_host_stack_transfer_request(transfer_request);
/* Fill actual length */
if (actual_length) {
*actual_length = transfer_request -> ux_transfer_request_actual_length;
}
/* Return completion status. */
return(status);
}
|