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