Skip to content
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

Make this library compatible for ESP8266 RTOS SDK. #215

Merged
merged 8 commits into from
Jan 22, 2025

Conversation

Adam5Wu
Copy link
Contributor

@Adam5Wu Adam5Wu commented Jan 20, 2025

No description provided.

Only require `sdmmc` when `CONFIG_LITTLEFS_SDMMC_SUPPORT` is set.
Avoid referring to `portMUX_INITIALIZER_UNLOCKED` and `portENTER_CRITICAL` / `portEXIT_CRITICAL`, which are not available for ESP8266 RTOS SDK.
ESP8266 RTOS SDK default enables VFS DIR support.
Copy link
Member

@BrianPugh BrianPugh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few small comments; I've never developed with ESP8266 RTOS SDK, so I would appreciate some overly-verbose comments for any references to it!

include/esp_littlefs.h Show resolved Hide resolved
src/esp_littlefs.c Outdated Show resolved Hide resolved
Use a more generic condition for ESP8266 RTOS SDK compatibility.
@@ -899,13 +899,17 @@ static int esp_littlefs_flags_conv(int m) {

static void esp_littlefs_take_efs_lock(void) {
if( _efs_lock == NULL ){
#if portNUM_PROCESSORS > 1 // SMP protection needed for multi-core
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last issue for this PR:

Is this portENTER_CRITICAL still required for a single core processor? The race condition is if 2 threads attempt to initialize the global _efs_lock, at the same time, then without this look we could result in 2 calls of xSemaphoreCreateMutex. This is avoided by the seemingly-redundant _efs_lock == NULL check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good point. I found taskENTER_CRITICAL() and taskEXIT_CRITICAL() which seem to be what is needed.

CMakeLists.txt Outdated
@@ -5,14 +5,15 @@ list(APPEND SOURCES src/esp_littlefs.c src/littlefs_esp_part.c src/lfs_config.c)

if(CONFIG_LITTLEFS_SDMMC_SUPPORT)
list(APPEND SOURCES src/littlefs_sdmmc.c)
list(APPEND priv_requires sdmmc)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure sdmmc has to be in pub_requires because it is referenced in the public include/esp_littlefs.h

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, PTAL~

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's in pub_requires, then we don't have to add it to priv_requires, so we should be able to delete this line (line 8).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, OK. I am not very familar with the conventions. :P

Add `sdmmc` to `pub_requires` since it is referred to in include/esp_littlefs.h
Use `taskENTER_CRITICAL()` and `taskEXIT_CRITICAL()` for single core concurrency protection.
@@ -899,13 +899,21 @@ static int esp_littlefs_flags_conv(int m) {

static void esp_littlefs_take_efs_lock(void) {
if( _efs_lock == NULL ){
#if portNUM_PROCESSORS > 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're doing this because the 8266 doesn't have a portENTER_CRITICAL macro, correct? If so, I guess we should change this back to #ifdef ESP8266 since this is an 8266-specific change, not dependent on the number of cores of the target device. Lets add a comment about it as well.

Sorry about the thrash!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just searching the sdk makes it seem like portENTER_CRITICAL is available, however.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, just that ESP8266's portENTER_CRITICAL doesn't take any arguments -- probably just an outdated ESP-IDF convention, similar to the dir support. So, sure I guess we can just do #ifdef ESP8266 -- so a future clean up (if the ESP8266 SDK ever get refreshed) would be easier. :D

`priv_requires` not needed if `pub_requires` is used.
Use `ESP8266` to guard the concurrency protection API patch instead.
@BrianPugh BrianPugh merged commit 1aeae11 into joltwallet:master Jan 22, 2025
9 checks passed
@BrianPugh
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants