1
0
mirror of https://github.com/mist-devel/mist-firmware.git synced 2026-02-07 08:27:13 +00:00
Files
mist-devel.mist-firmware/FatFs/diskio.c
Gyorgy Szombathelyi 6417550b83 Critical bugfix in multi-sector writes
...which wasn't used anywhere
2021-05-22 20:52:05 +02:00

210 lines
4.6 KiB
C

/*-----------------------------------------------------------------------*/
/* Low level disk I/O module SKELETON for FatFs (C)ChaN, 2019 */
/*-----------------------------------------------------------------------*/
/* 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 "ff.h" /* Obtains integer types */
#include "diskio.h" /* Declarations of disk functions */
#include "../mmc.h"
/* Definitions of physical drive number for each drive */
#define DEV_MMC 0
#define DEV_USB 1
/*-----------------------------------------------------------------------*/
/* Get Drive Status */
/*-----------------------------------------------------------------------*/
DSTATUS disk_status (
BYTE pdrv /* Physical drive nmuber to identify the drive */
)
{
DSTATUS stat;
int result;
switch (pdrv) {
case DEV_MMC :
result = MMC_CheckCard();
// translate the reslut code here
stat = result ? 0 : STA_NOINIT;
return stat;
/*
case DEV_USB :
result = USB_disk_status();
// translate the reslut code here
return stat;
*/
}
return STA_NOINIT;
}
/*-----------------------------------------------------------------------*/
/* Inidialize a Drive */
/*-----------------------------------------------------------------------*/
DSTATUS disk_initialize (
BYTE pdrv /* Physical drive nmuber to identify the drive */
)
{
DSTATUS stat;
int result;
switch (pdrv) {
case DEV_MMC :
//result = MMC_disk_initialize();
// translate the reslut code here
stat = 0;
return stat;
/*
case DEV_USB :
result = USB_disk_initialize();
// translate the reslut code here
return stat;
*/
}
return STA_NOINIT;
}
/*-----------------------------------------------------------------------*/
/* Read Sector(s) */
/*-----------------------------------------------------------------------*/
DRESULT disk_read (
BYTE pdrv, /* Physical drive nmuber to identify the drive */
BYTE *buff, /* Data buffer to store read data */
LBA_t sector, /* Start sector in LBA */
UINT count /* Number of sectors to read */
)
{
DRESULT res;
int result;
//iprintf("disk_read: %d LBA: %d count: %d\n", pdrv, sector, count);
switch (pdrv) {
case DEV_MMC :
// translate the arguments here
if (count == 1)
result = MMC_Read(sector, buff);
else
result = MMC_ReadMultiple(sector, buff, count);
// translate the reslut code here
res = result ? RES_OK : RES_ERROR;
return res;
/*
case DEV_USB :
// translate the arguments here
result = USB_disk_read(buff, sector, count);
// translate the reslut code here
return res;
*/
}
return RES_PARERR;
}
/*-----------------------------------------------------------------------*/
/* Write Sector(s) */
/*-----------------------------------------------------------------------*/
#if FF_FS_READONLY == 0
DRESULT disk_write (
BYTE pdrv, /* Physical drive nmuber to identify the drive */
const BYTE *buff, /* Data to be written */
LBA_t sector, /* Start sector in LBA */
UINT count /* Number of sectors to write */
)
{
DRESULT res;
int result;
//iprintf("disk_write: %d LBA: %d count: %d\n", pdrv, sector, count);
switch (pdrv) {
case DEV_MMC :
// translate the arguments here
while (count) {
result = MMC_Write(sector++, buff);
if (!result) return RES_ERROR;
count--;
buff += 512;
}
// translate the reslut code here
return RES_OK;
/*
case DEV_USB :
// translate the arguments here
result = USB_disk_write(buff, sector, count);
// translate the reslut code here
return res;
*/
}
return RES_PARERR;
}
#endif
/*-----------------------------------------------------------------------*/
/* Miscellaneous Functions */
/*-----------------------------------------------------------------------*/
DRESULT disk_ioctl (
BYTE pdrv, /* Physical drive nmuber (0..) */
BYTE cmd, /* Control code */
void *buff /* Buffer to send/receive control data */
)
{
DRESULT res;
int result;
switch (pdrv) {
case DEV_MMC :
// Process of the command for the MMC/SD card
return RES_OK;
/*
case DEV_USB :
// Process of the command the USB drive
return res;
*/
}
return RES_PARERR;
}