GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: core/src/ux_host_stack_device_configuration_get.c Lines: 14 18 77.8 %
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
/**   Host Stack                                                          */
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_stack.h"
30
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _ux_host_stack_device_configuration_get             PORTABLE C      */
37
/*                                                           6.1          */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Chaoqiong Xiao, Microsoft Corporation                               */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function returns a configuration container based on a device   */
45
/*    handle and a configuration index.                                   */
46
/*                                                                        */
47
/*  INPUT                                                                 */
48
/*                                                                        */
49
/*    device                                Pointer to device             */
50
/*    configuration_index                   Index of configuration        */
51
/*    configuration                         Pointer to configuration      */
52
/*                                            destination                 */
53
/*                                                                        */
54
/*  OUTPUT                                                                */
55
/*                                                                        */
56
/*    Completion Status                                                   */
57
/*                                                                        */
58
/*  CALLS                                                                 */
59
/*                                                                        */
60
/*    None                                                                */
61
/*                                                                        */
62
/*  CALLED BY                                                             */
63
/*                                                                        */
64
/*    Application                                                         */
65
/*    USBX Components                                                     */
66
/*                                                                        */
67
/**************************************************************************/
68
115
UINT  _ux_host_stack_device_configuration_get(UX_DEVICE *device, UINT configuration_index,
69
                                                        UX_CONFIGURATION **configuration)
70
{
71
72
UINT                    current_configuration_index;
73
UX_CONFIGURATION        *current_configuration;
74
75
    /* Do a sanity check on the device handle.  */
76
115
    if (device -> ux_device_handle != (ULONG) (ALIGN_TYPE) device)
77
    {
78
79
        /* Error trap. */
80
4
        _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ENUMERATOR, UX_DEVICE_HANDLE_UNKNOWN);
81
82
        /* If trace is enabled, insert this event into the trace buffer.  */
83
        UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_DEVICE_HANDLE_UNKNOWN, device, 0, 0, UX_TRACE_ERRORS, 0, 0)
84
85
4
        return(UX_DEVICE_HANDLE_UNKNOWN);
86
    }
87
88
    /* Start with the configuration attached to the device.  */
89
111
    current_configuration =  device -> ux_device_first_configuration;
90
91
    /* The first configuration has the index 0.  */
92
111
    current_configuration_index =  0;
93
94
    /* Traverse the list of the configurations until we found the right one.  */
95
112
    while (current_configuration != UX_NULL)
96
    {
97
98
        /* Check if the configuration index matches the current one.  */
99
111
        if (configuration_index == current_configuration_index)
100
        {
101
102
            /* Return the configuration pointer.  */
103
110
            *configuration =  current_configuration;
104
105
            /* If trace is enabled, insert this event into the trace buffer.  */
106
            UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_DEVICE_CONFIGURATION_GET, device, current_configuration, 0, 0, UX_TRACE_HOST_STACK_EVENTS, 0, 0)
107
108
            /* Return successful completion.  */
109
110
            return(UX_SUCCESS);
110
        }
111
112
        /* Move to the next configuration.  */
113
1
        current_configuration =  current_configuration -> ux_configuration_next_configuration;
114
115
        /* Move to the next index.  */
116
1
        current_configuration_index++;
117
    }
118
119
    /* Error trap. */
120
1
    _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ENUMERATOR, UX_CONFIGURATION_HANDLE_UNKNOWN);
121
122
    /* If trace is enabled, insert this event into the trace buffer.  */
123
    UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_CONFIGURATION_HANDLE_UNKNOWN, configuration, 0, 0, UX_TRACE_ERRORS, 0, 0)
124
125
    /* Return an error.  */
126
1
    return(UX_CONFIGURATION_HANDLE_UNKNOWN);
127
}
128
129
130
/**************************************************************************/
131
/*                                                                        */
132
/*  FUNCTION                                               RELEASE        */
133
/*                                                                        */
134
/*    _uxe_host_stack_device_configuration_get            PORTABLE C      */
135
/*                                                           6.3.0        */
136
/*  AUTHOR                                                                */
137
/*                                                                        */
138
/*    Chaoqiong Xiao, Microsoft Corporation                               */
139
/*                                                                        */
140
/*  DESCRIPTION                                                           */
141
/*                                                                        */
142
/*    This function checks errors in host stack config get function call. */
143
/*                                                                        */
144
/*  INPUT                                                                 */
145
/*                                                                        */
146
/*    device                                Pointer to device             */
147
/*    configuration_index                   Index of configuration        */
148
/*    configuration                         Pointer to configuration      */
149
/*                                            destination                 */
150
/*                                                                        */
151
/*  OUTPUT                                                                */
152
/*                                                                        */
153
/*    None                                                                */
154
/*                                                                        */
155
/*  CALLS                                                                 */
156
/*                                                                        */
157
/*    _ux_host_stack_device_configuration_get                             */
158
/*                                          Host configuration get        */
159
/*                                                                        */
160
/*  CALLED BY                                                             */
161
/*                                                                        */
162
/*    Application                                                         */
163
/*                                                                        */
164
/**************************************************************************/
165
UINT  _uxe_host_stack_device_configuration_get(UX_DEVICE *device, UINT configuration_index,
166
                                                        UX_CONFIGURATION **configuration)
167
{
168
169
    /* Sanity checks.  */
170
    if ((device == UX_NULL) || (configuration == UX_NULL))
171
        return(UX_INVALID_PARAMETER);
172
173
    /* Invoke configuration get function.  */
174
    return(_ux_host_stack_device_configuration_get(device, configuration_index, configuration));
175
}