From 8f6606141a673887385dcdfa7012d60aaa66d148 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 21 Jun 2019 15:33:10 +0800 Subject: [PATCH] fatfs: create separate ffsystem.c for host side testing --- components/fatfs/CMakeLists.txt | 2 +- components/fatfs/component.mk | 2 +- components/fatfs/diskio/diskio.c | 1 + .../fatfs/port/{ => freertos}/ffsystem.c | 40 +++++++--------- components/fatfs/port/linux/ffsystem.c | 46 +++++++++++++++++++ components/fatfs/src/ffconf.h | 2 + .../fatfs/test_fatfs_host/Makefile.files | 4 +- 7 files changed, 70 insertions(+), 27 deletions(-) rename components/fatfs/port/{ => freertos}/ffsystem.c (67%) create mode 100644 components/fatfs/port/linux/ffsystem.c diff --git a/components/fatfs/CMakeLists.txt b/components/fatfs/CMakeLists.txt index 05255a07c..2cd91bf00 100644 --- a/components/fatfs/CMakeLists.txt +++ b/components/fatfs/CMakeLists.txt @@ -3,7 +3,7 @@ idf_component_register(SRCS "diskio/diskio.c" "diskio/diskio_sdmmc.c" "diskio/diskio_wl.c" "src/ff.c" - "port/ffsystem.c" + "port/freertos/ffsystem.c" "src/ffunicode.c" "vfs/vfs_fat.c" "vfs/vfs_fat_sdmmc.c" diff --git a/components/fatfs/component.mk b/components/fatfs/component.mk index b3d696c05..bf33270c1 100644 --- a/components/fatfs/component.mk +++ b/components/fatfs/component.mk @@ -1,3 +1,3 @@ COMPONENT_ADD_INCLUDEDIRS := diskio vfs src -COMPONENT_SRCDIRS := diskio vfs port src +COMPONENT_SRCDIRS := diskio vfs port/freertos src COMPONENT_OBJEXCLUDE := src/diskio.o src/ffsystem.o diff --git a/components/fatfs/diskio/diskio.c b/components/fatfs/diskio/diskio.c index 47312a2be..c8075166d 100644 --- a/components/fatfs/diskio/diskio.c +++ b/components/fatfs/diskio/diskio.c @@ -10,6 +10,7 @@ #include #include +#include #include #include "diskio_impl.h" #include "ffconf.h" diff --git a/components/fatfs/port/ffsystem.c b/components/fatfs/port/freertos/ffsystem.c similarity index 67% rename from components/fatfs/port/ffsystem.c rename to components/fatfs/port/freertos/ffsystem.c index e1cbbbbf7..45a894de5 100644 --- a/components/fatfs/port/ffsystem.c +++ b/components/fatfs/port/freertos/ffsystem.c @@ -12,21 +12,15 @@ #include "esp_heap_caps.h" #endif - - -/*------------------------------------------------------------------------*/ -/* Allocate a memory block */ -/*------------------------------------------------------------------------*/ - -void* ff_memalloc ( /* Returns pointer to the allocated memory block (null on not enough core) */ - unsigned msize /* Number of bytes to allocate */ +void* ff_memalloc ( /* Returns pointer to the allocated memory block (null on not enough core) */ + unsigned msize /* Number of bytes to allocate */ ) { #ifdef CONFIG_FATFS_ALLOC_EXTRAM_FIRST - return heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT | MALLOC_CAP_SPIRAM, - MALLOC_CAP_DEFAULT | MALLOC_CAP_INTERNAL); + return heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT | MALLOC_CAP_SPIRAM, + MALLOC_CAP_DEFAULT | MALLOC_CAP_INTERNAL); #else - return malloc(msize); + return malloc(msize); #endif } @@ -36,16 +30,16 @@ void* ff_memalloc ( /* Returns pointer to the allocated memory block (null on no /*------------------------------------------------------------------------*/ void ff_memfree ( - void* mblock /* Pointer to the memory block to free (nothing to do for null) */ + void* mblock /* Pointer to the memory block to free (nothing to do for null) */ ) { - free(mblock); /* Free the memory block with POSIX API */ + free(mblock); /* Free the memory block with POSIX API */ } -#if FF_FS_REENTRANT /* Mutal exclusion */ +#if FF_FS_REENTRANT /* Mutal exclusion */ /*------------------------------------------------------------------------*/ /* Create a Synchronization Object */ @@ -56,9 +50,9 @@ void ff_memfree ( */ -int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object */ - BYTE vol, /* Corresponding volume (logical drive number) */ - FF_SYNC_t *sobj /* Pointer to return the created sync object */ +int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object */ + BYTE vol, /* Corresponding volume (logical drive number) */ + FF_SYNC_t *sobj /* Pointer to return the created sync object */ ) { *sobj = xSemaphoreCreateMutex(); @@ -74,8 +68,8 @@ int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object / the f_mount() function fails with FR_INT_ERR. */ -int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to an error */ - FF_SYNC_t sobj /* Sync object tied to the logical drive to be deleted */ +int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to an error */ + FF_SYNC_t sobj /* Sync object tied to the logical drive to be deleted */ ) { vSemaphoreDelete(sobj); @@ -90,8 +84,8 @@ int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to an error / When a 0 is returned, the file function fails with FR_TIMEOUT. */ -int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a grant */ - FF_SYNC_t sobj /* Sync object to wait */ +int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a grant */ + FF_SYNC_t sobj /* Sync object to wait */ ) { return (xSemaphoreTake(sobj, FF_FS_TIMEOUT) == pdTRUE) ? 1 : 0; @@ -105,10 +99,10 @@ int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a gran */ void ff_rel_grant ( - FF_SYNC_t sobj /* Sync object to be signaled */ + FF_SYNC_t sobj /* Sync object to be signaled */ ) { xSemaphoreGive(sobj); } -#endif +#endif // FF_FS_REENTRANT diff --git a/components/fatfs/port/linux/ffsystem.c b/components/fatfs/port/linux/ffsystem.c new file mode 100644 index 000000000..5013c8b12 --- /dev/null +++ b/components/fatfs/port/linux/ffsystem.c @@ -0,0 +1,46 @@ +/*------------------------------------------------------------------------*/ +/* OS Dependent Functions for FatFs */ +/* (C)ChaN, 2018 */ +/*------------------------------------------------------------------------*/ + + +#include "ff.h" +#include + +/* This is the implementation for host-side testing on Linux. + * Host-side tests are single threaded, so lock functionality isn't needed. + */ + +void* ff_memalloc(UINT msize) +{ + return malloc(msize); +} + +void ff_memfree(void* mblock) +{ + free(mblock); +} + +/* 1:Function succeeded, 0:Could not create the sync object */ +int ff_cre_syncobj(BYTE vol, FF_SYNC_t* sobj) +{ + *sobj = NULL; + return 1; +} + +/* 1:Function succeeded, 0:Could not delete due to an error */ +int ff_del_syncobj(FF_SYNC_t sobj) +{ + return 1; +} + +/* 1:Function succeeded, 0:Could not acquire lock */ +int ff_req_grant (FF_SYNC_t sobj) +{ + return 1; +} + +void ff_rel_grant (FF_SYNC_t sobj) +{ +} + diff --git a/components/fatfs/src/ffconf.h b/components/fatfs/src/ffconf.h index 958768eb2..79792beef 100644 --- a/components/fatfs/src/ffconf.h +++ b/components/fatfs/src/ffconf.h @@ -1,3 +1,5 @@ +#include "sdkconfig.h" + /*---------------------------------------------------------------------------/ / FatFs Functional Configurations /---------------------------------------------------------------------------*/ diff --git a/components/fatfs/test_fatfs_host/Makefile.files b/components/fatfs/test_fatfs_host/Makefile.files index 61347bb9b..ab77bc40c 100644 --- a/components/fatfs/test_fatfs_host/Makefile.files +++ b/components/fatfs/test_fatfs_host/Makefile.files @@ -1,13 +1,13 @@ SOURCE_FILES := \ $(addprefix ../src/, \ ff.c \ - ffsystem.c \ ffunicode.c \ ) \ $(addprefix ../diskio/,\ diskio.c \ diskio_wl.c \ - ) + ) \ + ../port/linux/ffsystem.c INCLUDE_DIRS := \ . \