Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
...
#define UX_SOURCE_CODE
#include "ux_api.h"
#include "ux_host_class_cdc_acm.h"
#include "ux_host_stack.h"
#define UX_HOST_CLASS_CDC_ACM_INIT_TRANSFER_WAIT
#define UX_HOST_CLASS_CDC_ACM_INIT_DESCRIPTORS_PARSE
#define UX_HOST_CLASS_CDC_ACM_INIT_DELAY_WAIT
#define UX_HOST_CLASS_CDC_ACM_INIT_LINE_CODING_SET
#define UX_HOST_CLASS_CDC_ACM_INIT_LINE_CODING_GET
#define UX_HOST_CLASS_CDC_ACM_INIT_LINE_CODING_CHECK
#define UX_HOST_CLASS_CDC_ACM_INIT_LINE_STATE_SET
#define UX_HOST_CLASS_CDC_ACM_INIT_ERROR
#define UX_HOST_CLASS_CDC_ACM_INIT_DONE
...
...
_ux_host_class_cdc_acm_entry(UX_HOST_CLASS_COMMAND *)
Files
loading...
CodeScopeSTM32 Libraries and Samplesusbxcommon/usbx_host_classes/src/ux_host_class_cdc_acm_entry.c
 
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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* Copyright (c) Microsoft Corporation. All rights reserved. */ /* */ /* This software is licensed under the Microsoft Software License */ /* Terms for Microsoft Azure RTOS. Full text of the license can be */ /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ /* and in the root directory of this software. */ /* */... /**************************************************************************/ ... /**************************************************************************/ /**************************************************************************/ /** */ /** USBX Component */ /** */ /** Acm Cdc Class */ /** */... /**************************************************************************/ /**************************************************************************/ /* Include necessary system files. */ #define UX_SOURCE_CODE #include "ux_api.h" #include "ux_host_class_cdc_acm.h" #include "ux_host_stack.h" #if defined(UX_HOST_STANDALONE) #define UX_HOST_CLASS_CDC_ACM_INIT_TRANSFER_WAIT (UX_STATE_WAIT) #define UX_HOST_CLASS_CDC_ACM_INIT_DESCRIPTORS_PARSE (UX_STATE_NEXT) #define UX_HOST_CLASS_CDC_ACM_INIT_DELAY_WAIT (UX_STATE_CLASS_STEP + 0) #define UX_HOST_CLASS_CDC_ACM_INIT_LINE_CODING_SET (UX_STATE_CLASS_STEP + 1) #define UX_HOST_CLASS_CDC_ACM_INIT_LINE_CODING_GET (UX_STATE_CLASS_STEP + 2) #define UX_HOST_CLASS_CDC_ACM_INIT_LINE_CODING_CHECK (UX_STATE_CLASS_STEP + 3) #define UX_HOST_CLASS_CDC_ACM_INIT_LINE_STATE_SET (UX_STATE_CLASS_STEP + 4) #define UX_HOST_CLASS_CDC_ACM_INIT_ERROR (UX_STATE_CLASS_STEP + 5) #define UX_HOST_CLASS_CDC_ACM_INIT_DONE (UX_STATE_CLASS_STEP + 6) 9 defines static inline UINT _ux_host_class_cdc_acm_activate_wait(UX_HOST_CLASS_COMMAND *command);/* ... */ #endif ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _ux_host_class_cdc_acm_entry PORTABLE C */ /* 6.1.10 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function is the entry point of the cdc_acm class. It will be */ /* called by the USBX stack enumeration module when there is a new */ /* cdc_acm on the bus or when the USB cdc_acm is removed. */ /* */ /* A CDC class can have multiple interfaces, one for Control and one */ /* for Data. Here we filter for the Communication Class with ACM */ /* subclass and the Communication Data Class. */ /* */ /* */ /* INPUT */ /* */ /* command Acm Cdc class command */ /* */ /* OUTPUT */ /* */ /* Completion Status */ /* */ /* CALLS */ /* */ /* _ux_host_class_cdc_acm_activate Activate cdc_acm class */ /* _ux_host_class_cdc_acm_deactivate Deactivate cdc_acm class */ /* */ /* CALLED BY */ /* */ /* Acm Cdc Class */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ /* resulting in version 6.1 */ /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */ /* added standalone support, */ /* resulting in version 6.1.10 */ /* */... /**************************************************************************/ UINT _ux_host_class_cdc_acm_entry(UX_HOST_CLASS_COMMAND *command) { UINT status; /* The command request will tell us we need to do here, either a enumeration query, an activation or a deactivation. *//* ... */ switch (command -> ux_host_class_command_request) { case UX_HOST_CLASS_COMMAND_QUERY: /* The query command is used to let the stack enumeration process know if we want to own this device or not. *//* ... */ if((command -> ux_host_class_command_usage == UX_HOST_CLASS_COMMAND_USAGE_CSP) && ((command -> ux_host_class_command_class == UX_HOST_CLASS_CDC_DATA_CLASS) || ((command -> ux_host_class_command_class == UX_HOST_CLASS_CDC_CONTROL_CLASS) && (command -> ux_host_class_command_subclass == UX_HOST_CLASS_CDC_ACM_SUBCLASS)) || ((command -> ux_host_class_command_class == UX_HOST_CLASS_CDC_CONTROL_CLASS) && (command -> ux_host_class_command_subclass == UX_HOST_CLASS_CDC_DLC_SUBCLASS)))) { /* Check for IAD presence. */ if ((command -> ux_host_class_command_iad_class == 0) && (command -> ux_host_class_command_iad_subclass == 0)) /* No IAD, we accept this class. */ return(UX_SUCCESS); else { if ((command -> ux_host_class_command_iad_class == UX_HOST_CLASS_CDC_CONTROL_CLASS) && (command -> ux_host_class_command_iad_subclass == UX_HOST_CLASS_CDC_ACM_SUBCLASS)) /* There is an IAD and this is for CDC-ACM. */ return(UX_SUCCESS); else /* The IAD does not match with CDC-ACM. */ return(UX_NO_CLASS_MATCH); }else { ... } }if ((command -> ux_host_class_command_usage == UX_HOST_CLASS_COMMAND_USAGE_CSP) && ((command -> ux_host_class_command_class == UX_HOST_CLASS_CDC_DATA_CLASS) || ((command -> ux_host_class_command_class == UX_HOST_CLASS_CDC_CONTROL_CLASS) && (command -> ux_host_class_command_subclass == UX_HOST_CLASS_CDC_ACM_SUBCLASS)) || ((command -> ux_host_class_command_class == UX_HOST_CLASS_CDC_CONTROL_CLASS) && (command -> ux_host_class_command_subclass == UX_HOST_CLASS_CDC_DLC_SUBCLASS)))) { ... } else /* No match. */ return(UX_NO_CLASS_MATCH); case UX_HOST_CLASS_COMMAND_QUERY: case UX_HOST_CLASS_COMMAND_ACTIVATE: /* The activate command is used when the device inserted has found a parent and is ready to complete the enumeration. *//* ... */ status = _ux_host_class_cdc_acm_activate(command); return(status); #if defined(UX_HOST_STANDALONE)case UX_HOST_CLASS_COMMAND_ACTIVATE: case UX_HOST_CLASS_COMMAND_ACTIVATE_WAIT: status = _ux_host_class_cdc_acm_activate_wait(command); return(status);/* ... */ #endif case UX_HOST_CLASS_COMMAND_ACTIVATE_WAIT: case UX_HOST_CLASS_COMMAND_DEACTIVATE: /* The deactivate command is used when the device has been extracted either directly or when its parents has been extracted. *//* ... */ status = _ux_host_class_cdc_acm_deactivate(command); return(status); case UX_HOST_CLASS_COMMAND_DEACTIVATE: default: /* Error trap. */ _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_FUNCTION_NOT_SUPPORTED); /* If trace is enabled, insert this event into the trace buffer. */ UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_FUNCTION_NOT_SUPPORTED, 0, 0, 0, UX_TRACE_ERRORS, 0, 0) return(UX_FUNCTION_NOT_SUPPORTED);default }switch (command -> ux_host_class_command_request) { ... } }{ ... } #if defined(UX_HOST_STANDALONE) static inline VOID _ux_host_class_cdc_acm_descriptors_parse(UX_HOST_CLASS_CDC_ACM *cdc_acm) { UX_ENDPOINT *control_endpoint; UX_TRANSFER *transfer_request; UX_INTERFACE *interface; UCHAR *descriptor; ULONG total_descriptor_length; UCHAR descriptor_length; UCHAR descriptor_type; UCHAR descriptor_byte2; ULONG interface_found; ULONG interface_parsed; UCHAR offset; /* 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; /* Check if transfer is done success. */ if (transfer_request -> ux_transfer_request_completion_code != UX_SUCCESS || transfer_request -> ux_transfer_request_actual_length != transfer_request -> ux_transfer_request_requested_length) { cdc_acm -> ux_host_class_cdc_acm_status = UX_DESCRIPTOR_CORRUPTED; cdc_acm -> ux_host_class_cdc_acm_cmd_state = UX_HOST_CLASS_CDC_ACM_INIT_ERROR; return; }if (transfer_request -> ux_transfer_request_completion_code != UX_SUCCESS || transfer_request -> ux_transfer_request_actual_length != transfer_request -> ux_transfer_request_requested_length) { ... } /* Get the interface. */ interface = cdc_acm -> ux_host_class_cdc_acm_interface; /* Parse the descriptor. */ total_descriptor_length = transfer_request -> ux_transfer_request_actual_length; descriptor = (UCHAR *)cdc_acm -> ux_host_class_cdc_acm_allocated; interface_found = UX_FALSE; interface_parsed = UX_FALSE; while(total_descriptor_length) { /* Get descriptor length, type, subtype. */ descriptor_length = *descriptor; descriptor_type = *(descriptor + 1); descriptor_byte2 = *(descriptor + 2); /* Make sure this descriptor has at least the minimum length. */ if (descriptor_length < 3 || descriptor_length > total_descriptor_length) { /* Descriptor is corrupted. */ break; }if (descriptor_length < 3 || descriptor_length > total_descriptor_length) { ... } /* Process related descriptors. */ switch(descriptor_type) { case UX_INTERFACE_DESCRIPTOR_ITEM: /* Check if interface is what we expected. */ if (interface -> ux_interface_descriptor.bInterfaceNumber == descriptor_byte2) { /* Mark found. */ interface_found = UX_TRUE; }if (interface -> ux_interface_descriptor.bInterfaceNumber == descriptor_byte2) { ... } else { /* Run out of expected interface. */ if (interface_found) { interface_parsed = UX_TRUE; }if (interface_found) { ... } }else { ... } break; case UX_INTERFACE_DESCRIPTOR_ITEM: case UX_HOST_CLASS_CDC_ACM_CS_INTERFACE: /* Check if we are in correct interface. */ if (interface_found) { /* Check bDescriptorSubType. */ switch(descriptor_byte2) { case UX_HOST_CLASS_CDC_ACM_CALL_MANAGEMENT_DESCRIPTOR: /* Store capabilities. */ cdc_acm -> ux_host_class_cdc_acm_capabilities = *(descriptor + UX_HOST_CLASS_CDC_ACM_CALL_MANAGEMENT_CAPABILITIES); break; case UX_HOST_CLASS_CDC_ACM_CALL_MANAGEMENT_DESCRIPTOR: case UX_HOST_CLASS_CDC_ACM_UNION_DESCRIPTOR: /* Check related interfaces. */ for (offset = UX_HOST_CLASS_CDC_ACM_UNION_FUNCTIONAL_MASTER; offset < descriptor_length; offset ++) { /* Save the interface in interface bitmap. */ cdc_acm -> ux_host_class_cdc_acm_interfaces_bitmap |= 1u << *(descriptor + offset); }for (offset = UX_HOST_CLASS_CDC_ACM_UNION_FUNCTIONAL_MASTER; offset < descriptor_length; offset ++) { ... } break; case UX_HOST_CLASS_CDC_ACM_UNION_DESCRIPTOR: default: break;default }switch (descriptor_byte2) { ... } }if (interface_found) { ... } break; case UX_HOST_CLASS_CDC_ACM_CS_INTERFACE: default: break;default }switch (descriptor_type) { ... } /* Next descriptor. */ descriptor += descriptor_length; total_descriptor_length -= descriptor_length; }while (total_descriptor_length) { ... } /* We can free the resource now. */ _ux_utility_memory_free(cdc_acm -> ux_host_class_cdc_acm_allocated); cdc_acm -> ux_host_class_cdc_acm_allocated = UX_NULL; /* Descriptor fail. */ if (interface_parsed == UX_FALSE) { /* Error trap. */ _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_DESCRIPTOR_CORRUPTED); /* If trace is enabled, insert this event into the trace buffer. */ UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_DESCRIPTOR_CORRUPTED, descriptor, 0, 0, UX_TRACE_ERRORS, 0, 0) /* Descriptor is corrupted. */ cdc_acm -> ux_host_class_cdc_acm_status = UX_DESCRIPTOR_CORRUPTED; cdc_acm -> ux_host_class_cdc_acm_cmd_state = UX_HOST_CLASS_CDC_ACM_INIT_ERROR; return; }if (interface_parsed == UX_FALSE) { ... } /* Descriptor is parsed. */ cdc_acm -> ux_host_class_cdc_acm_tick = _ux_utility_time_get(); cdc_acm -> ux_host_class_cdc_acm_cmd_state = UX_HOST_CLASS_CDC_ACM_INIT_DELAY_WAIT; }_ux_host_class_cdc_acm_descriptors_parse (UX_HOST_CLASS_CDC_ACM *cdc_acm) { ... } static inline UINT _ux_host_class_cdc_acm_activate_wait(UX_HOST_CLASS_COMMAND *command) { UX_HOST_CLASS *cdc_acm_class; UX_HOST_CLASS_CDC_ACM *cdc_acm_inst; UX_INTERFACE *interface; UX_HOST_CLASS_CDC_ACM *cdc_acm; UX_ENDPOINT *control_endpoint; UX_TRANSFER *transfer; UCHAR *buffer; ULONG rate, stop_bit, parity, data_bit; UINT status; ULONG tick, diff; /* Get the instance for this class. */ interface = (UX_INTERFACE *)command -> ux_host_class_command_container; cdc_acm = (UX_HOST_CLASS_CDC_ACM *) interface -> ux_interface_class_instance; /* Run initialize state machine. */ switch(cdc_acm -> ux_host_class_cdc_acm_cmd_state) { case UX_HOST_CLASS_CDC_ACM_INIT_DESCRIPTORS_PARSE: _ux_host_class_cdc_acm_descriptors_parse(cdc_acm); break; case UX_HOST_CLASS_CDC_ACM_INIT_DESCRIPTORS_PARSE: case UX_HOST_CLASS_CDC_ACM_INIT_DELAY_WAIT: tick = _ux_utility_time_get(); diff = _ux_utility_time_elapsed(cdc_acm -> ux_host_class_cdc_acm_tick, tick); if (diff > UX_MS_TO_TICK(UX_HOST_CLASS_CDC_ACM_DEVICE_INIT_DELAY)) { /* Allocate some buffer for commands. */ cdc_acm -> ux_host_class_cdc_acm_allocated = _ux_utility_memory_allocate(UX_SAFE_ALIGN, UX_CACHE_SAFE_MEMORY, 8); if (cdc_acm -> ux_host_class_cdc_acm_allocated == UX_NULL) { cdc_acm -> ux_host_class_cdc_acm_status = UX_MEMORY_INSUFFICIENT; cdc_acm -> ux_host_class_cdc_acm_cmd_state = UX_HOST_CLASS_CDC_ACM_INIT_ERROR; break; }if (cdc_acm -> ux_host_class_cdc_acm_allocated == UX_NULL) { ... } control_endpoint = &cdc_acm -> ux_host_class_cdc_acm_device -> ux_device_control_endpoint; transfer = &control_endpoint -> ux_endpoint_transfer_request; /* Initialize transfer buffer. */ transfer -> ux_transfer_request_data_pointer = (UCHAR *) cdc_acm -> ux_host_class_cdc_acm_allocated; /* Initialize transfer flags. */ transfer -> ux_transfer_request_flags = 0; cdc_acm -> ux_host_class_cdc_acm_cmd_state = UX_HOST_CLASS_CDC_ACM_INIT_LINE_CODING_SET; }if (diff > UX_MS_TO_TICK(UX_HOST_CLASS_CDC_ACM_DEVICE_INIT_DELAY)) { ... } break; case UX_HOST_CLASS_CDC_ACM_INIT_DELAY_WAIT: case UX_HOST_CLASS_CDC_ACM_INIT_LINE_CODING_SET: /* Put line coding things in buffer. */ buffer = (UCHAR *)cdc_acm -> ux_host_class_cdc_acm_allocated; rate = UX_HOST_CLASS_CDC_ACM_LINE_CODING_DEFAULT_RATE; stop_bit = UX_HOST_CLASS_CDC_ACM_LINE_CODING_DEFAULT_STOP_BIT; parity = UX_HOST_CLASS_CDC_ACM_LINE_CODING_DEFAULT_PARITY; data_bit = UX_HOST_CLASS_CDC_ACM_LINE_CODING_DEFAULT_DATA_BIT; _ux_utility_long_put(buffer + UX_HOST_CLASS_CDC_ACM_LINE_CODING_RATE, rate); *(buffer + UX_HOST_CLASS_CDC_ACM_LINE_CODING_STOP_BIT) = (UCHAR)stop_bit; *(buffer + UX_HOST_CLASS_CDC_ACM_LINE_CODING_PARITY) = (UCHAR)parity; *(buffer + UX_HOST_CLASS_CDC_ACM_LINE_CODING_DATA_BIT) = (UCHAR)data_bit; status = _ux_host_class_cdc_acm_command(cdc_acm, UX_HOST_CLASS_CDC_ACM_REQ_SET_LINE_CODING, 0, buffer, UX_HOST_CLASS_CDC_ACM_LINE_CODING_LENGTH); if (status != UX_SUCCESS) { cdc_acm -> ux_host_class_cdc_acm_status = status; cdc_acm -> ux_host_class_cdc_acm_cmd_state = UX_HOST_CLASS_CDC_ACM_INIT_ERROR; break; }if (status != UX_SUCCESS) { ... } cdc_acm -> ux_host_class_cdc_acm_cmd_state = UX_HOST_CLASS_CDC_ACM_INIT_TRANSFER_WAIT; cdc_acm -> ux_host_class_cdc_acm_next_state = UX_HOST_CLASS_CDC_ACM_INIT_LINE_CODING_GET; break; case UX_HOST_CLASS_CDC_ACM_INIT_LINE_CODING_SET: case UX_HOST_CLASS_CDC_ACM_INIT_LINE_CODING_GET: /* Get line coding things from device. */ buffer = (UCHAR *)cdc_acm -> ux_host_class_cdc_acm_allocated; status = _ux_host_class_cdc_acm_command(cdc_acm, UX_HOST_CLASS_CDC_ACM_REQ_GET_LINE_CODING, 0, buffer, UX_HOST_CLASS_CDC_ACM_LINE_CODING_LENGTH); if (status != UX_SUCCESS) { cdc_acm -> ux_host_class_cdc_acm_status = status; cdc_acm -> ux_host_class_cdc_acm_cmd_state = UX_HOST_CLASS_CDC_ACM_INIT_ERROR; break; }if (status != UX_SUCCESS) { ... } cdc_acm -> ux_host_class_cdc_acm_cmd_state = UX_HOST_CLASS_CDC_ACM_INIT_TRANSFER_WAIT; cdc_acm -> ux_host_class_cdc_acm_next_state = UX_HOST_CLASS_CDC_ACM_INIT_LINE_CODING_CHECK; break; case UX_HOST_CLASS_CDC_ACM_INIT_LINE_CODING_GET: case UX_HOST_CLASS_CDC_ACM_INIT_LINE_CODING_CHECK: /* Check line coding things in buffer. */ buffer = (UCHAR *)cdc_acm -> ux_host_class_cdc_acm_allocated; rate = _ux_utility_long_get(buffer + UX_HOST_CLASS_CDC_ACM_LINE_CODING_RATE); stop_bit = *(buffer + UX_HOST_CLASS_CDC_ACM_LINE_CODING_STOP_BIT); parity = *(buffer + UX_HOST_CLASS_CDC_ACM_LINE_CODING_PARITY); data_bit = *(buffer + UX_HOST_CLASS_CDC_ACM_LINE_CODING_DATA_BIT); if (rate != UX_HOST_CLASS_CDC_ACM_LINE_CODING_DEFAULT_RATE || stop_bit != UX_HOST_CLASS_CDC_ACM_LINE_CODING_DEFAULT_STOP_BIT || parity != UX_HOST_CLASS_CDC_ACM_LINE_CODING_DEFAULT_PARITY || data_bit != UX_HOST_CLASS_CDC_ACM_LINE_CODING_DEFAULT_DATA_BIT) { cdc_acm -> ux_host_class_cdc_acm_status = UX_DEVICE_ENUMERATION_FAILURE; cdc_acm -> ux_host_class_cdc_acm_cmd_state = UX_HOST_CLASS_CDC_ACM_INIT_ERROR; break; }if (rate != UX_HOST_CLASS_CDC_ACM_LINE_CODING_DEFAULT_RATE || stop_bit != UX_HOST_CLASS_CDC_ACM_LINE_CODING_DEFAULT_STOP_BIT || parity != UX_HOST_CLASS_CDC_ACM_LINE_CODING_DEFAULT_PARITY || data_bit != UX_HOST_CLASS_CDC_ACM_LINE_CODING_DEFAULT_DATA_BIT) { ... } /* Fall through. */case UX_HOST_CLASS_CDC_ACM_INIT_LINE_CODING_CHECK: case UX_HOST_CLASS_CDC_ACM_INIT_LINE_STATE_SET: /* Put line state things. */ buffer = (UCHAR *)cdc_acm -> ux_host_class_cdc_acm_allocated; *(buffer) = UX_HOST_CLASS_CDC_ACM_CTRL_DTR | UX_HOST_CLASS_CDC_ACM_CTRL_RTS; status = _ux_host_class_cdc_acm_command(cdc_acm, UX_HOST_CLASS_CDC_ACM_REQ_SET_LINE_STATE, *(buffer), UX_NULL, 0); if (status != UX_SUCCESS) { cdc_acm -> ux_host_class_cdc_acm_status = status; cdc_acm -> ux_host_class_cdc_acm_cmd_state = UX_HOST_CLASS_CDC_ACM_INIT_ERROR; break; }if (status != UX_SUCCESS) { ... } cdc_acm -> ux_host_class_cdc_acm_cmd_state = UX_HOST_CLASS_CDC_ACM_INIT_TRANSFER_WAIT; cdc_acm -> ux_host_class_cdc_acm_next_state = UX_HOST_CLASS_CDC_ACM_INIT_DONE; break; case UX_HOST_CLASS_CDC_ACM_INIT_LINE_STATE_SET: case UX_HOST_CLASS_CDC_ACM_INIT_ERROR: /* Fall through. */case UX_HOST_CLASS_CDC_ACM_INIT_ERROR: case UX_HOST_CLASS_CDC_ACM_INIT_DONE: /* Free allocated buffer. */ if (cdc_acm -> ux_host_class_cdc_acm_allocated) { _ux_utility_memory_free(cdc_acm -> ux_host_class_cdc_acm_allocated); cdc_acm -> ux_host_class_cdc_acm_allocated = UX_NULL; }if (cdc_acm -> ux_host_class_cdc_acm_allocated) { ... } /* Check status. */ if (cdc_acm -> ux_host_class_cdc_acm_status == UX_SUCCESS) { /* We scan CDC ACM instances to find the DATA instance. */ /* Get class. */ cdc_acm_class = cdc_acm -> ux_host_class_cdc_acm_class; /* Get first instance linked to the class. */ cdc_acm_inst = (UX_HOST_CLASS_CDC_ACM *)cdc_acm_class -> ux_host_class_first_instance; /* Scan all instances. */ while(cdc_acm_inst) { /* Get interface of the instance. */ interface = cdc_acm_inst -> ux_host_class_cdc_acm_interface; /* If this data interface is inside the associate list, link it. */ if (cdc_acm -> ux_host_class_cdc_acm_interfaces_bitmap & (1ul << interface -> ux_interface_descriptor.bInterfaceNumber)) { /* Save control instance and we are done. */ cdc_acm_inst -> ux_host_class_cdc_acm_control = cdc_acm; break; }if (cdc_acm -> ux_host_class_cdc_acm_interfaces_bitmap & (1ul << interface -> ux_interface_descriptor.bInterfaceNumber)) { ... } /* Next instance. */ cdc_acm_inst = cdc_acm_inst -> ux_host_class_cdc_acm_next_instance; }while (cdc_acm_inst) { ... } /* Mark the cdc_acm as live now. Both interfaces need to be live. */ cdc_acm -> ux_host_class_cdc_acm_state = UX_HOST_CLASS_INSTANCE_LIVE; /* If all is fine and the device is mounted, we may need to inform the application if a function has been programmed in the system structure. *//* ... */ if (_ux_system_host -> ux_system_host_change_function != UX_NULL) { /* Call system change function. */ _ux_system_host -> ux_system_host_change_function(UX_DEVICE_INSERTION, cdc_acm -> ux_host_class_cdc_acm_class, (VOID *) cdc_acm); }if (_ux_system_host -> ux_system_host_change_function != UX_NULL) { ... } /* If trace is enabled, insert this event into the trace buffer. */ UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_CDC_ACM_ACTIVATE, cdc_acm, 0, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0) /* If trace is enabled, register this object. */ UX_TRACE_OBJECT_REGISTER(UX_TRACE_HOST_OBJECT_TYPE_INTERFACE, cdc_acm, 0, 0, 0) /* Reset CMD state. */ cdc_acm -> ux_host_class_cdc_acm_cmd_state = UX_STATE_RESET; }if (cdc_acm -> ux_host_class_cdc_acm_status == UX_SUCCESS) { ... } else { /* On error case, it's possible data buffer allocated for interrupt endpoint and transfer started, stop and free it. */ if (cdc_acm -> ux_host_class_cdc_acm_interrupt_endpoint && cdc_acm -> ux_host_class_cdc_acm_interrupt_endpoint -> ux_endpoint_transfer_request.ux_transfer_request_data_pointer) { /* The first transfer request has already been initiated. Abort it. */ _ux_host_stack_endpoint_transfer_abort(cdc_acm -> ux_host_class_cdc_acm_interrupt_endpoint); /* Free the memory for the data pointer. */ _ux_utility_memory_free(cdc_acm -> ux_host_class_cdc_acm_interrupt_endpoint -> ux_endpoint_transfer_request.ux_transfer_request_data_pointer); }if (cdc_acm -> ux_host_class_cdc_acm_interrupt_endpoint && cdc_acm -> ux_host_class_cdc_acm_interrupt_endpoint -> ux_endpoint_transfer_request.ux_transfer_request_data_pointer) { ... } /* Destroy the instance. */ _ux_host_stack_class_instance_destroy(cdc_acm -> ux_host_class_cdc_acm_class, (VOID *) cdc_acm); /* Unmount instance. */ interface = cdc_acm -> ux_host_class_cdc_acm_interface; interface -> ux_interface_class_instance = UX_NULL; /* Free instance. */ _ux_utility_memory_free(cdc_acm); }else { ... } /* Done, OK to go on. */ return(UX_STATE_NEXT); case UX_HOST_CLASS_CDC_ACM_INIT_DONE: case UX_HOST_CLASS_CDC_ACM_INIT_TRANSFER_WAIT: /* Get transfer. */ control_endpoint = &cdc_acm -> ux_host_class_cdc_acm_device -> ux_device_control_endpoint; transfer = &control_endpoint -> ux_endpoint_transfer_request; /* Transfer state machine. */ status = _ux_host_stack_transfer_run(transfer); /* Is it done? */ if (status <= UX_STATE_NEXT) { /* Is there error? */ if (transfer -> ux_transfer_request_completion_code != UX_SUCCESS) { cdc_acm -> ux_host_class_cdc_acm_cmd_state = UX_STATE_EXIT; break; }if (transfer -> ux_transfer_request_completion_code != UX_SUCCESS) { ... } /* No error, next state. */ cdc_acm -> ux_host_class_cdc_acm_cmd_state = cdc_acm -> ux_host_class_cdc_acm_next_state; break; }if (status <= UX_STATE_NEXT) { ... } /* Keep waiting. */ break; /* UX_STATE_RESET, UX_STATE_EXIT, UX_STATE_IDLE, ... */case UX_HOST_CLASS_CDC_ACM_INIT_TRANSFER_WAIT: default: /* Do nothing. */ return(UX_STATE_NEXT);default }switch (cdc_acm -> ux_host_class_cdc_acm_cmd_state) { ... } /* Keep waiting. */ return(UX_STATE_WAIT); }_ux_host_class_cdc_acm_activate_wait (UX_HOST_CLASS_COMMAND *command) { ... } /* ... */#endif...