-
Notifications
You must be signed in to change notification settings - Fork 8.2k
fat_fs: Add reentrant zephyr support #51484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1371,6 +1371,16 @@ Filesystems: | |
| labels: | ||
| - "area: File System" | ||
|
|
||
| "Filesystems: FatFs reentrant support": | ||
| status: maintained | ||
| maintainers: | ||
| - ox11 | ||
| files: | ||
| - modules/fatfs/zfs_ffsystem.c | ||
| - tests/subsys/fs/fat_fs_api/src/test_fat_file_reentrant.c | ||
| labels: | ||
| - "area: File System" | ||
|
Comment on lines
+1374
to
+1382
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It does not make sense to have "FatFs reentrant support" as a dedicated area -- this is too much granularity. Please revert this change or define the maintainership as "Filesystems: Fatfs."
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not a maintainer of the entire FatFS module. or to add myself to the collaborators in the fs area The first option should IMHO be created by @de-nordic as he would be mentioned as maintainer. Additionally, is there anyone else that should be mentioned as collaborator? |
||
|
|
||
| Formatted Output: | ||
| status: maintained | ||
| maintainers: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* | ||
| * OS Dependent Functions for FatFs | ||
| * | ||
| * Copyright (c) 2023 Husqvarna AB | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| /* The file is based on template file by (C)ChaN, 2022, as | ||
| * available from FAT FS module source: | ||
| * https://github.com/zephyrproject-rtos/fatfs/blob/master/option/ffsystem.c | ||
| */ | ||
|
|
||
| #include <ff.h> | ||
|
|
||
| #if FF_USE_LFN == 3 /* Dynamic memory allocation */ | ||
| /* Allocate a memory block */ | ||
| void *ff_memalloc(UINT msize) | ||
| { | ||
| return k_malloc(msize); | ||
| } | ||
|
|
||
| /* Free a memory block */ | ||
| void ff_memfree(void *mblock) | ||
| { | ||
| k_free(mblock); | ||
| } | ||
| #endif /* FF_USE_LFN == 3 */ | ||
|
|
||
| #if FF_FS_REENTRANT /* Mutual exclusion */ | ||
| /* Table of Zephyr mutex. One for each volume and an extra one for the ff system. | ||
| * See also the template file used as reference. Link is available in the header of this file. | ||
| */ | ||
| static struct k_mutex fs_reentrant_mutex[FF_VOLUMES + 1]; | ||
|
|
||
| /* Create a Mutex | ||
| * Mutex ID vol: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) | ||
| * Returns 1: Succeeded or 0: Could not create the mutex | ||
| */ | ||
| int ff_mutex_create(int vol) | ||
| { | ||
| return (int)(k_mutex_init(&fs_reentrant_mutex[vol]) == 0); | ||
| } | ||
|
|
||
| /* Delete a Mutex | ||
| * Mutex ID vol: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) | ||
| */ | ||
| void ff_mutex_delete(int vol) | ||
| { | ||
| /* (nothing to do) */ | ||
| (void)vol; | ||
| } | ||
|
|
||
| /* Request Grant to Access the Volume | ||
| * Mutex ID vol: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) | ||
| * Returns 1: Succeeded or 0: Timeout | ||
| */ | ||
| int ff_mutex_take(int vol) | ||
| { | ||
| return (int)(k_mutex_lock(&fs_reentrant_mutex[vol], FF_FS_TIMEOUT) == 0); | ||
| } | ||
|
|
||
| /* Release Grant to Access the Volume | ||
| * Mutex ID vol: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) | ||
| */ | ||
| void ff_mutex_give(int vol) | ||
| { | ||
| k_mutex_unlock(&fs_reentrant_mutex[vol]); | ||
| } | ||
| #endif /* FF_FS_REENTRANT */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| # Copyright (c) 2016 Intel Corporation | ||
| # Copyright (c) 2020 Nordic Semiconductor ASA | ||
| # Copyright (c) 2023 Husqvarna AB | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| config FAT_FILESYSTEM_ELM | ||
|
|
@@ -220,6 +221,14 @@ config FS_FATFS_WINDOW_ALIGNMENT | |
| that, in worst scenario, value provided here may cause FATFS | ||
| structure to have size of twice the value. | ||
|
|
||
| config FS_FATFS_REENTRANT | ||
| bool "FatFs reentrant" | ||
| depends on !FS_FATFS_LFN_MODE_BSS | ||
| help | ||
|
||
| Enable the FatFs re-entrancy (thread safe) option for file/directory | ||
| access for each volume. Will create a zephyr mutex object for each | ||
| FatFs volume and a FatFs system mutex. | ||
|
|
||
| endmenu | ||
|
|
||
| endif # FAT_FILESYSTEM_ELM | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
List is missing test_fat_file_reentrant.c file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added it.