1
10
11
12
13
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
190
191
192
193
199
200
201
202
203
207
208
209
210
211
212
213
220
221
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
269
270
271
272
273
274
275
276
277
278
279
280
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
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
...
...
#define UX_SOURCE_CODE
#include "ux_api.h"
#include "ux_device_class_cdc_acm.h"
#include "ux_device_stack.h"
...
...
UINT _ux_device_class_cdc_acm_ioctl(UX_SLAVE_CLASS_CDC_ACM *cdc_acm, ULONG ioctl_function,
VOID *parameter)
{
UINT status;
UX_SLAVE_CLASS_CDC_ACM_LINE_CODING_PARAMETER *line_coding;
UX_SLAVE_CLASS_CDC_ACM_LINE_STATE_PARAMETER *line_state;
#ifndef UX_DEVICE_CLASS_CDC_ACM_TRANSMISSION_DISABLE
UX_SLAVE_CLASS_CDC_ACM_CALLBACK_PARAMETER *callback;
#endif
UX_SLAVE_ENDPOINT *endpoint;
UX_SLAVE_INTERFACE *interface;
UX_SLAVE_TRANSFER *transfer_request;
status = UX_SUCCESS;
switch (ioctl_function)
{
case UX_SLAVE_CLASS_CDC_ACM_IOCTL_SET_LINE_CODING:
line_coding = (UX_SLAVE_CLASS_CDC_ACM_LINE_CODING_PARAMETER *) parameter;
cdc_acm -> ux_slave_class_cdc_acm_baudrate = line_coding -> ux_slave_class_cdc_acm_parameter_baudrate;
cdc_acm -> ux_slave_class_cdc_acm_stop_bit = line_coding -> ux_slave_class_cdc_acm_parameter_stop_bit;
cdc_acm -> ux_slave_class_cdc_acm_parity = line_coding -> ux_slave_class_cdc_acm_parameter_parity;
cdc_acm -> ux_slave_class_cdc_acm_data_bit = line_coding -> ux_slave_class_cdc_acm_parameter_data_bit;
break;
case UX_SLAVE_CLASS_CDC_ACM_IOCTL_SET_LINE_CODING:
case UX_SLAVE_CLASS_CDC_ACM_IOCTL_GET_LINE_CODING:
line_coding = (UX_SLAVE_CLASS_CDC_ACM_LINE_CODING_PARAMETER *) parameter;
line_coding -> ux_slave_class_cdc_acm_parameter_baudrate = cdc_acm -> ux_slave_class_cdc_acm_baudrate;
line_coding -> ux_slave_class_cdc_acm_parameter_stop_bit = cdc_acm -> ux_slave_class_cdc_acm_stop_bit;
line_coding -> ux_slave_class_cdc_acm_parameter_parity = cdc_acm -> ux_slave_class_cdc_acm_parity;
line_coding -> ux_slave_class_cdc_acm_parameter_data_bit = cdc_acm -> ux_slave_class_cdc_acm_data_bit;
break;
case UX_SLAVE_CLASS_CDC_ACM_IOCTL_GET_LINE_CODING:
case UX_SLAVE_CLASS_CDC_ACM_IOCTL_GET_LINE_STATE:
line_state = (UX_SLAVE_CLASS_CDC_ACM_LINE_STATE_PARAMETER *) parameter;
line_state -> ux_slave_class_cdc_acm_parameter_rts = cdc_acm -> ux_slave_class_cdc_acm_data_rts_state;
line_state -> ux_slave_class_cdc_acm_parameter_dtr = cdc_acm -> ux_slave_class_cdc_acm_data_dtr_state;
break;
case UX_SLAVE_CLASS_CDC_ACM_IOCTL_GET_LINE_STATE:
case UX_SLAVE_CLASS_CDC_ACM_IOCTL_SET_LINE_STATE:
line_state = (UX_SLAVE_CLASS_CDC_ACM_LINE_STATE_PARAMETER *) parameter;
cdc_acm -> ux_slave_class_cdc_acm_data_rts_state = line_state -> ux_slave_class_cdc_acm_parameter_rts;
cdc_acm -> ux_slave_class_cdc_acm_data_dtr_state = line_state -> ux_slave_class_cdc_acm_parameter_dtr;
break;
case UX_SLAVE_CLASS_CDC_ACM_IOCTL_SET_LINE_STATE:
case UX_SLAVE_CLASS_CDC_ACM_IOCTL_ABORT_PIPE:
interface = cdc_acm -> ux_slave_class_cdc_acm_interface;
endpoint = interface -> ux_slave_interface_first_endpoint;
switch( (ULONG) (ALIGN_TYPE) parameter)
{
case UX_SLAVE_CLASS_CDC_ACM_ENDPOINT_XMIT :
if ((endpoint -> ux_slave_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) != UX_ENDPOINT_IN)
{
endpoint = endpoint -> ux_slave_endpoint_next_endpoint;
}if ((endpoint -> ux_slave_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) != UX_ENDPOINT_IN) { ... }
break;
case UX_SLAVE_CLASS_CDC_ACM_ENDPOINT_XMIT :
case UX_SLAVE_CLASS_CDC_ACM_ENDPOINT_RCV :
if ((endpoint -> ux_slave_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) != UX_ENDPOINT_OUT)
{
endpoint = endpoint -> ux_slave_endpoint_next_endpoint;
}if ((endpoint -> ux_slave_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) != UX_ENDPOINT_OUT) { ... }
break;
case UX_SLAVE_CLASS_CDC_ACM_ENDPOINT_RCV :
default :
status = UX_ENDPOINT_HANDLE_UNKNOWN;default
}switch ((ULONG) (ALIGN_TYPE) parameter) { ... }
transfer_request = &endpoint -> ux_slave_endpoint_transfer_request;
#if defined(UX_DEVICE_STANDALONE)
_ux_device_stack_transfer_abort(transfer_request, UX_TRANSFER_STATUS_ABORT);
if ((ULONG) (ALIGN_TYPE) parameter == UX_SLAVE_CLASS_CDC_ACM_ENDPOINT_XMIT)
cdc_acm -> ux_device_class_cdc_acm_write_state = UX_STATE_RESET;
else
cdc_acm -> ux_device_class_cdc_acm_read_state = UX_STATE_RESET;/* ... */
#else
if (transfer_request -> ux_slave_transfer_request_status == UX_TRANSFER_STATUS_PENDING)
{
_ux_device_stack_transfer_abort(transfer_request, UX_ABORTED);
}if (transfer_request -> ux_slave_transfer_request_status == UX_TRANSFER_STATUS_PENDING) { ... }
/* ... */#endif
break;
case UX_SLAVE_CLASS_CDC_ACM_IOCTL_ABORT_PIPE:
case UX_SLAVE_CLASS_CDC_ACM_IOCTL_SET_READ_TIMEOUT:
case UX_SLAVE_CLASS_CDC_ACM_IOCTL_SET_WRITE_TIMEOUT:
interface = cdc_acm -> ux_slave_class_cdc_acm_interface;
endpoint = interface -> ux_slave_interface_first_endpoint;
if ((endpoint -> ux_slave_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) !=
(ULONG)((ioctl_function == UX_SLAVE_CLASS_CDC_ACM_IOCTL_SET_READ_TIMEOUT) ? UX_ENDPOINT_OUT : UX_ENDPOINT_IN))
endpoint = endpoint -> ux_slave_endpoint_next_endpoint;
transfer_request = &endpoint -> ux_slave_endpoint_transfer_request;
if (transfer_request -> ux_slave_transfer_request_status == UX_TRANSFER_STATUS_PENDING)
status = UX_ERROR;
else
transfer_request -> ux_slave_transfer_request_timeout = (ULONG) (ALIGN_TYPE) parameter;
break;
#ifndef UX_DEVICE_CLASS_CDC_ACM_TRANSMISSION_DISABLE
case UX_SLAVE_CLASS_CDC_ACM_IOCTL_TRANSMISSION_START:
if (cdc_acm -> ux_slave_class_cdc_acm_transmission_status == UX_TRUE)
{
return(UX_ERROR);
}if (cdc_acm -> ux_slave_class_cdc_acm_transmission_status == UX_TRUE) { ... }
callback = (UX_SLAVE_CLASS_CDC_ACM_CALLBACK_PARAMETER *) parameter;
cdc_acm -> ux_device_class_cdc_acm_write_callback = callback -> ux_device_class_cdc_acm_parameter_write_callback;
cdc_acm -> ux_device_class_cdc_acm_read_callback = callback -> ux_device_class_cdc_acm_parameter_read_callback;
#if !defined(UX_DEVICE_STANDALONE)
_ux_utility_thread_resume(&cdc_acm -> ux_slave_class_cdc_acm_bulkin_thread);
_ux_utility_thread_resume(&cdc_acm -> ux_slave_class_cdc_acm_bulkout_thread);/* ... */
#endif
cdc_acm -> ux_slave_class_cdc_acm_transmission_status = UX_TRUE;
return(UX_SUCCESS);
case UX_SLAVE_CLASS_CDC_ACM_IOCTL_TRANSMISSION_START:
case UX_SLAVE_CLASS_CDC_ACM_IOCTL_TRANSMISSION_STOP:
if (cdc_acm -> ux_slave_class_cdc_acm_transmission_status == UX_TRUE)
{
interface = cdc_acm -> ux_slave_class_cdc_acm_interface;
endpoint = interface -> ux_slave_interface_first_endpoint;
transfer_request = &endpoint -> ux_slave_endpoint_transfer_request;
_ux_device_stack_transfer_abort(transfer_request, UX_ABORTED);
endpoint = endpoint -> ux_slave_endpoint_next_endpoint;
transfer_request = &endpoint -> ux_slave_endpoint_transfer_request;
_ux_device_stack_transfer_abort(transfer_request, UX_ABORTED);
#if !defined(UX_DEVICE_STANDALONE)
_ux_device_thread_suspend(&cdc_acm -> ux_slave_class_cdc_acm_bulkin_thread);
_ux_device_thread_suspend(&cdc_acm -> ux_slave_class_cdc_acm_bulkout_thread);/* ... */
#endif
cdc_acm -> ux_slave_class_cdc_acm_scheduled_write = UX_FALSE;
cdc_acm -> ux_slave_class_cdc_acm_transmission_status = UX_FALSE;
}if (cdc_acm -> ux_slave_class_cdc_acm_transmission_status == UX_TRUE) { ... }
else
return(UX_ERROR);
break; /* ... */
#endif
default:
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_FUNCTION_NOT_SUPPORTED);
UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_FUNCTION_NOT_SUPPORTED, 0, 0, 0, UX_TRACE_ERRORS, 0, 0)
status = UX_FUNCTION_NOT_SUPPORTED;default
}switch (ioctl_function) { ... }
return(status);
}{ ... }