aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Emil Fresk <emil.fresk@gmail.com> 2020-10-21 20:20:26 +0200
committerGravatar Emil Fresk <emil.fresk@gmail.com> 2020-10-21 20:25:13 +0200
commitf076b33bb91e9cd2cb1f71ba22ebfebab085d3a8 (patch)
treef5b3ca8705ee1038365a4b8744f650dbceabad01
parentf96b25fdf2d7421cc16830a4ccac4ebb3e69cc5d (diff)
downloadrtic-f076b33bb91e9cd2cb1f71ba22ebfebab085d3a8.tar.gz
rtic-f076b33bb91e9cd2cb1f71ba22ebfebab085d3a8.tar.zst
rtic-f076b33bb91e9cd2cb1f71ba22ebfebab085d3a8.zip
Namespace cleanup
-rw-r--r--examples/generics.rs4
-rw-r--r--examples/shared-with-init.rs2
-rw-r--r--examples/static.rs10
-rw-r--r--examples/task-local-minimal.rs3
-rw-r--r--examples/task-local.rs5
-rw-r--r--macros/src/codegen.rs35
-rw-r--r--macros/src/codegen/dispatchers.rs2
-rw-r--r--macros/src/codegen/post_init.rs5
-rw-r--r--macros/src/codegen/resources.rs16
-rw-r--r--macros/src/codegen/software_tasks.rs8
-rw-r--r--macros/src/codegen/timer_queue.rs4
11 files changed, 31 insertions, 63 deletions
diff --git a/examples/generics.rs b/examples/generics.rs
index b13baeb7..16327fb3 100644
--- a/examples/generics.rs
+++ b/examples/generics.rs
@@ -36,7 +36,7 @@ mod app {
hprintln!("UART0(STATE = {})", *STATE).unwrap();
// second argument has type `resources::shared`
- advance(STATE, c.resources.shared);
+ super::advance(STATE, c.resources.shared);
rtic::pend(Interrupt::UART1);
@@ -53,7 +53,7 @@ mod app {
*c.resources.shared += 0;
// second argument has type `Exclusive<u32>`
- advance(STATE, Exclusive(c.resources.shared));
+ super::advance(STATE, Exclusive(c.resources.shared));
}
}
diff --git a/examples/shared-with-init.rs b/examples/shared-with-init.rs
index 049a38bf..ec055886 100644
--- a/examples/shared-with-init.rs
+++ b/examples/shared-with-init.rs
@@ -12,9 +12,9 @@ pub struct MustBeSend;
#[app(device = lm3s6965)]
mod app {
+ use super::MustBeSend;
use cortex_m_semihosting::debug;
use lm3s6965::Interrupt;
- use super::MustBeSend;
#[resources]
struct Resources {
diff --git a/examples/static.rs b/examples/static.rs
index cd46145a..3b6cd4cd 100644
--- a/examples/static.rs
+++ b/examples/static.rs
@@ -21,7 +21,7 @@ mod app {
// Late resources
#[resources]
struct Resources {
- p: Producer<'static, u32, U4>,
+ ppppp: Producer<'static, u32, U4>,
c: Consumer<'static, u32, U4>,
}
@@ -29,10 +29,10 @@ mod app {
fn init(_: init::Context) -> init::LateResources {
static mut Q: Queue<u32, U4> = Queue(i::Queue::new());
- let (p, c) = Q.split();
+ let (ppppp, c) = Q.split();
// Initialization of late resources
- init::LateResources { p, c }
+ init::LateResources { ppppp, c }
}
#[idle(resources = [c])]
@@ -48,10 +48,10 @@ mod app {
}
}
- #[task(binds = UART0, resources = [p])]
+ #[task(binds = UART0, resources = [ppppp])]
fn uart0(c: uart0::Context) {
static mut KALLE: u32 = 0;
*KALLE += 1;
- c.resources.p.enqueue(42).unwrap();
+ c.resources.ppppp.enqueue(42).unwrap();
}
}
diff --git a/examples/task-local-minimal.rs b/examples/task-local-minimal.rs
index fd5ac68a..6e25c10d 100644
--- a/examples/task-local-minimal.rs
+++ b/examples/task-local-minimal.rs
@@ -4,11 +4,12 @@
#![no_main]
#![no_std]
-use cortex_m_semihosting::{debug, hprintln};
use panic_semihosting as _;
#[rtic::app(device = lm3s6965)]
mod app {
+ use cortex_m_semihosting::{debug, hprintln};
+
#[resources]
struct Resources {
// A local (move), late resource
diff --git a/examples/task-local.rs b/examples/task-local.rs
index 8f0dfc79..462a0d31 100644
--- a/examples/task-local.rs
+++ b/examples/task-local.rs
@@ -5,12 +5,13 @@
#![no_main]
#![no_std]
-use cortex_m_semihosting::{debug, hprintln};
-use lm3s6965::Interrupt;
use panic_semihosting as _;
#[rtic::app(device = lm3s6965)]
mod app {
+ use cortex_m_semihosting::{debug, hprintln};
+ use lm3s6965::Interrupt;
+
#[resources]
struct Resources {
// An early resource
diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs
index c38b47c9..b9755368 100644
--- a/macros/src/codegen.rs
+++ b/macros/src/codegen.rs
@@ -73,14 +73,10 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
}
));
- let (mod_app_resources, mod_resources, mod_resources_imports) =
- resources::codegen(app, analysis, extra);
+ let (mod_app_resources, mod_resources) = resources::codegen(app, analysis, extra);
- let (
- mod_app_hardware_tasks,
- root_hardware_tasks,
- user_hardware_tasks,
- ) = hardware_tasks::codegen(app, analysis, extra);
+ let (mod_app_hardware_tasks, root_hardware_tasks, user_hardware_tasks) =
+ hardware_tasks::codegen(app, analysis, extra);
let (mod_app_software_tasks, root_software_tasks, user_software_tasks) =
software_tasks::codegen(app, analysis, extra);
@@ -97,9 +93,11 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
let task_list = analysis.tasks.clone();
let mut tasks = vec![];
+
if !task_list.is_empty() {
tasks.push(quote!(
- enum Tasks {
+ #[allow(non_camel_case_types)]
+ pub enum Tasks {
#(#task_list),*
}
));
@@ -107,65 +105,46 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
quote!(
/// Implementation details
- mod #name {
+ pub mod #name {
/// Always include the device crate which contains the vector table
use #device as you_must_enable_the_rt_feature_for_the_pac_in_your_cargo_toml;
- /// 2
#(#user_imports)*
/// User code from within the module
#(#user_code)*
/// User code end
- /// 3
#(#user)*
- /// 4
#(#user_hardware_tasks)*
- /// 5
#(#user_software_tasks)*
- /// 6
#(#root)*
- /// 7
#mod_resources
- /// 8
#(#root_hardware_tasks)*
- /// 9
#(#root_software_tasks)*
- /// 10
/// Unused
#(#tasks)*
- /// 13
- #(#mod_resources_imports)*
-
- /// 14
/// app module
#(#mod_app)*
- /// 15
#(#mod_app_resources)*
- /// 16
#(#mod_app_hardware_tasks)*
- /// 17
#(#mod_app_software_tasks)*
- /// 18
#(#mod_app_dispatchers)*
- /// 19
#(#mod_app_timer_queue)*
- /// 20
#(#mains)*
}
)
diff --git a/macros/src/codegen/dispatchers.rs b/macros/src/codegen/dispatchers.rs
index bd4061d1..a76f622e 100644
--- a/macros/src/codegen/dispatchers.rs
+++ b/macros/src/codegen/dispatchers.rs
@@ -57,7 +57,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
);
items.push(quote!(
#[doc = #doc]
- pub static mut #rq: #rq_ty = #rq_expr;
+ static mut #rq: #rq_ty = #rq_expr;
));
let arms = channel
diff --git a/macros/src/codegen/post_init.rs b/macros/src/codegen/post_init.rs
index c35c6976..8defc85d 100644
--- a/macros/src/codegen/post_init.rs
+++ b/macros/src/codegen/post_init.rs
@@ -2,7 +2,7 @@ use proc_macro2::TokenStream as TokenStream2;
use quote::quote;
use rtic_syntax::ast::App;
-use crate::analyze::Analysis;
+use crate::{analyze::Analysis, codegen::util};
/// Generates code that runs after `#[init]` returns
pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> {
@@ -12,13 +12,14 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> {
if analysis.late_resources.len() > 0 {
// BTreeSet wrapped in a vector
for name in analysis.late_resources.first().unwrap() {
+ let mangled_name = util::mangle_ident(&name);
// If it's live
let cfgs = app.late_resources[name].cfgs.clone();
if analysis.locations.get(name).is_some() {
// Need to also include the cfgs
stmts.push(quote!(
#(#cfgs)*
- #name.as_mut_ptr().write(late.#name);
+ #mangled_name.as_mut_ptr().write(late.#name);
));
}
}
diff --git a/macros/src/codegen/resources.rs b/macros/src/codegen/resources.rs
index d5ec583e..0db4f728 100644
--- a/macros/src/codegen/resources.rs
+++ b/macros/src/codegen/resources.rs
@@ -14,12 +14,9 @@ pub fn codegen(
Vec<TokenStream2>,
// mod_resources -- the `resources` module
TokenStream2,
- // mod_resources_imports -- the `resources` module imports
- Vec<TokenStream2>,
) {
let mut mod_app = vec![];
let mut mod_resources = vec![];
- let mut mod_resources_imports = vec![];
for (name, res, expr, _) in app.resources(analysis) {
let cfgs = &res.cfgs;
@@ -86,12 +83,6 @@ pub fn codegen(
)
};
- mod_resources_imports.push(quote!(
- #[allow(non_camel_case_types)]
- #(#cfgs)*
- use super::resources::#name;
- ));
-
mod_app.push(util::impl_mutex(
extra,
cfgs,
@@ -107,11 +98,6 @@ pub fn codegen(
let mod_resources = if mod_resources.is_empty() {
quote!()
} else {
- // Also import the resource module
- mod_resources_imports.push(quote!(
- use super::resources;
- ));
-
quote!(mod resources {
use rtic::export::Priority;
@@ -119,5 +105,5 @@ pub fn codegen(
})
};
- (mod_app, mod_resources, mod_resources_imports)
+ (mod_app, mod_resources)
}
diff --git a/macros/src/codegen/software_tasks.rs b/macros/src/codegen/software_tasks.rs
index f5757a12..323060c4 100644
--- a/macros/src/codegen/software_tasks.rs
+++ b/macros/src/codegen/software_tasks.rs
@@ -50,7 +50,7 @@ pub fn codegen(
mod_app.push(quote!(
/// Queue version of a free-list that keeps track of empty slots in
/// the following buffers
- pub static mut #fq: #fq_ty = #fq_expr;
+ static mut #fq: #fq_ty = #fq_expr;
));
let ref elems = (0..cap)
@@ -64,7 +64,7 @@ pub fn codegen(
mod_app.push(quote!(
#uninit
/// Buffer that holds the instants associated to the inputs of a task
- pub static mut #instants:
+ static mut #instants:
[core::mem::MaybeUninit<<#m as rtic::Monotonic>::Instant>; #cap_lit] =
[#(#elems,)*];
));
@@ -75,7 +75,7 @@ pub fn codegen(
mod_app.push(quote!(
#uninit
/// Buffer that holds the inputs of a task
- pub static mut #inputs_ident: [core::mem::MaybeUninit<#input_ty>; #cap_lit] =
+ static mut #inputs_ident: [core::mem::MaybeUninit<#input_ty>; #cap_lit] =
[#(#elems,)*];
));
@@ -113,7 +113,7 @@ pub fn codegen(
#(#attrs)*
#(#cfgs)*
#[allow(non_snake_case)]
- pub fn #name(#(#locals_pat,)* #context: #name::Context #(,#inputs)*) {
+ fn #name(#(#locals_pat,)* #context: #name::Context #(,#inputs)*) {
use rtic::Mutex as _;
#(#stmts)*
diff --git a/macros/src/codegen/timer_queue.rs b/macros/src/codegen/timer_queue.rs
index c898a7fd..c081076e 100644
--- a/macros/src/codegen/timer_queue.rs
+++ b/macros/src/codegen/timer_queue.rs
@@ -31,7 +31,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
#[doc = #doc]
#[allow(non_camel_case_types)]
#[derive(Clone, Copy)]
- pub enum #t {
+ enum #t {
#(#variants,)*
}
));
@@ -52,7 +52,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
items.push(quote!(
#[doc = #doc]
- pub static mut #tq: #tq_ty = rtic::export::TimerQueue(
+ static mut #tq: #tq_ty = rtic::export::TimerQueue(
rtic::export::BinaryHeap(
rtic::export::iBinaryHeap::new()
)