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_isochronous_td_obtain              PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*     This function obtains a free TD from the isochronous TD list.      */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    hcd_sim_host                          Pointer to host controller    */
49 /*                                                                        */
50 /*  OUTPUT                                                                */
51 /*                                                                        */
52 /*    UX_HCD_SIM_HOST_ISO_TD *              Pointer to host ISO 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_isochronous_td_obtain(UX_HCD_SIM_HOST * hcd_sim_host)73 UX_HCD_SIM_HOST_ISO_TD  *_ux_hcd_sim_host_isochronous_td_obtain(UX_HCD_SIM_HOST *hcd_sim_host)
74 {
75 
76 UX_HCD_SIM_HOST_ISO_TD      *td;
77 ULONG                       td_index;
78 
79 
80     /* Start the search from the beginning of the list.  */
81     td =  hcd_sim_host -> ux_hcd_sim_host_iso_td_list;
82     for (td_index = 0; td_index < _ux_system_host -> ux_system_host_max_iso_td; td_index++)
83     {
84 
85         /* Check the TD status, a free TD is marked with the UX_USED flag.  */
86         if (td -> ux_sim_host_iso_td_status == UX_UNUSED)
87         {
88 
89             /* The TD may have been used, so we reset all fields.  */
90             _ux_utility_memory_set(td, 0, sizeof(UX_HCD_SIM_HOST_ISO_TD)); /* Use case of memset is verified. */
91 
92             /* This TD is now marked as USED.  */
93             td -> ux_sim_host_iso_td_status = UX_USED;
94 
95             /* Success, return pointer to TD.  */
96             return(td);
97         }
98 
99         /* Move to next TD.  */
100         td++;
101     }
102 
103     /* There is no available TD in the TD list, return a NULL.  */
104     return(UX_NULL);
105 }
106 
107