1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
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_get PORTABLE C */
37 /* 6.1 */
38 /* AUTHOR */
39 /* */
40 /* Chaoqiong Xiao, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function returns a configuration container based on a device */
45 /* handle and a configuration index. */
46 /* */
47 /* INPUT */
48 /* */
49 /* device Pointer to device */
50 /* configuration_index Index of configuration */
51 /* configuration Pointer to configuration */
52 /* destination */
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 /* RELEASE HISTORY */
68 /* */
69 /* DATE NAME DESCRIPTION */
70 /* */
71 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
72 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
73 /* resulting in version 6.1 */
74 /* */
75 /**************************************************************************/
_ux_host_stack_device_configuration_get(UX_DEVICE * device,UINT configuration_index,UX_CONFIGURATION ** configuration)76 UINT _ux_host_stack_device_configuration_get(UX_DEVICE *device, UINT configuration_index,
77 UX_CONFIGURATION **configuration)
78 {
79
80 UINT current_configuration_index;
81 UX_CONFIGURATION *current_configuration;
82
83 /* Do a sanity check on the device handle. */
84 if (device -> ux_device_handle != (ULONG) (ALIGN_TYPE) device)
85 {
86
87 /* Error trap. */
88 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ENUMERATOR, UX_DEVICE_HANDLE_UNKNOWN);
89
90 /* If trace is enabled, insert this event into the trace buffer. */
91 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_DEVICE_HANDLE_UNKNOWN, device, 0, 0, UX_TRACE_ERRORS, 0, 0)
92
93 return(UX_DEVICE_HANDLE_UNKNOWN);
94 }
95
96 /* Start with the configuration attached to the device. */
97 current_configuration = device -> ux_device_first_configuration;
98
99 /* The first configuration has the index 0. */
100 current_configuration_index = 0;
101
102 /* Traverse the list of the configurations until we found the right one. */
103 while (current_configuration != UX_NULL)
104 {
105
106 /* Check if the configuration index matches the current one. */
107 if (configuration_index == current_configuration_index)
108 {
109
110 /* Return the configuration pointer. */
111 *configuration = current_configuration;
112
113 /* If trace is enabled, insert this event into the trace buffer. */
114 UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_DEVICE_CONFIGURATION_GET, device, current_configuration, 0, 0, UX_TRACE_HOST_STACK_EVENTS, 0, 0)
115
116 /* Return successful completion. */
117 return(UX_SUCCESS);
118 }
119
120 /* Move to the next configuration. */
121 current_configuration = current_configuration -> ux_configuration_next_configuration;
122
123 /* Move to the next index. */
124 current_configuration_index++;
125 }
126
127 /* Error trap. */
128 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ENUMERATOR, UX_CONFIGURATION_HANDLE_UNKNOWN);
129
130 /* If trace is enabled, insert this event into the trace buffer. */
131 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_CONFIGURATION_HANDLE_UNKNOWN, configuration, 0, 0, UX_TRACE_ERRORS, 0, 0)
132
133 /* Return an error. */
134 return(UX_CONFIGURATION_HANDLE_UNKNOWN);
135 }
136
137