1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* Copyright (c) 2026-present Eclipse ThreadX contributors |
4 |
|
|
* |
5 |
|
|
* This program and the accompanying materials are made available under the |
6 |
|
|
* terms of the MIT License which is available at |
7 |
|
|
* https://opensource.org/licenses/MIT. |
8 |
|
|
* |
9 |
|
|
* SPDX-License-Identifier: MIT |
10 |
|
|
**************************************************************************/ |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/**************************************************************************/ |
15 |
|
|
/** */ |
16 |
|
|
/** USBX Component */ |
17 |
|
|
/** */ |
18 |
|
|
/** Storage Class */ |
19 |
|
|
/** */ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
/**************************************************************************/ |
22 |
|
|
|
23 |
|
|
|
24 |
|
|
/* Include necessary system files. */ |
25 |
|
|
|
26 |
|
|
#define UX_SOURCE_CODE |
27 |
|
|
|
28 |
|
|
#include "ux_api.h" |
29 |
|
|
#include "ux_host_class_storage.h" |
30 |
|
|
#include "ux_host_stack.h" |
31 |
|
|
|
32 |
|
|
|
33 |
|
|
/**************************************************************************/ |
34 |
|
|
/* */ |
35 |
|
|
/* FUNCTION RELEASE */ |
36 |
|
|
/* */ |
37 |
|
|
/* _ux_host_class_storage_endpoints_get PORTABLE C */ |
38 |
|
|
/* 6.3.0 */ |
39 |
|
|
/* AUTHOR */ |
40 |
|
|
/* */ |
41 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
42 |
|
|
/* */ |
43 |
|
|
/* DESCRIPTION */ |
44 |
|
|
/* */ |
45 |
|
|
/* This function searches for the handle of the bulk out endpoint and */ |
46 |
|
|
/* optionally the bulk in endpoint. */ |
47 |
|
|
/* */ |
48 |
|
|
/* INPUT */ |
49 |
|
|
/* */ |
50 |
|
|
/* storage Pointer to storage class */ |
51 |
|
|
/* */ |
52 |
|
|
/* OUTPUT */ |
53 |
|
|
/* */ |
54 |
|
|
/* Completion Status */ |
55 |
|
|
/* */ |
56 |
|
|
/* CALLS */ |
57 |
|
|
/* */ |
58 |
|
|
/* _ux_host_stack_interface_endpoint_get Get an endpoint pointer */ |
59 |
|
|
/* _ux_utility_memory_allocate Allocate memory */ |
60 |
|
|
/* */ |
61 |
|
|
/* CALLED BY */ |
62 |
|
|
/* */ |
63 |
|
|
/* Storage Class */ |
64 |
|
|
/* */ |
65 |
|
|
/**************************************************************************/ |
66 |
|
139 |
UINT _ux_host_class_storage_endpoints_get(UX_HOST_CLASS_STORAGE *storage) |
67 |
|
|
{ |
68 |
|
|
|
69 |
|
|
UINT endpoint_index; |
70 |
|
|
UX_ENDPOINT *endpoint; |
71 |
|
|
UINT status; |
72 |
|
|
|
73 |
|
|
|
74 |
|
|
/* Search for the bulk OUT endpoint. It is attached to the interface container. */ |
75 |
✓✓ |
259 |
for (endpoint_index = 0; endpoint_index < storage -> ux_host_class_storage_interface -> ux_interface_descriptor.bNumEndpoints; |
76 |
|
120 |
endpoint_index++) |
77 |
|
|
{ |
78 |
|
|
|
79 |
|
|
/* Get an endpoint. */ |
80 |
|
253 |
status = _ux_host_stack_interface_endpoint_get(storage -> ux_host_class_storage_interface, endpoint_index, &endpoint); |
81 |
|
|
|
82 |
|
|
/* Check status. */ |
83 |
✗✓ |
253 |
if (status != UX_SUCCESS) |
84 |
|
|
continue; |
85 |
|
|
|
86 |
|
|
/* We have an endpoint. Check if endpoint is bulk and OUT. */ |
87 |
✓✓ |
253 |
if (((endpoint -> ux_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) == UX_ENDPOINT_OUT) && |
88 |
✓✓ |
136 |
((endpoint -> ux_endpoint_descriptor.bmAttributes & UX_MASK_ENDPOINT_TYPE) == UX_BULK_ENDPOINT)) |
89 |
|
|
{ |
90 |
|
|
|
91 |
|
|
/* We have found the bulk OUT endpoint, save it! */ |
92 |
|
133 |
storage -> ux_host_class_storage_bulk_out_endpoint = endpoint; |
93 |
|
|
|
94 |
|
|
/* This transfer request always has the OUT direction. */ |
95 |
|
133 |
endpoint -> ux_endpoint_transfer_request.ux_transfer_request_type = UX_REQUEST_OUT; |
96 |
|
|
|
97 |
|
133 |
break; |
98 |
|
|
} |
99 |
|
|
} |
100 |
|
|
|
101 |
|
|
/* The bulk OUT endpoint is mandatory. */ |
102 |
✓✓ |
139 |
if (storage -> ux_host_class_storage_bulk_out_endpoint == UX_NULL) |
103 |
|
|
{ |
104 |
|
|
|
105 |
|
|
/* Error trap. */ |
106 |
|
6 |
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_ENDPOINT_HANDLE_UNKNOWN); |
107 |
|
|
|
108 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
109 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_ENDPOINT_HANDLE_UNKNOWN, storage, 0, 0, UX_TRACE_ERRORS, 0, 0) |
110 |
|
|
|
111 |
|
6 |
return(UX_ENDPOINT_HANDLE_UNKNOWN); |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
/* Search for the bulk IN endpoint. It is attached to the interface container. */ |
115 |
✓✓ |
176 |
for (endpoint_index = 0; endpoint_index < storage -> ux_host_class_storage_interface -> ux_interface_descriptor.bNumEndpoints; |
116 |
|
43 |
endpoint_index++) |
117 |
|
|
{ |
118 |
|
|
|
119 |
|
|
/* Get an endpoint. */ |
120 |
|
170 |
status = _ux_host_stack_interface_endpoint_get(storage -> ux_host_class_storage_interface, endpoint_index, &endpoint); |
121 |
|
|
|
122 |
|
|
/* Check status. */ |
123 |
✗✓ |
170 |
if (status != UX_SUCCESS) |
124 |
|
|
continue; |
125 |
|
|
|
126 |
|
|
/* We have an endpoint. Check if endpoint is bulk and IN. */ |
127 |
✓✓ |
170 |
if (((endpoint -> ux_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) == UX_ENDPOINT_IN) && |
128 |
✓✓ |
130 |
((endpoint -> ux_endpoint_descriptor.bmAttributes & UX_MASK_ENDPOINT_TYPE) == UX_BULK_ENDPOINT)) |
129 |
|
|
{ |
130 |
|
|
|
131 |
|
|
/* We have found the bulk IN endpoint, save it! */ |
132 |
|
127 |
storage -> ux_host_class_storage_bulk_in_endpoint = endpoint; |
133 |
|
|
|
134 |
|
|
/* This transfer request always has the IN direction. */ |
135 |
|
127 |
endpoint -> ux_endpoint_transfer_request.ux_transfer_request_type = UX_REQUEST_IN; |
136 |
|
|
|
137 |
|
127 |
break; |
138 |
|
|
} |
139 |
|
|
} |
140 |
|
|
|
141 |
|
|
/* The bulk IN endpoint is mandatory */ |
142 |
✓✓ |
133 |
if (storage -> ux_host_class_storage_bulk_in_endpoint == UX_NULL) |
143 |
|
|
{ |
144 |
|
|
|
145 |
|
|
/* Error trap. */ |
146 |
|
6 |
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_ENDPOINT_HANDLE_UNKNOWN); |
147 |
|
|
|
148 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
149 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_ENDPOINT_HANDLE_UNKNOWN, storage, 0, 0, UX_TRACE_ERRORS, 0, 0) |
150 |
|
|
|
151 |
|
6 |
return(UX_ENDPOINT_HANDLE_UNKNOWN); |
152 |
|
|
} |
153 |
|
|
|
154 |
|
|
/* Set default transfer timeout value. */ |
155 |
|
127 |
endpoint = storage -> ux_host_class_storage_bulk_in_endpoint; |
156 |
|
127 |
endpoint -> ux_endpoint_transfer_request.ux_transfer_request_timeout_value = |
157 |
|
|
UX_MS_TO_TICK_NON_ZERO(UX_HOST_CLASS_STORAGE_TRANSFER_TIMEOUT); |
158 |
|
127 |
endpoint = storage -> ux_host_class_storage_bulk_out_endpoint; |
159 |
|
127 |
endpoint -> ux_endpoint_transfer_request.ux_transfer_request_timeout_value = |
160 |
|
|
UX_MS_TO_TICK_NON_ZERO(UX_HOST_CLASS_STORAGE_TRANSFER_TIMEOUT); |
161 |
|
|
|
162 |
|
|
#ifdef UX_HOST_CLASS_STORAGE_INCLUDE_LEGACY_PROTOCOL_SUPPORT |
163 |
|
|
/* Search the Interrupt IN endpoint. This endpoint is optional and only valid for |
164 |
|
|
storage devices that use the CBI protocol. */ |
165 |
|
|
if (storage -> ux_host_class_storage_interface -> ux_interface_descriptor.bInterfaceProtocol == UX_HOST_CLASS_STORAGE_PROTOCOL_CBI) |
166 |
|
|
{ |
167 |
|
|
|
168 |
|
|
/* Yes, CBI protocol is present. Search for Interrupt IN endpoint. */ |
169 |
|
|
for (endpoint_index = 0; endpoint_index < storage -> ux_host_class_storage_interface -> ux_interface_descriptor.bNumEndpoints; |
170 |
|
|
endpoint_index++) |
171 |
|
|
{ |
172 |
|
|
|
173 |
|
|
/* Get an endpoint. */ |
174 |
|
|
status = _ux_host_stack_interface_endpoint_get(storage -> ux_host_class_storage_interface, endpoint_index, &endpoint); |
175 |
|
|
|
176 |
|
|
/* Check status. */ |
177 |
|
|
if (status != UX_SUCCESS) |
178 |
|
|
continue; |
179 |
|
|
|
180 |
|
|
/* Check if endpoint is Interrupt and IN. */ |
181 |
|
|
if (((endpoint -> ux_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) == UX_ENDPOINT_IN) && |
182 |
|
|
((endpoint -> ux_endpoint_descriptor.bmAttributes & UX_MASK_ENDPOINT_TYPE) == UX_INTERRUPT_ENDPOINT)) |
183 |
|
|
{ |
184 |
|
|
|
185 |
|
|
/* We have found the Interrupt IN endpoint, save it! */ |
186 |
|
|
storage -> ux_host_class_storage_interrupt_endpoint = endpoint; |
187 |
|
|
|
188 |
|
|
/* This transfer request always has the IN direction. */ |
189 |
|
|
endpoint -> ux_endpoint_transfer_request.ux_transfer_request_type = UX_REQUEST_IN; |
190 |
|
|
|
191 |
|
|
/* The size of the transfer is fixed to the endpoint size. */ |
192 |
|
|
endpoint -> ux_endpoint_transfer_request.ux_transfer_request_requested_length = |
193 |
|
|
endpoint -> ux_endpoint_transfer_request.ux_transfer_request_packet_length; |
194 |
|
|
|
195 |
|
|
/* Get some memory for this data transfer. */ |
196 |
|
|
endpoint -> ux_endpoint_transfer_request.ux_transfer_request_data_pointer = |
197 |
|
|
_ux_utility_memory_allocate(UX_SAFE_ALIGN, UX_CACHE_SAFE_MEMORY, |
198 |
|
|
endpoint -> ux_endpoint_descriptor.wMaxPacketSize); |
199 |
|
|
|
200 |
|
|
/* Check the memory pointer. */ |
201 |
|
|
if (endpoint -> ux_endpoint_transfer_request.ux_transfer_request_data_pointer == UX_NULL) |
202 |
|
|
return(UX_MEMORY_INSUFFICIENT); |
203 |
|
|
|
204 |
|
|
break; |
205 |
|
|
} |
206 |
|
|
} |
207 |
|
|
|
208 |
|
|
if (storage -> ux_host_class_storage_interrupt_endpoint == UX_NULL) |
209 |
|
|
{ |
210 |
|
|
|
211 |
|
|
/* Error trap. */ |
212 |
|
|
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_ENDPOINT_HANDLE_UNKNOWN); |
213 |
|
|
|
214 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
215 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_ENDPOINT_HANDLE_UNKNOWN, endpoint, 0, 0, UX_TRACE_ERRORS, 0, 0) |
216 |
|
|
|
217 |
|
|
return(UX_ENDPOINT_HANDLE_UNKNOWN); |
218 |
|
|
} |
219 |
|
|
} |
220 |
|
|
#endif |
221 |
|
|
|
222 |
|
|
/* Return successful completion. */ |
223 |
|
127 |
return(UX_SUCCESS); |
224 |
|
|
} |
225 |
|
|
|