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_ed_obtain PORTABLE C */
37 /* 6.1 */
38 /* AUTHOR */
39 /* */
40 /* Chaoqiong Xiao, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function obtains a free ED from the ED list. */
45 /* */
46 /* INPUT */
47 /* */
48 /* hcd_sim_host Pointer to host controller */
49 /* */
50 /* OUTPUT */
51 /* */
52 /* UX_HCD_SIM_HOST_ED * Pointer to ED */
53 /* */
54 /* CALLS */
55 /* */
56 /* _ux_utility_memory_set Set memory block */
57 /* */
58 /* CALLED BY */
59 /* */
60 /* Host Simulator Controller Driver */
61 /* */
62 /* RELEASE HISTORY */
63 /* */
64 /* DATE NAME DESCRIPTION */
65 /* */
66 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
67 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
68 /* verified memset and memcpy */
69 /* cases, */
70 /* resulting in version 6.1 */
71 /* */
72 /**************************************************************************/
_ux_hcd_sim_host_ed_obtain(UX_HCD_SIM_HOST * hcd_sim_host)73 UX_HCD_SIM_HOST_ED *_ux_hcd_sim_host_ed_obtain(UX_HCD_SIM_HOST *hcd_sim_host)
74 {
75
76 UX_HCD_SIM_HOST_ED *ed;
77 ULONG ed_index;
78
79
80 /* Start the search from the beginning of the list. */
81 ed = hcd_sim_host -> ux_hcd_sim_host_ed_list;
82 for(ed_index = 0; ed_index < _ux_system_host -> ux_system_host_max_ed; ed_index++)
83 {
84
85 /* Check the ED status, a free ED is marked with the UNUSED flag. */
86 if (ed -> ux_sim_host_ed_status == UX_UNUSED)
87 {
88
89 /* The ED may have been used, so we reset all fields. */
90 _ux_utility_memory_set(ed, 0, sizeof(UX_HCD_SIM_HOST_ED)); /* Use case of memset is verified. */
91
92 /* This ED is now marked as USED. */
93 ed -> ux_sim_host_ed_status = UX_USED;
94
95 /* Return ED pointer. */
96 return(ed);
97 }
98
99 /* Point to the next ED. */
100 ed++;
101 }
102
103 /* There is no available ED in the ED list. */
104 return(UX_NULL);
105 }
106
107