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 /**   Device Stack                                                        */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 #define UX_SOURCE_CODE
24 
25 
26 /* Include necessary system files.  */
27 
28 #include "ux_api.h"
29 #include "ux_device_stack.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _ux_device_stack_endpoint_stall                     PORTABLE C      */
37 /*                                                           6.1.10       */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function stalls an endpoint. The host will need to reissue     */
45 /*    a reset to clear the endpoint.                                      */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    endpoint                              Pointer to endpoint           */
50 /*                                                                        */
51 /*  OUTPUT                                                                */
52 /*                                                                        */
53 /*    Completion Status                                                   */
54 /*                                                                        */
55 /*  CALLS                                                                 */
56 /*                                                                        */
57 /*    (ux_slave_dcd_function)               DCD dispatch function         */
58 /*                                                                        */
59 /*  CALLED BY                                                             */
60 /*                                                                        */
61 /*    Application                                                         */
62 /*                                                                        */
63 /*  RELEASE HISTORY                                                       */
64 /*                                                                        */
65 /*    DATE              NAME                      DESCRIPTION             */
66 /*                                                                        */
67 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
68 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
69 /*                                            used UX prefix to refer to  */
70 /*                                            TX symbols instead of using */
71 /*                                            them directly,              */
72 /*                                            resulting in version 6.1    */
73 /*  01-31-2022     Chaoqiong Xiao           Modified comment(s),          */
74 /*                                            added standalone support,   */
75 /*                                            resulting in version 6.1.10 */
76 /*                                                                        */
77 /**************************************************************************/
_ux_device_stack_endpoint_stall(UX_SLAVE_ENDPOINT * endpoint)78 UINT  _ux_device_stack_endpoint_stall(UX_SLAVE_ENDPOINT *endpoint)
79 {
80 
81 UX_INTERRUPT_SAVE_AREA
82 
83 UX_SLAVE_DCD        *dcd;
84 UINT                status;
85 
86     /* If trace is enabled, insert this event into the trace buffer.  */
87     UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_STACK_ENDPOINT_STALL, endpoint, 0, 0, 0, UX_TRACE_DEVICE_STACK_EVENTS, 0, 0)
88 
89     /* Get the pointer to the DCD.  */
90     dcd =  &_ux_system_slave -> ux_system_slave_dcd;
91 
92     /* Assume device is in an invalid state here in order to reduce code in following
93        section where interrupts are disabled.  */
94     status =  UX_ERROR;
95 
96     /* Ensure we don't change the endpoint's state after disconnection routine
97        resets it.  */
98     UX_DISABLE
99 
100     /* Check if the device is in a valid state; as soon as the device is out
101        of the RESET state, transfers occur and thus endpoints may be stalled. */
102     if (_ux_system_slave -> ux_system_slave_device.ux_slave_device_state != UX_DEVICE_RESET &&
103         endpoint -> ux_slave_endpoint_state != UX_ENDPOINT_HALTED)
104     {
105 
106         /* Stall the endpoint.  */
107         status =  dcd -> ux_slave_dcd_function(dcd, UX_DCD_STALL_ENDPOINT, endpoint);
108 
109         /* Mark the endpoint state.  */
110         if ((endpoint -> ux_slave_endpoint_descriptor.bmAttributes & UX_MASK_ENDPOINT_TYPE) !=
111             UX_CONTROL_ENDPOINT)
112             endpoint -> ux_slave_endpoint_state =  UX_ENDPOINT_HALTED;
113     }
114 
115     /* Restore interrupts.  */
116     UX_RESTORE
117 
118     /* Return completion status.  */
119     return(status);
120 }
121 
122