diskio.c

来自「S64和VS1003的MP3播放实现的源代码/」· C语言 代码 · 共 165 行

C
165
字号
/*-----------------------------------------------------------------------*/
/* Low level disk I/O module skeleton for FatFs     (C)ChaN, 2007        */
/*-----------------------------------------------------------------------*/
/* This is a stub disk I/O module that acts as front end of the existing */
/* disk I/O modules and attach it to FatFs module with common interface. */
/*-----------------------------------------------------------------------*/


#include "diskio.h"

#define MMC		0	/* Physical drive number for Multi Media Card */
#define USB		1	/* Physical drive number for USB memory */



/*-----------------------------------------------------------------------*/
/* Inidialize a Drive                                                    */

DSTATUS disk_initialize (
	BYTE drv				/* Physical drive nmuber */
)
{
	DSTATUS stat = STA_NOINIT;

	switch (drv) 
    {
	    case MMC :
		    stat = MMC_disk_initialize();
		    // translate the reslut code here
		    break;

	    case USB :
		    stat = USB_disk_initialize();
		    // translate the reslut code here
		    break;
       
        default:
            break;
	}

	return stat;
}



/*-----------------------------------------------------------------------*/
/* Return Disk Status                                                    */

DSTATUS disk_status (
	BYTE drv		/* Physical drive nmuber */
)
{
	DSTATUS stat = STA_NOINIT;

	switch (drv) 
    {
	    case MMC :
		    stat = MMC_disk_status();
            break;

	    case USB :
		    stat = USB_disk_status();
		    break;

        default:
            break;
	}

	return stat;
}



/*-----------------------------------------------------------------------*/
/* Read Sector(s)                                                        */

DRESULT disk_read (
	BYTE drv,		/* Physical drive nmuber (0) */
	BYTE *buff,		/* Data buffer to store read data */
	DWORD sector,	/* Sector number (LBA) */
	BYTE count		/* Sector count (1..255) */
)
{
	DRESULT res = RES_PARERR;

	switch (drv) 
    {
    	case MMC :
    		res = MMC_disk_read(buff, sector, count);
            break;
    
    	case USB :
    		res = USB_disk_read(buff, sector, count);
            break;

        default:
            break;
	}

	return res;
}



/*-----------------------------------------------------------------------*/
/* Write Sector(s)                                                       */

#if _READONLY == 0
DRESULT disk_write (
	BYTE drv,			/* Physical drive nmuber (0) */
	const BYTE *buff,	/* Data to be written */
	DWORD sector,		/* Sector number (LBA) */
	BYTE count			/* Sector count (1..255) */
)
{
	DRESULT res = RES_PARERR;

	switch (drv) 
    {
    	case MMC :
    		res = MMC_disk_write(buff, sector, count);
            break;
    
    	case USB :
    		res = USB_disk_write(buff, sector, count);
            break;

        default:
            break;
	}
	return res;
}
#endif /* _READONLY */



/*-----------------------------------------------------------------------*/
/* Miscellaneous Functions                                               */

DRESULT disk_ioctl (
	BYTE drv,		/* Physical drive nmuber */
	BYTE ctrl,		/* Control code */
	void *buff		/* Buffer to send/receive data block */
)
{
	DRESULT res = RES_PARERR;

	switch (drv) 
    {


	case MMC :
		res = MMC_disk_ioctl(ctrl, buff);
        break;

	case USB :
		res = USB_disk_ioctl(ctrl, buff);
        break;

        default:
            break;
	}
	return res;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?