This repository has been archived on 2022-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
Luma3DS-3GX/source/fatfs/diskio.c

102 lines
3.6 KiB
C
Raw Normal View History

2015-08-05 03:57:37 +02:00
/*-----------------------------------------------------------------------*/
/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2014 */
/*-----------------------------------------------------------------------*/
/* If a working storage control module is available, it should be */
/* attached to the FatFs via a glue function rather than modifying it. */
/* This is an example of glue functions to attach various exsisting */
/* storage control modules to the FatFs module with a defined API. */
/*-----------------------------------------------------------------------*/
#include "diskio.h" /* FatFs lower layer API */
#include "sdmmc/sdmmc.h"
2016-05-25 15:26:51 +02:00
#include "../crypto.h"
2015-08-05 03:57:37 +02:00
/* Definitions of physical drive number for each media */
#define SDCARD 0
#define CTRNAND 1
2015-08-05 03:57:37 +02:00
/*-----------------------------------------------------------------------*/
/* Get Drive Status */
/*-----------------------------------------------------------------------*/
DSTATUS disk_status (
__attribute__((unused))
BYTE pdrv /* Physical drive nmuber to identify the drive */
2015-08-05 03:57:37 +02:00
)
{
return RES_OK;
2015-08-05 03:57:37 +02:00
}
/*-----------------------------------------------------------------------*/
/* Inidialize a Drive */
/*-----------------------------------------------------------------------*/
DSTATUS disk_initialize (
BYTE pdrv /* Physical drive nmuber to identify the drive */
2015-08-05 03:57:37 +02:00
)
{
2016-10-07 14:51:32 +02:00
static u32 sdmmcInitResult = 4;
2016-10-07 14:51:32 +02:00
if(sdmmcInitResult == 4) sdmmcInitResult = sdmmc_sdcard_init();
2017-08-28 02:54:20 +02:00
return ((pdrv == SDCARD && !(sdmmcInitResult & 2)) ||
(pdrv == CTRNAND && !(sdmmcInitResult & 1) && !ctrNandInit())) ? 0 : STA_NOINIT;
2015-08-05 03:57:37 +02:00
}
/*-----------------------------------------------------------------------*/
/* Read Sector(s) */
/*-----------------------------------------------------------------------*/
DRESULT disk_read (
BYTE pdrv, /* Physical drive nmuber to identify the drive */
2015-08-05 03:57:37 +02:00
BYTE *buff, /* Data buffer to store read data */
DWORD sector, /* Sector address in LBA */
UINT count /* Number of sectors to read */
)
{
2017-08-28 02:54:20 +02:00
return ((pdrv == SDCARD && !sdmmc_sdcard_readsectors(sector, count, buff)) ||
(pdrv == CTRNAND && !ctrNandRead(sector, count, buff))) ? RES_OK : RES_PARERR;
2015-08-05 03:57:37 +02:00
}
/*-----------------------------------------------------------------------*/
/* Write Sector(s) */
/*-----------------------------------------------------------------------*/
#if _USE_WRITE
DRESULT disk_write (
BYTE pdrv, /* Physical drive nmuber to identify the drive */
2016-03-17 04:51:07 +01:00
const BYTE *buff, /* Data to be written */
2015-08-05 03:57:37 +02:00
DWORD sector, /* Sector address in LBA */
UINT count /* Number of sectors to write */
)
{
2017-08-28 02:54:20 +02:00
return ((pdrv == SDCARD && (*(vu16 *)(SDMMC_BASE + REG_SDSTATUS0) & TMIO_STAT0_WRPROTECT) != 0 && !sdmmc_sdcard_writesectors(sector, count, buff)) ||
(pdrv == CTRNAND && !ctrNandWrite(sector, count, buff))) ? RES_OK : RES_PARERR;
2015-08-05 03:57:37 +02:00
}
#endif
2015-08-05 03:57:37 +02:00
/*-----------------------------------------------------------------------*/
/* Miscellaneous Functions */
/*-----------------------------------------------------------------------*/
#if _USE_IOCTL
DRESULT disk_ioctl (
__attribute__((unused))
2015-08-05 03:57:37 +02:00
BYTE pdrv, /* Physical drive nmuber (0..) */
BYTE cmd, /* Control code */
__attribute__((unused))
2015-08-05 03:57:37 +02:00
void *buff /* Buffer to send/receive control data */
)
{
2017-08-28 02:54:20 +02:00
return cmd == CTRL_SYNC ? RES_OK : RES_PARERR;
2015-08-05 03:57:37 +02:00
}
#endif