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 |
|
|
/** Device CDC ACM Class */ |
19 |
|
|
/** */ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
/**************************************************************************/ |
22 |
|
|
|
23 |
|
|
#define UX_SOURCE_CODE |
24 |
|
|
|
25 |
|
|
|
26 |
|
|
/* Include necessary system files. */ |
27 |
|
|
|
28 |
|
|
#include "ux_api.h" |
29 |
|
|
#include "ux_device_class_cdc_acm.h" |
30 |
|
|
#include "ux_device_stack.h" |
31 |
|
|
|
32 |
|
|
|
33 |
|
|
/**************************************************************************/ |
34 |
|
|
/* */ |
35 |
|
|
/* FUNCTION RELEASE */ |
36 |
|
|
/* */ |
37 |
|
|
/* _ux_device_class_cdc_acm_control_request PORTABLE C */ |
38 |
|
|
/* 6.1.12 */ |
39 |
|
|
/* AUTHOR */ |
40 |
|
|
/* */ |
41 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
42 |
|
|
/* */ |
43 |
|
|
/* DESCRIPTION */ |
44 |
|
|
/* */ |
45 |
|
|
/* This function manages the based sent by the host on the control */ |
46 |
|
|
/* endpoints with a CLASS or VENDOR SPECIFIC type. */ |
47 |
|
|
/* */ |
48 |
|
|
/* INPUT */ |
49 |
|
|
/* */ |
50 |
|
|
/* cdc_acm Pointer to cdc_acm class */ |
51 |
|
|
/* */ |
52 |
|
|
/* OUTPUT */ |
53 |
|
|
/* */ |
54 |
|
|
/* None */ |
55 |
|
|
/* */ |
56 |
|
|
/* CALLS */ |
57 |
|
|
/* */ |
58 |
|
|
/* _ux_device_stack_transfer_request Transfer request */ |
59 |
|
|
/* */ |
60 |
|
|
/* CALLED BY */ |
61 |
|
|
/* */ |
62 |
|
|
/* CDC Class */ |
63 |
|
|
/* */ |
64 |
|
|
/**************************************************************************/ |
65 |
|
227 |
UINT _ux_device_class_cdc_acm_control_request(UX_SLAVE_CLASS_COMMAND *command) |
66 |
|
|
{ |
67 |
|
|
UX_SLAVE_CLASS_CDC_ACM *cdc_acm; |
68 |
|
|
UX_SLAVE_CLASS *class_ptr; |
69 |
|
|
UX_SLAVE_TRANSFER *transfer_request; |
70 |
|
|
UX_SLAVE_DEVICE *device; |
71 |
|
|
ULONG request; |
72 |
|
|
ULONG value; |
73 |
|
|
ULONG request_length; |
74 |
|
|
ULONG transmit_length; |
75 |
|
|
|
76 |
|
|
/* Get the class container. */ |
77 |
|
227 |
class_ptr = command -> ux_slave_class_command_class_ptr; |
78 |
|
|
|
79 |
|
|
/* Get the class instance in the container. */ |
80 |
|
227 |
cdc_acm = (UX_SLAVE_CLASS_CDC_ACM *) class_ptr -> ux_slave_class_instance; |
81 |
|
|
|
82 |
|
|
/* Get the pointer to the device. */ |
83 |
|
227 |
device = &_ux_system_slave -> ux_system_slave_device; |
84 |
|
|
|
85 |
|
|
/* Get the pointer to the transfer request associated with the control endpoint. */ |
86 |
|
227 |
transfer_request = &device -> ux_slave_device_control_endpoint.ux_slave_endpoint_transfer_request; |
87 |
|
|
|
88 |
|
|
/* Extract all necessary fields of the request. */ |
89 |
|
227 |
request = *(transfer_request -> ux_slave_transfer_request_setup + UX_SETUP_REQUEST); |
90 |
|
|
|
91 |
|
|
/* Extract all necessary fields of the value. */ |
92 |
|
227 |
value = _ux_utility_short_get(transfer_request -> ux_slave_transfer_request_setup + UX_SETUP_VALUE); |
93 |
|
|
|
94 |
|
|
/* Pickup the request length. */ |
95 |
|
227 |
request_length = _ux_utility_short_get(transfer_request -> ux_slave_transfer_request_setup + UX_SETUP_LENGTH); |
96 |
|
|
|
97 |
|
227 |
transmit_length = request_length ; |
98 |
|
|
|
99 |
|
|
/* Here we proceed only the standard request we know of at the device level. */ |
100 |
✓✓✓✓ ✓ |
227 |
switch (request) |
101 |
|
|
{ |
102 |
|
|
|
103 |
|
74 |
case UX_SLAVE_CLASS_CDC_ACM_SET_CONTROL_LINE_STATE: |
104 |
|
|
|
105 |
|
|
/* Reset current line state values. */ |
106 |
|
74 |
cdc_acm -> ux_slave_class_cdc_acm_data_dtr_state = 0; |
107 |
|
74 |
cdc_acm -> ux_slave_class_cdc_acm_data_rts_state = 0; |
108 |
|
|
|
109 |
|
|
/* Get the line state parameters from the host. DTR signal. */ |
110 |
✓✓ |
74 |
if (value & UX_SLAVE_CLASS_CDC_ACM_LINE_STATE_DTR) |
111 |
|
73 |
cdc_acm -> ux_slave_class_cdc_acm_data_dtr_state = UX_TRUE; |
112 |
|
|
|
113 |
|
|
/* Get the line state parameters from the host. RTS signal. */ |
114 |
✓✓ |
74 |
if (value & UX_SLAVE_CLASS_CDC_ACM_LINE_STATE_RTS) |
115 |
|
73 |
cdc_acm -> ux_slave_class_cdc_acm_data_rts_state = UX_TRUE; |
116 |
|
|
|
117 |
|
|
/* If there is a parameter change function call it. */ |
118 |
✓✓ |
74 |
if (cdc_acm -> ux_slave_class_cdc_acm_parameter.ux_slave_class_cdc_acm_parameter_change != UX_NULL) |
119 |
|
|
{ |
120 |
|
|
|
121 |
|
|
/* Invoke the application. */ |
122 |
|
68 |
cdc_acm -> ux_slave_class_cdc_acm_parameter.ux_slave_class_cdc_acm_parameter_change(cdc_acm); |
123 |
|
|
} |
124 |
|
|
|
125 |
|
74 |
break ; |
126 |
|
|
|
127 |
|
76 |
case UX_SLAVE_CLASS_CDC_ACM_GET_LINE_CODING: |
128 |
|
|
|
129 |
|
|
/* Setup the length appropriately. */ |
130 |
✓✓ |
76 |
if (request_length > UX_SLAVE_CLASS_CDC_ACM_LINE_CODING_RESPONSE_SIZE) |
131 |
|
1 |
transmit_length = UX_SLAVE_CLASS_CDC_ACM_LINE_CODING_RESPONSE_SIZE; |
132 |
|
|
|
133 |
|
|
/* Send the line coding default parameters back to the host. */ |
134 |
|
76 |
_ux_utility_long_put(transfer_request -> ux_slave_transfer_request_data_pointer + UX_SLAVE_CLASS_CDC_ACM_LINE_CODING_BAUDRATE_STRUCT, |
135 |
|
|
cdc_acm -> ux_slave_class_cdc_acm_baudrate); |
136 |
|
76 |
*(transfer_request -> ux_slave_transfer_request_data_pointer + UX_SLAVE_CLASS_CDC_ACM_LINE_CODING_STOP_BIT_STRUCT) = cdc_acm -> ux_slave_class_cdc_acm_stop_bit; |
137 |
|
76 |
*(transfer_request -> ux_slave_transfer_request_data_pointer + UX_SLAVE_CLASS_CDC_ACM_LINE_CODING_PARITY_STRUCT) = cdc_acm -> ux_slave_class_cdc_acm_parity; |
138 |
|
76 |
*(transfer_request -> ux_slave_transfer_request_data_pointer + UX_SLAVE_CLASS_CDC_ACM_LINE_CODING_DATA_BIT_STRUCT) = cdc_acm -> ux_slave_class_cdc_acm_data_bit; |
139 |
|
|
|
140 |
|
|
/* Set the phase of the transfer to data out. */ |
141 |
|
76 |
transfer_request -> ux_slave_transfer_request_phase = UX_TRANSFER_PHASE_DATA_OUT; |
142 |
|
|
|
143 |
|
|
/* Perform the data transfer. */ |
144 |
|
76 |
_ux_device_stack_transfer_request(transfer_request, transmit_length, request_length); |
145 |
|
76 |
break; |
146 |
|
|
|
147 |
|
73 |
case UX_SLAVE_CLASS_CDC_ACM_SET_LINE_CODING: |
148 |
|
|
|
149 |
|
|
/* Get the line coding parameters from the host. */ |
150 |
|
73 |
cdc_acm -> ux_slave_class_cdc_acm_baudrate = _ux_utility_long_get(transfer_request -> ux_slave_transfer_request_data_pointer + UX_SLAVE_CLASS_CDC_ACM_LINE_CODING_BAUDRATE_STRUCT); |
151 |
|
73 |
cdc_acm -> ux_slave_class_cdc_acm_stop_bit = *(transfer_request -> ux_slave_transfer_request_data_pointer + UX_SLAVE_CLASS_CDC_ACM_LINE_CODING_STOP_BIT_STRUCT); |
152 |
|
73 |
cdc_acm -> ux_slave_class_cdc_acm_parity = *(transfer_request -> ux_slave_transfer_request_data_pointer + UX_SLAVE_CLASS_CDC_ACM_LINE_CODING_PARITY_STRUCT); |
153 |
|
73 |
cdc_acm -> ux_slave_class_cdc_acm_data_bit = *(transfer_request -> ux_slave_transfer_request_data_pointer + UX_SLAVE_CLASS_CDC_ACM_LINE_CODING_DATA_BIT_STRUCT); |
154 |
|
|
|
155 |
|
|
/* If there is a parameter change function call it. */ |
156 |
✓✓ |
73 |
if (cdc_acm -> ux_slave_class_cdc_acm_parameter.ux_slave_class_cdc_acm_parameter_change != UX_NULL) |
157 |
|
|
{ |
158 |
|
|
|
159 |
|
|
/* Invoke the application. */ |
160 |
|
67 |
cdc_acm -> ux_slave_class_cdc_acm_parameter.ux_slave_class_cdc_acm_parameter_change(cdc_acm); |
161 |
|
|
} |
162 |
|
|
|
163 |
|
73 |
break ; |
164 |
|
|
|
165 |
|
3 |
case UX_SLAVE_CLASS_CDC_ACM_SEND_BREAK: |
166 |
|
|
|
167 |
|
|
/* SEND_BREAK has no data stage, wValue contains break duration in ms. |
168 |
|
|
0x0000 means stop break. |
169 |
|
|
0x0001-0xFFFE means break signal duration in ms. |
170 |
|
|
0xFFFF means indefinite break. */ |
171 |
|
3 |
cdc_acm -> ux_slave_class_cdc_acm_break_duration = (ULONG) value; |
172 |
|
|
|
173 |
|
|
/* If there is a parameter change function call it. */ |
174 |
✓✗ |
3 |
if (cdc_acm -> ux_slave_class_cdc_acm_parameter.ux_slave_class_cdc_acm_parameter_change != UX_NULL) |
175 |
|
3 |
cdc_acm -> ux_slave_class_cdc_acm_parameter.ux_slave_class_cdc_acm_parameter_change(cdc_acm); |
176 |
|
|
|
177 |
|
3 |
break; |
178 |
|
|
|
179 |
|
1 |
default: |
180 |
|
|
|
181 |
|
|
/* Unknown function. It's not handled. */ |
182 |
|
1 |
return(UX_ERROR); |
183 |
|
|
} |
184 |
|
|
|
185 |
|
|
/* It's handled. */ |
186 |
|
226 |
return(UX_SUCCESS); |
187 |
|
|
} |