1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** USBX Component                                                        */
16 /**                                                                       */
17 /**   Host Simulator Controller Driver                                    */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define UX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "ux_api.h"
28 #include "ux_hcd_sim_host.h"
29 
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _ux_hcd_sim_host_asynchronous_endpoint_destroy      PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Chaoqiong Xiao, Microsoft Corporation                               */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function will destroy an asynchronous endpoint. The control    */
44 /*    and bulk endpoints fall into this category.                         */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    hcd_sim_host                          Pointer to host controller    */
49 /*    endpoint                              Pointer to endpoint           */
50 /*                                                                        */
51 /*  OUTPUT                                                                */
52 /*                                                                        */
53 /*    Completion Status                                                   */
54 /*                                                                        */
55 /*  CALLS                                                                 */
56 /*                                                                        */
57 /*    None                                                                */
58 /*                                                                        */
59 /*  CALLED BY                                                             */
60 /*                                                                        */
61 /*    Host Simulator Controller Driver                                    */
62 /*                                                                        */
63 /*  RELEASE HISTORY                                                       */
64 /*                                                                        */
65 /*    DATE              NAME                      DESCRIPTION             */
66 /*                                                                        */
67 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
68 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
69 /*                                            resulting in version 6.1    */
70 /*                                                                        */
71 /**************************************************************************/
_ux_hcd_sim_host_asynchronous_endpoint_destroy(UX_HCD_SIM_HOST * hcd_sim_host,UX_ENDPOINT * endpoint)72 UINT  _ux_hcd_sim_host_asynchronous_endpoint_destroy(UX_HCD_SIM_HOST *hcd_sim_host, UX_ENDPOINT *endpoint)
73 {
74 
75 UX_HCD_SIM_HOST_ED      *ed;
76 UX_HCD_SIM_HOST_ED      *previous_ed;
77 UX_HCD_SIM_HOST_ED      *next_ed;
78 UX_HCD_SIM_HOST_TD      *td;
79 
80 
81     /* From the endpoint container fetch the host simulator ED descriptor.  */
82     ed =  (UX_HCD_SIM_HOST_ED *) endpoint -> ux_endpoint_ed;
83 
84     /* Get the previous ED in the list for this ED.  */
85     previous_ed =  ed -> ux_sim_host_ed_previous_ed;
86 
87     /* Get the next ED in the list for this ED.  */
88     next_ed =  ed -> ux_sim_host_ed_next_ed;
89 
90     /* If the previous ED is NULL, we are at trying to remove the head ED.  */
91     if (previous_ed == UX_NULL)
92 
93         /* Store the new endpoint in the control list.  */
94         hcd_sim_host -> ux_hcd_sim_host_asynch_head_ed =  next_ed;
95     else
96 
97         /* The previous ED points now to the ED after the ED we are removing.  */
98         previous_ed -> ux_sim_host_ed_next_ed =  next_ed;
99 
100     /* Update the previous ED pointer in the next ED if exists.  */
101     if (next_ed != UX_NULL)
102         next_ed -> ux_sim_host_ed_previous_ed =  previous_ed;
103 
104     /* Determine if we need to adjust the current ED.  */
105     if (hcd_sim_host -> ux_hcd_sim_host_asynch_current_ed == ed)
106     {
107 
108         /* Move the current to the next.  */
109         hcd_sim_host -> ux_hcd_sim_host_asynch_current_ed =  next_ed;
110     }
111 
112     /* We need to free the dummy TD that was attached to the ED.  */
113     td =  ed -> ux_sim_host_ed_tail_td;
114     td -> ux_sim_host_td_status =  UX_UNUSED;
115 
116     /* Now we can safely make the ED free.  */
117     ed -> ux_sim_host_ed_status =  UX_UNUSED;
118 
119     /* Return successful completion.  */
120     return(UX_SUCCESS);
121 }
122 
123