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_start_stop PORTABLE C */ |
38 |
|
|
/* 6.1 */ |
39 |
|
|
/* AUTHOR */ |
40 |
|
|
/* */ |
41 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
42 |
|
|
/* */ |
43 |
|
|
/* DESCRIPTION */ |
44 |
|
|
/* */ |
45 |
|
|
/* This function starts or stops the UFI device. */ |
46 |
|
|
/* */ |
47 |
|
|
/* INPUT */ |
48 |
|
|
/* */ |
49 |
|
|
/* storage Pointer to storage class */ |
50 |
|
|
/* start_stop_flag 1 or 0 if start/stop */ |
51 |
|
|
/* */ |
52 |
|
|
/* OUTPUT */ |
53 |
|
|
/* */ |
54 |
|
|
/* Completion Status */ |
55 |
|
|
/* */ |
56 |
|
|
/* CALLS */ |
57 |
|
|
/* */ |
58 |
|
|
/* _ux_host_class_storage_cbw_initialize Initialize the CBW */ |
59 |
|
|
/* _ux_host_class_storage_transport Send transport layer command */ |
60 |
|
|
/* */ |
61 |
|
|
/* CALLED BY */ |
62 |
|
|
/* */ |
63 |
|
|
/* Storage Class */ |
64 |
|
|
/* */ |
65 |
|
|
/**************************************************************************/ |
66 |
|
3 |
UINT _ux_host_class_storage_start_stop(UX_HOST_CLASS_STORAGE *storage, |
67 |
|
|
ULONG start_stop_signal) |
68 |
|
|
{ |
69 |
|
|
|
70 |
|
|
UINT status; |
71 |
|
|
UCHAR *cbw; |
72 |
|
|
UINT command_length; |
73 |
|
|
ULONG command_retry; |
74 |
|
|
|
75 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
76 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_STORAGE_START_STOP, storage, start_stop_signal, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0) |
77 |
|
|
|
78 |
|
|
/* Use a pointer for the CBW, easier to manipulate. */ |
79 |
|
3 |
cbw = (UCHAR *) storage -> ux_host_class_storage_cbw; |
80 |
|
|
|
81 |
|
|
/* Get the START_STOP Command Length. */ |
82 |
|
|
#ifdef UX_HOST_CLASS_STORAGE_INCLUDE_LEGACY_PROTOCOL_SUPPORT |
83 |
|
|
if (storage -> ux_host_class_storage_interface -> ux_interface_descriptor.bInterfaceSubClass == UX_HOST_CLASS_STORAGE_SUBCLASS_UFI) |
84 |
|
|
command_length = UX_HOST_CLASS_STORAGE_START_STOP_COMMAND_LENGTH_UFI; |
85 |
|
|
else |
86 |
|
|
command_length = UX_HOST_CLASS_STORAGE_START_STOP_COMMAND_LENGTH_SBC; |
87 |
|
|
#else |
88 |
|
3 |
command_length = UX_HOST_CLASS_STORAGE_START_STOP_COMMAND_LENGTH_SBC; |
89 |
|
|
#endif |
90 |
|
|
|
91 |
|
|
/* Initialize the CBW for this command. */ |
92 |
|
3 |
_ux_host_class_storage_cbw_initialize(storage, 0, 0, command_length); |
93 |
|
|
|
94 |
|
|
/* Prepare the START STOP command block. */ |
95 |
|
3 |
*(cbw + UX_HOST_CLASS_STORAGE_CBW_CB + UX_HOST_CLASS_STORAGE_START_STOP_OPERATION) = UX_HOST_CLASS_STORAGE_SCSI_START_STOP; |
96 |
|
|
|
97 |
|
|
/* Set the required signal. */ |
98 |
|
3 |
*(cbw + UX_HOST_CLASS_STORAGE_CBW_CB + UX_HOST_CLASS_STORAGE_START_STOP_START_BIT) = (UCHAR) start_stop_signal; |
99 |
|
|
|
100 |
|
|
/* On floppies, this operation tends to fail a few times. So we try harder. */ |
101 |
✓✓ |
53 |
for (command_retry = 0; command_retry < 50; command_retry++) |
102 |
|
|
{ |
103 |
|
|
|
104 |
|
|
/* Send the command to transport layer. */ |
105 |
|
52 |
status = _ux_host_class_storage_transport(storage, UX_NULL); |
106 |
|
|
|
107 |
|
|
/* If we have a transport error give up. */ |
108 |
✓✓ |
52 |
if(status != UX_SUCCESS) |
109 |
|
|
|
110 |
|
|
/* Return completion status. */ |
111 |
|
1 |
return(status); |
112 |
|
|
|
113 |
|
|
/* Check the CSW. We may learn something there about the state of the device. */ |
114 |
✓✓ |
51 |
if (storage -> ux_host_class_storage_sense_code == 0) |
115 |
|
1 |
return(UX_SUCCESS); |
116 |
|
|
} |
117 |
|
|
|
118 |
|
|
/* The start/Stop did not work. */ |
119 |
|
1 |
return(UX_ERROR); |
120 |
|
|
} |
121 |
|
|
|