GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_host_classes/src/ux_host_class_cdc_acm_command.c Lines: 23 27 85.2 %
Date: 2026-03-06 18:57:10 Branches: 5 7 71.4 %

Line Branch Exec Source
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
/**   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.3.0        */
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
/*    Application                                                         */
74
/*                                                                        */
75
/**************************************************************************/
76
230
UINT  _ux_host_class_cdc_acm_command(UX_HOST_CLASS_CDC_ACM *cdc_acm, ULONG command,
77
                                    ULONG value, UCHAR *data_buffer, ULONG data_length)
78
{
79
80
#if defined(UX_HOST_STANDALONE)
81
UX_INTERRUPT_SAVE_AREA
82
UX_DEVICE       *device;
83
#endif
84
85
UX_ENDPOINT     *control_endpoint;
86
UX_TRANSFER     *transfer_request;
87
UINT            status;
88
ULONG           request_direction;
89
90
91
    /* We need to get the default control endpoint transfer request pointer.  */
92
230
    control_endpoint =  &cdc_acm -> ux_host_class_cdc_acm_device -> ux_device_control_endpoint;
93
230
    transfer_request =  &control_endpoint -> ux_endpoint_transfer_request;
94
95
    /* Check the direction of the command.  */
96
230
    switch (command)
97
    {
98
99
152
    case UX_HOST_CLASS_CDC_ACM_REQ_SEND_ENCAPSULATED_COMMAND        :
100
    /* Fall through.  */
101
    case UX_HOST_CLASS_CDC_ACM_REQ_SET_COMM_FEATURE                 :
102
    /* Fall through.  */
103
    case UX_HOST_CLASS_CDC_ACM_REQ_CLEAR_COMM_FEATURE               :
104
    /* Fall through.  */
105
    case UX_HOST_CLASS_CDC_ACM_REQ_SET_AUX_LINE_STATE               :
106
    /* Fall through.  */
107
    case UX_HOST_CLASS_CDC_ACM_REQ_SET_HOOK_STATE                   :
108
    /* Fall through.  */
109
    case UX_HOST_CLASS_CDC_ACM_REQ_PULSE_SETUP                      :
110
    /* Fall through.  */
111
    case UX_HOST_CLASS_CDC_ACM_REQ_SEND_PULSE                       :
112
    /* Fall through.  */
113
    case UX_HOST_CLASS_CDC_ACM_REQ_SET_PUSLE_TIME                   :
114
    /* Fall through.  */
115
    case UX_HOST_CLASS_CDC_ACM_REQ_RING_AUX_JACK                    :
116
    /* Fall through.  */
117
    case UX_HOST_CLASS_CDC_ACM_REQ_SET_LINE_CODING                  :
118
    /* Fall through.  */
119
    case UX_HOST_CLASS_CDC_ACM_REQ_SET_LINE_STATE                   :
120
    /* Fall through.  */
121
    case UX_HOST_CLASS_CDC_ACM_REQ_SEND_BREAK                       :
122
    /* Fall through.  */
123
    case UX_HOST_CLASS_CDC_ACM_REQ_SET_RINGER_PARMS                 :
124
    /* Fall through.  */
125
    case UX_HOST_CLASS_CDC_ACM_REQ_SET_OPERATION_PARMS              :
126
    /* Fall through.  */
127
    case UX_HOST_CLASS_CDC_ACM_REQ_SET_LINE_PARMS                   :
128
129
        /* Direction is out */
130
152
        request_direction = UX_REQUEST_OUT;
131
152
        break;
132
133
134
77
    case UX_HOST_CLASS_CDC_ACM_REQ_GET_ENCAPSULATED_COMMAND         :
135
    /* Fall through.  */
136
    case UX_HOST_CLASS_CDC_ACM_REQ_GET_COMM_FEATURE                 :
137
    /* Fall through.  */
138
    case UX_HOST_CLASS_CDC_ACM_REQ_GET_LINE_CODING                  :
139
    /* Fall through.  */
140
    case UX_HOST_CLASS_CDC_ACM_REQ_GET_RINGER_PARMS                 :
141
    /* Fall through.  */
142
    case UX_HOST_CLASS_CDC_ACM_REQ_GET_OPERATION_PARMS              :
143
    /* Fall through.  */
144
    case UX_HOST_CLASS_CDC_ACM_REQ_GET_LINE_PARMS                   :
145
146
        /* Direction is in */
147
77
        request_direction = UX_REQUEST_IN;
148
77
        break;
149
150
151
1
    default :
152
153
1
        return(UX_ERROR);
154
155
    }
156
157
#if defined(UX_HOST_STANDALONE)
158
159
    /* Get device instance.  */
160
    device = cdc_acm -> ux_host_class_cdc_acm_device;
161
162
    /* Check device EP0 transfer lock flag.  */
163
    UX_DISABLE
164
    if (device -> ux_device_flags & UX_DEVICE_FLAG_LOCK)
165
    {
166
        UX_RESTORE
167
        return(UX_STATE_LOCK);
168
    }
169
170
    /* Lock the device for EP0 transfer.  */
171
    device -> ux_device_flags |= UX_DEVICE_FLAG_LOCK;
172
    transfer_request -> ux_transfer_request_flags |= UX_TRANSFER_FLAG_AUTO_DEVICE_UNLOCK;
173
    UX_RESTORE
174
#else
175
176
    /* Protect the control endpoint semaphore here.  It will be unprotected in the
177
       transfer request function.  */
178
229
    status =  _ux_host_semaphore_get(&cdc_acm -> ux_host_class_cdc_acm_device -> ux_device_protection_semaphore, UX_WAIT_FOREVER);
179
180
    /* Check for status.  */
181
229
    if (status != UX_SUCCESS)
182
183
        /* Something went wrong. */
184
1
        return(status);
185
#endif
186
187
    /* Create a transfer_request for the request.  */
188
228
    transfer_request -> ux_transfer_request_data_pointer     =  data_buffer;
189
228
    transfer_request -> ux_transfer_request_requested_length =  data_length;
190
228
    transfer_request -> ux_transfer_request_function         =  command;
191
228
    transfer_request -> ux_transfer_request_type             =  request_direction | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE;
192
228
    transfer_request -> ux_transfer_request_value            =  value;
193
228
    transfer_request -> ux_transfer_request_index            =  cdc_acm -> ux_host_class_cdc_acm_interface -> ux_interface_descriptor.bInterfaceNumber;
194
195
    /* Send request to HCD layer.  */
196
228
    status =  _ux_host_stack_transfer_request(transfer_request);
197
198
    /* Return completion status.  */
199
227
    return(status);
200
}
201
202
203
/**************************************************************************/
204
/*                                                                        */
205
/*  FUNCTION                                               RELEASE        */
206
/*                                                                        */
207
/*    _uxe_host_class_cdc_acm_command                     PORTABLE C      */
208
/*                                                           6.3.0        */
209
/*  AUTHOR                                                                */
210
/*                                                                        */
211
/*    Chaoqiong Xiao, Microsoft Corporation                               */
212
/*                                                                        */
213
/*  DESCRIPTION                                                           */
214
/*                                                                        */
215
/*    This function checks errors in CDC ACM command function call.       */
216
/*                                                                        */
217
/*  INPUT                                                                 */
218
/*                                                                        */
219
/*    cdc_acm                               Pointer to CDC ACM class      */
220
/*    command                               command value                 */
221
/*    value                                 value to be sent in the       */
222
/*                                          command request               */
223
/*    data_buffer                           buffer to be sent             */
224
/*    data_length                           length of the buffer to send  */
225
/*                                                                        */
226
/*  OUTPUT                                                                */
227
/*                                                                        */
228
/*    Status                                                              */
229
/*                                                                        */
230
/*  CALLS                                                                 */
231
/*                                                                        */
232
/*    _ux_host_class_cdc_acm_command        Send CDC ACM request          */
233
/*                                                                        */
234
/*  CALLED BY                                                             */
235
/*                                                                        */
236
/*    Application                                                         */
237
/*    CDC ACM Class                                                       */
238
/*                                                                        */
239
/**************************************************************************/
240
UINT  _uxe_host_class_cdc_acm_command(UX_HOST_CLASS_CDC_ACM *cdc_acm, ULONG command,
241
                                    ULONG value, UCHAR *data_buffer, ULONG data_length)
242
{
243
244
    /* Sanity check.  */
245
    if (cdc_acm == UX_NULL)
246
        return(UX_INVALID_PARAMETER);
247
248
    /* Invoke CDC ACM command send function.  */
249
    return(_ux_host_class_cdc_acm_command(cdc_acm, command, value, data_buffer, data_length));
250
}