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 /** EHCI 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_ehci.h"
30 #include "ux_host_stack.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _ux_hcd_ehci_regular_td_obtain PORTABLE C */
38 /* 6.1.11 */
39 /* AUTHOR */
40 /* */
41 /* Chaoqiong Xiao, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function obtains a free TD from the regular TD list. */
46 /* */
47 /* INPUT */
48 /* */
49 /* hcd_ehci Pointer to EHCI controller */
50 /* */
51 /* OUTPUT */
52 /* */
53 /* UX_EHCI_TD * Pointer to TD */
54 /* */
55 /* CALLS */
56 /* */
57 /* _ux_utility_memory_set Set memory block */
58 /* _ux_host_mutex_on Get protection mutex */
59 /* _ux_host_mutex_off Release protection mutex */
60 /* */
61 /* CALLED BY */
62 /* */
63 /* EHCI 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 /* verified memset and memcpy */
72 /* cases, */
73 /* resulting in version 6.1 */
74 /* 04-25-2022 Chaoqiong Xiao Modified comment(s), */
75 /* fixed standalone compile, */
76 /* resulting in version 6.1.11 */
77 /* */
78 /**************************************************************************/
_ux_hcd_ehci_regular_td_obtain(UX_HCD_EHCI * hcd_ehci)79 UX_EHCI_TD *_ux_hcd_ehci_regular_td_obtain(UX_HCD_EHCI *hcd_ehci)
80 {
81
82 UX_EHCI_TD *td;
83 ULONG td_index;
84 ULONG td_element;
85
86
87 /* Get the mutex as this is a critical section. */
88 _ux_host_mutex_on(&_ux_system -> ux_system_mutex);
89
90 /* Start the search from the beginning of the list. */
91 td = hcd_ehci -> ux_hcd_ehci_td_list;
92 for (td_index = 0; td_index < _ux_system_host -> ux_system_host_max_td; td_index++)
93 {
94
95 /* Check the TD status, a free TD is marked with the USED flag. */
96 if (td -> ux_ehci_td_status == UX_UNUSED)
97 {
98
99 /* The TD may have been used, so we reset all fields. */
100 _ux_utility_memory_set(td, 0, sizeof(UX_EHCI_TD)); /* Use case of memset is verified. */
101
102 /* This TD is now marked as USED. */
103 td -> ux_ehci_td_status = UX_USED;
104
105 /* Initialize the link pointer and alternate TD fields. */
106 td_element = UX_EHCI_TD_T;
107 td -> ux_ehci_td_link_pointer = (UX_EHCI_TD *) td_element;
108 td -> ux_ehci_td_alternate_link_pointer = (UX_EHCI_TD *) td_element;
109
110 /* Release the protection. */
111 _ux_host_mutex_off(&_ux_system -> ux_system_mutex);
112
113 /* Success, return TD pointer. */
114 return(td);
115 }
116
117 /* Look at next TD. */
118 td++;
119 }
120
121 /* There is no available TD in the TD list. */
122
123 /* Release protection. */
124 _ux_host_mutex_off(&_ux_system -> ux_system_mutex);
125
126 /* Error, return a null. */
127 return(UX_NULL);
128 }
129
130