Skip to content

Commit

Permalink
ESP32: add support for "Platform Attachments"
Browse files Browse the repository at this point in the history
This will allow to store miscellaneous information inside ESP32PlatformData
sturct, so we don't need to add new fields or lists to it every time we
add support to a new NIF.

This change has been introduced to support tracking of mounted
filesystem in order to allow umounting them using `esp:umount/1`.

Signed-off-by: Davide Bettio <[email protected]>
  • Loading branch information
bettio committed Sep 29, 2024
1 parent 389ec97 commit 06370b6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/platforms/esp32/components/avm_sys/include/esp32_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ struct EventListener
listener_event_t sender;
};

struct PlatformAttachment
{
struct ListHead list_head;

// attachment_type must be unique for a certain type of entry.
// I suggest using a function pointer to the "constructor function" as a unique value since
// different functions have always different (and unique) addresses.
uintptr_t attachment_type;
};

struct ESP32PlatformData
{
pthread_t select_thread;
Expand All @@ -114,6 +124,8 @@ struct ESP32PlatformData
#endif
mbedtls_ctr_drbg_context random_ctx;
bool random_is_initialized;

struct SyncList attachment_list;
};

typedef void (*port_driver_init_t)(GlobalContext *global);
Expand Down
2 changes: 2 additions & 0 deletions src/platforms/esp32/components/avm_sys/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ void sys_init_platform(GlobalContext *glb)

platform->entropy_is_initialized = false;
platform->random_is_initialized = false;

synclist_init(&platform->attachment_list);
}

void sys_free_platform(GlobalContext *glb)
Expand Down

0 comments on commit 06370b6

Please sign in to comment.