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: 2024-12-12 17:16:36 Branches: 8 12 66.7 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 *
4
 * This program and the accompanying materials are made available under the
5
 * terms of the MIT License which is available at
6
 * https://opensource.org/licenses/MIT.
7
 *
8
 * SPDX-License-Identifier: MIT
9
 **************************************************************************/
10
11
12
/**************************************************************************/
13
/**************************************************************************/
14
/**                                                                       */
15
/** USBX Component                                                        */
16
/**                                                                       */
17
/**   ACM CDC Class                                                       */
18
/**                                                                       */
19
/**************************************************************************/
20
/**************************************************************************/
21
22
23
/* Include necessary system files.  */
24
25
#define UX_SOURCE_CODE
26
27
#include "ux_api.h"
28
#include "ux_host_class_cdc_acm.h"
29
#include "ux_host_stack.h"
30
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _ux_host_class_cdc_acm_reception_stop               PORTABLE C      */
37
/*                                                           6.1.10       */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Chaoqiong Xiao, Microsoft Corporation                               */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function stops background reception previously started by      */
45
/*    ux_host_class_cdc_acm_reception_start.                              */
46
/*                                                                        */
47
/*  INPUT                                                                 */
48
/*                                                                        */
49
/*    cdc_acm                               Pointer to cdc_acm class      */
50
/*    cdc_acm_reception                     Pointer to reception struct   */
51
/*                                                                        */
52
/*  OUTPUT                                                                */
53
/*                                                                        */
54
/*    Completion Status                                                   */
55
/*                                                                        */
56
/*  CALLS                                                                 */
57
/*                                                                        */
58
/*    _ux_host_stack_endpoint_transfer_abort                              */
59
/*                                          Abort transfer                */
60
/*    _ux_host_semaphore_get                Get semaphore                 */
61
/*                                                                        */
62
/*  CALLED BY                                                             */
63
/*                                                                        */
64
/*    Application                                                         */
65
/*                                                                        */
66
/*  RELEASE HISTORY                                                       */
67
/*                                                                        */
68
/*    DATE              NAME                      DESCRIPTION             */
69
/*                                                                        */
70
/*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
71
/*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
72
/*                                            resulting in version 6.1    */
73
/*  01-31-2022     Chaoqiong Xiao           Modified comment(s),          */
74
/*                                            added standalone support,   */
75
/*                                            resulting in version 6.1.10 */
76
/*                                                                        */
77
/**************************************************************************/
78
7
UINT  _ux_host_class_cdc_acm_reception_stop(UX_HOST_CLASS_CDC_ACM *cdc_acm,
79
                                    UX_HOST_CLASS_CDC_ACM_RECEPTION *cdc_acm_reception)
80
{
81
82
UX_TRANSFER              *transfer_request;
83
84
    /* If trace is enabled, insert this event into the trace buffer.  */
85
    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)
86
87
    /* Ensure the instance is valid.  */
88
7
    if (cdc_acm -> ux_host_class_cdc_acm_state !=  UX_HOST_CLASS_INSTANCE_LIVE)
89
    {
90
91
        /* Error trap. */
92
1
        _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_INSTANCE_UNKNOWN);
93
94
        /* If trace is enabled, insert this event into the trace buffer.  */
95
        UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, cdc_acm, 0, 0, UX_TRACE_ERRORS, 0, 0)
96
97
1
        return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
98
    }
99
100
    /* As further protection, we must ensure this instance of the interface is the data interface and not
101
       the control interface !  */
102
6
    if (cdc_acm -> ux_host_class_cdc_acm_interface -> ux_interface_descriptor.bInterfaceClass != UX_HOST_CLASS_CDC_DATA_CLASS)
103
    {
104
105
        /* Error trap. */
106
1
        _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_INSTANCE_UNKNOWN);
107
108
        /* If trace is enabled, insert this event into the trace buffer.  */
109
        UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, cdc_acm, 0, 0, UX_TRACE_ERRORS, 0, 0)
110
111
1
        return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
112
    }
113
114
    /* Check if we do have transfers for this application. If none, nothing to do. */
115
5
    if (cdc_acm_reception -> ux_host_class_cdc_acm_reception_state ==  UX_HOST_CLASS_CDC_ACM_RECEPTION_STATE_STOPPED)
116
1
        return(UX_SUCCESS);
117
118
    /* We need to abort transactions on the bulk In pipe.  */
119
4
    _ux_host_stack_endpoint_transfer_abort(cdc_acm -> ux_host_class_cdc_acm_bulk_in_endpoint);
120
121
    /* Declare the reception stopped.  */
122
4
    cdc_acm_reception -> ux_host_class_cdc_acm_reception_state =  UX_HOST_CLASS_CDC_ACM_RECEPTION_STATE_STOPPED;
123
124
    /* Obtain pointer to transfer request.  */
125
4
    transfer_request = &cdc_acm -> ux_host_class_cdc_acm_bulk_in_endpoint -> ux_endpoint_transfer_request;
126
127
    /* Reset the completion callback function.  */
128
4
    transfer_request -> ux_transfer_request_completion_function = UX_NULL;
129
130
#if !defined(UX_HOST_STANDALONE)
131
132
    /* Clear semaphore counts that were (incorrectly) increased during each transfer
133
       completion.  */
134
21
    while (transfer_request -> ux_transfer_request_semaphore.tx_semaphore_count)
135
17
        _ux_host_semaphore_get(&transfer_request -> ux_transfer_request_semaphore, 0);
136
#endif
137
138
    /* This function never really fails.  */
139
4
    return(UX_SUCCESS);
140
}
141
142
143
/**************************************************************************/
144
/*                                                                        */
145
/*  FUNCTION                                               RELEASE        */
146
/*                                                                        */
147
/*    _uxe_host_class_cdc_acm_reception_stop              PORTABLE C      */
148
/*                                                           6.3.0        */
149
/*  AUTHOR                                                                */
150
/*                                                                        */
151
/*    Chaoqiong Xiao, Microsoft Corporation                               */
152
/*                                                                        */
153
/*  DESCRIPTION                                                           */
154
/*                                                                        */
155
/*    This function checks errors in CDC ACM reception function call.     */
156
/*                                                                        */
157
/*  INPUT                                                                 */
158
/*                                                                        */
159
/*    cdc_acm                               Pointer to CDC ACM class      */
160
/*    cdc_acm_reception                     Pointer to reception struct   */
161
/*                                                                        */
162
/*  OUTPUT                                                                */
163
/*                                                                        */
164
/*    Status                                                              */
165
/*                                                                        */
166
/*  CALLS                                                                 */
167
/*                                                                        */
168
/*    _ux_host_class_cdc_acm_reception_stop CDC ACM reception stop        */
169
/*                                                                        */
170
/*  CALLED BY                                                             */
171
/*                                                                        */
172
/*    Application                                                         */
173
/*                                                                        */
174
/*  RELEASE HISTORY                                                       */
175
/*                                                                        */
176
/*    DATE              NAME                      DESCRIPTION             */
177
/*                                                                        */
178
/*  10-31-2023     Chaoqiong Xiao           Initial Version 6.3.0         */
179
/*                                                                        */
180
/**************************************************************************/
181
UINT  _uxe_host_class_cdc_acm_reception_stop(UX_HOST_CLASS_CDC_ACM *cdc_acm,
182
                                    UX_HOST_CLASS_CDC_ACM_RECEPTION *cdc_acm_reception)
183
{
184
185
    /* Sanity checks.  */
186
    if ((cdc_acm == UX_NULL) || (cdc_acm_reception == UX_NULL))
187
        return(UX_INVALID_PARAMETER);
188
189
    /* Invoke CDC ACM reception function.  */
190
    return(_ux_host_class_cdc_acm_reception_stop(cdc_acm, cdc_acm_reception));
191
}