summaryrefslogtreecommitdiff
path: root/common/usbx_host_controllers/src/ux_hcd_ehci_ed_clean.c
blob: af6c9daf355bd7ba69e4c192e0eab7fd9ec7cd05 (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
/***************************************************************************
 * 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                                                        */
/**                                                                       */
/**   EHCI Controller Driver                                              */
/**                                                                       */
/**************************************************************************/
/**************************************************************************/


/* Include necessary system files.  */

#define UX_SOURCE_CODE

#include "ux_api.h"
#include "ux_hcd_ehci.h"
#include "ux_host_stack.h"


/**************************************************************************/
/*                                                                        */
/*  FUNCTION                                               RELEASE        */
/*                                                                        */
/*    _ux_hcd_ehci_ed_clean                               PORTABLE C      */
/*                                                           6.1          */
/*  AUTHOR                                                                */
/*                                                                        */
/*    Chaoqiong Xiao, Microsoft Corporation                               */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*    This function cleans the tds attached to a ED in case a transfer    */
/*    has to be aborted.                                                  */
/*                                                                        */
/*  INPUT                                                                 */
/*                                                                        */
/*    ed                                    Pointer to ED                 */
/*                                                                        */
/*  OUTPUT                                                                */
/*                                                                        */
/*    Completion Status                                                   */
/*                                                                        */
/*  CALLS                                                                 */
/*                                                                        */
/*    _ux_utility_virtual_address           Get virtual address           */
/*                                                                        */
/*  CALLED BY                                                             */
/*                                                                        */
/*    EHCI Controller Driver                                              */
/*                                                                        */
/**************************************************************************/
UINT  _ux_hcd_ehci_ed_clean(UX_EHCI_ED *ed)
{

UX_EHCI_TD      *td;
UX_EHCI_TD      *next_td;


    /* Get the first pointer to the TD.  */
    td =  ed -> ux_ehci_ed_queue_element;
    td =  (UX_EHCI_TD *) ((ULONG) td & ~UX_EHCI_QH_T);
    td =  _ux_utility_virtual_address(td);

    /* Mark the TD link of the endpoint as terminated.  */
    ed -> ux_ehci_ed_queue_element =  (UX_EHCI_TD *) UX_EHCI_TD_T;

    /* Free all tds attached to the ED.  */
    while (td != UX_NULL)
    {

        /* Get the next TD pointed by the current TD.  */
        next_td =  td -> ux_ehci_td_link_pointer;
        next_td =  (UX_EHCI_TD *) ((ULONG) next_td & ~UX_EHCI_TD_T);
        next_td =  _ux_utility_virtual_address(next_td);

        /* Mark the current TD as free.  */
        td -> ux_ehci_td_status =  UX_UNUSED;

        td =  next_td;
    }

    /* Reset the first TD.  */
    ed -> ux_ehci_ed_first_td =  UX_NULL;

    /* Reset the last TD.  */
    ed -> ux_ehci_ed_last_td =  UX_NULL;

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