1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
10 /**************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** USBX Component */
17 /** */
18 /** Host Simulator Controller Driver */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23 #define UX_SOURCE_CODE
24
25
26 /* Include necessary system files. */
27
28 #include "ux_api.h"
29 #include "ux_hcd_sim_host.h"
30
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _ux_hcd_sim_host_entry PORTABLE C */
37 /* 6.1.10 */
38 /* AUTHOR */
39 /* */
40 /* Chaoqiong Xiao, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function dispatch the HCD function internally to the simulator */
45 /* controller driver. */
46 /* */
47 /* INPUT */
48 /* */
49 /* hcd Pointer to HCD */
50 /* function Function for driver to perform*/
51 /* parameter Pointer to parameter(s) */
52 /* */
53 /* OUTPUT */
54 /* */
55 /* Completion Status */
56 /* */
57 /* CALLS */
58 /* */
59 /* _ux_hcd_sim_host_asynch_queue_process Process asynch queue */
60 /* _ux_hcd_sim_host_asynch_schedule Schedule async work */
61 /* _ux_hcd_sim_host_asynchronous_endpoint_create Create async endpoint */
62 /* _ux_hcd_sim_host_asynchronous_endpoint_destroy Destroy async endpoint */
63 /* _ux_hcd_sim_host_endpoint_reset Reset endpoint */
64 /* _ux_hcd_sim_host_frame_number_get Get frame number */
65 /* _ux_hcd_sim_host_interrupt_endpoint_create Create endpoint */
66 /* _ux_hcd_sim_host_iso_queue_process Process iso queue */
67 /* _ux_hcd_sim_host_iso_schedule Schedule iso work */
68 /* _ux_hcd_sim_host_isochronous_endpoint_create Create iso endpoint */
69 /* _ux_hcd_sim_host_periodic_endpoint_destroy Destroy endpoint */
70 /* _ux_hcd_sim_host_periodic_schedule Schedule periodic */
71 /* _ux_hcd_sim_host_port_status_get Get port status */
72 /* _ux_hcd_sim_host_port_reset Reset port */
73 /* _ux_hcd_sim_host_request_transfer Request transfer */
74 /* _ux_hcd_sim_host_transfer_abort Abort transfer */
75 /* */
76 /* CALLED BY */
77 /* */
78 /* Host Stack */
79 /* */
80 /* RELEASE HISTORY */
81 /* */
82 /* DATE NAME DESCRIPTION */
83 /* */
84 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
85 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
86 /* added controller disable, */
87 /* resulting in version 6.1 */
88 /* 11-09-2020 Chaoqiong Xiao Modified comment(s), */
89 /* added HCD uninitialize, */
90 /* resulting in version 6.1.2 */
91 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
92 /* added standalone support, */
93 /* resulting in version 6.1.10 */
94 /* */
95 /**************************************************************************/
_ux_hcd_sim_host_entry(UX_HCD * hcd,UINT function,VOID * parameter)96 UINT _ux_hcd_sim_host_entry(UX_HCD *hcd, UINT function, VOID *parameter)
97 {
98
99 UINT status = 0;
100 UX_HCD_SIM_HOST *hcd_sim_host;
101
102
103 /* Check the status of the controller. */
104 if (hcd -> ux_hcd_status == UX_UNUSED)
105 {
106
107 /* Error trap. */
108 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_HCD, UX_CONTROLLER_UNKNOWN);
109
110 /* If trace is enabled, insert this event into the trace buffer. */
111 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_CONTROLLER_UNKNOWN, 0, 0, 0, UX_TRACE_ERRORS, 0, 0)
112
113 return(UX_CONTROLLER_UNKNOWN);
114 }
115
116 /* Get the pointer to the host simulator HCD. */
117 hcd_sim_host = (UX_HCD_SIM_HOST *) hcd -> ux_hcd_controller_hardware;
118
119 /* look at the function and route it. */
120 switch(function)
121 {
122
123 case UX_HCD_UNINITIALIZE:
124 status = _ux_hcd_sim_host_uninitialize(hcd_sim_host);
125 break;
126
127
128 case UX_HCD_DISABLE_CONTROLLER:
129
130 status = _ux_hcd_sim_host_controller_disable(hcd_sim_host);
131 break;
132
133
134 case UX_HCD_GET_PORT_STATUS:
135
136 status = _ux_hcd_sim_host_port_status_get(hcd_sim_host, (ULONG) (ALIGN_TYPE) parameter);
137 break;
138
139
140 case UX_HCD_ENABLE_PORT:
141
142 status = UX_SUCCESS;
143 break;
144
145
146 case UX_HCD_DISABLE_PORT:
147
148 status = UX_SUCCESS;
149 break;
150
151
152 case UX_HCD_POWER_ON_PORT:
153
154 status = UX_SUCCESS;
155 break;
156
157
158 case UX_HCD_POWER_DOWN_PORT:
159
160 status = UX_SUCCESS;
161 break;
162
163
164 case UX_HCD_SUSPEND_PORT:
165
166 status = UX_SUCCESS;
167 break;
168
169
170 case UX_HCD_RESUME_PORT:
171
172 status = UX_SUCCESS;
173 break;
174
175
176 case UX_HCD_RESET_PORT:
177
178 status = _ux_hcd_sim_host_port_reset(hcd_sim_host, (ULONG) (ALIGN_TYPE) parameter);
179 break;
180
181
182 case UX_HCD_GET_FRAME_NUMBER:
183
184 status = _ux_hcd_sim_host_frame_number_get(hcd_sim_host, (ULONG *) parameter);
185 break;
186
187
188 case UX_HCD_SET_FRAME_NUMBER:
189
190 status = UX_SUCCESS;
191 break;
192
193
194 case UX_HCD_TRANSFER_REQUEST:
195
196 #if defined(UX_HOST_STANDALONE)
197 status = _ux_hcd_sim_host_transfer_run(hcd_sim_host, (UX_TRANSFER *) parameter);
198 #else
199 status = _ux_hcd_sim_host_request_transfer(hcd_sim_host, (UX_TRANSFER *) parameter);
200 #endif
201 break;
202
203
204 case UX_HCD_TRANSFER_ABORT:
205
206 status = _ux_hcd_sim_host_transfer_abort(hcd_sim_host, (UX_TRANSFER *) parameter);
207 break;
208
209
210 case UX_HCD_CREATE_ENDPOINT:
211
212 switch ((((UX_ENDPOINT*) parameter) -> ux_endpoint_descriptor.bmAttributes) & UX_MASK_ENDPOINT_TYPE)
213 {
214
215 case UX_CONTROL_ENDPOINT:
216 case UX_BULK_ENDPOINT:
217
218 status = _ux_hcd_sim_host_asynchronous_endpoint_create(hcd_sim_host, (UX_ENDPOINT*) parameter);
219 break;
220
221
222 case UX_INTERRUPT_ENDPOINT:
223
224 status = _ux_hcd_sim_host_interrupt_endpoint_create(hcd_sim_host, (UX_ENDPOINT*) parameter);
225 break;
226
227
228 case UX_ISOCHRONOUS_ENDPOINT:
229
230 status = _ux_hcd_sim_host_isochronous_endpoint_create(hcd_sim_host, (UX_ENDPOINT*) parameter);
231 break;
232
233 }
234 break;
235
236
237 case UX_HCD_DESTROY_ENDPOINT:
238
239 switch ((((UX_ENDPOINT*) parameter) -> ux_endpoint_descriptor.bmAttributes) & UX_MASK_ENDPOINT_TYPE)
240 {
241
242 case UX_CONTROL_ENDPOINT:
243 case UX_BULK_ENDPOINT:
244
245 status = _ux_hcd_sim_host_asynchronous_endpoint_destroy(hcd_sim_host, (UX_ENDPOINT*) parameter);
246 break;
247
248
249 case UX_INTERRUPT_ENDPOINT:
250 case UX_ISOCHRONOUS_ENDPOINT:
251
252 status = _ux_hcd_sim_host_periodic_endpoint_destroy(hcd_sim_host, (UX_ENDPOINT*) parameter);
253 break;
254
255 }
256 break;
257
258
259 case UX_HCD_RESET_ENDPOINT:
260
261 status = _ux_hcd_sim_host_endpoint_reset(hcd_sim_host, (UX_ENDPOINT*) parameter);
262 break;
263
264
265 case UX_HCD_PROCESS_DONE_QUEUE:
266
267 _ux_hcd_sim_host_iso_queue_process(hcd_sim_host);
268 _ux_hcd_sim_host_asynch_queue_process(hcd_sim_host);
269 _ux_hcd_sim_host_iso_schedule(hcd_sim_host);
270 _ux_hcd_sim_host_periodic_schedule(hcd_sim_host);
271 _ux_hcd_sim_host_asynch_schedule(hcd_sim_host);
272 status = UX_SUCCESS;
273 break;
274
275
276 default:
277
278 /* Error trap. */
279 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_HCD, UX_FUNCTION_NOT_SUPPORTED);
280
281 /* If trace is enabled, insert this event into the trace buffer. */
282 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_FUNCTION_NOT_SUPPORTED, 0, 0, 0, UX_TRACE_ERRORS, 0, 0)
283
284 /* Unknown request, return an error. */
285 status = UX_FUNCTION_NOT_SUPPORTED;
286 }
287
288 /* Return completion status. */
289 return(status);
290 }
291
292