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 /**************************************************************************/
25 /*                                                                        */
26 /*  COMPONENT DEFINITION                                   RELEASE        */
27 /*                                                                        */
28 /*    ux_host_stack.h                                     PORTABLE C      */
29 /*                                                           6.1.12       */
30 /*  AUTHOR                                                                */
31 /*                                                                        */
32 /*    Chaoqiong Xiao, Microsoft Corporation                               */
33 /*                                                                        */
34 /*  DESCRIPTION                                                           */
35 /*                                                                        */
36 /*    This file contains all the header and extern functions used by the  */
37 /*    USBX Host Stack component.                                          */
38 /*                                                                        */
39 /*  RELEASE HISTORY                                                       */
40 /*                                                                        */
41 /*    DATE              NAME                      DESCRIPTION             */
42 /*                                                                        */
43 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
44 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
45 /*                                            added uninitialize APIs,    */
46 /*                                            optimized based on compile  */
47 /*                                            definitions,                */
48 /*                                            resulting in version 6.1    */
49 /*  02-02-2021     Chaoqiong Xiao           Modified comment(s),          */
50 /*                                            added configuration activate*/
51 /*                                            and deactivate support,     */
52 /*                                            added host device string    */
53 /*                                            descriptor get support,     */
54 /*                                            updated internal function,  */
55 /*                                            resulting in version 6.1.4  */
56 /*  08-02-2021     Chaoqiong Xiao           Modified comment(s),          */
57 /*                                            added extern "C" keyword    */
58 /*                                            for compatibility with C++, */
59 /*                                            resulting in version 6.1.8  */
60 /*  01-31-2022     Chaoqiong Xiao           Modified comment(s),          */
61 /*                                            added standalone support,   */
62 /*                                            resulting in version 6.1.10 */
63 /*  07-29-2022     Chaoqiong Xiao           Modified comment(s),          */
64 /*                                            fixed parameter/variable    */
65 /*                                            names conflict C++ keyword, */
66 /*                                            added standalone HUB,       */
67 /*                                            resulting in version 6.1.12 */
68 /*                                                                        */
69 /**************************************************************************/
70 
71 #ifndef UX_HOST_STACK_H
72 #define UX_HOST_STACK_H
73 
74 /* Determine if a C++ compiler is being used.  If so, ensure that standard
75    C is used to process the API information.  */
76 
77 #ifdef   __cplusplus
78 
79 /* Yes, C++ compiler is present.  Use standard C.  */
80 extern   "C" {
81 
82 #endif
83 
84 
85 /* Define Host Stack enumeration state machine states.  */
86 
87 #define UX_HOST_STACK_ENUM_PORT_ENABLE          (UX_STATE_STEP + 0)
88 #define UX_HOST_STACK_ENUM_PORT_RESET           (UX_STATE_STEP + 1)
89 #define UX_HOST_STACK_ENUM_PORT_RESET_WAIT      (UX_STATE_STEP + 2)
90 #define UX_HOST_STACK_ENUM_HUB_OPERATION_WAIT   (UX_STATE_STEP + 3)
91 #define UX_HOST_STACK_ENUM_DEVICE_ADDR_SET      (UX_STATE_STEP + 4)
92 #define UX_HOST_STACK_ENUM_DEVICE_ADDR_SENT     (UX_STATE_STEP + 5)
93 #define UX_HOST_STACK_ENUM_DEVICE_DESCR_READ    (UX_STATE_STEP + 6)
94 #define UX_HOST_STACK_ENUM_DEVICE_DESCR_PARSE   (UX_STATE_STEP + 7)
95 #define UX_HOST_STACK_ENUM_CONFIG_DESCR_READ    (UX_STATE_STEP + 8)
96 #define UX_HOST_STACK_ENUM_CONFIG_DESCR_PARSE   (UX_STATE_STEP + 9)
97 #define UX_HOST_STACK_ENUM_CONFIG_DESCR_NEXT    (UX_STATE_STEP + 10)
98 #define UX_HOST_STACK_ENUM_CONFIG_SET           (UX_STATE_STEP + 11)
99 #define UX_HOST_STACK_ENUM_CONFIG_ACTIVATE      (UX_STATE_STEP + 12)
100 #define UX_HOST_STACK_ENUM_ACTIVATE             (UX_STATE_STEP + 13)
101 #define UX_HOST_STACK_ENUM_ACTIVATE_WAIT        (UX_STATE_STEP + 14)
102 #define UX_HOST_STACK_ENUM_RETRY                (UX_STATE_STEP + 15)
103 #define UX_HOST_STACK_ENUM_NEXT                 (UX_STATE_STEP + 16)
104 #define UX_HOST_STACK_ENUM_TRANS_LOCK_WAIT      (UX_STATE_STEP + 17)
105 #define UX_HOST_STACK_ENUM_TRANS_WAIT           (UX_STATE_STEP + 18)
106 #define UX_HOST_STACK_ENUM_WAIT                 (UX_STATE_STEP + 19)
107 #define UX_HOST_STACK_ENUM_FAIL                 (UX_STATE_STEP + 20)
108 #define UX_HOST_STACK_ENUM_DONE                 (UX_STATE_STEP + 21)
109 #define UX_HOST_STACK_ENUM_IDLE                 (UX_STATE_STEP + 22)
110 
111 
112 /* Define Host Stack component function prototypes.  */
113 
114 #if UX_MAX_DEVICES > 1
115 VOID    _ux_host_stack_bandwidth_release(UX_HCD *hcd, UX_ENDPOINT *endpoint);
116 VOID    _ux_host_stack_bandwidth_claim(UX_HCD *hcd, UX_ENDPOINT *endpoint);
117 UINT    _ux_host_stack_bandwidth_check(UX_HCD *hcd, UX_ENDPOINT *endpoint);
118 #else
119 #define _ux_host_stack_bandwidth_release(a,b)
120 #define _ux_host_stack_bandwidth_claim(a,b)
121 #define _ux_host_stack_bandwidth_check(a,b)                     (UX_SUCCESS)
122 #endif
123 
124 UX_HOST_CLASS * _ux_host_stack_class_call(UX_HOST_CLASS_COMMAND *class_command);
125 UINT    _ux_host_stack_class_device_scan(UX_DEVICE *device);
126 UINT    _ux_host_stack_class_get(UCHAR *class_name, UX_HOST_CLASS **ux_class);
127 UINT    _ux_host_stack_class_instance_destroy(UX_HOST_CLASS *class, VOID *class_instance);
128 UINT    _ux_host_stack_class_instance_create(UX_HOST_CLASS *class, VOID *class_instance);
129 UINT    _ux_host_stack_class_instance_get(UX_HOST_CLASS *class, UINT class_index, VOID **class_instance);
130 UINT    _ux_host_stack_class_instance_verify(UCHAR *class_name, VOID *class_instance);
131 UINT    _ux_host_stack_class_interface_scan(UX_DEVICE *device);
132 UINT    _ux_host_stack_class_register(UCHAR *class_name,
133                         UINT (*class_entry_function)(struct UX_HOST_CLASS_COMMAND_STRUCT *));
134 UINT    _ux_host_stack_class_unregister(UINT (*class_entry_function)(struct UX_HOST_CLASS_COMMAND_STRUCT *));
135 UINT    _ux_host_stack_configuration_descriptor_parse(UX_DEVICE *device, UX_CONFIGURATION *configuration, UINT configuration_index);
136 UINT    _ux_host_stack_configuration_enumerate(UX_DEVICE *device);
137 UINT    _ux_host_stack_configuration_instance_create(UX_CONFIGURATION *configuration);
138 VOID    _ux_host_stack_configuration_instance_delete(UX_CONFIGURATION *configuration);
139 UINT    _ux_host_stack_configuration_interface_get(UX_CONFIGURATION *configuration,
140                                                 UINT interface_index, UINT alternate_setting_index,
141                                                 UX_INTERFACE **ux_interface);
142 UINT    _ux_host_stack_configuration_interface_scan(UX_CONFIGURATION *configuration);
143 UINT    _ux_host_stack_configuration_set(UX_CONFIGURATION *configuration);
144 VOID    _ux_host_stack_delay_ms(ULONG time);
145 UINT    _ux_host_stack_device_address_set(UX_DEVICE *device);
146 UINT    _ux_host_stack_device_configuration_activate(UX_CONFIGURATION *configuration);
147 UINT    _ux_host_stack_device_configuration_deactivate(UX_DEVICE *device);
148 UINT    _ux_host_stack_device_configuration_get(UX_DEVICE *device, UINT configuration_index,
149                                                         UX_CONFIGURATION **configuration);
150 UINT    _ux_host_stack_device_configuration_select(UX_CONFIGURATION *configuration);
151 UINT    _ux_host_stack_device_configuration_reset(UX_DEVICE *device);
152 UINT    _ux_host_stack_device_descriptor_read(UX_DEVICE *device);
153 UINT    _ux_host_stack_device_get(ULONG device_index, UX_DEVICE **device);
154 UINT    _ux_host_stack_device_string_get(UX_DEVICE *device, UCHAR *descriptor_buffer, ULONG length, ULONG language_id, ULONG string_index);
155 UINT    _ux_host_stack_device_remove(UX_HCD *hcd, UX_DEVICE *parent, UINT port_index);
156 UINT    _ux_host_stack_device_resources_free(UX_DEVICE *device);
157 UINT    _ux_host_stack_endpoint_instance_create(UX_ENDPOINT *endpoint);
158 VOID    _ux_host_stack_endpoint_instance_delete(UX_ENDPOINT *endpoint);
159 UINT    _ux_host_stack_endpoint_reset(UX_ENDPOINT *endpoint);
160 UINT    _ux_host_stack_endpoint_transfer_abort(UX_ENDPOINT *endpoint);
161 VOID    _ux_host_stack_enum_thread_entry(ULONG input);
162 UINT    _ux_host_stack_hcd_register(UCHAR *hcd_name,
163                                     UINT (*hcd_init_function)(struct UX_HCD_STRUCT *), ULONG hcd_param1, ULONG hcd_param2);
164 UINT    _ux_host_stack_hcd_unregister(UCHAR *hcd_name, ULONG hcd_param1, ULONG hcd_param2);
165 VOID    _ux_host_stack_hcd_thread_entry(ULONG input);
166 UINT    _ux_host_stack_hcd_transfer_request(UX_TRANSFER *transfer_request);
167 UINT    _ux_host_stack_initialize(UINT (*ux_system_host_change_function)(ULONG, UX_HOST_CLASS *, VOID *));
168 UINT    _ux_host_stack_uninitialize(VOID);
169 UINT    _ux_host_stack_interface_endpoint_get(UX_INTERFACE *ux_interface, UINT endpoint_index, UX_ENDPOINT **endpoint);
170 UINT    _ux_host_stack_interface_instance_create(UX_INTERFACE *ux_interface);
171 VOID    _ux_host_stack_interface_instance_delete(UX_INTERFACE *ux_interface);
172 UINT    _ux_host_stack_interface_set(UX_INTERFACE *ux_interface);
173 UINT    _ux_host_stack_interface_setting_select(UX_INTERFACE *ux_interface);
174 UINT    _ux_host_stack_interfaces_scan(UX_CONFIGURATION *configuration, UCHAR * descriptor);
175 VOID    _ux_host_stack_new_configuration_create(UX_DEVICE *device, UX_CONFIGURATION *configuration);
176 UX_DEVICE  *_ux_host_stack_new_device_get(VOID);
177 UINT    _ux_host_stack_new_device_create(UX_HCD *hcd, UX_DEVICE *device_owner,
178                                 UINT port_index, UINT device_speed,
179                                 UINT port_max_power,
180                                 UX_DEVICE **created_device);
181 UINT    _ux_host_stack_new_endpoint_create(UX_INTERFACE *ux_interface, UCHAR * interface_endpoint);
182 UINT    _ux_host_stack_new_interface_create(UX_CONFIGURATION *configuration, UCHAR * descriptor, ULONG length);
183 VOID    _ux_host_stack_rh_change_process(VOID);
184 UINT    _ux_host_stack_rh_device_extraction(UX_HCD *hcd, UINT port_index);
185 UINT    _ux_host_stack_rh_device_insertion(UX_HCD *hcd, UINT port_index);
186 UINT    _ux_host_stack_transfer_request(UX_TRANSFER *transfer_request);
187 UINT    _ux_host_stack_transfer_request_abort(UX_TRANSFER *transfer_request);
188 UINT    _ux_host_stack_role_swap(UX_DEVICE *device);
189 
190 #if defined(UX_OTG_SUPPORT)
191 VOID    _ux_host_stack_hnp_polling_thread_entry(ULONG id);
192 #endif
193 
194 UINT    _ux_host_stack_tasks_run(VOID);
195 UINT    _ux_host_stack_transfer_run(UX_TRANSFER *transfer_request);
196 
197 /* Determine if a C++ compiler is being used.  If so, complete the standard
198    C conditional started above.  */
199 #ifdef __cplusplus
200 }
201 #endif
202 
203 #endif
204 
205