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_device_get PORTABLE C */ |
37 |
|
|
/* 6.1 */ |
38 |
|
|
/* AUTHOR */ |
39 |
|
|
/* */ |
40 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
41 |
|
|
/* */ |
42 |
|
|
/* DESCRIPTION */ |
43 |
|
|
/* */ |
44 |
|
|
/* This function returns a device container based on its index. The */ |
45 |
|
|
/* device index start with device 0. Note that the index is a ULONG */ |
46 |
|
|
/* because we could have several controllers and a byte index might */ |
47 |
|
|
/* not be enough. */ |
48 |
|
|
/* */ |
49 |
|
|
/* INPUT */ |
50 |
|
|
/* */ |
51 |
|
|
/* device_index Index of device */ |
52 |
|
|
/* device Destination for device pointer*/ |
53 |
|
|
/* */ |
54 |
|
|
/* OUTPUT */ |
55 |
|
|
/* */ |
56 |
|
|
/* Completion Status */ |
57 |
|
|
/* */ |
58 |
|
|
/* CALLS */ |
59 |
|
|
/* */ |
60 |
|
|
/* None */ |
61 |
|
|
/* */ |
62 |
|
|
/* CALLED BY */ |
63 |
|
|
/* */ |
64 |
|
|
/* Application */ |
65 |
|
|
/* USBX Components */ |
66 |
|
|
/* */ |
67 |
|
|
/**************************************************************************/ |
68 |
|
983 |
UINT _ux_host_stack_device_get(ULONG device_index, UX_DEVICE **device) |
69 |
|
|
{ |
70 |
|
|
|
71 |
|
|
UX_DEVICE *current_device; |
72 |
|
|
#if UX_MAX_DEVICES > 1 |
73 |
|
|
ULONG current_device_index; |
74 |
|
|
#endif |
75 |
|
|
|
76 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
77 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_DEVICE_GET, device_index, 0, 0, 0, UX_TRACE_HOST_STACK_EVENTS, 0, 0) |
78 |
|
|
|
79 |
|
|
/* Check if the device index is still within the limits. */ |
80 |
✓✓ |
983 |
if (device_index >= UX_SYSTEM_HOST_MAX_DEVICES_GET()) |
81 |
|
|
{ |
82 |
|
|
|
83 |
|
|
/* Error trap. */ |
84 |
|
1 |
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ENUMERATOR, UX_DEVICE_HANDLE_UNKNOWN); |
85 |
|
|
|
86 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
87 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_DEVICE_HANDLE_UNKNOWN, device, 0, 0, UX_TRACE_ERRORS, 0, 0) |
88 |
|
|
|
89 |
|
1 |
return(UX_DEVICE_HANDLE_UNKNOWN); |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
#if UX_MAX_DEVICES > 1 |
93 |
|
|
|
94 |
|
|
/* Start with the first device. */ |
95 |
|
982 |
current_device = _ux_system_host -> ux_system_host_device_array; |
96 |
|
982 |
current_device_index = 0; |
97 |
|
|
|
98 |
|
|
/* Search the list until the end. */ |
99 |
✓✓ |
2518 |
while (current_device_index < _ux_system_host -> ux_system_host_max_devices) |
100 |
|
|
{ |
101 |
|
|
|
102 |
|
|
/* Check to see if this device is existing. */ |
103 |
✓✓ |
2326 |
if (current_device -> ux_device_handle != UX_UNUSED) |
104 |
|
|
{ |
105 |
|
|
|
106 |
|
|
/* Have we reached the index we are looking for? */ |
107 |
✓✓ |
791 |
if (device_index == current_device_index) |
108 |
|
|
{ |
109 |
|
|
|
110 |
|
|
/* Yes, return the device pointer. */ |
111 |
|
790 |
*device = current_device; |
112 |
|
|
|
113 |
|
|
/* Return successful completion. */ |
114 |
|
790 |
return(UX_SUCCESS); |
115 |
|
|
} |
116 |
|
|
} |
117 |
|
|
|
118 |
|
|
/* Move to next device index. */ |
119 |
|
1536 |
current_device_index++; |
120 |
|
|
|
121 |
|
|
/* Move to next device. */ |
122 |
|
1536 |
current_device++; |
123 |
|
|
} |
124 |
|
|
#else |
125 |
|
|
|
126 |
|
|
/* Only one device, just check if it's used. */ |
127 |
|
|
current_device = _ux_system_host -> ux_system_host_device_array; |
128 |
|
|
if (current_device -> ux_device_handle != UX_UNUSED) |
129 |
|
|
{ |
130 |
|
|
*device = current_device; |
131 |
|
|
return(UX_SUCCESS); |
132 |
|
|
} |
133 |
|
|
#endif |
134 |
|
|
|
135 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
136 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_DEVICE_HANDLE_UNKNOWN, device, 0, 0, UX_TRACE_ERRORS, 0, 0) |
137 |
|
|
|
138 |
|
|
/* Return error. */ |
139 |
|
192 |
return(UX_DEVICE_HANDLE_UNKNOWN); |
140 |
|
|
} |
141 |
|
|
|
142 |
|
|
|
143 |
|
|
/**************************************************************************/ |
144 |
|
|
/* */ |
145 |
|
|
/* FUNCTION RELEASE */ |
146 |
|
|
/* */ |
147 |
|
|
/* _uxe_host_stack_device_get PORTABLE C */ |
148 |
|
|
/* 6.3.0 */ |
149 |
|
|
/* AUTHOR */ |
150 |
|
|
/* */ |
151 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
152 |
|
|
/* */ |
153 |
|
|
/* DESCRIPTION */ |
154 |
|
|
/* */ |
155 |
|
|
/* This function checks errors in host stack device get function call. */ |
156 |
|
|
/* */ |
157 |
|
|
/* INPUT */ |
158 |
|
|
/* */ |
159 |
|
|
/* device_index Index of device */ |
160 |
|
|
/* device Destination for device pointer*/ |
161 |
|
|
/* */ |
162 |
|
|
/* OUTPUT */ |
163 |
|
|
/* */ |
164 |
|
|
/* None */ |
165 |
|
|
/* */ |
166 |
|
|
/* CALLS */ |
167 |
|
|
/* */ |
168 |
|
|
/* _ux_host_stack_device_get Host stack device get */ |
169 |
|
|
/* */ |
170 |
|
|
/* CALLED BY */ |
171 |
|
|
/* */ |
172 |
|
|
/* Application */ |
173 |
|
|
/* */ |
174 |
|
|
/**************************************************************************/ |
175 |
|
|
UINT _uxe_host_stack_device_get(ULONG device_index, UX_DEVICE **device) |
176 |
|
|
{ |
177 |
|
|
|
178 |
|
|
/* Sanity check. */ |
179 |
|
|
if (device == UX_NULL) |
180 |
|
|
return(UX_INVALID_PARAMETER); |
181 |
|
|
|
182 |
|
|
/* Invoke device get function. */ |
183 |
|
|
return(_ux_host_stack_device_get(device_index, device)); |
184 |
|
|
} |