GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_device_classes/src/ux_device_class_cdc_acm_write_with_callback.c Lines: 14 18 77.8 %
Date: 2026-03-06 18:57:10 Branches: 6 12 50.0 %

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
/** USBX Component                                                        */
16
/**                                                                       */
17
/**   Device CDC Class                                                    */
18
/**                                                                       */
19
/**************************************************************************/
20
/**************************************************************************/
21
22
#define UX_SOURCE_CODE
23
24
25
/* Include necessary system files.  */
26
27
#include "ux_api.h"
28
#include "ux_device_class_cdc_acm.h"
29
#include "ux_device_stack.h"
30
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _ux_device_class_cdc_acm_write_with_callback        PORTABLE C      */
37
/*                                                           6.3.0        */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Chaoqiong Xiao, Microsoft Corporation                               */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function writes to  the CDC class with callback                */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    cdc_acm                               Address of cdc_acm class      */
49
/*                                                instance                */
50
/*    buffer                                Pointer to data to write      */
51
/*    requested_length                      Length of bytes to write      */
52
/*                                                                        */
53
/*  OUTPUT                                                                */
54
/*                                                                        */
55
/*    None                                                                */
56
/*                                                                        */
57
/*  CALLS                                                                 */
58
/*                                                                        */
59
/*   _ux_device_stack_transfer_request                                    */
60
/*                                                                        */
61
/*  CALLED BY                                                             */
62
/*                                                                        */
63
/*    Application                                                         */
64
/*                                                                        */
65
/**************************************************************************/
66
10
UINT _ux_device_class_cdc_acm_write_with_callback(UX_SLAVE_CLASS_CDC_ACM *cdc_acm, UCHAR *buffer,
67
                                ULONG requested_length)
68
{
69
#ifdef UX_DEVICE_CLASS_CDC_ACM_TRANSMISSION_DISABLE
70
    UX_PARAMETER_NOT_USED(cdc_acm);
71
    UX_PARAMETER_NOT_USED(buffer);
72
    UX_PARAMETER_NOT_USED(requested_length);
73
    return(UX_FUNCTION_NOT_SUPPORTED);
74
#else
75
UX_SLAVE_DEVICE             *device;
76
UINT                        status;
77
78
    /* If trace is enabled, insert this event into the trace buffer.  */
79
    UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_CLASS_CDC_ACM_WRITE, cdc_acm, buffer, requested_length, 0, UX_TRACE_DEVICE_CLASS_EVENTS, 0, 0)
80
81
    /* Get the pointer to the device.  */
82
10
    device =  &_ux_system_slave -> ux_system_slave_device;
83
84
    /* As long as the device is in the CONFIGURED state.  */
85
10
    if (device -> ux_slave_device_state != UX_DEVICE_CONFIGURED)
86
    {
87
88
        /* Error trap. */
89
1
        _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_CONFIGURATION_HANDLE_UNKNOWN);
90
91
        /* If trace is enabled, insert this event into the trace buffer.  */
92
        UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_CONFIGURATION_HANDLE_UNKNOWN, device, 0, 0, UX_TRACE_ERRORS, 0, 0)
93
94
        /* Cannot proceed with command, the interface is down.  */
95
1
        return(UX_CONFIGURATION_HANDLE_UNKNOWN);
96
    }
97
98
    /* Are we already in transmission mode ?  */
99
9
    if (cdc_acm -> ux_slave_class_cdc_acm_transmission_status != UX_TRUE)
100
    {
101
102
        /* We should not to that ! */
103
1
        return(UX_ERROR);
104
105
    }
106
107
    /* Have we already scheduled a buffer ?   */
108
8
    if (cdc_acm -> ux_slave_class_cdc_acm_scheduled_write == UX_TRUE)
109
    {
110
111
        /* We should not to that ! */
112
1
        return(UX_ERROR);
113
    }
114
115
#if defined(UX_DEVICE_STANDALONE)
116
117
    /* Save the length to be sent. */
118
    cdc_acm -> ux_device_class_cdc_acm_write_requested_length = requested_length;
119
120
    /* And the buffer pointer.  */
121
    cdc_acm -> ux_device_class_cdc_acm_write_buffer = buffer;
122
123
    /* Schedule a transmission.  */
124
    cdc_acm -> ux_slave_class_cdc_acm_scheduled_write = UX_TRUE;
125
126
    /* Status success.  */
127
    status = (UX_SUCCESS);
128
#else
129
130
    /* Save the length to be sent. */
131
7
    cdc_acm -> ux_slave_class_cdc_acm_callback_total_length = requested_length;
132
133
    /* And the buffer pointer.  */
134
7
    cdc_acm -> ux_slave_class_cdc_acm_callback_data_pointer = buffer;
135
136
    /* Schedule a transmission.  */
137
7
    cdc_acm -> ux_slave_class_cdc_acm_scheduled_write = UX_TRUE;
138
139
    /* Invoke the bulkin thread by sending a flag .  */
140
7
    status = _ux_device_event_flags_set(&cdc_acm -> ux_slave_class_cdc_acm_event_flags_group, UX_DEVICE_CLASS_CDC_ACM_WRITE_EVENT, UX_OR);
141
#endif
142
143
    /* Simply return the last function result.  When we leave this function, the deferred writing has been scheduled. */
144
7
    return(status);
145
#endif
146
}
147
148
/**************************************************************************/
149
/*                                                                        */
150
/*  FUNCTION                                               RELEASE        */
151
/*                                                                        */
152
/*    _uxe_device_class_cdc_acm_write_with_callback       PORTABLE C      */
153
/*                                                           6.3.0        */
154
/*  AUTHOR                                                                */
155
/*                                                                        */
156
/*    Yajun Xia, Microsoft Corporation                                    */
157
/*                                                                        */
158
/*  DESCRIPTION                                                           */
159
/*                                                                        */
160
/*    This function checks errors in CDC ACM class write with             */
161
/*    callback function.                                                  */
162
/*                                                                        */
163
/*  INPUT                                                                 */
164
/*                                                                        */
165
/*    cdc_acm                               Address of cdc_acm class      */
166
/*                                                instance                */
167
/*    buffer                                Pointer to data to write      */
168
/*    requested_length                      Length of bytes to write      */
169
/*                                                                        */
170
/*  OUTPUT                                                                */
171
/*                                                                        */
172
/*    None                                                                */
173
/*                                                                        */
174
/*  CALLS                                                                 */
175
/*                                                                        */
176
/*   _ux_device_class_cdc_acm_write_with_callback                         */
177
/*                                                                        */
178
/*  CALLED BY                                                             */
179
/*                                                                        */
180
/*    Application                                                         */
181
/*                                                                        */
182
/**************************************************************************/
183
UINT _uxe_device_class_cdc_acm_write_with_callback(UX_SLAVE_CLASS_CDC_ACM *cdc_acm, UCHAR *buffer,
184
                                                   ULONG requested_length)
185
{
186
187
    /* Sanity checks.  */
188
    if ((cdc_acm == UX_NULL) || ((buffer == UX_NULL) && (requested_length > 0)))
189
    {
190
        return (UX_INVALID_PARAMETER);
191
    }
192
193
    return (_ux_device_class_cdc_acm_write_with_callback(cdc_acm, buffer, requested_length));
194
}