tmp
doxygen.7AND9C
usbmsc.h
Go to the documentation of this file.
1
//*****************************************************************************
2
//
3
// usbmsc.h - Generic types and defines use by the mass storage class.
4
//
5
// Copyright (c) 2008-2017 Texas Instruments Incorporated. All rights reserved.
6
// Software License Agreement
7
//
8
// Texas Instruments (TI) is supplying this software for use solely and
9
// exclusively on TI's microcontroller products. The software is owned by
10
// TI and/or its suppliers, and is protected under applicable copyright
11
// laws. You may not combine this software with "viral" open-source
12
// software in order to form a larger program.
13
//
14
// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
15
// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
16
// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17
// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
18
// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
19
// DAMAGES, FOR ANY REASON WHATSOEVER.
20
//
21
//*****************************************************************************
22
23
#ifndef __USBMSC_H__
24
#define __USBMSC_H__
25
26
//*****************************************************************************
27
//
28
// If building with a C++ compiler, make all of the definitions in this header
29
// have a C binding.
30
//
31
//*****************************************************************************
32
#ifdef __cplusplus
33
extern
"C"
34
{
35
#endif
36
37
//*****************************************************************************
38
//
39
// The request for the maximum number of logical units on a mass storage
40
// device.
41
//
42
//*****************************************************************************
43
#define USBREQ_GET_MAX_LUN 0xfe
44
45
//*****************************************************************************
46
//
47
// The request for the bulk only reset of a mass storage device.
48
//
49
//*****************************************************************************
50
#define USBREQ_BULK_ONLY_RESET 0xff
51
52
//*****************************************************************************
53
//
54
// The signatures defined by USB MSC class specification.
55
//
56
//*****************************************************************************
57
#define CBW_SIGNATURE 0x43425355
58
#define CSW_SIGNATURE 0x53425355
59
60
//*****************************************************************************
61
//
62
// Flag for the bmCBWFlags member of tMSCCBW
63
//
64
//*****************************************************************************
65
#define CBWFLAGS_DIR_M 0x80
66
#define CBWFLAGS_DIR_IN 0x80
67
#define CBWFLAGS_DIR_OUT 0x00
68
69
//*****************************************************************************
70
//
71
// All structures defined in this section of the header require byte packing of
72
// fields. This is usually accomplished using the PACKED macro but, for IAR
73
// Embedded Workbench, this requries a pragma.
74
//
75
//*****************************************************************************
76
#ifdef __ICCARM__
77
#pragma pack(1)
78
#endif
79
80
//*****************************************************************************
81
//
82
// The following packed structure is used to access the Command Block Wrapper
83
// (CBW) data structure that is used when communicating with USB Mass Storage
84
// Class devices.
85
//
86
//*****************************************************************************
87
typedef
struct
88
{
89
//
90
// Signature that helps identify this data packet as a CBW. The signature
91
// field shall contain the value 0x43425355 (little endian), indicating a
92
// CBW.
93
//
94
uint32_t
dCBWSignature
;
95
96
//
97
// The Command Block Tag sent by the host controller. The device shall
98
// echo the contents of this field back to the host in the dCSWTag field
99
// of the associated CSW. The dCSWTag positively associates a CSW with the
100
// corresponding CBW.
101
//
102
uint32_t
dCBWTag
;
103
104
//
105
// The number of bytes of data that the host expects to transfer on the
106
// Bulk-In or Bulk-Out endpoint (as indicated by the Direction bit) during
107
// the execution of this command. If this field is zero, the device and
108
// the host will not transfer data between the CBW and the associated CSW,
109
// and the device will ignore the value of the Direction bit in
110
// bmCBWFlags.
111
//
112
uint32_t
dCBWDataTransferLength
;
113
114
//
115
// The device will ignore these bits if the dCBWDataTransferLength value
116
// is set to 0.
117
//
118
// The bits of this field are defined as follows:
119
// Bit 7 Direction
120
// 0 = Data-Out from host to the device,
121
// 1 = Data-In from the device to the host.
122
// Bit 6 Obsolete - The host shall set this bit to zero.
123
// Bits 5..0 Reserved - the host shall set these bits to zero.
124
//
125
uint8_t
bmCBWFlags
;
126
127
//
128
// The device Logical Unit Number (LUN) to which the command block is being
129
// sent. For devices that support multiple LUNs, the host shall place into
130
// this field the LUN to which this command block is addressed. Otherwise,
131
// the host shall set this field to zero.
132
//
133
uint8_t
bCBWLUN
;
134
135
//
136
// The valid length of the CBWCB in bytes. This defines the valid length
137
// of the command block. The only legal values are 1 through 16. All
138
// other values are reserved.
139
//
140
uint8_t
bCBWCBLength
;
141
142
//
143
// This array holds the command block to be executed by the device. The
144
// MSC device will interpret the first bCBWCBLength bytes in this field as
145
// a command block as defined by the command set identified by
146
// bInterfaceSubClass. If the command set supported by the device uses
147
// command blocks of fewer than 16 bytes in length, the significant bytes
148
// shall be transferred first, beginning with the byte at offset 15. The
149
// device will ignore the content of the CBWCB field past the byte at
150
// offset (15 + bCBWCBLength - 1).
151
//
152
uint8_t CBWCB[16];
153
}
154
PACKED
tMSCCBW;
155
156
//*****************************************************************************
157
//
158
// Flags for the bCSWStatus member of tMSCCSW
159
//
160
//*****************************************************************************
161
#define CSWSTATUS_CMD_SUCCESS 0
162
#define CSWSTATUS_CMD_FAILED 1
163
#define CSWSTATUS_PHASE_ERROR 2
164
165
//*****************************************************************************
166
//
167
// This structure encapsulates the Command Status Word (CSW) structure that is
168
// sent in response to all CBW commands.
169
//
170
//*****************************************************************************
171
typedef
struct
172
{
173
//
174
// Signature that identifies this data packet as a CSW. The signature
175
// field must contain the value 53425355h (little endian) to indicate CSW.
176
//
177
uint32_t
dCSWSignature
;
178
179
//
180
// The device will set this field to the value received in the dCBWTag of
181
// the associated CBW.
182
//
183
uint32_t
dCSWTag
;
184
185
//
186
// For OUT transactions the device will fill the dCSWDataResidue field with
187
// the difference between the amount of data expected as stated in the
188
// dCBWDataTransferLength, and the actual amount of data processed by the
189
// device. For IN transactions the device will fill the dCSWDataResidue
190
// field with the difference between the amount of data expected as stated
191
// in the dCBWDataTransferLength and the actual amount of relevant data
192
// sent by the device. The dCSWDataResidue will not exceed the value sent
193
// in the dCBWDataTransferLength.
194
//
195
uint32_t
dCSWDataResidue
;
196
197
//
198
// The bCSWStatus field indicates the success or failure of the command.
199
// The device shall set this byte to zero if the command completed
200
// successfully. A non-zero value shall indicate a failure during command
201
// execution.
202
//
203
uint8_t
bCSWStatus
;
204
}
205
PACKED
tMSCCSW;
206
207
//*****************************************************************************
208
//
209
// Return to default packing when using the IAR Embedded Workbench compiler.
210
//
211
//*****************************************************************************
212
#ifdef __ICCARM__
213
#pragma pack()
214
#endif
215
216
//*****************************************************************************
217
//
218
// SCSI Command return codes.
219
//
220
//*****************************************************************************
221
#define SCSI_CMD_STATUS_PASS 0x00
222
#define SCSI_CMD_STATUS_FAIL 0x01
223
224
//*****************************************************************************
225
//
226
// SCSI commands.
227
//
228
//*****************************************************************************
229
#define SCSI_TEST_UNIT_READY 0x00
230
#define SCSI_REQUEST_SENSE 0x03
231
#define SCSI_INQUIRY_CMD 0x12
232
#define SCSI_MODE_SENSE_6 0x1a
233
#define SCSI_START_STOP_UNIT 0x1b
234
#define SCSI_MEDIUM_REMOVAL 0x1e
235
#define SCSI_READ_CAPACITIES 0x23
236
#define SCSI_READ_CAPACITY 0x25
237
#define SCSI_READ_10 0x28
238
#define SCSI_WRITE_10 0x2a
239
240
//*****************************************************************************
241
//
242
// SCSI Test Unit Ready definitions.
243
//
244
//*****************************************************************************
245
246
//*****************************************************************************
247
//
248
// SCSI Inquiry command definitions.
249
//
250
//*****************************************************************************
251
252
//*****************************************************************************
253
//
254
// Size of the SCSI inquiry response data.
255
//
256
//*****************************************************************************
257
#define SCSI_INQUIRY_DATA_SZ 36
258
259
//*****************************************************************************
260
//
261
// Offset 0 of the Inquiry Data.
262
//
263
//*****************************************************************************
264
#define SCSI_INQ_PQ_M 0xe0 // Peripheral Qualifier Mask.
265
#define SCSI_INQ_PQ_CNCT 0x00 // Device connected.
266
#define SCSI_INQ_PQ_DISC 0x20 // Device disconnected.
267
#define SCSI_INQ_PDT_M 0x1f // Peripheral Device Type Mask.
268
#define SCSI_INQ_PDT_SBC 0x00 // Direct Access device.
269
270
//*****************************************************************************
271
//
272
// Offset 1 of the Inquiry Data.
273
//
274
//*****************************************************************************
275
#define SCSI_INQ_RMB 0x80 // Device is removable.
276
277
//*****************************************************************************
278
//
279
// Macro to check if removeable.
280
//
281
//*****************************************************************************
282
#define SCSIIsRemovable(pData) \
283
(((uint8_t *)pData)[1] & SCSI_INQ_RMB)
284
285
//*****************************************************************************
286
//
287
// SCSI Read Capacity definitions.
288
//
289
//*****************************************************************************
290
291
//*****************************************************************************
292
//
293
// Size of the SCSI Read Capacity response data.
294
//
295
//*****************************************************************************
296
#define SCSI_READ_CAPACITY_SZ 0x08
297
298
//*****************************************************************************
299
//
300
// SCSI Mode Sense definitions, these are passed in via the ui32Flags parameter
301
// of the SCSIModeSense() function call.
302
//
303
//*****************************************************************************
304
305
//*****************************************************************************
306
//
307
// Disable block descriptors.
308
//
309
//*****************************************************************************
310
#define SCSI_MS_DBD 0x00000800
311
312
//*****************************************************************************
313
//
314
// Page Code values, used in combination with Page Control values.
315
//
316
//*****************************************************************************
317
#define SCSI_MS_PC_VENDOR 0x00000000
318
#define SCSI_MS_PC_DISCO 0x00020000
319
#define SCSI_MS_PC_CONTROL 0x000a0000
320
#define SCSI_MS_PC_LUN 0x00180000
321
#define SCSI_MS_PC_PORT 0x00190000
322
#define SCSI_MS_PC_POWER 0x001a0000
323
#define SCSI_MS_PC_INFORM 0x001c0000
324
#define SCSI_MS_PC_ALL 0x003f0000
325
326
//*****************************************************************************
327
//
328
// Page Control values.
329
//
330
//*****************************************************************************
331
#define SCSI_MS_PC_CURRENT 0x00000000
332
#define SCSI_MS_PC_CHANGEABLE 0x00400000
333
#define SCSI_MS_PC_DEFAULT 0x00800000
334
#define SCSI_MS_PC_SAVED 0x00c00000
335
336
//*****************************************************************************
337
//
338
// Request Sense Definitions.
339
//
340
//*****************************************************************************
341
342
//*****************************************************************************
343
//
344
// Size of the data returned by the Request Sense command.
345
//
346
//*****************************************************************************
347
#define SCSI_REQUEST_SENSE_SZ 18
348
349
#define SCSI_RS_SKEY 2 // Sense Key offset.
350
#define SCSI_RS_SKEY_AD_SKEY 12 // Additional Sense Key offset.
351
352
//*****************************************************************************
353
//
354
// Offset 0 in the Request Sense response.
355
//
356
//*****************************************************************************
357
#define SCSI_RS_VALID 0x80 // Response is valid.
358
#define SCSI_RS_CUR_ERRORS 0x70 // Current errors returned.
359
#define SCSI_RS_DEFER_ERRORS 0x71 // Deferred errors returned.
360
361
//*****************************************************************************
362
//
363
// Offset 2 in the Request Sense response.
364
//
365
//*****************************************************************************
366
#define SCSI_RS_KEY_M 0x0f // Sense Key.
367
#define SCSI_RS_KEY_NO_SENSE 0x00 // No Sense Data.
368
#define SCSI_RS_KEY_RECOVRD_ERR 0x01 // Recovered Error.
369
#define SCSI_RS_KEY_NOT_READY 0x02 // Not Ready.
370
#define SCSI_RS_KEY_MEDIUM_ERR 0x03 // Error in the media.
371
#define SCSI_RS_KEY_HW_ERR 0x04 // Hardware Error, non recoverable.
372
#define SCSI_RS_KEY_ILGL_RQST 0x05 // Illegal request.
373
#define SCSI_RS_KEY_UNIT_ATTN 0x06 // Unit changed or reset.
374
#define SCSI_RS_KEY_DATA_PROT 0x07 // Write Protect error.
375
#define SCSI_RS_KEY_BLANK_CHK 0x08 // Write once error, block not clear.
376
#define SCSI_RS_KEY_ABORT 0x0b // Last command was aborted.
377
#define SCSI_RS_ILI 0x20 // Incorrect length indicator.
378
#define SCSI_RS_EOM 0x40 // End of medium condition.
379
#define SCSI_RS_FILEMARK 0x80 // Command has read a filemark/setmark.
380
#define SCSI_RS_MED_NOT_PRSNT 0x003a // Medium not present.
381
#define SCSI_RS_MED_NOTRDY2RDY 0x0028 // Not ready to ready transition.
382
#define SCSI_RS_PV_INVALID 0x0226 // Parameter Value Invalid.
383
384
//*****************************************************************************
385
//
386
// Additional information for SCSI_RS_KEY_NOT_READY
387
//
388
//*****************************************************************************
389
#define SCSI_RS_KEY_NOTPRSNT 0x3A // Media Not Present.
390
391
//*****************************************************************************
392
//
393
// Prevent/Allow Medium Removal Definitions.
394
//
395
//*****************************************************************************
396
397
//*****************************************************************************
398
//
399
// Offset 4 in the Prevent/Allow Medium Removal command.
400
//
401
//*****************************************************************************
402
#define SCSI_PE_MEDRMV_M 0x03
403
#define SCSI_PE_MEDRMV_ALLOW 0x00
404
#define SCSI_PE_MEDRMV_PREVENT 0x01
405
406
//*****************************************************************************
407
//
408
// Start/Stop Unit Definitions.
409
//
410
//*****************************************************************************
411
412
//*****************************************************************************
413
//
414
// Offset 1 in the Start/Stop Unit command.
415
//
416
//*****************************************************************************
417
#define SCSI_SS_UNIT_IMMED 0x01
418
#define SCSI_SS_UNIT_LUN_M 0xe0
419
420
//*****************************************************************************
421
//
422
// Offset 4 in the Start/Stop Unit command.
423
//
424
//*****************************************************************************
425
#define SCSI_SS_UNIT_START 0x01
426
#define SCSI_SS_UNIT_LOEJ 0x02
427
#define SCSI_SS_UNIT_PWR_M 0xf0
428
#define SCSI_SS_UNIT_PWR_ACTIVE 0x10
429
#define SCSI_SS_UNIT_PWR_IDLE 0x20
430
#define SCSI_SS_UNIT_PWR_STDBY 0x30
431
#define SCSI_SS_UNIT_PWR_DSLEEP 0x50
432
433
//*****************************************************************************
434
//
435
// Mark the end of the C bindings section for C++ compilers.
436
//
437
//*****************************************************************************
438
#ifdef __cplusplus
439
}
440
#endif
441
442
#endif // __USBMSC_H__
PACKED::bmCBWFlags
uint8_t bmCBWFlags
Definition:
usbmsc.h:125
PACKED::bCSWStatus
uint8_t bCSWStatus
Definition:
usbmsc.h:203
PACKED::dCSWDataResidue
uint32_t dCSWDataResidue
Definition:
usbmsc.h:195
PACKED::bCBWCBLength
uint8_t bCBWCBLength
Definition:
usbmsc.h:140
PACKED::dCBWTag
uint32_t dCBWTag
Definition:
usbmsc.h:102
PACKED::bCBWLUN
uint8_t bCBWLUN
Definition:
usbmsc.h:133
PACKED::dCBWSignature
uint32_t dCBWSignature
Definition:
usbmsc.h:94
PACKED::dCBWDataTransferLength
uint32_t dCBWDataTransferLength
Definition:
usbmsc.h:112
PACKED::dCSWSignature
uint32_t dCSWSignature
Definition:
usbmsc.h:177
PACKED::dCSWTag
uint32_t dCSWTag
Definition:
usbmsc.h:183
PACKED
USB_CDC_GET/SET_LINE_CODING request-specific data.
Definition:
usbaudio.h:288
Copyright 2017, Texas Instruments Incorporated