aboutsummaryrefslogtreecommitdiff
path: root/macros
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <jorge@japaric.io> 2019-06-18 10:31:31 +0200
committerGravatar Jorge Aparicio <jorge@japaric.io> 2019-06-18 10:31:31 +0200
commit9897728709528a02545523bea72576abce89dc4c (patch)
tree49619bfb8e3e09cccbc9c2bd1854abfe1618c8fd /macros
parent81275bfa4f41e2066770087f3a33cad4227eab41 (diff)
downloadrtic-9897728709528a02545523bea72576abce89dc4c.tar.gz
rtic-9897728709528a02545523bea72576abce89dc4c.tar.zst
rtic-9897728709528a02545523bea72576abce89dc4c.zip
add homogeneous multi-core support
Diffstat (limited to 'macros')
-rw-r--r--macros/Cargo.toml1
-rw-r--r--macros/src/check.rs22
-rw-r--r--macros/src/codegen.rs3
-rw-r--r--macros/src/codegen/dispatchers.rs10
-rw-r--r--macros/src/codegen/hardware_tasks.rs6
-rw-r--r--macros/src/codegen/post_init.rs18
-rw-r--r--macros/src/codegen/pre_init.rs17
-rw-r--r--macros/src/codegen/resources.rs8
-rw-r--r--macros/src/codegen/software_tasks.rs8
-rw-r--r--macros/src/codegen/spawn_body.rs5
-rw-r--r--macros/src/codegen/timer_queue.rs8
-rw-r--r--macros/src/codegen/util.rs23
-rw-r--r--macros/src/lib.rs2
13 files changed, 112 insertions, 19 deletions
diff --git a/macros/Cargo.toml b/macros/Cargo.toml
index 2854dad4..c4e897fa 100644
--- a/macros/Cargo.toml
+++ b/macros/Cargo.toml
@@ -24,3 +24,4 @@ git = "https://github.com/japaric/rtfm-syntax"
[features]
heterogeneous = []
+homogeneous = []
diff --git a/macros/src/check.rs b/macros/src/check.rs
index c22a0f1f..619ec8fb 100644
--- a/macros/src/check.rs
+++ b/macros/src/check.rs
@@ -20,6 +20,28 @@ impl<'a> 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
// accepted
for (name, task) in app
diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs
index 86b4a67e..92766260 100644
--- a/macros/src/codegen.rs
+++ b/macros/src/codegen.rs
@@ -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 main = util::suffixed("main", core);
mains.push(quote!(
#[no_mangle]
#cfg_core
- unsafe fn main() -> ! {
+ unsafe extern "C" fn #main() -> ! {
#(#assertion_stmts)*
#(#pre_init_stmts)*
diff --git a/macros/src/codegen/dispatchers.rs b/macros/src/codegen/dispatchers.rs
index 65d25c78..988e3c84 100644
--- a/macros/src/codegen/dispatchers.rs
+++ b/macros/src/codegen/dispatchers.rs
@@ -55,8 +55,14 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
})),
)
} 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::Queue(rtfm::export::iQueue::u8())),
)
@@ -156,7 +162,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
receiver, level
);
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!(
#[allow(non_snake_case)]
#[doc = #doc]
diff --git a/macros/src/codegen/hardware_tasks.rs b/macros/src/codegen/hardware_tasks.rs
index e65bad56..e7f053d3 100644
--- a/macros/src/codegen/hardware_tasks.rs
+++ b/macros/src/codegen/hardware_tasks.rs
@@ -49,7 +49,11 @@ pub fn codegen(
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;
const_app.push(quote!(
diff --git a/macros/src/codegen/post_init.rs b/macros/src/codegen/post_init.rs
index f492d31d..3f1e4451 100644
--- a/macros/src/codegen/post_init.rs
+++ b/macros/src/codegen/post_init.rs
@@ -27,9 +27,16 @@ pub fn codegen(
// initialized
if analysis.initialization_barriers.contains_key(&core) {
let ib = util::init_barrier(core);
+ let shared = if cfg!(feature = "heterogeneous") {
+ Some(quote!(
+ #[rtfm::export::shared]
+ ))
+ } else {
+ None
+ };
const_app.push(quote!(
- #[rtfm::export::shared]
+ #shared
static #ib: rtfm::export::Barrier = rtfm::export::Barrier::new();
));
@@ -84,9 +91,16 @@ pub fn codegen(
if core == FIRST {
for &i in analysis.timer_queues.keys() {
let rv = util::rendezvous_ident(i);
+ let shared = if cfg!(feature = "heterogeneous") {
+ Some(quote!(
+ #[rtfm::export::shared]
+ ))
+ } else {
+ None
+ };
const_app.push(quote!(
- #[rtfm::export::shared]
+ #shared
static #rv: rtfm::export::Barrier = rtfm::export::Barrier::new();
));
diff --git a/macros/src/codegen/pre_init.rs b/macros/src/codegen/pre_init.rs
index 3ba17dcf..19fc6461 100644
--- a/macros/src/codegen/pre_init.rs
+++ b/macros/src/codegen/pre_init.rs
@@ -39,7 +39,8 @@ pub fn codegen(
}
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;
@@ -64,25 +65,33 @@ pub fn codegen(
stmts.push(quote!(let _ = [(); ((1 << #nvic_prio_bits) - #priority as usize)];));
// NOTE this also checks that the interrupt exists in the `Interrupt` enumeration
+ let interrupt = util::interrupt_ident(core, app.args.cores);
stmts.push(quote!(
core.NVIC.set_priority(
- #device::Interrupt::#name,
+ #device::#interrupt::#name,
rtfm::export::logical2hw(#priority, #nvic_prio_bits),
);
));
// NOTE unmask the interrupt *after* setting its priority: changing the priority of a pended
// 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
// we are ready to receive messages from *other* cores
if analysis.spawn_barriers.contains_key(&core) {
let sb = util::spawn_barrier(core);
+ let shared = if cfg!(feature = "heterogeneous") {
+ Some(quote!(
+ #[rtfm::export::shared]
+ ))
+ } else {
+ None
+ };
const_app.push(quote!(
- #[rtfm::export::shared]
+ #shared
static #sb: rtfm::export::Barrier = rtfm::export::Barrier::new();
));
diff --git a/macros/src/codegen/resources.rs b/macros/src/codegen/resources.rs
index 2dd10eac..2425681b 100644
--- a/macros/src/codegen/resources.rs
+++ b/macros/src/codegen/resources.rs
@@ -33,7 +33,13 @@ pub fn codegen(
} => util::cfg_core(*core, app.args.cores),
// 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 {
diff --git a/macros/src/codegen/software_tasks.rs b/macros/src/codegen/software_tasks.rs
index 8b2c0cd5..383a5d82 100644
--- a/macros/src/codegen/software_tasks.rs
+++ b/macros/src/codegen/software_tasks.rs
@@ -52,8 +52,14 @@ pub fn codegen(
})),
)
} 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::Queue(rtfm::export::iQueue::u8())),
)
diff --git a/macros/src/codegen/spawn_body.rs b/macros/src/codegen/spawn_body.rs
index 83cb5c0a..98bce074 100644
--- a/macros/src/codegen/spawn_body.rs
+++ b/macros/src/codegen/spawn_body.rs
@@ -45,14 +45,15 @@ pub fn codegen(
};
let device = extra.device;
+ let enum_ = util::interrupt_ident(receiver, app.args.cores);
let interrupt = &analysis.interrupts[&receiver][&priority];
let pend = if sender != receiver {
quote!(
- #device::xpend(#receiver, #device::Interrupt::#interrupt);
+ #device::xpend(#receiver, #device::#enum_::#interrupt);
)
} else {
quote!(
- rtfm::pend(#device::Interrupt::#interrupt);
+ rtfm::pend(#device::#enum_::#interrupt);
)
};
diff --git a/macros/src/codegen/timer_queue.rs b/macros/src/codegen/timer_queue.rs
index cb845774..d306ed5b 100644
--- a/macros/src/codegen/timer_queue.rs
+++ b/macros/src/codegen/timer_queue.rs
@@ -89,15 +89,16 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
let receiver = task.args.core;
let rq = util::rq_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 pend = if sender != receiver {
quote!(
- #device::xpend(#receiver, #device::Interrupt::#interrupt);
+ #device::xpend(#receiver, #device::#enum_::#interrupt);
)
} else {
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<_>>();
let priority = timer_queue.priority;
+ let sys_tick = util::suffixed("SysTick", sender);
items.push(quote!(
#cfg_sender
#[no_mangle]
- unsafe fn SysTick() {
+ unsafe fn #sys_tick() {
use rtfm::Mutex as _;
/// The priority of this handler
diff --git a/macros/src/codegen/util.rs b/macros/src/codegen/util.rs
index 203fcee8..8c43b350 100644
--- a/macros/src/codegen/util.rs
+++ b/macros/src/codegen/util.rs
@@ -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> {
if cores == 1 {
None
- } else {
+ } else if cfg!(feature = "heterogeneous") {
let core = core.to_string();
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())
}
+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
pub fn late_resources_ident(init: &Ident) -> Ident {
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
///
/// At most there's one timer queue per core
diff --git a/macros/src/lib.rs b/macros/src/lib.rs
index 6e1a7978..6502d9ca 100644
--- a/macros/src/lib.rs
+++ b/macros/src/lib.rs
@@ -20,7 +20,7 @@ pub fn app(args: TokenStream, input: TokenStream) -> TokenStream {
args,
input,
Settings {
- parse_cores: cfg!(feature = "heterogeneous"),
+ parse_cores: cfg!(feature = "heterogeneous") || cfg!(feature = "homogeneous"),
parse_exception: true,
parse_extern_interrupt: true,
parse_interrupt: true,