1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** USBX Component */
16 /** */
17 /** Device Stack */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22 #define UX_SOURCE_CODE
23
24
25 /* Include necessary system files. */
26
27 #include "ux_api.h"
28 #include "ux_device_stack.h"
29
30
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _ux_device_stack_transfer_abort PORTABLE C */
36 /* 6.1.10 */
37 /* AUTHOR */
38 /* */
39 /* Chaoqiong Xiao, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This function aborts a pending transfer request that has been */
44 /* previously submitted. This function only cancels a specific */
45 /* transfer request. */
46 /* */
47 /* The call back to the function will have the */
48 /* UX_TRANSFER_STATUS_ABORT status */
49 /* */
50 /* INPUT */
51 /* */
52 /* transfer_request Pointer to transfer request */
53 /* completion_code Completion code */
54 /* */
55 /* OUTPUT */
56 /* */
57 /* Completion Status */
58 /* */
59 /* CALLS */
60 /* */
61 /* _ux_utility_semaphore_put Put semaphore */
62 /* */
63 /* CALLED BY */
64 /* */
65 /* Application */
66 /* Device Stack */
67 /* */
68 /* RELEASE HISTORY */
69 /* */
70 /* DATE NAME DESCRIPTION */
71 /* */
72 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
73 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
74 /* used UX prefix to refer to */
75 /* TX symbols instead of using */
76 /* them directly, */
77 /* resulting in version 6.1 */
78 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
79 /* added standalone support, */
80 /* assigned aborting code, */
81 /* resulting in version 6.1.10 */
82 /* */
83 /**************************************************************************/
_ux_device_stack_transfer_abort(UX_SLAVE_TRANSFER * transfer_request,ULONG completion_code)84 UINT _ux_device_stack_transfer_abort(UX_SLAVE_TRANSFER *transfer_request, ULONG completion_code)
85 {
86
87 UX_INTERRUPT_SAVE_AREA
88
89 UX_SLAVE_DCD *dcd;
90
91 UX_PARAMETER_NOT_USED(completion_code);
92
93 /* If trace is enabled, insert this event into the trace buffer. */
94 UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_STACK_TRANSFER_ABORT, transfer_request, completion_code, 0, 0, UX_TRACE_DEVICE_STACK_EVENTS, 0, 0)
95
96 /* Get the pointer to the DCD. */
97 dcd = &_ux_system_slave -> ux_system_slave_dcd;
98
99 /* Sets the completion code due to bus reset. */
100 transfer_request -> ux_slave_transfer_request_completion_code = completion_code;
101
102 /* Ensure we're not preempted by the transfer completion ISR. */
103 UX_DISABLE
104
105 /* It's possible the transfer already completed. Ensure it hasn't before doing the abort. */
106 if (transfer_request -> ux_slave_transfer_request_status == UX_TRANSFER_STATUS_PENDING)
107 {
108
109 /* Call the DCD if necessary for cleaning up the pending transfer. */
110 dcd -> ux_slave_dcd_function(dcd, UX_DCD_TRANSFER_ABORT, (VOID *) transfer_request);
111
112 /* Restore interrupts. Note that the transfer request should not be modified now. */
113 UX_RESTORE
114
115 /* We need to set the completion code for the transfer to aborted. Note
116 that the transfer request function cannot simultaneously modify this
117 because if the transfer was pending, then the transfer's thread is
118 currently waiting for it to complete. */
119 transfer_request -> ux_slave_transfer_request_status = UX_TRANSFER_STATUS_ABORT;
120
121 /* Wake up the device driver who is waiting on the semaphore. */
122 _ux_device_semaphore_put(&transfer_request -> ux_slave_transfer_request_semaphore);
123 }
124 else
125 {
126
127 /* Restore interrupts. */
128 UX_RESTORE
129 }
130
131 /* This function never fails. */
132 return(UX_SUCCESS);
133 }
134
135