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.3.0 */ 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 /* 10-31-2023 Chaoqiong Xiao Modified comment(s), */ 69 /* added error checks support, */ 70 /* resulting in version 6.3.0 */ 71 /* */ 72 /**************************************************************************/ 73 74 #ifndef UX_HOST_STACK_H 75 #define UX_HOST_STACK_H 76 77 /* Determine if a C++ compiler is being used. If so, ensure that standard 78 C is used to process the API information. */ 79 80 #ifdef __cplusplus 81 82 /* Yes, C++ compiler is present. Use standard C. */ 83 extern "C" { 84 85 #endif 86 87 88 /* Internal option: enable the basic USBX error checking. This define is typically used 89 while debugging application. */ 90 #if defined(UX_ENABLE_ERROR_CHECKING) && !defined(UX_HOST_STACK_ENABLE_ERROR_CHECKING) 91 #define UX_HOST_STACK_ENABLE_ERROR_CHECKING 92 #endif 93 94 95 /* Define Host Stack enumeration state machine states. */ 96 97 #define UX_HOST_STACK_ENUM_PORT_ENABLE (UX_STATE_STEP + 0) 98 #define UX_HOST_STACK_ENUM_PORT_RESET (UX_STATE_STEP + 1) 99 #define UX_HOST_STACK_ENUM_PORT_RESET_WAIT (UX_STATE_STEP + 2) 100 #define UX_HOST_STACK_ENUM_HUB_OPERATION_WAIT (UX_STATE_STEP + 3) 101 #define UX_HOST_STACK_ENUM_DEVICE_ADDR_SET (UX_STATE_STEP + 4) 102 #define UX_HOST_STACK_ENUM_DEVICE_ADDR_SENT (UX_STATE_STEP + 5) 103 #define UX_HOST_STACK_ENUM_DEVICE_DESCR_READ (UX_STATE_STEP + 6) 104 #define UX_HOST_STACK_ENUM_DEVICE_DESCR_PARSE (UX_STATE_STEP + 7) 105 #define UX_HOST_STACK_ENUM_CONFIG_DESCR_READ (UX_STATE_STEP + 8) 106 #define UX_HOST_STACK_ENUM_CONFIG_DESCR_PARSE (UX_STATE_STEP + 9) 107 #define UX_HOST_STACK_ENUM_CONFIG_DESCR_NEXT (UX_STATE_STEP + 10) 108 #define UX_HOST_STACK_ENUM_CONFIG_SET (UX_STATE_STEP + 11) 109 #define UX_HOST_STACK_ENUM_CONFIG_ACTIVATE (UX_STATE_STEP + 12) 110 #define UX_HOST_STACK_ENUM_ACTIVATE (UX_STATE_STEP + 13) 111 #define UX_HOST_STACK_ENUM_ACTIVATE_WAIT (UX_STATE_STEP + 14) 112 #define UX_HOST_STACK_ENUM_RETRY (UX_STATE_STEP + 15) 113 #define UX_HOST_STACK_ENUM_NEXT (UX_STATE_STEP + 16) 114 #define UX_HOST_STACK_ENUM_TRANS_LOCK_WAIT (UX_STATE_STEP + 17) 115 #define UX_HOST_STACK_ENUM_TRANS_WAIT (UX_STATE_STEP + 18) 116 #define UX_HOST_STACK_ENUM_WAIT (UX_STATE_STEP + 19) 117 #define UX_HOST_STACK_ENUM_FAIL (UX_STATE_STEP + 20) 118 #define UX_HOST_STACK_ENUM_DONE (UX_STATE_STEP + 21) 119 #define UX_HOST_STACK_ENUM_IDLE (UX_STATE_STEP + 22) 120 121 122 /* Define Host Stack component function prototypes. */ 123 124 #if UX_MAX_DEVICES > 1 125 VOID _ux_host_stack_bandwidth_release(UX_HCD *hcd, UX_ENDPOINT *endpoint); 126 VOID _ux_host_stack_bandwidth_claim(UX_HCD *hcd, UX_ENDPOINT *endpoint); 127 UINT _ux_host_stack_bandwidth_check(UX_HCD *hcd, UX_ENDPOINT *endpoint); 128 #else 129 #define _ux_host_stack_bandwidth_release(a,b) 130 #define _ux_host_stack_bandwidth_claim(a,b) 131 #define _ux_host_stack_bandwidth_check(a,b) (UX_SUCCESS) 132 #endif 133 134 UX_HOST_CLASS * _ux_host_stack_class_call(UX_HOST_CLASS_COMMAND *class_command); 135 UINT _ux_host_stack_class_device_scan(UX_DEVICE *device); 136 UINT _ux_host_stack_class_get(UCHAR *class_name, UX_HOST_CLASS **ux_class); 137 UINT _ux_host_stack_class_instance_destroy(UX_HOST_CLASS *class, VOID *class_instance); 138 UINT _ux_host_stack_class_instance_create(UX_HOST_CLASS *class, VOID *class_instance); 139 UINT _ux_host_stack_class_instance_get(UX_HOST_CLASS *class, UINT class_index, VOID **class_instance); 140 UINT _ux_host_stack_class_instance_verify(UCHAR *class_name, VOID *class_instance); 141 UINT _ux_host_stack_class_interface_scan(UX_DEVICE *device); 142 UINT _ux_host_stack_class_register(UCHAR *class_name, 143 UINT (*class_entry_function)(struct UX_HOST_CLASS_COMMAND_STRUCT *)); 144 UINT _ux_host_stack_class_unregister(UINT (*class_entry_function)(struct UX_HOST_CLASS_COMMAND_STRUCT *)); 145 UINT _ux_host_stack_configuration_descriptor_parse(UX_DEVICE *device, UX_CONFIGURATION *configuration, UINT configuration_index); 146 UINT _ux_host_stack_configuration_enumerate(UX_DEVICE *device); 147 UINT _ux_host_stack_configuration_instance_create(UX_CONFIGURATION *configuration); 148 VOID _ux_host_stack_configuration_instance_delete(UX_CONFIGURATION *configuration); 149 UINT _ux_host_stack_configuration_interface_get(UX_CONFIGURATION *configuration, 150 UINT interface_index, UINT alternate_setting_index, 151 UX_INTERFACE **ux_interface); 152 UINT _ux_host_stack_configuration_interface_scan(UX_CONFIGURATION *configuration); 153 UINT _ux_host_stack_configuration_set(UX_CONFIGURATION *configuration); 154 VOID _ux_host_stack_delay_ms(ULONG time); 155 UINT _ux_host_stack_device_address_set(UX_DEVICE *device); 156 UINT _ux_host_stack_device_configuration_activate(UX_CONFIGURATION *configuration); 157 UINT _ux_host_stack_device_configuration_deactivate(UX_DEVICE *device); 158 UINT _ux_host_stack_device_configuration_get(UX_DEVICE *device, UINT configuration_index, 159 UX_CONFIGURATION **configuration); 160 UINT _ux_host_stack_device_configuration_select(UX_CONFIGURATION *configuration); 161 UINT _ux_host_stack_device_configuration_reset(UX_DEVICE *device); 162 UINT _ux_host_stack_device_descriptor_read(UX_DEVICE *device); 163 UINT _ux_host_stack_device_get(ULONG device_index, UX_DEVICE **device); 164 UINT _ux_host_stack_device_string_get(UX_DEVICE *device, UCHAR *descriptor_buffer, ULONG length, ULONG language_id, ULONG string_index); 165 UINT _ux_host_stack_device_remove(UX_HCD *hcd, UX_DEVICE *parent, UINT port_index); 166 UINT _ux_host_stack_device_resources_free(UX_DEVICE *device); 167 UINT _ux_host_stack_endpoint_instance_create(UX_ENDPOINT *endpoint); 168 VOID _ux_host_stack_endpoint_instance_delete(UX_ENDPOINT *endpoint); 169 UINT _ux_host_stack_endpoint_reset(UX_ENDPOINT *endpoint); 170 UINT _ux_host_stack_endpoint_transfer_abort(UX_ENDPOINT *endpoint); 171 VOID _ux_host_stack_enum_thread_entry(ULONG input); 172 UINT _ux_host_stack_hcd_register(UCHAR *hcd_name, 173 UINT (*hcd_init_function)(struct UX_HCD_STRUCT *), ULONG hcd_param1, ULONG hcd_param2); 174 UINT _ux_host_stack_hcd_unregister(UCHAR *hcd_name, ULONG hcd_param1, ULONG hcd_param2); 175 VOID _ux_host_stack_hcd_thread_entry(ULONG input); 176 UINT _ux_host_stack_hcd_transfer_request(UX_TRANSFER *transfer_request); 177 UINT _ux_host_stack_initialize(UINT (*ux_system_host_change_function)(ULONG, UX_HOST_CLASS *, VOID *)); 178 UINT _ux_host_stack_uninitialize(VOID); 179 UINT _ux_host_stack_interface_endpoint_get(UX_INTERFACE *ux_interface, UINT endpoint_index, UX_ENDPOINT **endpoint); 180 UINT _ux_host_stack_interface_instance_create(UX_INTERFACE *ux_interface); 181 VOID _ux_host_stack_interface_instance_delete(UX_INTERFACE *ux_interface); 182 UINT _ux_host_stack_interface_set(UX_INTERFACE *ux_interface); 183 UINT _ux_host_stack_interface_setting_select(UX_INTERFACE *ux_interface); 184 UINT _ux_host_stack_interfaces_scan(UX_CONFIGURATION *configuration, UCHAR * descriptor); 185 VOID _ux_host_stack_new_configuration_create(UX_DEVICE *device, UX_CONFIGURATION *configuration); 186 UX_DEVICE *_ux_host_stack_new_device_get(VOID); 187 UINT _ux_host_stack_new_device_create(UX_HCD *hcd, UX_DEVICE *device_owner, 188 UINT port_index, UINT device_speed, 189 UINT port_max_power, 190 UX_DEVICE **created_device); 191 UINT _ux_host_stack_new_endpoint_create(UX_INTERFACE *ux_interface, UCHAR * interface_endpoint); 192 UINT _ux_host_stack_new_interface_create(UX_CONFIGURATION *configuration, UCHAR * descriptor, ULONG length); 193 VOID _ux_host_stack_rh_change_process(VOID); 194 UINT _ux_host_stack_rh_device_extraction(UX_HCD *hcd, UINT port_index); 195 UINT _ux_host_stack_rh_device_insertion(UX_HCD *hcd, UINT port_index); 196 UINT _ux_host_stack_transfer_request(UX_TRANSFER *transfer_request); 197 UINT _ux_host_stack_transfer_request_abort(UX_TRANSFER *transfer_request); 198 UINT _ux_host_stack_role_swap(UX_DEVICE *device); 199 200 #if defined(UX_OTG_SUPPORT) 201 VOID _ux_host_stack_hnp_polling_thread_entry(ULONG id); 202 #endif 203 204 UINT _ux_host_stack_tasks_run(VOID); 205 UINT _ux_host_stack_transfer_run(UX_TRANSFER *transfer_request); 206 207 208 UINT _uxe_host_stack_class_get(UCHAR *class_name, UX_HOST_CLASS **ux_class); 209 UINT _uxe_host_stack_class_instance_get(UX_HOST_CLASS *class, UINT class_index, VOID **class_instance); 210 UINT _uxe_host_stack_class_register(UCHAR *class_name, 211 UINT (*class_entry_function)(struct UX_HOST_CLASS_COMMAND_STRUCT *)); 212 UINT _uxe_host_stack_configuration_interface_get(UX_CONFIGURATION *configuration, 213 UINT interface_index, UINT alternate_setting_index, 214 UX_INTERFACE **ux_interface); 215 UINT _uxe_host_stack_device_configuration_activate(UX_CONFIGURATION *configuration); 216 UINT _uxe_host_stack_device_configuration_deactivate(UX_DEVICE *device); 217 UINT _uxe_host_stack_device_configuration_get(UX_DEVICE *device, UINT configuration_index, 218 UX_CONFIGURATION **configuration); 219 UINT _uxe_host_stack_device_get(ULONG device_index, UX_DEVICE **device); 220 UINT _uxe_host_stack_device_string_get(UX_DEVICE *device, UCHAR *descriptor_buffer, ULONG length, ULONG language_id, ULONG string_index); 221 UINT _uxe_host_stack_endpoint_transfer_abort(UX_ENDPOINT *endpoint); 222 UINT _uxe_host_stack_hcd_register(UCHAR *hcd_name, 223 UINT (*hcd_init_function)(struct UX_HCD_STRUCT *), ULONG hcd_param1, ULONG hcd_param2); 224 UINT _uxe_host_stack_hcd_unregister(UCHAR *hcd_name, ULONG hcd_param1, ULONG hcd_param2); 225 UINT _uxe_host_stack_interface_endpoint_get(UX_INTERFACE *ux_interface, UINT endpoint_index, UX_ENDPOINT **endpoint); 226 UINT _uxe_host_stack_interface_setting_select(UX_INTERFACE *ux_interface); 227 UINT _uxe_host_stack_transfer_request(UX_TRANSFER *transfer_request); 228 UINT _uxe_host_stack_transfer_request_abort(UX_TRANSFER *transfer_request); 229 UINT _uxe_host_stack_transfer_run(UX_TRANSFER *transfer_request); 230 231 232 /* Determine if a C++ compiler is being used. If so, complete the standard 233 C conditional started above. */ 234 #ifdef __cplusplus 235 } 236 #endif 237 238 #endif 239 240