GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: core/src/ux_device_stack_interface_delete.c Lines: 20 20 100.0 %
Date: 2026-03-06 18:57:10 Branches: 2 2 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_interface_delete                   PORTABLE C      */
37
/*                                                           6.1.12       */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Chaoqiong Xiao, Microsoft Corporation                               */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function deletes an interface. Semaphore and memory are        */
45
/*    released and the controller driver is invoked to disable the        */
46
/*    hardware endpoint.  The interface is then removed from the          */
47
/*    configuration.                                                      */
48
/*                                                                        */
49
/*  INPUT                                                                 */
50
/*                                                                        */
51
/*    interface                             Pointer to interface          */
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
/*    Application                                                         */
64
/*                                                                        */
65
/**************************************************************************/
66
1445
UINT  _ux_device_stack_interface_delete(UX_SLAVE_INTERFACE *interface_ptr)
67
{
68
69
UX_SLAVE_DCD            *dcd;
70
UX_SLAVE_DEVICE         *device;
71
UX_SLAVE_ENDPOINT       *endpoint;
72
UX_SLAVE_ENDPOINT       *next_endpoint;
73
74
    /* If trace is enabled, register this object.  */
75
    UX_TRACE_OBJECT_UNREGISTER(interface_ptr);
76
77
    /* If trace is enabled, insert this event into the trace buffer.  */
78
    UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_STACK_INTERFACE_DELETE, interface_ptr, 0, 0, 0, UX_TRACE_DEVICE_STACK_EVENTS, 0, 0)
79
80
    /* Get the pointer to the device.  */
81
1445
    device =  &_ux_system_slave -> ux_system_slave_device;
82
83
    /* Find the first endpoints associated with this interface.  */
84
1445
    next_endpoint =  interface_ptr -> ux_slave_interface_first_endpoint;
85
86
    /* Parse all the endpoints.  */
87
3366
    while (next_endpoint != UX_NULL)
88
    {
89
90
        /* Save this endpoint.  */
91
1921
        endpoint =  next_endpoint;
92
93
        /* Find the next endpoint.  */
94
1921
        next_endpoint =  endpoint -> ux_slave_endpoint_next_endpoint;
95
96
        /* Get the pointer to the DCD.  */
97
1921
        dcd =  &_ux_system_slave->ux_system_slave_dcd;
98
99
        /* The endpoint must be destroyed.  */
100
1921
        dcd -> ux_slave_dcd_function(dcd, UX_DCD_DESTROY_ENDPOINT, endpoint);
101
102
        /* Free the endpoint.  */
103
1921
        endpoint -> ux_slave_endpoint_status =  UX_UNUSED;
104
105
        /* Make sure the endpoint instance is now cleaned up.  */
106
1921
        endpoint -> ux_slave_endpoint_state =  0;
107
1921
        endpoint -> ux_slave_endpoint_next_endpoint =  UX_NULL;
108
1921
        endpoint -> ux_slave_endpoint_interface =  UX_NULL;
109
1921
        endpoint -> ux_slave_endpoint_device =  UX_NULL;
110
    }
111
112
    /* It's always from first one (to delete).  */
113
    /* Rebuild the first link.  */
114
1445
    device -> ux_slave_device_first_interface =  interface_ptr -> ux_slave_interface_next_interface;
115
116
    /* The interface is removed from the link, its memory must be cleaned and returned to the pool.  */
117
1445
    interface_ptr -> ux_slave_interface_class          =  UX_NULL;
118
1445
    interface_ptr -> ux_slave_interface_class_instance =  UX_NULL;
119
1445
    interface_ptr -> ux_slave_interface_next_interface =  UX_NULL;
120
1445
    interface_ptr -> ux_slave_interface_first_endpoint =  UX_NULL;
121
1445
    interface_ptr -> ux_slave_interface_status         =  UX_UNUSED;
122
123
    /* Return successful completion.  */
124
1445
    return(UX_SUCCESS);
125
}
126