mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-29 15:04:32 +01:00
add homogeneous multi-core support
This commit is contained in:
parent
81275bfa4f
commit
9897728709
33 changed files with 385 additions and 53 deletions
|
@ -74,6 +74,7 @@ compiletest_rs = "0.3.22"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
heterogeneous = ["cortex-m-rtfm-macros/heterogeneous", "microamp"]
|
heterogeneous = ["cortex-m-rtfm-macros/heterogeneous", "microamp"]
|
||||||
|
homogeneous = ["cortex-m-rtfm-macros/homogeneous", "microamp"]
|
||||||
# used for testing this crate; do not use in applications
|
# used for testing this crate; do not use in applications
|
||||||
__v7 =[]
|
__v7 =[]
|
||||||
|
|
||||||
|
@ -83,6 +84,7 @@ lto = true
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
|
"heterogeneous",
|
||||||
|
"homogeneous",
|
||||||
"macros",
|
"macros",
|
||||||
"mc",
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -43,7 +43,7 @@ main() {
|
||||||
cargo test --test multi --features heterogeneous --target $T
|
cargo test --test multi --features heterogeneous --target $T
|
||||||
|
|
||||||
# multi-core compile-pass tests
|
# multi-core compile-pass tests
|
||||||
pushd mc
|
pushd heterogeneous
|
||||||
local exs=(
|
local exs=(
|
||||||
smallest
|
smallest
|
||||||
x-init-2
|
x-init-2
|
||||||
|
@ -91,6 +91,8 @@ main() {
|
||||||
cargo check --target $T --examples --features __v7
|
cargo check --target $T --examples --features __v7
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
cargo check -p homogeneous --target $T --examples
|
||||||
|
|
||||||
# run-pass tests
|
# run-pass tests
|
||||||
case $T in
|
case $T in
|
||||||
thumbv6m-none-eabi | thumbv7m-none-eabi)
|
thumbv6m-none-eabi | thumbv7m-none-eabi)
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
[package]
|
[package]
|
||||||
authors = ["Jorge Aparicio <jorge@japaric.io>"]
|
authors = ["Jorge Aparicio <jorge@japaric.io>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
name = "mc"
|
name = "heterogeneous"
|
||||||
# this crate is only used for testing
|
# this crate is only used for testing
|
||||||
publish = false
|
publish = false
|
||||||
version = "0.0.0-alpha.0"
|
version = "0.0.0-alpha.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cortex-m = "0.6.0"
|
bare-metal = "0.2.4"
|
||||||
|
|
||||||
[dependencies.cortex-m-rtfm]
|
[dependencies.cortex-m-rtfm]
|
||||||
path = ".."
|
path = ".."
|
1
heterogeneous/README.md
Normal file
1
heterogeneous/README.md
Normal file
|
@ -0,0 +1 @@
|
||||||
|
This directory contains *heterogeneous* multi-core compile pass tests.
|
7
heterogeneous/examples/smallest.rs
Normal file
7
heterogeneous/examples/smallest.rs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#![no_main]
|
||||||
|
#![no_std]
|
||||||
|
|
||||||
|
use panic_halt as _;
|
||||||
|
|
||||||
|
#[rtfm::app(cores = 2, device = heterogeneous)]
|
||||||
|
const APP: () = {};
|
39
heterogeneous/examples/x-init-2.rs
Normal file
39
heterogeneous/examples/x-init-2.rs
Normal file
|
@ -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 {}
|
||||||
|
}
|
||||||
|
};
|
26
heterogeneous/examples/x-init.rs
Normal file
26
heterogeneous/examples/x-init.rs
Normal file
|
@ -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 }
|
||||||
|
}
|
||||||
|
};
|
36
heterogeneous/examples/x-schedule.rs
Normal file
36
heterogeneous/examples/x-schedule.rs
Normal file
|
@ -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();
|
||||||
|
}
|
||||||
|
};
|
20
heterogeneous/examples/x-spawn.rs
Normal file
20
heterogeneous/examples/x-spawn.rs
Normal file
|
@ -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();
|
||||||
|
}
|
||||||
|
};
|
|
@ -7,14 +7,15 @@ use core::{
|
||||||
ops::{Add, Sub},
|
ops::{Add, Sub},
|
||||||
};
|
};
|
||||||
|
|
||||||
use cortex_m::interrupt::Nr;
|
use bare_metal::Nr;
|
||||||
use rtfm::Monotonic;
|
use rtfm::Monotonic;
|
||||||
|
|
||||||
|
// both cores have the exact same interrupts
|
||||||
|
pub use Interrupt_0 as Interrupt_1;
|
||||||
|
|
||||||
// Fake priority bits
|
// Fake priority bits
|
||||||
pub const NVIC_PRIO_BITS: u8 = 3;
|
pub const NVIC_PRIO_BITS: u8 = 3;
|
||||||
|
|
||||||
pub struct CrossPend;
|
|
||||||
|
|
||||||
pub fn xpend(_core: u8, _interrupt: impl Nr) {}
|
pub fn xpend(_core: u8, _interrupt: impl Nr) {}
|
||||||
|
|
||||||
/// Fake monotonic timer
|
/// Fake monotonic timer
|
||||||
|
@ -72,28 +73,22 @@ impl PartialOrd for Instant {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fake interrupts
|
// Fake interrupts
|
||||||
pub enum Interrupt {
|
#[allow(non_camel_case_types)]
|
||||||
I0,
|
#[derive(Clone, Copy)]
|
||||||
I1,
|
#[repr(u8)]
|
||||||
I2,
|
pub enum Interrupt_0 {
|
||||||
I3,
|
I0 = 0,
|
||||||
I4,
|
I1 = 1,
|
||||||
I5,
|
I2 = 2,
|
||||||
I6,
|
I3 = 3,
|
||||||
I7,
|
I4 = 4,
|
||||||
|
I5 = 5,
|
||||||
|
I6 = 6,
|
||||||
|
I7 = 7,
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl Nr for Interrupt {
|
unsafe impl Nr for Interrupt_0 {
|
||||||
fn nr(&self) -> u8 {
|
fn nr(&self) -> u8 {
|
||||||
match self {
|
*self as u8
|
||||||
Interrupt::I0 => 0,
|
|
||||||
Interrupt::I1 => 1,
|
|
||||||
Interrupt::I2 => 2,
|
|
||||||
Interrupt::I3 => 3,
|
|
||||||
Interrupt::I4 => 4,
|
|
||||||
Interrupt::I5 => 5,
|
|
||||||
Interrupt::I6 => 6,
|
|
||||||
Interrupt::I7 => 7,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
17
homogeneous/Cargo.toml
Normal file
17
homogeneous/Cargo.toml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
[package]
|
||||||
|
authors = ["Jorge Aparicio <jorge@japaric.io>"]
|
||||||
|
edition = "2018"
|
||||||
|
name = "homogeneous"
|
||||||
|
# this crate is only used for testing
|
||||||
|
publish = false
|
||||||
|
version = "0.0.0-alpha.0"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
bare-metal = "0.2.4"
|
||||||
|
|
||||||
|
[dependencies.cortex-m-rtfm]
|
||||||
|
path = ".."
|
||||||
|
features = ["homogeneous"]
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
panic-halt = "0.2.0"
|
1
homogeneous/README.md
Normal file
1
homogeneous/README.md
Normal file
|
@ -0,0 +1 @@
|
||||||
|
This directory contains *homogeneous* multi-core compile pass tests.
|
|
@ -3,5 +3,5 @@
|
||||||
|
|
||||||
use panic_halt as _;
|
use panic_halt as _;
|
||||||
|
|
||||||
#[rtfm::app(cores = 2, device = mc)]
|
#[rtfm::app(cores = 2, device = homogeneous)]
|
||||||
const APP: () = {};
|
const APP: () = {};
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
use panic_halt as _;
|
use panic_halt as _;
|
||||||
|
|
||||||
#[rtfm::app(cores = 2, device = mc)]
|
#[rtfm::app(cores = 2, device = homogeneous)]
|
||||||
const APP: () = {
|
const APP: () = {
|
||||||
extern "C" {
|
extern "C" {
|
||||||
// owned by core #1 but initialized by core #0
|
// owned by core #1 but initialized by core #0
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
use panic_halt as _;
|
use panic_halt as _;
|
||||||
|
|
||||||
#[rtfm::app(cores = 2, device = mc)]
|
#[rtfm::app(cores = 2, device = homogeneous)]
|
||||||
const APP: () = {
|
const APP: () = {
|
||||||
extern "C" {
|
extern "C" {
|
||||||
static mut X: u32;
|
static mut X: u32;
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
use panic_halt as _;
|
use panic_halt as _;
|
||||||
|
|
||||||
#[rtfm::app(cores = 2, device = mc, monotonic = mc::MT)]
|
#[rtfm::app(cores = 2, device = homogeneous, monotonic = homogeneous::MT)]
|
||||||
const APP: () = {
|
const APP: () = {
|
||||||
#[init(core = 0, spawn = [ping])]
|
#[init(core = 0, spawn = [ping])]
|
||||||
fn init(c: init::Context) {
|
fn init(c: init::Context) {
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
use panic_halt as _;
|
use panic_halt as _;
|
||||||
|
|
||||||
#[rtfm::app(cores = 2, device = mc)]
|
#[rtfm::app(cores = 2, device = homogeneous)]
|
||||||
const APP: () = {
|
const APP: () = {
|
||||||
#[init(core = 0, spawn = [foo])]
|
#[init(core = 0, spawn = [foo])]
|
||||||
fn init(c: init::Context) {
|
fn init(c: init::Context) {
|
94
homogeneous/src/lib.rs
Normal file
94
homogeneous/src/lib.rs
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
//! Fake multi-core PAC
|
||||||
|
|
||||||
|
#![no_std]
|
||||||
|
|
||||||
|
use core::{
|
||||||
|
cmp::Ordering,
|
||||||
|
ops::{Add, Sub},
|
||||||
|
};
|
||||||
|
|
||||||
|
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 fn xpend(_core: u8, _interrupt: impl Nr) {}
|
||||||
|
|
||||||
|
/// Fake monotonic timer
|
||||||
|
pub struct MT;
|
||||||
|
|
||||||
|
unsafe impl Monotonic for MT {
|
||||||
|
type Instant = Instant;
|
||||||
|
|
||||||
|
fn ratio() -> u32 {
|
||||||
|
1
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn reset() {
|
||||||
|
(0xE0001004 as *mut u32).write_volatile(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn now() -> Instant {
|
||||||
|
unsafe { Instant((0xE0001004 as *const u32).read_volatile() as i32) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn zero() -> Instant {
|
||||||
|
Instant(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Eq, PartialEq)]
|
||||||
|
pub struct Instant(i32);
|
||||||
|
|
||||||
|
impl Add<u32> for Instant {
|
||||||
|
type Output = Instant;
|
||||||
|
|
||||||
|
fn add(self, rhs: u32) -> Self {
|
||||||
|
Instant(self.0.wrapping_add(rhs as i32))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Sub for Instant {
|
||||||
|
type Output = u32;
|
||||||
|
|
||||||
|
fn sub(self, rhs: Self) -> u32 {
|
||||||
|
self.0.checked_sub(rhs.0).unwrap() as u32
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Ord for Instant {
|
||||||
|
fn cmp(&self, rhs: &Self) -> Ordering {
|
||||||
|
self.0.wrapping_sub(rhs.0).cmp(&0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialOrd for Instant {
|
||||||
|
fn partial_cmp(&self, rhs: &Self) -> Option<Ordering> {
|
||||||
|
Some(self.cmp(rhs))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fake interrupts
|
||||||
|
#[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_0 {
|
||||||
|
fn nr(&self) -> u8 {
|
||||||
|
*self as u8
|
||||||
|
}
|
||||||
|
}
|
|
@ -24,3 +24,4 @@ git = "https://github.com/japaric/rtfm-syntax"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
heterogeneous = []
|
heterogeneous = []
|
||||||
|
homogeneous = []
|
||||||
|
|
|
@ -20,6 +20,28 @@ impl<'a> Extra<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn app<'a>(app: &'a App, analysis: &Analysis) -> parse::Result<Extra<'a>> {
|
pub fn app<'a>(app: &'a App, analysis: &Analysis) -> parse::Result<Extra<'a>> {
|
||||||
|
if cfg!(feature = "homogeneous") {
|
||||||
|
// this RTFM mode uses the same namespace for all cores so we need to check that the
|
||||||
|
// identifiers used for each core `#[init]` and `#[idle]` functions don't collide
|
||||||
|
let mut seen = HashSet::new();
|
||||||
|
|
||||||
|
for name in app
|
||||||
|
.inits
|
||||||
|
.values()
|
||||||
|
.map(|init| &init.name)
|
||||||
|
.chain(app.idles.values().map(|idle| &idle.name))
|
||||||
|
{
|
||||||
|
if seen.contains(name) {
|
||||||
|
return Err(parse::Error::new(
|
||||||
|
name.span(),
|
||||||
|
"this identifier is already being used by another core",
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
seen.insert(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// check that all exceptions are valid; only exceptions with configurable priorities are
|
// check that all exceptions are valid; only exceptions with configurable priorities are
|
||||||
// accepted
|
// accepted
|
||||||
for (name, task) in app
|
for (name, task) in app
|
||||||
|
|
|
@ -67,10 +67,11 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
|
||||||
));
|
));
|
||||||
|
|
||||||
let cfg_core = util::cfg_core(core, app.args.cores);
|
let cfg_core = util::cfg_core(core, app.args.cores);
|
||||||
|
let main = util::suffixed("main", core);
|
||||||
mains.push(quote!(
|
mains.push(quote!(
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
#cfg_core
|
#cfg_core
|
||||||
unsafe fn main() -> ! {
|
unsafe extern "C" fn #main() -> ! {
|
||||||
#(#assertion_stmts)*
|
#(#assertion_stmts)*
|
||||||
|
|
||||||
#(#pre_init_stmts)*
|
#(#pre_init_stmts)*
|
||||||
|
|
|
@ -55,8 +55,14 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
|
||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
let shared = if cfg!(feature = "heterogeneous") {
|
||||||
|
Some(quote!(#[rtfm::export::shared]))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
(
|
(
|
||||||
Some(quote!(#[rtfm::export::shared])),
|
shared,
|
||||||
quote!(rtfm::export::MCRQ<#t, #n>),
|
quote!(rtfm::export::MCRQ<#t, #n>),
|
||||||
quote!(rtfm::export::Queue(rtfm::export::iQueue::u8())),
|
quote!(rtfm::export::Queue(rtfm::export::iQueue::u8())),
|
||||||
)
|
)
|
||||||
|
@ -156,7 +162,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
|
||||||
receiver, level
|
receiver, level
|
||||||
);
|
);
|
||||||
let cfg_receiver = util::cfg_core(receiver, app.args.cores);
|
let cfg_receiver = util::cfg_core(receiver, app.args.cores);
|
||||||
let interrupt = &interrupts[&level];
|
let interrupt = util::suffixed(&interrupts[&level].to_string(), receiver);
|
||||||
items.push(quote!(
|
items.push(quote!(
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
#[doc = #doc]
|
#[doc = #doc]
|
||||||
|
|
|
@ -49,7 +49,11 @@ pub fn codegen(
|
||||||
quote!(#name::Locals::new(),)
|
quote!(#name::Locals::new(),)
|
||||||
};
|
};
|
||||||
|
|
||||||
let symbol = task.args.binds(name);
|
let symbol = if cfg!(feature = "homogeneous") {
|
||||||
|
util::suffixed(&task.args.binds(name).to_string(), core)
|
||||||
|
} else {
|
||||||
|
task.args.binds(name).clone()
|
||||||
|
};
|
||||||
let priority = task.args.priority;
|
let priority = task.args.priority;
|
||||||
|
|
||||||
const_app.push(quote!(
|
const_app.push(quote!(
|
||||||
|
|
|
@ -27,9 +27,16 @@ pub fn codegen(
|
||||||
// initialized
|
// initialized
|
||||||
if analysis.initialization_barriers.contains_key(&core) {
|
if analysis.initialization_barriers.contains_key(&core) {
|
||||||
let ib = util::init_barrier(core);
|
let ib = util::init_barrier(core);
|
||||||
|
let shared = if cfg!(feature = "heterogeneous") {
|
||||||
|
Some(quote!(
|
||||||
|
#[rtfm::export::shared]
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
const_app.push(quote!(
|
const_app.push(quote!(
|
||||||
#[rtfm::export::shared]
|
#shared
|
||||||
static #ib: rtfm::export::Barrier = rtfm::export::Barrier::new();
|
static #ib: rtfm::export::Barrier = rtfm::export::Barrier::new();
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -84,9 +91,16 @@ pub fn codegen(
|
||||||
if core == FIRST {
|
if core == FIRST {
|
||||||
for &i in analysis.timer_queues.keys() {
|
for &i in analysis.timer_queues.keys() {
|
||||||
let rv = util::rendezvous_ident(i);
|
let rv = util::rendezvous_ident(i);
|
||||||
|
let shared = if cfg!(feature = "heterogeneous") {
|
||||||
|
Some(quote!(
|
||||||
|
#[rtfm::export::shared]
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
const_app.push(quote!(
|
const_app.push(quote!(
|
||||||
#[rtfm::export::shared]
|
#shared
|
||||||
static #rv: rtfm::export::Barrier = rtfm::export::Barrier::new();
|
static #rv: rtfm::export::Barrier = rtfm::export::Barrier::new();
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,8 @@ pub fn codegen(
|
||||||
}
|
}
|
||||||
|
|
||||||
stmts.push(quote!(
|
stmts.push(quote!(
|
||||||
let mut core = rtfm::export::Peripherals::steal();
|
// NOTE(transmute) to avoid debug_assertion in multi-core mode
|
||||||
|
let mut core: rtfm::export::Peripherals = core::mem::transmute(());
|
||||||
));
|
));
|
||||||
|
|
||||||
let device = extra.device;
|
let device = extra.device;
|
||||||
|
@ -64,25 +65,33 @@ pub fn codegen(
|
||||||
stmts.push(quote!(let _ = [(); ((1 << #nvic_prio_bits) - #priority as usize)];));
|
stmts.push(quote!(let _ = [(); ((1 << #nvic_prio_bits) - #priority as usize)];));
|
||||||
|
|
||||||
// NOTE this also checks that the interrupt exists in the `Interrupt` enumeration
|
// NOTE this also checks that the interrupt exists in the `Interrupt` enumeration
|
||||||
|
let interrupt = util::interrupt_ident(core, app.args.cores);
|
||||||
stmts.push(quote!(
|
stmts.push(quote!(
|
||||||
core.NVIC.set_priority(
|
core.NVIC.set_priority(
|
||||||
#device::Interrupt::#name,
|
#device::#interrupt::#name,
|
||||||
rtfm::export::logical2hw(#priority, #nvic_prio_bits),
|
rtfm::export::logical2hw(#priority, #nvic_prio_bits),
|
||||||
);
|
);
|
||||||
));
|
));
|
||||||
|
|
||||||
// NOTE unmask the interrupt *after* setting its priority: changing the priority of a pended
|
// NOTE unmask the interrupt *after* setting its priority: changing the priority of a pended
|
||||||
// interrupt is implementation defined
|
// interrupt is implementation defined
|
||||||
stmts.push(quote!(core.NVIC.enable(#device::Interrupt::#name);));
|
stmts.push(quote!(core.NVIC.enable(#device::#interrupt::#name);));
|
||||||
}
|
}
|
||||||
|
|
||||||
// cross-spawn barriers: now that priorities have been set and the interrupts have been unmasked
|
// cross-spawn barriers: now that priorities have been set and the interrupts have been unmasked
|
||||||
// we are ready to receive messages from *other* cores
|
// we are ready to receive messages from *other* cores
|
||||||
if analysis.spawn_barriers.contains_key(&core) {
|
if analysis.spawn_barriers.contains_key(&core) {
|
||||||
let sb = util::spawn_barrier(core);
|
let sb = util::spawn_barrier(core);
|
||||||
|
let shared = if cfg!(feature = "heterogeneous") {
|
||||||
|
Some(quote!(
|
||||||
|
#[rtfm::export::shared]
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
const_app.push(quote!(
|
const_app.push(quote!(
|
||||||
#[rtfm::export::shared]
|
#shared
|
||||||
static #sb: rtfm::export::Barrier = rtfm::export::Barrier::new();
|
static #sb: rtfm::export::Barrier = rtfm::export::Barrier::new();
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,13 @@ pub fn codegen(
|
||||||
} => util::cfg_core(*core, app.args.cores),
|
} => util::cfg_core(*core, app.args.cores),
|
||||||
|
|
||||||
// shared `static`s and cross-initialized resources need to be in `.shared` memory
|
// shared `static`s and cross-initialized resources need to be in `.shared` memory
|
||||||
_ => Some(quote!(#[rtfm::export::shared])),
|
_ => {
|
||||||
|
if cfg!(feature = "heterogeneous") {
|
||||||
|
Some(quote!(#[rtfm::export::shared]))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let (ty, expr) = if let Some(expr) = expr {
|
let (ty, expr) = if let Some(expr) = expr {
|
||||||
|
|
|
@ -52,8 +52,14 @@ pub fn codegen(
|
||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
let shared = if cfg!(feature = "heterogeneous") {
|
||||||
|
Some(quote!(#[rtfm::export::shared]))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
(
|
(
|
||||||
Some(quote!(#[rtfm::export::shared])),
|
shared,
|
||||||
quote!(rtfm::export::MCFQ<#cap_ty>),
|
quote!(rtfm::export::MCFQ<#cap_ty>),
|
||||||
quote!(rtfm::export::Queue(rtfm::export::iQueue::u8())),
|
quote!(rtfm::export::Queue(rtfm::export::iQueue::u8())),
|
||||||
)
|
)
|
||||||
|
|
|
@ -45,14 +45,15 @@ pub fn codegen(
|
||||||
};
|
};
|
||||||
|
|
||||||
let device = extra.device;
|
let device = extra.device;
|
||||||
|
let enum_ = util::interrupt_ident(receiver, app.args.cores);
|
||||||
let interrupt = &analysis.interrupts[&receiver][&priority];
|
let interrupt = &analysis.interrupts[&receiver][&priority];
|
||||||
let pend = if sender != receiver {
|
let pend = if sender != receiver {
|
||||||
quote!(
|
quote!(
|
||||||
#device::xpend(#receiver, #device::Interrupt::#interrupt);
|
#device::xpend(#receiver, #device::#enum_::#interrupt);
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
quote!(
|
quote!(
|
||||||
rtfm::pend(#device::Interrupt::#interrupt);
|
rtfm::pend(#device::#enum_::#interrupt);
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -89,15 +89,16 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
|
||||||
let receiver = task.args.core;
|
let receiver = task.args.core;
|
||||||
let rq = util::rq_ident(receiver, priority, sender);
|
let rq = util::rq_ident(receiver, priority, sender);
|
||||||
let rqt = util::spawn_t_ident(receiver, priority, sender);
|
let rqt = util::spawn_t_ident(receiver, priority, sender);
|
||||||
|
let enum_ = util::interrupt_ident(receiver, app.args.cores);
|
||||||
let interrupt = &analysis.interrupts[&receiver][&priority];
|
let interrupt = &analysis.interrupts[&receiver][&priority];
|
||||||
|
|
||||||
let pend = if sender != receiver {
|
let pend = if sender != receiver {
|
||||||
quote!(
|
quote!(
|
||||||
#device::xpend(#receiver, #device::Interrupt::#interrupt);
|
#device::xpend(#receiver, #device::#enum_::#interrupt);
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
quote!(
|
quote!(
|
||||||
rtfm::pend(#device::Interrupt::#interrupt);
|
rtfm::pend(#device::#enum_::#interrupt);
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -115,10 +116,11 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let priority = timer_queue.priority;
|
let priority = timer_queue.priority;
|
||||||
|
let sys_tick = util::suffixed("SysTick", sender);
|
||||||
items.push(quote!(
|
items.push(quote!(
|
||||||
#cfg_sender
|
#cfg_sender
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
unsafe fn SysTick() {
|
unsafe fn #sys_tick() {
|
||||||
use rtfm::Mutex as _;
|
use rtfm::Mutex as _;
|
||||||
|
|
||||||
/// The priority of this handler
|
/// The priority of this handler
|
||||||
|
|
|
@ -27,9 +27,11 @@ pub fn capacity_typenum(capacity: u8, round_up_to_power_of_two: bool) -> TokenSt
|
||||||
pub fn cfg_core(core: Core, cores: u8) -> Option<TokenStream2> {
|
pub fn cfg_core(core: Core, cores: u8) -> Option<TokenStream2> {
|
||||||
if cores == 1 {
|
if cores == 1 {
|
||||||
None
|
None
|
||||||
} else {
|
} else if cfg!(feature = "heterogeneous") {
|
||||||
let core = core.to_string();
|
let core = core.to_string();
|
||||||
Some(quote!(#[cfg(core = #core)]))
|
Some(quote!(#[cfg(core = #core)]))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,6 +104,15 @@ pub fn instants_ident(task: &Ident, sender: Core) -> Ident {
|
||||||
Ident::new(&format!("{}_S{}_INSTANTS", task, sender), Span::call_site())
|
Ident::new(&format!("{}_S{}_INSTANTS", task, sender), Span::call_site())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn interrupt_ident(core: Core, cores: u8) -> Ident {
|
||||||
|
let span = Span::call_site();
|
||||||
|
if cores == 1 {
|
||||||
|
Ident::new("Interrupt", span)
|
||||||
|
} else {
|
||||||
|
Ident::new(&format!("Interrupt_{}", core), span)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Generates a pre-reexport identifier for the "late resources" struct
|
/// Generates a pre-reexport identifier for the "late resources" struct
|
||||||
pub fn late_resources_ident(init: &Ident) -> Ident {
|
pub fn late_resources_ident(init: &Ident) -> Ident {
|
||||||
Ident::new(
|
Ident::new(
|
||||||
|
@ -245,6 +256,16 @@ pub fn spawn_t_ident(receiver: Core, priority: u8, sender: Core) -> Ident {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn suffixed(name: &str, core: u8) -> Ident {
|
||||||
|
let span = Span::call_site();
|
||||||
|
|
||||||
|
if cfg!(feature = "homogeneous") {
|
||||||
|
Ident::new(&format!("{}_{}", name, core), span)
|
||||||
|
} else {
|
||||||
|
Ident::new(name, span)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Generates an identifier for a timer queue
|
/// Generates an identifier for a timer queue
|
||||||
///
|
///
|
||||||
/// At most there's one timer queue per core
|
/// At most there's one timer queue per core
|
||||||
|
|
|
@ -20,7 +20,7 @@ pub fn app(args: TokenStream, input: TokenStream) -> TokenStream {
|
||||||
args,
|
args,
|
||||||
input,
|
input,
|
||||||
Settings {
|
Settings {
|
||||||
parse_cores: cfg!(feature = "heterogeneous"),
|
parse_cores: cfg!(feature = "heterogeneous") || cfg!(feature = "homogeneous"),
|
||||||
parse_exception: true,
|
parse_exception: true,
|
||||||
parse_extern_interrupt: true,
|
parse_extern_interrupt: true,
|
||||||
parse_interrupt: true,
|
parse_interrupt: true,
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
This directory contains multi-core compile pass tests.
|
|
|
@ -47,7 +47,7 @@ use cortex_m::{
|
||||||
interrupt::Nr,
|
interrupt::Nr,
|
||||||
peripheral::{CBP, CPUID, DCB, DWT, FPB, FPU, ITM, MPU, NVIC, SCB, TPIU},
|
peripheral::{CBP, CPUID, DCB, DWT, FPB, FPU, ITM, MPU, NVIC, SCB, TPIU},
|
||||||
};
|
};
|
||||||
#[cfg(not(feature = "heterogeneous"))]
|
#[cfg(all(not(feature = "heterogeneous"), not(feature = "homogeneous")))]
|
||||||
use cortex_m_rt as _; // vector table
|
use cortex_m_rt as _; // vector table
|
||||||
pub use cortex_m_rtfm_macros::app;
|
pub use cortex_m_rtfm_macros::app;
|
||||||
pub use rtfm_core::{Exclusive, Mutex};
|
pub use rtfm_core::{Exclusive, Mutex};
|
||||||
|
|
Loading…
Reference in a new issue