summaryrefslogtreecommitdiff
path: root/common/core/src/ux_hcd_sim_host_asynch_schedule.c
blob: 609fe9b324fc731a934eb3dd470ec7196f30727f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/***************************************************************************
 * Copyright (c) 2024 Microsoft Corporation
 * Copyright (c) 2026-present Eclipse ThreadX contributors
 *
 * This program and the accompanying materials are made available under the
 * terms of the MIT License which is available at
 * https://opensource.org/licenses/MIT.
 *
 * SPDX-License-Identifier: MIT
 **************************************************************************/


/**************************************************************************/
/**************************************************************************/
/**                                                                       */
/** USBX Component                                                        */
/**                                                                       */
/**   Host Simulator Controller Driver                                    */
/**                                                                       */
/**************************************************************************/
/**************************************************************************/

#define UX_SOURCE_CODE


/* Include necessary system files.  */

#include "ux_api.h"
#include "ux_hcd_sim_host.h"


/**************************************************************************/
/*                                                                        */
/*  FUNCTION                                               RELEASE        */
/*                                                                        */
/*    _ux_hcd_sim_host_asynch_schedule                    PORTABLE C      */
/*                                                           6.1          */
/*  AUTHOR                                                                */
/*                                                                        */
/*    Chaoqiong Xiao, Microsoft Corporation                               */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*    This function schedules new transfers from the control/bulk lists.  */
/*                                                                        */
/*  INPUT                                                                 */
/*                                                                        */
/*    hcd_sim_host                          Pointer to host controller    */
/*                                                                        */
/*  OUTPUT                                                                */
/*                                                                        */
/*    None                                                                */
/*                                                                        */
/*  CALLS                                                                 */
/*                                                                        */
/*    _ux_hcd_sim_host_transaction_schedule Schedule simulator transaction*/
/*                                                                        */
/*  CALLED BY                                                             */
/*                                                                        */
/*    Host Simulator Controller Driver                                    */
/*                                                                        */
/**************************************************************************/
VOID  _ux_hcd_sim_host_asynch_schedule(UX_HCD_SIM_HOST *hcd_sim_host)
{

UX_HCD_SIM_HOST_ED      *ed;
UX_HCD_SIM_HOST_ED      *first_ed;
UINT                    status;


    /* Get the pointer to the current ED in the asynchronous list.  */
    ed =  hcd_sim_host -> ux_hcd_sim_host_asynch_current_ed;

    /* Check if there is any ED candidate in the asynch list.  */
    if (ed == UX_NULL)
    {

        /* Check if there is any ED in the asynch list. If none, nothing to do.  */
        if (hcd_sim_host -> ux_hcd_sim_host_asynch_head_ed == UX_NULL)
            return;
        else
            ed = hcd_sim_host -> ux_hcd_sim_host_asynch_head_ed;
    }

    /* Remember this ED.  */
    first_ed =  ed;

    /* In simulation, we are not tied to bandwidth limitation.  */
    do
    {

        /* Check if this ED has a tail and head TD different.  */
        if (ed -> ux_sim_host_ed_tail_td != ed -> ux_sim_host_ed_head_td)
        {

            /* Schedule this transaction with the device simulator.  */
            status =  _ux_hcd_sim_host_transaction_schedule(hcd_sim_host, ed);

            /* If the TD has been added to the list, we can memorize this ED has
               being served and make the next ED as the one to be first scanned
               at the next SOF.  */
            if (status == UX_SUCCESS)
            {

                if (ed -> ux_sim_host_ed_next_ed == UX_NULL)
                    hcd_sim_host -> ux_hcd_sim_host_asynch_current_ed =  hcd_sim_host -> ux_hcd_sim_host_asynch_head_ed;
                else
                    hcd_sim_host -> ux_hcd_sim_host_asynch_current_ed =  ed -> ux_sim_host_ed_next_ed;
            }
        }

        /* Point to the next ED in the list. Check if at end of list.  */
        if (ed -> ux_sim_host_ed_next_ed == UX_NULL)
            ed =  hcd_sim_host -> ux_hcd_sim_host_asynch_head_ed;
        else
            ed =  ed -> ux_sim_host_ed_next_ed;

    } while ((ed) && (ed != first_ed));
}