mini/diskio.c

77 lines
1.7 KiB
C
Raw Normal View History

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"
#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
DSTATUS disk_initialize (BYTE drv) {
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
}
2009-04-13 02:59:01 +02:00
// Return Disk Status
DSTATUS disk_status (BYTE drv) {
2009-04-13 15:42:46 +02:00
(void)drv;
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)
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 */