diff options
author | 2019-06-18 10:31:31 +0200 | |
---|---|---|
committer | 2019-06-18 10:31:31 +0200 | |
commit | 9897728709528a02545523bea72576abce89dc4c (patch) | |
tree | 49619bfb8e3e09cccbc9c2bd1854abfe1618c8fd /heterogeneous | |
parent | 81275bfa4f41e2066770087f3a33cad4227eab41 (diff) | |
download | rtic-9897728709528a02545523bea72576abce89dc4c.tar.gz rtic-9897728709528a02545523bea72576abce89dc4c.tar.zst rtic-9897728709528a02545523bea72576abce89dc4c.zip |
add homogeneous multi-core support
Diffstat (limited to '')
-rw-r--r-- | heterogeneous/Cargo.toml (renamed from mc/Cargo.toml) | 4 | ||||
-rw-r--r-- | heterogeneous/README.md | 1 | ||||
-rw-r--r-- | heterogeneous/examples/smallest.rs | 7 | ||||
-rw-r--r-- | heterogeneous/examples/x-init-2.rs | 39 | ||||
-rw-r--r-- | heterogeneous/examples/x-init.rs | 26 | ||||
-rw-r--r-- | heterogeneous/examples/x-schedule.rs | 36 | ||||
-rw-r--r-- | heterogeneous/examples/x-spawn.rs | 20 | ||||
-rw-r--r-- | heterogeneous/src/lib.rs (renamed from mc/src/lib.rs) | 41 |
8 files changed, 149 insertions, 25 deletions
diff --git a/mc/Cargo.toml b/heterogeneous/Cargo.toml index 7c75335d..fd05d07e 100644 --- a/mc/Cargo.toml +++ b/heterogeneous/Cargo.toml @@ -1,13 +1,13 @@ [package] authors = ["Jorge Aparicio <jorge@japaric.io>"] edition = "2018" -name = "mc" +name = "heterogeneous" # this crate is only used for testing publish = false version = "0.0.0-alpha.0" [dependencies] -cortex-m = "0.6.0" +bare-metal = "0.2.4" [dependencies.cortex-m-rtfm] path = ".." diff --git a/heterogeneous/README.md b/heterogeneous/README.md new file mode 100644 index 00000000..8e49ff8b --- /dev/null +++ b/heterogeneous/README.md @@ -0,0 +1 @@ +This directory contains *heterogeneous* multi-core compile pass tests. diff --git a/heterogeneous/examples/smallest.rs b/heterogeneous/examples/smallest.rs new file mode 100644 index 00000000..9b6bb82d --- /dev/null +++ b/heterogeneous/examples/smallest.rs @@ -0,0 +1,7 @@ +#![no_main] +#![no_std] + +use panic_halt as _; + +#[rtfm::app(cores = 2, device = heterogeneous)] +const APP: () = {}; diff --git a/heterogeneous/examples/x-init-2.rs b/heterogeneous/examples/x-init-2.rs new file mode 100644 index 00000000..b9c39197 --- /dev/null +++ b/heterogeneous/examples/x-init-2.rs @@ -0,0 +1,39 @@ +//! [compile-pass] Cross initialization of late resources + +#![deny(unsafe_code)] +#![deny(warnings)] +#![no_main] +#![no_std] + +use panic_halt as _; + +#[rtfm::app(cores = 2, device = heterogeneous)] +const APP: () = { + extern "C" { + // owned by core #1 but initialized by core #0 + static mut X: u32; + + // owned by core #0 but initialized by core #1 + static mut Y: u32; + } + + #[init(core = 0, late = [X])] + fn a(_: a::Context) -> a::LateResources { + a::LateResources { X: 0 } + } + + #[idle(core = 0, resources = [Y])] + fn b(_: b::Context) -> ! { + loop {} + } + + #[init(core = 1)] + fn c(_: c::Context) -> c::LateResources { + c::LateResources { Y: 0 } + } + + #[idle(core = 1, resources = [X])] + fn d(_: d::Context) -> ! { + loop {} + } +}; diff --git a/heterogeneous/examples/x-init.rs b/heterogeneous/examples/x-init.rs new file mode 100644 index 00000000..53e73805 --- /dev/null +++ b/heterogeneous/examples/x-init.rs @@ -0,0 +1,26 @@ +//! [compile-pass] Split initialization of late resources + +#![deny(unsafe_code)] +#![deny(warnings)] +#![no_main] +#![no_std] + +use panic_halt as _; + +#[rtfm::app(cores = 2, device = heterogeneous)] +const APP: () = { + extern "C" { + static mut X: u32; + static mut Y: u32; + } + + #[init(core = 0, late = [X])] + fn a(_: a::Context) -> a::LateResources { + a::LateResources { X: 0 } + } + + #[init(core = 1)] + fn b(_: b::Context) -> b::LateResources { + b::LateResources { Y: 0 } + } +}; diff --git a/heterogeneous/examples/x-schedule.rs b/heterogeneous/examples/x-schedule.rs new file mode 100644 index 00000000..cbfc01f9 --- /dev/null +++ b/heterogeneous/examples/x-schedule.rs @@ -0,0 +1,36 @@ +#![no_main] +#![no_std] + +use panic_halt as _; + +#[rtfm::app(cores = 2, device = heterogeneous, monotonic = heterogeneous::MT)] +const APP: () = { + #[init(core = 0, spawn = [ping])] + fn init(c: init::Context) { + c.spawn.ping().ok(); + } + + #[task(core = 0, schedule = [ping])] + fn pong(c: pong::Context) { + c.schedule.ping(c.scheduled + 1_000_000).ok(); + } + + #[task(core = 1, schedule = [pong])] + fn ping(c: ping::Context) { + c.schedule.pong(c.scheduled + 1_000_000).ok(); + } + + extern "C" { + #[core = 0] + fn I0(); + + #[core = 0] + fn I1(); + + #[core = 1] + fn I0(); + + #[core = 1] + fn I1(); + } +}; diff --git a/heterogeneous/examples/x-spawn.rs b/heterogeneous/examples/x-spawn.rs new file mode 100644 index 00000000..3fc64f6f --- /dev/null +++ b/heterogeneous/examples/x-spawn.rs @@ -0,0 +1,20 @@ +#![no_main] +#![no_std] + +use panic_halt as _; + +#[rtfm::app(cores = 2, device = heterogeneous)] +const APP: () = { + #[init(core = 0, spawn = [foo])] + fn init(c: init::Context) { + c.spawn.foo().ok(); + } + + #[task(core = 1)] + fn foo(_: foo::Context) {} + + extern "C" { + #[core = 1] + fn I0(); + } +}; diff --git a/mc/src/lib.rs b/heterogeneous/src/lib.rs index d86c0e8e..a4f0ec57 100644 --- a/mc/src/lib.rs +++ b/heterogeneous/src/lib.rs @@ -7,14 +7,15 @@ use core::{ ops::{Add, Sub}, }; -use cortex_m::interrupt::Nr; +use bare_metal::Nr; use rtfm::Monotonic; +// both cores have the exact same interrupts +pub use Interrupt_0 as Interrupt_1; + // Fake priority bits pub const NVIC_PRIO_BITS: u8 = 3; -pub struct CrossPend; - pub fn xpend(_core: u8, _interrupt: impl Nr) {} /// Fake monotonic timer @@ -72,28 +73,22 @@ impl PartialOrd for Instant { } // Fake interrupts -pub enum Interrupt { - I0, - I1, - I2, - I3, - I4, - I5, - I6, - I7, +#[allow(non_camel_case_types)] +#[derive(Clone, Copy)] +#[repr(u8)] +pub enum Interrupt_0 { + I0 = 0, + I1 = 1, + I2 = 2, + I3 = 3, + I4 = 4, + I5 = 5, + I6 = 6, + I7 = 7, } -unsafe impl Nr for Interrupt { +unsafe impl Nr for Interrupt_0 { fn nr(&self) -> u8 { - match self { - Interrupt::I0 => 0, - Interrupt::I1 => 1, - Interrupt::I2 => 2, - Interrupt::I3 => 3, - Interrupt::I4 => 4, - Interrupt::I5 => 5, - Interrupt::I6 => 6, - Interrupt::I7 => 7, - } + *self as u8 } } |