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 /** CDC ACM 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_cdc_acm.h"
30 #include "ux_host_stack.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _ux_host_class_cdc_acm_command PORTABLE C */
38 /* 6.1.10 */
39 /* AUTHOR */
40 /* */
41 /* Chaoqiong Xiao, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function will send a command to the ACM device. The command */
46 /* can be one of the following : */
47 /* SET_CONTROL */
48 /* SET_LINE */
49 /* SEND_BREAK */
50 /* */
51 /* */
52 /* INPUT */
53 /* */
54 /* acm Pointer to acm class */
55 /* command command value */
56 /* value value to be sent in the */
57 /* command request */
58 /* data_buffer buffer to be sent */
59 /* data_length length of the buffer to send */
60 /* */
61 /* */
62 /* OUTPUT */
63 /* */
64 /* Completion Status */
65 /* */
66 /* CALLS */
67 /* */
68 /* _ux_host_stack_transfer_request Process transfer request */
69 /* _ux_host_semaphore_get Get semaphore */
70 /* */
71 /* CALLED BY */
72 /* */
73 /* Storage Class */
74 /* */
75 /* RELEASE HISTORY */
76 /* */
77 /* DATE NAME DESCRIPTION */
78 /* */
79 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
80 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
81 /* resulting in version 6.1 */
82 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
83 /* added standalone support, */
84 /* resulting in version 6.1.10 */
85 /* */
86 /**************************************************************************/
_ux_host_class_cdc_acm_command(UX_HOST_CLASS_CDC_ACM * cdc_acm,ULONG command,ULONG value,UCHAR * data_buffer,ULONG data_length)87 UINT _ux_host_class_cdc_acm_command(UX_HOST_CLASS_CDC_ACM *cdc_acm, ULONG command,
88 ULONG value, UCHAR *data_buffer, ULONG data_length)
89 {
90
91 #if defined(UX_HOST_STANDALONE)
92 UX_INTERRUPT_SAVE_AREA
93 UX_DEVICE *device;
94 #endif
95
96 UX_ENDPOINT *control_endpoint;
97 UX_TRANSFER *transfer_request;
98 UINT status;
99 ULONG request_direction;
100
101
102 /* We need to get the default control endpoint transfer request pointer. */
103 control_endpoint = &cdc_acm -> ux_host_class_cdc_acm_device -> ux_device_control_endpoint;
104 transfer_request = &control_endpoint -> ux_endpoint_transfer_request;
105
106 /* Check the direction of the command. */
107 switch (command)
108 {
109
110 case UX_HOST_CLASS_CDC_ACM_REQ_SEND_ENCAPSULATED_COMMAND :
111 /* Fall through. */
112 case UX_HOST_CLASS_CDC_ACM_REQ_SET_COMM_FEATURE :
113 /* Fall through. */
114 case UX_HOST_CLASS_CDC_ACM_REQ_CLEAR_COMM_FEATURE :
115 /* Fall through. */
116 case UX_HOST_CLASS_CDC_ACM_REQ_SET_AUX_LINE_STATE :
117 /* Fall through. */
118 case UX_HOST_CLASS_CDC_ACM_REQ_SET_HOOK_STATE :
119 /* Fall through. */
120 case UX_HOST_CLASS_CDC_ACM_REQ_PULSE_SETUP :
121 /* Fall through. */
122 case UX_HOST_CLASS_CDC_ACM_REQ_SEND_PULSE :
123 /* Fall through. */
124 case UX_HOST_CLASS_CDC_ACM_REQ_SET_PUSLE_TIME :
125 /* Fall through. */
126 case UX_HOST_CLASS_CDC_ACM_REQ_RING_AUX_JACK :
127 /* Fall through. */
128 case UX_HOST_CLASS_CDC_ACM_REQ_SET_LINE_CODING :
129 /* Fall through. */
130 case UX_HOST_CLASS_CDC_ACM_REQ_SET_LINE_STATE :
131 /* Fall through. */
132 case UX_HOST_CLASS_CDC_ACM_REQ_SEND_BREAK :
133 /* Fall through. */
134 case UX_HOST_CLASS_CDC_ACM_REQ_SET_RINGER_PARMS :
135 /* Fall through. */
136 case UX_HOST_CLASS_CDC_ACM_REQ_SET_OPERATION_PARMS :
137 /* Fall through. */
138 case UX_HOST_CLASS_CDC_ACM_REQ_SET_LINE_PARMS :
139
140 /* Direction is out */
141 request_direction = UX_REQUEST_OUT;
142 break;
143
144
145 case UX_HOST_CLASS_CDC_ACM_REQ_GET_ENCAPSULATED_COMMAND :
146 /* Fall through. */
147 case UX_HOST_CLASS_CDC_ACM_REQ_GET_COMM_FEATURE :
148 /* Fall through. */
149 case UX_HOST_CLASS_CDC_ACM_REQ_GET_LINE_CODING :
150 /* Fall through. */
151 case UX_HOST_CLASS_CDC_ACM_REQ_GET_RINGER_PARMS :
152 /* Fall through. */
153 case UX_HOST_CLASS_CDC_ACM_REQ_GET_OPERATION_PARMS :
154 /* Fall through. */
155 case UX_HOST_CLASS_CDC_ACM_REQ_GET_LINE_PARMS :
156
157 /* Direction is in */
158 request_direction = UX_REQUEST_IN;
159 break;
160
161
162 default :
163
164 return(UX_ERROR);
165
166 }
167
168 #if defined(UX_HOST_STANDALONE)
169
170 /* Get device instance. */
171 device = cdc_acm -> ux_host_class_cdc_acm_device;
172
173 /* Check device EP0 transfer lock flag. */
174 UX_DISABLE
175 if (device -> ux_device_flags & UX_DEVICE_FLAG_LOCK)
176 {
177 UX_RESTORE
178 return(UX_STATE_LOCK);
179 }
180
181 /* Lock the device for EP0 transfer. */
182 device -> ux_device_flags |= UX_DEVICE_FLAG_LOCK;
183 transfer_request -> ux_transfer_request_flags |= UX_TRANSFER_FLAG_AUTO_DEVICE_UNLOCK;
184 UX_RESTORE
185 #else
186
187 /* Protect the control endpoint semaphore here. It will be unprotected in the
188 transfer request function. */
189 status = _ux_host_semaphore_get(&cdc_acm -> ux_host_class_cdc_acm_device -> ux_device_protection_semaphore, UX_WAIT_FOREVER);
190
191 /* Check for status. */
192 if (status != UX_SUCCESS)
193
194 /* Something went wrong. */
195 return(status);
196 #endif
197
198 /* Create a transfer_request for the request. */
199 transfer_request -> ux_transfer_request_data_pointer = data_buffer;
200 transfer_request -> ux_transfer_request_requested_length = data_length;
201 transfer_request -> ux_transfer_request_function = command;
202 transfer_request -> ux_transfer_request_type = request_direction | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE;
203 transfer_request -> ux_transfer_request_value = value;
204 transfer_request -> ux_transfer_request_index = cdc_acm -> ux_host_class_cdc_acm_interface -> ux_interface_descriptor.bInterfaceNumber;
205
206 /* Send request to HCD layer. */
207 status = _ux_host_stack_transfer_request(transfer_request);
208
209 /* Return completion status. */
210 return(status);
211 }
212