minimult_cortex-m

This crate for Rust provides a minimal multitask library Minimult for Cortex-M microcontrollers.

Target

Single-core systems of

Features

Examples

Usage

```rust // Runnable on QEMU ARM

![no_main]

![no_std]

use cortexm::Peripherals; use cortexmrt::entry; use cortexmrt::exception; use cortexmsemihosting::debug; use cortexmsemihosting::hprintln; extern crate panicsemihosting;

use minimultcortexm::*;

[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();

hprintln!("Minimult run").unwrap();
mt.run()

}

[exception]

fn SysTick() { Minimult::kick(0/tid/); }

fn task0(mut snd: MTMsgSender) { for vsnd in 0.. { Minimult::idle();

    hprintln!("task0 send {}", vsnd).unwrap();
    snd.send(vsnd);
}

}

fn task1(mut rcv: MTMsgReceiver, shch: MTSharedCh) { 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) { let mut j = 0;

while j < 5 {
    let vlook = shch.look();

    assert!((j == *vlook) || (j + 1 == *vlook));
    //hprintln!("task2 look {}", *vlook).unwrap(); // many lines printed
    j = *vlook;
}

hprintln!("task2 exit").unwrap();
debug::exit(debug::EXIT_SUCCESS);

} ```

Other Examples

You can find a specific board's example here. Currently there are very few examples, however.