usbmsc.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. //*****************************************************************************
  2. //
  3. // usbmsc.h - Generic types and defines use by the mass storage class.
  4. //
  5. // Copyright (c) 2008-2010 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. // This is part of revision 6288 of the Stellaris USB Library.
  22. //
  23. //*****************************************************************************
  24. #ifndef __USBMSC_H__
  25. #define __USBMSC_H__
  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. // The request for the maximum number of logical units on a mass storage
  39. // device.
  40. //
  41. //*****************************************************************************
  42. #define USBREQ_GET_MAX_LUN 0xfe
  43. //*****************************************************************************
  44. //
  45. // The signatures defined by USB MSC class specification.
  46. //
  47. //*****************************************************************************
  48. #define CBW_SIGNATURE 0x43425355
  49. #define CSW_SIGNATURE 0x53425355
  50. //*****************************************************************************
  51. //
  52. // Flag for the bmCBWFlags member of tMSCCBW
  53. //
  54. //*****************************************************************************
  55. #define CBWFLAGS_DIR_M 0x80
  56. #define CBWFLAGS_DIR_IN 0x80
  57. #define CBWFLAGS_DIR_OUT 0x00
  58. //*****************************************************************************
  59. //
  60. // All structures defined in this section of the header require byte packing of
  61. // fields. This is usually accomplished using the USBLIB_PACKED macro but, for IAR
  62. // Embedded Workbench, this requries a pragma.
  63. //
  64. //*****************************************************************************
  65. #if defined(ewarm) || defined(__IAR_SYSTEMS_ICC__)
  66. #pragma pack(1)
  67. #endif
  68. //*****************************************************************************
  69. //
  70. // The following packed structure is used to access the Command Block Wrapper
  71. // (CBW) data structure that is used when communicating with USB Mass Storage
  72. // Class devices.
  73. //
  74. //*****************************************************************************
  75. typedef struct
  76. {
  77. //
  78. // Signature that helps identify this data packet as a CBW. The signature
  79. // field shall contain the value 0x43425355 (little endian), indicating a
  80. // CBW.
  81. //
  82. unsigned int dCBWSignature;
  83. //
  84. // The Command Block Tag sent by the host controller. The device shall
  85. // echo the contents of this field back to the host in the dCSWTag field
  86. // of the associated CSW. The dCSWTag positively associates a CSW with the
  87. // corresponding CBW.
  88. //
  89. unsigned int dCBWTag;
  90. //
  91. // The number of bytes of data that the host expects to transfer on the
  92. // Bulk-In or Bulk-Out endpoint (as indicated by the Direction bit) during
  93. // the execution of this command. If this field is zero, the device and
  94. // the host will not transfer data between the CBW and the associated CSW,
  95. // and the device will ignore the value of the Direction bit in
  96. // bmCBWFlags.
  97. //
  98. unsigned int dCBWDataTransferLength;
  99. //
  100. // The device will ignore these bits if the dCBWDataTransferLength value
  101. // is set to 0.
  102. //
  103. // The bits of this field are defined as follows:
  104. // Bit 7 Direction
  105. // 0 = Data-Out from host to the device,
  106. // 1 = Data-In from the device to the host.
  107. // Bit 6 Obsolete - The host shall set this bit to zero.
  108. // Bits 5..0 Reserved - the host shall set these bits to zero.
  109. //
  110. unsigned char bmCBWFlags;
  111. //
  112. // The device Logical Unit Number (LUN) to which the command block is being
  113. // sent. For devices that support multiple LUNs, the host shall place into
  114. // this field the LUN to which this command block is addressed. Otherwise,
  115. // the host shall set this field to zero.
  116. //
  117. unsigned char bCBWLUN;
  118. //
  119. // The valid length of the CBWCB in bytes. This defines the valid length
  120. // of the command block. The only legal values are 1 through 16. All
  121. // other values are reserved.
  122. //
  123. unsigned char bCBWCBLength;
  124. //
  125. // This array holds the command block to be executed by the device. The
  126. // MSC device will interpret the first bCBWCBLength bytes in this field as
  127. // a command block as defined by the command set identified by
  128. // bInterfaceSubClass. If the command set supported by the device uses
  129. // command blocks of fewer than 16 bytes in length, the significant bytes
  130. // shall be transferred first, beginning with the byte at offset 15. The
  131. // device will ignore the content of the CBWCB field past the byte at
  132. // offset (15 + bCBWCBLength - 1).
  133. //
  134. unsigned char CBWCB[16];
  135. }
  136. USBLIB_PACKED tMSCCBW;
  137. //*****************************************************************************
  138. //
  139. // Flags for the bCSWStatus member of tMSCCSW
  140. //
  141. //*****************************************************************************
  142. #define CSWSTATUS_CMD_SUCCESS 0
  143. #define CSWSTATUS_CMD_FAILED 1
  144. #define CSWSTATUS_PHASE_ERROR 2
  145. //*****************************************************************************
  146. //
  147. // This structure encapsulates the Command Status Word (CSW) structure that is
  148. // sent in response to all CBW commands.
  149. //
  150. //*****************************************************************************
  151. typedef struct
  152. {
  153. //
  154. // Signature that identifies this data packet as a CSW. The signature
  155. // field must contain the value 53425355h (little endian) to indicate CSW.
  156. //
  157. unsigned int dCSWSignature;
  158. //
  159. // The device will set this field to the value received in the dCBWTag of
  160. // the associated CBW.
  161. //
  162. unsigned int dCSWTag;
  163. //
  164. // For OUT transactions the device will fill the dCSWDataResidue field with
  165. // the difference between the amount of data expected as stated in the
  166. // dCBWDataTransferLength, and the actual amount of data processed by the
  167. // device. For IN transactions the device will fill the dCSWDataResidue
  168. // field with the difference between the amount of data expected as stated
  169. // in the dCBWDataTransferLength and the actual amount of relevant data
  170. // sent by the device. The dCSWDataResidue will not exceed the value sent
  171. // in the dCBWDataTransferLength.
  172. //
  173. unsigned int dCSWDataResidue;
  174. //
  175. // The bCSWStatus field indicates the success or failure of the command.
  176. // The device shall set this byte to zero if the command completed
  177. // successfully. A non-zero value shall indicate a failure during command
  178. // execution.
  179. //
  180. unsigned char bCSWStatus;
  181. }
  182. USBLIB_PACKED tMSCCSW;
  183. //*****************************************************************************
  184. //
  185. // Return to default packing when using the IAR Embedded Workbench compiler.
  186. //
  187. //*****************************************************************************
  188. #if defined(ewarm) || defined(__IAR_SYSTEMS_ICC__)
  189. #pragma pack()
  190. #endif
  191. //*****************************************************************************
  192. //
  193. // SCSI Command return codes.
  194. //
  195. //*****************************************************************************
  196. #define SCSI_CMD_STATUS_PASS 0x00
  197. #define SCSI_CMD_STATUS_FAIL 0x01
  198. //*****************************************************************************
  199. //
  200. // SCSI commands.
  201. //
  202. //*****************************************************************************
  203. #define SCSI_TEST_UNIT_READY 0x00
  204. #define SCSI_REQUEST_SENSE 0x03
  205. #define SCSI_INQUIRY_CMD 0x12
  206. #define SCSI_MODE_SENSE_6 0x1a
  207. #define SCSI_READ_CAPACITIES 0x23
  208. #define SCSI_READ_CAPACITY 0x25
  209. #define SCSI_READ_10 0x28
  210. #define SCSI_WRITE_10 0x2a
  211. #define SCSI_VERIFY_10 0x2f
  212. //*****************************************************************************
  213. //
  214. // SCSI Test Unit Ready definitions.
  215. //
  216. //*****************************************************************************
  217. //*****************************************************************************
  218. //
  219. // SCSI Inquiry command definitions.
  220. //
  221. //*****************************************************************************
  222. //*****************************************************************************
  223. //
  224. // Size of the SCSI inquiry response data.
  225. //
  226. //*****************************************************************************
  227. #define SCSI_INQUIRY_DATA_SZ 36
  228. //*****************************************************************************
  229. //
  230. // Offset 0 of the Inquiry Data.
  231. //
  232. //*****************************************************************************
  233. #define SCSI_INQ_PQ_M 0xe0 // Peripheral Qualifier Mask.
  234. #define SCSI_INQ_PQ_CNCT 0x00 // Device connected.
  235. #define SCSI_INQ_PQ_DISC 0x20 // Device disconnected.
  236. #define SCSI_INQ_PDT_M 0x1f // Peripheral Device Type Mask.
  237. #define SCSI_INQ_PDT_SBC 0x00 // Direct Access device.
  238. //*****************************************************************************
  239. //
  240. // Offset 1 of the Inquiry Data.
  241. //
  242. //*****************************************************************************
  243. #define SCSI_INQ_RMB 0x80 // Device is removable.
  244. //*****************************************************************************
  245. //
  246. // Macro to check if removeable.
  247. //
  248. //*****************************************************************************
  249. #define SCSIIsRemovable(pData) \
  250. (((unsigned char *)pData)[1] & SCSI_INQ_RMB)
  251. //*****************************************************************************
  252. //
  253. // SCSI Read Capacity definitions.
  254. //
  255. //*****************************************************************************
  256. //*****************************************************************************
  257. //
  258. // Size of the SCSI Read Capacity response data.
  259. //
  260. //*****************************************************************************
  261. #define SCSI_READ_CAPACITY_SZ 0x08
  262. //*****************************************************************************
  263. //
  264. // SCSI Mode Sense definitions, these are passed in via the ulFlags parameter
  265. // of the SCSIModeSense() function call.
  266. //
  267. //*****************************************************************************
  268. //*****************************************************************************
  269. //
  270. // Disable block descriptors.
  271. //
  272. //*****************************************************************************
  273. #define SCSI_MS_DBD 0x00000800
  274. //*****************************************************************************
  275. //
  276. // Page Code values, used in combination with Page Control values.
  277. //
  278. //*****************************************************************************
  279. #define SCSI_MS_PC_VENDOR 0x00000000
  280. #define SCSI_MS_PC_DISCO 0x00020000
  281. #define SCSI_MS_PC_CONTROL 0x000a0000
  282. #define SCSI_MS_PC_LUN 0x00180000
  283. #define SCSI_MS_PC_PORT 0x00190000
  284. #define SCSI_MS_PC_POWER 0x001a0000
  285. #define SCSI_MS_PC_INFORM 0x001c0000
  286. #define SCSI_MS_PC_ALL 0x003f0000
  287. //*****************************************************************************
  288. //
  289. // Page Control values.
  290. //
  291. //*****************************************************************************
  292. #define SCSI_MS_PC_CURRENT 0x00000000
  293. #define SCSI_MS_PC_CHANGEABLE 0x00400000
  294. #define SCSI_MS_PC_DEFAULT 0x00800000
  295. #define SCSI_MS_PC_SAVED 0x00c00000
  296. //*****************************************************************************
  297. //
  298. // Request Sense Definitions.
  299. //
  300. //*****************************************************************************
  301. //*****************************************************************************
  302. //
  303. // Size of the data returned by the Request Sense command.
  304. //
  305. //*****************************************************************************
  306. #define SCSI_REQUEST_SENSE_SZ 18
  307. #define SCSI_RS_SKEY 2 // Sense Key offset.
  308. #define SCSI_RS_SKEY_AD_SKEY 12 // Additional Sense Key offset.
  309. //*****************************************************************************
  310. //
  311. // Offset 0 in the Request Sense response.
  312. //
  313. //*****************************************************************************
  314. #define SCSI_RS_VALID 0x80 // Response is valid.
  315. #define SCSI_RS_CUR_ERRORS 0x70 // Current errors returned.
  316. #define SCSI_RS_DEFER_ERRORS 0x71 // Deferred errors returned.
  317. //*****************************************************************************
  318. //
  319. // Offset 2 in the Request Sense response.
  320. //
  321. //*****************************************************************************
  322. #define SCSI_RS_KEY_M 0x0f // Sense Key.
  323. #define SCSI_RS_KEY_NO_SENSE 0x00 // No Sense Data.
  324. #define SCSI_RS_KEY_RECOVRD_ERR 0x01 // Recovered Error.
  325. #define SCSI_RS_KEY_NOT_READY 0x02 // Not Ready.
  326. #define SCSI_RS_KEY_MEDIUM_ERR 0x03 // Error in the media.
  327. #define SCSI_RS_KEY_HW_ERR 0x04 // Hardware Error, non recoverable.
  328. #define SCSI_RS_KEY_ILGL_RQST 0x05 // Illegal request.
  329. #define SCSI_RS_KEY_UNIT_ATTN 0x06 // Unit changed or reset.
  330. #define SCSI_RS_KEY_DATA_PROT 0x07 // Write Protect error.
  331. #define SCSI_RS_KEY_BLANK_CHK 0x07 // Write once error, block not clear.
  332. #define SCSI_RS_KEY_ABORT 0x0b // Last command was aborted.
  333. #define SCSI_RS_ILI 0x20 // Incorrect length indicator.
  334. #define SCSI_RS_EOM 0x40 // End of medium condition.
  335. #define SCSI_RS_FILEMARK 0x80 // Command has read a filemark/setmark.
  336. #define SCSI_RS_MED_NOT_PRSNT 0x003a // Medium not present.
  337. #define SCSI_RS_MED_NOTRDY2RDY 0x0028 // Not ready to ready transition.
  338. #define SCSI_RS_PV_INVALID 0x0226 // Parameter Value Invalid.
  339. //*****************************************************************************
  340. //
  341. // Additional information for SCSI_RS_KEY_NOT_READY
  342. //
  343. //*****************************************************************************
  344. #define SCSI_RS_KEY_NOTPRSNT 0x3A // Media Not Present.
  345. //*****************************************************************************
  346. //
  347. // Mark the end of the C bindings section for C++ compilers.
  348. //
  349. //*****************************************************************************
  350. #ifdef __cplusplus
  351. }
  352. #endif
  353. #endif // __USBMSC_H__