diff options
| author | Damien George <damien.p.george@gmail.com> | 2017-01-31 13:59:53 +1100 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2017-01-31 18:42:35 +1100 |
| commit | 882ec01e42227445a63f6d5b38cac14d8635f2ad (patch) | |
| tree | 98abee9fe7fb1e3ecacc7f3b13f87de058e42624 /stmhal/main.c | |
| parent | bebb3a616006d7f31b52213133ed7fb7d89cdcef (diff) | |
stmhal: Initial implementation of multithreading, currently disabled.
This patch brings the _thread module to stmhal/pyboard. There is a very
simple round-robin thread scheduler, which is disabled if there is only
one thread (for efficiency when threading is not used).
The scheduler currently switches threads at a rate of 250Hz using the
systick timer and the pend-SV interrupt.
The GIL is disabled so one must be careful to use lock objects to prevent
concurrent access of objects.
The threading is disabled by default, one can enabled it with the config
option MICROPY_PY_THREAD to test it out.
Diffstat (limited to 'stmhal/main.c')
| -rw-r--r-- | stmhal/main.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/stmhal/main.c b/stmhal/main.c index 722ca41b4..4ffa0d9ba 100644 --- a/stmhal/main.c +++ b/stmhal/main.c @@ -43,6 +43,7 @@ #include "systick.h" #include "pendsv.h" +#include "pybthread.h" #include "gccollect.h" #include "readline.h" #include "modmachine.h" @@ -67,6 +68,7 @@ void SystemClock_Config(void); +pyb_thread_t pyb_thread_main; fs_user_mount_t fs_user_mount_flash; mp_vfs_mount_t mp_vfs_mount_flash; @@ -419,11 +421,6 @@ STATIC uint update_reset_mode(uint reset_mode) { int main(void) { // TODO disable JTAG - // Stack limit should be less than real stack size, so we have a chance - // to recover from limit hit. (Limit is measured in bytes.) - mp_stack_ctrl_init(); - mp_stack_set_limit((char*)&_ram_end - (char*)&_heap_end - 1024); - /* STM32F4xx HAL library initialization: - Configure the Flash prefetch, instruction and Data caches - Configure the Systick to generate an interrupt each 1 msec @@ -457,6 +454,7 @@ int main(void) { #endif // basic sub-system init + pyb_thread_init(&pyb_thread_main); pendsv_init(); led_init(); #if MICROPY_HW_HAS_SWITCH @@ -502,6 +500,17 @@ soft_reset: storage_init(); } + // Python threading init + #if MICROPY_PY_THREAD + mp_thread_init(); + #endif + + // Stack limit should be less than real stack size, so we have a chance + // to recover from limit hit. (Limit is measured in bytes.) + // Note: stack control relies on main thread being initialised above + mp_stack_ctrl_init(); + mp_stack_set_limit((char*)&_ram_end - (char*)&_heap_end - 1024); + // GC init gc_init(&_heap_start, &_heap_end); |
