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 Data Pump 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_dpump.h"
30 #include "ux_host_stack.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _ux_host_class_dpump_endpoints_get PORTABLE C */
38 /* 6.1.10 */
39 /* AUTHOR */
40 /* */
41 /* Chaoqiong Xiao, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function search for the handle of the bulk out and bulk in */
46 /* endpoints. */
47 /* */
48 /* INPUT */
49 /* */
50 /* dpump Pointer to dpump class */
51 /* */
52 /* OUTPUT */
53 /* */
54 /* Completion Status */
55 /* */
56 /* CALLS */
57 /* */
58 /* _ux_host_stack_interface_endpoint_get Get interface endpoint */
59 /* */
60 /* CALLED BY */
61 /* */
62 /* _ux_host_class_dpump_activate Activate dpump class */
63 /* */
64 /* RELEASE HISTORY */
65 /* */
66 /* DATE NAME DESCRIPTION */
67 /* */
68 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
69 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
70 /* resulting in version 6.1 */
71 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
72 /* added standalone support, */
73 /* resulting in version 6.1.10 */
74 /* */
75 /**************************************************************************/
_ux_host_class_dpump_endpoints_get(UX_HOST_CLASS_DPUMP * dpump)76 UINT _ux_host_class_dpump_endpoints_get(UX_HOST_CLASS_DPUMP *dpump)
77 {
78
79 UINT status;
80 UINT endpoint_index;
81 UX_ENDPOINT *endpoint;
82
83
84 /* Search the bulk OUT endpoint. It is attached to the interface container. */
85 for (endpoint_index = 0; endpoint_index < dpump -> ux_host_class_dpump_interface -> ux_interface_descriptor.bNumEndpoints;
86 endpoint_index++)
87 {
88
89 /* Get interface endpoint. */
90 status = _ux_host_stack_interface_endpoint_get(dpump -> ux_host_class_dpump_interface, endpoint_index, &endpoint);
91
92 /* Check the completion status. */
93 if (status == UX_SUCCESS)
94 {
95
96 /* Check if endpoint is bulk and OUT. */
97 if (((endpoint -> ux_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) == UX_ENDPOINT_OUT) &&
98 ((endpoint -> ux_endpoint_descriptor.bmAttributes & UX_MASK_ENDPOINT_TYPE) == UX_BULK_ENDPOINT))
99 {
100
101 /* This transfer_request always have the OUT direction. */
102 endpoint -> ux_endpoint_transfer_request.ux_transfer_request_type = UX_REQUEST_OUT;
103
104 /* Setup default timeout value. */
105 endpoint -> ux_endpoint_transfer_request.ux_transfer_request_timeout_value =
106 UX_HOST_CLASS_DPUMP_CLASS_TRANSFER_TIMEOUT;
107
108 /* We have found the bulk endpoint, save it. */
109 dpump -> ux_host_class_dpump_bulk_out_endpoint = endpoint;
110 break;
111 }
112 }
113 }
114
115 /* The bulk out endpoint is mandatory. */
116 if (dpump -> ux_host_class_dpump_bulk_out_endpoint == UX_NULL)
117 {
118
119 /* Error trap. */
120 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_ENDPOINT_HANDLE_UNKNOWN);
121
122 /* If trace is enabled, insert this event into the trace buffer. */
123 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_ENDPOINT_HANDLE_UNKNOWN, dpump, 0, 0, UX_TRACE_ERRORS, 0, 0)
124
125 return(UX_ENDPOINT_HANDLE_UNKNOWN);
126 }
127
128 /* Search the bulk IN endpoint. It is attached to the interface container. */
129
130 for (endpoint_index = 0; endpoint_index < dpump -> ux_host_class_dpump_interface -> ux_interface_descriptor.bNumEndpoints;
131 endpoint_index++)
132 {
133
134 /* Get the endpoint handle. */
135 status = _ux_host_stack_interface_endpoint_get(dpump -> ux_host_class_dpump_interface, endpoint_index, &endpoint);
136
137 /* Check the completion status. */
138 if (status == UX_SUCCESS)
139 {
140
141 /* Check if endpoint is bulk and IN. */
142 if (((endpoint -> ux_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) == UX_ENDPOINT_IN) &&
143 ((endpoint -> ux_endpoint_descriptor.bmAttributes & UX_MASK_ENDPOINT_TYPE) == UX_BULK_ENDPOINT))
144 {
145
146 /* This transfer_request always have the IN direction. */
147 endpoint -> ux_endpoint_transfer_request.ux_transfer_request_type = UX_REQUEST_IN;
148
149 /* Setup default timeout value. */
150 endpoint -> ux_endpoint_transfer_request.ux_transfer_request_timeout_value =
151 UX_HOST_CLASS_DPUMP_CLASS_TRANSFER_TIMEOUT;
152
153 /* We have found the bulk endpoint, save it. */
154 dpump -> ux_host_class_dpump_bulk_in_endpoint = endpoint;
155 break;
156 }
157 }
158 }
159
160 /* The bulk in endpoint is mandatory. */
161 if (dpump -> ux_host_class_dpump_bulk_in_endpoint == UX_NULL)
162 {
163
164 /* Error trap. */
165 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_ENDPOINT_HANDLE_UNKNOWN);
166
167 /* If trace is enabled, insert this event into the trace buffer. */
168 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_ENDPOINT_HANDLE_UNKNOWN, dpump, 0, 0, UX_TRACE_ERRORS, 0, 0)
169
170 return(UX_ENDPOINT_HANDLE_UNKNOWN);
171 }
172
173 /* All endpoints have been mounted. */
174 return(UX_SUCCESS);
175 }
176
177