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_configuration_select PORTABLE C */ |
37 |
|
|
/* 6.1.10 */ |
38 |
|
|
/* AUTHOR */ |
39 |
|
|
/* */ |
40 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
41 |
|
|
/* */ |
42 |
|
|
/* DESCRIPTION */ |
43 |
|
|
/* */ |
44 |
|
|
/* This function selects a specific configuration for a device. */ |
45 |
|
|
/* When this configuration is set to the device, by default all the */ |
46 |
|
|
/* device interface and their associated alternate setting 0 is */ |
47 |
|
|
/* activated on the device. If the device/interface class driver */ |
48 |
|
|
/* wishes to change the setting of a particular interface, it needs */ |
49 |
|
|
/* to issue a select interface setting function. */ |
50 |
|
|
/* */ |
51 |
|
|
/* INPUT */ |
52 |
|
|
/* */ |
53 |
|
|
/* configuration Pointer to configuration */ |
54 |
|
|
/* */ |
55 |
|
|
/* OUTPUT */ |
56 |
|
|
/* */ |
57 |
|
|
/* Completion Status */ |
58 |
|
|
/* */ |
59 |
|
|
/* CALLS */ |
60 |
|
|
/* */ |
61 |
|
|
/* _ux_host_stack_configuration_instance_create Create configuration */ |
62 |
|
|
/* instance */ |
63 |
|
|
/* _ux_host_stack_configuration_instance_delete Delete configuration */ |
64 |
|
|
/* instance */ |
65 |
|
|
/* _ux_host_stack_configuration_set Set configuration */ |
66 |
|
|
/* */ |
67 |
|
|
/* CALLED BY */ |
68 |
|
|
/* */ |
69 |
|
|
/* Application */ |
70 |
|
|
/* USBX Components */ |
71 |
|
|
/* */ |
72 |
|
|
/**************************************************************************/ |
73 |
|
930 |
UINT _ux_host_stack_device_configuration_select(UX_CONFIGURATION *configuration) |
74 |
|
|
{ |
75 |
|
|
|
76 |
|
|
UX_DEVICE *device; |
77 |
|
|
UX_CONFIGURATION *current_configuration; |
78 |
|
|
UINT status; |
79 |
|
|
|
80 |
|
|
/* Check for validity of the configuration handle. */ |
81 |
✓✓ |
930 |
if (configuration -> ux_configuration_handle != (ULONG) (ALIGN_TYPE) configuration) |
82 |
|
|
{ |
83 |
|
|
|
84 |
|
|
/* Error trap. */ |
85 |
|
4 |
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ENUMERATOR, UX_CONFIGURATION_HANDLE_UNKNOWN); |
86 |
|
|
|
87 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
88 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_CONFIGURATION_HANDLE_UNKNOWN, configuration, 0, 0, UX_TRACE_ERRORS, 0, 0) |
89 |
|
|
|
90 |
|
4 |
return(UX_CONFIGURATION_HANDLE_UNKNOWN); |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
/* Get the device container for this configuration. */ |
94 |
|
926 |
device = configuration -> ux_configuration_device; |
95 |
|
|
|
96 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
97 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_DEVICE_CONFIGURATION_SELECT, device, configuration, 0, 0, UX_TRACE_HOST_STACK_EVENTS, 0, 0) |
98 |
|
|
|
99 |
|
|
/* We need to check the amount of power the bus powered device is consuming |
100 |
|
|
before switch configuration. Otherwise we may run the risk of |
101 |
|
|
an over current fault. */ |
102 |
✓✓ |
926 |
if (((configuration -> ux_configuration_descriptor.bmAttributes & UX_CONFIGURATION_DEVICE_SELF_POWERED) == 0) && |
103 |
✓✓ |
26 |
(configuration -> ux_configuration_descriptor.MaxPower > UX_DEVICE_MAX_POWER_GET(device))) |
104 |
|
|
{ |
105 |
|
|
|
106 |
|
|
/* Error trap. */ |
107 |
|
1 |
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ENUMERATOR, UX_OVER_CURRENT_CONDITION); |
108 |
|
|
|
109 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
110 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_OVER_CURRENT_CONDITION, configuration, 0, 0, UX_TRACE_ERRORS, 0, 0) |
111 |
|
|
|
112 |
|
1 |
return(UX_OVER_CURRENT_CONDITION); |
113 |
|
|
} |
114 |
|
|
|
115 |
|
|
/* Check for the state of the device . If the device is already configured, |
116 |
|
|
we need to cancel the existing configuration before enabling this one. */ |
117 |
✓✓ |
925 |
if (device -> ux_device_state == UX_DEVICE_CONFIGURED) |
118 |
|
|
{ |
119 |
|
|
|
120 |
|
|
/* The device is configured. Get the first configuration pointer. */ |
121 |
|
5 |
current_configuration = device -> ux_device_current_configuration; |
122 |
|
|
|
123 |
|
|
/* Deselect this instance */ |
124 |
|
5 |
_ux_host_stack_configuration_instance_delete(current_configuration); |
125 |
|
|
} |
126 |
|
|
|
127 |
|
|
/* The device can now be configured. */ |
128 |
|
925 |
status = _ux_host_stack_configuration_set(configuration); |
129 |
✓✓ |
925 |
if (status != UX_SUCCESS) |
130 |
|
16 |
return(status); |
131 |
|
|
|
132 |
|
|
/* Create the configuration instance. */ |
133 |
|
909 |
status = _ux_host_stack_configuration_instance_create(configuration); |
134 |
|
|
|
135 |
|
|
/* Return completion status. */ |
136 |
|
909 |
return(status); |
137 |
|
|
} |
138 |
|
|
|