1 /* This test is designed to test the simple dpump host/device class operation.  */
2 
3 #include <stdio.h>
4 #include "tx_api.h"
5 #include "ux_api.h"
6 #include "ux_system.h"
7 #include "ux_utility.h"
8 
9 #include "fx_api.h"
10 
11 #include "ux_device_class_cdc_acm.h"
12 #include "ux_device_stack.h"
13 
14 #include "ux_host_class_cdc_acm.h"
15 
16 #include "ux_test_dcd_sim_slave.h"
17 #include "ux_test_hcd_sim_host.h"
18 #include "ux_test_utility_sim.h"
19 
20 #include "ux_host_stack.h"
21 
22 /* Define constants.  */
23 #define                             UX_DEMO_DEBUG_SIZE  (4096*8)
24 #define                             UX_DEMO_STACK_SIZE  1024
25 #define                             UX_DEMO_BUFFER_SIZE (UX_SLAVE_REQUEST_DATA_MAX_LENGTH + 1)
26 #define                             UX_DEMO_XMIT_BUFFER_SIZE 512
27 #define                             UX_DEMO_RECEPTION_BUFFER_SIZE 512
28 #define                             UX_DEMO_FILE_BUFFER_SIZE 512
29 #define                             UX_DEMO_RECEPTION_BLOCK_SIZE 64
30 #define                             UX_DEMO_MEMORY_SIZE     (64*1024)
31 #define                             UX_DEMO_FILE_SIZE       (128 * 1024)
32 #define                             UX_RAM_DISK_MEMORY      (256 * 1024)
33 
34 #define     LSB(x) ( (x) & 0x00ff)
35 #define     MSB(x) (((x) & 0xff00) >> 8)
36 
37 /* Configuration descriptor 9 bytes */
38 #define CFG_DESC(wTotalLength, bNumInterfaces, bmAttributes, bConfigurationValue)\
39     /* Configuration 1 descriptor 9 bytes */\
40     0x09, 0x02, LSB(wTotalLength), MSB(wTotalLength),\
41     (bNumInterfaces), (bConfigurationValue), 0x00,\
42     (bmAttributes), 0x00,
43 #define CFG_DESC_LEN 9
44 
45 #define IAD_DESC(bIfc) \
46     /* Interface association descriptor. 8 bytes.  */\
47     0x08, 0x0b, (bIfc), 0x02, 0x02, 0x02, 0x00, 0x00,
48 #define IAD_DESC_LEN 8
49 
50 #define CDC_IFC_DESC_ALL(bIfc, bIntIn, bBulkIn, bBulkOut)\
51     /* Communication Class Interface Descriptor Requirement. 9 bytes.   */\
52     0x09, 0x04, (bIfc), 0x00, 0x01, 0x02, 0x02, 0x01, 0x00,\
53     /* Header Functional Descriptor 5 bytes */\
54     0x05, 0x24, 0x00, 0x10, 0x01,\
55     /* ACM Functional Descriptor 4 bytes */\
56     0x04, 0x24, 0x02, 0x0f,\
57     /* Union Functional Descriptor 5 bytes */\
58     0x05, 0x24, 0x06, (bIfc), (bIfc + 1),\
59     /* Call Management Functional Descriptor 5 bytes */\
60     0x05, 0x24, 0x01, 0x03, (bIfc + 1),\
61     /* Endpoint interrupt in descriptor 7 bytes */\
62     0x07, 0x05, (bIntIn), 0x03, 0x40, 0x00, 0x10,\
63     /* Data Class Interface Descriptor Requirement 9 bytes */\
64     0x09, 0x04, (bIfc + 1), 0x00, 0x02, 0x0A, 0x00, 0x00, 0x00,\
65     /* Endpoint bulk in descriptor 7 bytes */\
66     0x07, 0x05, (bBulkIn), 0x02, 0x40, 0x00, 0x01,\
67     /* Endpoint bulk out descriptor 7 bytes */\
68     0x07, 0x05, (bBulkOut), 0x02, 0x40, 0x00, 0x01,
69 #define CDC_IFC_DESC_ALL1(bIfc, bIntIn, bBulkIn, bBulkOut)\
70     /* Communication Class Interface Descriptor Requirement. 9 bytes.   */\
71     0x09, 0x04, (bIfc), 0x00, 0x01, 0x02, 0x02, 0x01, 0x00,\
72     /* Header Functional Descriptor 5 bytes */\
73     0x05, 0x24, 0x00, 0x10, 0x01,\
74     /* ACM Functional Descriptor 4 bytes */\
75     0x04, 0x24, 0x02, 0x0f,\
76     /* Union Functional Descriptor 5 bytes */\
77     0x05, 0x24, 0x06, (bIfc), (bIfc + 1),\
78     /* Call Management Functional Descriptor 5 bytes */\
79     0x05, 0x24, 0x01, 0x03, (bIfc + 1),\
80     /* Endpoint interrupt in descriptor 7 bytes */\
81     0x07, 0x05, (bIntIn), 0x03, 0x40, 0x00, 0x10,\
82     /* Data Class Interface Descriptor Requirement 9 bytes */\
83     0x09, 0x04, (bIfc + 1), 0x00, 0x02, 0x0A, 0x00, 0x00, 0x00,\
84     /* Endpoint bulk out descriptor 7 bytes */\
85     0x07, 0x05, (bBulkOut), 0x02, 0x40, 0x00, 0x01,\
86     /* Endpoint bulk in descriptor 7 bytes */\
87     0x07, 0x05, (bBulkIn), 0x02, 0x40, 0x00, 0x01,
88 #define CDC_IFC_DESC_ALL_LEN (9+5+4+5+5+7+ 9+7+7)
89 
90 /* Define local/extern function prototypes.  */
91 static VOID                                test_thread_entry(ULONG);
92 static TX_THREAD                           tx_test_thread_host_simulation;
93 static TX_THREAD                           tx_test_thread_slave_simulation;
94 static VOID                                tx_test_thread_host_simulation_entry(ULONG);
95 static VOID                                tx_test_thread_slave_simulation_entry(ULONG);
96 
97 static VOID                                test_cdc_instance_activate(VOID  *cdc_instance);
98 static VOID                                test_cdc_instance_deactivate(VOID *cdc_instance);
99 static VOID                                test_cdc_instance_parameter_change(VOID *cdc_instance);
100 
101 /* Define global data structures.  */
102 static UCHAR                               usbx_memory[UX_DEMO_MEMORY_SIZE + (UX_DEMO_STACK_SIZE * 2)];
103 
104 static UX_HOST_CLASS_CDC_ACM               *cdc_acm_host_control = UX_NULL;
105 static UX_HOST_CLASS_CDC_ACM               *cdc_acm_host_data = UX_NULL;
106 
107 static UX_HOST_CLASS_CDC_ACM               *cdc_acm_host_control1 = UX_NULL;
108 static UX_HOST_CLASS_CDC_ACM               *cdc_acm_host_data1 = UX_NULL;
109 
110 static UX_SLAVE_CLASS_CDC_ACM              *cdc_acm_slave = UX_NULL;
111 
112 static UX_SLAVE_CLASS_CDC_ACM              *cdc_acm_slave1 = UX_NULL;
113 
114 static UCHAR                               cdc_acm_slave_change;
115 static UX_SLAVE_CLASS_CDC_ACM_PARAMETER    parameter;
116 
117 static ULONG                               error_counter;
118 
119 static ULONG                               error_callback_counter;
120 static UCHAR                               error_callback_ignore;
121 
122 static ULONG                               call_counter;
123 
124 static UCHAR                               buffer[UX_DEMO_BUFFER_SIZE];
125 
126 static UCHAR                               test_slave_code = 0;
127 static UCHAR                               test_slave_state = 0;
128 
129 /* Define device framework.  */
130 
131 static unsigned char device_framework_full_speed[] = {
132 
133     /* Device descriptor     18 bytes
134        0x02 bDeviceClass:    CDC class code
135        0x00 bDeviceSubclass: CDC class sub code
136        0x00 bDeviceProtocol: CDC Device protocol
137 
138        idVendor & idProduct - http://www.linux-usb.org/usb.ids
139     */
140     0x12, 0x01, 0x10, 0x01,
141     0xEF, 0x02, 0x01,
142     0x08,
143     0x84, 0x84, 0x00, 0x00,
144     0x00, 0x01,
145     0x01, 0x02, 03,
146     0x01, /* bNumConfigurations */
147 
148     /* Configuration 1 descriptor 9 bytes, total 75 bytes */
149     CFG_DESC(CFG_DESC_LEN + (IAD_DESC_LEN + CDC_IFC_DESC_ALL_LEN) * 2, 4, 0x40, 1)
150     /* IAD 8 bytes */
151     IAD_DESC(0)
152     /* CDC_ACM interfaces */
153     CDC_IFC_DESC_ALL(0, 0x83, 0x81, 0x02)
154     /* IAD 8 bytes */
155     IAD_DESC(2)
156     /* CDC_ACM interfaces */
157     CDC_IFC_DESC_ALL1(2, 0x86, 0x85, 0x04)
158 };
159 #define             DEVICE_FRAMEWORK_LENGTH_FULL_SPEED      sizeof(device_framework_full_speed)
160 
161 static unsigned char device_framework_high_speed[] = {
162 
163     /* Device descriptor     18 bytes
164        0x02 bDeviceClass:    CDC class code
165        0x00 bDeviceSubclass: CDC class sub code
166        0x00 bDeviceProtocol: CDC Device protocol
167 
168        idVendor & idProduct - http://www.linux-usb.org/usb.ids
169     */
170     0x12, 0x01, 0x00, 0x02,
171     0xEF, 0x02, 0x01,
172     0x40,
173     0x84, 0x84, 0x00, 0x00,
174     0x00, 0x01,
175     0x01, 0x02, 03,
176     0x01, /* bNumConfigurations */
177 
178     /* Device qualifier descriptor 10 bytes */
179     0x0a, 0x06, 0x00, 0x02,
180     0x02, 0x00, 0x00,
181     0x40,
182     0x01,
183     0x00,
184 
185     /* Configuration 1 descriptor 9 bytes, total 75 bytes */
186     CFG_DESC(CFG_DESC_LEN + IAD_DESC_LEN + CDC_IFC_DESC_ALL_LEN, 2, 0x60, 1)
187     /* IAD 8 bytes */
188     IAD_DESC(0)
189     /* CDC_ACM interfaces */
190     CDC_IFC_DESC_ALL1(0, 0x83, 0x81, 0x02)
191     /* IAD 8 bytes */
192     IAD_DESC(2)
193     /* CDC_ACM interfaces */
194     CDC_IFC_DESC_ALL(2, 0x86, 0x85, 0x04)
195 };
196 #define             DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED      sizeof(device_framework_high_speed)
197 
198 static unsigned char string_framework[] = {
199 
200     /* Manufacturer string descriptor : Index 1 - "Express Logic" */
201     0x09, 0x04, 0x01, 0x0c,
202     0x45, 0x78, 0x70, 0x72,0x65, 0x73, 0x20, 0x4c,
203     0x6f, 0x67, 0x69, 0x63,
204 
205     /* Product string descriptor : Index 2 - "EL Composite device" */
206     0x09, 0x04, 0x02, 0x13,
207     0x45, 0x4c, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x6f,
208     0x73, 0x69, 0x74, 0x65, 0x20, 0x64, 0x65, 0x76,
209     0x69, 0x63, 0x65,
210 
211     /* Serial Number string descriptor : Index 3 - "0001" */
212     0x09, 0x04, 0x03, 0x04,
213     0x30, 0x30, 0x30, 0x31
214 };
215 #define             STRING_FRAMEWORK_LENGTH                 sizeof(string_framework)
216 
217 /* Multiple languages are supported on the device, to add
218     a language besides english, the unicode language code must
219     be appended to the language_id_framework array and the length
220     adjusted accordingly. */
221 static unsigned char language_id_framework[] = {
222 
223     /* English. */
224     0x09, 0x04
225 };
226 #define             LANGUAGE_ID_FRAMEWORK_LENGTH            sizeof(language_id_framework)
227 
228 /* Define the ISR dispatch.  */
229 
230 extern VOID    (*test_isr_dispatch)(void);
231 
232 
233 /* Prototype for test control return.  */
234 
235 void  test_control_return(UINT status);
236 
237 
238 /* Define the ISR dispatch routine.  */
239 
test_isr(void)240 static void    test_isr(void)
241 {
242 
243     /* For further expansion of interrupt-level testing.  */
244 }
245 
break_on_cdc_acm_all_ready(VOID)246 static UINT break_on_cdc_acm_all_ready(VOID)
247 {
248 
249     if (cdc_acm_host_control == UX_NULL || cdc_acm_host_data == UX_NULL)
250         /* Do not break. */
251         return 0;
252 
253     if (cdc_acm_host_control1 == UX_NULL || cdc_acm_host_data1 == UX_NULL)
254         /* Do not break. */
255         return 0;
256 
257     if (cdc_acm_host_control->ux_host_class_cdc_acm_state != UX_HOST_CLASS_INSTANCE_LIVE)
258         /* Do not break. */
259         return 0;
260 
261     if (cdc_acm_host_data->ux_host_class_cdc_acm_state != UX_HOST_CLASS_INSTANCE_LIVE)
262         /* Do not break. */
263         return 0;
264 
265     if (cdc_acm_host_control1->ux_host_class_cdc_acm_state != UX_HOST_CLASS_INSTANCE_LIVE)
266         /* Do not break. */
267         return 0;
268 
269     if (cdc_acm_host_data1->ux_host_class_cdc_acm_state != UX_HOST_CLASS_INSTANCE_LIVE)
270         /* Do not break. */
271         return 0;
272 
273     if (cdc_acm_slave == UX_NULL || cdc_acm_slave1 == UX_NULL)
274         /* Do not break. */
275         return 0;
276 
277     /* All found, break. */
278     return 1;
279 }
280 
break_on_removal(VOID)281 static UINT break_on_removal(VOID)
282 {
283 
284 UINT                     status;
285 UX_DEVICE               *device;
286 
287     if (cdc_acm_host_control != UX_NULL || cdc_acm_host_data != UX_NULL)
288         /* Do not break. */
289         return 0;
290 
291     if (cdc_acm_host_control1 != UX_NULL || cdc_acm_host_data1 != UX_NULL)
292         /* Do not break. */
293         return 0;
294 
295     if (cdc_acm_slave != UX_NULL || cdc_acm_slave1 != UX_NULL)
296         /* Do not break. */
297         return 0;
298 
299     return 1;
300 }
301 
test_host_change_function(ULONG event,UX_HOST_CLASS * cls,VOID * inst)302 static UINT test_host_change_function(ULONG event, UX_HOST_CLASS *cls, VOID *inst)
303 {
304 
305 UX_HOST_CLASS_CDC_ACM *cdc_acm = (UX_HOST_CLASS_CDC_ACM *) inst;
306 
307     switch(event)
308     {
309 
310         case UX_DEVICE_INSERTION:
311 
312             if (cdc_acm -> ux_host_class_cdc_acm_interface -> ux_interface_descriptor.bInterfaceClass == UX_HOST_CLASS_CDC_CONTROL_CLASS)
313             {
314                 if (cdc_acm_host_control == UX_NULL)
315                     cdc_acm_host_control = cdc_acm;
316                 else
317                     if (cdc_acm_host_control1 == UX_NULL)
318                         cdc_acm_host_control1 = cdc_acm;
319             }
320             else
321             {
322                 if (cdc_acm_host_data == UX_NULL)
323                     cdc_acm_host_data = cdc_acm;
324                 else
325                     if (cdc_acm_host_data1 == UX_NULL)
326                         cdc_acm_host_data1 = cdc_acm;
327             }
328             break;
329 
330         case UX_DEVICE_REMOVAL:
331 
332             if (cdc_acm -> ux_host_class_cdc_acm_interface -> ux_interface_descriptor.bInterfaceClass == UX_HOST_CLASS_CDC_CONTROL_CLASS)
333             {
334                 if (cdc_acm_host_control == cdc_acm)
335                     cdc_acm_host_control = UX_NULL;
336                 if (cdc_acm_host_control1 == cdc_acm)
337                     cdc_acm_host_control1 = UX_NULL;
338             }
339             else
340             {
341                 if (cdc_acm_host_data == cdc_acm)
342                     cdc_acm_host_data = UX_NULL;
343                 if (cdc_acm_host_data1 == cdc_acm)
344                     cdc_acm_host_data1 = UX_NULL;
345             }
346             break;
347 
348         default:
349             break;
350     }
351     return 0;
352 }
353 
test_cdc_instance_activate(VOID * cdc_instance)354 static VOID    test_cdc_instance_activate(VOID *cdc_instance)
355 {
356 
357     /* Save the CDC instance.  */
358     if (cdc_acm_slave == UX_NULL)
359         cdc_acm_slave = (UX_SLAVE_CLASS_CDC_ACM *) cdc_instance;
360     else
361     if (cdc_acm_slave1 == UX_NULL)
362         cdc_acm_slave1 =  (UX_SLAVE_CLASS_CDC_ACM *) cdc_instance;
363 }
test_cdc_instance_deactivate(VOID * cdc_instance)364 static VOID    test_cdc_instance_deactivate(VOID *cdc_instance)
365 {
366 
367     /* Reset the CDC instance.  */
368     if ((VOID *)cdc_acm_slave == cdc_instance)
369         cdc_acm_slave = UX_NULL;
370     if ((VOID *)cdc_acm_slave1 == cdc_instance)
371         cdc_acm_slave1 = UX_NULL;
372 }
373 
test_cdc_instance_parameter_change(VOID * cdc_instance)374 static VOID test_cdc_instance_parameter_change(VOID *cdc_instance)
375 {
376 
377     /* Set CDC parameter change flag. */
378     cdc_acm_slave_change = UX_TRUE;
379 }
380 
test_ux_error_callback(UINT system_level,UINT system_context,UINT error_code)381 static VOID test_ux_error_callback(UINT system_level, UINT system_context, UINT error_code)
382 {
383     error_callback_counter ++;
384 
385     if (!error_callback_ignore)
386     {
387         /* Ignore UX_DEVICE_HANDLE_UNKNOWN.  */
388         if (UX_DEVICE_HANDLE_UNKNOWN == error_code)
389             return;
390         {
391             /* Failed test.  */
392             printf("Error #%d, system_level: %d, system_context: %d, error_code: 0x%x\n", __LINE__, system_level, system_context, error_code);
393             // test_control_return(1);
394         }
395     }
396 }
397 
sleep_break_on_parameter_change(VOID)398 static UINT  sleep_break_on_parameter_change(VOID)
399 {
400 
401     /* Break if cdc_acm_slave_change is TRUE.  */
402     return(cdc_acm_slave_change);
403 }
404 
405 /* Define what the initial system looks like.  */
406 
407 #ifdef CTEST
test_application_define(void * first_unused_memory)408 void test_application_define(void *first_unused_memory)
409 #else
410 void usbx_test_USBX_142_application_define(void *first_unused_memory)
411 #endif
412 {
413 
414 UINT                    status;
415 CHAR *                  stack_pointer;
416 CHAR *                  memory_pointer;
417 ULONG                   test_n;
418 
419 ULONG                   mem_count;
420 ULONG                   sem_count;
421 ULONG                   thread_count;
422 
423     printf("Running USBX-142 device DTR callback Test........................... ");
424     stepinfo("\n");
425 
426     /* Initialize the free memory pointer */
427     stack_pointer = (CHAR *) usbx_memory;
428     memory_pointer = stack_pointer + (UX_DEMO_STACK_SIZE * 2);
429 
430     /* Initialize USBX Memory */
431     status = ux_system_initialize(memory_pointer, UX_DEMO_MEMORY_SIZE, UX_NULL, 0);
432     /* Check for error.  */
433     if (status != UX_SUCCESS)
434     {
435 
436         printf("ERROR #%d\n", __LINE__);
437         test_control_return(1);
438     }
439 
440     /* Register the error callback. */
441     _ux_utility_error_callback_register(test_ux_error_callback);
442 
443     /* The code below is required for installing the host portion of USBX */
444     status =  ux_host_stack_initialize(test_host_change_function);
445     if (status != UX_SUCCESS)
446     {
447 
448         printf("ERROR #%d\n", __LINE__);
449         test_control_return(1);
450     }
451 
452     /* Register CDC ACM class */
453     status =  ux_host_stack_class_register(_ux_system_host_class_cdc_acm_name, ux_host_class_cdc_acm_entry);
454     if (status != UX_SUCCESS)
455     {
456 
457         printf("ERROR #%d\n", __LINE__);
458         test_control_return(1);
459     }
460 
461     /* The code below is required for installing the device portion of USBX. No call back for
462        device status change in this example. */
463     status =  ux_device_stack_initialize(device_framework_high_speed, DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED,
464                                        device_framework_full_speed, DEVICE_FRAMEWORK_LENGTH_FULL_SPEED,
465                                        string_framework, STRING_FRAMEWORK_LENGTH,
466                                        language_id_framework, LANGUAGE_ID_FRAMEWORK_LENGTH,UX_NULL);
467     if(status!=UX_SUCCESS)
468     {
469 
470         printf("ERROR #%d\n", __LINE__);
471         test_control_return(1);
472     }
473 
474     /* Set the parameters for callback when insertion/extraction of a CDC device.  */
475     parameter.ux_slave_class_cdc_acm_instance_activate   =  test_cdc_instance_activate;
476     parameter.ux_slave_class_cdc_acm_instance_deactivate =  test_cdc_instance_deactivate;
477     parameter.ux_slave_class_cdc_acm_parameter_change    =  test_cdc_instance_parameter_change;
478 
479     /* Initialize the device cdc class. This class owns both interfaces starting with 0. */
480     status  =  ux_device_stack_class_register(_ux_system_slave_class_cdc_acm_name, ux_device_class_cdc_acm_entry,
481                                              1,0,  &parameter);
482     status |=  ux_device_stack_class_register(_ux_system_slave_class_cdc_acm_name, ux_device_class_cdc_acm_entry,
483                                              1,2,  &parameter);
484     status |=  ux_device_stack_class_register(_ux_system_slave_class_cdc_acm_name, ux_device_class_cdc_acm_entry,
485                                              1,4,  &parameter);
486 #if UX_MAX_SLAVE_CLASS_DRIVER > 1
487     if(status!=UX_SUCCESS)
488     {
489 
490         printf("ERROR #%d\n", __LINE__);
491         test_control_return(1);
492     }
493 #endif
494     /* Initialize the simulated device controller.  */
495     status =  _ux_test_dcd_sim_slave_initialize();
496 
497     /* Check for error.  */
498     if (status != TX_SUCCESS)
499     {
500 
501         printf("ERROR #%d\n", __LINE__);
502         test_control_return(1);
503     }
504 
505     /* Register HCD for test */
506     status =  ux_host_stack_hcd_register(_ux_system_host_hcd_simulator_name, _ux_test_hcd_sim_host_initialize,0,0);
507     if (status != UX_SUCCESS)
508     {
509 
510         printf("ERROR #%d\n", __LINE__);
511         test_control_return(1);
512     }
513 
514     /* Create the main host simulation thread.  */
515     status =  tx_thread_create(&tx_test_thread_host_simulation, "tx test host simulation", tx_test_thread_host_simulation_entry, 0,
516             stack_pointer, UX_DEMO_STACK_SIZE,
517             20, 20, 1, TX_AUTO_START);
518 
519     /* Check for error.  */
520     if (status != TX_SUCCESS)
521     {
522 
523         printf("ERROR #%d\n", __LINE__);
524         test_control_return(1);
525     }
526 
527     /* Create the main slave simulation  thread.  */
528     status =  tx_thread_create(&tx_test_thread_slave_simulation, "tx test slave simulation", tx_test_thread_slave_simulation_entry, 0,
529             stack_pointer + UX_DEMO_STACK_SIZE, UX_DEMO_STACK_SIZE,
530             20, 20, 1, TX_DONT_START);
531 
532     /* Check for error.  */
533     if (status != TX_SUCCESS)
534     {
535 
536         printf("ERROR #%d\n", __LINE__);
537         test_control_return(1);
538     }
539 }
540 
tx_test_thread_host_simulation_entry(ULONG arg)541 void  tx_test_thread_host_simulation_entry(ULONG arg)
542 {
543 
544 UINT                                                status;
545 UX_HOST_CLASS_CDC_ACM_LINE_STATE                    line_state;
546 UX_SLAVE_CLASS_CDC_ACM_LINE_STATE_PARAMETER         new_line_state;
547 
548 
549     /* Test connect. */
550     stepinfo(">>>>>>>>>>>>>>>> Test connect (FS)\n");
551     ux_test_hcd_sim_host_connect(UX_FULL_SPEED_DEVICE);
552     ux_test_breakable_sleep(500, break_on_cdc_acm_all_ready);
553     if (!(cdc_acm_host_control
554             && cdc_acm_host_data
555             && cdc_acm_slave
556 #if UX_MAX_SLAVE_CLASS_DRIVER > 1
557             && cdc_acm_host_control1
558             && cdc_acm_host_data1
559             && cdc_acm_slave1
560 #endif
561             ))
562     {
563 
564         printf("ERROR #%d: connect fail\n", __LINE__);
565         test_control_return(1);
566     }
567 
568     stepinfo(">>>>>>>>>>>>>>>> Test SET_LINE_STATE(DTR: true)\n");
569     line_state.ux_host_class_cdc_acm_line_state_dtr = UX_TRUE;
570     cdc_acm_slave_change = UX_FALSE;
571     status = ux_host_class_cdc_acm_ioctl(cdc_acm_host_control, UX_HOST_CLASS_CDC_ACM_IOCTL_SET_LINE_STATE, (VOID *)&line_state);
572     if (status != UX_SUCCESS)
573     {
574         printf("ERROR #%d: host_ioctl_set_line_state error 0x%x\n", __LINE__, status);
575         error_counter ++;
576     }
577     else if (cdc_acm_slave_change == UX_FALSE)
578     {
579         printf("ERROR #%d: no parameter change callback\n", __LINE__);
580         error_counter ++;
581     }
582     status = ux_device_class_cdc_acm_ioctl(cdc_acm_slave, UX_SLAVE_CLASS_CDC_ACM_IOCTL_GET_LINE_STATE, &new_line_state);
583     if (status != UX_SUCCESS)
584     {
585         printf("ERROR #%d: ioctl_get_line_state error 0x%x\n", __LINE__, status);
586         error_counter ++;
587     }
588     else if (new_line_state.ux_slave_class_cdc_acm_parameter_dtr != line_state.ux_host_class_cdc_acm_line_state_dtr)
589     {
590         printf("ERROR #%d: DTR not modified, still %d\n", __LINE__, new_line_state.ux_slave_class_cdc_acm_parameter_dtr);
591         error_counter ++;
592     }
593 
594     stepinfo(">>>>>>>>>>>>>>>> Test SET_LINE_STATE(DTR: false)\n");
595     line_state.ux_host_class_cdc_acm_line_state_dtr = UX_FALSE;
596     cdc_acm_slave_change = UX_FALSE;
597     status = ux_host_class_cdc_acm_ioctl(cdc_acm_host_control, UX_HOST_CLASS_CDC_ACM_IOCTL_SET_LINE_STATE, (VOID *)&line_state);
598     if (status != UX_SUCCESS)
599     {
600         printf("ERROR #%d: host_ioctl_set_line_state error 0x%x\n", __LINE__, status);
601         error_counter ++;
602     }
603     else if (cdc_acm_slave_change == UX_FALSE)
604     {
605         printf("ERROR #%d: no parameter change callback\n", __LINE__);
606         error_counter ++;
607     }
608     status = ux_device_class_cdc_acm_ioctl(cdc_acm_slave, UX_SLAVE_CLASS_CDC_ACM_IOCTL_GET_LINE_STATE, &new_line_state);
609     if (status != UX_SUCCESS)
610     {
611         printf("ERROR #%d: ioctl_get_line_state error 0x%x\n", __LINE__, status);
612         error_counter ++;
613     }
614     else if (new_line_state.ux_slave_class_cdc_acm_parameter_dtr != line_state.ux_host_class_cdc_acm_line_state_dtr)
615     {
616         printf("ERROR #%d: DTR not modified, still %d\n", __LINE__, new_line_state.ux_slave_class_cdc_acm_parameter_dtr);
617         error_counter ++;
618     }
619 
620     stepinfo(">>>>>>>>>>>>>>>> Test disconnect\n");
621     ux_test_dcd_sim_slave_disconnect();
622     ux_test_hcd_sim_host_disconnect();
623 
624     ux_test_breakable_sleep(100, break_on_removal);
625 
626     if (cdc_acm_host_control || cdc_acm_host_data || cdc_acm_slave)
627     {
628 
629         printf("ERROR #%d: disconnect fail\n", __LINE__);
630         test_control_return(1);
631     }
632 
633     stepinfo(">>>>>>>>>>>>>>>> Deinitialize\n");
634 
635     /* Deinitialize the class.  */
636     ux_device_stack_class_unregister(_ux_system_slave_class_cdc_acm_name, ux_device_class_cdc_acm_entry);
637     ux_device_stack_class_unregister(_ux_system_slave_class_cdc_acm_name, ux_device_class_cdc_acm_entry);
638     ux_device_stack_class_unregister(_ux_system_slave_class_cdc_acm_name, ux_device_class_cdc_acm_entry);
639 
640     /* Deinitialize the device side of usbx.  */
641     _ux_device_stack_uninitialize();
642 
643     /* And finally the usbx system resources.  */
644     _ux_system_uninitialize();
645 
646     stepinfo(">>>>>>>>>>>>>>>> Dump results\n");
647 
648     if (error_counter > 0)
649     {
650 
651         /* Test error.  */
652         printf("ERROR #%d: total %ld errors\n", __LINE__, error_counter);
653         test_control_return(1);
654     }
655 
656     /* Successful test.  */
657     printf("SUCCESS!\n");
658     test_control_return(0);
659 }
660 
tx_test_thread_slave_simulation_entry(ULONG arg)661 void  tx_test_thread_slave_simulation_entry(ULONG arg)
662 {
663 UINT  status;
664 ULONG actual_length;
665 
666     while(1)
667     {
668         switch (test_slave_code)
669         {
670         case 1:
671             stepinfo(">>>>>>>>>>>>>>>> Slave read START\n");
672             test_slave_state ++;
673             status = ux_device_class_cdc_acm_read(cdc_acm_slave, buffer, 256, &actual_length);
674             stepinfo(">>>>>>>>>>>>>>>> Slave read END\n");
675             if (status != UX_TRANSFER_BUS_RESET)
676             {
677                 printf("ERROR #%d: read not abort 0x%x\n", __LINE__, status);
678                 error_counter ++;
679             }
680             break;
681         case 2:
682             stepinfo(">>>>>>>>>>>>>>>> Slave write START\n");
683             test_slave_state ++;
684             status = ux_device_class_cdc_acm_write(cdc_acm_slave, buffer, 1024, &actual_length);
685             stepinfo(">>>>>>>>>>>>>>>> Slave write END\n");
686             if (status != UX_TRANSFER_BUS_RESET)
687             {
688                 printf("ERROR #%d: write not abort 0x%x\n", __LINE__, status);
689                 error_counter ++;
690             }
691             break;
692         default:
693             break;
694         }
695         test_slave_state = 0;
696         tx_thread_suspend(&tx_test_thread_slave_simulation);
697     }
698 }
699