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 
24 /* Include necessary system files.  */
25 
26 #define UX_SOURCE_CODE
27 
28 #include "ux_api.h"
29 #include "ux_hcd_sim_host.h"
30 #include "ux_host_stack.h"
31 
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _ux_hcd_sim_host_transfer_abort                     PORTABLE C      */
38 /*                                                           6.1.10       */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Chaoqiong Xiao, Microsoft Corporation                               */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*     This function will abort transactions attached to a transfer       */
46 /*     request.                                                           */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    hcd_sim_host                         Pointer to host controller     */
51 /*    transfer_request                     Pointer to transfer request    */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    Completion Status                                                   */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    _ux_utility_delay_ms                  Delay                         */
60 /*                                                                        */
61 /*  CALLED BY                                                             */
62 /*                                                                        */
63 /*    Host Simulator Controller Driver                                    */
64 /*                                                                        */
65 /*  RELEASE HISTORY                                                       */
66 /*                                                                        */
67 /*    DATE              NAME                      DESCRIPTION             */
68 /*                                                                        */
69 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
70 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
71 /*                                            resulting in version 6.1    */
72 /*  01-31-2022     Chaoqiong Xiao           Modified comment(s),          */
73 /*                                            added standalone support,   */
74 /*                                            resulting in version 6.1.10 */
75 /*                                                                        */
76 /**************************************************************************/
_ux_hcd_sim_host_transfer_abort(UX_HCD_SIM_HOST * hcd_sim_host,UX_TRANSFER * transfer_request)77 UINT  _ux_hcd_sim_host_transfer_abort(UX_HCD_SIM_HOST *hcd_sim_host, UX_TRANSFER *transfer_request)
78 {
79 
80 UX_ENDPOINT             *endpoint;
81 UX_HCD_SIM_HOST_ED      *ed;
82 UX_HCD_SIM_HOST_TD      *head_td;
83 UX_HCD_SIM_HOST_TD      *tail_td;
84 
85     UX_PARAMETER_NOT_USED(hcd_sim_host);
86 
87     /* Get the pointer to the endpoint associated with the transfer request.  */
88     endpoint =  (UX_ENDPOINT *) transfer_request -> ux_transfer_request_endpoint;
89 
90     /* From the endpoint container, get the address of the physical endpoint.  */
91     ed =  (UX_HCD_SIM_HOST_ED *) endpoint -> ux_endpoint_ed;
92 
93     /* Check if this physical endpoint has been initialized properly!  */
94     if (ed == UX_NULL)
95     {
96 
97         /* Error trap. */
98         _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_HCD, UX_ENDPOINT_HANDLE_UNKNOWN);
99 
100         /* If trace is enabled, insert this event into the trace buffer.  */
101         UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_ENDPOINT_HANDLE_UNKNOWN, endpoint, 0, 0, UX_TRACE_ERRORS, 0, 0)
102 
103         return(UX_ENDPOINT_HANDLE_UNKNOWN);
104     }
105 
106 #if defined(UX_HOST_STANDALONE)
107     ed -> ux_sim_host_ed_status |= UX_HCD_SIM_HOST_ED_SKIP;
108 #else
109     /* The endpoint may be active. If so, set the skip bit.  */
110     ed -> ux_sim_host_ed_status |=  UX_HCD_SIM_HOST_ED_SKIP;
111 
112     /* Wait for the controller to finish the current frame processing.  */
113     _ux_utility_delay_ms(1);
114 #endif
115 
116     /* Remove all the TDs from this ED and leave the head and tail pointing to the dummy TD.  */
117     head_td =  ed -> ux_sim_host_ed_head_td;
118     tail_td =  ed -> ux_sim_host_ed_tail_td;
119 
120     /* Free all TDs attached to the ED.  */
121     while (head_td != tail_td)
122     {
123 
124         /* Mark the current head TD as free. */
125         head_td -> ux_sim_host_td_status =  UX_UNUSED;
126 
127         /* Update the head TD with the next TD.  */
128         ed -> ux_sim_host_ed_head_td =  head_td -> ux_sim_host_td_next_td;
129 
130         /* Now the new head TD is the next TD in the chain.  */
131         head_td =  ed -> ux_sim_host_ed_head_td;
132     }
133 
134 #if defined(UX_HOST_STANDALONE)
135     /* Remove the skip and transfer bits in the ED.  */
136     ed -> ux_sim_host_ed_status &= ~(UX_HCD_SIM_HOST_ED_SKIP|UX_HCD_SIM_HOST_ED_TRANSFER);
137 #else
138     /* Remove the reset bit in the ED.  */
139     ed -> ux_sim_host_ed_status &=  (ULONG)~UX_HCD_SIM_HOST_ED_SKIP;
140 #endif
141 
142     /* Return successful completion.  */
143     return(UX_SUCCESS);
144 }
145 
146