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 Sierra Wireless AR 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_swar.h"
30 #include "ux_host_stack.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _ux_host_class_swar_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 Sierra Wireless USB device has multiple interfaces. */
47 /* We first need to find the interface which uses Bulk endpoints to */
48 /* carry data. */
49 /* */
50 /* INPUT */
51 /* */
52 /* swar Pointer to swar class */
53 /* */
54 /* OUTPUT */
55 /* */
56 /* Completion Status */
57 /* */
58 /* CALLS */
59 /* */
60 /* _ux_host_stack_interface_endpoint_get Get interface endpoint */
61 /* */
62 /* CALLED BY */
63 /* */
64 /* _ux_host_class_swar_activate Activate swar class */
65 /* */
66 /* RELEASE HISTORY */
67 /* */
68 /* DATE NAME DESCRIPTION */
69 /* */
70 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
71 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
72 /* resulting in version 6.1 */
73 /* */
74 /**************************************************************************/
_ux_host_class_swar_endpoints_get(UX_HOST_CLASS_SWAR * swar)75 UINT _ux_host_class_swar_endpoints_get(UX_HOST_CLASS_SWAR *swar)
76 {
77
78 UINT status;
79 UX_ENDPOINT *endpoint;
80 UINT endpoint_index;
81
82 /* Search the bulk OUT endpoint. It is attached to the interface container. */
83 for (endpoint_index = 0; endpoint_index < swar -> ux_host_class_swar_interface -> ux_interface_descriptor.bNumEndpoints;
84 endpoint_index++)
85 {
86
87 /* Get interface endpoint. */
88 status = _ux_host_stack_interface_endpoint_get(swar -> ux_host_class_swar_interface, endpoint_index, &endpoint);
89
90 /* Check the completion status. */
91 if (status == UX_SUCCESS)
92 {
93
94 /* Check if endpoint is bulk and OUT. */
95 if (((endpoint -> ux_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) == UX_ENDPOINT_OUT) &&
96 ((endpoint -> ux_endpoint_descriptor.bmAttributes & UX_MASK_ENDPOINT_TYPE) == UX_BULK_ENDPOINT))
97 {
98
99 /* This transfer_request always have the OUT direction. */
100 endpoint -> ux_endpoint_transfer_request.ux_transfer_request_type = UX_REQUEST_OUT;
101
102 /* We have found the bulk endpoint, save it. */
103 swar -> ux_host_class_swar_bulk_out_endpoint = endpoint;
104 break;
105 }
106 }
107 }
108
109 /* The bulk out endpoint is mandatory. */
110 if (swar -> ux_host_class_swar_bulk_out_endpoint == UX_NULL)
111 {
112
113 /* Error trap. */
114 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_ENDPOINT_HANDLE_UNKNOWN);
115
116 /* If trace is enabled, insert this event into the trace buffer. */
117 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_ENDPOINT_HANDLE_UNKNOWN, swar, 0, 0, UX_TRACE_ERRORS, 0, 0)
118
119 return(UX_ENDPOINT_HANDLE_UNKNOWN);
120 }
121
122 /* Search the bulk IN endpoint. It is attached to the interface container. */
123
124 for (endpoint_index = 0; endpoint_index < swar -> ux_host_class_swar_interface -> ux_interface_descriptor.bNumEndpoints;
125 endpoint_index++)
126 {
127
128 /* Get the endpoint handle. */
129 status = _ux_host_stack_interface_endpoint_get(swar -> ux_host_class_swar_interface, endpoint_index, &endpoint);
130
131 /* Check the completion status. */
132 if (status == UX_SUCCESS)
133 {
134
135 /* Check if endpoint is bulk and IN. */
136 if (((endpoint -> ux_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) == UX_ENDPOINT_IN) &&
137 ((endpoint -> ux_endpoint_descriptor.bmAttributes & UX_MASK_ENDPOINT_TYPE) == UX_BULK_ENDPOINT))
138 {
139
140 /* This transfer_request always have the IN direction. */
141 endpoint -> ux_endpoint_transfer_request.ux_transfer_request_type = UX_REQUEST_IN;
142
143 /* We have found the bulk endpoint, save it. */
144 swar -> ux_host_class_swar_bulk_in_endpoint = endpoint;
145 break;
146 }
147 }
148 }
149
150 /* The bulk in endpoint is mandatory. */
151 if (swar -> ux_host_class_swar_bulk_in_endpoint == UX_NULL)
152 {
153
154 /* Error trap. */
155 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_ENDPOINT_HANDLE_UNKNOWN);
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, swar, 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