From f0152ab13b753d4e0ebfacc9afa7c574e5c6979a Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 22 Apr 2012 10:47:39 +0000 Subject: Integrated FatFS 0.9, changes to the FatFS demos and integration files. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4120 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/various/diskio.c | 244 ------------------------------ os/various/fatfs_bindings/fatfs.mk | 4 +- os/various/fatfs_bindings/fatfs_syscall.c | 8 +- 3 files changed, 7 insertions(+), 249 deletions(-) delete mode 100755 os/various/diskio.c (limited to 'os') diff --git a/os/various/diskio.c b/os/various/diskio.c deleted file mode 100755 index 07d44db49..000000000 --- a/os/various/diskio.c +++ /dev/null @@ -1,244 +0,0 @@ -/*-----------------------------------------------------------------------*/ -/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2007 */ -/*-----------------------------------------------------------------------*/ -/* This is a stub disk I/O module that acts as front end of the existing */ -/* disk I/O modules and attach it to FatFs module with common interface. */ -/*-----------------------------------------------------------------------*/ - -#include "ch.h" -#include "hal.h" - -#include "diskio.h" - -#if HAL_USE_MMC_SPI && HAL_USE_SDC -#error "cannot specify both MMC_SPI and SDC drivers" -#endif - -#if HAL_USE_MMC_SPI -extern MMCDriver MMCD1; -#elif HAL_USE_SDC -extern SDCDriver SDCD1; -#else -#error "MMC_SPI or SDC driver must be specified" -#endif - -#if HAL_USE_RTC -#include "chrtclib.h" -extern RTCDriver RTCD1; -#endif - -/*-----------------------------------------------------------------------*/ -/* Correspondence between physical drive number and physical drive. */ - -#define MMC 0 -#define SDC 0 - - - -/*-----------------------------------------------------------------------*/ -/* Inidialize a Drive */ - -DSTATUS disk_initialize ( - 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; -} - - - -/*-----------------------------------------------------------------------*/ -/* Return Disk Status */ - -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; -} - - - -/*-----------------------------------------------------------------------*/ -/* Read Sector(s) */ - -DRESULT disk_read ( - BYTE drv, /* Physical drive nmuber (0..) */ - BYTE *buff, /* Data buffer to store read data */ - DWORD sector, /* Sector address (LBA) */ - BYTE count /* Number of sectors to read (1..255) */ -) -{ - switch (drv) { -#if HAL_USE_MMC_SPI - case MMC: - if (mmcGetDriverState(&MMCD1) != MMC_READY) - return RES_NOTRDY; - if (mmcStartSequentialRead(&MMCD1, sector)) - return RES_ERROR; - while (count > 0) { - if (mmcSequentialRead(&MMCD1, buff)) - return RES_ERROR; - buff += MMC_SECTOR_SIZE; - count--; - } - if (mmcStopSequentialRead(&MMCD1)) - return RES_ERROR; - return RES_OK; -#else - case SDC: - if (sdcGetDriverState(&SDCD1) != SDC_ACTIVE) - return RES_NOTRDY; - if (sdcRead(&SDCD1, sector, buff, count)) - return RES_ERROR; - return RES_OK; -#endif - } - return RES_PARERR; -} - - - -/*-----------------------------------------------------------------------*/ -/* Write Sector(s) */ - -#if _READONLY == 0 -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; -} -#endif /* _READONLY */ - - - -/*-----------------------------------------------------------------------*/ -/* Miscellaneous Functions */ - -DRESULT disk_ioctl ( - BYTE drv, /* Physical drive nmuber (0..) */ - BYTE ctrl, /* Control code */ - void *buff /* Buffer to send/receive control data */ -) -{ - switch (drv) { -#if HAL_USE_MMC_SPI - case MMC: - switch (ctrl) { - case CTRL_SYNC: - return RES_OK; - case GET_SECTOR_SIZE: - *((WORD *)buff) = MMC_SECTOR_SIZE; - return RES_OK; - default: - return RES_PARERR; - } -#else - case SDC: - switch (ctrl) { - case CTRL_SYNC: - return RES_OK; - case GET_SECTOR_COUNT: - *((DWORD *)buff) = sdcGetCardCapacity(&SDCD1); - return RES_OK; - case GET_SECTOR_SIZE: - *((WORD *)buff) = SDC_BLOCK_SIZE; - return RES_OK; - case GET_BLOCK_SIZE: - *((DWORD *)buff) = 256; /* 512b blocks in one erase block */ - return RES_OK; - default: - return RES_PARERR; - } -#endif - } - return RES_PARERR; -} - -DWORD get_fattime(void) { -#if HAL_USE_RTC - return rtcGetTimeFat(&RTCD1); -#else - return ((uint32_t)0 | (1 << 16)) | (1 << 21); /* wrong but valid time */ -#endif -} - - - diff --git a/os/various/fatfs_bindings/fatfs.mk b/os/various/fatfs_bindings/fatfs.mk index 9f80da3b6..1bbdc254f 100644 --- a/os/various/fatfs_bindings/fatfs.mk +++ b/os/various/fatfs_bindings/fatfs.mk @@ -1,6 +1,6 @@ # FATFS files. -FATFSSRC = ${CHIBIOS}/various/fatfs_bindings/fatfs_diskio.c \ - ${CHIBIOS}/various/fatfs_bindings/fatfs_syscall.c \ +FATFSSRC = ${CHIBIOS}/os/various/fatfs_bindings/fatfs_diskio.c \ + ${CHIBIOS}/os/various/fatfs_bindings/fatfs_syscall.c \ ${CHIBIOS}/ext/fatfs/src/ff.c \ ${CHIBIOS}/ext/fatfs/src/option/ccsbcs.c \ diff --git a/os/various/fatfs_bindings/fatfs_syscall.c b/os/various/fatfs_bindings/fatfs_syscall.c index dbfb264b6..642b05fb3 100644 --- a/os/various/fatfs_bindings/fatfs_syscall.c +++ b/os/various/fatfs_bindings/fatfs_syscall.c @@ -32,7 +32,9 @@ MEMORYPOOL_DECL(fs_sem_pool, sizeof(Semaphore), chCoreAlloc); /*------------------------------------------------------------------------*/ /* Create a Synchronization Object */ /*------------------------------------------------------------------------*/ -int ff_cre_syncobj(_SYNC_t *sobj) { +int ff_cre_syncobj(BYTE vol, _SYNC_t *sobj) { + + (void)vol; *sobj = chPoolAlloc(&fs_sem_pool); if (*sobj == NULL) @@ -56,14 +58,14 @@ int ff_del_syncobj(_SYNC_t sobj) { /*------------------------------------------------------------------------*/ int ff_req_grant(_SYNC_t sobj) { - msg_t msg = chSemWaitTimeout(sobj, (systick_t)_FS_TIMEOUT); + msg_t msg = chSemWaitTimeout(sobj, (systime_t)_FS_TIMEOUT); return msg == RDY_OK; } /*------------------------------------------------------------------------*/ /* Release Grant to Access the Volume */ /*------------------------------------------------------------------------*/ -void ff_rel_grant(_SYNC_t sob) { +void ff_rel_grant(_SYNC_t sobj) { chSemSignal(sobj); } -- cgit v1.2.3