1
10
13
14
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
136
137
138
140
141
142
143
144
145
146
147
148
149
150
151
152
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
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
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
284
285
286
287
288
289
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
363
364
365
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
387
388
389
390
391
392
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
417
418
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
...
...
...
#define UX_SOURCE_CODE
#include "ux_api.h"
#include "ux_device_stack.h"
...
...
UINT _ux_device_stack_alternate_setting_set(ULONG interface_value, ULONG alternate_setting_value)
{
UX_SLAVE_DEVICE *device;
UX_SLAVE_INTERFACE *interface;
#if !defined(UX_DEVICE_ALTERNATE_SETTING_SUPPORT_DISABLE)
UX_SLAVE_DCD *dcd;
UX_SLAVE_TRANSFER *transfer_request;
UCHAR *device_framework;
ULONG device_framework_length;
ULONG descriptor_length;
UCHAR descriptor_type;
UX_CONFIGURATION_DESCRIPTOR configuration_descriptor;
UX_INTERFACE_DESCRIPTOR interface_descriptor;
UX_SLAVE_ENDPOINT *endpoint;
UX_SLAVE_ENDPOINT *next_endpoint;
UX_SLAVE_ENDPOINT *endpoint_link;
ULONG endpoints_pool_number;
UX_SLAVE_CLASS_COMMAND class_command;
UX_SLAVE_CLASS *class;
UINT status;
ULONG max_transfer_length, n_trans;/* ... */
#endif
UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_STACK_ALTERNATE_SETTING_SET, interface_value, alternate_setting_value, 0, 0, UX_TRACE_DEVICE_STACK_EVENTS, 0, 0)
device = &_ux_system_slave -> ux_system_slave_device;
if (device -> ux_slave_device_state != UX_DEVICE_CONFIGURED)
return(UX_FUNCTION_NOT_SUPPORTED);
interface = device -> ux_slave_device_first_interface;
#if !defined(UX_DEVICE_INITIALIZE_FRAMEWORK_SCAN_DISABLE) || UX_MAX_DEVICE_INTERFACES > 1
while (interface != UX_NULL)
{
if (interface -> ux_slave_interface_descriptor.bInterfaceNumber == interface_value)
break;
else
interface = interface -> ux_slave_interface_next_interface;
}while (interface != UX_NULL) { ... }
/* ... */#else
if (interface -> ux_slave_interface_descriptor.bInterfaceNumber != interface_value)
interface = UX_NULL;/* ... */
#endif
/* ... */
if (interface == UX_NULL)
{
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_INTERFACE_HANDLE_UNKNOWN);
UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_INTERFACE_HANDLE_UNKNOWN, interface, 0, 0, UX_TRACE_ERRORS, 0, 0)
return(UX_INTERFACE_HANDLE_UNKNOWN);
}if (interface == UX_NULL) { ... }
/* ... */
if (interface -> ux_slave_interface_descriptor.bAlternateSetting == alternate_setting_value)
return(UX_SUCCESS);
#if defined(UX_DEVICE_ALTERNATE_SETTING_SUPPORT_DISABLE)
_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, interface, 0, 0, UX_TRACE_ERRORS, 0, 0)
return(UX_FUNCTION_NOT_SUPPORTED);/* ... */
#else
dcd = &_ux_system_slave->ux_system_slave_dcd;
device_framework = _ux_system_slave -> ux_system_slave_device_framework;
device_framework_length = _ux_system_slave -> ux_system_slave_device_framework_length;
while (device_framework_length != 0)
{
descriptor_length = (ULONG) *device_framework;
descriptor_type =* (device_framework + 1);
if (descriptor_type == UX_CONFIGURATION_DESCRIPTOR_ITEM)
{
_ux_utility_descriptor_parse(device_framework,
_ux_system_configuration_descriptor_structure,
UX_CONFIGURATION_DESCRIPTOR_ENTRIES,
(UCHAR *) &configuration_descriptor);
if (configuration_descriptor.bConfigurationValue == device -> ux_slave_device_configuration_selected)
{
device_framework_length = configuration_descriptor.wTotalLength;
/* ... */
while (device_framework_length != 0)
{
descriptor_length = (ULONG) *device_framework;
descriptor_type = *(device_framework + 1);
if (descriptor_type == UX_INTERFACE_DESCRIPTOR_ITEM)
{
_ux_utility_descriptor_parse(device_framework,
_ux_system_interface_descriptor_structure,
UX_INTERFACE_DESCRIPTOR_ENTRIES,
(UCHAR *) &interface_descriptor);
if (interface_descriptor.bInterfaceNumber == interface_value &&
interface_descriptor.bAlternateSetting == alternate_setting_value)
{
/* ... */
endpoint = interface -> ux_slave_interface_first_endpoint;
while (endpoint != UX_NULL)
{
_ux_device_stack_transfer_all_request_abort(endpoint, UX_TRANSFER_BUS_RESET);
dcd -> ux_slave_dcd_function(dcd, UX_DCD_DESTROY_ENDPOINT, (VOID *) endpoint);
next_endpoint = endpoint -> ux_slave_endpoint_next_endpoint;
endpoint -> ux_slave_endpoint_status = UX_UNUSED;
endpoint -> ux_slave_endpoint_state = 0;
endpoint -> ux_slave_endpoint_next_endpoint = UX_NULL;
endpoint -> ux_slave_endpoint_interface = UX_NULL;
endpoint -> ux_slave_endpoint_device = UX_NULL;
endpoint = next_endpoint;
}while (endpoint != UX_NULL) { ... }
interface -> ux_slave_interface_first_endpoint = UX_NULL;
device_framework_length -= (ULONG) *device_framework;
device_framework += (ULONG) *device_framework;
while (device_framework_length != 0)
{
descriptor_length = (ULONG) *device_framework;
descriptor_type = *(device_framework + 1);
switch(descriptor_type)
{
case UX_ENDPOINT_DESCRIPTOR_ITEM:
/* ... */
endpoint = device -> ux_slave_device_endpoints_pool;
endpoints_pool_number = device -> ux_slave_device_endpoints_pool_number;
while (endpoints_pool_number != 0)
{
if (endpoint -> ux_slave_endpoint_status == UX_UNUSED)
{
endpoint -> ux_slave_endpoint_status = UX_USED;
break;
}if (endpoint -> ux_slave_endpoint_status == UX_UNUSED) { ... }
endpoint++;
endpoints_pool_number--;
}while (endpoints_pool_number != 0) { ... }
if (endpoints_pool_number == 0)
return(UX_MEMORY_INSUFFICIENT);
_ux_utility_descriptor_parse(device_framework,
_ux_system_endpoint_descriptor_structure,
UX_ENDPOINT_DESCRIPTOR_ENTRIES,
(UCHAR *) &endpoint -> ux_slave_endpoint_descriptor);
transfer_request = &endpoint -> ux_slave_endpoint_transfer_request;
UX_ASSERT(endpoint -> ux_slave_endpoint_descriptor.wMaxPacketSize != 0);
max_transfer_length =
endpoint -> ux_slave_endpoint_descriptor.wMaxPacketSize &
UX_MAX_PACKET_SIZE_MASK;
if ((_ux_system_slave -> ux_system_slave_speed == UX_HIGH_SPEED_DEVICE) &&
(endpoint -> ux_slave_endpoint_descriptor.bmAttributes & 0x1u))
{
n_trans = endpoint -> ux_slave_endpoint_descriptor.wMaxPacketSize &
UX_MAX_NUMBER_OF_TRANSACTIONS_MASK;
if (n_trans)
{
n_trans >>= UX_MAX_NUMBER_OF_TRANSACTIONS_SHIFT;
n_trans ++;
max_transfer_length *= n_trans;
}if (n_trans) { ... }
}if ((_ux_system_slave -> ux_system_slave_speed == UX_HIGH_SPEED_DEVICE) && (endpoint -> ux_slave_endpoint_descriptor.bmAttributes & 0x1u)) { ... }
UX_ASSERT(max_transfer_length <= UX_SLAVE_REQUEST_DATA_MAX_LENGTH);
transfer_request -> ux_slave_transfer_request_transfer_length = max_transfer_length;
transfer_request -> ux_slave_transfer_request_endpoint = endpoint;
transfer_request -> ux_slave_transfer_request_timeout = UX_WAIT_FOREVER;
endpoint -> ux_slave_endpoint_interface = interface;
endpoint -> ux_slave_endpoint_device = device;
status = dcd -> ux_slave_dcd_function(dcd, UX_DCD_CREATE_ENDPOINT, (VOID *) endpoint);
if (status != UX_SUCCESS)
{
endpoint -> ux_slave_endpoint_status = UX_UNUSED;
return(status);
}if (status != UX_SUCCESS) { ... }
if (interface -> ux_slave_interface_first_endpoint == UX_NULL)
{
interface -> ux_slave_interface_first_endpoint = endpoint;
}if (interface -> ux_slave_interface_first_endpoint == UX_NULL) { ... }
else
{
endpoint_link = interface -> ux_slave_interface_first_endpoint;
while (endpoint_link -> ux_slave_endpoint_next_endpoint != UX_NULL)
endpoint_link = endpoint_link -> ux_slave_endpoint_next_endpoint;
endpoint_link -> ux_slave_endpoint_next_endpoint = endpoint;
}else { ... }
break;
case UX_ENDPOINT_DESCRIPTOR_ITEM:
case UX_CONFIGURATION_DESCRIPTOR_ITEM:
case UX_INTERFACE_DESCRIPTOR_ITEM:
/* ... */
device_framework_length = descriptor_length;
break;
case UX_INTERFACE_DESCRIPTOR_ITEM:
default:
break;default
}switch (descriptor_type) { ... }
device_framework_length -= descriptor_length;
device_framework += descriptor_length;
}while (device_framework_length != 0) { ... }
_ux_utility_memory_copy(&interface -> ux_slave_interface_descriptor, &interface_descriptor, sizeof(UX_INTERFACE_DESCRIPTOR));
class = _ux_system_slave -> ux_system_slave_interface_class_array[interface -> ux_slave_interface_descriptor.bInterfaceNumber];
if (class == UX_NULL || class -> ux_slave_class_status == UX_UNUSED)
{
return (UX_NO_CLASS_MATCH);
}if (class == UX_NULL || class -> ux_slave_class_status == UX_UNUSED) { ... }
/* ... */
class_command.ux_slave_class_command_request = UX_SLAVE_CLASS_COMMAND_CHANGE;
class_command.ux_slave_class_command_interface = (VOID *) interface;
class_command.ux_slave_class_command_class_ptr = class;
class -> ux_slave_class_interface = interface;
status = class -> ux_slave_class_entry_function(&class_command);
return(status);
}if (interface_descriptor.bInterfaceNumber == interface_value && interface_descriptor.bAlternateSetting == alternate_setting_value) { ... }
}if (descriptor_type == UX_INTERFACE_DESCRIPTOR_ITEM) { ... }
device_framework_length -= descriptor_length;
device_framework += descriptor_length;
}while (device_framework_length != 0) { ... }
break;
}if (configuration_descriptor.bConfigurationValue == device -> ux_slave_device_configuration_selected) { ... }
}if (descriptor_type == UX_CONFIGURATION_DESCRIPTOR_ITEM) { ... }
device_framework_length -= descriptor_length;
device_framework += descriptor_length;
}while (device_framework_length != 0) { ... }
return(UX_ERROR);/* ... */
#endif
}{ ... }