Skip to content

Commit

Permalink
enable static threads
Browse files Browse the repository at this point in the history
  • Loading branch information
mjs513 authored and facchinm committed Jan 29, 2025
1 parent b28f7a1 commit e526e32
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cores/arduino/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@
#include <zephyr/llext/symbol.h>
#endif

#ifdef CONFIG_MULTITHREADING
void start_static_threads();
#endif

int main(void) {
#if (DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm) && CONFIG_USB_CDC_ACM)
Serial.begin(115200);
#endif

#ifdef CONFIG_MULTITHREADING
start_static_threads();
#endif

setup();

for (;;) {
Expand Down
26 changes: 26 additions & 0 deletions cores/arduino/threads.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "Arduino.h"

#ifdef CONFIG_MULTITHREADING
void start_static_threads() {
#define _FOREACH_STATIC_THREAD(thread_data) \
STRUCT_SECTION_FOREACH(_static_thread_data, thread_data)

_FOREACH_STATIC_THREAD(thread_data) {
k_thread_create(thread_data->init_thread, thread_data->init_stack, thread_data->init_stack_size, thread_data->init_entry,
thread_data->init_p1, thread_data->init_p2, thread_data->init_p3, thread_data->init_prio,
thread_data->init_options, thread_data->init_delay);
k_thread_name_set(thread_data->init_thread, thread_data->init_name);
thread_data->init_thread->init_data = thread_data;
}

/*
* Take a sched lock to prevent them from running
* until they are all started.
*/
k_sched_lock();
_FOREACH_STATIC_THREAD(thread_data) {
k_thread_start(thread_data->init_thread);
}
k_sched_unlock();
}
#endif
2 changes: 2 additions & 0 deletions loader/llext_exports.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ EXPORT_SYMBOL(isupper);
EXPORT_SYMBOL(islower);
EXPORT_SYMBOL(isxdigit);

EXPORT_SYMBOL(k_sched_lock);
EXPORT_SYMBOL(k_sched_unlock);

#if defined(CONFIG_USB_DEVICE_STACK)
EXPORT_SYMBOL(usb_enable);
Expand Down
4 changes: 4 additions & 0 deletions variants/llext/linker_script.ld
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ SECTIONS {
KEEP (*(.ctors))
KEEP (*(.dtors))
KEEP (*(.fini))

__static_thread_data_list_start = .;
KEEP(*(SORT_BY_NAME(.__static_thread_data.static.*)));
__static_thread_data_list_end = .;
}

.rodata : {
Expand Down

0 comments on commit e526e32

Please sign in to comment.