Made FatFS HAL device configurable.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@11350 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
Giovanni Di Sirio 2018-01-19 13:42:12 +00:00
parent 1a35b418db
commit d1fbd41782
1 changed files with 34 additions and 26 deletions

View File

@ -13,10 +13,18 @@
#error "cannot specify both MMC_SPI and SDC drivers" #error "cannot specify both MMC_SPI and SDC drivers"
#endif #endif
#if !defined(FATFS_HAL_DEVICE)
#if HAL_USE_MMC_SPI #if HAL_USE_MMC_SPI
extern MMCDriver MMCD1; #define FATFS_HAL_DEVICE MMCD1
#else
#define FATFS_HAL_DEVICE SDCD1
#endif
#endif
#if HAL_USE_MMC_SPI
extern MMCDriver FATFS_HAL_DEVICE;
#elif HAL_USE_SDC #elif HAL_USE_SDC
extern SDCDriver SDCD1; extern SDCDriver FATFS_HAL_DEVICE;
#else #else
#error "MMC_SPI or SDC driver must be specified" #error "MMC_SPI or SDC driver must be specified"
#endif #endif
@ -47,18 +55,18 @@ DSTATUS disk_initialize (
case MMC: case MMC:
stat = 0; stat = 0;
/* It is initialized externally, just reads the status.*/ /* It is initialized externally, just reads the status.*/
if (blkGetDriverState(&MMCD1) != BLK_READY) if (blkGetDriverState(&FATFS_HAL_DEVICE) != BLK_READY)
stat |= STA_NOINIT; stat |= STA_NOINIT;
if (mmcIsWriteProtected(&MMCD1)) if (mmcIsWriteProtected(&FATFS_HAL_DEVICE))
stat |= STA_PROTECT; stat |= STA_PROTECT;
return stat; return stat;
#else #else
case SDC: case SDC:
stat = 0; stat = 0;
/* It is initialized externally, just reads the status.*/ /* It is initialized externally, just reads the status.*/
if (blkGetDriverState(&SDCD1) != BLK_READY) if (blkGetDriverState(&FATFS_HAL_DEVICE) != BLK_READY)
stat |= STA_NOINIT; stat |= STA_NOINIT;
if (sdcIsWriteProtected(&SDCD1)) if (sdcIsWriteProtected(&FATFS_HAL_DEVICE))
stat |= STA_PROTECT; stat |= STA_PROTECT;
return stat; return stat;
#endif #endif
@ -82,18 +90,18 @@ DSTATUS disk_status (
case MMC: case MMC:
stat = 0; stat = 0;
/* It is initialized externally, just reads the status.*/ /* It is initialized externally, just reads the status.*/
if (blkGetDriverState(&MMCD1) != BLK_READY) if (blkGetDriverState(&FATFS_HAL_DEVICE) != BLK_READY)
stat |= STA_NOINIT; stat |= STA_NOINIT;
if (mmcIsWriteProtected(&MMCD1)) if (mmcIsWriteProtected(&FATFS_HAL_DEVICE))
stat |= STA_PROTECT; stat |= STA_PROTECT;
return stat; return stat;
#else #else
case SDC: case SDC:
stat = 0; stat = 0;
/* It is initialized externally, just reads the status.*/ /* It is initialized externally, just reads the status.*/
if (blkGetDriverState(&SDCD1) != BLK_READY) if (blkGetDriverState(&FATFS_HAL_DEVICE) != BLK_READY)
stat |= STA_NOINIT; stat |= STA_NOINIT;
if (sdcIsWriteProtected(&SDCD1)) if (sdcIsWriteProtected(&FATFS_HAL_DEVICE))
stat |= STA_PROTECT; stat |= STA_PROTECT;
return stat; return stat;
#endif #endif
@ -116,24 +124,24 @@ DRESULT disk_read (
switch (pdrv) { switch (pdrv) {
#if HAL_USE_MMC_SPI #if HAL_USE_MMC_SPI
case MMC: case MMC:
if (blkGetDriverState(&MMCD1) != BLK_READY) if (blkGetDriverState(&FATFS_HAL_DEVICE) != BLK_READY)
return RES_NOTRDY; return RES_NOTRDY;
if (mmcStartSequentialRead(&MMCD1, sector)) if (mmcStartSequentialRead(&FATFS_HAL_DEVICE, sector))
return RES_ERROR; return RES_ERROR;
while (count > 0) { while (count > 0) {
if (mmcSequentialRead(&MMCD1, buff)) if (mmcSequentialRead(&FATFS_HAL_DEVICE, buff))
return RES_ERROR; return RES_ERROR;
buff += MMCSD_BLOCK_SIZE; buff += MMCSD_BLOCK_SIZE;
count--; count--;
} }
if (mmcStopSequentialRead(&MMCD1)) if (mmcStopSequentialRead(&FATFS_HAL_DEVICE))
return RES_ERROR; return RES_ERROR;
return RES_OK; return RES_OK;
#else #else
case SDC: case SDC:
if (blkGetDriverState(&SDCD1) != BLK_READY) if (blkGetDriverState(&FATFS_HAL_DEVICE) != BLK_READY)
return RES_NOTRDY; return RES_NOTRDY;
if (sdcRead(&SDCD1, sector, buff, count)) if (sdcRead(&FATFS_HAL_DEVICE, sector, buff, count))
return RES_ERROR; return RES_ERROR;
return RES_OK; return RES_OK;
#endif #endif
@ -157,26 +165,26 @@ DRESULT disk_write (
switch (pdrv) { switch (pdrv) {
#if HAL_USE_MMC_SPI #if HAL_USE_MMC_SPI
case MMC: case MMC:
if (blkGetDriverState(&MMCD1) != BLK_READY) if (blkGetDriverState(&FATFS_HAL_DEVICE) != BLK_READY)
return RES_NOTRDY; return RES_NOTRDY;
if (mmcIsWriteProtected(&MMCD1)) if (mmcIsWriteProtected(&FATFS_HAL_DEVICE))
return RES_WRPRT; return RES_WRPRT;
if (mmcStartSequentialWrite(&MMCD1, sector)) if (mmcStartSequentialWrite(&FATFS_HAL_DEVICE, sector))
return RES_ERROR; return RES_ERROR;
while (count > 0) { while (count > 0) {
if (mmcSequentialWrite(&MMCD1, buff)) if (mmcSequentialWrite(&FATFS_HAL_DEVICE, buff))
return RES_ERROR; return RES_ERROR;
buff += MMCSD_BLOCK_SIZE; buff += MMCSD_BLOCK_SIZE;
count--; count--;
} }
if (mmcStopSequentialWrite(&MMCD1)) if (mmcStopSequentialWrite(&FATFS_HAL_DEVICE))
return RES_ERROR; return RES_ERROR;
return RES_OK; return RES_OK;
#else #else
case SDC: case SDC:
if (blkGetDriverState(&SDCD1) != BLK_READY) if (blkGetDriverState(&FATFS_HAL_DEVICE) != BLK_READY)
return RES_NOTRDY; return RES_NOTRDY;
if (sdcWrite(&SDCD1, sector, buff, count)) if (sdcWrite(&FATFS_HAL_DEVICE, sector, buff, count))
return RES_ERROR; return RES_ERROR;
return RES_OK; return RES_OK;
#endif #endif
@ -211,7 +219,7 @@ DRESULT disk_ioctl (
#endif #endif
#if FF_USE_TRIM #if FF_USE_TRIM
case CTRL_TRIM: case CTRL_TRIM:
mmcErase(&MMCD1, *((DWORD *)buff), *((DWORD *)buff + 1)); mmcErase(&FATFS_HAL_DEVICE, *((DWORD *)buff), *((DWORD *)buff + 1));
return RES_OK; return RES_OK;
#endif #endif
default: default:
@ -223,7 +231,7 @@ DRESULT disk_ioctl (
case CTRL_SYNC: case CTRL_SYNC:
return RES_OK; return RES_OK;
case GET_SECTOR_COUNT: case GET_SECTOR_COUNT:
*((DWORD *)buff) = mmcsdGetCardCapacity(&SDCD1); *((DWORD *)buff) = mmcsdGetCardCapacity(&FATFS_HAL_DEVICE);
return RES_OK; return RES_OK;
#if FF_MAX_SS > FF_MIN_SS #if FF_MAX_SS > FF_MIN_SS
case GET_SECTOR_SIZE: case GET_SECTOR_SIZE:
@ -235,7 +243,7 @@ DRESULT disk_ioctl (
return RES_OK; return RES_OK;
#if FF_USE_TRIM #if FF_USE_TRIM
case CTRL_TRIM: case CTRL_TRIM:
sdcErase(&SDCD1, *((DWORD *)buff), *((DWORD *)buff + 1)); sdcErase(&FATFS_HAL_DEVICE, *((DWORD *)buff), *((DWORD *)buff + 1));
return RES_OK; return RES_OK;
#endif #endif
default: default: