4 #include "usbh_msc_core.h"
5 /*--------------------------------------------------------------------------
7 Module Private Functions and Variables
9 ---------------------------------------------------------------------------*/
11 static volatile DSTATUS Stat = STA_NOINIT; /* Disk status */
13 extern USB_OTG_CORE_HANDLE USB_OTG_Core;
14 extern USBH_HOST USB_Host;
16 /*-----------------------------------------------------------------------*/
17 /* Initialize Disk Drive */
18 /*-----------------------------------------------------------------------*/
20 DSTATUS disk_initialize (
21 BYTE drv /* Physical drive number (0) */
25 if(HCD_IsDeviceConnected(&USB_OTG_Core))
37 /*-----------------------------------------------------------------------*/
39 /*-----------------------------------------------------------------------*/
42 BYTE drv /* Physical drive number (0) */
45 if (drv) return STA_NOINIT; /* Supports only single drive */
51 /*-----------------------------------------------------------------------*/
53 /*-----------------------------------------------------------------------*/
56 BYTE drv, /* Physical drive number (0) */
57 BYTE *buff, /* Pointer to the data buffer to store read data */
58 DWORD sector, /* Start sector number (LBA) */
59 BYTE count /* Sector count (1..255) */
62 BYTE status = USBH_MSC_OK;
64 if (drv || !count) return RES_PARERR;
65 if (Stat & STA_NOINIT) return RES_NOTRDY;
68 if(HCD_IsDeviceConnected(&USB_OTG_Core))
73 status = USBH_MSC_Read10(&USB_OTG_Core, buff,sector,512);
74 USBH_MSC_HandleBOTXfer(&USB_OTG_Core ,&USB_Host);
76 if(!HCD_IsDeviceConnected(&USB_OTG_Core))
81 while(status == USBH_MSC_BUSY );
84 if(status == USBH_MSC_OK)
92 /*-----------------------------------------------------------------------*/
94 /*-----------------------------------------------------------------------*/
98 BYTE drv, /* Physical drive number (0) */
99 const BYTE *buff, /* Pointer to the data to be written */
100 DWORD sector, /* Start sector number (LBA) */
101 BYTE count /* Sector count (1..255) */
104 BYTE status = USBH_MSC_OK;
105 if (drv || !count) return RES_PARERR;
106 if (Stat & STA_NOINIT) return RES_NOTRDY;
107 if (Stat & STA_PROTECT) return RES_WRPRT;
110 if(HCD_IsDeviceConnected(&USB_OTG_Core))
114 status = USBH_MSC_Write10(&USB_OTG_Core,(BYTE*)buff,sector,512);
115 USBH_MSC_HandleBOTXfer(&USB_OTG_Core, &USB_Host);
117 if(!HCD_IsDeviceConnected(&USB_OTG_Core))
123 while(status == USBH_MSC_BUSY );
127 if(status == USBH_MSC_OK)
131 #endif /* _READONLY == 0 */
135 /*-----------------------------------------------------------------------*/
136 /* Miscellaneous Functions */
137 /*-----------------------------------------------------------------------*/
141 BYTE drv, /* Physical drive number (0) */
142 BYTE ctrl, /* Control code */
143 void *buff /* Buffer to send/receive control data */
146 DRESULT res = RES_OK;
148 if (drv) return RES_PARERR;
152 if (Stat & STA_NOINIT) return RES_NOTRDY;
155 case CTRL_SYNC : /* Make sure that no pending write process */
160 case GET_SECTOR_COUNT : /* Get number of sectors on the disk (DWORD) */
162 *(DWORD*)buff = (DWORD) USBH_MSC_Param.MSCapacity;
166 case GET_SECTOR_SIZE : /* Get R/W sector size (WORD) */
171 case GET_BLOCK_SIZE : /* Get erase block size in unit of sector (DWORD) */
186 #endif /* _USE_IOCTL != 0 */