1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* Copyright (c) 2026-present Eclipse ThreadX contributors |
4 |
|
|
* |
5 |
|
|
* This program and the accompanying materials are made available under the |
6 |
|
|
* terms of the MIT License which is available at |
7 |
|
|
* https://opensource.org/licenses/MIT. |
8 |
|
|
* |
9 |
|
|
* SPDX-License-Identifier: MIT |
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_transfer_request_abort PORTABLE C */ |
37 |
|
|
/* 6.2.0 */ |
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 the 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 Transfer request structure */ |
54 |
|
|
/* */ |
55 |
|
|
/* OUTPUT */ |
56 |
|
|
/* */ |
57 |
|
|
/* Completion Status If UX_SUCCESS, transfer was */ |
58 |
|
|
/* successfully aborted */ |
59 |
|
|
/* */ |
60 |
|
|
/* CALLS */ |
61 |
|
|
/* */ |
62 |
|
|
/* HCD Entry Function */ |
63 |
|
|
/* Transfer Completion Function */ |
64 |
|
|
/* _ux_utility_semaphore_put Put semaphore */ |
65 |
|
|
/* */ |
66 |
|
|
/* CALLED BY */ |
67 |
|
|
/* */ |
68 |
|
|
/* Application */ |
69 |
|
|
/* USBX Components */ |
70 |
|
|
/* */ |
71 |
|
|
/**************************************************************************/ |
72 |
|
2107 |
UINT _ux_host_stack_transfer_request_abort(UX_TRANSFER *transfer_request) |
73 |
|
|
{ |
74 |
|
|
|
75 |
|
|
UX_HCD *hcd; |
76 |
|
|
ULONG completion_code; |
77 |
|
|
|
78 |
|
|
|
79 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
80 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_TRANSFER_REQUEST_ABORT, |
81 |
|
|
transfer_request -> ux_transfer_request_endpoint -> ux_endpoint_device, |
82 |
|
|
transfer_request -> ux_transfer_request_endpoint, |
83 |
|
|
transfer_request, 0, UX_TRACE_HOST_STACK_EVENTS, 0, 0) |
84 |
|
|
|
85 |
|
|
/* With the device we have the pointer to the HCD. */ |
86 |
|
2107 |
hcd = UX_DEVICE_HCD_GET(transfer_request -> ux_transfer_request_endpoint -> ux_endpoint_device); |
87 |
|
|
|
88 |
|
|
/* Check pending transaction. */ |
89 |
✓✓ |
2107 |
if (transfer_request -> ux_transfer_request_completion_code == UX_TRANSFER_STATUS_PENDING) |
90 |
|
|
{ |
91 |
|
|
|
92 |
|
|
/* Send the abort command to the controller. */ |
93 |
|
826 |
hcd -> ux_hcd_entry_function(hcd, UX_HCD_TRANSFER_ABORT, transfer_request); |
94 |
|
|
|
95 |
|
|
/* Save the completion code since we're about to set it to ABORT. The |
96 |
|
|
reason we can't just assume its value is PENDING is that in between |
97 |
|
|
the completion code check and this line, it's possible that the transfer |
98 |
|
|
completed (by HCD function call below, or ISR), which would've |
99 |
|
|
changed the completion code to SUCCESS and put the semaphore. |
100 |
|
|
Even it's recommended to keep completion code untouched to let things |
101 |
|
|
changed later here. |
102 |
|
|
Such a case is valid, and we want to make sure we don't put() the |
103 |
|
|
transfer request's semaphore again. */ |
104 |
|
825 |
completion_code = transfer_request -> ux_transfer_request_completion_code; |
105 |
|
|
|
106 |
|
|
/* Set the transfer_request status to abort. */ |
107 |
|
825 |
transfer_request -> ux_transfer_request_completion_code = UX_TRANSFER_STATUS_ABORT; |
108 |
|
|
|
109 |
|
|
/* We need to inform the class that owns this transfer_request of the |
110 |
|
|
abort if there is a call back mechanism. */ |
111 |
✓✓ |
825 |
if (transfer_request -> ux_transfer_request_completion_function != UX_NULL) |
112 |
|
277 |
transfer_request -> ux_transfer_request_completion_function(transfer_request); |
113 |
|
|
|
114 |
|
|
/* Is a thread waiting on the semaphore? */ |
115 |
✓✓ |
825 |
if (/* Is the transfer pending? */ |
116 |
✓✓ |
822 |
completion_code == UX_TRANSFER_STATUS_PENDING && |
117 |
|
|
#if !defined(UX_HOST_STANDALONE) |
118 |
|
|
/* Is the thread waiting not this one? (clearly we're not waiting!) */ |
119 |
|
822 |
transfer_request -> ux_transfer_request_thread_pending != _ux_utility_thread_identify() && |
120 |
|
|
#endif |
121 |
|
|
/* Does the transfer request not have a completion function? */ |
122 |
✓✓ |
121 |
transfer_request -> ux_transfer_request_completion_function == UX_NULL) |
123 |
|
|
|
124 |
|
|
/* Wake up the semaphore for this request. */ |
125 |
|
57 |
_ux_host_semaphore_put(&transfer_request -> ux_transfer_request_semaphore); |
126 |
|
|
} |
127 |
|
|
|
128 |
|
|
/* This function never fails! */ |
129 |
|
2106 |
return(UX_SUCCESS); |
130 |
|
|
} |
131 |
|
|
|
132 |
|
|
|
133 |
|
|
/**************************************************************************/ |
134 |
|
|
/* */ |
135 |
|
|
/* FUNCTION RELEASE */ |
136 |
|
|
/* */ |
137 |
|
|
/* _uxe_host_stack_transfer_request_abort PORTABLE C */ |
138 |
|
|
/* 6.3.0 */ |
139 |
|
|
/* AUTHOR */ |
140 |
|
|
/* */ |
141 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
142 |
|
|
/* */ |
143 |
|
|
/* DESCRIPTION */ |
144 |
|
|
/* */ |
145 |
|
|
/* This function checks errors in host stack transfer abort function */ |
146 |
|
|
/* call. */ |
147 |
|
|
/* */ |
148 |
|
|
/* INPUT */ |
149 |
|
|
/* */ |
150 |
|
|
/* transfer_request Pointer to transfer */ |
151 |
|
|
/* */ |
152 |
|
|
/* OUTPUT */ |
153 |
|
|
/* */ |
154 |
|
|
/* None */ |
155 |
|
|
/* */ |
156 |
|
|
/* CALLS */ |
157 |
|
|
/* */ |
158 |
|
|
/* _ux_host_stack_transfer_request_abort Transfer abort */ |
159 |
|
|
/* */ |
160 |
|
|
/* CALLED BY */ |
161 |
|
|
/* */ |
162 |
|
|
/* Application */ |
163 |
|
|
/* */ |
164 |
|
|
/**************************************************************************/ |
165 |
|
|
UINT _uxe_host_stack_transfer_request_abort(UX_TRANSFER *transfer_request) |
166 |
|
|
{ |
167 |
|
|
|
168 |
|
|
/* Sanity checks. */ |
169 |
|
|
if (transfer_request == UX_NULL) |
170 |
|
|
return(UX_INVALID_PARAMETER); |
171 |
|
|
if (transfer_request -> ux_transfer_request_endpoint == UX_NULL) |
172 |
|
|
return(UX_ENDPOINT_HANDLE_UNKNOWN); |
173 |
|
|
if (transfer_request -> ux_transfer_request_endpoint -> ux_endpoint_device == UX_NULL) |
174 |
|
|
return(UX_DEVICE_HANDLE_UNKNOWN); |
175 |
|
|
if (UX_DEVICE_HCD_GET(transfer_request -> ux_transfer_request_endpoint -> ux_endpoint_device) == UX_NULL) |
176 |
|
|
return(UX_INVALID_PARAMETER); |
177 |
|
|
|
178 |
|
|
/* Invoke transfer abort function. */ |
179 |
|
|
return(_ux_host_stack_transfer_request_abort(transfer_request)); |
180 |
|
|
} |