Skip to content

Commit e526e32

Browse files
mjs513facchinm
authored andcommitted
enable static threads
1 parent b28f7a1 commit e526e32

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

Diff for: cores/arduino/main.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,19 @@
99
#include <zephyr/llext/symbol.h>
1010
#endif
1111

12+
#ifdef CONFIG_MULTITHREADING
13+
void start_static_threads();
14+
#endif
15+
1216
int main(void) {
1317
#if (DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm) && CONFIG_USB_CDC_ACM)
1418
Serial.begin(115200);
1519
#endif
20+
21+
#ifdef CONFIG_MULTITHREADING
22+
start_static_threads();
23+
#endif
24+
1625
setup();
1726

1827
for (;;) {

Diff for: cores/arduino/threads.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "Arduino.h"
2+
3+
#ifdef CONFIG_MULTITHREADING
4+
void start_static_threads() {
5+
#define _FOREACH_STATIC_THREAD(thread_data) \
6+
STRUCT_SECTION_FOREACH(_static_thread_data, thread_data)
7+
8+
_FOREACH_STATIC_THREAD(thread_data) {
9+
k_thread_create(thread_data->init_thread, thread_data->init_stack, thread_data->init_stack_size, thread_data->init_entry,
10+
thread_data->init_p1, thread_data->init_p2, thread_data->init_p3, thread_data->init_prio,
11+
thread_data->init_options, thread_data->init_delay);
12+
k_thread_name_set(thread_data->init_thread, thread_data->init_name);
13+
thread_data->init_thread->init_data = thread_data;
14+
}
15+
16+
/*
17+
* Take a sched lock to prevent them from running
18+
* until they are all started.
19+
*/
20+
k_sched_lock();
21+
_FOREACH_STATIC_THREAD(thread_data) {
22+
k_thread_start(thread_data->init_thread);
23+
}
24+
k_sched_unlock();
25+
}
26+
#endif

Diff for: loader/llext_exports.c

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ EXPORT_SYMBOL(isupper);
4848
EXPORT_SYMBOL(islower);
4949
EXPORT_SYMBOL(isxdigit);
5050

51+
EXPORT_SYMBOL(k_sched_lock);
52+
EXPORT_SYMBOL(k_sched_unlock);
5153

5254
#if defined(CONFIG_USB_DEVICE_STACK)
5355
EXPORT_SYMBOL(usb_enable);

Diff for: variants/llext/linker_script.ld

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ SECTIONS {
3434
KEEP (*(.ctors))
3535
KEEP (*(.dtors))
3636
KEEP (*(.fini))
37+
38+
__static_thread_data_list_start = .;
39+
KEEP(*(SORT_BY_NAME(.__static_thread_data.static.*)));
40+
__static_thread_data_list_end = .;
3741
}
3842

3943
.rodata : {

0 commit comments

Comments
 (0)