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"
...
...
_ux_host_class_cdc_acm_ioctl(UX_HOST_CLASS_CDC_ACM *, ULONG, void *)
Files
loading...
CodeScopeSTM32 Libraries and Samplesusbxcommon/usbx_host_classes/src/ux_host_class_cdc_acm_ioctl.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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* 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 */ /** */ /** CDC ACM 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" ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _ux_host_class_cdc_acm_ioctl PORTABLE C */ /* 6.1.10 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function is the ioctl entry point for the application to */ /* configure the ACM device. */ /* */ /* */ /* INPUT */ /* */ /* acm Pointer to acm class */ /* ioctl_function ioctl function */ /* parameter pointer to structure */ /* */ /* OUTPUT */ /* */ /* Completion Status */ /* */ /* CALLS */ /* */ /* _ux_host_stack_endpoint_transfer_abort */ /* Abort transfer */ /* _ux_host_class_cdc_acm_command Send command to acm device */ /* _ux_utility_memory_allocate Allocate memory */ /* _ux_utility_memory_free Free memory */ /* _ux_utility_long_put Put 32-bit value */ /* */ /* CALLED BY */ /* */ /* Storage 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_ioctl(UX_HOST_CLASS_CDC_ACM *cdc_acm, ULONG ioctl_function, VOID *parameter) { UINT status; UCHAR *data_buffer; UX_HOST_CLASS_CDC_ACM_LINE_CODING *line_coding; UX_HOST_CLASS_CDC_ACM_LINE_STATE *line_state; VOID (*callback_function) (struct UX_HOST_CLASS_CDC_ACM_STRUCT *, ULONG, ULONG ); ULONG value; #if defined(UX_HOST_STANDALONE) VOID (*write_callback_function) (struct UX_HOST_CLASS_CDC_ACM_STRUCT *, UINT, ULONG ); UX_TRANSFER *transfer;/* ... */ #endif /* Ensure the instance is valid. */ if ((cdc_acm -> ux_host_class_cdc_acm_state != UX_HOST_CLASS_INSTANCE_LIVE) && (cdc_acm -> ux_host_class_cdc_acm_state != UX_HOST_CLASS_INSTANCE_MOUNTING)) { /* If trace is enabled, insert this event into the trace buffer. */ UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, cdc_acm, 0, 0, UX_TRACE_ERRORS, 0, 0) return(UX_HOST_CLASS_INSTANCE_UNKNOWN); }if ((cdc_acm -> ux_host_class_cdc_acm_state != UX_HOST_CLASS_INSTANCE_LIVE) && (cdc_acm -> ux_host_class_cdc_acm_state != UX_HOST_CLASS_INSTANCE_MOUNTING)) { ... } /* The command request will tell us what we need to do here. */ switch (ioctl_function) { case UX_HOST_CLASS_CDC_ACM_IOCTL_SET_LINE_CODING: /* If trace is enabled, insert this event into the trace buffer. */ UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_CDC_ACM_IOCTL_SET_LINE_CODING, cdc_acm, parameter, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0) /* Allocate some cache safe memory for the control command. */ data_buffer = _ux_utility_memory_allocate(UX_SAFE_ALIGN, UX_CACHE_SAFE_MEMORY, UX_HOST_CLASS_CDC_ACM_LINE_CODING_LENGTH); /* Check if error. Return with error if no memory could be allocated. */ if (data_buffer == UX_NULL) /* Do not proceed. Set error code. */ status = UX_MEMORY_INSUFFICIENT; else { /* Build the buffer from the calling parameter. Cast the calling parameter. */ line_coding = (UX_HOST_CLASS_CDC_ACM_LINE_CODING *) parameter; /* Put the data rate. */ _ux_utility_long_put(data_buffer + UX_HOST_CLASS_CDC_ACM_LINE_CODING_RATE, line_coding -> ux_host_class_cdc_acm_line_coding_dter); /* Then the stop bit. */ *(data_buffer + UX_HOST_CLASS_CDC_ACM_LINE_CODING_STOP_BIT) = (UCHAR) line_coding -> ux_host_class_cdc_acm_line_coding_stop_bit; /* Then the parity. */ *(data_buffer + UX_HOST_CLASS_CDC_ACM_LINE_CODING_PARITY) = (UCHAR) line_coding -> ux_host_class_cdc_acm_line_coding_parity; /* Finally the data bits. */ *(data_buffer + UX_HOST_CLASS_CDC_ACM_LINE_CODING_DATA_BIT) = (UCHAR) line_coding -> ux_host_class_cdc_acm_line_coding_data_bits; /* Send the command to the device. */ status = _ux_host_class_cdc_acm_command(cdc_acm, UX_HOST_CLASS_CDC_ACM_REQ_SET_LINE_CODING, 0, data_buffer, UX_HOST_CLASS_CDC_ACM_LINE_CODING_LENGTH); /* We free the resources allocated no matter what. */ _ux_utility_memory_free(data_buffer); }else { ... } break; case UX_HOST_CLASS_CDC_ACM_IOCTL_SET_LINE_CODING: case UX_HOST_CLASS_CDC_ACM_IOCTL_GET_LINE_CODING: /* If trace is enabled, insert this event into the trace buffer. */ UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_CDC_ACM_IOCTL_GET_LINE_CODING, cdc_acm, parameter, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0) /* Allocate some cache safe memory for the control command. */ data_buffer = _ux_utility_memory_allocate(UX_SAFE_ALIGN, UX_CACHE_SAFE_MEMORY, UX_HOST_CLASS_CDC_ACM_LINE_CODING_LENGTH); /* Check if error. Return with error if no memory could be allocated. */ if (data_buffer == UX_NULL) /* Do not proceed. Set error code. */ status = UX_MEMORY_INSUFFICIENT; else { /* Send the command to the device. */ status = _ux_host_class_cdc_acm_command(cdc_acm, UX_HOST_CLASS_CDC_ACM_REQ_GET_LINE_CODING, 0, data_buffer, UX_HOST_CLASS_CDC_ACM_LINE_CODING_LENGTH); /* Fill in the calling buffer if the result is successful. */ if (status == UX_SUCCESS) { /* Build the buffer from the calling parameter. Cast the calling parameter. */ line_coding = (UX_HOST_CLASS_CDC_ACM_LINE_CODING *) parameter; /* Get the data rate. */ line_coding -> ux_host_class_cdc_acm_line_coding_dter = _ux_utility_long_get(data_buffer + UX_HOST_CLASS_CDC_ACM_LINE_CODING_RATE); /* Then the stop bit. */ line_coding -> ux_host_class_cdc_acm_line_coding_stop_bit = (ULONG) *(data_buffer + UX_HOST_CLASS_CDC_ACM_LINE_CODING_STOP_BIT); /* Then the parity. */ line_coding -> ux_host_class_cdc_acm_line_coding_parity = (ULONG) *(data_buffer + UX_HOST_CLASS_CDC_ACM_LINE_CODING_PARITY); /* Finally the data bits. */ line_coding -> ux_host_class_cdc_acm_line_coding_data_bits = (ULONG) *(data_buffer + UX_HOST_CLASS_CDC_ACM_LINE_CODING_DATA_BIT); }if (status == UX_SUCCESS) { ... } /* We free the resources allocated no matter what. */ _ux_utility_memory_free(data_buffer); }else { ... } break; case UX_HOST_CLASS_CDC_ACM_IOCTL_GET_LINE_CODING: case UX_HOST_CLASS_CDC_ACM_IOCTL_SET_LINE_STATE: /* If trace is enabled, insert this event into the trace buffer. */ UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_CDC_ACM_IOCTL_SET_LINE_STATE, cdc_acm, parameter, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0) /* Cast the calling parameter. */ line_state = (UX_HOST_CLASS_CDC_ACM_LINE_STATE *) parameter; /* Build the value field. */ value = (line_state -> ux_host_class_cdc_acm_line_state_dtr | (line_state -> ux_host_class_cdc_acm_line_state_rts << 1)); /* Send the command to the device. */ status = _ux_host_class_cdc_acm_command(cdc_acm, UX_HOST_CLASS_CDC_ACM_REQ_SET_LINE_STATE, value, UX_NULL,0); break; case UX_HOST_CLASS_CDC_ACM_IOCTL_SET_LINE_STATE: case UX_HOST_CLASS_CDC_ACM_IOCTL_SEND_BREAK : /* If trace is enabled, insert this event into the trace buffer. */ UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_CDC_ACM_IOCTL_SEND_BREAK, cdc_acm, parameter, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0) /* Build the value field. */ value = *((ULONG *) parameter); /* Send the command to the device. */ status = _ux_host_class_cdc_acm_command(cdc_acm, UX_HOST_CLASS_CDC_ACM_REQ_SEND_BREAK, value, UX_NULL,0); break; case UX_HOST_CLASS_CDC_ACM_IOCTL_SEND_BREAK : case UX_HOST_CLASS_CDC_ACM_IOCTL_ABORT_IN_PIPE : /* If trace is enabled, insert this event into the trace buffer. */ UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_CDC_ACM_IOCTL_ABORT_IN_PIPE, cdc_acm, cdc_acm -> ux_host_class_cdc_acm_bulk_in_endpoint, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0) /* We need to abort transactions on the bulk In pipe. */ _ux_host_stack_endpoint_transfer_abort(cdc_acm -> ux_host_class_cdc_acm_bulk_in_endpoint); /* Status is successful. */ status = UX_SUCCESS; break; case UX_HOST_CLASS_CDC_ACM_IOCTL_ABORT_IN_PIPE : case UX_HOST_CLASS_CDC_ACM_IOCTL_ABORT_OUT_PIPE : /* If trace is enabled, insert this event into the trace buffer. */ UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_CDC_ACM_IOCTL_ABORT_OUT_PIPE, cdc_acm, cdc_acm -> ux_host_class_cdc_acm_bulk_out_endpoint, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0) /* We need to abort transactions on the bulk Out pipe. */ _ux_host_stack_endpoint_transfer_abort(cdc_acm -> ux_host_class_cdc_acm_bulk_out_endpoint); #if defined(UX_HOST_STANDALONE) /* Reset write state. */ cdc_acm -> ux_host_class_cdc_acm_write_state = UX_STATE_RESET;/* ... */ #endif /* Status is successful. */ status = UX_SUCCESS; break; case UX_HOST_CLASS_CDC_ACM_IOCTL_ABORT_OUT_PIPE : case UX_HOST_CLASS_CDC_ACM_IOCTL_NOTIFICATION_CALLBACK : /* If trace is enabled, insert this event into the trace buffer. */ UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_CDC_ACM_IOCTL_NOTIFICATION_CALLBACK, cdc_acm, parameter, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0) /* Register a callback when the line state has changed. */ callback_function = ((VOID (*) (struct UX_HOST_CLASS_CDC_ACM_STRUCT *, ULONG, ULONG )) (ALIGN_TYPE)parameter); cdc_acm -> ux_host_class_cdc_acm_device_status_change_callback = callback_function; /* Status is successful. */ status = UX_SUCCESS; break; case UX_HOST_CLASS_CDC_ACM_IOCTL_NOTIFICATION_CALLBACK : case UX_HOST_CLASS_CDC_ACM_IOCTL_GET_DEVICE_STATUS : /* If trace is enabled, insert this event into the trace buffer. */ UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_CDC_ACM_IOCTL_GET_DEVICE_STATUS, cdc_acm, cdc_acm -> ux_host_class_cdc_acm_device_state, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0) /* Return the device status. */ *((ULONG *) parameter) = cdc_acm -> ux_host_class_cdc_acm_device_state; /* Status is successful. */ status = UX_SUCCESS; break; #if defined(UX_HOST_STANDALONE)case UX_HOST_CLASS_CDC_ACM_IOCTL_GET_DEVICE_STATUS : case UX_HOST_CLASS_CDC_ACM_IOCTL_WRITE_CALLBACK: /* Register a callback when write is done. */ write_callback_function = ((VOID (*) (struct UX_HOST_CLASS_CDC_ACM_STRUCT *, UINT, ULONG )) (ALIGN_TYPE)parameter); cdc_acm -> ux_host_class_cdc_acm_write_callback = write_callback_function; /* Status is successful. */ status = UX_SUCCESS; break; case UX_HOST_CLASS_CDC_ACM_IOCTL_WRITE_CALLBACK: case UX_HOST_CLASS_CDC_ACM_IOCTL_GET_WRITE_STATUS: /* Check write state. */ if (cdc_acm -> ux_host_class_cdc_acm_write_state == UX_STATE_WAIT) { status = UX_BUSY; }if (cdc_acm -> ux_host_class_cdc_acm_write_state == UX_STATE_WAIT) { ... } else { /* Get transfer for write. */ transfer = &cdc_acm -> ux_host_class_cdc_acm_bulk_out_endpoint -> ux_endpoint_transfer_request; /* Status is from transfer completion code. */ status = transfer -> ux_transfer_request_completion_code; /* Actual length is from latest write count. */ *(ULONG *)parameter = cdc_acm -> ux_host_class_cdc_acm_write_count; }else { ... } break;/* ... */ #endif 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) /* Function not supported. Return an error. */ status = UX_FUNCTION_NOT_SUPPORTED;default }switch (ioctl_function) { ... } /* Return status to caller. */ return(status); }{ ... }