From c2a27f3e7c5700be2eb2f29bcfb677241f62703e Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Fri, 27 Jun 2014 16:16:42 +0200 Subject: [PATCH] working implementation with gfx syscalls --- src/gfile/fatfs/fatfs.mk | 3 +- src/gfile/fatfs/src/diskio.c | 236 ------------------ src/gfile/fatfs/src/ffconf.h | 8 +- .../{chibios_fatfs_syscall.c => syscall.c} | 73 +++--- 4 files changed, 39 insertions(+), 281 deletions(-) delete mode 100644 src/gfile/fatfs/src/diskio.c rename src/gfile/fatfs/src/{chibios_fatfs_syscall.c => syscall.c} (53%) diff --git a/src/gfile/fatfs/fatfs.mk b/src/gfile/fatfs/fatfs.mk index 279ae56f..0b540a41 100644 --- a/src/gfile/fatfs/fatfs.mk +++ b/src/gfile/fatfs/fatfs.mk @@ -1,6 +1,7 @@ GFXSRC += $(GFXLIB)/src/gfile/fatfs/src/ff.c \ $(GFXLIB)/src/gfile/fatfs/src/chibios_fatfs_diskio.c \ - $(GFXLIB)/src/gfile/fatfs/src/chibios_fatfs_syscall.c + $(GFXLIB)/src/gfile/fatfs/src/syscall.c + GFXINC += $(GFXLIB)/src/gfile/fatfs/src diff --git a/src/gfile/fatfs/src/diskio.c b/src/gfile/fatfs/src/diskio.c deleted file mode 100644 index 64194eb6..00000000 --- a/src/gfile/fatfs/src/diskio.c +++ /dev/null @@ -1,236 +0,0 @@ -/*-----------------------------------------------------------------------*/ -/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2013 */ -/*-----------------------------------------------------------------------*/ -/* If a working storage control module is available, it should be */ -/* attached to the FatFs via a glue function rather than modifying it. */ -/* This is an example of glue functions to attach various exsisting */ -/* storage control module to the FatFs module with a defined API. */ -/*-----------------------------------------------------------------------*/ - -#include "diskio.h" /* FatFs lower layer API */ -#include "usbdisk.h" /* Example: USB drive control */ -#include "atadrive.h" /* Example: ATA drive control */ -#include "sdcard.h" /* Example: MMC/SDC contorl */ - -/* Definitions of physical drive number for each media */ -#define ATA 0 -#define MMC 1 -#define USB 2 - - -/*-----------------------------------------------------------------------*/ -/* Inidialize a Drive */ -/*-----------------------------------------------------------------------*/ - -DSTATUS disk_initialize ( - BYTE pdrv /* Physical drive nmuber (0..) */ -) -{ - DSTATUS stat; - int result; - - switch (pdrv) { - case ATA : - result = ATA_disk_initialize(); - - // translate the reslut code here - - return stat; - - case MMC : - result = MMC_disk_initialize(); - - // translate the reslut code here - - return stat; - - case USB : - result = USB_disk_initialize(); - - // translate the reslut code here - - return stat; - } - return STA_NOINIT; -} - - - -/*-----------------------------------------------------------------------*/ -/* Get Disk Status */ -/*-----------------------------------------------------------------------*/ - -DSTATUS disk_status ( - BYTE pdrv /* Physical drive nmuber (0..) */ -) -{ - DSTATUS stat; - int result; - - switch (pdrv) { - case ATA : - result = ATA_disk_status(); - - // translate the reslut code here - - return stat; - - case MMC : - result = MMC_disk_status(); - - // translate the reslut code here - - return stat; - - case USB : - result = USB_disk_status(); - - // translate the reslut code here - - return stat; - } - return STA_NOINIT; -} - - - -/*-----------------------------------------------------------------------*/ -/* Read Sector(s) */ -/*-----------------------------------------------------------------------*/ - -DRESULT disk_read ( - BYTE pdrv, /* Physical drive nmuber (0..) */ - BYTE *buff, /* Data buffer to store read data */ - DWORD sector, /* Sector address (LBA) */ - UINT count /* Number of sectors to read (1..128) */ -) -{ - DRESULT res; - int result; - - switch (pdrv) { - case ATA : - // translate the arguments here - - result = ATA_disk_read(buff, sector, count); - - // translate the reslut code here - - return res; - - case MMC : - // translate the arguments here - - result = MMC_disk_read(buff, sector, count); - - // translate the reslut code here - - return res; - - case USB : - // translate the arguments here - - result = USB_disk_read(buff, sector, count); - - // translate the reslut code here - - return res; - } - return RES_PARERR; -} - - - -/*-----------------------------------------------------------------------*/ -/* Write Sector(s) */ -/*-----------------------------------------------------------------------*/ - -#if _USE_WRITE -DRESULT disk_write ( - BYTE pdrv, /* Physical drive nmuber (0..) */ - const BYTE *buff, /* Data to be written */ - DWORD sector, /* Sector address (LBA) */ - UINT count /* Number of sectors to write (1..128) */ -) -{ - DRESULT res; - int result; - - switch (pdrv) { - case ATA : - // translate the arguments here - - result = ATA_disk_write(buff, sector, count); - - // translate the reslut code here - - return res; - - case MMC : - // translate the arguments here - - result = MMC_disk_write(buff, sector, count); - - // translate the reslut code here - - return res; - - case USB : - // translate the arguments here - - result = USB_disk_write(buff, sector, count); - - // translate the reslut code here - - return res; - } - return RES_PARERR; -} -#endif - - -/*-----------------------------------------------------------------------*/ -/* Miscellaneous Functions */ -/*-----------------------------------------------------------------------*/ - -#if _USE_IOCTL -DRESULT disk_ioctl ( - BYTE pdrv, /* Physical drive nmuber (0..) */ - BYTE cmd, /* Control code */ - void *buff /* Buffer to send/receive control data */ -) -{ - DRESULT res; - int result; - - switch (pdrv) { - case ATA : - // pre-process here - - result = ATA_disk_ioctl(cmd, buff); - - // post-process here - - return res; - - case MMC : - // pre-process here - - result = MMC_disk_ioctl(cmd, buff); - - // post-process here - - return res; - - case USB : - // pre-process here - - result = USB_disk_ioctl(cmd, buff); - - // post-process here - - return res; - } - return RES_PARERR; -} -#endif diff --git a/src/gfile/fatfs/src/ffconf.h b/src/gfile/fatfs/src/ffconf.h index 72fc6143..aec765a4 100644 --- a/src/gfile/fatfs/src/ffconf.h +++ b/src/gfile/fatfs/src/ffconf.h @@ -5,7 +5,6 @@ #ifndef _FFCONF #define _FFCONF 8051 /* Revision ID */ - /*---------------------------------------------------------------------------/ / Functions and Buffer Configurations /---------------------------------------------------------------------------*/ @@ -189,9 +188,12 @@ / with file lock control. This feature uses bss _FS_LOCK * 12 bytes. */ -#define _FS_REENTRANT 0 /* 0:Disable or 1:Enable */ +#define _FS_REENTRANT 1 /* 0:Disable or 1:Enable */ +#if _FS_REENTRANT + #include "gfx.h" +#endif #define _FS_TIMEOUT 1000 /* Timeout period in unit of time tick */ -#define _SYNC_t HANDLE /* O/S dependent sync object type. e.g. HANDLE, OS_EVENT*, ID, SemaphoreHandle_t and etc.. */ +#define _SYNC_t gfxSem /* O/S dependent sync object type. e.g. HANDLE, OS_EVENT*, ID, SemaphoreHandle_t and etc.. */ /* The _FS_REENTRANT option switches the re-entrancy (thread safe) of the FatFs module. / / 0: Disable re-entrancy. _FS_TIMEOUT and _SYNC_t have no effect. diff --git a/src/gfile/fatfs/src/chibios_fatfs_syscall.c b/src/gfile/fatfs/src/syscall.c similarity index 53% rename from src/gfile/fatfs/src/chibios_fatfs_syscall.c rename to src/gfile/fatfs/src/syscall.c index a42cbcff..ccc22bdb 100644 --- a/src/gfile/fatfs/src/chibios_fatfs_syscall.c +++ b/src/gfile/fatfs/src/syscall.c @@ -1,67 +1,57 @@ /* - ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio + * 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 + */ - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -/*------------------------------------------------------------------------*/ -/* Sample code of OS dependent controls for FatFs R0.08b */ -/* (C)ChaN, 2011 */ -/*------------------------------------------------------------------------*/ - -#include "ch.h" +#include "gfx.h" #include "ff.h" #if _FS_REENTRANT + /*------------------------------------------------------------------------*/ /* Static array of Synchronization Objects */ /*------------------------------------------------------------------------*/ -static Semaphore ff_sem[_VOLUMES]; +static gfxSem ff_sem[_VOLUMES]; /*------------------------------------------------------------------------*/ /* Create a Synchronization Object */ /*------------------------------------------------------------------------*/ -int ff_cre_syncobj(BYTE vol, _SYNC_t *sobj) { +int ff_cre_syncobj(BYTE vol, _SYNC_t *sobj) +{ + *sobj = ff_sem[vol]; + gfxSemInit(sobj, 1, MAX_SEMAPHORE_COUNT); - *sobj = &ff_sem[vol]; - chSemInit(*sobj, 1); - return TRUE; + return 1; } /*------------------------------------------------------------------------*/ /* Delete a Synchronization Object */ /*------------------------------------------------------------------------*/ -int ff_del_syncobj(_SYNC_t sobj) { +int ff_del_syncobj(_SYNC_t sobj) +{ + gfxSemDestroy( (gfxSem*)&sobj ); - chSemReset(sobj, 0); - return TRUE; + return 1; } /*------------------------------------------------------------------------*/ /* Request Grant to Access the Volume */ /*------------------------------------------------------------------------*/ -int ff_req_grant(_SYNC_t sobj) { - - msg_t msg = chSemWaitTimeout(sobj, (systime_t)_FS_TIMEOUT); - return msg == RDY_OK; +int ff_req_grant(_SYNC_t sobj) +{ + 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) { - - chSemSignal(sobj); +void ff_rel_grant(_SYNC_t sobj) +{ + gfxSemSignal( (gfxSem*)&sobj ); } #endif /* _FS_REENTRANT */ @@ -69,16 +59,17 @@ void ff_rel_grant(_SYNC_t sobj) { /*------------------------------------------------------------------------*/ /* Allocate a memory block */ /*------------------------------------------------------------------------*/ -void *ff_memalloc(UINT size) { - - return chHeapAlloc(NULL, size); +void *ff_memalloc(UINT size) +{ + return gfxAlloc( (size_t)size ); } /*------------------------------------------------------------------------*/ /* Free a memory block */ /*------------------------------------------------------------------------*/ -void ff_memfree(void *mblock) { - - chHeapFree(mblock); +void ff_memfree(void *mblock) +{ + gfxFree(mblock); } #endif /* _USE_LFN == 3 */ +