Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
...
#define UX_SOURCE_CODE
#include "ux_api.h"
#include "ux_host_stack.h"
UX_MAX_HCD_mul_ovf31
UX_MAX_CLASS_DRIVER_mul_ovf32
UX_MAX_DEVICES_mul_ovf33
#define UX_HOST_HNP_POLLING_THREAD_STACK_SIZE
_ux_system_host
_ux_system_host_hcd_periodic_tree_entries
_ux_system_host_class_hub_name
_ux_system_host_class_printer_name
_ux_system_host_class_storage_name
_ux_system_host_class_hid_name
_ux_system_host_class_audio_name
_ux_system_host_class_cdc_acm_name
_ux_system_host_class_cdc_dlc_name
_ux_system_host_class_cdc_ecm_name
_ux_system_host_class_prolific_name
_ux_system_host_class_pima_name
_ux_system_host_class_dpump_name
_ux_system_host_class_asix_name
_ux_system_host_class_swar_name
_ux_system_host_class_gser_name
_ux_system_host_class_hid_client_remote_control_name
_ux_system_host_class_hid_client_mouse_name
_ux_system_host_class_hid_client_keyboard_name
_ux_system_host_hcd_ohci_name
_ux_system_host_hcd_ehci_name
_ux_system_host_hcd_isp1161_name
_ux_system_host_hcd_isp1362_name
_ux_system_host_hcd_sh2_name
_ux_system_host_hcd_rx_name
_ux_system_host_hcd_pic32_name
_ux_system_host_hcd_stm32_name
_ux_system_host_hcd_musb_name
_ux_system_host_hcd_atm7_name
_ux_system_host_hcd_simulator_name
...
...
_ux_host_stack_initialize(UINT (*)(ULONG, UX_HOST_CLASS *, void *))
Files
loading...
CodeScopeSTM32 Libraries and Samplesusbxcommon/core/src/ux_host_stack_initialize.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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* 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 */ /** */ /** Host Stack */ /** */... /**************************************************************************/ /**************************************************************************/ /* Include necessary system files. */ #define UX_SOURCE_CODE #include "ux_api.h" #include "ux_host_stack.h" UX_COMPILE_TIME_ASSERT(!UX_OVERFLOW_CHECK_MULC_ULONG(sizeof(UX_HCD), UX_MAX_HCD), UX_MAX_HCD_mul_ovf) UX_COMPILE_TIME_ASSERT(!UX_OVERFLOW_CHECK_MULC_ULONG(sizeof(UX_HOST_CLASS), UX_MAX_CLASS_DRIVER), UX_MAX_CLASS_DRIVER_mul_ovf) UX_COMPILE_TIME_ASSERT(!UX_OVERFLOW_CHECK_MULC_ULONG(sizeof(UX_DEVICE), UX_MAX_DEVICES), UX_MAX_DEVICES_mul_ovf) #ifndef UX_HOST_HNP_POLLING_THREAD_STACK_SIZE #define UX_HOST_HNP_POLLING_THREAD_STACK_SIZE UX_THREAD_STACK_SIZE #endif /* Defined USBX host variables. */ UX_SYSTEM_HOST *_ux_system_host; /* Define table of periodic tree entries, properly indexed. */ UINT _ux_system_host_hcd_periodic_tree_entries[32] = { 0x00, 0x10, 0x08, 0x18, 0x04, 0x14, 0x0c, 0x1c, 0x02, 0x12, 0x0a, 0x1a, 0x06, 0x16, 0x0e, 0x1e, 0x01, 0x11, 0x09, 0x19, 0x05, 0x15, 0x0d, 0x1d, 0x03, 0x13, 0x0b, 0x1b, 0x07, 0x17, 0x0f, 0x1f...}; /* Define the names of all the USB Classes of USBX. */ UCHAR _ux_system_host_class_hub_name[] = "ux_host_class_hub"; UCHAR _ux_system_host_class_printer_name[] = "ux_host_class_printer"; UCHAR _ux_system_host_class_storage_name[] = "ux_host_class_storage"; UCHAR _ux_system_host_class_hid_name[] = "ux_host_class_hid"; UCHAR _ux_system_host_class_audio_name[] = "ux_host_class_audio"; UCHAR _ux_system_host_class_cdc_acm_name[] = "ux_host_class_cdc_acm"; UCHAR _ux_system_host_class_cdc_dlc_name[] = "ux_host_class_cdc_dlc"; UCHAR _ux_system_host_class_cdc_ecm_name[] = "ux_host_class_cdc_ecm"; UCHAR _ux_system_host_class_prolific_name[] = "ux_host_class_prolific"; UCHAR _ux_system_host_class_pima_name[] = "ux_host_class_pima"; UCHAR _ux_system_host_class_dpump_name[] = "ux_host_class_dpump"; UCHAR _ux_system_host_class_asix_name[] = "ux_host_class_asix"; UCHAR _ux_system_host_class_swar_name[] = "ux_host_class_sierra_wireless"; UCHAR _ux_system_host_class_gser_name[] = "ux_host_class_generic_serial"; UCHAR _ux_system_host_class_hid_client_remote_control_name[] = "ux_host_class_hid_client_remote_control"; UCHAR _ux_system_host_class_hid_client_mouse_name[] = "ux_host_class_hid_client_mouse"; UCHAR _ux_system_host_class_hid_client_keyboard_name[] = "ux_host_class_hid_client_keyboard"; /* Define the name of all the USB Host Controllers of USBX. */ UCHAR _ux_system_host_hcd_ohci_name[] = "ux_hcd_ohci"; UCHAR _ux_system_host_hcd_ehci_name[] = "ux_hcd_ehci"; UCHAR _ux_system_host_hcd_isp1161_name[] = "ux_hcd_isp1161"; UCHAR _ux_system_host_hcd_isp1362_name[] = "ux_hcd_isp1362"; UCHAR _ux_system_host_hcd_sh2_name[] = "ux_hcd_rx"; UCHAR _ux_system_host_hcd_rx_name[] = "ux_hcd_sh2"; UCHAR _ux_system_host_hcd_pic32_name[] = "ux_hcd_pic32"; UCHAR _ux_system_host_hcd_stm32_name[] = "ux_hcd_stm32"; UCHAR _ux_system_host_hcd_musb_name[] = "ux_hcd_musb"; UCHAR _ux_system_host_hcd_atm7_name[] = "ux_hcd_atm7"; UCHAR _ux_system_host_hcd_simulator_name[] = "ux_hcd_simulator"; ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _ux_host_stack_initialize PORTABLE C */ /* 6.1.10 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function initializes all the host code for USBX to work on a */ /* specific platform. */ /* */ /* INPUT */ /* */ /* (ux_system_host_change_function) Function pointer to the */ /* callback function for a */ /* device change */ /* */ /* OUTPUT */ /* */ /* Completion Status */ /* */ /* */ /* CALLS */ /* */ /* _ux_utility_memory_allocate Allocate host memory */ /* _ux_utility_semaphore_create Create host semaphore */ /* _ux_utility_mutex_create Create host mutex */ /* _ux_utility_thread_create Create host thread */ /* */ /* CALLED BY */ /* */ /* Application */ /* */ /* 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, used UX prefix */ /* to refer to TX symbols */ /* instead of using them */ /* directly, */ /* 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_stack_initialize(UINT (*ux_system_host_change_function)(ULONG, UX_HOST_CLASS *, VOID *)) { UINT status; UCHAR *memory; #if defined(UX_HOST_STANDALONE) UINT i; UX_DEVICE *device;/* ... */ #endif /* If trace is enabled, insert this event into the trace buffer. */ UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_INITIALIZE, 0, 0, 0, 0, UX_TRACE_HOST_STACK_EVENTS, 0, 0) /* Initialize some of the global so that we don't have to recompile the core code when one item is adjusted. *//* ... */ _ux_system_host -> ux_system_host_max_ed = UX_MAX_ED; _ux_system_host -> ux_system_host_max_td = UX_MAX_TD; _ux_system_host -> ux_system_host_max_iso_td = UX_MAX_ISO_TD; UX_SYSTEM_HOST_MAX_CLASS_SET(UX_MAX_CLASS_DRIVER); UX_SYSTEM_HOST_MAX_HCD_SET(UX_MAX_HCD); UX_SYSTEM_HOST_MAX_DEVICES_SET(UX_MAX_DEVICES); /* Set the change device function address. */ _ux_system_host -> ux_system_host_change_function = ux_system_host_change_function; /* Allocate memory for the HCDs. * sizeof(UX_HCD)*UX_MAX_HCD overflow is checked outside of the function. *//* ... */ memory = _ux_utility_memory_allocate(UX_NO_ALIGN, UX_REGULAR_MEMORY, sizeof(UX_HCD)*UX_MAX_HCD); /* Check for successful allocation. */ if (memory == UX_NULL) return(UX_MEMORY_INSUFFICIENT); /* Set to success by default. */ status = UX_SUCCESS; /* Store memory in system structure. */ _ux_system_host -> ux_system_host_hcd_array = (UX_HCD *) memory; /* Allocate memory for the classes. * sizeof(UX_HOST_CLASS)*UX_MAX_CLASS_DRIVER overflow is checked outside of the function. *//* ... */ memory = _ux_utility_memory_allocate(UX_NO_ALIGN, UX_REGULAR_MEMORY, sizeof(UX_HOST_CLASS)*UX_MAX_CLASS_DRIVER); /* Check for successful allocation. */ if (memory == UX_NULL) status = UX_MEMORY_INSUFFICIENT; else /* Store memory in system structure. */ _ux_system_host -> ux_system_host_class_array = (UX_HOST_CLASS *) memory; /* Allocate memory for the device containers. * sizeof(UX_DEVICE)*UX_MAX_DEVICES overflow is checked outside of the function. *//* ... */ if (status == UX_SUCCESS) { memory = _ux_utility_memory_allocate(UX_NO_ALIGN, UX_REGULAR_MEMORY, sizeof(UX_DEVICE)*UX_MAX_DEVICES); /* Check for successful allocation. */ if(memory == UX_NULL) status = UX_MEMORY_INSUFFICIENT; else /* Store memory in system structure. */ _ux_system_host -> ux_system_host_device_array = (UX_DEVICE *) memory; #if defined(UX_HOST_STANDALONE) /* Add devices to the enumeration list, with ENUM flags cleared. */ if (status == UX_SUCCESS) { /* Start from the last device instance. */ device = &_ux_system_host -> ux_system_host_device_array[UX_MAX_DEVICES - 1]; /* Insert all devices to enumeration list head. */ for (i = 0; i < UX_MAX_DEVICES; i ++) { /* Insert to head. */ device -> ux_device_enum_next = _ux_system_host -> ux_system_host_enum_device; _ux_system_host -> ux_system_host_enum_device = device; /* Next device. */ device --; }for (i = 0; i < UX_MAX_DEVICES; i ++) { ... } }if (status == UX_SUCCESS) { ... } /* ... */#endif }if (status == UX_SUCCESS) { ... } #if !defined(UX_HOST_STANDALONE) /* Obtain enough stack for the two USBX host threads. */ if (status == UX_SUCCESS) { _ux_system_host -> ux_system_host_enum_thread_stack = _ux_utility_memory_allocate(UX_NO_ALIGN, UX_REGULAR_MEMORY, UX_HOST_ENUM_THREAD_STACK_SIZE); /* Check for successful allocation. */ if (_ux_system_host -> ux_system_host_enum_thread_stack == UX_NULL) status = UX_MEMORY_INSUFFICIENT; }if (status == UX_SUCCESS) { ... } /* Allocate another stack area. */ if (status == UX_SUCCESS) { _ux_system_host -> ux_system_host_hcd_thread_stack = _ux_utility_memory_allocate(UX_NO_ALIGN, UX_REGULAR_MEMORY, UX_HOST_HCD_THREAD_STACK_SIZE); /* Check for successful allocation. */ if (_ux_system_host -> ux_system_host_hcd_thread_stack == UX_NULL) status = UX_MEMORY_INSUFFICIENT; }if (status == UX_SUCCESS) { ... } /* Create the semaphores used by the hub and root hub to awake the enumeration thread. */ if (status == UX_SUCCESS) { status = _ux_utility_semaphore_create(&_ux_system_host -> ux_system_host_enum_semaphore, "ux_system_host_enum_semaphore", 0); if(status != UX_SUCCESS) status = UX_SEMAPHORE_ERROR; }if (status == UX_SUCCESS) { ... } /* Create the semaphores used by the HCD to perform the completion phase of transfer_requests. */ if (status == UX_SUCCESS) { status = _ux_utility_semaphore_create(&_ux_system_host -> ux_system_host_hcd_semaphore, "ux_system_host_hcd_semaphore", 0); if(status != UX_SUCCESS) status = UX_SEMAPHORE_ERROR; }if (status == UX_SUCCESS) { ... } /* Create the enumeration thread of USBX. */ if (status == UX_SUCCESS) { status = _ux_utility_thread_create(&_ux_system_host -> ux_system_host_enum_thread, "ux_system_host_enum_thread", _ux_host_stack_enum_thread_entry, 0, _ux_system_host -> ux_system_host_enum_thread_stack, UX_HOST_ENUM_THREAD_STACK_SIZE, UX_THREAD_PRIORITY_ENUM, UX_THREAD_PRIORITY_ENUM, UX_NO_TIME_SLICE, UX_AUTO_START); /* Check the completion status. */ if(status != UX_SUCCESS) status = UX_THREAD_ERROR; }if (status == UX_SUCCESS) { ... } /* Create the HCD thread of USBX. */ if (status == UX_SUCCESS) { status = _ux_utility_thread_create(&_ux_system_host -> ux_system_host_hcd_thread, "ux_host_stack_hcd_thread", _ux_host_stack_hcd_thread_entry, 0, _ux_system_host -> ux_system_host_hcd_thread_stack, UX_HOST_HCD_THREAD_STACK_SIZE, UX_THREAD_PRIORITY_HCD, UX_THREAD_PRIORITY_HCD, UX_NO_TIME_SLICE,UX_AUTO_START); /* Check the completion status. */ if(status != UX_SUCCESS) status = UX_THREAD_ERROR; }if (status == UX_SUCCESS) { ... } /* ... */#endif #if defined(UX_OTG_SUPPORT) && !defined(UX_OTG_STANDALONE) /* Allocate another stack area for the HNP polling thread. */ if (status == UX_SUCCESS) { _ux_system_host -> ux_system_host_hnp_polling_thread_stack = _ux_utility_memory_allocate(UX_NO_ALIGN, UX_REGULAR_MEMORY, UX_HOST_HNP_POLLING_THREAD_STACK_SIZE); /* Check for successful allocation. */ if (_ux_system_host -> ux_system_host_hnp_polling_thread_stack == UX_NULL) status = UX_MEMORY_INSUFFICIENT; }if (status == UX_SUCCESS) { ... } /* Create the HNP polling thread of USBX. */ if (status == UX_SUCCESS) { status = _ux_utility_thread_create(&_ux_system_host -> ux_system_host_hnp_polling_thread, "ux_host_stack_hnp_polling_thread", _ux_host_stack_hnp_polling_thread_entry, 0, _ux_system_host -> ux_system_host_hnp_polling_thread_stack, UX_HOST_HNP_POLLING_THREAD_STACK_SIZE, UX_THREAD_PRIORITY_ENUM, UX_THREAD_PRIORITY_ENUM, UX_NO_TIME_SLICE, UX_AUTO_START); /* Check the completion status. */ if (status != UX_SUCCESS) status = UX_THREAD_ERROR; /* Return success (SUCCESS). */ else return(status); }if (status == UX_SUCCESS) { ... } /* Free up resources on error cases. */ /* Last resource, _ux_system_host -> ux_system_host_hnp_polling_thread is not created or created error, * no need to delete it. *//* ... */ /* Free _ux_system_host -> ux_system_host_hnp_polling_thread_stack. */ if (_ux_system_host -> ux_system_host_hnp_polling_thread_stack) _ux_utility_memory_free(_ux_system_host -> ux_system_host_hnp_polling_thread_stack); /* Delete _ux_system_host -> ux_system_host_hcd_thread. */ if (_ux_system_host -> ux_system_host_hcd_thread.tx_thread_id != 0) _ux_utility_thread_delete(&_ux_system_host -> ux_system_host_hcd_thread);/* ... */ #else /* Return completion status to caller if success. */ if (status == UX_SUCCESS) return(status); /* Free up resources on error cases. */ /* Last resource, _ux_system_host -> ux_system_host_hcd_thread is not created or created error, * no need to delete it. *//* ... */ /* ... */#endif #if !defined(UX_HOST_STANDALONE) /* Delete _ux_system_host -> ux_system_host_enum_thread. */ if (_ux_system_host -> ux_system_host_enum_thread.tx_thread_id != 0) _ux_utility_thread_delete(&_ux_system_host -> ux_system_host_enum_thread); /* Delete _ux_system_host -> ux_system_host_hcd_semaphore. */ if (_ux_system_host -> ux_system_host_hcd_semaphore.tx_semaphore_id != 0) _ux_utility_semaphore_delete(&_ux_system_host -> ux_system_host_hcd_semaphore); /* Delete _ux_system_host -> ux_system_host_enum_semaphore. */ if (_ux_system_host -> ux_system_host_enum_semaphore.tx_semaphore_id != 0) _ux_utility_semaphore_delete(&_ux_system_host -> ux_system_host_enum_semaphore); /* Free _ux_system_host -> ux_system_host_hcd_thread_stack. */ if (_ux_system_host -> ux_system_host_hcd_thread_stack) _ux_utility_memory_free(_ux_system_host -> ux_system_host_hcd_thread_stack); /* Free _ux_system_host -> ux_system_host_enum_thread_stack. */ if (_ux_system_host -> ux_system_host_enum_thread_stack) _ux_utility_memory_free(_ux_system_host -> ux_system_host_enum_thread_stack);/* ... */ #endif /* Free _ux_system_host -> ux_system_host_device_array. */ if (_ux_system_host -> ux_system_host_device_array) _ux_utility_memory_free(_ux_system_host -> ux_system_host_device_array); /* Free _ux_system_host -> ux_system_host_class_array. */ if (_ux_system_host -> ux_system_host_class_array) _ux_utility_memory_free(_ux_system_host -> ux_system_host_class_array); /* Free _ux_system_host -> ux_system_host_hcd_array. */ _ux_utility_memory_free(_ux_system_host -> ux_system_host_hcd_array); /* Return completion status to caller. */ return(status); }{ ... }