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_transfer_abort                     PORTABLE C      */
37 /*                                                           6.1.10       */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function aborts a pending transfer request that has been       */
45 /*    previously submitted. This function only cancels a specific         */
46 /*    transfer request.                                                   */
47 /*                                                                        */
48 /*    The call back to the function will have the                         */
49 /*    UX_TRANSFER_STATUS_ABORT status                                     */
50 /*                                                                        */
51 /*  INPUT                                                                 */
52 /*                                                                        */
53 /*    transfer_request                      Pointer to transfer request   */
54 /*    completion_code                       Completion code               */
55 /*                                                                        */
56 /*  OUTPUT                                                                */
57 /*                                                                        */
58 /*    Completion Status                                                   */
59 /*                                                                        */
60 /*  CALLS                                                                 */
61 /*                                                                        */
62 /*    _ux_utility_semaphore_put             Put semaphore                 */
63 /*                                                                        */
64 /*  CALLED BY                                                             */
65 /*                                                                        */
66 /*    Application                                                         */
67 /*    Device Stack                                                        */
68 /*                                                                        */
69 /*  RELEASE HISTORY                                                       */
70 /*                                                                        */
71 /*    DATE              NAME                      DESCRIPTION             */
72 /*                                                                        */
73 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
74 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
75 /*                                            used UX prefix to refer to  */
76 /*                                            TX symbols instead of using */
77 /*                                            them directly,              */
78 /*                                            resulting in version 6.1    */
79 /*  01-31-2022     Chaoqiong Xiao           Modified comment(s),          */
80 /*                                            added standalone support,   */
81 /*                                            assigned aborting code,     */
82 /*                                            resulting in version 6.1.10 */
83 /*                                                                        */
84 /**************************************************************************/
_ux_device_stack_transfer_abort(UX_SLAVE_TRANSFER * transfer_request,ULONG completion_code)85 UINT  _ux_device_stack_transfer_abort(UX_SLAVE_TRANSFER *transfer_request, ULONG completion_code)
86 {
87 
88 UX_INTERRUPT_SAVE_AREA
89 
90 UX_SLAVE_DCD    *dcd;
91 
92     UX_PARAMETER_NOT_USED(completion_code);
93 
94     /* If trace is enabled, insert this event into the trace buffer.  */
95     UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_STACK_TRANSFER_ABORT, transfer_request, completion_code, 0, 0, UX_TRACE_DEVICE_STACK_EVENTS, 0, 0)
96 
97     /* Get the pointer to the DCD.  */
98     dcd =  &_ux_system_slave -> ux_system_slave_dcd;
99 
100     /* Sets the completion code due to bus reset.  */
101     transfer_request -> ux_slave_transfer_request_completion_code = completion_code;
102 
103     /* Ensure we're not preempted by the transfer completion ISR.  */
104     UX_DISABLE
105 
106     /* It's possible the transfer already completed. Ensure it hasn't before doing the abort.  */
107     if (transfer_request -> ux_slave_transfer_request_status == UX_TRANSFER_STATUS_PENDING)
108     {
109 
110         /* Call the DCD if necessary for cleaning up the pending transfer.  */
111         dcd -> ux_slave_dcd_function(dcd, UX_DCD_TRANSFER_ABORT, (VOID *) transfer_request);
112 
113         /* Restore interrupts. Note that the transfer request should not be modified now.  */
114         UX_RESTORE
115 
116         /* We need to set the completion code for the transfer to aborted. Note
117            that the transfer request function cannot simultaneously modify this
118            because if the transfer was pending, then the transfer's thread is
119            currently waiting for it to complete.  */
120         transfer_request -> ux_slave_transfer_request_status =  UX_TRANSFER_STATUS_ABORT;
121 
122         /* Wake up the device driver who is waiting on the semaphore.  */
123         _ux_device_semaphore_put(&transfer_request -> ux_slave_transfer_request_semaphore);
124     }
125     else
126     {
127 
128         /* Restore interrupts.  */
129         UX_RESTORE
130     }
131 
132     /* This function never fails.  */
133     return(UX_SUCCESS);
134 }
135 
136