Fatfs Cleanup
This commit is contained in:
parent
c2a27f3e7c
commit
a9f1520e02
10 changed files with 433 additions and 413 deletions
|
@ -219,7 +219,7 @@
|
||||||
// #define GFILE_ALLOW_FLOATS FALSE
|
// #define GFILE_ALLOW_FLOATS FALSE
|
||||||
// #define GFILE_ALLOW_DEVICESPECIFIC FALSE
|
// #define GFILE_ALLOW_DEVICESPECIFIC FALSE
|
||||||
// #define GFILE_MAX_GFILES 3
|
// #define GFILE_MAX_GFILES 3
|
||||||
//#define GFILE_NEED_AUTOMOUNT FALSE
|
//#define GFILE_NEED_NOAUTOMOUNT FALSE
|
||||||
|
|
||||||
//#define GFILE_NEED_MEMFS FALSE
|
//#define GFILE_NEED_MEMFS FALSE
|
||||||
//#define GFILE_NEED_ROMFS FALSE
|
//#define GFILE_NEED_ROMFS FALSE
|
||||||
|
|
20
src/gfile/fatfs/fatfs.c
Normal file
20
src/gfile/fatfs/fatfs.c
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
/*
|
||||||
|
* This file is subject to the terms of the GFX License. If a copy of
|
||||||
|
* the license was not distributed with this file, you can obtain one at:
|
||||||
|
*
|
||||||
|
* http://ugfx.org/license.html
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file src/gfile/fatfs/fatfs.c
|
||||||
|
* @brief GFILE FATFS wrapper.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "gfx.h"
|
||||||
|
|
||||||
|
#if GFX_USE_GFILE && GFILE_NEED_FATFS
|
||||||
|
|
||||||
|
#include "src/ff.c"
|
||||||
|
|
||||||
|
#endif // GFX_USE_GFILE && GFILE_NEED_FATFS
|
|
@ -1,6 +1,6 @@
|
||||||
GFXSRC += $(GFXLIB)/src/gfile/fatfs/src/ff.c \
|
GFXSRC += $(GFXLIB)/src/gfile/fatfs/fatfs.c \
|
||||||
$(GFXLIB)/src/gfile/fatfs/src/chibios_fatfs_diskio.c \
|
$(GFXLIB)/src/gfile/fatfs/fatfs_syscall.c \
|
||||||
$(GFXLIB)/src/gfile/fatfs/src/syscall.c
|
$(GFXLIB)/src/gfile/fatfs/fatfs_chibios_diskio.c
|
||||||
|
|
||||||
|
|
||||||
GFXINC += $(GFXLIB)/src/gfile/fatfs/src
|
GFXINC += $(GFXLIB)/src/gfile/fatfs/src
|
||||||
|
|
|
@ -1,254 +1,257 @@
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2007 */
|
/* 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 */
|
/* 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. */
|
/* disk I/O modules and attach it to FatFs module with common interface. */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "ch.h"
|
#include "gfx.h"
|
||||||
#include "hal.h"
|
|
||||||
#include "ffconf.h"
|
#if GFX_USE_GFILE && GFILE_NEED_FATFS && GFX_USE_OS_CHIBIOS
|
||||||
#include "diskio.h"
|
|
||||||
|
#include "ffconf.h"
|
||||||
#if HAL_USE_MMC_SPI && HAL_USE_SDC
|
#include "diskio.h"
|
||||||
#error "cannot specify both MMC_SPI and SDC drivers"
|
|
||||||
#endif
|
#if HAL_USE_MMC_SPI && HAL_USE_SDC
|
||||||
|
#error "cannot specify both MMC_SPI and SDC drivers"
|
||||||
#if HAL_USE_MMC_SPI
|
#endif
|
||||||
extern MMCDriver MMCD1;
|
|
||||||
#elif HAL_USE_SDC
|
#if HAL_USE_MMC_SPI
|
||||||
extern SDCDriver SDCD1;
|
extern MMCDriver MMCD1;
|
||||||
#else
|
#elif HAL_USE_SDC
|
||||||
#error "MMC_SPI or SDC driver must be specified"
|
extern SDCDriver SDCD1;
|
||||||
#endif
|
#else
|
||||||
|
#error "MMC_SPI or SDC driver must be specified"
|
||||||
#if HAL_USE_RTC
|
#endif
|
||||||
#include "chrtclib.h"
|
|
||||||
extern RTCDriver RTCD1;
|
#if HAL_USE_RTC
|
||||||
#endif
|
#include "chrtclib.h"
|
||||||
|
extern RTCDriver RTCD1;
|
||||||
/*-----------------------------------------------------------------------*/
|
#endif
|
||||||
/* Correspondence between physical drive number and physical drive. */
|
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
#define MMC 0
|
/* Correspondence between physical drive number and physical drive. */
|
||||||
#define SDC 0
|
|
||||||
|
#define MMC 0
|
||||||
|
#define SDC 0
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
/* Inidialize a Drive */
|
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
DSTATUS disk_initialize (
|
/* Inidialize a Drive */
|
||||||
BYTE drv /* Physical drive nmuber (0..) */
|
|
||||||
)
|
DSTATUS disk_initialize (
|
||||||
{
|
BYTE drv /* Physical drive nmuber (0..) */
|
||||||
DSTATUS stat;
|
)
|
||||||
|
{
|
||||||
switch (drv) {
|
DSTATUS stat;
|
||||||
#if HAL_USE_MMC_SPI
|
|
||||||
case MMC:
|
switch (drv) {
|
||||||
stat = 0;
|
#if HAL_USE_MMC_SPI
|
||||||
/* It is initialized externally, just reads the status.*/
|
case MMC:
|
||||||
if (blkGetDriverState(&MMCD1) != BLK_READY)
|
stat = 0;
|
||||||
stat |= STA_NOINIT;
|
/* It is initialized externally, just reads the status.*/
|
||||||
if (mmcIsWriteProtected(&MMCD1))
|
if (blkGetDriverState(&MMCD1) != BLK_READY)
|
||||||
stat |= STA_PROTECT;
|
stat |= STA_NOINIT;
|
||||||
return stat;
|
if (mmcIsWriteProtected(&MMCD1))
|
||||||
#else
|
stat |= STA_PROTECT;
|
||||||
case SDC:
|
return stat;
|
||||||
stat = 0;
|
#else
|
||||||
/* It is initialized externally, just reads the status.*/
|
case SDC:
|
||||||
if (blkGetDriverState(&SDCD1) != BLK_READY)
|
stat = 0;
|
||||||
stat |= STA_NOINIT;
|
/* It is initialized externally, just reads the status.*/
|
||||||
if (sdcIsWriteProtected(&SDCD1))
|
if (blkGetDriverState(&SDCD1) != BLK_READY)
|
||||||
stat |= STA_PROTECT;
|
stat |= STA_NOINIT;
|
||||||
return stat;
|
if (sdcIsWriteProtected(&SDCD1))
|
||||||
#endif
|
stat |= STA_PROTECT;
|
||||||
}
|
return stat;
|
||||||
return STA_NODISK;
|
#endif
|
||||||
}
|
}
|
||||||
|
return STA_NODISK;
|
||||||
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
/* Return Disk Status */
|
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
DSTATUS disk_status (
|
/* Return Disk Status */
|
||||||
BYTE drv /* Physical drive nmuber (0..) */
|
|
||||||
)
|
DSTATUS disk_status (
|
||||||
{
|
BYTE drv /* Physical drive nmuber (0..) */
|
||||||
DSTATUS stat;
|
)
|
||||||
|
{
|
||||||
switch (drv) {
|
DSTATUS stat;
|
||||||
#if HAL_USE_MMC_SPI
|
|
||||||
case MMC:
|
switch (drv) {
|
||||||
stat = 0;
|
#if HAL_USE_MMC_SPI
|
||||||
/* It is initialized externally, just reads the status.*/
|
case MMC:
|
||||||
if (blkGetDriverState(&MMCD1) != BLK_READY)
|
stat = 0;
|
||||||
stat |= STA_NOINIT;
|
/* It is initialized externally, just reads the status.*/
|
||||||
if (mmcIsWriteProtected(&MMCD1))
|
if (blkGetDriverState(&MMCD1) != BLK_READY)
|
||||||
stat |= STA_PROTECT;
|
stat |= STA_NOINIT;
|
||||||
return stat;
|
if (mmcIsWriteProtected(&MMCD1))
|
||||||
#else
|
stat |= STA_PROTECT;
|
||||||
case SDC:
|
return stat;
|
||||||
stat = 0;
|
#else
|
||||||
/* It is initialized externally, just reads the status.*/
|
case SDC:
|
||||||
if (blkGetDriverState(&SDCD1) != BLK_READY)
|
stat = 0;
|
||||||
stat |= STA_NOINIT;
|
/* It is initialized externally, just reads the status.*/
|
||||||
if (sdcIsWriteProtected(&SDCD1))
|
if (blkGetDriverState(&SDCD1) != BLK_READY)
|
||||||
stat |= STA_PROTECT;
|
stat |= STA_NOINIT;
|
||||||
return stat;
|
if (sdcIsWriteProtected(&SDCD1))
|
||||||
#endif
|
stat |= STA_PROTECT;
|
||||||
}
|
return stat;
|
||||||
return STA_NODISK;
|
#endif
|
||||||
}
|
}
|
||||||
|
return STA_NODISK;
|
||||||
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
/* Read Sector(s) */
|
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
DRESULT disk_read (
|
/* Read Sector(s) */
|
||||||
BYTE drv, /* Physical drive nmuber (0..) */
|
|
||||||
BYTE *buff, /* Data buffer to store read data */
|
DRESULT disk_read (
|
||||||
DWORD sector, /* Sector address (LBA) */
|
BYTE drv, /* Physical drive nmuber (0..) */
|
||||||
UINT count /* Number of sectors to read (1..255) */
|
BYTE *buff, /* Data buffer to store read data */
|
||||||
)
|
DWORD sector, /* Sector address (LBA) */
|
||||||
{
|
UINT count /* Number of sectors to read (1..255) */
|
||||||
switch (drv) {
|
)
|
||||||
#if HAL_USE_MMC_SPI
|
{
|
||||||
case MMC:
|
switch (drv) {
|
||||||
if (blkGetDriverState(&MMCD1) != BLK_READY)
|
#if HAL_USE_MMC_SPI
|
||||||
return RES_NOTRDY;
|
case MMC:
|
||||||
if (mmcStartSequentialRead(&MMCD1, sector))
|
if (blkGetDriverState(&MMCD1) != BLK_READY)
|
||||||
return RES_ERROR;
|
return RES_NOTRDY;
|
||||||
while (count > 0) {
|
if (mmcStartSequentialRead(&MMCD1, sector))
|
||||||
if (mmcSequentialRead(&MMCD1, buff))
|
return RES_ERROR;
|
||||||
return RES_ERROR;
|
while (count > 0) {
|
||||||
buff += MMCSD_BLOCK_SIZE;
|
if (mmcSequentialRead(&MMCD1, buff))
|
||||||
count--;
|
return RES_ERROR;
|
||||||
}
|
buff += MMCSD_BLOCK_SIZE;
|
||||||
if (mmcStopSequentialRead(&MMCD1))
|
count--;
|
||||||
return RES_ERROR;
|
}
|
||||||
return RES_OK;
|
if (mmcStopSequentialRead(&MMCD1))
|
||||||
#else
|
return RES_ERROR;
|
||||||
case SDC:
|
return RES_OK;
|
||||||
if (blkGetDriverState(&SDCD1) != BLK_READY)
|
#else
|
||||||
return RES_NOTRDY;
|
case SDC:
|
||||||
if (sdcRead(&SDCD1, sector, buff, count))
|
if (blkGetDriverState(&SDCD1) != BLK_READY)
|
||||||
return RES_ERROR;
|
return RES_NOTRDY;
|
||||||
return RES_OK;
|
if (sdcRead(&SDCD1, sector, buff, count))
|
||||||
#endif
|
return RES_ERROR;
|
||||||
}
|
return RES_OK;
|
||||||
return RES_PARERR;
|
#endif
|
||||||
}
|
}
|
||||||
|
return RES_PARERR;
|
||||||
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
/* Write Sector(s) */
|
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
#if _READONLY == 0
|
/* Write Sector(s) */
|
||||||
DRESULT disk_write (
|
|
||||||
BYTE drv, /* Physical drive nmuber (0..) */
|
#if _READONLY == 0
|
||||||
const BYTE *buff, /* Data to be written */
|
DRESULT disk_write (
|
||||||
DWORD sector, /* Sector address (LBA) */
|
BYTE drv, /* Physical drive nmuber (0..) */
|
||||||
UINT count /* Number of sectors to write (1..255) */
|
const BYTE *buff, /* Data to be written */
|
||||||
)
|
DWORD sector, /* Sector address (LBA) */
|
||||||
{
|
UINT count /* Number of sectors to write (1..255) */
|
||||||
switch (drv) {
|
)
|
||||||
#if HAL_USE_MMC_SPI
|
{
|
||||||
case MMC:
|
switch (drv) {
|
||||||
if (blkGetDriverState(&MMCD1) != BLK_READY)
|
#if HAL_USE_MMC_SPI
|
||||||
return RES_NOTRDY;
|
case MMC:
|
||||||
if (mmcIsWriteProtected(&MMCD1))
|
if (blkGetDriverState(&MMCD1) != BLK_READY)
|
||||||
return RES_WRPRT;
|
return RES_NOTRDY;
|
||||||
if (mmcStartSequentialWrite(&MMCD1, sector))
|
if (mmcIsWriteProtected(&MMCD1))
|
||||||
return RES_ERROR;
|
return RES_WRPRT;
|
||||||
while (count > 0) {
|
if (mmcStartSequentialWrite(&MMCD1, sector))
|
||||||
if (mmcSequentialWrite(&MMCD1, buff))
|
return RES_ERROR;
|
||||||
return RES_ERROR;
|
while (count > 0) {
|
||||||
buff += MMCSD_BLOCK_SIZE;
|
if (mmcSequentialWrite(&MMCD1, buff))
|
||||||
count--;
|
return RES_ERROR;
|
||||||
}
|
buff += MMCSD_BLOCK_SIZE;
|
||||||
if (mmcStopSequentialWrite(&MMCD1))
|
count--;
|
||||||
return RES_ERROR;
|
}
|
||||||
return RES_OK;
|
if (mmcStopSequentialWrite(&MMCD1))
|
||||||
#else
|
return RES_ERROR;
|
||||||
case SDC:
|
return RES_OK;
|
||||||
if (blkGetDriverState(&SDCD1) != BLK_READY)
|
#else
|
||||||
return RES_NOTRDY;
|
case SDC:
|
||||||
if (sdcWrite(&SDCD1, sector, buff, count))
|
if (blkGetDriverState(&SDCD1) != BLK_READY)
|
||||||
return RES_ERROR;
|
return RES_NOTRDY;
|
||||||
return RES_OK;
|
if (sdcWrite(&SDCD1, sector, buff, count))
|
||||||
#endif
|
return RES_ERROR;
|
||||||
}
|
return RES_OK;
|
||||||
return RES_PARERR;
|
#endif
|
||||||
}
|
}
|
||||||
#endif /* _READONLY */
|
return RES_PARERR;
|
||||||
|
}
|
||||||
|
#endif /* _READONLY */
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
/* Miscellaneous Functions */
|
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
DRESULT disk_ioctl (
|
/* Miscellaneous Functions */
|
||||||
BYTE drv, /* Physical drive nmuber (0..) */
|
|
||||||
BYTE ctrl, /* Control code */
|
DRESULT disk_ioctl (
|
||||||
void *buff /* Buffer to send/receive control data */
|
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 (drv) {
|
||||||
switch (ctrl) {
|
#if HAL_USE_MMC_SPI
|
||||||
case CTRL_SYNC:
|
case MMC:
|
||||||
return RES_OK;
|
switch (ctrl) {
|
||||||
case GET_SECTOR_SIZE:
|
case CTRL_SYNC:
|
||||||
*((WORD *)buff) = MMCSD_BLOCK_SIZE;
|
return RES_OK;
|
||||||
return RES_OK;
|
case GET_SECTOR_SIZE:
|
||||||
#if _USE_ERASE
|
*((WORD *)buff) = MMCSD_BLOCK_SIZE;
|
||||||
case CTRL_ERASE_SECTOR:
|
return RES_OK;
|
||||||
mmcErase(&MMCD1, *((DWORD *)buff), *((DWORD *)buff + 1));
|
#if _USE_ERASE
|
||||||
return RES_OK;
|
case CTRL_ERASE_SECTOR:
|
||||||
#endif
|
mmcErase(&MMCD1, *((DWORD *)buff), *((DWORD *)buff + 1));
|
||||||
default:
|
return RES_OK;
|
||||||
return RES_PARERR;
|
#endif
|
||||||
}
|
default:
|
||||||
#else
|
return RES_PARERR;
|
||||||
case SDC:
|
}
|
||||||
switch (ctrl) {
|
#else
|
||||||
case CTRL_SYNC:
|
case SDC:
|
||||||
return RES_OK;
|
switch (ctrl) {
|
||||||
case GET_SECTOR_COUNT:
|
case CTRL_SYNC:
|
||||||
*((DWORD *)buff) = mmcsdGetCardCapacity(&SDCD1);
|
return RES_OK;
|
||||||
return RES_OK;
|
case GET_SECTOR_COUNT:
|
||||||
case GET_SECTOR_SIZE:
|
*((DWORD *)buff) = mmcsdGetCardCapacity(&SDCD1);
|
||||||
*((WORD *)buff) = MMCSD_BLOCK_SIZE;
|
return RES_OK;
|
||||||
return RES_OK;
|
case GET_SECTOR_SIZE:
|
||||||
case GET_BLOCK_SIZE:
|
*((WORD *)buff) = MMCSD_BLOCK_SIZE;
|
||||||
*((DWORD *)buff) = 256; /* 512b blocks in one erase block */
|
return RES_OK;
|
||||||
return RES_OK;
|
case GET_BLOCK_SIZE:
|
||||||
#if _USE_ERASE
|
*((DWORD *)buff) = 256; /* 512b blocks in one erase block */
|
||||||
case CTRL_ERASE_SECTOR:
|
return RES_OK;
|
||||||
sdcErase(&SDCD1, *((DWORD *)buff), *((DWORD *)buff + 1));
|
#if _USE_ERASE
|
||||||
return RES_OK;
|
case CTRL_ERASE_SECTOR:
|
||||||
#endif
|
sdcErase(&SDCD1, *((DWORD *)buff), *((DWORD *)buff + 1));
|
||||||
default:
|
return RES_OK;
|
||||||
return RES_PARERR;
|
#endif
|
||||||
}
|
default:
|
||||||
#endif
|
return RES_PARERR;
|
||||||
}
|
}
|
||||||
return RES_PARERR;
|
#endif
|
||||||
}
|
}
|
||||||
|
return RES_PARERR;
|
||||||
DWORD get_fattime(void) {
|
}
|
||||||
#if HAL_USE_RTC
|
|
||||||
return rtcGetTimeFat(&RTCD1);
|
DWORD get_fattime(void) {
|
||||||
#else
|
#if HAL_USE_RTC
|
||||||
return ((uint32_t)0 | (1 << 16)) | (1 << 21); /* wrong but valid time */
|
return rtcGetTimeFat(&RTCD1);
|
||||||
#endif
|
#else
|
||||||
}
|
return ((uint32_t)0 | (1 << 16)) | (1 << 21); /* wrong but valid time */
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // GFX_USE_GFILE && GFILE_NEED_FATFS && GFX_USE_OS_CHIBIOS
|
||||||
|
|
||||||
|
|
|
@ -1,75 +1,80 @@
|
||||||
/*
|
/*
|
||||||
* This file is subject to the terms of the GFX License. If a copy of
|
* This file is subject to the terms of the GFX License. If a copy of
|
||||||
* the license was not distributed with this file, you can obtain one at:
|
* the license was not distributed with this file, you can obtain one at:
|
||||||
*
|
*
|
||||||
* http://ugfx.org/license.html
|
* http://ugfx.org/license.html
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "gfx.h"
|
#include "gfx.h"
|
||||||
#include "ff.h"
|
|
||||||
|
#if GFX_USE_GFILE && GFILE_NEED_FATFS
|
||||||
#if _FS_REENTRANT
|
|
||||||
|
#include "ff.h"
|
||||||
/*------------------------------------------------------------------------*/
|
|
||||||
/* Static array of Synchronization Objects */
|
#if _FS_REENTRANT
|
||||||
/*------------------------------------------------------------------------*/
|
|
||||||
static gfxSem ff_sem[_VOLUMES];
|
/*------------------------------------------------------------------------*/
|
||||||
|
/* Static array of Synchronization Objects */
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
/* Create a Synchronization Object */
|
static gfxSem ff_sem[_VOLUMES];
|
||||||
/*------------------------------------------------------------------------*/
|
|
||||||
int ff_cre_syncobj(BYTE vol, _SYNC_t *sobj)
|
/*------------------------------------------------------------------------*/
|
||||||
{
|
/* Create a Synchronization Object */
|
||||||
*sobj = ff_sem[vol];
|
/*------------------------------------------------------------------------*/
|
||||||
gfxSemInit(sobj, 1, MAX_SEMAPHORE_COUNT);
|
int ff_cre_syncobj(BYTE vol, _SYNC_t *sobj)
|
||||||
|
{
|
||||||
return 1;
|
*sobj = ff_sem[vol];
|
||||||
}
|
gfxSemInit(sobj, 1, MAX_SEMAPHORE_COUNT);
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
return 1;
|
||||||
/* Delete a Synchronization Object */
|
}
|
||||||
/*------------------------------------------------------------------------*/
|
|
||||||
int ff_del_syncobj(_SYNC_t sobj)
|
/*------------------------------------------------------------------------*/
|
||||||
{
|
/* Delete a Synchronization Object */
|
||||||
gfxSemDestroy( (gfxSem*)&sobj );
|
/*------------------------------------------------------------------------*/
|
||||||
|
int ff_del_syncobj(_SYNC_t sobj)
|
||||||
return 1;
|
{
|
||||||
}
|
gfxSemDestroy( (gfxSem*)&sobj );
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
return 1;
|
||||||
/* Request Grant to Access the Volume */
|
}
|
||||||
/*------------------------------------------------------------------------*/
|
|
||||||
int ff_req_grant(_SYNC_t sobj)
|
/*------------------------------------------------------------------------*/
|
||||||
{
|
/* Request Grant to Access the Volume */
|
||||||
if (gfxSemWait( (gfxSem*)&sobj, (delaytime_t)_FS_TIMEOUT) )
|
/*------------------------------------------------------------------------*/
|
||||||
return TRUE;
|
int ff_req_grant(_SYNC_t sobj)
|
||||||
return FALSE;
|
{
|
||||||
}
|
if (gfxSemWait( (gfxSem*)&sobj, (delaytime_t)_FS_TIMEOUT) )
|
||||||
|
return TRUE;
|
||||||
/*------------------------------------------------------------------------*/
|
return FALSE;
|
||||||
/* Release Grant to Access the Volume */
|
}
|
||||||
/*------------------------------------------------------------------------*/
|
|
||||||
void ff_rel_grant(_SYNC_t sobj)
|
/*------------------------------------------------------------------------*/
|
||||||
{
|
/* Release Grant to Access the Volume */
|
||||||
gfxSemSignal( (gfxSem*)&sobj );
|
/*------------------------------------------------------------------------*/
|
||||||
}
|
void ff_rel_grant(_SYNC_t sobj)
|
||||||
#endif /* _FS_REENTRANT */
|
{
|
||||||
|
gfxSemSignal( (gfxSem*)&sobj );
|
||||||
#if _USE_LFN == 3 /* LFN with a working buffer on the heap */
|
}
|
||||||
/*------------------------------------------------------------------------*/
|
#endif /* _FS_REENTRANT */
|
||||||
/* Allocate a memory block */
|
|
||||||
/*------------------------------------------------------------------------*/
|
#if _USE_LFN == 3 /* LFN with a working buffer on the heap */
|
||||||
void *ff_memalloc(UINT size)
|
/*------------------------------------------------------------------------*/
|
||||||
{
|
/* Allocate a memory block */
|
||||||
return gfxAlloc( (size_t)size );
|
/*------------------------------------------------------------------------*/
|
||||||
}
|
void *ff_memalloc(UINT size)
|
||||||
|
{
|
||||||
/*------------------------------------------------------------------------*/
|
return gfxAlloc( (size_t)size );
|
||||||
/* Free a memory block */
|
}
|
||||||
/*------------------------------------------------------------------------*/
|
|
||||||
void ff_memfree(void *mblock)
|
/*------------------------------------------------------------------------*/
|
||||||
{
|
/* Free a memory block */
|
||||||
gfxFree(mblock);
|
/*------------------------------------------------------------------------*/
|
||||||
}
|
void ff_memfree(void *mblock)
|
||||||
#endif /* _USE_LFN == 3 */
|
{
|
||||||
|
gfxFree(mblock);
|
||||||
|
}
|
||||||
|
#endif /* _USE_LFN == 3 */
|
||||||
|
|
||||||
|
#endif // GFX_USE_GFILE && GFILE_NEED_FATFS
|
||||||
|
|
|
@ -477,35 +477,33 @@ bool_t gfileEOF(GFILE *f) {
|
||||||
return f->vmt->eof(f);
|
return f->vmt->eof(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if GFILE_NEED_FATFS
|
bool_t gfileMount(char fs, const char* drive) {
|
||||||
bool_t gfileMount(char fs, const char* drive) {
|
const GFILEVMT *p;
|
||||||
const GFILEVMT *p;
|
|
||||||
|
|
||||||
// Find the correct VMT
|
// Find the correct VMT
|
||||||
for(p = FsChain; p; p = p->next) {
|
for(p = FsChain; p; p = p->next) {
|
||||||
if (p->prefix == fs) {
|
if (p->prefix == fs) {
|
||||||
if (!p->mount)
|
if (!p->mount)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
return p->mount(drive);
|
return p->mount(drive);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
bool_t gfileUnmount(char fs, const char* drive) {
|
bool_t gfileUnmount(char fs, const char* drive) {
|
||||||
const GFILEVMT *p;
|
const GFILEVMT *p;
|
||||||
|
|
||||||
// Find the correct VMT
|
// Find the correct VMT
|
||||||
for(p = FsChain; p; p = p->next) {
|
for(p = FsChain; p; p = p->next) {
|
||||||
if (p->prefix == fs) {
|
if (p->prefix == fs) {
|
||||||
if (!p->mount)
|
if (!p->mount)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
return p->unmount(drive);
|
return p->unmount(drive);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
#endif
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
/********************************************************
|
/********************************************************
|
||||||
* String VMT routines
|
* String VMT routines
|
||||||
|
|
|
@ -56,20 +56,21 @@ static const GFILEVMT FsFatFSVMT = {
|
||||||
static bool_t fatfs_mounted = FALSE;
|
static bool_t fatfs_mounted = FALSE;
|
||||||
static FATFS fatfs_fs;
|
static FATFS fatfs_fs;
|
||||||
|
|
||||||
static void _flags2mode(GFILE* f, BYTE* mode)
|
static BYTE fatfs_flags2mode(GFILE* f)
|
||||||
{
|
{
|
||||||
*mode = 0;
|
BYTE mode = 0;
|
||||||
|
|
||||||
if (f->flags & GFILEFLG_READ)
|
if (f->flags & GFILEFLG_READ)
|
||||||
*mode |= FA_READ;
|
mode |= FA_READ;
|
||||||
if (f->flags & GFILEFLG_WRITE)
|
if (f->flags & GFILEFLG_WRITE)
|
||||||
*mode |= FA_WRITE;
|
mode |= FA_WRITE;
|
||||||
if (f->flags & GFILEFLG_APPEND)
|
if (f->flags & GFILEFLG_APPEND)
|
||||||
*mode |= 0; // ToDo
|
mode |= 0; // ToDo
|
||||||
if (f->flags & GFILEFLG_TRUNC)
|
if (f->flags & GFILEFLG_TRUNC)
|
||||||
*mode |= FA_CREATE_ALWAYS;
|
mode |= FA_CREATE_ALWAYS;
|
||||||
|
|
||||||
/* ToDo - Complete */
|
/* ToDo - Complete */
|
||||||
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool_t fatfsDel(const char* fname)
|
static bool_t fatfsDel(const char* fname)
|
||||||
|
@ -121,19 +122,16 @@ static bool_t fatfsRename(const char* oldname, const char* newname)
|
||||||
static bool_t fatfsOpen(GFILE* f, const char* fname)
|
static bool_t fatfsOpen(GFILE* f, const char* fname)
|
||||||
{
|
{
|
||||||
FIL* fd;
|
FIL* fd;
|
||||||
BYTE mode;
|
|
||||||
FRESULT ferr;
|
#if !GFILE_NEED_NOAUTOMOUNT
|
||||||
/*
|
if (!fatfs_mounted && !fatfsMount(""))
|
||||||
if (!fatfs_mounted && !fatfsMount(""))
|
return FALSE;
|
||||||
return FALSE;
|
#endif
|
||||||
*/
|
|
||||||
if (!(fd = gfxAlloc(sizeof(FIL))))
|
if (!(fd = gfxAlloc(sizeof(FIL))))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
_flags2mode(f, &mode);
|
if (f_open(fd, fname, fatfs_flags2mode(f)) != FR_OK) {
|
||||||
|
|
||||||
ferr = f_open(fd, fname, mode);
|
|
||||||
if (ferr != FR_OK) {
|
|
||||||
gfxFree(fd);
|
gfxFree(fd);
|
||||||
f->obj = 0;
|
f->obj = 0;
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ static const GFILEVMT FsNativeVMT = {
|
||||||
#undef GFILE_CHAINHEAD
|
#undef GFILE_CHAINHEAD
|
||||||
#define GFILE_CHAINHEAD &FsNativeVMT
|
#define GFILE_CHAINHEAD &FsNativeVMT
|
||||||
|
|
||||||
static void flags2mode(char *buf, uint16_t flags) {
|
static void Native_flags2mode(char *buf, uint16_t flags) {
|
||||||
if (flags & GFILEFLG_MUSTEXIST)
|
if (flags & GFILEFLG_MUSTEXIST)
|
||||||
*buf = 'r';
|
*buf = 'r';
|
||||||
else if (flags & GFILEFLG_APPEND)
|
else if (flags & GFILEFLG_APPEND)
|
||||||
|
@ -90,7 +90,7 @@ static bool_t NativeOpen(GFILE *f, const char *fname) {
|
||||||
FILE *fd;
|
FILE *fd;
|
||||||
char mode[5];
|
char mode[5];
|
||||||
|
|
||||||
flags2mode(mode, f->flags);
|
Native_flags2mode(mode, f->flags);
|
||||||
if (!(fd = fopen(fname, mode)))
|
if (!(fd = fopen(fname, mode)))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
f->obj = (void *)fd;
|
f->obj = (void *)fd;
|
||||||
|
|
|
@ -197,6 +197,35 @@ extern "C" {
|
||||||
*/
|
*/
|
||||||
bool_t gfileEOF(GFILE *f);
|
bool_t gfileEOF(GFILE *f);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Mount a logical drive (aka partition)
|
||||||
|
*
|
||||||
|
* @details Not supported by every file system
|
||||||
|
* @details Currently just one drive at one is supported.
|
||||||
|
*
|
||||||
|
* @param[in] fs The file system (F for FatFS)
|
||||||
|
* @param[in] drive The logical drive prefix
|
||||||
|
*
|
||||||
|
* @return TRUE on success, FALSE otherwise
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
bool_t gfileMount(char fs, const char *drive);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Unmount a logical drive (aka partition)
|
||||||
|
*
|
||||||
|
* @details Does have no effect if @p gfileMount() as been called before hand
|
||||||
|
*
|
||||||
|
* @param[in] fs The file system (F for FatFS)
|
||||||
|
* @param[in] drive The logical drive prefix
|
||||||
|
*
|
||||||
|
* @return TRUE on success, FALSE otherwise
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
bool_t gfileUnmount(char fs, const char *drive);
|
||||||
|
|
||||||
#if GFILE_NEED_CHIBIOSFS && GFX_USE_OS_CHIBIOS
|
#if GFILE_NEED_CHIBIOSFS && GFX_USE_OS_CHIBIOS
|
||||||
GFILE * gfileOpenBaseFileStream(void *BaseFileStreamPtr, const char *mode);
|
GFILE * gfileOpenBaseFileStream(void *BaseFileStreamPtr, const char *mode);
|
||||||
#endif
|
#endif
|
||||||
|
@ -205,37 +234,6 @@ extern "C" {
|
||||||
GFILE * gfileOpenMemory(void *memptr, const char *mode);
|
GFILE * gfileOpenMemory(void *memptr, const char *mode);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if GFILE_NEED_FATFS
|
|
||||||
/**
|
|
||||||
* @brief Mount a logical drive (aka partition)
|
|
||||||
*
|
|
||||||
* @details Not supported by every file system
|
|
||||||
* @details Currently just one drive at one is supported.
|
|
||||||
*
|
|
||||||
* @param[in] fs The file system (F for FatFS)
|
|
||||||
* @param[in] drive The logical drive prefix
|
|
||||||
*
|
|
||||||
* @return TRUE on success, FALSE otherwise
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
bool_t gfileMount(char fs, const char *drive);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Unmount a logical drive (aka partition)
|
|
||||||
*
|
|
||||||
* @details Does have no effect if @p gfileMount() as been called before hand
|
|
||||||
*
|
|
||||||
* @param[in] fs The file system (F for FatFS)
|
|
||||||
* @param[in] drive The logical drive prefix
|
|
||||||
*
|
|
||||||
* @return TRUE on success, FALSE otherwise
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
bool_t gfileUnmount(char fs, const char *drive);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if GFILE_NEED_PRINTG
|
#if GFILE_NEED_PRINTG
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
|
|
@ -21,16 +21,14 @@
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* @brief Should the filesystem be mounted automatically
|
* @brief Should the filesystem not be mounted automatically
|
||||||
* @details The filesystem will be mounted automatically if the
|
* @details The filesystem is normally mounted automatically if the
|
||||||
* user does not do it manually.
|
* user does not do it manually. This option turns that off
|
||||||
|
* so the user must manually mount the file-system first.
|
||||||
* @details Defaults to FALSE
|
* @details Defaults to FALSE
|
||||||
*
|
|
||||||
* @note Only available for filesystems that actually implement a
|
|
||||||
* mounting routine.
|
|
||||||
*/
|
*/
|
||||||
#ifndef GFILE_NEED_AUTOMOUNT
|
#ifndef GFILE_NEED_NOAUTOMOUNT
|
||||||
#define GFILE_NEED_AUTOMOUNT FALSE
|
#define GFILE_NEED_NOAUTOMOUNT FALSE
|
||||||
#endif
|
#endif
|
||||||
/**
|
/**
|
||||||
* @brief Include printg, fprintg etc functions
|
* @brief Include printg, fprintg etc functions
|
||||||
|
|
Loading…
Add table
Reference in a new issue