mini/diskio.c

127 lines
3.1 KiB
C
Raw Normal View History

2008-12-28 14:35:37 +01:00
/*-----------------------------------------------------------------------*/
/* 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"
2009-04-09 14:20:12 +02:00
#include "string.h"
#include "sdmmc.h"
//#include "sdhc.h"
2009-04-09 14:20:12 +02:00
#ifndef MEM2_BSS
#define MEM2_BSS
#endif
2008-12-28 14:35:37 +01:00
//static sdhci_t sdhci;
2009-01-08 23:27:22 +01:00
static u8 buffer[512] MEM2_BSS ALIGNED(32);
2008-12-28 14:35:37 +01:00
/*-----------------------------------------------------------------------*/
/* Inidialize a Drive */
DSTATUS disk_initialize (
BYTE drv /* Physical drive nmuber (0..) */
)
{
if (sdmmc_check_card(SDMMC_DEFAULT_DEVICE) == SDMMC_NO_CARD)
2008-12-28 14:35:37 +01:00
return STA_NOINIT;
sdmmc_ack_card(SDMMC_DEFAULT_DEVICE);
return disk_status(drv);
2008-12-28 14:35:37 +01:00
}
/*-----------------------------------------------------------------------*/
/* Return Disk Status */
DSTATUS disk_status (
BYTE drv /* Physical drive nmuber (0..) */
)
{
// if (sd_inserted(&sdhci) == 0)
// return STA_NODISK;
2009-04-09 14:20:12 +02:00
if (sdmmc_check_card(SDMMC_DEFAULT_DEVICE) == SDMMC_INSERTED)
return 0;
else
return STA_NODISK;
2008-12-28 14:35:37 +01:00
}
/*-----------------------------------------------------------------------*/
/* Read Sector(s) */
DRESULT disk_read (
BYTE drv, /* Physical drive nmuber (0..) */
BYTE *buff, /* Data buffer to store read data */
DWORD sector, /* Sector address (LBA) */
BYTE count /* Number of sectors to read (1..255) */
)
{
int i;
DRESULT res;
res = RES_OK;
2009-04-09 14:20:12 +02:00
for (i = 0; i < count; i++) {
if (sdmmc_read(SDMMC_DEFAULT_DEVICE, sector+i, 1, buffer) != 0){
2008-12-28 14:35:37 +01:00
res = RES_ERROR;
break;
}
2009-04-09 14:20:12 +02:00
2008-12-28 14:35:37 +01:00
memcpy(buff + i * 512, buffer, 512);
}
2009-04-09 14:20:12 +02:00
2008-12-28 14:35:37 +01:00
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 address (LBA) */
BYTE count /* Number of sectors to write (1..255) */
)
{
int i;
DRESULT res;
res = RES_OK;
2009-04-09 14:20:12 +02:00
for (i = 0; i < count; i++) {
2008-12-28 14:35:37 +01:00
memcpy(buffer, buff + i * 512, 512);
2009-04-09 14:20:12 +02:00
/* if(sd_write(&sdhci, sector + i, 1, buffer) != 0) {
2008-12-28 14:35:37 +01:00
res = RES_ERROR;
break;
}*/
2008-12-28 14:35:37 +01:00
}
2009-04-09 14:20:12 +02:00
2008-12-28 14:35:37 +01:00
return res;
}
#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 */
)
{
2009-04-09 14:20:12 +02:00
if (ctrl == CTRL_SYNC)
2008-12-28 14:35:37 +01:00
return RES_OK;
2009-04-09 14:20:12 +02:00
return RES_PARERR;
2008-12-28 14:35:37 +01:00
}