DSTATUS disk_initialize ( BYTE pdrv /* Physical drive nmuber to identify the drive */ ) { DSTATUS stat; switch (pdrv) { #if HAL_USE_MMC_SPI case MMC: stat = 0; /* It is initialized externally, just reads the status.*/ if (blkGetDriverState(&MMCD1) != BLK_READY) stat |= STA_NOINIT; if (mmcIsWriteProtected(&MMCD1)) stat |= STA_PROTECT; return stat; #else case SDC: stat = 0; /* It is initialized externally, just reads the status.*/ if (blkGetDriverState(&SDCD1) != BLK_READY) stat |= STA_NOINIT; if (sdcIsWriteProtected(&SDCD1)) stat |= STA_PROTECT; return stat; #endif } return STA_NOINIT; }
DSTATUS disk_status ( BYTE drv /* Physical drive nmuber (0..) */ ) { DSTATUS stat; switch (drv) { #if HAL_USE_MMC_SPI case MMC: stat = 0; /* It is initialized externally, just reads the status.*/ if (mmcGetDriverState(&MMCD1) != MMC_READY) stat |= STA_NOINIT; if (mmcIsWriteProtected(&MMCD1)) stat |= STA_PROTECT; return stat; #else case SDC: stat = 0; /* It is initialized externally, just reads the status.*/ if (sdcGetDriverState(&SDCD1) != SDC_ACTIVE) stat |= STA_NOINIT; if (sdcIsWriteProtected(&SDCD1)) stat |= STA_PROTECT; return stat; #endif } return STA_NODISK; }
DRESULT disk_write ( BYTE pdrv, /* Physical drive nmuber to identify the drive */ const BYTE *buff, /* Data to be written */ DWORD sector, /* Sector address in LBA */ UINT count /* Number of sectors to write */ ) { switch (pdrv) { #if HAL_USE_MMC_SPI case MMC: if (blkGetDriverState(&MMCD1) != BLK_READY) return RES_NOTRDY; if (mmcIsWriteProtected(&MMCD1)) return RES_WRPRT; if (mmcStartSequentialWrite(&MMCD1, sector)) return RES_ERROR; while (count > 0) { if (mmcSequentialWrite(&MMCD1, buff)) return RES_ERROR; buff += MMCSD_BLOCK_SIZE; count--; } if (mmcStopSequentialWrite(&MMCD1)) return RES_ERROR; return RES_OK; #else case SDC: if (blkGetDriverState(&SDCD1) != BLK_READY) return RES_NOTRDY; if (sdcWrite(&SDCD1, sector, buff, count)) return RES_ERROR; return RES_OK; #endif } return RES_PARERR; }
DRESULT disk_write ( BYTE drv, /* Physical drive nmuber (0..) */ const BYTE *buff, /* Data to be written */ DWORD sector, /* Sector address (LBA) */ BYTE count /* Number of sectors to write (1..255) */ ) { switch (drv) { #if HAL_USE_MMC_SPI case MMC: if (mmcGetDriverState(&MMCD1) != MMC_READY) return RES_NOTRDY; if (mmcIsWriteProtected(&MMCD1)) return RES_WRPRT; if (mmcStartSequentialWrite(&MMCD1, sector)) return RES_ERROR; while (count > 0) { if (mmcSequentialWrite(&MMCD1, buff)) return RES_ERROR; buff += MMC_SECTOR_SIZE; count--; } if (mmcStopSequentialWrite(&MMCD1)) return RES_ERROR; return RES_OK; #else case SDC: if (sdcGetDriverState(&SDCD1) != SDC_ACTIVE) return RES_NOTRDY; if (sdcWrite(&SDCD1, sector, buff, count)) return RES_ERROR; return RES_OK; #endif } return RES_PARERR; }