GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_host_classes/src/ux_host_class_cdc_acm_configure.c Lines: 19 19 100.0 %
Date: 2026-03-06 18:57:10 Branches: 14 14 100.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
/**   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_configure                    PORTABLE C      */
38
/*                                                           6.1          */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Chaoqiong Xiao, Microsoft Corporation                               */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This function calls the USBX stack to do a SET_CONFIGURATION to the */
46
/*    cdc_acm. Once the cdc_acm is configured, its interface will be      */
47
/*    activated. The bulk endpoints (1 IN, 1 OUT ) and the optional       */
48
/*    interrupt endpoint are enumerated.                                  */
49
/*                                                                        */
50
/*  INPUT                                                                 */
51
/*                                                                        */
52
/*    cdc_acm                               Pointer to cdc_acm class      */
53
/*                                                                        */
54
/*  OUTPUT                                                                */
55
/*                                                                        */
56
/*    Completion Status                                                   */
57
/*                                                                        */
58
/*  CALLS                                                                 */
59
/*                                                                        */
60
/*    _ux_host_stack_configuration_interface_get  Get interface           */
61
/*    _ux_host_stack_device_configuration_get     Get configuration       */
62
/*    _ux_host_stack_device_configuration_select  Select configuration    */
63
/*                                                                        */
64
/*  CALLED BY                                                             */
65
/*                                                                        */
66
/*    _ux_host_class_cdc_acm_activate        Data Pump class activate     */
67
/*                                                                        */
68
/**************************************************************************/
69
155
UINT  _ux_host_class_cdc_acm_configure(UX_HOST_CLASS_CDC_ACM *cdc_acm)
70
{
71
72
UINT                    status;
73
UX_CONFIGURATION        *configuration;
74
#if UX_MAX_DEVICES > 1
75
UX_DEVICE               *parent_device;
76
#endif
77
78
79
    /* If the device has been configured already, we don't need to do it
80
       again. */
81
155
    if (cdc_acm -> ux_host_class_cdc_acm_device -> ux_device_state == UX_DEVICE_CONFIGURED)
82
148
        return(UX_SUCCESS);
83
84
    /* A cdc_acm normally has one configuration. So retrieve the 1st configuration
85
       only.  */
86
7
    status =  _ux_host_stack_device_configuration_get(cdc_acm -> ux_host_class_cdc_acm_device, 0, &configuration);
87
7
    if (status != UX_SUCCESS)
88
    {
89
90
        /* Error trap. */
91
1
        _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_CONFIGURATION_HANDLE_UNKNOWN);
92
93
        /* If trace is enabled, insert this event into the trace buffer.  */
94
        UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_CONFIGURATION_HANDLE_UNKNOWN, cdc_acm -> ux_host_class_cdc_acm_device, 0, 0, UX_TRACE_ERRORS, 0, 0)
95
96
1
        return(UX_CONFIGURATION_HANDLE_UNKNOWN);
97
    }
98
99
#if UX_MAX_DEVICES > 1
100
    /* Check the cdc_acm power source and check the parent power source for
101
       incompatible connections.  */
102
6
    if (cdc_acm -> ux_host_class_cdc_acm_device -> ux_device_power_source == UX_DEVICE_BUS_POWERED)
103
    {
104
105
        /* Get parent device pointer.  */
106
3
        parent_device =  cdc_acm -> ux_host_class_cdc_acm_device -> ux_device_parent;
107
108
        /* If the device is NULL, the parent is the root cdc_acm and we don't have to worry
109
           if the parent is not the root cdc_acm, check for its power source.  */
110

3
        if ((parent_device != UX_NULL) && (parent_device -> ux_device_power_source == UX_DEVICE_BUS_POWERED))
111
        {
112
113
            /* Error trap. */
114
1
            _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_CONNECTION_INCOMPATIBLE);
115
116
            /* If trace is enabled, insert this event into the trace buffer.  */
117
            UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_CONNECTION_INCOMPATIBLE, cdc_acm, 0, 0, UX_TRACE_ERRORS, 0, 0)
118
119
1
            return(UX_CONNECTION_INCOMPATIBLE);
120
        }
121
    }
122
#endif
123
124
    /* We have the valid configuration. Ask the USBX stack to set this configuration.  */
125
5
    status =  _ux_host_stack_device_configuration_select(configuration);
126
5
    if (status != UX_SUCCESS)
127
3
        return(status);
128
129
    /* If the operation went well, the cdc_acm default alternate setting for the cdc_acm interface is
130
       active and the interrupt endpoint is now enabled. We have to memorize the first interface since
131
       the interrupt endpoint is hooked to it. */
132
2
    status =  _ux_host_stack_configuration_interface_get(configuration, 0, 0, &cdc_acm -> ux_host_class_cdc_acm_interface);
133
2
    if (status != UX_SUCCESS)
134
    {
135
136
        /* Store the instance in the interface container, this is for the USB stack
137
           when it needs to invoke the class.  */
138
1
        cdc_acm -> ux_host_class_cdc_acm_interface -> ux_interface_class_instance =  (VOID *) cdc_acm;
139
    }
140
141
    /* Return completion status.  */
142
2
    return(status);
143
}
144