diff options
author | Damien George <damien.p.george@gmail.com> | 2017-02-06 15:13:30 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-02-15 13:28:48 +1100 |
commit | 05a4859585c4e0a55fca2e7467ba70da6453fdcb (patch) | |
tree | 70d87f5ac3437b2e46e5b4d2d7b29b9ecced3776 /stmhal/stm32_it.c | |
parent | f6c22a06797735e4a65a91491d8373ba951a798b (diff) |
stmhal: Implement a proper thread scheduler.
This patch changes the threading implementation from simple round-robin
with busy waits on mutexs, to proper scheduling whereby threads that are
waiting on a mutex are only scheduled when the mutex becomes available.
Diffstat (limited to 'stmhal/stm32_it.c')
-rw-r--r-- | stmhal/stm32_it.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/stmhal/stm32_it.c b/stmhal/stm32_it.c index 4152050a9..d8fcc59ce 100644 --- a/stmhal/stm32_it.c +++ b/stmhal/stm32_it.c @@ -70,6 +70,7 @@ #include "stm32_it.h" #include STM32_HAL_H +#include "py/mpstate.h" #include "py/obj.h" #include "py/mphal.h" #include "pendsv.h" @@ -315,9 +316,14 @@ void SysTick_Handler(void) { } #if MICROPY_PY_THREAD - // signal a thread switch at 4ms=250Hz - if (pyb_thread_enabled && (uwTick & 0x03) == 0x03) { - SCB->ICSR = SCB_ICSR_PENDSVSET_Msk; + if (pyb_thread_enabled) { + if (pyb_thread_cur->timeslice == 0) { + if (pyb_thread_cur->run_next != pyb_thread_cur) { + SCB->ICSR = SCB_ICSR_PENDSVSET_Msk; + } + } else { + --pyb_thread_cur->timeslice; + } } #endif } |