Примерно так:
Код
DSTATUS USB_disk_initialize(void)
{
int32_t rc;
uint32_t numBlks, blkSize;
uint8_t inquiryResult[INQUIRY_LENGTH];
// Host_Init(); /* Initialize the lpc17xx host controller */
// rc = Host_EnumDev(); /* Enumerate the device connected */
if (usbhost_ms) {
/* Initialize the mass storage and scsi interfaces */
rc = MS_Init( &blkSize, &numBlks, inquiryResult );
if (rc == OK) {
return FR_OK;
} else {
return (FR_DISK_ERR);
}
} else {
return (FR_DISK_ERR);
}
}
DSTATUS USB_disk_status(void)
{
return FR_OK;
}
DRESULT USB_disk_read(
BYTE *buff, /* Pointer to the data buffer to store read data */
DWORD sector, /* Start sector number (LBA) */
BYTE count /* Sector count (1..255) */
)
{
MS_BulkRecv(sector, count, buff);
return RES_OK;
}
DRESULT USB_disk_write(
BYTE *buff, /* Pointer to the data to be written */
DWORD sector, /* Start sector number (LBA) */
BYTE count /* Sector count (1..255) */
)
{
MS_BulkSend(sector, count, buff);
return RES_OK;
}
extern uint32_t MS_BlkSize;
extern uint32_t MS_NumBlks;
DRESULT USB_disk_ioctl (
BYTE ctrl, /* Control code */
void *buff /* Buffer to send/receive control data */
)
{
DRESULT res;
BYTE n, csd[16], *ptr = buff;
WORD csize;
res = RES_ERROR;
if (ctrl == CTRL_POWER)
{
res = RES_OK;
}
else {
switch (ctrl) {
case CTRL_SYNC : /* Make sure that no pending write process */
res = RES_OK;
break;
case GET_SECTOR_COUNT : /* Get number of sectors on the disk (DWORD) */
csize = MS_NumBlks;
*(DWORD*)buff = (DWORD)csize;
res = RES_OK;
break;
case GET_SECTOR_SIZE : /* Get R/W sector size (WORD) */
*(WORD*)buff = MS_BlkSize;
res = RES_OK;
break;
case GET_BLOCK_SIZE : /* Get erase block size in unit of sector (DWORD) */
*(DWORD*)buff = 1;
res = RES_OK;
break;
default:
res = RES_PARERR;
}
}
return res;
}