Skip to content

Commit

Permalink
fat: remove disk_read_sdram API, and move that into the SDFS backend
Browse files Browse the repository at this point in the history
  • Loading branch information
rasky committed Oct 12, 2024
1 parent 0fa0747 commit a9a6122
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 17 deletions.
55 changes: 52 additions & 3 deletions include/fat.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,63 @@ extern "C" {
* volume.
*/
typedef struct {
///@cond
/**
* @brief Initialize the underlying device.
*
* This function is called at mount time.
*
* @return Disk status codes (see fatfs/diskio.h)
* @see http://elm-chan.org/fsw/ff/doc/dinit.html
*/
int (*disk_initialize)(void);

/**
* @brief Return the current status of the underlying device.
*
* Return the current status of the device. The status can be
* a combination of:
*
* * STA_NOINIT: device must be reinitialized
* * STA_NODISK: no medium in the device
* * STA_PROTECT: write protected
*
* @return Disk status codes (see fatfs/diskio.h)
* @see http://elm-chan.org/fsw/ff/doc/dstat.html
*/
int (*disk_status)(void);

/**
* @brief Read sectors from the underlying device into RDRAM.
*
* This function reads sectors from the underlying device into RDRAM.
*
* @return Result code (see fatfs/diskio.h)
* @see http://elm-chan.org/fsw/ff/doc/dread.html
*/
int (*disk_read)(uint8_t* buff, int64_t sector, int count);
int (*disk_read_sdram)(uint8_t* buff, int64_t sector, int count);

/**
* @brief Write sectors from RDRAM to the underlying device.
*
* This function writes sectors from RDRAM to the underlying device.
*
* @return Result code (see fatfs/diskio.h)
* @see http://elm-chan.org/fsw/ff/doc/dwrite.html
*/
int (*disk_write)(const uint8_t* buff, int64_t sector, int count);

/**
* @brief Perform a I/O request on the underlying device.
*
* This function performs a I/O request on the underlying device.
* FatFs uses this function to perform various operations like
* getting the sector count, the sector size, etc. It can be
* used to implement custom operations as well.
*
* @return Result code (see fatfs/diskio.h)
* @see http://elm-chan.org/fsw/ff/doc/dioctl.html
*/
int (*disk_ioctl)(uint8_t cmd, void* buff);
///@endcond
} fat_disk_t;


Expand Down
22 changes: 15 additions & 7 deletions src/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,27 @@ static int fat_disk_initialize_sd(void)

static int fat_disk_read_sd(uint8_t* buff, int64_t sector, int count)
{
_Static_assert(FF_MIN_SS == 512, "this function assumes sector size == 512");
_Static_assert(FF_MAX_SS == 512, "this function assumes sector size == 512");
assertf((uint32_t)sector == sector, "unsupported access to SD card > 2 TiB");
return cart_card_rd_dram(buff, sector, count) ? RES_ERROR : RES_OK;
}

static int fat_disk_read_sdram_sd(uint8_t* buff, int64_t sector, int count)
{
assertf((uint32_t)sector == sector, "unsupported access to SD card > 2 TiB");
return cart_card_rd_cart(PhysicalAddr(buff), sector, count) ? RES_ERROR : RES_OK;
// Check whether the user is requesting a read into RDRAM, or into
// the cartridge's SDRAM (that is, a PI-accessible address). We try
// to be generic here and not hardcode specific addresses; we assume
// libcart will know better than us where the SDRAM is located.
if (PhysicalAddr(buff) < 0x00800000)
return cart_card_rd_dram(buff, sector, count) ? RES_ERROR : RES_OK;
if (io_accessible(PhysicalAddr(buff)))
return cart_card_rd_cart(PhysicalAddr(buff), sector, count) ? RES_ERROR : RES_OK;

return RES_PARERR;
}


static int fat_disk_write_sd(const uint8_t* buff, int64_t sector, int count)
{
_Static_assert(FF_MIN_SS == 512, "this function assumes sector size == 512");
_Static_assert(FF_MAX_SS == 512, "this function assumes sector size == 512");
assertf((uint32_t)sector == sector, "unsupported access to SD card > 2 TiB");
return cart_card_wr_dram(buff, sector, count) ? RES_ERROR : RES_OK;
}
Expand All @@ -208,7 +217,6 @@ static fat_disk_t fat_disk_sd =
.disk_initialize = fat_disk_initialize_sd,
.disk_status = fat_disk_status_default,
.disk_read = fat_disk_read_sd,
.disk_read_sdram = fat_disk_read_sdram_sd,
.disk_write = fat_disk_write_sd,
.disk_ioctl = fat_disk_ioctl_default,
};
Expand Down
8 changes: 1 addition & 7 deletions src/fat.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,13 @@ DSTATUS disk_status(BYTE pdrv)

DRESULT disk_read(BYTE pdrv, BYTE* buff, LBA_t sector, UINT count)
{
_Static_assert(FF_MIN_SS == 512, "this function assumes sector size == 512");
_Static_assert(FF_MAX_SS == 512, "this function assumes sector size == 512");
if (fat_disks[pdrv].disk_read && PhysicalAddr(buff) < 0x00800000)
if (fat_disks[pdrv].disk_read)
return fat_disks[pdrv].disk_read(buff, sector, count);
if (fat_disks[pdrv].disk_read_sdram && io_accessible(PhysicalAddr(buff)))
return fat_disks[pdrv].disk_read_sdram(buff, sector, count);
return RES_PARERR;
}

DRESULT disk_write(BYTE pdrv, const BYTE* buff, LBA_t sector, UINT count)
{
_Static_assert(FF_MIN_SS == 512, "this function assumes sector size == 512");
_Static_assert(FF_MAX_SS == 512, "this function assumes sector size == 512");
if (fat_disks[pdrv].disk_write)
return fat_disks[pdrv].disk_write(buff, sector, count);
return RES_PARERR;
Expand Down

0 comments on commit a9a6122

Please sign in to comment.