2014-08-13 05:48:16 +00:00
|
|
|
/*-----------------------------------------------------------------------*/
|
2017-06-24 06:35:31 +00:00
|
|
|
/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2016 */
|
2014-08-13 05:48:16 +00:00
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
/* If a working storage control module is available, it should be */
|
|
|
|
/* attached to the FatFs via a glue function rather than modifying it. */
|
|
|
|
/* This is an example of glue functions to attach various exsisting */
|
2017-06-24 06:35:31 +00:00
|
|
|
/* storage control modules to the FatFs module with a defined API. */
|
2014-08-13 05:48:16 +00:00
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#include "diskio.h" /* FatFs lower layer API */
|
|
|
|
|
2017-06-24 06:35:31 +00:00
|
|
|
/* Definitions of physical drive number for each drive */
|
|
|
|
#define DEV_RAM 0 /* Example: Map Ramdisk to physical drive 0 */
|
|
|
|
#define DEV_MMC 1 /* Example: Map MMC/SD card to physical drive 1 */
|
|
|
|
#define DEV_USB 2 /* Example: Map USB MSD to physical drive 2 */
|
2014-08-13 05:48:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------*/
|
2017-06-24 06:35:31 +00:00
|
|
|
/* Get Drive Status */
|
2014-08-13 05:48:16 +00:00
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
|
2017-06-24 06:35:31 +00:00
|
|
|
DSTATUS disk_status (
|
|
|
|
BYTE pdrv /* Physical drive nmuber to identify the drive */
|
2014-08-13 05:48:16 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
DSTATUS stat;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
switch (pdrv) {
|
2017-06-24 06:35:31 +00:00
|
|
|
case DEV_RAM :
|
|
|
|
result = RAM_disk_status();
|
2014-08-13 05:48:16 +00:00
|
|
|
|
|
|
|
// translate the reslut code here
|
|
|
|
|
|
|
|
return stat;
|
|
|
|
|
2017-06-24 06:35:31 +00:00
|
|
|
case DEV_MMC :
|
|
|
|
result = MMC_disk_status();
|
2014-08-13 05:48:16 +00:00
|
|
|
|
|
|
|
// translate the reslut code here
|
|
|
|
|
|
|
|
return stat;
|
|
|
|
|
2017-06-24 06:35:31 +00:00
|
|
|
case DEV_USB :
|
|
|
|
result = USB_disk_status();
|
2014-08-13 05:48:16 +00:00
|
|
|
|
|
|
|
// translate the reslut code here
|
|
|
|
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
return STA_NOINIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------*/
|
2017-06-24 06:35:31 +00:00
|
|
|
/* Inidialize a Drive */
|
2014-08-13 05:48:16 +00:00
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
|
2017-06-24 06:35:31 +00:00
|
|
|
DSTATUS disk_initialize (
|
|
|
|
BYTE pdrv /* Physical drive nmuber to identify the drive */
|
2014-08-13 05:48:16 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
DSTATUS stat;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
switch (pdrv) {
|
2017-06-24 06:35:31 +00:00
|
|
|
case DEV_RAM :
|
|
|
|
result = RAM_disk_initialize();
|
2014-08-13 05:48:16 +00:00
|
|
|
|
|
|
|
// translate the reslut code here
|
|
|
|
|
|
|
|
return stat;
|
|
|
|
|
2017-06-24 06:35:31 +00:00
|
|
|
case DEV_MMC :
|
|
|
|
result = MMC_disk_initialize();
|
2014-08-13 05:48:16 +00:00
|
|
|
|
|
|
|
// translate the reslut code here
|
|
|
|
|
|
|
|
return stat;
|
|
|
|
|
2017-06-24 06:35:31 +00:00
|
|
|
case DEV_USB :
|
|
|
|
result = USB_disk_initialize();
|
2014-08-13 05:48:16 +00:00
|
|
|
|
|
|
|
// translate the reslut code here
|
|
|
|
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
return STA_NOINIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
/* Read Sector(s) */
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
DRESULT disk_read (
|
2017-06-24 06:35:31 +00:00
|
|
|
BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
2014-08-13 05:48:16 +00:00
|
|
|
BYTE *buff, /* Data buffer to store read data */
|
2017-06-24 06:35:31 +00:00
|
|
|
DWORD sector, /* Start sector in LBA */
|
|
|
|
UINT count /* Number of sectors to read */
|
2014-08-13 05:48:16 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
DRESULT res;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
switch (pdrv) {
|
2017-06-24 06:35:31 +00:00
|
|
|
case DEV_RAM :
|
2014-08-13 05:48:16 +00:00
|
|
|
// translate the arguments here
|
|
|
|
|
2017-06-24 06:35:31 +00:00
|
|
|
result = RAM_disk_read(buff, sector, count);
|
2014-08-13 05:48:16 +00:00
|
|
|
|
|
|
|
// translate the reslut code here
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
2017-06-24 06:35:31 +00:00
|
|
|
case DEV_MMC :
|
2014-08-13 05:48:16 +00:00
|
|
|
// translate the arguments here
|
|
|
|
|
|
|
|
result = MMC_disk_read(buff, sector, count);
|
|
|
|
|
|
|
|
// translate the reslut code here
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
2017-06-24 06:35:31 +00:00
|
|
|
case DEV_USB :
|
2014-08-13 05:48:16 +00:00
|
|
|
// translate the arguments here
|
|
|
|
|
|
|
|
result = USB_disk_read(buff, sector, count);
|
|
|
|
|
|
|
|
// translate the reslut code here
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2017-06-24 06:35:31 +00:00
|
|
|
|
2014-08-13 05:48:16 +00:00
|
|
|
return RES_PARERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
/* Write Sector(s) */
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
DRESULT disk_write (
|
2017-06-24 06:35:31 +00:00
|
|
|
BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
2014-08-13 05:48:16 +00:00
|
|
|
const BYTE *buff, /* Data to be written */
|
2017-06-24 06:35:31 +00:00
|
|
|
DWORD sector, /* Start sector in LBA */
|
|
|
|
UINT count /* Number of sectors to write */
|
2014-08-13 05:48:16 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
DRESULT res;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
switch (pdrv) {
|
2017-06-24 06:35:31 +00:00
|
|
|
case DEV_RAM :
|
2014-08-13 05:48:16 +00:00
|
|
|
// translate the arguments here
|
|
|
|
|
2017-06-24 06:35:31 +00:00
|
|
|
result = RAM_disk_write(buff, sector, count);
|
2014-08-13 05:48:16 +00:00
|
|
|
|
|
|
|
// translate the reslut code here
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
2017-06-24 06:35:31 +00:00
|
|
|
case DEV_MMC :
|
2014-08-13 05:48:16 +00:00
|
|
|
// translate the arguments here
|
|
|
|
|
|
|
|
result = MMC_disk_write(buff, sector, count);
|
|
|
|
|
|
|
|
// translate the reslut code here
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
2017-06-24 06:35:31 +00:00
|
|
|
case DEV_USB :
|
2014-08-13 05:48:16 +00:00
|
|
|
// translate the arguments here
|
|
|
|
|
|
|
|
result = USB_disk_write(buff, sector, count);
|
|
|
|
|
|
|
|
// translate the reslut code here
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2017-06-24 06:35:31 +00:00
|
|
|
|
2014-08-13 05:48:16 +00:00
|
|
|
return RES_PARERR;
|
|
|
|
}
|
2017-06-24 06:35:31 +00:00
|
|
|
|
2014-08-13 05:48:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
/* Miscellaneous Functions */
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
DRESULT disk_ioctl (
|
|
|
|
BYTE pdrv, /* Physical drive nmuber (0..) */
|
|
|
|
BYTE cmd, /* Control code */
|
|
|
|
void *buff /* Buffer to send/receive control data */
|
|
|
|
)
|
|
|
|
{
|
|
|
|
DRESULT res;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
switch (pdrv) {
|
2017-06-24 06:35:31 +00:00
|
|
|
case DEV_RAM :
|
2014-08-13 05:48:16 +00:00
|
|
|
|
2017-06-24 06:35:31 +00:00
|
|
|
// Process of the command for the RAM drive
|
2014-08-13 05:48:16 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
|
2017-06-24 06:35:31 +00:00
|
|
|
case DEV_MMC :
|
2014-08-13 05:48:16 +00:00
|
|
|
|
2017-06-24 06:35:31 +00:00
|
|
|
// Process of the command for the MMC/SD card
|
2014-08-13 05:48:16 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
|
2017-06-24 06:35:31 +00:00
|
|
|
case DEV_USB :
|
2014-08-13 05:48:16 +00:00
|
|
|
|
2017-06-24 06:35:31 +00:00
|
|
|
// Process of the command the USB drive
|
2014-08-13 05:48:16 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2017-06-24 06:35:31 +00:00
|
|
|
|
2014-08-13 05:48:16 +00:00
|
|
|
return RES_PARERR;
|
|
|
|
}
|
2017-06-24 06:35:31 +00:00
|
|
|
|