1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
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 /*  RELEASE HISTORY                                                       */
66 /*                                                                        */
67 /*    DATE              NAME                      DESCRIPTION             */
68 /*                                                                        */
69 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
70 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
71 /*                                            resulting in version 6.1    */
72 /*  07-29-2022     Chaoqiong Xiao           Modified comment(s),          */
73 /*                                            fixed parameter/variable    */
74 /*                                            names conflict C++ keyword, */
75 /*                                            resulting in version 6.1.12 */
76 /*                                                                        */
77 /**************************************************************************/
_ux_device_stack_interface_delete(UX_SLAVE_INTERFACE * interface_ptr)78 UINT  _ux_device_stack_interface_delete(UX_SLAVE_INTERFACE *interface_ptr)
79 {
80 
81 UX_SLAVE_DCD            *dcd;
82 UX_SLAVE_DEVICE         *device;
83 UX_SLAVE_ENDPOINT       *endpoint;
84 UX_SLAVE_ENDPOINT       *next_endpoint;
85 
86     /* If trace is enabled, register this object.  */
87     UX_TRACE_OBJECT_UNREGISTER(interface_ptr);
88 
89     /* If trace is enabled, insert this event into the trace buffer.  */
90     UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_STACK_INTERFACE_DELETE, interface_ptr, 0, 0, 0, UX_TRACE_DEVICE_STACK_EVENTS, 0, 0)
91 
92     /* Get the pointer to the device.  */
93     device =  &_ux_system_slave -> ux_system_slave_device;
94 
95     /* Find the first endpoints associated with this interface.  */
96     next_endpoint =  interface_ptr -> ux_slave_interface_first_endpoint;
97 
98     /* Parse all the endpoints.  */
99     while (next_endpoint != UX_NULL)
100     {
101 
102         /* Save this endpoint.  */
103         endpoint =  next_endpoint;
104 
105         /* Find the next endpoint.  */
106         next_endpoint =  endpoint -> ux_slave_endpoint_next_endpoint;
107 
108         /* Get the pointer to the DCD.  */
109         dcd =  &_ux_system_slave->ux_system_slave_dcd;
110 
111         /* The endpoint must be destroyed.  */
112         dcd -> ux_slave_dcd_function(dcd, UX_DCD_DESTROY_ENDPOINT, endpoint);
113 
114         /* Free the endpoint.  */
115         endpoint -> ux_slave_endpoint_status =  UX_UNUSED;
116 
117         /* Make sure the endpoint instance is now cleaned up.  */
118         endpoint -> ux_slave_endpoint_state =  0;
119         endpoint -> ux_slave_endpoint_next_endpoint =  UX_NULL;
120         endpoint -> ux_slave_endpoint_interface =  UX_NULL;
121         endpoint -> ux_slave_endpoint_device =  UX_NULL;
122     }
123 
124     /* It's always from first one (to delete).  */
125     /* Rebuild the first link.  */
126     device -> ux_slave_device_first_interface =  interface_ptr -> ux_slave_interface_next_interface;
127 
128     /* The interface is removed from the link, its memory must be cleaned and returned to the pool.  */
129     interface_ptr -> ux_slave_interface_class          =  UX_NULL;
130     interface_ptr -> ux_slave_interface_class_instance =  UX_NULL;
131     interface_ptr -> ux_slave_interface_next_interface =  UX_NULL;
132     interface_ptr -> ux_slave_interface_first_endpoint =  UX_NULL;
133     interface_ptr -> ux_slave_interface_status         =  UX_UNUSED;
134 
135     /* Return successful completion.  */
136     return(UX_SUCCESS);
137 }
138 
139