Skip to content

Commit

Permalink
Merge pull request #404 from josesimoes/patch-3
Browse files Browse the repository at this point in the history
Update fatfs_diskio
  • Loading branch information
fpoussin committed Jun 11, 2024
2 parents 729528d + 8b15418 commit 5621625
Showing 1 changed file with 75 additions and 87 deletions.
162 changes: 75 additions & 87 deletions os/various/fatfs_bindings/fatfs_diskio.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ extern RTCDriver RTCD1;


/*-----------------------------------------------------------------------*/
/* Inidialize a Drive */
/* Initialize a Drive */

DSTATUS disk_initialize (
BYTE pdrv /* Physical drive number (0..) */
Expand All @@ -55,38 +55,36 @@ DSTATUS disk_initialize (

switch (pdrv) {
#if HAL_USE_MMC_SPI
case FATFSDEV_MMC:
stat = 0;
/* It is initialized externally, just reads the status.*/
if (blkGetDriverState(&FATFS_HAL_DEVICE) != BLK_READY)
stat |= STA_NOINIT;
if (mmcIsWriteProtected(&FATFS_HAL_DEVICE))
stat |= STA_PROTECT;
return stat;
case FATFSDEV_MMC:
stat = 0;
/* It is initialized externally, just reads the status.*/
if (blkGetDriverState(&FATFS_HAL_DEVICE) != BLK_READY)
stat |= STA_NOINIT;
if (mmcIsWriteProtected(&FATFS_HAL_DEVICE))
stat |= STA_PROTECT;
return stat;
#elif HAL_USE_SDC
case FATFSDEV_MMC:
stat = 0;
/* It is initialized externally, just reads the status.*/
if (blkGetDriverState(&FATFS_HAL_DEVICE) != BLK_READY)
stat |= STA_NOINIT;
if (blkIsWriteProtected(&FATFS_HAL_DEVICE))
stat |= STA_PROTECT;
return stat;
case FATFSDEV_MMC:
stat = 0;
/* It is initialized externally, just reads the status.*/
if (blkGetDriverState(&FATFS_HAL_DEVICE) != BLK_READY)
stat |= STA_NOINIT;
if (blkIsWriteProtected(&FATFS_HAL_DEVICE))
stat |= STA_PROTECT;
return stat;
#endif
#if HAL_USBH_USE_MSD
case FATFSDEV_MSD:
stat = 0;
/* It is initialized externally, just reads the status.*/
if (blkGetDriverState(&MSBLKD[0]) != BLK_READY)
stat |= STA_NOINIT;
return stat;
case FATFSDEV_MSD:
stat = 0;
/* It is initialized externally, just reads the status.*/
if (blkGetDriverState(&MSBLKD[0]) != BLK_READY)
stat |= STA_NOINIT;
return stat;
#endif
}
return STA_NOINIT;
}



/*-----------------------------------------------------------------------*/
/* Return Disk Status */

Expand Down Expand Up @@ -117,19 +115,17 @@ DSTATUS disk_status (
return stat;
#endif
#if HAL_USBH_USE_MSD
case FATFSDEV_MSD:
stat = 0;
/* It is initialized externally, just reads the status.*/
if (blkGetDriverState(&MSBLKD[0]) != BLK_READY)
stat |= STA_NOINIT;
return stat;
case FATFSDEV_MSD:
stat = 0;
/* It is initialized externally, just reads the status.*/
if (blkGetDriverState(&MSBLKD[0]) != BLK_READY)
stat |= STA_NOINIT;
return stat;
#endif
}
return STA_NOINIT;
}



/*-----------------------------------------------------------------------*/
/* Read Sector(s) */

Expand Down Expand Up @@ -165,20 +161,18 @@ DRESULT disk_read (
return RES_OK;
#endif
#if HAL_USBH_USE_MSD
case FATFSDEV_MSD:
/* It is initialized externally, just reads the status.*/
if (blkGetDriverState(&MSBLKD[0]) != BLK_READY)
return RES_NOTRDY;
if (usbhmsdLUNRead(&MSBLKD[0], sector, buff, count))
return RES_ERROR;
return RES_OK;
case FATFSDEV_MSD:
/* It is initialized externally, just reads the status.*/
if (blkGetDriverState(&MSBLKD[0]) != BLK_READY)
return RES_NOTRDY;
if (usbhmsdLUNRead(&MSBLKD[0], sector, buff, count))
return RES_ERROR;
return RES_OK;
#endif
}
return RES_PARERR;
}



/*-----------------------------------------------------------------------*/
/* Write Sector(s) */

Expand All @@ -190,7 +184,6 @@ DRESULT disk_write (
UINT count /* Number of sectors to write (1..255) */
)
{

switch (pdrv) {
#if HAL_USE_MMC_SPI
case FATFSDEV_MMC:
Expand Down Expand Up @@ -228,24 +221,22 @@ DRESULT disk_write (
#endif
#if HAL_USBH_USE_MSD
case FATFSDEV_MSD:
/* It is initialized externally, just reads the status.*/
if (blkGetDriverState(&MSBLKD[0]) != BLK_READY)
return RES_NOTRDY;
/* It is initialized externally, just reads the status.*/
if (blkGetDriverState(&MSBLKD[0]) != BLK_READY)
return RES_NOTRDY;

// invalidate cache on buffer
cacheBufferFlush(buff, count * MSBLKD[0].info.blk_size);

if (usbhmsdLUNWrite(&MSBLKD[0], sector, buff, count))
return RES_ERROR;
return RES_OK;
if (usbhmsdLUNWrite(&MSBLKD[0], sector, buff, count))
return RES_ERROR;
return RES_OK;
#endif
}
return RES_PARERR;
}
#endif /* _FS_READONLY */



/*-----------------------------------------------------------------------*/
/* Miscellaneous Functions */

Expand All @@ -255,8 +246,6 @@ DRESULT disk_ioctl (
void *buff /* Buffer to send/receive control data */
)
{
BlockDeviceInfo bdi;

(void)buff;

switch (pdrv) {
Expand All @@ -280,59 +269,58 @@ DRESULT disk_ioctl (
}
#elif HAL_USE_SDC
case FATFSDEV_MMC:
BlockDeviceInfo bdi;

switch (cmd) {
case CTRL_SYNC:
case CTRL_SYNC:
return RES_OK;
case GET_SECTOR_COUNT:
if (blkGetInfo(&FATFS_HAL_DEVICE, &bdi)) {
return RES_ERROR;
}
*((DWORD *)buff) = bdi.blk_num;
return RES_OK;
case GET_SECTOR_COUNT:
if (blkGetInfo(&FATFS_HAL_DEVICE, &bdi)) {
return RES_ERROR;
}
*((DWORD *)buff) = bdi.blk_num;
return RES_OK;
#if FF_MAX_SS > FF_MIN_SS
case GET_SECTOR_SIZE:
if (blkGetInfo(&FATFS_HAL_DEVICE, &bdi)) {
return RES_ERROR;
}
*((WORD *)buff) = bdi.blk_size;
return RES_OK;
#endif
case GET_BLOCK_SIZE:
*((DWORD *)buff) = 256; /* 512b blocks in one erase block */
case GET_SECTOR_SIZE:
if (blkGetInfo(&FATFS_HAL_DEVICE, &bdi)) {
return RES_ERROR;
}
*((WORD *)buff) = bdi.blk_size;
return RES_OK;
#endif
#if FF_USE_TRIM
case GET_BLOCK_SIZE:
/* unsupported */
break;
case CTRL_TRIM:
/* unsupported */
break;
case GET_BLOCK_SIZE:
/* unsupported */
break;
case CTRL_TRIM:
/* unsupported */
break;
#endif
default:
return RES_PARERR;
default:
return RES_PARERR;
}
#endif
#if HAL_USBH_USE_MSD
case FATFSDEV_MSD:
switch (cmd) {
case CTRL_SYNC:
return RES_OK;
case GET_SECTOR_COUNT:
*((DWORD *)buff) = MSBLKD[0].info.blk_num;
return RES_OK;
case CTRL_SYNC:
return RES_OK;
case GET_SECTOR_COUNT:
*((DWORD *)buff) = MSBLKD[0].info.blk_num;
return RES_OK;
#if FF_MAX_SS > FF_MIN_SS
case GET_SECTOR_SIZE:
*((WORD *)buff) = MSBLKD[0].info.blk_size;
return RES_OK;
case GET_SECTOR_SIZE:
*((WORD *)buff) = MSBLKD[0].info.blk_size;
return RES_OK;
#endif
#if FF_USE_TRIM
#error "unimplemented yet!"
// case CTRL_TRIM:
// ....
// return RES_OK;
#endif
default:
return RES_PARERR;
default:
return RES_PARERR;
}
#endif
}
Expand Down

0 comments on commit 5621625

Please sign in to comment.