Skip to content

Commit 32ddb34

Browse files
authored
Merge pull request #43 from mjs513/Thread-Support
update to get threads working
2 parents 78a9a62 + 786b797 commit 32ddb34

File tree

5 files changed

+48
-0
lines changed

5 files changed

+48
-0
lines changed

Diff for: cores/arduino/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ zephyr_sources(api/String.cpp)
1919

2020
if(DEFINED CONFIG_ARDUINO_ENTRY)
2121
zephyr_sources(main.cpp)
22+
zephyr_sources(threads.cpp)
2223
endif()
2324

2425
endif()

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

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