1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ----------------------------------------------------------------------------
*/
//------------------------------------------------------------------------------
/// \unit
/// !Purpose
///
/// Mass Storage class definitions.
///
/// See
/// - <a
/// href="http://www.usb.org/developers/devclass_docs/usb_msc_overview_1.2.pdf">
/// USB Mass Storage Class Spec. Overview</a>
/// - <a href="http://www.usb.org/developers/devclass_docs/usbmassbulk_10.pdf">
/// USB Mass Storage Class Bulk-Only Transport</a>
///
/// !Usage
///
/// -# Uses "MSD Requests" to check incoming requests from USB Host.
/// -# Uses "MSD Subclass Codes" and "MSD Protocol Codes" to fill %device
/// interface descriptors for a MSD %device.
/// -# Handle the incoming Bulk data with "MSD CBW Definitions" and MSCbw
/// structure.
/// -# Prepare the outgoing Bulk data with "MSD CSW Definitions" and MSCsw
/// structure.
//------------------------------------------------------------------------------
#ifndef MSD_H
#define MSD_H
//------------------------------------------------------------------------------
// Definitions
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/// \page "MSD Requests"
/// This page lists MSD-specific requests ( Actually for Bulk-only protocol ).
///
/// !Requests
/// - MSD_BULK_ONLY_RESET
/// - MSD_GET_MAX_LUN
/// Reset the mass storage %device and its associated interface.
#define MSD_BULK_ONLY_RESET 0xFF
/// Return the maximum LUN number supported by the %device.
#define MSD_GET_MAX_LUN 0xFE
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/// \page "MSD Subclass Codes"
/// This page lists the Subclass Codes for bInterfaceSubClass field.
/// (Table 2.1, USB Mass Storage Class Spec. Overview)
///
/// !SubClasses
/// - MSD_SUBCLASS_RBC
/// - MSD_SUBCLASS_SFF_MCC
/// - MSD_SUBCLASS_QIC
/// - MSD_SUBCLASS_UFI
/// - MSD_SUBCLASS_SFF
/// - MSD_SUBCLASS_SCSI
/// Reduced Block Commands (RBC) T10
#define MSD_SUBCLASS_RBC 0x01
/// C/DVD devices
#define MSD_SUBCLASS_SFF_MCC 0x02
/// Tape device
#define MSD_SUBCLASS_QIC 0x03
/// Floppy disk drive (FDD) device
#define MSD_SUBCLASS_UFI 0x04
/// Floppy disk drive (FDD) device
#define MSD_SUBCLASS_SFF 0x05
/// SCSI transparent command set
#define MSD_SUBCLASS_SCSI 0x06
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/// \page "MSD Protocol Codes"
/// This page lists the Transport Protocol codes for MSD.
/// (Table 3.1, USB Mass Storage Class Spec. Overview)
///
/// !Protocols
/// - MSD_PROTOCOL_CBI_COMPLETION
/// - MSD_PROTOCOL_CBI
/// - MSD_PROTOCOL_BULK_ONLY
/// Control/Bulk/Interrupt (CBI) Transport (with command complete interrupt)
#define MSD_PROTOCOL_CBI_COMPLETION 0x00
/// Control/Bulk/Interrupt (CBI) Transport (no command complete interrupt)
#define MSD_PROTOCOL_CBI 0x01
/// Bulk-Only Transport
#define MSD_PROTOCOL_BULK_ONLY 0x50
//------------------------------------------------------------------------------
/// Test unit control:
#define CTRL_NOT_READY 0x00
#define CTRL_GOOD 0x01
#define CTRL_BUSY 0x02
//------------------------------------------------------------------------------
/// \page "MSD CBW Definitions"
/// This page lists the Command Block Wrapper (CBW) definitions.
///
/// !Constants
/// - MSD_CBW_SIZE
/// - MSD_CBW_SIGNATURE
///
/// !Fields
/// - MSD_CBW_DEVICE_TO_HOST
/// Command Block Wrapper Size
#define MSD_CBW_SIZE 31
/// 'USBC' 0x43425355
#define MSD_CBW_SIGNATURE 0x43425355
/// CBW bmCBWFlags field
#define MSD_CBW_DEVICE_TO_HOST (1 << 7)
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/// \page "MSD CSW Definitions"
/// This page lists the Command Status Wrapper (CSW) definitions.
///
/// !Constants
/// - MSD_CSW_SIZE
/// - MSD_CSW_SIGNATURE
///
/// !Command Block Status Values
/// (Table 5.3 , USB Mass Storage Class Bulk-Only Transport)
/// - MSD_CSW_COMMAND_PASSED
/// - MSD_CSW_COMMAND_FAILED
/// - MSD_CSW_PHASE_ERROR
/// Command Status Wrapper Size
#define MSD_CSW_SIZE 13
/// 'USBS' 0x53425355
#define MSD_CSW_SIGNATURE 0x53425355
/// Command Passed (good status)
#define MSD_CSW_COMMAND_PASSED 0
/// Command Failed
#define MSD_CSW_COMMAND_FAILED 1
/// Phase Error
#define MSD_CSW_PHASE_ERROR 2
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Structures
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/// Command Block Wrapper (CBW),
/// See Table 5.1, USB Mass Storage Class Bulk-Only Transport.
///
/// The CBW shall start on a packet boundary and shall end as a
/// short packet with exactly 31 (1Fh) bytes transferred.
//------------------------------------------------------------------------------
typedef struct {
/// 'USBC' 0x43425355 (little endian)
unsigned int dCBWSignature;
/// Must be the same as dCSWTag
unsigned int dCBWTag;
/// Number of bytes transfer
unsigned int dCBWDataTransferLength;
/// Indicates the directin of the transfer:
/// 0x80=IN=device-to-host,
/// 0x00=OUT=host-to-device
unsigned char bmCBWFlags;
/// bits 0->3: bCBWLUN
unsigned char bCBWLUN :4,
bReserved1:4; /// reserved
/// bits 0->4: bCBWCBLength
unsigned char bCBWCBLength:5,
bReserved2 :3; /// reserved
/// Command block
unsigned char pCommand[16];
} MSCbw;
//------------------------------------------------------------------------------
/// Command Status Wrapper (CSW),
/// See Table 5.2, USB Mass Storage Class Bulk-Only Transport.
//------------------------------------------------------------------------------
typedef struct
{
/// 'USBS' 0x53425355 (little endian)
unsigned int dCSWSignature;
/// Must be the same as dCBWTag
unsigned int dCSWTag;
/// For Data-Out the device shall report in the dCSWDataResidue the
/// difference between the amount of data expected as stated in the
/// dCBWDataTransferLength, and the actual amount of data processed by
/// the device. For Data-In the device shall report in the dCSWDataResidue
/// the difference between the amount of data expected as stated in the
/// dCBWDataTransferLength and the actual amount of relevant data sent by
/// the device. The dCSWDataResidue shall not exceed the value sent in the
/// dCBWDataTransferLength.
unsigned int dCSWDataResidue;
/// Indicates the success or failure of the command.
unsigned char bCSWStatus;
} MSCsw;
#endif //#ifndef MSD_H
|