fatfs: create separate ffsystem.c for host side testing

This commit is contained in:
Ivan Grokhotkov 2019-06-21 15:33:10 +08:00
parent 66bdeca603
commit 8f6606141a
7 changed files with 70 additions and 27 deletions

View File

@ -3,7 +3,7 @@ idf_component_register(SRCS "diskio/diskio.c"
"diskio/diskio_sdmmc.c" "diskio/diskio_sdmmc.c"
"diskio/diskio_wl.c" "diskio/diskio_wl.c"
"src/ff.c" "src/ff.c"
"port/ffsystem.c" "port/freertos/ffsystem.c"
"src/ffunicode.c" "src/ffunicode.c"
"vfs/vfs_fat.c" "vfs/vfs_fat.c"
"vfs/vfs_fat_sdmmc.c" "vfs/vfs_fat_sdmmc.c"

View File

@ -1,3 +1,3 @@
COMPONENT_ADD_INCLUDEDIRS := diskio vfs src 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 COMPONENT_OBJEXCLUDE := src/diskio.o src/ffsystem.o

View File

@ -10,6 +10,7 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <stdlib.h>
#include <sys/time.h> #include <sys/time.h>
#include "diskio_impl.h" #include "diskio_impl.h"
#include "ffconf.h" #include "ffconf.h"

View File

@ -12,21 +12,15 @@
#include "esp_heap_caps.h" #include "esp_heap_caps.h"
#endif #endif
void* ff_memalloc ( /* Returns pointer to the allocated memory block (null on not enough core) */
unsigned msize /* Number of bytes to allocate */
/*------------------------------------------------------------------------*/
/* 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 */
) )
{ {
#ifdef CONFIG_FATFS_ALLOC_EXTRAM_FIRST #ifdef CONFIG_FATFS_ALLOC_EXTRAM_FIRST
return heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT | MALLOC_CAP_SPIRAM, return heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT | MALLOC_CAP_SPIRAM,
MALLOC_CAP_DEFAULT | MALLOC_CAP_INTERNAL); MALLOC_CAP_DEFAULT | MALLOC_CAP_INTERNAL);
#else #else
return malloc(msize); return malloc(msize);
#endif #endif
} }
@ -36,16 +30,16 @@ void* ff_memalloc ( /* Returns pointer to the allocated memory block (null on no
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
void ff_memfree ( 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 */ /* 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 */ int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object */
BYTE vol, /* Corresponding volume (logical drive number) */ BYTE vol, /* Corresponding volume (logical drive number) */
FF_SYNC_t *sobj /* Pointer to return the created sync object */ FF_SYNC_t *sobj /* Pointer to return the created sync object */
) )
{ {
*sobj = xSemaphoreCreateMutex(); *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. / the f_mount() function fails with FR_INT_ERR.
*/ */
int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to an error */ 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 */ FF_SYNC_t sobj /* Sync object tied to the logical drive to be deleted */
) )
{ {
vSemaphoreDelete(sobj); 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. / 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 */ 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 */ FF_SYNC_t sobj /* Sync object to wait */
) )
{ {
return (xSemaphoreTake(sobj, FF_FS_TIMEOUT) == pdTRUE) ? 1 : 0; 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 ( void ff_rel_grant (
FF_SYNC_t sobj /* Sync object to be signaled */ FF_SYNC_t sobj /* Sync object to be signaled */
) )
{ {
xSemaphoreGive(sobj); xSemaphoreGive(sobj);
} }
#endif #endif // FF_FS_REENTRANT

View File

@ -0,0 +1,46 @@
/*------------------------------------------------------------------------*/
/* OS Dependent Functions for FatFs */
/* (C)ChaN, 2018 */
/*------------------------------------------------------------------------*/
#include "ff.h"
#include <stdlib.h>
/* 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)
{
}

View File

@ -1,3 +1,5 @@
#include "sdkconfig.h"
/*---------------------------------------------------------------------------/ /*---------------------------------------------------------------------------/
/ FatFs Functional Configurations / FatFs Functional Configurations
/---------------------------------------------------------------------------*/ /---------------------------------------------------------------------------*/

View File

@ -1,13 +1,13 @@
SOURCE_FILES := \ SOURCE_FILES := \
$(addprefix ../src/, \ $(addprefix ../src/, \
ff.c \ ff.c \
ffsystem.c \
ffunicode.c \ ffunicode.c \
) \ ) \
$(addprefix ../diskio/,\ $(addprefix ../diskio/,\
diskio.c \ diskio.c \
diskio_wl.c \ diskio_wl.c \
) ) \
../port/linux/ffsystem.c
INCLUDE_DIRS := \ INCLUDE_DIRS := \
. \ . \