GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_host_classes/src/ux_host_class_cdc_acm_reception_start.c Lines: 20 24 83.3 %
Date: 2026-03-06 18:57:10 Branches: 6 10 60.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
/**                                                                       */
16
/** USBX Component                                                        */
17
/**                                                                       */
18
/**   ACM CDC 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_reception_start              PORTABLE C      */
38
/*                                                           6.1          */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Chaoqiong Xiao, Microsoft Corporation                               */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This function starts a reception with the ACM modem. This mechanism */
46
/*    allows for non blocking calls based on a packet orientated round    */
47
/*    robbin buffer. When a packet is fully or partially received, an     */
48
/*    application callback function is invoked and a new transfer request */
49
/*    is rescheduled.                                                     */
50
/*                                                                        */
51
/*  INPUT                                                                 */
52
/*                                                                        */
53
/*    cdc_acm                               Pointer to cdc_acm class      */
54
/*    cdc_acm_reception                     Pointer to reception struct   */
55
/*                                                                        */
56
/*  OUTPUT                                                                */
57
/*                                                                        */
58
/*    Completion Status                                                   */
59
/*                                                                        */
60
/*  CALLS                                                                 */
61
/*                                                                        */
62
/*    _ux_host_stack_transfer_request       Process transfer request      */
63
/*                                                                        */
64
/*  CALLED BY                                                             */
65
/*                                                                        */
66
/*    Application                                                         */
67
/*                                                                        */
68
/**************************************************************************/
69
13
UINT  _ux_host_class_cdc_acm_reception_start (UX_HOST_CLASS_CDC_ACM *cdc_acm,
70
                                    UX_HOST_CLASS_CDC_ACM_RECEPTION *cdc_acm_reception)
71
{
72
73
UX_TRANSFER     *transfer_request;
74
UINT            status;
75
76
    /* If trace is enabled, insert this event into the trace buffer.  */
77
    UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_CDC_ACM_RECEPTION_START, cdc_acm, 0, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
78
79
    /* Ensure the instance is valid.  */
80
13
    if (cdc_acm -> ux_host_class_cdc_acm_state !=  UX_HOST_CLASS_INSTANCE_LIVE)
81
    {
82
83
        /* Error trap. */
84
1
        _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_INSTANCE_UNKNOWN);
85
86
        /* If trace is enabled, insert this event into the trace buffer.  */
87
        UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, cdc_acm, 0, 0, UX_TRACE_ERRORS, 0, 0)
88
89
1
        return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
90
    }
91
92
    /* As further protection, we must ensure this instance of the interface is the data interface and not
93
       the control interface !  */
94
12
    if (cdc_acm -> ux_host_class_cdc_acm_interface -> ux_interface_descriptor.bInterfaceClass != UX_HOST_CLASS_CDC_DATA_CLASS)
95
    {
96
97
        /* Error trap. */
98
1
        _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_INSTANCE_UNKNOWN);
99
100
        /* If trace is enabled, insert this event into the trace buffer.  */
101
        UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, cdc_acm, 0, 0, UX_TRACE_ERRORS, 0, 0)
102
103
1
        return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
104
    }
105
106
    /* Start by aligning the head and tail of buffers to the same address supplied by the application.  */
107
11
    cdc_acm_reception -> ux_host_class_cdc_acm_reception_data_head =  cdc_acm_reception -> ux_host_class_cdc_acm_reception_data_buffer;
108
11
    cdc_acm_reception -> ux_host_class_cdc_acm_reception_data_tail =  cdc_acm_reception -> ux_host_class_cdc_acm_reception_data_buffer;
109
110
    /* Get the pointer to the bulk in endpoint in the transfer_request.  */
111
11
    transfer_request =  &cdc_acm -> ux_host_class_cdc_acm_bulk_in_endpoint -> ux_endpoint_transfer_request;
112
113
    /* Initialize the transfer request.  */
114
11
    transfer_request -> ux_transfer_request_class_instance      =  (VOID *) cdc_acm;
115
11
    transfer_request -> ux_transfer_request_data_pointer        =  cdc_acm_reception -> ux_host_class_cdc_acm_reception_data_head;
116
11
    transfer_request -> ux_transfer_request_requested_length    =  cdc_acm_reception -> ux_host_class_cdc_acm_reception_block_size;
117
11
    transfer_request -> ux_transfer_request_completion_function =  _ux_host_class_cdc_acm_reception_callback;
118
119
    /* Save the acm reception structure in the acm structure.  */
120
11
    cdc_acm -> ux_host_class_cdc_acm_reception = cdc_acm_reception;
121
122
    /* And declare we have a transfer in progress.  */
123
11
    cdc_acm_reception -> ux_host_class_cdc_acm_reception_state =  UX_HOST_CLASS_CDC_ACM_RECEPTION_STATE_STARTED;
124
125
    /* Arm a first transfer on the bulk in endpoint. There is a callback to this function so we return to the caller
126
       right away. */
127
11
    status =  _ux_host_stack_transfer_request(transfer_request);
128
129
    /* We do not know if the first transfer was successful yet.  If the status is not OK, we need to stop the transfer
130
       in progress flag. */
131
11
    if (status != UX_SUCCESS)
132
1
        cdc_acm_reception -> ux_host_class_cdc_acm_reception_state =  UX_HOST_CLASS_CDC_ACM_RECEPTION_STATE_STOPPED;
133
134
11
    return(status);
135
}
136
137
138
/**************************************************************************/
139
/*                                                                        */
140
/*  FUNCTION                                               RELEASE        */
141
/*                                                                        */
142
/*    _uxe_host_class_cdc_acm_reception_start             PORTABLE C      */
143
/*                                                           6.3.0        */
144
/*  AUTHOR                                                                */
145
/*                                                                        */
146
/*    Chaoqiong Xiao, Microsoft Corporation                               */
147
/*                                                                        */
148
/*  DESCRIPTION                                                           */
149
/*                                                                        */
150
/*    This function checks errors in CDC ACM reception function call.     */
151
/*                                                                        */
152
/*  INPUT                                                                 */
153
/*                                                                        */
154
/*    cdc_acm                               Pointer to CDC ACM class      */
155
/*    cdc_acm_reception                     Pointer to reception struct   */
156
/*                                                                        */
157
/*  OUTPUT                                                                */
158
/*                                                                        */
159
/*    Status                                                              */
160
/*                                                                        */
161
/*  CALLS                                                                 */
162
/*                                                                        */
163
/*    _ux_host_class_cdc_acm_reception_start                              */
164
/*                                          CDC ACM reception start       */
165
/*                                                                        */
166
/*  CALLED BY                                                             */
167
/*                                                                        */
168
/*    Application                                                         */
169
/*                                                                        */
170
/**************************************************************************/
171
UINT  _uxe_host_class_cdc_acm_reception_start (UX_HOST_CLASS_CDC_ACM *cdc_acm,
172
                                    UX_HOST_CLASS_CDC_ACM_RECEPTION *cdc_acm_reception)
173
{
174
175
    /* Sanity checks.  */
176
    if ((cdc_acm == UX_NULL) || (cdc_acm_reception == UX_NULL))
177
        return(UX_INVALID_PARAMETER);
178
179
    /* Invoke CDC ACM reception start function.  */
180
    return(_ux_host_class_cdc_acm_reception_start(cdc_acm, cdc_acm_reception));
181
}