⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 diskio.c

📁 基于msp430单片机的SD卡读写驱动
💻 C
字号:
/*-----------------------------------------------------------------------*/
/* 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 "hal_hardware_board.h"
//#include "hal_MMC_hardware_board.h"
#include "mmc.h"
#include <stdio.h>
#include "diskio.h"

/*-----------------------------------------------------------------------*/
/* Correspondence between drive number and physical drive                */
/* Note that Tiny-FatFs supports only single drive and always            */
/* accesses drive number 0.                                              */

#define ATA		1
#define MMC		0
#define USB		2



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

DSTATUS disk_initialize (
	BYTE drv				/* Physical drive nmuber (0..) */
)
{
	//DSTATUS stat;
	int result;

	switch (drv) {
	case ATA :
		//result = ATA_disk_initialize();
		// translate the reslut code here

		return 0;

	case MMC :
		//result = MMC_disk_initialize();
                result = mmcInit();
		// translate the reslut code here

		//return stat;
                return result;

	case USB :
		//result = USB_disk_initialize();
		// translate the reslut code here

		return 0;
	}
	return STA_NOINIT;
}



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

DSTATUS disk_status (
	BYTE drv		/* Physical drive nmuber (0..) */
)
{
	//DSTATUS stat;
	//int result;

	switch (drv) {
	case ATA :
		//result = ATA_disk_status();
		// translate the reslut code here

		return 0;

	case MMC :
		//result = MMC_disk_status();
		// translate the reslut code here

		//return stat;
                return 0;

	case USB :
		//result = USB_disk_status();
		// translate the reslut code here

		return 0;
	}
	return STA_NOINIT;
}



/*-----------------------------------------------------------------------*/
/* 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;
	//int     result;
        UINT    i;

	switch (drv) {
	case ATA :
		//result = ATA_disk_read(buff, sector, count);
		// translate the reslut code here

		return RES_OK;

	case MMC :
		//result = MMC_disk_read(buff, sector, count);
		// translate the reslut code here
                for(i=0;i<count;i++)
                {
                    mmcReadSector(sector+i, buff+512*i); 
                }

		return RES_OK;
                //return 0;

	case USB :
		//result = USB_disk_read(buff, sector, count);
		// translate the reslut code here

		return RES_OK;
	}
	return RES_PARERR;
}



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

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

	switch (drv) {
	case ATA :
		//result = ATA_disk_write(buff, sector, count);
		// translate the reslut code here

		return RES_OK;

	case MMC :
		//result = MMC_disk_write(buff, sector, count);
		// translate the reslut code here
                for(i=0;i<count;i++)
                {
                     mmcWriteSector(sector+i, buff+512*i); 
                }

		//return res;
                return RES_OK;

	case USB :
		//result = USB_disk_write(buff, sector, count);
		// translate the reslut code here

		return RES_OK;
	}
	return RES_PARERR;
}
#endif /* _READONLY */



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

DRESULT disk_ioctl (
	BYTE drv,		/* Physical drive nmuber (0..) */
	BYTE ctrl,		/* Control code */
	void *buff		/* Buffer to send/receive control data */
)
{
	//DRESULT res;
	//int result;

	switch (drv) {
	case ATA :
		// pre-process here

		//result = ATA_disk_ioctl(ctrl, buff);
		// post-process here

		return RES_OK;

	case MMC :
		// pre-process here

		//result = MMC_disk_ioctl(ctrl, buff);
		// post-process here

		//return res;
                return RES_OK;

	case USB :
		// pre-process here

		//result = USB_disk_ioctl(ctrl, buff);
		// post-process here

		return RES_OK;
	}
	return RES_PARERR;
}

⌨️ 快捷键说明

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