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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
162
163
164
165
166
167
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
192
193
...
...
...
#define UX_SOURCE_CODE
#include "ux_api.h"
#include "ux_host_stack.h"
...
...
UINT _ux_host_stack_device_address_set(UX_DEVICE *device)
{
UINT status = UX_ERROR;
UX_TRANSFER *transfer_request;
UX_ENDPOINT *control_endpoint;
USHORT device_address;
#if UX_MAX_DEVICES > 1
UX_HCD *hcd;
UINT address_byte_index;
UINT address_bit_index;
UCHAR device_address_byte;/* ... */
#endif
control_endpoint = &device -> ux_device_control_endpoint;
transfer_request = &control_endpoint -> ux_endpoint_transfer_request;
device_address = 1;
#if UX_MAX_DEVICES > 1
hcd = UX_DEVICE_HCD_GET(device);
for (address_byte_index = 0; address_byte_index < 16; address_byte_index++)
{
device_address_byte = hcd -> ux_hcd_address[address_byte_index];
for (address_bit_index = 0; address_bit_index < 8; address_bit_index++)
{
if ((device_address_byte & (1 << address_bit_index)) == 0)
{
device_address_byte = (UCHAR)((UCHAR)device_address_byte | (UCHAR)(1 << address_bit_index));
hcd -> ux_hcd_address[address_byte_index] = device_address_byte;
status = UX_SUCCESS;
break;
}if ((device_address_byte & (1 << address_bit_index)) == 0) { ... }
device_address++;
}for (address_bit_index = 0; address_bit_index < 8; address_bit_index++) { ... }
if (status == UX_SUCCESS)
{
break;
}if (status == UX_SUCCESS) { ... }
}for (address_byte_index = 0; address_byte_index < 16; address_byte_index++) { ... }
if (status == UX_ERROR)
return(UX_ERROR);/* ... */
#endif
UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_DEVICE_ADDRESS_SET, device, device_address, 0, 0, UX_TRACE_HOST_STACK_EVENTS, 0, 0)
transfer_request -> ux_transfer_request_data_pointer = UX_NULL;
transfer_request -> ux_transfer_request_requested_length = 0;
transfer_request -> ux_transfer_request_function = UX_SET_ADDRESS;
transfer_request -> ux_transfer_request_type = UX_REQUEST_OUT | UX_REQUEST_TYPE_STANDARD | UX_REQUEST_TARGET_DEVICE;
transfer_request -> ux_transfer_request_value = device_address;
transfer_request -> ux_transfer_request_index = 0;
#if defined(UX_HOST_STANDALONE)
device -> ux_device_enum_trans = transfer_request;
status = UX_SUCCESS;
return(status);/* ... */
#else
status = _ux_host_stack_transfer_request(transfer_request);
/* ... */
device -> ux_device_address = (ULONG) device_address;
if (status == UX_SUCCESS)
{
device -> ux_device_state = UX_DEVICE_ADDRESSED;
_ux_utility_delay_ms(UX_DEVICE_ADDRESS_SET_WAIT);
return(status);
}if (status == UX_SUCCESS) { ... }
else
{
/* ... */
return(status);
}else { ... }
/* ... */#endif
}{ ... }