GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: core/src/ux_device_stack_endpoint_stall.c Lines: 11 11 100.0 %
Date: 2026-03-06 18:57:10 Branches: 6 6 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_endpoint_stall                     PORTABLE C      */
37
/*                                                           6.1.10       */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Chaoqiong Xiao, Microsoft Corporation                               */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function stalls an endpoint. The host will need to reissue     */
45
/*    a reset to clear the endpoint.                                      */
46
/*                                                                        */
47
/*  INPUT                                                                 */
48
/*                                                                        */
49
/*    endpoint                              Pointer to endpoint           */
50
/*                                                                        */
51
/*  OUTPUT                                                                */
52
/*                                                                        */
53
/*    Completion Status                                                   */
54
/*                                                                        */
55
/*  CALLS                                                                 */
56
/*                                                                        */
57
/*    (ux_slave_dcd_function)               DCD dispatch function         */
58
/*                                                                        */
59
/*  CALLED BY                                                             */
60
/*                                                                        */
61
/*    Application                                                         */
62
/*                                                                        */
63
/**************************************************************************/
64
3812
UINT  _ux_device_stack_endpoint_stall(UX_SLAVE_ENDPOINT *endpoint)
65
{
66
67
UX_INTERRUPT_SAVE_AREA
68
69
UX_SLAVE_DCD        *dcd;
70
UINT                status;
71
72
    /* If trace is enabled, insert this event into the trace buffer.  */
73
    UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_STACK_ENDPOINT_STALL, endpoint, 0, 0, 0, UX_TRACE_DEVICE_STACK_EVENTS, 0, 0)
74
75
    /* Get the pointer to the DCD.  */
76
3812
    dcd =  &_ux_system_slave -> ux_system_slave_dcd;
77
78
    /* Assume device is in an invalid state here in order to reduce code in following
79
       section where interrupts are disabled.  */
80
3812
    status =  UX_ERROR;
81
82
    /* Ensure we don't change the endpoint's state after disconnection routine
83
       resets it.  */
84
3812
    UX_DISABLE
85
86
    /* Check if the device is in a valid state; as soon as the device is out
87
       of the RESET state, transfers occur and thus endpoints may be stalled. */
88
3812
    if (_ux_system_slave -> ux_system_slave_device.ux_slave_device_state != UX_DEVICE_RESET &&
89
3801
        endpoint -> ux_slave_endpoint_state != UX_ENDPOINT_HALTED)
90
    {
91
92
        /* Stall the endpoint.  */
93
1487
        status =  dcd -> ux_slave_dcd_function(dcd, UX_DCD_STALL_ENDPOINT, endpoint);
94
95
        /* Mark the endpoint state.  */
96
1487
        if ((endpoint -> ux_slave_endpoint_descriptor.bmAttributes & UX_MASK_ENDPOINT_TYPE) !=
97
            UX_CONTROL_ENDPOINT)
98
1389
            endpoint -> ux_slave_endpoint_state =  UX_ENDPOINT_HALTED;
99
    }
100
101
    /* Restore interrupts.  */
102
3812
    UX_RESTORE
103
104
    /* Return completion status.  */
105
3812
    return(status);
106
}
107