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
101
102
103
104
105
108
111
114
117
119
120
121
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
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
212
213
214
215
216
217
218
...
...
...
#define UX_SOURCE_CODE
#define UX_HCD_STM32_SOURCE_CODE
#include "ux_api.h"
#include "ux_hcd_stm32.h"
#include "ux_host_stack.h"
...
...
UINT _ux_hcd_stm32_endpoint_create(UX_HCD_STM32 *hcd_stm32, UX_ENDPOINT *endpoint)
{
UX_HCD_STM32_ED *ed;
UX_DEVICE *device;
ULONG channel_index;
UINT device_speed;
UINT endpoint_type;
device = endpoint -> ux_endpoint_device;
switch (device -> ux_device_speed)
{
case UX_HIGH_SPEED_DEVICE:
device_speed = HCD_DEVICE_SPEED_HIGH;
break;case UX_HIGH_SPEED_DEVICE:
case UX_FULL_SPEED_DEVICE:
device_speed = HCD_DEVICE_SPEED_FULL;
break;case UX_FULL_SPEED_DEVICE:
case UX_LOW_SPEED_DEVICE:
device_speed = HCD_DEVICE_SPEED_LOW;
break;case UX_LOW_SPEED_DEVICE:
default:
return(UX_ERROR);default
}switch (device -> ux_device_speed) { ... }
switch ((endpoint -> ux_endpoint_descriptor.bmAttributes) & UX_MASK_ENDPOINT_TYPE)
{
case UX_CONTROL_ENDPOINT:
endpoint_type = EP_TYPE_CTRL;
break;case UX_CONTROL_ENDPOINT:
case UX_BULK_ENDPOINT:
endpoint_type = EP_TYPE_BULK;
break;case UX_BULK_ENDPOINT:
case UX_INTERRUPT_ENDPOINT:
endpoint_type = EP_TYPE_INTR;
break;case UX_INTERRUPT_ENDPOINT:
case UX_ISOCHRONOUS_ENDPOINT:
endpoint_type = EP_TYPE_ISOC;
break;case UX_ISOCHRONOUS_ENDPOINT:
default:
return(UX_FUNCTION_NOT_SUPPORTED);default
}switch ((endpoint -> ux_endpoint_descriptor.bmAttributes) & UX_MASK_ENDPOINT_TYPE) { ... }
/* ... */
ed = _ux_hcd_stm32_ed_obtain(hcd_stm32);
if (ed == UX_NULL)
return(UX_NO_ED_AVAILABLE);
for (channel_index = 0; channel_index < hcd_stm32 -> ux_hcd_stm32_nb_channels; channel_index++)
{
if (hcd_stm32 -> ux_hcd_stm32_channels_ed[channel_index] == UX_NULL)
{
hcd_stm32 -> ux_hcd_stm32_channels_ed[channel_index] = ed;
ed -> ux_stm32_ed_channel = channel_index;
break;
}if (hcd_stm32 -> ux_hcd_stm32_channels_ed[channel_index] == UX_NULL) { ... }
}for (channel_index = 0; channel_index < hcd_stm32 -> ux_hcd_stm32_nb_channels; channel_index++) { ... }
if (ed -> ux_stm32_ed_channel == UX_HCD_STM32_NO_CHANNEL_ASSIGNED)
{
ed -> ux_stm32_ed_status = UX_HCD_STM32_ED_STATUS_FREE;
return(UX_NO_ED_AVAILABLE);
}if (ed -> ux_stm32_ed_channel == UX_HCD_STM32_NO_CHANNEL_ASSIGNED) { ... }
if ((endpoint_type == EP_TYPE_INTR) || (endpoint_type == EP_TYPE_ISOC))
{
if (endpoint_type == EP_TYPE_ISOC || device_speed == HCD_DEVICE_SPEED_HIGH)
{
ed -> ux_stm32_ed_interval_mask = (UCHAR)(1 << (endpoint -> ux_endpoint_descriptor.bInterval - 1)) - 1;
}if (endpoint_type == EP_TYPE_ISOC || device_speed == HCD_DEVICE_SPEED_HIGH) { ... }
else
{
ed -> ux_stm32_ed_interval_mask = endpoint -> ux_endpoint_descriptor.bInterval;
ed -> ux_stm32_ed_interval_mask |= ed -> ux_stm32_ed_interval_mask >> 1;
ed -> ux_stm32_ed_interval_mask |= ed -> ux_stm32_ed_interval_mask >> 2;
ed -> ux_stm32_ed_interval_mask |= ed -> ux_stm32_ed_interval_mask >> 4;
ed -> ux_stm32_ed_interval_mask >>= 1;
}else { ... }
ed -> ux_stm32_ed_interval_position = (UCHAR)_ux_hcd_stm32_least_traffic_list_get(hcd_stm32);
ed -> ux_stm32_ed_next_ed = hcd_stm32 -> ux_hcd_stm32_periodic_ed_head;
hcd_stm32 -> ux_hcd_stm32_periodic_ed_head = ed;
hcd_stm32 -> ux_hcd_stm32_periodic_scheduler_active ++;
}if ((endpoint_type == EP_TYPE_INTR) || (endpoint_type == EP_TYPE_ISOC)) { ... }
endpoint -> ux_endpoint_ed = (VOID *) ed;
ed -> ux_stm32_ed_endpoint = endpoint;
HAL_HCD_HC_Init(hcd_stm32->hcd_handle,
channel_index,
endpoint -> ux_endpoint_descriptor.bEndpointAddress,
device -> ux_device_address,
device_speed,
endpoint_type,
endpoint -> ux_endpoint_descriptor.wMaxPacketSize);
hcd_stm32 -> hcd_handle -> hc[ed -> ux_stm32_ed_channel].toggle_in = 0;
hcd_stm32 -> hcd_handle -> hc[ed -> ux_stm32_ed_channel].toggle_out = 0;
/* ... */
endpoint -> ux_endpoint_transfer_request.ux_transfer_request_maximum_length = UX_HCD_STM32_MAX_PACKET_COUNT *
endpoint -> ux_endpoint_descriptor.wMaxPacketSize;
return(UX_SUCCESS);
}{ ... }