summaryrefslogtreecommitdiff
path: root/common/usbx_host_controllers/src/ux_hcd_ohci_periodic_tree_create.c
blob: 5022129a90393948482d8f16681e20650b382d9d (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/***************************************************************************
 * 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                                                        */
/**                                                                       */
/**   OHCI Controller Driver                                              */
/**                                                                       */
/**************************************************************************/
/**************************************************************************/


/* Include necessary system files.  */

#define UX_SOURCE_CODE

#include "ux_api.h"
#include "ux_hcd_ohci.h"
#include "ux_host_stack.h"


/**************************************************************************/
/*                                                                        */
/*  FUNCTION                                               RELEASE        */
/*                                                                        */
/*    _ux_hcd_ohci_periodic_tree_create                   PORTABLE C      */
/*                                                           6.1          */
/*  AUTHOR                                                                */
/*                                                                        */
/*    Chaoqiong Xiao, Microsoft Corporation                               */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*     This function creates the periodic static tree for the interrupt   */
/*     and isochronous eds.                                               */
/*                                                                        */
/*  INPUT                                                                 */
/*                                                                        */
/*    hcd_ohci                              Pointer to OHCI controller    */
/*                                                                        */
/*  OUTPUT                                                                */
/*                                                                        */
/*    Completion Status                                                   */
/*                                                                        */
/*  CALLS                                                                 */
/*                                                                        */
/*    _ux_hcd_ohci_ed_obtain                Obtain an ED                  */
/*    _ux_utility_physical_address          Get physical address          */
/*                                                                        */
/*  CALLED BY                                                             */
/*                                                                        */
/*    OHCI Controller Driver                                              */
/*                                                                        */
/**************************************************************************/
UINT  _ux_hcd_ohci_periodic_tree_create(UX_HCD_OHCI *hcd_ohci)
{

UX_HCD_OHCI_HCCA        *ohci_hcca;
UX_OHCI_ED              *ed;
UINT                    list_index;
UINT                    list_entries;
UINT                    current_list_entry;
UX_OHCI_ED              *ed_list[32];
UX_OHCI_ED              *ed_start_list[32];


    /* We need the pointer to the HCCA. It contains the pointer to the first
       32 periodic entries.  */
    ohci_hcca =  hcd_ohci -> ux_hcd_ohci_hcca;

    /* Start with the 1st list - it has 32 entries.  */
    list_entries =  32;

    /* Create each list one by one starting from the 32ms list.  */
    for (list_index = 0; list_index < 6; list_index++)
    {

        for (current_list_entry = 0; current_list_entry < list_entries;current_list_entry++)
        {

            /* In each list, insert an static ED as the anchor. There should not
               be any errors when obtaining a new ED, still we do a sanity check.  */
            ed =  _ux_hcd_ohci_ed_obtain(hcd_ohci);
            if (ed == UX_NULL)
                return(UX_NO_ED_AVAILABLE);

            /* Mark this anchor ED as static by putting it as SKIPPED, the OHCI
               controller will not look into its tail and head list and will simply
               jump to the next ED.  */
            ed -> ux_ohci_ed_dw0 =  UX_OHCI_ED_SKIP;

            /* Either we hook this new ED to the start list for further processing
               or we hook it to the 2 successive entries in the previous list.  */
            if (list_index == 0)
            {

                ed_start_list[current_list_entry] =  ed;
            }
            else
            {

                ed_list[current_list_entry * 2] -> ux_ohci_ed_next_ed =        _ux_utility_physical_address(ed);
                ed_list[(current_list_entry * 2) + 1] -> ux_ohci_ed_next_ed =  _ux_utility_physical_address(ed);
            }

            /* Memorize this ED in the local list. We do this operation now, otherwise
               we would erase the previous list eds.  */
            ed_list[current_list_entry] =  ed;
        }

        /*  Shift the number of entries in the next list by 1 (i.e. divide by 2).  */
        list_entries =  list_entries >> 1;
    }

    /* The tree has been completed but the entries in the HCCA are in the wrong order.
       We need to swap each entry according to the OHCI specified entry order list
       so that we have a fair interval frequency for each periodic ED. The primary eds
       are fetched from the start list, translated into physical addresses and stored
       into the HCCA.  */
    for (current_list_entry = 0; current_list_entry < 32; current_list_entry++)
    {

        ed =  ed_start_list[_ux_system_host_hcd_periodic_tree_entries[current_list_entry]];
        ohci_hcca -> ux_hcd_ohci_hcca_ed[current_list_entry] =  _ux_utility_physical_address(ed);
    }

    /* Return successful completion.  */
    return(UX_SUCCESS);
}