1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* Copyright (c) 2026-present Eclipse ThreadX contributors |
4 |
|
|
* |
5 |
|
|
* This program and the accompanying materials are made available under the |
6 |
|
|
* terms of the MIT License which is available at |
7 |
|
|
* https://opensource.org/licenses/MIT. |
8 |
|
|
* |
9 |
|
|
* SPDX-License-Identifier: MIT |
10 |
|
|
**************************************************************************/ |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/**************************************************************************/ |
15 |
|
|
/** */ |
16 |
|
|
/** USBX Component */ |
17 |
|
|
/** */ |
18 |
|
|
/** Storage Class */ |
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_class_storage.h" |
30 |
|
|
#include "ux_host_stack.h" |
31 |
|
|
|
32 |
|
|
|
33 |
|
|
/**************************************************************************/ |
34 |
|
|
/* */ |
35 |
|
|
/* FUNCTION RELEASE */ |
36 |
|
|
/* */ |
37 |
|
|
/* _ux_host_class_storage_device_reset PORTABLE C */ |
38 |
|
|
/* 6.1.11 */ |
39 |
|
|
/* AUTHOR */ |
40 |
|
|
/* */ |
41 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
42 |
|
|
/* */ |
43 |
|
|
/* DESCRIPTION */ |
44 |
|
|
/* */ |
45 |
|
|
/* This function will perform a reset on the device if it is a */ |
46 |
|
|
/* Bulk Only device. */ |
47 |
|
|
/* */ |
48 |
|
|
/* INPUT */ |
49 |
|
|
/* */ |
50 |
|
|
/* storage Pointer to storage class */ |
51 |
|
|
/* */ |
52 |
|
|
/* OUTPUT */ |
53 |
|
|
/* */ |
54 |
|
|
/* Completion Status */ |
55 |
|
|
/* */ |
56 |
|
|
/* CALLS */ |
57 |
|
|
/* */ |
58 |
|
|
/* _ux_host_stack_transfer_request Process transfer request */ |
59 |
|
|
/* _ux_host_stack_endpoint_reset Reset endpoint */ |
60 |
|
|
/* */ |
61 |
|
|
/* CALLED BY */ |
62 |
|
|
/* */ |
63 |
|
|
/* Storage Class */ |
64 |
|
|
/* */ |
65 |
|
|
/**************************************************************************/ |
66 |
|
288 |
UINT _ux_host_class_storage_device_reset(UX_HOST_CLASS_STORAGE *storage) |
67 |
|
|
{ |
68 |
|
|
|
69 |
|
|
UX_ENDPOINT *control_endpoint; |
70 |
|
|
UX_TRANSFER *transfer_request; |
71 |
|
|
UINT status; |
72 |
|
|
|
73 |
|
|
|
74 |
|
|
#ifdef UX_HOST_CLASS_STORAGE_INCLUDE_LEGACY_PROTOCOL_SUPPORT |
75 |
|
|
/* We need to perform a reset only for BO devices. */ |
76 |
|
|
if (storage -> ux_host_class_storage_interface -> ux_interface_descriptor.bInterfaceProtocol == UX_HOST_CLASS_STORAGE_PROTOCOL_BO) |
77 |
|
|
{ |
78 |
|
|
#endif |
79 |
|
|
|
80 |
|
|
/* We need to get the default control endpoint transfer request pointer. */ |
81 |
|
288 |
control_endpoint = &storage -> ux_host_class_storage_device -> ux_device_control_endpoint; |
82 |
|
288 |
transfer_request = &control_endpoint -> ux_endpoint_transfer_request; |
83 |
|
|
|
84 |
|
|
/* We need to prevent other threads from simultaneously using the endpoint. */ |
85 |
|
288 |
_ux_host_semaphore_get_norc(&control_endpoint -> ux_endpoint_device -> ux_device_protection_semaphore, UX_WAIT_FOREVER); |
86 |
|
|
|
87 |
|
|
/* Create a transfer_request for the RESET request. */ |
88 |
|
288 |
transfer_request -> ux_transfer_request_data_pointer = UX_NULL; |
89 |
|
288 |
transfer_request -> ux_transfer_request_requested_length = 0; |
90 |
|
288 |
transfer_request -> ux_transfer_request_function = UX_HOST_CLASS_STORAGE_RESET; |
91 |
|
288 |
transfer_request -> ux_transfer_request_type = UX_REQUEST_OUT | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE; |
92 |
|
288 |
transfer_request -> ux_transfer_request_value = 0; |
93 |
|
288 |
transfer_request -> ux_transfer_request_index = storage -> ux_host_class_storage_interface -> ux_interface_descriptor.bInterfaceNumber; |
94 |
|
|
|
95 |
|
|
/* Send request to HCD layer. */ |
96 |
|
288 |
status = _ux_host_stack_transfer_request(transfer_request); |
97 |
|
|
|
98 |
|
|
/* Per the spec, reset the endpoints as well. */ |
99 |
|
288 |
_ux_host_stack_endpoint_reset(storage -> ux_host_class_storage_bulk_in_endpoint); |
100 |
|
288 |
_ux_host_stack_endpoint_reset(storage -> ux_host_class_storage_bulk_out_endpoint); |
101 |
|
|
|
102 |
|
|
/* Return completion status. */ |
103 |
|
288 |
return(status); |
104 |
|
|
|
105 |
|
|
#ifdef UX_HOST_CLASS_STORAGE_INCLUDE_LEGACY_PROTOCOL_SUPPORT |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
/* In case the device is not a BO device, we always succeed. */ |
109 |
|
|
return(UX_SUCCESS); |
110 |
|
|
#endif |
111 |
|
|
} |