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 |
|
|
/** HUB Class */ |
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_class_hub.h" |
30 |
|
|
#include "ux_host_stack.h" |
31 |
|
|
|
32 |
|
|
|
33 |
|
|
/**************************************************************************/ |
34 |
|
|
/* */ |
35 |
|
|
/* FUNCTION RELEASE */ |
36 |
|
|
/* */ |
37 |
|
|
/* _ux_host_class_hub_status_get PORTABLE C */ |
38 |
|
|
/* 6.1.12 */ |
39 |
|
|
/* AUTHOR */ |
40 |
|
|
/* */ |
41 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
42 |
|
|
/* */ |
43 |
|
|
/* DESCRIPTION */ |
44 |
|
|
/* */ |
45 |
|
|
/* This function will do a GET_STATUS from the HUB. This function */ |
46 |
|
|
/* retrieves the current status and the changed bits. */ |
47 |
|
|
/* */ |
48 |
|
|
/* In standalone mode, this functioin prepares the control transfer */ |
49 |
|
|
/* request data memory and request context of specific command, for */ |
50 |
|
|
/* host stack transfer function to process, in next steps. The */ |
51 |
|
|
/* allocated memory must be freed after transfer request is processed. */ |
52 |
|
|
/* */ |
53 |
|
|
/* INPUT */ |
54 |
|
|
/* */ |
55 |
|
|
/* hub Pointer to HUB class */ |
56 |
|
|
/* port Port of device */ |
57 |
|
|
/* port_status Destination for port status */ |
58 |
|
|
/* port_change Destination for port change */ |
59 |
|
|
/* */ |
60 |
|
|
/* OUTPUT */ |
61 |
|
|
/* */ |
62 |
|
|
/* Completion Status */ |
63 |
|
|
/* */ |
64 |
|
|
/* CALLS */ |
65 |
|
|
/* */ |
66 |
|
|
/* _ux_host_stack_transfer_request Process transfer request */ |
67 |
|
|
/* _ux_utility_memory_allocate Allocate memory block */ |
68 |
|
|
/* _ux_utility_memory_free Release memory block */ |
69 |
|
|
/* _ux_utility_short_get Get 16-bit word */ |
70 |
|
|
/* */ |
71 |
|
|
/* CALLED BY */ |
72 |
|
|
/* */ |
73 |
|
|
/* HUB Class */ |
74 |
|
|
/* */ |
75 |
|
|
/**************************************************************************/ |
76 |
|
79 |
UINT _ux_host_class_hub_status_get(UX_HOST_CLASS_HUB *hub, UINT port, USHORT *port_status, USHORT *port_change) |
77 |
|
|
{ |
78 |
|
|
|
79 |
|
|
UCHAR *port_data; |
80 |
|
|
UX_ENDPOINT *control_endpoint; |
81 |
|
|
UX_TRANSFER *transfer_request; |
82 |
|
|
UINT target; |
83 |
|
|
UINT status; |
84 |
|
|
|
85 |
|
|
|
86 |
|
|
/* We need to get the default control endpoint transfer request pointer. */ |
87 |
|
79 |
control_endpoint = &hub -> ux_host_class_hub_device -> ux_device_control_endpoint; |
88 |
|
79 |
transfer_request = &control_endpoint -> ux_endpoint_transfer_request; |
89 |
|
|
|
90 |
|
|
/* The target is DEVICE for the HUB and OTHER for the downstream ports. */ |
91 |
✓✓ |
79 |
if (port == 0) |
92 |
|
2 |
target = UX_REQUEST_TARGET_DEVICE; |
93 |
|
|
else |
94 |
|
77 |
target = UX_REQUEST_TARGET_OTHER; |
95 |
|
|
|
96 |
|
|
/* Allocate a buffer for the port status and change: 2 words. */ |
97 |
|
79 |
port_data = _ux_utility_memory_allocate(UX_SAFE_ALIGN, UX_CACHE_SAFE_MEMORY, 4); |
98 |
✓✓ |
79 |
if(port_data == UX_NULL) |
99 |
|
1 |
return(UX_MEMORY_INSUFFICIENT); |
100 |
|
|
|
101 |
|
|
/* Create a transfer request for the GET_STATUS request. */ |
102 |
|
78 |
transfer_request -> ux_transfer_request_requested_length = 4; |
103 |
|
78 |
transfer_request -> ux_transfer_request_data_pointer = port_data; |
104 |
|
78 |
transfer_request -> ux_transfer_request_function = UX_HOST_CLASS_HUB_GET_STATUS; |
105 |
|
78 |
transfer_request -> ux_transfer_request_type = UX_REQUEST_IN | UX_REQUEST_TYPE_CLASS | target; |
106 |
|
78 |
transfer_request -> ux_transfer_request_value = 0; |
107 |
|
78 |
transfer_request -> ux_transfer_request_index = port; |
108 |
|
|
|
109 |
|
|
#if defined(UX_HOST_STANDALONE) |
110 |
|
|
|
111 |
|
|
/* No status change change copy. */ |
112 |
|
|
UX_PARAMETER_NOT_USED(port_status); |
113 |
|
|
UX_PARAMETER_NOT_USED(port_change); |
114 |
|
|
|
115 |
|
|
/* Save allocated buffer. */ |
116 |
|
|
hub -> ux_host_class_hub_allocated = port_data; |
117 |
|
|
|
118 |
|
|
/* Reset transfer state for _run. */ |
119 |
|
|
UX_TRANSFER_STATE_RESET(transfer_request); |
120 |
|
|
status = UX_SUCCESS; |
121 |
|
|
#else |
122 |
|
|
|
123 |
|
|
/* Send request to HCD layer. */ |
124 |
|
78 |
status = _ux_host_stack_transfer_request(transfer_request); |
125 |
|
|
|
126 |
|
|
/* Check for error and completion of the transfer. */ |
127 |
✓✓ |
78 |
if (status == UX_SUCCESS) |
128 |
|
|
{ |
129 |
|
|
|
130 |
✓✓ |
75 |
if (transfer_request -> ux_transfer_request_actual_length == 4) |
131 |
|
|
{ |
132 |
|
|
|
133 |
|
|
/* The 2 words are now in the buffer. We need to resolve their endianness |
134 |
|
|
and report them as separate items to the called. */ |
135 |
|
74 |
*port_status = (USHORT)_ux_utility_short_get(port_data); |
136 |
|
74 |
*port_change = (USHORT)_ux_utility_short_get(port_data+2); |
137 |
|
|
} |
138 |
|
|
else |
139 |
|
|
{ |
140 |
|
|
|
141 |
|
|
/* Invalid length. Return error. */ |
142 |
|
1 |
status = UX_TRANSFER_DATA_LESS_THAN_EXPECTED; |
143 |
|
|
} |
144 |
|
|
} |
145 |
|
|
|
146 |
|
|
/* Free the buffer resource now. */ |
147 |
|
78 |
_ux_utility_memory_free(port_data); |
148 |
|
|
|
149 |
|
|
#endif |
150 |
|
|
|
151 |
|
|
/* Return completion status. */ |
152 |
|
78 |
return(status); |
153 |
|
|
} |