1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** USBX Component                                                        */
16 /**                                                                       */
17 /**   Host Simulator Controller Driver                                    */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define UX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "ux_api.h"
28 #include "ux_hcd_sim_host.h"
29 
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _ux_hcd_sim_host_asynch_schedule                    PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Chaoqiong Xiao, Microsoft Corporation                               */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function schedules new transfers from the control/bulk lists.  */
44 /*                                                                        */
45 /*  INPUT                                                                 */
46 /*                                                                        */
47 /*    hcd_sim_host                          Pointer to host controller    */
48 /*                                                                        */
49 /*  OUTPUT                                                                */
50 /*                                                                        */
51 /*    None                                                                */
52 /*                                                                        */
53 /*  CALLS                                                                 */
54 /*                                                                        */
55 /*    _ux_hcd_sim_host_transaction_schedule Schedule simulator transaction*/
56 /*                                                                        */
57 /*  CALLED BY                                                             */
58 /*                                                                        */
59 /*    Host Simulator Controller Driver                                    */
60 /*                                                                        */
61 /*  RELEASE HISTORY                                                       */
62 /*                                                                        */
63 /*    DATE              NAME                      DESCRIPTION             */
64 /*                                                                        */
65 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
66 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
67 /*                                            resulting in version 6.1    */
68 /*                                                                        */
69 /**************************************************************************/
_ux_hcd_sim_host_asynch_schedule(UX_HCD_SIM_HOST * hcd_sim_host)70 VOID  _ux_hcd_sim_host_asynch_schedule(UX_HCD_SIM_HOST *hcd_sim_host)
71 {
72 
73 UX_HCD_SIM_HOST_ED      *ed;
74 UX_HCD_SIM_HOST_ED      *first_ed;
75 UINT                    status;
76 
77 
78     /* Get the pointer to the current ED in the asynchronous list.  */
79     ed =  hcd_sim_host -> ux_hcd_sim_host_asynch_current_ed;
80 
81     /* Check if there is any ED candidate in the asynch list.  */
82     if (ed == UX_NULL)
83     {
84 
85         /* Check if there is any ED in the asynch list. If none, nothing to do.  */
86         if (hcd_sim_host -> ux_hcd_sim_host_asynch_head_ed == UX_NULL)
87             return;
88         else
89             ed = hcd_sim_host -> ux_hcd_sim_host_asynch_head_ed;
90     }
91 
92     /* Remember this ED.  */
93     first_ed =  ed;
94 
95     /* In simulation, we are not tied to bandwidth limitation.  */
96     do
97     {
98 
99         /* Check if this ED has a tail and head TD different.  */
100         if (ed -> ux_sim_host_ed_tail_td != ed -> ux_sim_host_ed_head_td)
101         {
102 
103             /* Schedule this transaction with the device simulator.  */
104             status =  _ux_hcd_sim_host_transaction_schedule(hcd_sim_host, ed);
105 
106             /* If the TD has been added to the list, we can memorize this ED has
107                being served and make the next ED as the one to be first scanned
108                at the next SOF.  */
109             if (status == UX_SUCCESS)
110             {
111 
112                 if (ed -> ux_sim_host_ed_next_ed == UX_NULL)
113                     hcd_sim_host -> ux_hcd_sim_host_asynch_current_ed =  hcd_sim_host -> ux_hcd_sim_host_asynch_head_ed;
114                 else
115                     hcd_sim_host -> ux_hcd_sim_host_asynch_current_ed =  ed -> ux_sim_host_ed_next_ed;
116             }
117         }
118 
119         /* Point to the next ED in the list. Check if at end of list.  */
120         if (ed -> ux_sim_host_ed_next_ed == UX_NULL)
121             ed =  hcd_sim_host -> ux_hcd_sim_host_asynch_head_ed;
122         else
123             ed =  ed -> ux_sim_host_ed_next_ed;
124 
125     } while ((ed) && (ed != first_ed));
126 }
127 
128