GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: core/src/ux_device_stack_get_status.c Lines: 31 31 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_get_status                         PORTABLE C      */
37
/*                                                           6.1.6        */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Chaoqiong Xiao, Microsoft Corporation                               */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function obtains the status of a USB component of the device   */
45
/*    such as device or endpoint.                                         */
46
/*                                                                        */
47
/*  INPUT                                                                 */
48
/*                                                                        */
49
/*    request_type                          Request type                  */
50
/*    request_index                         Request index                 */
51
/*    request_length                        Request length                */
52
/*                                                                        */
53
/*  OUTPUT                                                                */
54
/*                                                                        */
55
/*    Completion Status                                                   */
56
/*                                                                        */
57
/*  CALLS                                                                 */
58
/*                                                                        */
59
/*    _ux_device_stack_transfer_request     Transfer request              */
60
/*    (ux_slave_dcd_function)               DCD dispatch function         */
61
/*                                                                        */
62
/*  CALLED BY                                                             */
63
/*                                                                        */
64
/*    Device Stack                                                        */
65
/*                                                                        */
66
/**************************************************************************/
67
221
UINT  _ux_device_stack_get_status(ULONG request_type, ULONG request_index, ULONG request_length)
68
{
69
70
UX_SLAVE_DCD            *dcd;
71
UX_SLAVE_TRANSFER       *transfer_request;
72
UX_SLAVE_DEVICE         *device;
73
UX_SLAVE_ENDPOINT       *endpoint;
74
UINT                    status;
75
ULONG                   data_length;
76
77
    UX_PARAMETER_NOT_USED(request_length);
78
79
    /* If trace is enabled, insert this event into the trace buffer.  */
80
    UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_STACK_GET_STATUS, request_type, request_index, request_length, 0, UX_TRACE_DEVICE_STACK_EVENTS, 0, 0)
81
82
    /* Get the pointer to the DCD.  */
83
221
    dcd =  &_ux_system_slave -> ux_system_slave_dcd;
84
85
    /* Get the pointer to the device.  */
86
221
    device =  &_ux_system_slave -> ux_system_slave_device;
87
88
    /* Get the control endpoint for the device.  */
89
221
    endpoint =  &device -> ux_slave_device_control_endpoint;
90
91
    /* Get the pointer to the transfer request associated with the endpoint.  */
92
221
    transfer_request =  &endpoint -> ux_slave_endpoint_transfer_request;
93
94
    /* Reset the status buffer.  */
95
221
    *transfer_request -> ux_slave_transfer_request_data_pointer =  0;
96
221
    *(transfer_request -> ux_slave_transfer_request_data_pointer + 1) =  0;
97
98
    /* The default length for GET_STATUS is 2, except for OTG get Status.  */
99
221
    data_length = 2;
100
101
    /* The status can be for either the device or the endpoint.  */
102
221
    switch (request_type & UX_REQUEST_TARGET)
103
    {
104
105
72
    case UX_REQUEST_TARGET_DEVICE:
106
107
        /* When the device is probed, it is either for the power/remote capabilities or OTG role swap.
108
           We differentiate with the Windex, 0 or OTG status Selector.  */
109
72
        if (request_index == UX_OTG_STATUS_SELECTOR)
110
        {
111
112
            /* Set the data length to 1.  */
113
1
            data_length = 1;
114
115
#ifdef UX_OTG_SUPPORT
116
            /* Store the Role Swap flag.  */
117
            *transfer_request -> ux_slave_transfer_request_data_pointer =  (UCHAR) _ux_system_otg -> ux_system_otg_slave_role_swap_flag;
118
#endif
119
120
        }
121
        else
122
        {
123
124
            /* Store the current power state in the status buffer. */
125
71
            if (_ux_system_slave -> ux_system_slave_power_state == UX_DEVICE_SELF_POWERED)
126
34
                *transfer_request -> ux_slave_transfer_request_data_pointer =  1;
127
128
            /* Store the remote wakeup capability state in the status buffer.  */
129
130
71
            if (_ux_system_slave -> ux_system_slave_remote_wakeup_enabled)
131
2
                *transfer_request -> ux_slave_transfer_request_data_pointer |=  2;
132
        }
133
134
72
        break;
135
136
148
    case UX_REQUEST_TARGET_ENDPOINT:
137
138
#ifndef UX_DEVICE_BIDIRECTIONAL_ENDPOINT_SUPPORT
139
140
        /* This feature returns the halt state of a specific endpoint.  The endpoint index
141
           is used to retrieve the endpoint container.  */
142
148
        status =  dcd -> ux_slave_dcd_function(dcd, UX_DCD_ENDPOINT_STATUS, (VOID *)(ALIGN_TYPE)(request_index & (UINT)~UX_ENDPOINT_DIRECTION));
143
#else
144
145
        /* This feature returns the halt state of a specific endpoint.  The endpoint address
146
           is used to retrieve the endpoint container.  */
147
        status =  dcd -> ux_slave_dcd_function(dcd, UX_DCD_ENDPOINT_STATUS, (VOID *)(ALIGN_TYPE)(request_index));
148
#endif
149
150
        /* Check the status. We may have a unknown endpoint.  */
151
148
        if (status != UX_ERROR)
152
        {
153
154
147
            if (status == UX_TRUE)
155
33
                *transfer_request -> ux_slave_transfer_request_data_pointer =  1;
156
        }
157
        else
158
        {
159
160
            /* We stall the command. Endpoint is wrong.  */
161
1
            dcd -> ux_slave_dcd_function(dcd, UX_DCD_STALL_ENDPOINT, endpoint);
162
163
            /* No more work to do here.  The command failed but the upper layer does not depend on it.  */
164
1
            return(UX_SUCCESS);
165
        }
166
147
        break;
167
168
1
    default:
169
170
        /* We stall the command.  */
171
1
        dcd -> ux_slave_dcd_function(dcd, UX_DCD_STALL_ENDPOINT, endpoint);
172
173
        /* No more work to do here.  The command failed but the upper layer does not depend on it.  */
174
1
        return(UX_SUCCESS);
175
    }
176
177
    /* Set the phase of the transfer to data out.  */
178
219
    transfer_request -> ux_slave_transfer_request_phase =  UX_TRANSFER_PHASE_DATA_OUT;
179
180
    /* Send the descriptor with the appropriate length to the host.  */
181
219
    status =  _ux_device_stack_transfer_request(transfer_request, data_length, data_length);
182
183
    /* Return the function status.  */
184
219
    return(status);
185
}
186