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 /** Generic Serial Host module 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_gser.h"
30 #include "ux_host_stack.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _ux_host_class_gser_endpoints_get PORTABLE C */
38 /* 6.1 */
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. The Generic Serial USB device has multiple interfaces. */
47 /* */
48 /* INPUT */
49 /* */
50 /* gser Pointer to gser 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_gser_activate Activate gser 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 /* */
72 /**************************************************************************/
_ux_host_class_gser_endpoints_get(UX_HOST_CLASS_GSER * gser)73 UINT _ux_host_class_gser_endpoints_get(UX_HOST_CLASS_GSER *gser)
74 {
75
76 UINT status;
77 UX_ENDPOINT *endpoint;
78 ULONG endpoint_index;
79 ULONG interface_index;
80
81 /* Search the endpoints on all interfaces. */
82 for (interface_index = 0; interface_index < UX_HOST_CLASS_GSER_INTERFACE_NUMBER; interface_index++)
83 {
84
85 /* Search the bulk OUT endpoint. It is attached to the interface container. */
86 for (endpoint_index = 0; endpoint_index < gser -> ux_host_class_gser_interface_array[interface_index].ux_host_class_gser_interface -> ux_interface_descriptor.bNumEndpoints;
87 endpoint_index++)
88 {
89
90 /* Get interface endpoint. */
91 status = _ux_host_stack_interface_endpoint_get(gser -> ux_host_class_gser_interface_array[interface_index].ux_host_class_gser_interface, endpoint_index, &endpoint);
92
93 /* Check the completion status. */
94 if (status == UX_SUCCESS)
95 {
96
97 /* Check if endpoint is bulk and OUT. */
98 if (((endpoint -> ux_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) == UX_ENDPOINT_OUT) &&
99 ((endpoint -> ux_endpoint_descriptor.bmAttributes & UX_MASK_ENDPOINT_TYPE) == UX_BULK_ENDPOINT))
100 {
101
102 /* This transfer_request always have the OUT direction. */
103 endpoint -> ux_endpoint_transfer_request.ux_transfer_request_type = UX_REQUEST_OUT;
104
105 /* We have found the bulk endpoint, save it. */
106 gser -> ux_host_class_gser_interface_array[interface_index].ux_host_class_gser_bulk_out_endpoint = endpoint;
107 break;
108 }
109 }
110 }
111
112 /* The bulk out endpoint is mandatory. */
113 if (gser -> ux_host_class_gser_interface_array[interface_index].ux_host_class_gser_bulk_out_endpoint == UX_NULL)
114 {
115
116 /* Error trap. */
117 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_ENDPOINT_HANDLE_UNKNOWN);
118
119 /* If trace is enabled, insert this event into the trace buffer. */
120 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_ENDPOINT_HANDLE_UNKNOWN, gser, 0, 0, UX_TRACE_ERRORS, 0, 0)
121
122 return(UX_ENDPOINT_HANDLE_UNKNOWN);
123 }
124
125 /* Search the bulk IN endpoint. It is attached to the interface container. */
126
127 for (endpoint_index = 0; endpoint_index < gser -> ux_host_class_gser_interface_array[interface_index].ux_host_class_gser_interface -> ux_interface_descriptor.bNumEndpoints;
128 endpoint_index++)
129 {
130
131 /* Get the endpoint handle. */
132 status = _ux_host_stack_interface_endpoint_get(gser -> ux_host_class_gser_interface_array[interface_index].ux_host_class_gser_interface, endpoint_index, &endpoint);
133
134 /* Check the completion status. */
135 if (status == UX_SUCCESS)
136 {
137
138 /* Check if endpoint is bulk and IN. */
139 if (((endpoint -> ux_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) == UX_ENDPOINT_IN) &&
140 ((endpoint -> ux_endpoint_descriptor.bmAttributes & UX_MASK_ENDPOINT_TYPE) == UX_BULK_ENDPOINT))
141 {
142
143 /* This transfer_request always have the IN direction. */
144 endpoint -> ux_endpoint_transfer_request.ux_transfer_request_type = UX_REQUEST_IN;
145
146 /* We have found the bulk endpoint, save it. */
147 gser -> ux_host_class_gser_interface_array[interface_index].ux_host_class_gser_bulk_in_endpoint = endpoint;
148 break;
149 }
150 }
151 }
152
153 /* The bulk in endpoint is mandatory. */
154 if (gser -> ux_host_class_gser_interface_array[interface_index].ux_host_class_gser_bulk_in_endpoint == UX_NULL)
155 {
156
157 /* If trace is enabled, insert this event into the trace buffer. */
158 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_ENDPOINT_HANDLE_UNKNOWN, gser, 0, 0, UX_TRACE_ERRORS, 0, 0)
159
160 return(UX_ENDPOINT_HANDLE_UNKNOWN);
161 }
162 }
163 /* All endpoints have been mounted. */
164 return(UX_SUCCESS);
165 }
166
167