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 /** Storage Class */ 18 /** */ 19 /**************************************************************************/ 20 /**************************************************************************/ 21 22 23 /* Include necessary system files. */ 24 25 #define UX_SOURCE_CODE 26 27 #include "ux_api.h" 28 #include "ux_host_class_storage.h" 29 #include "ux_host_stack.h" 30 31 32 /**************************************************************************/ 33 /* */ 34 /* FUNCTION RELEASE */ 35 /* */ 36 /* _ux_host_class_storage_device_reset PORTABLE C */ 37 /* 6.1.11 */ 38 /* AUTHOR */ 39 /* */ 40 /* Chaoqiong Xiao, Microsoft Corporation */ 41 /* */ 42 /* DESCRIPTION */ 43 /* */ 44 /* This function will perform a reset on the device if it is a */ 45 /* Bulk Only device. */ 46 /* */ 47 /* INPUT */ 48 /* */ 49 /* storage Pointer to storage class */ 50 /* */ 51 /* OUTPUT */ 52 /* */ 53 /* Completion Status */ 54 /* */ 55 /* CALLS */ 56 /* */ 57 /* _ux_host_stack_transfer_request Process transfer request */ 58 /* _ux_host_stack_endpoint_reset Reset endpoint */ 59 /* */ 60 /* CALLED BY */ 61 /* */ 62 /* Storage Class */ 63 /* */ 64 /* RELEASE HISTORY */ 65 /* */ 66 /* DATE NAME DESCRIPTION */ 67 /* */ 68 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ 69 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ 70 /* resulting in version 6.1 */ 71 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */ 72 /* added standalone support, */ 73 /* resulting in version 6.1.10 */ 74 /* 04-25-2022 Chaoqiong Xiao Modified comment(s), */ 75 /* internal clean up, */ 76 /* resulting in version 6.1.11 */ 77 /* */ 78 /**************************************************************************/ _ux_host_class_storage_device_reset(UX_HOST_CLASS_STORAGE * storage)79UINT _ux_host_class_storage_device_reset(UX_HOST_CLASS_STORAGE *storage) 80 { 81 82 UX_ENDPOINT *control_endpoint; 83 UX_TRANSFER *transfer_request; 84 UINT status; 85 86 87 #ifdef UX_HOST_CLASS_STORAGE_INCLUDE_LEGACY_PROTOCOL_SUPPORT 88 /* We need to perform a reset only for BO devices. */ 89 if (storage -> ux_host_class_storage_interface -> ux_interface_descriptor.bInterfaceProtocol == UX_HOST_CLASS_STORAGE_PROTOCOL_BO) 90 { 91 #endif 92 93 /* We need to get the default control endpoint transfer request pointer. */ 94 control_endpoint = &storage -> ux_host_class_storage_device -> ux_device_control_endpoint; 95 transfer_request = &control_endpoint -> ux_endpoint_transfer_request; 96 97 /* We need to prevent other threads from simultaneously using the endpoint. */ 98 _ux_host_semaphore_get_norc(&control_endpoint -> ux_endpoint_device -> ux_device_protection_semaphore, UX_WAIT_FOREVER); 99 100 /* Create a transfer_request for the RESET request. */ 101 transfer_request -> ux_transfer_request_data_pointer = UX_NULL; 102 transfer_request -> ux_transfer_request_requested_length = 0; 103 transfer_request -> ux_transfer_request_function = UX_HOST_CLASS_STORAGE_RESET; 104 transfer_request -> ux_transfer_request_type = UX_REQUEST_OUT | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE; 105 transfer_request -> ux_transfer_request_value = 0; 106 transfer_request -> ux_transfer_request_index = storage -> ux_host_class_storage_interface -> ux_interface_descriptor.bInterfaceNumber; 107 108 /* Send request to HCD layer. */ 109 status = _ux_host_stack_transfer_request(transfer_request); 110 111 /* Per the spec, reset the endpoints as well. */ 112 _ux_host_stack_endpoint_reset(storage -> ux_host_class_storage_bulk_in_endpoint); 113 _ux_host_stack_endpoint_reset(storage -> ux_host_class_storage_bulk_out_endpoint); 114 115 /* Return completion status. */ 116 return(status); 117 118 #ifdef UX_HOST_CLASS_STORAGE_INCLUDE_LEGACY_PROTOCOL_SUPPORT 119 } 120 121 /* In case the device is not a BO device, we always succeed. */ 122 return(UX_SUCCESS); 123 #endif 124 } 125