GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: core/src/ux_device_stack_clear_feature.c Lines: 25 25 100.0 %
Date: 2026-03-06 18:57:10 Branches: 13 13 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
/**   Device Stack                                                        */
19
/**                                                                       */
20
/**************************************************************************/
21
/**************************************************************************/
22
23
#define UX_SOURCE_CODE
24
25
26
/* Include necessary system files.  */
27
28
#include "ux_api.h"
29
#include "ux_device_stack.h"
30
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _ux_device_stack_clear_feature                      PORTABLE C      */
37
/*                                                           6.1.12       */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Chaoqiong Xiao, Microsoft Corporation                               */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function clears a specific feature (Device, Interface,         */
45
/*    Endpoint ....).                                                     */
46
/*                                                                        */
47
/*  INPUT                                                                 */
48
/*                                                                        */
49
/*    request_type                          Request type                  */
50
/*    request_value                         Request value                 */
51
/*    request_index                         Request index                 */
52
/*                                                                        */
53
/*  OUTPUT                                                                */
54
/*                                                                        */
55
/*    Completion Status                                                   */
56
/*                                                                        */
57
/*  CALLS                                                                 */
58
/*                                                                        */
59
/*    (ux_slave_dcd_function)               DCD dispatch function         */
60
/*                                                                        */
61
/*  CALLED BY                                                             */
62
/*                                                                        */
63
/*    Device Stack                                                        */
64
/*                                                                        */
65
/**************************************************************************/
66
1427
UINT  _ux_device_stack_clear_feature(ULONG request_type, ULONG request_value, ULONG request_index)
67
{
68
69
UX_SLAVE_DCD            *dcd;
70
UX_SLAVE_DEVICE         *device;
71
UX_SLAVE_INTERFACE      *interface_ptr;
72
UX_SLAVE_ENDPOINT       *endpoint;
73
UX_SLAVE_ENDPOINT       *endpoint_target;
74
75
    UX_PARAMETER_NOT_USED(request_value);
76
77
    /* If trace is enabled, insert this event into the trace buffer.  */
78
    UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_STACK_CLEAR_FEATURE, request_type, request_value, request_index, 0, UX_TRACE_DEVICE_STACK_EVENTS, 0, 0)
79
80
    /* Get the pointer to the DCD.  */
81
1427
    dcd =  &_ux_system_slave -> ux_system_slave_dcd;
82
83
    /* Get the pointer to the device.  */
84
1427
    device =  &_ux_system_slave -> ux_system_slave_device;
85
86
    /* Get the control endpoint for the device.  */
87
1427
    endpoint =  &device -> ux_slave_device_control_endpoint;
88
89
    /* The request can be for either the device or the endpoint.  */
90
1427
    switch (request_type & UX_REQUEST_TARGET)
91
    {
92
93
4
    case UX_REQUEST_TARGET_DEVICE:
94
95
        /* Check if we have a DEVICE_REMOTE_WAKEUP Feature.  */
96
4
        if (request_value == UX_REQUEST_FEATURE_DEVICE_REMOTE_WAKEUP)
97
        {
98
99
            /* Check if we have the capability. */
100
3
            if (_ux_system_slave -> ux_system_slave_remote_wakeup_capability)
101
            {
102
103
                /* Disable the feature. */
104
2
                _ux_system_slave -> ux_system_slave_remote_wakeup_enabled = UX_FALSE;
105
            }
106
107
            else
108
109
                /* Protocol error. */
110
1
                return (UX_FUNCTION_NOT_SUPPORTED);
111
        }
112
113
3
        break;
114
115
1422
    case UX_REQUEST_TARGET_ENDPOINT:
116
117
        /* The only clear feature for endpoint is ENDPOINT_STALL. This clears
118
           the endpoint of the stall situation and resets its data toggle.
119
           We need to find the endpoint through the interface(s). */
120
1422
        interface_ptr =  device -> ux_slave_device_first_interface;
121
122
#if !defined(UX_DEVICE_INITIALIZE_FRAMEWORK_SCAN_DISABLE) || UX_MAX_DEVICE_INTERFACES > 1
123
1427
        while (interface_ptr != UX_NULL)
124
        {
125
#endif
126
127
            /* Get the first endpoint for this interface.  */
128
1426
            endpoint_target =  interface_ptr -> ux_slave_interface_first_endpoint;
129
130
            /* Parse all the endpoints.  */
131
1747
            while (endpoint_target != UX_NULL)
132
            {
133
134
                /* Check the endpoint index.  */
135
1742
                if (endpoint_target -> ux_slave_endpoint_descriptor.bEndpointAddress == request_index)
136
                {
137
138
                    /* Reset the endpoint.  */
139
1421
                    dcd -> ux_slave_dcd_function(dcd, UX_DCD_RESET_ENDPOINT, endpoint_target);
140
141
                    /* Mark its state now.  */
142
1421
                    endpoint_target -> ux_slave_endpoint_state = UX_ENDPOINT_RESET;
143
144
                    /* Return the function status.  */
145
1421
                    return(UX_SUCCESS);
146
                }
147
148
                /* Next endpoint.  */
149
321
                endpoint_target =  endpoint_target -> ux_slave_endpoint_next_endpoint;
150
            }
151
152
#if !defined(UX_DEVICE_INITIALIZE_FRAMEWORK_SCAN_DISABLE) || UX_MAX_DEVICE_INTERFACES > 1
153
            /* Next interface.  */
154
5
            interface_ptr =  interface_ptr -> ux_slave_interface_next_interface;
155
        }
156
#endif
157
158
        /* Intentional fallthrough and go into the default case. */
159
        /* fall through */
160
161
    /* We get here when the endpoint is wrong. Should not happen though.  */
162
    default:
163
164
        /* We stall the command.  */
165
2
        dcd -> ux_slave_dcd_function(dcd, UX_DCD_STALL_ENDPOINT, endpoint);
166
167
        /* No more work to do here.  The command failed but the upper layer does not depend on it.  */
168
2
        return(UX_SUCCESS);
169
    }
170
171
    /* Return the function status.  */
172
3
    return(UX_SUCCESS);
173
}
174