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_hcd_ohci.h"
30 #include "ux_host_stack.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _ux_hcd_ohci_transfer_abort PORTABLE C */
38 /* 6.1.2 */
39 /* AUTHOR */
40 /* */
41 /* Chaoqiong Xiao, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function will abort transactions attached to a transfer */
46 /* request. */
47 /* */
48 /* INPUT */
49 /* */
50 /* hcd_ohci Pointer to OHCI controller */
51 /* transfer_request Pointer to transfer request */
52 /* */
53 /* OUTPUT */
54 /* */
55 /* Completion Status */
56 /* */
57 /* CALLS */
58 /* */
59 /* _ux_utility_delay_ms Delay */
60 /* _ux_utility_physical_address Get physical address */
61 /* _ux_utility_virtual_address Get virtual address */
62 /* */
63 /* CALLED BY */
64 /* */
65 /* OHCI Controller Driver */
66 /* */
67 /* RELEASE HISTORY */
68 /* */
69 /* DATE NAME DESCRIPTION */
70 /* */
71 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
72 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
73 /* fixed physical and virtual */
74 /* address conversion, */
75 /* resulting in version 6.1 */
76 /* 11-09-2020 Chaoqiong Xiao Modified comment(s), */
77 /* fixed compile warnings, */
78 /* resulting in version 6.1.2 */
79 /* */
80 /**************************************************************************/
_ux_hcd_ohci_transfer_abort(UX_HCD_OHCI * hcd_ohci,UX_TRANSFER * transfer_request)81 UINT _ux_hcd_ohci_transfer_abort(UX_HCD_OHCI *hcd_ohci, UX_TRANSFER *transfer_request)
82 {
83
84 UX_ENDPOINT *endpoint;
85 UX_OHCI_ED *ed;
86 UX_OHCI_TD *head_td;
87 UX_OHCI_TD *tail_td;
88 ULONG value_td;
89 ULONG value_carry;
90
91
92 UX_PARAMETER_NOT_USED(hcd_ohci);
93
94 /* Get the pointer to the endpoint associated with the transfer request. */
95 endpoint = (UX_ENDPOINT *) transfer_request -> ux_transfer_request_endpoint;
96
97 /* From the endpoint container, get the address of the physical endpoint. */
98 ed = (UX_OHCI_ED *) endpoint -> ux_endpoint_ed;
99
100 /* Check if this physical endpoint has been initialized properly! */
101 if (ed == UX_NULL)
102 {
103
104 /* Error trap. */
105 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_HCD, UX_ENDPOINT_HANDLE_UNKNOWN);
106
107 /* If trace is enabled, insert this event into the trace buffer. */
108 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_ENDPOINT_HANDLE_UNKNOWN, endpoint, 0, 0, UX_TRACE_ERRORS, 0, 0)
109
110 return(UX_ENDPOINT_HANDLE_UNKNOWN);
111 }
112
113 /* The endpoint may be active. If so, set the skip bit. */
114 ed -> ux_ohci_ed_dw0 |= UX_OHCI_ED_SKIP;
115
116 /* Wait for the controller to finish the current frame processing. */
117 _ux_utility_delay_ms(1);
118
119 /* Ensure that the potential Carry bit is maintained in the head ED. */
120 value_carry = (ULONG)(ed -> ux_ohci_ed_head_td) & UX_OHCI_ED_TOGGLE_CARRY;
121
122 /* Ensure that the potential Halt bit is removed in the head ED. */
123 value_td = (ULONG) _ux_utility_virtual_address(ed -> ux_ohci_ed_head_td) & UX_OHCI_ED_MASK_TD;
124 head_td = (UX_OHCI_TD *)value_td;
125
126 /* Remove all the tds from this ED and leave the head and tail pointing
127 to the dummy TD. */
128 tail_td = _ux_utility_virtual_address(ed -> ux_ohci_ed_tail_td);
129
130 /* Free all tds attached to the ED */
131 while (head_td != tail_td)
132 {
133
134 /* Update the head TD with the next TD. */
135 ed -> ux_ohci_ed_head_td = head_td -> ux_ohci_td_next_td;
136
137 /* Mark the current head TD as free. */
138 head_td -> ux_ohci_td_status = UX_UNUSED;
139
140 /* Now the new head TD is the next TD in the chain. */
141 head_td = _ux_utility_virtual_address(ed -> ux_ohci_ed_head_td);
142 }
143
144 /* Restore the value carry for next transfers. */
145 value_td = (ULONG) ed -> ux_ohci_ed_head_td;
146 value_td |= value_carry;
147 ed -> ux_ohci_ed_head_td = (UX_OHCI_TD *) value_td;
148
149 /* Remove the reset bit in the ED. */
150 ed -> ux_ohci_ed_dw0 &= ~UX_OHCI_ED_SKIP;
151
152 /* Return successful completion. */
153 return(UX_SUCCESS);
154 }
155
156