2009-04-13 02:59:01 +02:00
|
|
|
/*
|
|
|
|
mini - a Free Software replacement for the Nintendo/BroadOn IOS.
|
|
|
|
glue layer for FatFs
|
|
|
|
|
2009-04-13 22:13:45 +02:00
|
|
|
Copyright (C) 2008, 2009 Sven Peter <svenpeter@gmail.com>
|
|
|
|
Copyright (C) 2008, 2009 Haxx Enterprises <bushing@gmail.com>
|
2009-04-13 02:59:01 +02:00
|
|
|
|
2009-05-11 07:53:16 +02:00
|
|
|
# This code is licensed to you under the terms of the GNU GPL, version 2;
|
|
|
|
# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
|
2009-04-13 02:59:01 +02:00
|
|
|
*/
|
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);
|
2009-10-26 10:19:37 +01:00
|
|
|
|
|
|
|
// Initialize a Drive
|
|
|
|
DSTATUS disk_initialize (BYTE drv) {
|
|
|
|
if (sdmmc_check_card() == SDMMC_NO_CARD)
|
|
|
|
return STA_NOINIT;
|
|
|
|
|
|
|
|
sdmmc_ack_card();
|
|
|
|
return disk_status(drv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return Disk Status
|
|
|
|
DSTATUS disk_status (BYTE drv) {
|
|
|
|
(void)drv;
|
|
|
|
if (sdmmc_check_card() == 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)
|
|
|
|
DRESULT disk_read (BYTE drv, BYTE *buff, DWORD sector, BYTE count) {
|
2009-10-26 10:19:37 +01:00
|
|
|
int i;
|
|
|
|
(void)drv;
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
if (sdmmc_read(sector+i, 1, buffer) != 0)
|
|
|
|
return RES_ERROR;
|
|
|
|
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-10-26 10:19:37 +01:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
memcpy(buffer, buff + i * 512, 512);
|
|
|
|
|
|
|
|
if(sdmmc_write(sector + i, 1, buffer) != 0)
|
|
|
|
return RES_ERROR;
|
|
|
|
}
|
|
|
|
|
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 */
|