]> granicus.if.org Git - esp-idf/commitdiff
fatfs: expose some configuration values in Kconfig
authorIvan Grokhotkov <ivan@espressif.com>
Tue, 17 Oct 2017 10:27:40 +0000 (18:27 +0800)
committerIvan Grokhotkov <ivan@espressif.com>
Tue, 17 Oct 2017 10:43:46 +0000 (18:43 +0800)
- _FS_TINY: disables per-file caches
- _FS_TIMEOUT: locking timeout for concurrent access
- _FS_LOCK: prevents operations which are not allowed on open files

Also sets _MAX_SS based on sector size configured for wear_levelling.
This reduces memory usage of FATFS if wear_levelling is using 512 byte
sectors.

components/fatfs/Kconfig
components/fatfs/src/ffconf.h

index 2e10f046d52a43f74dee2e2a14cfeb4a0d6632bf..f12199ed4b35fd610103605bedad27a574121478 100644 (file)
@@ -105,4 +105,49 @@ config FATFS_MAX_LFN
    help
       Maximum long filename length. Can be reduced to save RAM.
 
+config FATFS_FS_LOCK
+   int "Number of simultaneously open files protected by lock function"
+   default 0
+   range 0 65535
+   help
+      This option sets the FATFS configuration value _FS_LOCK.
+      The option _FS_LOCK switches file lock function to control duplicated file open
+      and illegal operation to open objects.
+       
+      * 0: Disable file lock function. To avoid volume corruption, application
+           should avoid illegal open, remove and rename to the open objects.
+       
+      * >0: Enable file lock function. The value defines how many files/sub-directories
+           can be opened simultaneously under file lock control.
+           
+      Note that the file lock control is independent of re-entrancy.
+
+config FATFS_TIMEOUT_MS
+   int "Timeout for acquiring a file lock, ms"
+   default 10000
+   help
+      This option sets FATFS configuration value _FS_TIMEOUT, scaled to milliseconds.
+      Sets the number of milliseconds FATFS will wait to acquire a mutex when
+      operating on an open file. For example, if one task is performing a lenghty
+      operation, another task will wait for the first task to release the lock,
+      and time out after amount of time set by this option.
+      
+
+config FATFS_PER_FILE_CACHE
+   bool "Use separate cache for each file"
+   default y
+   help
+      This option affects FATFS configuration value _FS_TINY.
+      
+      If this option is set, _FS_TINY is 0, and each open file has its own cache,
+      size of the cache is equal to the _MAX_SS variable (512 or 4096 bytes).
+      This option uses more RAM if more than 1 file is open, but needs less reads
+      and writes to the storage for some operations.
+      
+      If this option is not set, _FS_TINY is 1, and single cache is used for
+      all open files, size is also equal to _MAX_SS variable. This reduces the
+      amount of heap used when multiple files are open, but increases the number
+      of read and write operations which FATFS needs to make.
+      
+
 endmenu
index ab17e6922ccc88d9d750b362fbaafef9f9a34edb..8933ec6f65aad16e3cb7cbfe95eb718996179b6a 100644 (file)
@@ -1,3 +1,4 @@
+#include <sys/param.h>\r
 #include "sdkconfig.h"\r
 /*---------------------------------------------------------------------------/\r
 /  FatFs - FAT file system module configuration file\r
 /  arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk()\r
 /  funciton will be available. */\r
 \r
+/* SD card sector size */\r
+#define _SS_SDCARD      512\r
+/* wear_levelling library sector size */\r
+#define _SS_WL          CONFIG_WL_SECTOR_SIZE\r
 \r
-#define        _MIN_SS         512\r
-#define        _MAX_SS         4096\r
+#define        _MIN_SS         MIN(_SS_SDCARD, _SS_WL)\r
+#define        _MAX_SS         MAX(_SS_SDCARD, _SS_WL)\r
 /* These options configure the range of sector size to be supported. (512, 1024,\r
 /  2048 or 4096) Always set both 512 for most systems, all type of memory cards and\r
 /  harddisk. But a larger value may be required for on-board flash memory and some\r
 / System Configurations\r
 /---------------------------------------------------------------------------*/\r
 \r
-#define        _FS_TINY        0\r
+#define        _FS_TINY        (!CONFIG_FATFS_PER_FILE_CACHE)\r
 /* This option switches tiny buffer configuration. (0:Normal or 1:Tiny)\r
 /  At the tiny configuration, size of file object (FIL) is reduced _MAX_SS bytes.\r
 /  Instead of private sector buffer eliminated from the file object, common sector\r
 /  These options have no effect at read-only configuration (_FS_READONLY = 1). */\r
 \r
 \r
-#define        _FS_LOCK        0\r
+#define        _FS_LOCK        CONFIG_FATFS_FS_LOCK\r
 /* The option _FS_LOCK switches file lock function to control duplicated file open\r
 /  and illegal operation to open objects. This option must be 0 when _FS_READONLY\r
 /  is 1.\r
 \r
 \r
 #define _FS_REENTRANT  1\r
-#define _FS_TIMEOUT            1000\r
+#define _FS_TIMEOUT            (CONFIG_FATFS_TIMEOUT_MS / portTICK_PERIOD_MS)\r
 #define        _SYNC_t                 SemaphoreHandle_t\r
 /* The option _FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs\r
 /  module itself. Note that regardless of this option, file access to different\r