GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_host_classes/src/ux_host_class_cdc_acm_reception_stop.c Lines: 16 20 80.0 %
Date: 2026-03-06 18:57:10 Branches: 8 12 66.7 %

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_stop               PORTABLE C      */
38
/*                                                           6.1.10       */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Chaoqiong Xiao, Microsoft Corporation                               */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This function stops background reception previously started by      */
46
/*    ux_host_class_cdc_acm_reception_start.                              */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    cdc_acm                               Pointer to cdc_acm class      */
51
/*    cdc_acm_reception                     Pointer to reception struct   */
52
/*                                                                        */
53
/*  OUTPUT                                                                */
54
/*                                                                        */
55
/*    Completion Status                                                   */
56
/*                                                                        */
57
/*  CALLS                                                                 */
58
/*                                                                        */
59
/*    _ux_host_stack_endpoint_transfer_abort                              */
60
/*                                          Abort transfer                */
61
/*    _ux_host_semaphore_get                Get semaphore                 */
62
/*                                                                        */
63
/*  CALLED BY                                                             */
64
/*                                                                        */
65
/*    Application                                                         */
66
/*                                                                        */
67
/**************************************************************************/
68
7
UINT  _ux_host_class_cdc_acm_reception_stop(UX_HOST_CLASS_CDC_ACM *cdc_acm,
69
                                    UX_HOST_CLASS_CDC_ACM_RECEPTION *cdc_acm_reception)
70
{
71
72
UX_TRANSFER              *transfer_request;
73
74
    /* If trace is enabled, insert this event into the trace buffer.  */
75
    UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_CDC_ACM_RECEPTION_STOP, cdc_acm, 0, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
76
77
    /* Ensure the instance is valid.  */
78
7
    if (cdc_acm -> ux_host_class_cdc_acm_state !=  UX_HOST_CLASS_INSTANCE_LIVE)
79
    {
80
81
        /* Error trap. */
82
1
        _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_INSTANCE_UNKNOWN);
83
84
        /* If trace is enabled, insert this event into the trace buffer.  */
85
        UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, cdc_acm, 0, 0, UX_TRACE_ERRORS, 0, 0)
86
87
1
        return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
88
    }
89
90
    /* As further protection, we must ensure this instance of the interface is the data interface and not
91
       the control interface !  */
92
6
    if (cdc_acm -> ux_host_class_cdc_acm_interface -> ux_interface_descriptor.bInterfaceClass != UX_HOST_CLASS_CDC_DATA_CLASS)
93
    {
94
95
        /* Error trap. */
96
1
        _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_INSTANCE_UNKNOWN);
97
98
        /* If trace is enabled, insert this event into the trace buffer.  */
99
        UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, cdc_acm, 0, 0, UX_TRACE_ERRORS, 0, 0)
100
101
1
        return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
102
    }
103
104
    /* Check if we do have transfers for this application. If none, nothing to do. */
105
5
    if (cdc_acm_reception -> ux_host_class_cdc_acm_reception_state ==  UX_HOST_CLASS_CDC_ACM_RECEPTION_STATE_STOPPED)
106
1
        return(UX_SUCCESS);
107
108
    /* We need to abort transactions on the bulk In pipe.  */
109
4
    _ux_host_stack_endpoint_transfer_abort(cdc_acm -> ux_host_class_cdc_acm_bulk_in_endpoint);
110
111
    /* Declare the reception stopped.  */
112
4
    cdc_acm_reception -> ux_host_class_cdc_acm_reception_state =  UX_HOST_CLASS_CDC_ACM_RECEPTION_STATE_STOPPED;
113
114
    /* Obtain pointer to transfer request.  */
115
4
    transfer_request = &cdc_acm -> ux_host_class_cdc_acm_bulk_in_endpoint -> ux_endpoint_transfer_request;
116
117
    /* Reset the completion callback function.  */
118
4
    transfer_request -> ux_transfer_request_completion_function = UX_NULL;
119
120
#if !defined(UX_HOST_STANDALONE)
121
122
    /* Clear semaphore counts that were (incorrectly) increased during each transfer
123
       completion.  */
124
21
    while (_ux_host_semaphore_waiting(&(transfer_request -> ux_transfer_request_semaphore)))
125
17
        _ux_host_semaphore_get(&transfer_request -> ux_transfer_request_semaphore, 0);
126
#endif
127
128
    /* This function never really fails.  */
129
4
    return(UX_SUCCESS);
130
}
131
132
133
/**************************************************************************/
134
/*                                                                        */
135
/*  FUNCTION                                               RELEASE        */
136
/*                                                                        */
137
/*    _uxe_host_class_cdc_acm_reception_stop              PORTABLE C      */
138
/*                                                           6.3.0        */
139
/*  AUTHOR                                                                */
140
/*                                                                        */
141
/*    Chaoqiong Xiao, Microsoft Corporation                               */
142
/*                                                                        */
143
/*  DESCRIPTION                                                           */
144
/*                                                                        */
145
/*    This function checks errors in CDC ACM reception function call.     */
146
/*                                                                        */
147
/*  INPUT                                                                 */
148
/*                                                                        */
149
/*    cdc_acm                               Pointer to CDC ACM class      */
150
/*    cdc_acm_reception                     Pointer to reception struct   */
151
/*                                                                        */
152
/*  OUTPUT                                                                */
153
/*                                                                        */
154
/*    Status                                                              */
155
/*                                                                        */
156
/*  CALLS                                                                 */
157
/*                                                                        */
158
/*    _ux_host_class_cdc_acm_reception_stop CDC ACM reception stop        */
159
/*                                                                        */
160
/*  CALLED BY                                                             */
161
/*                                                                        */
162
/*    Application                                                         */
163
/*                                                                        */
164
/**************************************************************************/
165
UINT  _uxe_host_class_cdc_acm_reception_stop(UX_HOST_CLASS_CDC_ACM *cdc_acm,
166
                                    UX_HOST_CLASS_CDC_ACM_RECEPTION *cdc_acm_reception)
167
{
168
169
    /* Sanity checks.  */
170
    if ((cdc_acm == UX_NULL) || (cdc_acm_reception == UX_NULL))
171
        return(UX_INVALID_PARAMETER);
172
173
    /* Invoke CDC ACM reception function.  */
174
    return(_ux_host_class_cdc_acm_reception_stop(cdc_acm, cdc_acm_reception));
175
}