This crate for Rust provides a minimal multitask library Minimult
for Cortex-M microcontrollers.
Single-core systems of
thumbv6m-none-eabi
)thumbv7m-none-eabi
)thumbv7em-none-eabi
)thumbv7em-none-eabihf
)thumbv8m.base-none-eabi
)thumbv8m.main-none-eabi
)Minimult
is still in beta because the author had only a few tests only on Cortex-M4 with FPU.
Minimult
can take closures and register them as tasks.Minimult
runs into a loop to start dispatching those tasks.idle
and kick
MTMsgSender
and MTMsgReceiver
dispatch
can be directly requested so that timer-based preemption is also possible.Minimult
doesn't require a global allocator but reserves a bunch of memory block in advance.```rust
use cortexm::Peripherals; use cortexmrt::entry; use cortexmrt::exception; extern crate panicsemihosting;
// other codes...
use minimultcortexm::*;
fn main() -> ! { let mut mem = Minimult::mem::<[u8; 4096]>(); let mut mt = Minimult::new(&mut mem, 2);
// other codes...
let mut q = mt.msgq::<u32>(4);
let (snd, rcv) = q.ch();
mt.register(0/*tid*/, 1, 256, || task0(snd));
mt.register(1/*tid*/, 1, 256, || task1(rcv));
// other codes...
let cmperi = Peripherals::take().unwrap();
let mut syst = cmperi.SYST;
syst.set_clock_source(cortex_m::peripheral::syst::SystClkSource::Core);
syst.set_reload(0xffffff);
syst.clear_current();
syst.enable_counter();
syst.enable_interrupt();
// other codes...
mt.run()
}
fn SysTick() { // other codes...
Minimult::kick(0/*tid*/);
}
fn task0(snd: MTMsgSender
loop {
Minimult::idle();
// other codes...
let some_value = 1;
snd.send(some_value);
}
}
fn task1(rcv: MTMsgReceiver
loop {
let mut some_value = 0;
rcv.receive(|v| {some_value = *v});
// other codes...
}
} ```
You can find a specific board's example here. Currently there are very few examples, however.