1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** USBX Component */
16 /** */
17 /** Host Simulator Controller Driver */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22 #define UX_SOURCE_CODE
23
24
25 /* Include necessary system files. */
26
27 #include "ux_api.h"
28 #include "ux_hcd_sim_host.h"
29
30
31 #if defined(UX_HOST_STANDALONE)
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _ux_hcd_sim_host_transfer_run PORTABLE C */
37 /* 6.1.10 */
38 /* AUTHOR */
39 /* */
40 /* Chaoqiong Xiao, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function is the handler for all the transactions on the USB. */
45 /* The transfer request passed as parameter contains the endpoint and */
46 /* the device descriptors in addition to the type of transaction de */
47 /* be executed. This function routes the transfer request to */
48 /* according to the type of transfer to be executed. */
49 /* */
50 /* It's for standalone mode. */
51 /* */
52 /* INPUT */
53 /* */
54 /* hcd_sim_host Pointer to host controller */
55 /* transfer_request Pointer to transfer request */
56 /* */
57 /* OUTPUT */
58 /* */
59 /* Completion Status */
60 /* */
61 /* CALLS */
62 /* */
63 /* _ux_hcd_sim_host_request_bulk_transfer Request bulk transfer */
64 /* _ux_hcd_sim_host_request_control_transfer Request control */
65 /* transfer */
66 /* _ux_hcd_sim_host_request_interrupt_transfer Request interrupt */
67 /* transfer */
68 /* _ux_hcd_sim_host_request_isochronous_transfer Request isochronous */
69 /* transfer */
70 /* */
71 /* CALLED BY */
72 /* */
73 /* Host Simulator Controller Driver */
74 /* */
75 /* RELEASE HISTORY */
76 /* */
77 /* DATE NAME DESCRIPTION */
78 /* */
79 /* 01-31-2022 Chaoqiong Xiao Initial Version 6.1.10 */
80 /* */
81 /**************************************************************************/
_ux_hcd_sim_host_transfer_run(UX_HCD_SIM_HOST * hcd_sim_host,UX_TRANSFER * transfer_request)82 UINT _ux_hcd_sim_host_transfer_run(UX_HCD_SIM_HOST *hcd_sim_host, UX_TRANSFER *transfer_request)
83 {
84
85 UX_INTERRUPT_SAVE_AREA
86 UX_ENDPOINT *endpoint;
87 UX_HCD_SIM_HOST_ED *ed;
88 UINT status = 0;
89
90
91 /* Get the pointer to the Endpoint. */
92 endpoint = (UX_ENDPOINT *) transfer_request -> ux_transfer_request_endpoint;
93
94 /* Sanity check. */
95 if (endpoint == UX_NULL)
96 return(UX_STATE_EXIT);
97
98 /* Get ED. */
99 ed = (UX_HCD_SIM_HOST_ED *)endpoint -> ux_endpoint_ed;
100
101 /* Sanity check. */
102 if (ed == UX_NULL)
103 return(UX_STATE_EXIT);
104
105 UX_DISABLE
106
107 /* If transfer started, check status. */
108 if (ed -> ux_sim_host_ed_status & UX_HCD_SIM_HOST_ED_TRANSFER)
109 {
110 if (ed -> ux_sim_host_ed_head_td != ed -> ux_sim_host_ed_tail_td)
111 {
112 UX_RESTORE
113 return(UX_STATE_WAIT);
114 }
115
116 /* Check if it's transfer waiting state. */
117 if (transfer_request -> ux_transfer_request_status != UX_TRANSFER_STATUS_NOT_PENDING)
118 {
119
120 /* Yes, polling pending status, report and transfer done. */
121 ed -> ux_sim_host_ed_status &= ~UX_HCD_SIM_HOST_ED_TRANSFER;
122 UX_RESTORE
123 return(UX_STATE_NEXT);
124 }
125
126 /* Maybe transfer completed but state not reported yet. */
127 }
128 ed -> ux_sim_host_ed_status |= UX_HCD_SIM_HOST_ED_TRANSFER;
129 transfer_request -> ux_transfer_request_status = UX_TRANSFER_STATUS_PENDING;
130
131 UX_RESTORE
132
133 /* We reset the actual length field of the transfer request as a safety measure. */
134 transfer_request -> ux_transfer_request_actual_length = 0;
135
136 /* Isolate the endpoint type and route the transfer request. */
137 switch ((endpoint -> ux_endpoint_descriptor.bmAttributes) & UX_MASK_ENDPOINT_TYPE)
138 {
139
140 case UX_CONTROL_ENDPOINT:
141
142 status = _ux_hcd_sim_host_request_control_transfer(hcd_sim_host, transfer_request);
143 break;
144
145
146 case UX_BULK_ENDPOINT:
147
148 status = _ux_hcd_sim_host_request_bulk_transfer(hcd_sim_host, transfer_request);
149 break;
150
151 case UX_INTERRUPT_ENDPOINT:
152
153 status = _ux_hcd_sim_host_request_interrupt_transfer(hcd_sim_host, transfer_request);
154 break;
155
156 case UX_ISOCHRONOUS_ENDPOINT:
157
158 status = _ux_hcd_sim_host_request_isochronous_transfer(hcd_sim_host, transfer_request);
159 break;
160
161 }
162
163 return (status == UX_SUCCESS) ? (UX_STATE_WAIT) : (UX_STATE_ERROR);
164 }
165 #endif
166