Context switch
Posted: Thu Dec 20, 2018 4:54 pm
I'm wondering if it's feasible to implement with pure Oberon code (of course Astrobe-specific) a simple cooperative multitasking
for the STM32 M7 platform based on following assumptions:
1) each task is an Oberon procedure but with its own stack
2) each task explicitly gives control to other tasks (if any) through a Yield() call
3) the Yield is a custom procedure triggering a software interrupt
4) an interrupt handler is installed for the sw interrupt defined in point 3;
it saves the current context (HW registers), selects a new task, then restores the context of such new task
I have found most of the required pieces inside Astrobe:
SYSTEM.PUT(MCU.STIR, N) is supposed to trigger the sw interrupt N
Traps.Assign(address, P) is supposed to install an handler P in the vector <address> for IRQ N
SYSTEM.REG(X) and SYSTEM.LDREG(X, value) allow to save and restore HW registers
but it's quite difficult to put them together, so far I'm just getting Hard Faults...
Any help/suggestion/reference code is welcome!
for the STM32 M7 platform based on following assumptions:
1) each task is an Oberon procedure but with its own stack
2) each task explicitly gives control to other tasks (if any) through a Yield() call
3) the Yield is a custom procedure triggering a software interrupt
4) an interrupt handler is installed for the sw interrupt defined in point 3;
it saves the current context (HW registers), selects a new task, then restores the context of such new task
I have found most of the required pieces inside Astrobe:
SYSTEM.PUT(MCU.STIR, N) is supposed to trigger the sw interrupt N
Traps.Assign(address, P) is supposed to install an handler P in the vector <address> for IRQ N
SYSTEM.REG(X) and SYSTEM.LDREG(X, value) allow to save and restore HW registers
but it's quite difficult to put them together, so far I'm just getting Hard Faults...
Any help/suggestion/reference code is welcome!