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 /** OHCI Controller Driver */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23
24 /* Include necessary system files. */
25
26 #define UX_SOURCE_CODE
27
28 #include "ux_api.h"
29 #include "ux_host_stack.h"
30 #include "ux_hcd_ohci.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _ux_hcd_ohci_periodic_endpoint_destroy PORTABLE C */
38 /* 6.1.2 */
39 /* AUTHOR */
40 /* */
41 /* Chaoqiong Xiao, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function will destroy an interrupt or isochronous endpoint. */
46 /* */
47 /* INPUT */
48 /* */
49 /* hcd_ohci Pointer to OHCI controller */
50 /* endpoint Pointer to endpoint */
51 /* */
52 /* OUTPUT */
53 /* */
54 /* Completion Status */
55 /* */
56 /* CALLS */
57 /* */
58 /* _ux_utility_delay_ms Delay ms */
59 /* */
60 /* CALLED BY */
61 /* */
62 /* OHCI Controller Driver */
63 /* */
64 /* RELEASE HISTORY */
65 /* */
66 /* DATE NAME DESCRIPTION */
67 /* */
68 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
69 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
70 /* fixed physical and virtual */
71 /* address conversion, */
72 /* resulting in version 6.1 */
73 /* 11-09-2020 Chaoqiong Xiao Modified comment(s), */
74 /* fixed compile warnings, */
75 /* resulting in version 6.1.2 */
76 /* */
77 /**************************************************************************/
_ux_hcd_ohci_periodic_endpoint_destroy(UX_HCD_OHCI * hcd_ohci,UX_ENDPOINT * endpoint)78 UINT _ux_hcd_ohci_periodic_endpoint_destroy(UX_HCD_OHCI *hcd_ohci, UX_ENDPOINT *endpoint)
79 {
80
81 UX_OHCI_ED *ed;
82 UX_OHCI_ED *previous_ed;
83 UX_OHCI_ED *next_ed;
84 UX_OHCI_TD *tail_td;
85 UX_OHCI_TD *head_td;
86 ULONG value_td;
87
88
89 UX_PARAMETER_NOT_USED(hcd_ohci);
90
91 /* From the endpoint container fetch the OHCI ED descriptor. */
92 ed = (UX_OHCI_ED*) endpoint -> ux_endpoint_ed;
93
94 /* Check if this physical endpoint has been initialized properly! */
95 if (ed == UX_NULL)
96 {
97
98 /* Error trap. */
99 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_HCD, UX_ENDPOINT_HANDLE_UNKNOWN);
100
101 /* If trace is enabled, insert this event into the trace buffer. */
102 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_ENDPOINT_HANDLE_UNKNOWN, endpoint, 0, 0, UX_TRACE_ERRORS, 0, 0)
103
104 return(UX_ENDPOINT_HANDLE_UNKNOWN);
105 }
106
107 /* The endpoint may be active. If so, set the skip bit. */
108 ed -> ux_ohci_ed_dw0 |= UX_OHCI_ED_SKIP;
109
110 /* Wait for the controller to finish the current frame processing. */
111 _ux_utility_delay_ms(1);
112
113 /* Get the previous ED in the list for this ED. */
114 previous_ed = ed -> ux_ohci_ed_previous_ed;
115
116 /* Get the next ED in the list for this ED. */
117 next_ed = ed -> ux_ohci_ed_next_ed;
118
119 /* The previous ED points now to the ED after the ED we are removing. */
120 previous_ed -> ux_ohci_ed_next_ed = next_ed;
121
122 /* There may not be any next endpoint. But if there is one, link it
123 to the previous ED. */
124 if (next_ed != UX_NULL)
125 {
126
127 /* Update the previous ED pointer in the next ED. */
128 next_ed = _ux_utility_virtual_address(next_ed);
129 next_ed -> ux_ohci_ed_previous_ed = previous_ed;
130 }
131
132 /* Ensure that the potential Halt bit is removed in the head ED. */
133 value_td = (ULONG) _ux_utility_virtual_address(ed -> ux_ohci_ed_head_td) & UX_OHCI_ED_MASK_TD;
134 head_td = (UX_OHCI_TD *)value_td;
135
136 /* Remove all the tds from this ED and leave the head and tail pointing
137 to the dummy TD. */
138 tail_td = _ux_utility_virtual_address(ed -> ux_ohci_ed_tail_td);
139
140 /* Free all tds attached to the ED */
141 while (head_td != tail_td)
142 {
143
144 /* Update the head TD with the next TD. */
145 ed -> ux_ohci_ed_head_td = head_td -> ux_ohci_td_next_td;
146
147 /* Mark the current head TD as free. */
148 head_td -> ux_ohci_td_status = UX_UNUSED;
149
150 /* Now the new head TD is the next TD in the chain. */
151 head_td = _ux_utility_virtual_address(ed -> ux_ohci_ed_head_td);
152 }
153
154 /* We need to free the dummy TD that was attached to the ED. */
155 tail_td -> ux_ohci_td_status = UX_UNUSED;
156
157 /* Now we can safely make the ED free. */
158 ed -> ux_ohci_ed_status = UX_UNUSED;
159
160 /* Return success. */
161 return(UX_SUCCESS);
162 }
163
164