Crates.io | minimult_cortex-m |
lib.rs | minimult_cortex-m |
version | 0.3.3 |
source | src |
created_at | 2019-10-20 05:04:24.395751 |
updated_at | 2019-11-20 12:38:42.87547 |
description | A minimal multitask library, or RTOS, for Cortex-M microcontrollers. |
homepage | https://github.com/convexbrain/Minimult/tree/master/minimult_cortex-m |
repository | https://github.com/convexbrain/Minimult |
max_upload_size | |
id | 174136 |
size | 81,441 |
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
) with FPU (thumbv7em-none-eabihf
)thumbv8m.base-none-eabi
)thumbv8m.main-none-eabi
) with FPU (thumbv8m.main-none-eabihf
)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
MTSharedCh
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.// Runnable on QEMU ARM
#![no_main]
#![no_std]
use cortex_m::Peripherals;
use cortex_m_rt::entry;
use cortex_m_rt::exception;
use cortex_m_semihosting::debug;
use cortex_m_semihosting::hprintln;
use panic_semihosting as _;
use minimult_cortex_m::*;
#[entry]
fn main() -> !
{
let mut mem = Minimult::mem::<[u8; 4096]>();
let mut mt = Minimult::new(&mut mem, 3);
let mut q = mt.msgq::<u32>(4);
let (snd, rcv) = q.ch();
let sh = mt.share::<u32>(0);
let shch1 = sh.ch();
let shch2 = sh.ch();
mt.register(0/*tid*/, 1, 256, || task0(snd));
mt.register(1/*tid*/, 1, 256, || task1(rcv, shch1));
mt.register(2/*tid*/, 1, 256, || task2(shch2));
// SysTick settings
let cmperi = Peripherals::take().unwrap();
let mut syst = cmperi.SYST;
syst.set_clock_source(cortex_m::peripheral::syst::SystClkSource::Core);
syst.set_reload(1_000_000);
syst.clear_current();
syst.enable_counter();
syst.enable_interrupt();
// must be error in terms of lifetime and ownership
//drop(mem);
//drop(q);
//drop(snd);
//drop(rcv);
//drop(sh);
//drop(shch1);
//drop(shch2);
hprintln!("Minimult run").unwrap();
mt.run()
}
#[exception]
fn SysTick()
{
Minimult::kick(0/*tid*/);
}
fn task0(mut snd: MTMsgSender<u32>)
{
for vsnd in 0.. {
Minimult::idle();
hprintln!("task0 send {}", vsnd).unwrap();
snd.send(vsnd);
}
}
fn task1(mut rcv: MTMsgReceiver<u32>, shch: MTSharedCh<u32>)
{
for i in 0.. {
let vrcv = rcv.receive();
assert_eq!(i, vrcv);
hprintln!("task1 touch {}", vrcv).unwrap();
let mut vtouch = shch.touch();
*vtouch = vrcv;
}
}
fn task2(shch: MTSharedCh<u32>)
{
let mut j = 0;
while j < 50 {
let vlook = shch.look();
assert!(j <= *vlook);
//hprintln!("task2 look {}", *vlook).unwrap(); // many lines printed
j = *vlook;
}
hprintln!("task2 exit").unwrap();
debug::exit(debug::EXIT_SUCCESS);
}
You can find a specific board's example here. Currently there are very few examples, however.