2009-04-13 02:59:01 +02:00
|
|
|
/*
|
|
|
|
mini - a Free Software replacement for the Nintendo/BroadOn IOS.
|
|
|
|
|
|
|
|
glue layer for FatFs
|
|
|
|
|
|
|
|
Copyright (C) 2008, 2009 Sven Peter <svenpeter@gmail.com>
|
|
|
|
Copyright (C) 2008, 2009 Haxx Enterprises <bushing@gmail.com>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, version 2.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
|
|
|
*/
|
2008-12-28 14:35:37 +01:00
|
|
|
|
|
|
|
#include "diskio.h"
|
2009-04-09 14:20:12 +02:00
|
|
|
#include "string.h"
|
2009-04-12 13:17:44 +02:00
|
|
|
#include "sdmmc.h"
|
2009-04-09 14:20:12 +02:00
|
|
|
|
|
|
|
#ifndef MEM2_BSS
|
|
|
|
#define MEM2_BSS
|
|
|
|
#endif
|
2008-12-28 14:35:37 +01:00
|
|
|
|
2009-01-08 23:27:22 +01:00
|
|
|
static u8 buffer[512] MEM2_BSS ALIGNED(32);
|
2008-12-28 14:35:37 +01:00
|
|
|
|
2009-04-13 02:59:01 +02:00
|
|
|
// Initialize a Drive
|
2008-12-28 14:35:37 +01:00
|
|
|
|
2009-04-13 02:59:01 +02:00
|
|
|
DSTATUS disk_initialize (BYTE drv) {
|
2009-04-12 13:17:44 +02:00
|
|
|
if (sdmmc_check_card(SDMMC_DEFAULT_DEVICE) == SDMMC_NO_CARD)
|
2008-12-28 14:35:37 +01:00
|
|
|
return STA_NOINIT;
|
2009-04-12 13:17:44 +02:00
|
|
|
|
|
|
|
sdmmc_ack_card(SDMMC_DEFAULT_DEVICE);
|
|
|
|
return disk_status(drv);
|
2008-12-28 14:35:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-04-13 02:59:01 +02:00
|
|
|
// Return Disk Status
|
2009-04-09 14:20:12 +02:00
|
|
|
|
2009-04-13 02:59:01 +02:00
|
|
|
DSTATUS disk_status (BYTE drv) {
|
2009-04-13 15:42:46 +02:00
|
|
|
(void)drv;
|
2009-04-12 13:17:44 +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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-04-13 02:59:01 +02:00
|
|
|
// Read Sector(s)
|
2008-12-28 14:35:37 +01:00
|
|
|
|
2009-04-13 02:59:01 +02:00
|
|
|
DRESULT disk_read (BYTE drv, BYTE *buff, DWORD sector, BYTE count) {
|
2008-12-28 14:35:37 +01:00
|
|
|
int i;
|
2009-04-13 15:42:46 +02:00
|
|
|
(void)drv;
|
2009-04-09 14:20:12 +02:00
|
|
|
for (i = 0; i < count; i++) {
|
2009-04-13 02:59:01 +02:00
|
|
|
if (sdmmc_read(SDMMC_DEFAULT_DEVICE, sector+i, 1, buffer) != 0)
|
|
|
|
return RES_ERROR;
|
2008-12-28 14:35:37 +01:00
|
|
|
memcpy(buff + i * 512, buffer, 512);
|
|
|
|
}
|
2009-04-09 14:20:12 +02:00
|
|
|
|
2009-04-13 02:59:01 +02:00
|
|
|
return RES_OK;
|
2008-12-28 14:35:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-04-13 02:59:01 +02:00
|
|
|
// Write Sector(s)
|
2008-12-28 14:35:37 +01:00
|
|
|
|
|
|
|
#if _READONLY == 0
|
2009-04-13 02:59:01 +02:00
|
|
|
DRESULT disk_write (BYTE drv, const BYTE *buff, DWORD sector, BYTE count) {
|
2008-12-28 14:35:37 +01:00
|
|
|
int i;
|
|
|
|
|
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
|
|
|
|
2009-04-13 02:59:01 +02:00
|
|
|
if(sdmmc_write(SDMMC_DEFAULT_DEVICE, sector + i, 1, buffer) != 0)
|
|
|
|
return RES_ERROR;
|
2008-12-28 14:35:37 +01:00
|
|
|
}
|
2009-04-09 14:20:12 +02:00
|
|
|
|
2009-04-13 02:59:01 +02:00
|
|
|
return RES_OK;
|
2008-12-28 14:35:37 +01:00
|
|
|
}
|
|
|
|
#endif /* _READONLY */
|
|
|
|
|
2009-04-13 02:59:01 +02:00
|
|
|
#if _USE_IOCTL == 1
|
|
|
|
DRESULT disk_ioctl (BYTE drv, BYTE ctrl, void *buff) {
|
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
|
|
|
}
|
2009-04-13 02:59:01 +02:00
|
|
|
#endif /* _USE_IOCTL */
|