usbdmsc.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. //*****************************************************************************
  2. //
  3. // usbdmsc.h - USB mass storage device class driver.
  4. //
  5. // Copyright (c) 2009-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 __USBDMSC_H__
  25. #define __USBDMSC_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. //! \addtogroup msc_device_class_api
  39. //! @{
  40. //
  41. //*****************************************************************************
  42. //*****************************************************************************
  43. //
  44. // USBDMSCMediaChange() ulStatus values.
  45. //
  46. //*****************************************************************************
  47. typedef enum
  48. {
  49. USBDMSC_MEDIA_PRESENT,
  50. USBDMSC_MEDIA_NOTPRESENT,
  51. USBDMSC_MEDIA_UNKNOWN
  52. }
  53. tUSBDMSCMediaStatus;
  54. //*****************************************************************************
  55. //
  56. //! Media Access functions.
  57. //
  58. //*****************************************************************************
  59. typedef struct
  60. {
  61. //
  62. //! This function is used to initialize and open the physical drive number
  63. //! associated with the parameter ulDrive. The function will return zero if
  64. //! the drive could not be opened for some reason. In the case of removable
  65. //! device like an SD card this function should return zero if the SD card
  66. //! is not present.
  67. //! The function returns a pointer to data that should be passed to other
  68. //! APIs or it will return 0 if no drive was found.
  69. //
  70. void *(* Open)(unsigned int ulDrive);
  71. //*****************************************************************************
  72. //
  73. // This function close the drive number in use by the mass storage class device.
  74. //
  75. // /param pvDrive is the pointer that was returned from a call to
  76. // USBDMSCStorageOpen().
  77. //
  78. // This function is used to close the physical drive number associated with the
  79. // parameter /e pvDrive. This function will return 0 if the drive was closed
  80. // successfully and any other value will indicate a failure.
  81. //
  82. // /return Returns 0 if the drive was successfully closed or non-zero for a
  83. // failure.
  84. //
  85. //*****************************************************************************
  86. void (* Close)(void * pvDrive);
  87. //*****************************************************************************
  88. //
  89. // This function will read a block from a device opened by the
  90. // USBDMSCStorageOpen() call.
  91. //
  92. // /param pvDrive is the pointer that was returned from a call to
  93. // USBDMSCStorageOpen().
  94. // /param pucData is the buffer that data will be written into.
  95. // /param ulSector is the block address to read.
  96. // /param ulNumBlocks is the number of blocks to read.
  97. //
  98. // This function is use to read blocks from a physical device and return them
  99. // in the /e pucData buffer. The data area pointed to by /e pucData should be
  100. // at least /e ulNumBlocks * Block Size bytes to prevent overwriting data.
  101. //
  102. // /return Returns the number of bytes that were read from the device.
  103. //
  104. //*****************************************************************************
  105. unsigned int (* BlockRead)(void * pvDrive, unsigned char *pucData,
  106. unsigned int ulSector,
  107. unsigned int ulNumBlocks);
  108. //*****************************************************************************
  109. //
  110. // This function will write a block to a device opened by the
  111. // USBDMSCStorageOpen() call.
  112. //
  113. // /param pvDrive is the pointer that was returned from a call to
  114. // USBDMSCStorageOpen().
  115. // /param pucData is the buffer that data will be used for writing.
  116. // /param ulNumBlocks is the number of blocks to write.
  117. //
  118. // This function is use to write blocks to a physical device from the buffer
  119. // pointed to by the /e pucData buffer. If the number of blocks is greater than
  120. // one then the block address will increment and write to the next block until
  121. // /e ulNumBlocks * Block Size bytes have been written.
  122. //
  123. // /return Returns the number of bytes that were written to the device.
  124. //
  125. //*****************************************************************************
  126. unsigned int (* BlockWrite)(void * pvDrive, unsigned char *pucData,
  127. unsigned int ulSector,
  128. unsigned int ulNumBlocks);
  129. //*****************************************************************************
  130. //
  131. // This function will return the number of blocks present on a device.
  132. //
  133. // /param pvDrive is the pointer that was returned from a call to
  134. // USBDMSCStorageOpen().
  135. //
  136. // This function is used to return the total number of blocks on a physical
  137. // device based on the /e pvDrive parameter.
  138. //
  139. // /return Returns the number of blocks that are present in a device.
  140. //
  141. //*****************************************************************************
  142. unsigned int (* NumBlocks)(void * pvDrive);
  143. }
  144. tMSCDMedia;
  145. //*****************************************************************************
  146. //
  147. // These defines control the sizes of USB transfers for data and commands.
  148. //
  149. //*****************************************************************************
  150. #define DEVICE_BLOCK_SIZE 512
  151. //*****************************************************************************
  152. //
  153. // PRIVATE
  154. //
  155. // This structure defines the private instance data and state variables for the
  156. // mass storage class. The memory for this structure is pointed to by
  157. // the psPrivateData field in the tUSBDMSCDevice structure passed on
  158. // USBDMSCInit() and should not be modified by any code outside of the mass
  159. // storage device code.
  160. //
  161. //*****************************************************************************
  162. typedef struct
  163. {
  164. unsigned int ulUSBBase;
  165. tDeviceInfo *psDevInfo;
  166. tConfigDescriptor *psConfDescriptor;
  167. //
  168. // These three values are used to return the current sense data for an
  169. // instance of the mass storage class.
  170. //
  171. unsigned char ucErrorCode;
  172. unsigned char ucSenseKey;
  173. unsigned short usAddSenseCode;
  174. //
  175. // The pointer to the instance returned from the Open call to the media.
  176. //
  177. void *pvMedia;
  178. volatile tBoolean bConnected;
  179. //
  180. // Holds the flag settings for this instance.
  181. //
  182. unsigned int ulFlags;
  183. tUSBDMSCMediaStatus eMediaStatus;
  184. unsigned int pulBuffer[DEVICE_BLOCK_SIZE];
  185. unsigned int ulBytesToTransfer;
  186. unsigned int ulCurrentLBA;
  187. unsigned char ucINEndpoint;
  188. unsigned char ucINDMA;
  189. unsigned char ucOUTEndpoint;
  190. unsigned char ucOUTDMA;
  191. unsigned char ucInterface;
  192. unsigned char ucSCSIState;
  193. }
  194. tMSCInstance;
  195. //*****************************************************************************
  196. //
  197. //
  198. //*****************************************************************************
  199. #ifdef DEPRECATED
  200. //*****************************************************************************
  201. //
  202. // This is the size in bytes of the private data for the mass storage class.
  203. //
  204. // This value is deprecated and should not be used, any new code should just
  205. // pass in a tMSCInstance structure in the psPrivateData field.
  206. //
  207. //*****************************************************************************
  208. #define USB_MSC_WORKSPACE_SIZE sizeof(tMSCInstance);
  209. #endif
  210. //*****************************************************************************
  211. //
  212. //! The size of the memory that should be allocated to create a configuration
  213. //! descriptor for a single instance of the USB Audio Device.
  214. //! This does not include the configuration descriptor which is automatically
  215. //! ignored by the composite device class.
  216. //
  217. // For reference this is sizeof(g_pAudioControlInterface) +
  218. // sizeof(g_pAudioStreamInterface
  219. //
  220. //*****************************************************************************
  221. #define COMPOSITE_DMSC_SIZE (23)
  222. //*****************************************************************************
  223. //
  224. //! The structure used by the application to define operating parameters for
  225. //! the mass storage device.
  226. //
  227. //*****************************************************************************
  228. typedef struct
  229. {
  230. //
  231. //! The vendor ID that this device is to present in the device descriptor.
  232. //
  233. unsigned short usVID;
  234. //
  235. //! The product ID that this device is to present in the device descriptor.
  236. //
  237. unsigned short usPID;
  238. //
  239. //! 8 byte vendor string.
  240. //
  241. unsigned char pucVendor[8];
  242. //
  243. //! 16 byte vendor string.
  244. //
  245. unsigned char pucProduct[16];
  246. //
  247. //! 4 byte vendor string.
  248. //
  249. unsigned char pucVersion[4];
  250. //
  251. //! The maximum power consumption of the device, expressed in milliamps.
  252. //
  253. unsigned short usMaxPowermA;
  254. //
  255. //! Indicates whether the device is self or bus-powered and whether or not
  256. //! it supports remote wakeup. Valid values are USB_CONF_ATTR_SELF_PWR or
  257. //! USB_CONF_ATTR_BUS_PWR, optionally ORed with USB_CONF_ATTR_RWAKE.
  258. //
  259. unsigned char ucPwrAttributes;
  260. //
  261. //! A pointer to the string descriptor array for this device. This array
  262. //! must contain the following string descriptor pointers in this order.
  263. //! Language descriptor, Manufacturer name string (language 1), Product
  264. //! name string (language 1), Serial number string (language 1), MSC
  265. //! Interface description string (language 1), Configuration description
  266. //! string (language 1).
  267. //!
  268. //! If supporting more than 1 language, the descriptor block (except for
  269. //! string descriptor 0) must be repeated for each language defined in the
  270. //! language descriptor.
  271. //!
  272. //
  273. const unsigned char * const *ppStringDescriptors;
  274. //
  275. //! The number of descriptors provided in the ppStringDescriptors
  276. //! array. This must be 1 + ((5 + (num HID strings)) * (num languages)).
  277. //
  278. unsigned int ulNumStringDescriptors;
  279. //
  280. //! This structure holds the access functions for the media used by this
  281. //! instance of the mass storage class device. All of the functions in this
  282. //! structure are required to be filled out with valid functions.
  283. //
  284. tMSCDMedia sMediaFunctions;
  285. //
  286. //! This is the callback function for various events that occur during
  287. //! mass storage class operation.
  288. //
  289. tUSBCallback pfnEventCallback;
  290. //
  291. //! A pointer to the private instance data for this device. This memory
  292. //! must remain accessible for as long as the MSC device is in use and must
  293. //! not be modified by any code outside the MSC class driver.
  294. //
  295. tMSCInstance *psPrivateData;
  296. }
  297. tUSBDMSCDevice;
  298. //*****************************************************************************
  299. //
  300. // MSC-specific device class driver events
  301. //
  302. //*****************************************************************************
  303. //*****************************************************************************
  304. //
  305. //! This event indicates that the host has completed other operations and is
  306. //! no longer accessing the device.
  307. //
  308. //*****************************************************************************
  309. #define USBD_MSC_EVENT_IDLE (USBD_MSC_EVENT_BASE + 0)
  310. //*****************************************************************************
  311. //
  312. //! This event indicates that the host is reading the storage media.
  313. //
  314. //*****************************************************************************
  315. #define USBD_MSC_EVENT_READING (USBD_MSC_EVENT_BASE + 1)
  316. //*****************************************************************************
  317. //
  318. //! This event indicates that the host is writing to the storage media.
  319. //
  320. //*****************************************************************************
  321. #define USBD_MSC_EVENT_WRITING (USBD_MSC_EVENT_BASE + 2)
  322. extern tDeviceInfo g_sMSCDeviceInfo;
  323. //*****************************************************************************
  324. //
  325. // API Function Prototypes
  326. //
  327. //*****************************************************************************
  328. extern void *USBDMSCInit(unsigned int ulIndex,
  329. const tUSBDMSCDevice *psMSCDevice);
  330. extern void *USBDMSCCompositeInit(unsigned int ulIndex,
  331. const tUSBDMSCDevice *psMSCDevice);
  332. extern void USBDMSCTerm(void *pvInstance);
  333. extern void USBDMSCMediaChange(void *pvInstance,
  334. tUSBDMSCMediaStatus eMediaStatus);
  335. //*****************************************************************************
  336. //
  337. // Close the Doxygen group.
  338. //! @}
  339. //
  340. //*****************************************************************************
  341. //*****************************************************************************
  342. //
  343. // Mark the end of the C bindings section for C++ compilers.
  344. //
  345. //*****************************************************************************
  346. #ifdef __cplusplus
  347. }
  348. #endif
  349. #endif