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 Stack                                                          */
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_host_stack.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _ux_host_stack_endpoint_reset                       PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function resets an endpoint after a stall or other error       */
45 /*    condition.                                                          */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    endpoint                              Endpoint to abort transfer    */
50 /*                                                                        */
51 /*  OUTPUT                                                                */
52 /*                                                                        */
53 /*    Completion Status                                                   */
54 /*                                                                        */
55 /*  CALLS                                                                 */
56 /*                                                                        */
57 /*    _ux_host_stack_transfer_request       Send transfer request         */
58 /*    (ux_hcd_entry_function)               HCD entry function            */
59 /*                                                                        */
60 /*  CALLED BY                                                             */
61 /*                                                                        */
62 /*    USBX Components                                                     */
63 /*                                                                        */
64 /*  RELEASE HISTORY                                                       */
65 /*                                                                        */
66 /*    DATE              NAME                      DESCRIPTION             */
67 /*                                                                        */
68 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
69 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
70 /*                                            optimized based on compile  */
71 /*                                            definitions,                */
72 /*                                            resulting in version 6.1    */
73 /*                                                                        */
74 /**************************************************************************/
_ux_host_stack_endpoint_reset(UX_ENDPOINT * endpoint)75 UINT  _ux_host_stack_endpoint_reset(UX_ENDPOINT *endpoint)
76 {
77 
78 UX_ENDPOINT     *control_endpoint;
79 UX_TRANSFER     *transfer_request;
80 UX_DEVICE       *device;
81 UX_HCD          *hcd;
82 UINT            status;
83 
84 
85     /* Get the device container from the endpoint */
86     device =  endpoint -> ux_endpoint_device;
87 
88     /* If trace is enabled, insert this event into the trace buffer.  */
89     UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_ENDPOINT_RESET, device, endpoint, 0, 0, UX_TRACE_HOST_STACK_EVENTS, 0, 0)
90 
91     /* Get the control endpoint attached to the device.  */
92     control_endpoint =  &device -> ux_device_control_endpoint;
93 
94     /* Retrieve the transfer_request pointer.  */
95     transfer_request =  &control_endpoint -> ux_endpoint_transfer_request;
96 
97     /* Create a transfer_request for the CLEAR_FEATURE request.  */
98     transfer_request -> ux_transfer_request_data_pointer =      UX_NULL;
99     transfer_request -> ux_transfer_request_requested_length =  0;
100     transfer_request -> ux_transfer_request_function =          UX_CLEAR_FEATURE;
101     transfer_request -> ux_transfer_request_type =              UX_REQUEST_OUT| UX_REQUEST_TYPE_STANDARD | UX_REQUEST_TARGET_ENDPOINT;
102     transfer_request -> ux_transfer_request_value =             UX_ENDPOINT_HALT;
103     transfer_request -> ux_transfer_request_index =             endpoint -> ux_endpoint_descriptor.bEndpointAddress;
104 
105     /* Send request to HCD layer.  */
106     status =  _ux_host_stack_transfer_request(transfer_request);
107 
108     /* Reset the endpoint at the HCD level.  */
109     if (status == UX_SUCCESS)
110     {
111 
112         /* Pickup HCD pointer.  */
113         hcd = UX_DEVICE_HCD_GET(device);
114 
115         /* Call HCD entry function.  */
116         status =  hcd -> ux_hcd_entry_function(hcd, UX_HCD_RESET_ENDPOINT, endpoint);
117     }
118 
119     /* And return the completion status.  */
120     return(status);
121 }
122 
123