This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit e1028818ac9fe687d54bfb988d64e8f68cffb39f
Author: Jerzy Kasenberg <[email protected]>
AuthorDate: Thu Jul 10 20:52:17 2025 +0200

    fs/fatfs: Enable thread safe support
    
    Add syscfg value to enable FATFS thread safe
    functionality.
    
    Signed-off-by: Jerzy Kasenberg <[email protected]>
---
 fs/fatfs/include/fatfs/ffconf.h |  9 +++++----
 fs/fatfs/src/mynewt_glue.c      | 43 +++++++++++++++++++++++++++++++++++++++++
 fs/fatfs/syscfg.yml             | 14 ++++++++++++++
 3 files changed, 62 insertions(+), 4 deletions(-)

diff --git a/fs/fatfs/include/fatfs/ffconf.h b/fs/fatfs/include/fatfs/ffconf.h
index 48e810771..ee3f171ae 100644
--- a/fs/fatfs/include/fatfs/ffconf.h
+++ b/fs/fatfs/include/fatfs/ffconf.h
@@ -2,6 +2,8 @@
 /  FatFs - FAT file system module configuration file
 /---------------------------------------------------------------------------*/
 
+#include <syscfg/syscfg.h>
+
 #define _FFCONF 68020  /* Revision ID */
 
 /*---------------------------------------------------------------------------/
@@ -240,10 +242,9 @@
 /      can be opened simultaneously under file lock control. Note that the file
 /      lock control is independent of re-entrancy. */
 
-
-#define _FS_REENTRANT  0
-#define _FS_TIMEOUT            1000
-#define        _SYNC_t                 HANDLE
+#define _FS_REENTRANT MYNEWT_VAL_FATFS_REENTRANT
+#define _FS_TIMEOUT   MYNEWT_VAL_FATFS_TIMEOUT
+#define _SYNC_t       void *
 /* The option _FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs
 /  module itself. Note that regardless of this option, file access to different
 /  volume is always re-entrant and volume control functions, f_mount(), 
f_mkfs()
diff --git a/fs/fatfs/src/mynewt_glue.c b/fs/fatfs/src/mynewt_glue.c
index 715475ea1..6ef26e379 100644
--- a/fs/fatfs/src/mynewt_glue.c
+++ b/fs/fatfs/src/mynewt_glue.c
@@ -674,6 +674,49 @@ get_fattime(void)
     return 0;
 }
 
+int
+ff_cre_syncobj(BYTE vol, _SYNC_t *sobj)
+{
+    struct os_mutex *mutex = os_malloc(sizeof(*mutex));
+
+    if (mutex) {
+        os_mutex_init(mutex);
+        *sobj = mutex;
+    }
+
+    return mutex != NULL;
+}
+
+int
+ff_req_grant(_SYNC_t sobj)
+{
+    struct os_mutex *mutex = (struct os_mutex *)sobj;
+    int rc;
+
+    rc = os_mutex_pend(mutex, _FS_TIMEOUT);
+
+    return rc == OS_OK;
+}
+
+void
+ff_rel_grant(_SYNC_t sobj)
+{
+    struct os_mutex *mutex = (struct os_mutex *)sobj;
+
+    os_mutex_release(mutex);
+}
+
+int
+ff_del_syncobj(_SYNC_t sobj)
+{
+    struct os_mutex *mutex = (struct os_mutex *)sobj;
+
+    assert(mutex->mu_owner == NULL);
+    os_free(mutex);
+
+    return FR_OK;
+}
+
 void
 fatfs_pkg_init(void)
 {
diff --git a/fs/fatfs/syscfg.yml b/fs/fatfs/syscfg.yml
index a446eca8b..2f2ba8a24 100644
--- a/fs/fatfs/syscfg.yml
+++ b/fs/fatfs/syscfg.yml
@@ -23,6 +23,17 @@ syscfg.defs:
             Sysinit stage for FATFS functionality.
         value: 200
 
+    FATFS_REENTRANT:
+        description: >
+            0 - Disable locking on file system
+            1 - Enable locking to multi thread access
+        value: 0
+
+    FATFS_TIMEOUT:
+        description: >
+            Timout for locking file system object.
+        value: 1000
+
     FATFS_LOG_MODULE:
         description: 'Numeric module ID to use for FATFS log messages.'
         value: 253
@@ -30,6 +41,9 @@ syscfg.defs:
         description: 'Minimum level for the FATFS log.'
         value: 2
 
+syscfg.vals.OS_SCHEDULING:
+    FATFS_REENTRANT: 1
+
 syscfg.logs:
     FATFS_LOG:
         module: MYNEWT_VAL(FATFS_LOG_MODULE)

Reply via email to