USBLibAPIGuide  1.00.00.01
usbdmsc.h
Go to the documentation of this file.
1 //*****************************************************************************
2 //
3 // usbdmsc.h - USB mass storage device class driver.
4 //
5 // Copyright (c) 2009-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 __USBDMSC_H__
24 #define __USBDMSC_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 //
41 //
42 //*****************************************************************************
43 
44 //*****************************************************************************
45 //
47 //
48 //*****************************************************************************
49 typedef struct
50 {
51  //
59  //
60  void *(*pfnOpen)(uint32_t ui32Drive);
61 
62  //*************************************************************************
63  //
70  //
71  //*************************************************************************
72  void (*pfnClose)(void *pvDrive);
73 
74  //*************************************************************************
75  //
85  //
86  //*************************************************************************
87  uint32_t (*pfnBlockRead)(void *pvDrive, uint8_t *pui8Data,
88  uint32_t ui32Sector, uint32_t ui32NumBlocks);
89 
90  //*************************************************************************
91  //
102  //
103  //*************************************************************************
104  uint32_t (*pfnBlockWrite)(void *pvDrive, uint8_t *pui8Data,
105  uint32_t ui32Sector, uint32_t ui32NumBlocks);
106 
107  //*************************************************************************
108  //
112  //
113  //*************************************************************************
114  uint32_t (*pfnNumBlocks)(void *pvDrive);
115 
116  //*************************************************************************
117  //
121  //
122  //*************************************************************************
123  uint32_t (*pfnBlockSize)(void *pvDrive);
124 
125 }
126 tMSCDMedia;
127 
128 //*****************************************************************************
129 //
130 // These defines control the default sizes of USB transfers for data and
131 // commands.
132 //
133 //*****************************************************************************
134 #define DEVICE_BLOCK_SIZE 512
135 
136 //*****************************************************************************
137 //
138 // USBDMSCMediaChange() tUSBDMSCMediaStatus values.
139 //
140 //*****************************************************************************
141 typedef enum
142 {
147 }
149 
150 //*****************************************************************************
151 //
152 // PRIVATE
153 //
154 // This structure defines the private instance data and state variables for the
155 // mass storage class. The memory for this structure is in the the
156 // sPrivateData field in the tUSBDMSCDevice structure passed on
157 // USBDMSCInit() and should not be modified by any code outside of the mass
158 // storage device code.
159 //
160 //*****************************************************************************
161 typedef struct
162 {
163  //
164  // Base address for the USB controller.
165  //
166  uint32_t ui32USBBase;
167 
168  //
169  // The device info to interact with the lower level DCD code.
170  //
172 
173  //
174  // These three values are used to return the current sense data for an
175  // instance of the mass storage class.
176  //
177  uint8_t ui8ErrorCode;
178  uint8_t ui8SenseKey;
180 
181  //
182  // The pointer to the instance returned from the Open call to the media.
183  //
184  void *pvMedia;
185 
186  //
187  // The connection status of the device.
188  //
189  volatile bool bConnected;
190 
191  //
192  // Holds the flag settings for this instance.
193  //
194  uint32_t ui32Flags;
195 
196  //
197  // Holds the current media status.
198  //
199  tUSBDMSCMediaStatus iMediaStatus;
200 
201  //
202  // MSC block buffer.
203  //
204  uint32_t pui32Buffer[0x1000>>2];
205 
206  //
207  // Current number of bytes to transfer.
208  //
210 
211  //
212  // The LBA for the current transfer.
213  //
214  uint32_t ui32CurrentLBA;
215 
216  //
217  // The IN endpoint number, this is modified in composite devices.
218  //
219  uint8_t ui8INEndpoint;
220 
221  //
222  // The IN DMA channel.
223  //
224  uint8_t ui8INDMA;
225 
226  //
227  // The OUT endpoint number, this is modified in composite devices.
228  //
229  uint8_t ui8OUTEndpoint;
230 
231  //
232  // The OUT DMA channel.
233  //
234  uint8_t ui8OUTDMA;
235 
236  //
237  // The bulk class interface number, this is modified in composite devices.
238  //
239  uint8_t ui8Interface;
240 
241  //
242  // Active SCSI state.
243  //
244  uint8_t ui8SCSIState;
245 
246  //
247  // A copy of the DMA instance data used with calls to USBLibDMA functions.
248  //
250 }
252 
253 //*****************************************************************************
254 //
255 // This is the size of the g_pui8MSCInterface array in bytes.
256 //
257 //*****************************************************************************
258 #define MSCINTERFACE_SIZE (23)
259 
260 //*****************************************************************************
261 //
266 //
267 //
268 //*****************************************************************************
269 #define COMPOSITE_DMSC_SIZE (MSCINTERFACE_SIZE)
270 
271 //*****************************************************************************
272 //
275 //
276 //*****************************************************************************
277 typedef struct
278 {
279  //
281  //
282  const uint16_t ui16VID;
283 
284  //
286  //
287  const uint16_t ui16PID;
288 
289  //
291  //
292  const uint8_t pui8Vendor[8];
293 
294  //
296  //
297  const uint8_t pui8Product[16];
298 
299  //
301  //
302  const uint8_t pui8Version[4];
303 
304  //
306  //
307  const uint16_t ui16MaxPowermA;
308 
309  //
314  //
315  const uint8_t ui8PwrAttributes;
316 
317  //
329  //
330  const uint8_t * const *ppui8StringDescriptors;
331 
332  //
335  //
336  const uint32_t ui32NumStringDescriptors;
337 
338  //
342  //
344 
345  //
348  //
350 
351  //
355  //
357 }
359 
360 //*****************************************************************************
361 //
362 // MSC-specific device class driver events
363 //
364 //*****************************************************************************
365 
366 //*****************************************************************************
367 //
370 //
371 //*****************************************************************************
372 #define USBD_MSC_EVENT_IDLE (USBD_MSC_EVENT_BASE + 0)
373 
374 //*****************************************************************************
375 //
377 //
378 //*****************************************************************************
379 #define USBD_MSC_EVENT_READING (USBD_MSC_EVENT_BASE + 1)
380 
381 //*****************************************************************************
382 //
384 //
385 //*****************************************************************************
386 #define USBD_MSC_EVENT_WRITING (USBD_MSC_EVENT_BASE + 2)
387 
388 //*****************************************************************************
389 //
390 // API Function Prototypes
391 //
392 //*****************************************************************************
393 extern void *USBDMSCInit(uint32_t ui32Index,
394  tUSBDMSCDevice *psMSCDevice);
395 extern void *USBDMSCCompositeInit(uint32_t ui32Index,
396  tUSBDMSCDevice *psMSCDevice,
397  tCompositeEntry *psCompEntry);
398 extern void USBDMSCTerm(void *pvInstance);
399 extern void USBDMSCMediaChange(void *pvInstance,
400  tUSBDMSCMediaStatus eMediaStatus);
401 
402 //*****************************************************************************
403 //
404 // Close the Doxygen group.
406 //
407 //*****************************************************************************
408 
409 //*****************************************************************************
410 //
411 // Mark the end of the C bindings section for C++ compilers.
412 //
413 //*****************************************************************************
414 #ifdef __cplusplus
415 }
416 #endif
417 
418 #endif
Definition: usbdmsc.h:161
tUSBDMSCMediaStatus iMediaStatus
Definition: usbdmsc.h:199
uint32_t ui32CurrentLBA
Definition: usbdmsc.h:214
uint32_t ui32Flags
Definition: usbdmsc.h:194
const uint16_t ui16VID
The vendor ID that this device is to present in the device descriptor.
Definition: usbdmsc.h:282
Definition: usbdmsc.h:143
Definition: usbdevice.h:135
const uint16_t ui16MaxPowermA
The maximum power consumption of the device, expressed in milliamps.
Definition: usbdmsc.h:307
tMSCInstance sPrivateData
Definition: usbdmsc.h:356
uint8_t ui8OUTDMA
Definition: usbdmsc.h:234
Definition: usbdmsc.h:145
void * pvMedia
Definition: usbdmsc.h:184
void * USBDMSCCompositeInit(uint32_t ui32Index, tUSBDMSCDevice *psMSCDevice, tCompositeEntry *psCompEntry)
Definition: usbdmsc.c:1142
const uint16_t ui16PID
The product ID that this device is to present in the device descriptor.
Definition: usbdmsc.h:287
Media Access functions.
Definition: usbdmsc.h:49
const uint32_t ui32NumStringDescriptors
Definition: usbdmsc.h:336
volatile bool bConnected
Definition: usbdmsc.h:189
const tMSCDMedia sMediaFunctions
Definition: usbdmsc.h:343
uint8_t ui8OUTEndpoint
Definition: usbdmsc.h:229
Definition: usbdmsc.h:277
uint32_t ui32BytesToTransfer
Definition: usbdmsc.h:209
Definition: usbdmsc.h:146
Definition: usbdmsc.h:144
Definition: usbdevice.h:66
uint32_t ui32USBBase
Definition: usbdmsc.h:166
uint32_t(* tUSBCallback)(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgParam, void *pvMsgData)
Definition: usblib.h:1220
uint8_t ui8SCSIState
Definition: usbdmsc.h:244
const tUSBCallback pfnEventCallback
Definition: usbdmsc.h:349
uint8_t ui8Interface
Definition: usbdmsc.h:239
uint16_t ui16AddSenseCode
Definition: usbdmsc.h:179
void USBDMSCMediaChange(void *pvMSCDevice, tUSBDMSCMediaStatus iMediaStatus)
Definition: usbdmsc.c:423
uint8_t ui8INDMA
Definition: usbdmsc.h:224
Definition: usblibpriv.h:177
void USBDMSCTerm(void *pvMSCDevice)
Definition: usbdmsc.c:1262
const uint8_t ui8PwrAttributes
Definition: usbdmsc.h:315
tUSBDMAInstance * psDMAInstance
Definition: usbdmsc.h:249
uint8_t ui8INEndpoint
Definition: usbdmsc.h:219
const uint8_t *const * ppui8StringDescriptors
Definition: usbdmsc.h:330
void * USBDMSCInit(uint32_t ui32Index, tUSBDMSCDevice *psMSCDevice)
Definition: usbdmsc.c:1069
uint8_t ui8ErrorCode
Definition: usbdmsc.h:177
uint8_t ui8SenseKey
Definition: usbdmsc.h:178
tDeviceInfo sDevInfo
Definition: usbdmsc.h:171
tUSBDMSCMediaStatus
Definition: usbdmsc.h:141
© Copyright 1995-2020, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale