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_next_td_clean                          PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Chaoqiong Xiao, Microsoft Corporation                               */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*     This function cleans all the tds attached to a ED. The end of the  */
46 /*     TD chain is pointed by the tail TD.                                */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    td                                    Pointer to OHCI TD            */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    None                                                                */
55 /*                                                                        */
56 /*  CALLS                                                                 */
57 /*                                                                        */
58 /*    _ux_utility_physical_address          Get physical address          */
59 /*    _ux_utility_virtual_address           Get virtual address           */
60 /*                                                                        */
61 /*  CALLED BY                                                             */
62 /*                                                                        */
63 /*    OHCI Controller Driver                                              */
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 /*                                            fixed physical and virtual  */
72 /*                                            address conversion,         */
73 /*                                            resulting in version 6.1    */
74 /*                                                                        */
75 /**************************************************************************/
_ux_hcd_ohci_next_td_clean(UX_OHCI_TD * td)76 VOID  _ux_hcd_ohci_next_td_clean(UX_OHCI_TD *td)
77 {
78 
79 UX_OHCI_ED      *ed;
80 UX_OHCI_TD      *head_td;
81 UX_OHCI_TD      *tail_td;
82 ULONG           value_td;
83 ULONG           value_carry;
84 
85 
86     /* Obtain the pointer to the ED from the TD.  */
87     ed =  td -> ux_ohci_td_ed;
88 
89     /* Ensure that the potential Carry bit is maintained in the head ED.  */
90     value_carry =  (ULONG)(ed -> ux_ohci_ed_head_td) & UX_OHCI_ED_TOGGLE_CARRY;
91 
92     /* Ensure that the potential Halt bit is removed in the head ED.  */
93     value_td =  (ULONG) _ux_utility_virtual_address(ed -> ux_ohci_ed_head_td) & UX_OHCI_ED_MASK_TD;
94     head_td =   (UX_OHCI_TD *)value_td;
95 
96     /* Remove all the tds from this ED and leave the head and tail pointing
97        to the dummy TD.  */
98     tail_td =  _ux_utility_virtual_address(ed -> ux_ohci_ed_tail_td);
99 
100     /* Free all tds attached to the ED.  */
101     while (head_td != tail_td)
102     {
103 
104         /* Mark the current head_td as free.  */
105         head_td -> ux_ohci_td_status =  UX_UNUSED;
106 
107         /* Update the head TD with the next TD.  */
108         ed -> ux_ohci_ed_head_td =  head_td -> ux_ohci_td_next_td;
109 
110         /* Now the new head_td is the next TD in the chain.  */
111         head_td =  _ux_utility_virtual_address(ed -> ux_ohci_ed_head_td);
112     }
113 
114     /* Restore the value carry for next transfers.  */
115     value_td =   (ULONG) ed -> ux_ohci_ed_head_td;
116     value_td |=  value_carry;
117     ed -> ux_ohci_ed_head_td =  (UX_OHCI_TD *) value_td;
118 
119     /* Return to caller.  */
120     return;
121 }
122 
123