1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
/***************************************************************************
* Copyright (c) 2024 Microsoft Corporation
* Copyright (c) 2026-present Eclipse ThreadX contributors
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: MIT
**************************************************************************/
/**************************************************************************/
/**************************************************************************/
/** */
/** USBX Component */
/** */
/** Host Stack */
/** */
/**************************************************************************/
/**************************************************************************/
/* Include necessary system files. */
#define UX_SOURCE_CODE
#include "ux_api.h"
#include "ux_host_stack.h"
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _ux_host_stack_configuration_set PORTABLE C */
/* 6.1.10 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function performs a setting of a device configuration. */
/* */
/* In RTOS mode, this function is blocking. */
/* If the host is OTG capable and the device has an OTG descriptor */
/* that supports HNP we perform a SET_FEATURE with b_hnp_support. */
/* */
/* In standalone mode, when device enumeration is in progress, this */
/* function is non-blocking, it prepares transfer for enum step of */
/* SET_CONFIGURE request. Otherwise it blocks until transfer request */
/* done. */
/* */
/* INPUT */
/* */
/* configuration Pointer to configuration */
/* */
/* OUTPUT */
/* */
/* Completion Status */
/* */
/* CALLS */
/* */
/* _ux_host_stack_transfer_request Process transfer request */
/* */
/* CALLED BY */
/* */
/* USBX Components */
/* */
/**************************************************************************/
UINT _ux_host_stack_configuration_set(UX_CONFIGURATION *configuration)
{
UX_DEVICE *device;
UX_TRANSFER *transfer_request;
UINT status;
UX_ENDPOINT *control_endpoint;
#ifdef UX_OTG_SUPPORT
UX_HCD *hcd;
#endif
/* A configuration is selected. Retrieve the pointer to the control endpoint
and its transfer request. */
device = configuration -> ux_configuration_device;
control_endpoint = &device -> ux_device_control_endpoint;
transfer_request = &control_endpoint -> ux_endpoint_transfer_request;
#ifdef UX_OTG_SUPPORT
/* Check if the configuration has an OTG device with HNP feature. */
if (configuration -> ux_configuration_otg_capabilities & UX_OTG_HNP_SUPPORT)
{
/* For HNP to work the device has to be connected directly to the Root Hub and not
a down stream hub. If the parent is NULL, the device is on the root hub. */
if (UX_DEVICE_PARENT_IS_ROOTHUB(device))
{
/* With the device we have the pointer to the HCD. */
hcd = UX_DEVICE_HCD_GET(device);
/* Check the HCD to ensure we have an OTG host controller. */
if (hcd -> ux_hcd_otg_capabilities & UX_HCD_OTG_CAPABLE)
{
/* The Host controller is OTG aware. Perform a SET_FEATURE with b_hnp_support. */
transfer_request -> ux_transfer_request_data_pointer = UX_NULL;
transfer_request -> ux_transfer_request_requested_length = 0;
transfer_request -> ux_transfer_request_function = UX_SET_FEATURE;
transfer_request -> ux_transfer_request_type = UX_REQUEST_OUT| UX_REQUEST_TYPE_STANDARD | UX_REQUEST_TARGET_DEVICE;
transfer_request -> ux_transfer_request_value = UX_OTG_FEATURE_A_HNP_SUPPORT;
transfer_request -> ux_transfer_request_index = 0;
/* Send request to HCD layer. */
status = _ux_host_stack_transfer_request(transfer_request);
/* If the device fails this command we turn off its OTG capabilities. */
if (status != UX_SUCCESS)
/* Reset the OTG capabilities of the device. */
configuration -> ux_configuration_otg_capabilities = 0;
}
}
}
#endif
/* If trace is enabled, insert this event into the trace buffer. */
UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_CONFIGURATION_SET, configuration, 0, 0, 0, UX_TRACE_HOST_STACK_EVENTS, 0, 0)
/* Create a transfer_request for the SET_CONFIGURATION request. No data for this request. */
transfer_request -> ux_transfer_request_requested_length = 0;
transfer_request -> ux_transfer_request_function = UX_SET_CONFIGURATION;
transfer_request -> ux_transfer_request_type = UX_REQUEST_OUT | UX_REQUEST_TYPE_STANDARD | UX_REQUEST_TARGET_DEVICE;
transfer_request -> ux_transfer_request_value = (USHORT) configuration -> ux_configuration_descriptor.bConfigurationValue;
transfer_request -> ux_transfer_request_index = 0;
#if defined(UX_HOST_STANDALONE)
if (device -> ux_device_flags &= UX_DEVICE_FLAG_ENUM)
{
/* Special case for enumeration process, non-blocking. */
device -> ux_device_enum_trans = transfer_request;
status = UX_SUCCESS;
return(status);
}
/* Tend to be blocking after enumeration done. */
#endif
/* Send request to HCD layer. */
status = _ux_host_stack_transfer_request(transfer_request);
/* Check completion status. */
if(status == UX_SUCCESS)
{
/* Change the device state to configured. */
device -> ux_device_state = UX_DEVICE_CONFIGURED;
/* Store the new configuration value in the device container. */
device -> ux_device_current_configuration = configuration;
/* Save current device power source. */
device -> ux_device_power_source = (configuration ->
ux_configuration_descriptor.bmAttributes &
UX_CONFIGURATION_DEVICE_SELF_POWERED) ?
UX_DEVICE_SELF_POWERED : UX_DEVICE_BUS_POWERED;
}
/* Return status to caller. */
return(status);
}
|