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 /**   Host Simulator Controller Driver                                    */
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_hcd_sim_host.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _ux_hcd_sim_host_periodic_endpoint_destroy          PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*     This function will destroy an interrupt or isochronous endpoint.   */
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_periodic_endpoint_destroy(UX_HCD_SIM_HOST * hcd_sim_host,UX_ENDPOINT * endpoint)72 UINT  _ux_hcd_sim_host_periodic_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     /* The previous ED points now to the ED after the ED we are removing.  */
91     if (previous_ed)
92         previous_ed -> ux_sim_host_ed_next_ed =  next_ed;
93 
94     /* Update the previous ED pointer in the next ED.  */
95     if (next_ed)
96         next_ed -> ux_sim_host_ed_previous_ed =  previous_ed;
97 
98     /* We need to free the dummy TD that was attached to the ED.  */
99     td =  ed -> ux_sim_host_ed_tail_td;
100     td -> ux_sim_host_td_status =  UX_UNUSED;
101 
102     /* Now we can safely make the ED free.  */
103     ed -> ux_sim_host_ed_status =  UX_UNUSED;
104 
105     /* Decrement the number of interrupt endpoints active. When the counter
106        reaches 0, the periodic scheduler will be turned off.  */
107     hcd_sim_host -> ux_hcd_sim_host_periodic_scheduler_active--;
108 
109     /* Return successful completion.  */
110     return(UX_SUCCESS);
111 }
112 
113