Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
...
#define UX_SOURCE_CODE
#include "ux_api.h"
#include "ux_device_stack.h"
...
...
_ux_device_stack_configuration_set(ULONG)
Files
loading...
CodeScopeSTM32 Libraries and Samplesusbxcommon/core/src/ux_device_stack_configuration_set.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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* 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 */ /** */ /** Device Stack */ /** */... /**************************************************************************/ /**************************************************************************/ #define UX_SOURCE_CODE /* Include necessary system files. */ #include "ux_api.h" #include "ux_device_stack.h" ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _ux_device_stack_configuration_set PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function sets the configuration from the host and will enable */ /* the default alternate setting 0 for all the interfaces attached to */ /* this configuration. */ /* */ /* INPUT */ /* */ /* endpoint Pointer to endpoint */ /* configuration_value Configuration selected */ /* */ /* OUTPUT */ /* */ /* Completion Status */ /* */ /* CALLS */ /* */ /* (ux_slave_class_entry_function) Device class entry function */ /* (ux_slave_dcd_function) DCD dispatch function */ /* _ux_device_stack_interface_delete Delete interface */ /* _ux_device_stack_interface_set Set interface */ /* _ux_utility_descriptor_parse Parse descriptor */ /* */ /* CALLED BY */ /* */ /* Application */ /* Device Stack */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ /* optimized based on compile */ /* definitions, */ /* resulting in version 6.1 */ /* */... /**************************************************************************/ UINT _ux_device_stack_configuration_set(ULONG configuration_value) { UX_SLAVE_DCD *dcd; UCHAR * device_framework; ULONG device_framework_length; ULONG descriptor_length; UCHAR descriptor_type; UX_CONFIGURATION_DESCRIPTOR configuration_descriptor = { 0 }; UX_INTERFACE_DESCRIPTOR interface_descriptor; UX_SLAVE_INTERFACE *interface; #if !defined(UX_DEVICE_INITIALIZE_FRAMEWORK_SCAN_DISABLE) || UX_MAX_DEVICE_INTERFACES > 1 UX_SLAVE_INTERFACE *next_interface; #endif UX_SLAVE_CLASS *class_inst; UX_SLAVE_CLASS *current_class = UX_NULL; UX_SLAVE_CLASS_COMMAND class_command; UX_SLAVE_DEVICE *device; ULONG iad_flag; ULONG iad_first_interface = 0; ULONG iad_number_interfaces = 0; #if UX_MAX_SLAVE_CLASS_DRIVER > 1 ULONG class_index; #endif /* If trace is enabled, insert this event into the trace buffer. */ UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_STACK_CONFIGURATION_SET, configuration_value, 0, 0, 0, UX_TRACE_DEVICE_STACK_EVENTS, 0, 0) /* Get the pointer to the DCD. */ dcd = &_ux_system_slave -> ux_system_slave_dcd; /* Get the pointer to the device. */ device = &_ux_system_slave -> ux_system_slave_device; /* Reset the IAD flag. */ iad_flag = UX_FALSE; /* If the configuration value is already selected, keep it. */ if (device -> ux_slave_device_configuration_selected == configuration_value) return(UX_SUCCESS); /* We may have multiple configurations !, the index will tell us what configuration descriptor we need to return. *//* ... */ device_framework = _ux_system_slave -> ux_system_slave_device_framework; device_framework_length = _ux_system_slave -> ux_system_slave_device_framework_length; /* Parse the device framework and locate a configuration descriptor. */ while (device_framework_length != 0) { /* Get the length of the current descriptor. */ descriptor_length = (ULONG) *device_framework; /* And its type. */ descriptor_type = *(device_framework + 1); /* Check if this is a configuration descriptor. */ if (descriptor_type == UX_CONFIGURATION_DESCRIPTOR_ITEM) { /* Parse the descriptor in something more readable. */ _ux_utility_descriptor_parse(device_framework, _ux_system_configuration_descriptor_structure, UX_CONFIGURATION_DESCRIPTOR_ENTRIES, (UCHAR *) &configuration_descriptor); /* Now we need to check the configuration value. It has to be the same as the one specified in the setup function. *//* ... */ if (configuration_descriptor.bConfigurationValue == configuration_value) /* The configuration is found. */ break; }if (descriptor_type == UX_CONFIGURATION_DESCRIPTOR_ITEM) { ... } /* Adjust what is left of the device framework. */ device_framework_length -= descriptor_length; /* Point to the next descriptor. */ device_framework += descriptor_length; }while (device_framework_length != 0) { ... } /* Configuration not found. */ if (device_framework_length == 0 && configuration_value != 0) return(UX_ERROR); /* We unmount the configuration if there is previous configuration selected. */ if (device -> ux_slave_device_configuration_selected) { /* Get the pointer to the first interface. */ interface = device -> ux_slave_device_first_interface; #if !defined(UX_DEVICE_INITIALIZE_FRAMEWORK_SCAN_DISABLE) || UX_MAX_DEVICE_INTERFACES > 1 /* Deactivate all the interfaces if any. */ while (interface != UX_NULL) { #endif /* Build all the fields of the Class Command. */ class_command.ux_slave_class_command_request = UX_SLAVE_CLASS_COMMAND_DEACTIVATE; class_command.ux_slave_class_command_interface = (VOID *) interface; /* Get the pointer to the class container of this interface. */ class_inst = interface -> ux_slave_interface_class; /* Store the class container. */ class_command.ux_slave_class_command_class_ptr = class_inst; /* If there is a class container for this instance, deactivate it. */ if (class_inst != UX_NULL) /* Call the class with the DEACTIVATE signal. */ class_inst -> ux_slave_class_entry_function(&class_command); #if !defined(UX_DEVICE_INITIALIZE_FRAMEWORK_SCAN_DISABLE) || UX_MAX_DEVICE_INTERFACES > 1 /* Get the next interface. */ next_interface = interface -> ux_slave_interface_next_interface;/* ... */ #endif /* Remove the interface and all endpoints associated with it. */ _ux_device_stack_interface_delete(interface); #if !defined(UX_DEVICE_INITIALIZE_FRAMEWORK_SCAN_DISABLE) || UX_MAX_DEVICE_INTERFACES > 1 /* Now we refresh the interface pointer. */ interface = next_interface; }/* ... */ while (interface != UX_NULL) { ... }#endif }if (device -> ux_slave_device_configuration_selected) { ... } /* No configuration is selected. */ device -> ux_slave_device_configuration_selected = 0; /* Mark the device as attached now. */ device -> ux_slave_device_state = UX_DEVICE_ATTACHED; /* The DCD needs to update the device state too. */ dcd -> ux_slave_dcd_function(dcd, UX_DCD_CHANGE_STATE, (VOID *) UX_DEVICE_ATTACHED); /* If the host tries to unconfigure, we are done. */ if (configuration_value == 0) return(UX_SUCCESS); /* Memorize the configuration selected. */ device -> ux_slave_device_configuration_selected = configuration_value; /* We have found the configuration value requested by the host. Create the configuration descriptor and attach it to the device. *//* ... */ _ux_utility_descriptor_parse(device_framework, _ux_system_configuration_descriptor_structure, UX_CONFIGURATION_DESCRIPTOR_ENTRIES, (UCHAR *) &device -> ux_slave_device_configuration_descriptor); /* Configuration character D6 is for Self-powered */ _ux_system_slave -> ux_system_slave_power_state = (configuration_descriptor.bmAttributes & 0x40) ? UX_DEVICE_SELF_POWERED : UX_DEVICE_BUS_POWERED; /* Configuration character D5 is for Remote Wakeup */ _ux_system_slave -> ux_system_slave_remote_wakeup_capability = (configuration_descriptor.bmAttributes & 0x20) ? UX_TRUE : UX_FALSE; /* Search only in current configuration */ device_framework_length = configuration_descriptor.wTotalLength; /* We need to scan all the interface descriptors following this configuration descriptor and enable all endpoints associated with the default alternate setting of each interface. *//* ... */ while (device_framework_length != 0) { /* Get the length of the current descriptor. */ descriptor_length = (ULONG) *device_framework; /* And its type. */ descriptor_type = *(device_framework + 1); /* Check if this is an interface association descriptor. */ if(descriptor_type == UX_INTERFACE_ASSOCIATION_DESCRIPTOR_ITEM) { /* Set the IAD flag. */ iad_flag = UX_TRUE; /* Get the first interface we have in the IAD. */ iad_first_interface = (ULONG) *(device_framework + 2); /* Get the number of interfaces we have in the IAD. */ iad_number_interfaces = (ULONG) *(device_framework + 3); }if (descriptor_type == UX_INTERFACE_ASSOCIATION_DESCRIPTOR_ITEM) { ... } /* Check if this is an interface descriptor. */ if(descriptor_type == UX_INTERFACE_DESCRIPTOR_ITEM) { /* Parse the descriptor in something more readable. */ _ux_utility_descriptor_parse(device_framework, _ux_system_interface_descriptor_structure, UX_INTERFACE_DESCRIPTOR_ENTRIES, (UCHAR *) &interface_descriptor); /* If the alternate setting is 0 for this interface, we need to memorize its class association and start it. *//* ... */ if (interface_descriptor.bAlternateSetting == 0) { /* Are we in a IAD scenario ? */ if (iad_flag == UX_TRUE) { /* Check if this is the first interface from the IAD. In this case, we need to match a class to this interface. *//* ... */ if (interface_descriptor.bInterfaceNumber == iad_first_interface) { /* First interface. Scan the list of classes to find a match. */ class_inst = _ux_system_slave -> ux_system_slave_class_array; #if UX_MAX_SLAVE_CLASS_DRIVER > 1 /* Parse all the class drivers. */ for (class_index = 0; class_index < _ux_system_slave -> ux_system_slave_max_class; class_index++) { #endif /* Check if this class driver is used. */ if (class_inst -> ux_slave_class_status == UX_USED) { /* Check if this is the same interface for the same configuration. */ if ((interface_descriptor.bInterfaceNumber == class_inst -> ux_slave_class_interface_number) && (configuration_value == class_inst -> ux_slave_class_configuration_number)) { /* Memorize the class in the class/interface array. */ _ux_system_slave -> ux_system_slave_interface_class_array[interface_descriptor.bInterfaceNumber] = class_inst; /* And again as the current class. */ current_class = class_inst; #if UX_MAX_SLAVE_CLASS_DRIVER > 1 /* We are done here. */ break;/* ... */ #endif }if ((interface_descriptor.bInterfaceNumber == class_inst -> ux_slave_class_interface_number) && (configuration_value == class_inst -> ux_slave_class_configuration_number)) { ... } }if (class_inst -> ux_slave_class_status == UX_USED) { ... } #if UX_MAX_SLAVE_CLASS_DRIVER > 1 /* Move to the next registered class. */ class_inst ++; }/* ... */ for (class_index = 0; class_index < _ux_system_slave -> ux_system_slave_max_class; class_index++) { ... }#endif }if (interface_descriptor.bInterfaceNumber == iad_first_interface) { ... } else /* Memorize the class in the class/interface array. We use the current class. */ _ux_system_slave -> ux_system_slave_interface_class_array[interface_descriptor.bInterfaceNumber] = current_class; /* Decrement the number of interfaces found in the same IAD. */ iad_number_interfaces--; /* If none are left, get out of the IAD state machine. */ if (iad_number_interfaces == 0) /* We have exhausted the interfaces within the IAD. */ iad_flag = UX_FALSE; }if (iad_flag == UX_TRUE) { ... } else { /* First interface. Scan the list of classes to find a match. */ class_inst = _ux_system_slave -> ux_system_slave_class_array; #if UX_MAX_SLAVE_CLASS_DRIVER > 1 /* Parse all the class drivers. */ for (class_index = 0; class_index < _ux_system_slave -> ux_system_slave_max_class; class_index++) { #endif /* Check if this class driver is used. */ if (class_inst -> ux_slave_class_status == UX_USED) { /* Check if this is the same interface for the same configuration. */ if ((interface_descriptor.bInterfaceNumber == class_inst -> ux_slave_class_interface_number) && (configuration_value == class_inst -> ux_slave_class_configuration_number)) { /* Memorize the class in the class/interface array. */ _ux_system_slave -> ux_system_slave_interface_class_array[interface_descriptor.bInterfaceNumber] = class_inst; #if UX_MAX_SLAVE_CLASS_DRIVER > 1 /* We are done here. */ break;/* ... */ #endif }if ((interface_descriptor.bInterfaceNumber == class_inst -> ux_slave_class_interface_number) && (configuration_value == class_inst -> ux_slave_class_configuration_number)) { ... } }if (class_inst -> ux_slave_class_status == UX_USED) { ... } #if UX_MAX_SLAVE_CLASS_DRIVER > 1 /* Move to the next registered class. */ class_inst ++; }/* ... */ for (class_index = 0; class_index < _ux_system_slave -> ux_system_slave_max_class; class_index++) { ... }#endif }else { ... } /* Set the interface. */ _ux_device_stack_interface_set(device_framework, device_framework_length, 0); }if (interface_descriptor.bAlternateSetting == 0) { ... } }if (descriptor_type == UX_INTERFACE_DESCRIPTOR_ITEM) { ... } /* Adjust what is left of the device framework. */ device_framework_length -= descriptor_length; /* Point to the next descriptor. */ device_framework += descriptor_length; }while (device_framework_length != 0) { ... } /* Mark the device as configured now. */ device -> ux_slave_device_state = UX_DEVICE_CONFIGURED; /* The DCD needs to update the device state too. */ dcd -> ux_slave_dcd_function(dcd, UX_DCD_CHANGE_STATE, (VOID *) UX_DEVICE_CONFIGURED); /* Configuration mounted. */ return(UX_SUCCESS); }{ ... }