Namespace cleanup

This commit is contained in:
Emil Fresk 2020-10-21 20:20:26 +02:00
parent f96b25fdf2
commit f076b33bb9
11 changed files with 31 additions and 63 deletions

View file

@ -36,7 +36,7 @@ mod app {
hprintln!("UART0(STATE = {})", *STATE).unwrap(); hprintln!("UART0(STATE = {})", *STATE).unwrap();
// second argument has type `resources::shared` // second argument has type `resources::shared`
advance(STATE, c.resources.shared); super::advance(STATE, c.resources.shared);
rtic::pend(Interrupt::UART1); rtic::pend(Interrupt::UART1);
@ -53,7 +53,7 @@ mod app {
*c.resources.shared += 0; *c.resources.shared += 0;
// second argument has type `Exclusive<u32>` // second argument has type `Exclusive<u32>`
advance(STATE, Exclusive(c.resources.shared)); super::advance(STATE, Exclusive(c.resources.shared));
} }
} }

View file

@ -12,9 +12,9 @@ pub struct MustBeSend;
#[app(device = lm3s6965)] #[app(device = lm3s6965)]
mod app { mod app {
use super::MustBeSend;
use cortex_m_semihosting::debug; use cortex_m_semihosting::debug;
use lm3s6965::Interrupt; use lm3s6965::Interrupt;
use super::MustBeSend;
#[resources] #[resources]
struct Resources { struct Resources {

View file

@ -21,7 +21,7 @@ mod app {
// Late resources // Late resources
#[resources] #[resources]
struct Resources { struct Resources {
p: Producer<'static, u32, U4>, ppppp: Producer<'static, u32, U4>,
c: Consumer<'static, u32, U4>, c: Consumer<'static, u32, U4>,
} }
@ -29,10 +29,10 @@ mod app {
fn init(_: init::Context) -> init::LateResources { fn init(_: init::Context) -> init::LateResources {
static mut Q: Queue<u32, U4> = Queue(i::Queue::new()); static mut Q: Queue<u32, U4> = Queue(i::Queue::new());
let (p, c) = Q.split(); let (ppppp, c) = Q.split();
// Initialization of late resources // Initialization of late resources
init::LateResources { p, c } init::LateResources { ppppp, c }
} }
#[idle(resources = [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) { fn uart0(c: uart0::Context) {
static mut KALLE: u32 = 0; static mut KALLE: u32 = 0;
*KALLE += 1; *KALLE += 1;
c.resources.p.enqueue(42).unwrap(); c.resources.ppppp.enqueue(42).unwrap();
} }
} }

View file

@ -4,11 +4,12 @@
#![no_main] #![no_main]
#![no_std] #![no_std]
use cortex_m_semihosting::{debug, hprintln};
use panic_semihosting as _; use panic_semihosting as _;
#[rtic::app(device = lm3s6965)] #[rtic::app(device = lm3s6965)]
mod app { mod app {
use cortex_m_semihosting::{debug, hprintln};
#[resources] #[resources]
struct Resources { struct Resources {
// A local (move), late resource // A local (move), late resource

View file

@ -5,12 +5,13 @@
#![no_main] #![no_main]
#![no_std] #![no_std]
use cortex_m_semihosting::{debug, hprintln};
use lm3s6965::Interrupt;
use panic_semihosting as _; use panic_semihosting as _;
#[rtic::app(device = lm3s6965)] #[rtic::app(device = lm3s6965)]
mod app { mod app {
use cortex_m_semihosting::{debug, hprintln};
use lm3s6965::Interrupt;
#[resources] #[resources]
struct Resources { struct Resources {
// An early resource // An early resource

View file

@ -73,14 +73,10 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
} }
)); ));
let (mod_app_resources, mod_resources, mod_resources_imports) = let (mod_app_resources, mod_resources) = resources::codegen(app, analysis, extra);
resources::codegen(app, analysis, extra);
let ( let (mod_app_hardware_tasks, root_hardware_tasks, user_hardware_tasks) =
mod_app_hardware_tasks, hardware_tasks::codegen(app, analysis, extra);
root_hardware_tasks,
user_hardware_tasks,
) = hardware_tasks::codegen(app, analysis, extra);
let (mod_app_software_tasks, root_software_tasks, user_software_tasks) = let (mod_app_software_tasks, root_software_tasks, user_software_tasks) =
software_tasks::codegen(app, analysis, extra); 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 task_list = analysis.tasks.clone();
let mut tasks = vec![]; let mut tasks = vec![];
if !task_list.is_empty() { if !task_list.is_empty() {
tasks.push(quote!( tasks.push(quote!(
enum Tasks { #[allow(non_camel_case_types)]
pub enum Tasks {
#(#task_list),* #(#task_list),*
} }
)); ));
@ -107,65 +105,46 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
quote!( quote!(
/// Implementation details /// Implementation details
mod #name { pub mod #name {
/// Always include the device crate which contains the vector table /// 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; use #device as you_must_enable_the_rt_feature_for_the_pac_in_your_cargo_toml;
/// 2
#(#user_imports)* #(#user_imports)*
/// User code from within the module /// User code from within the module
#(#user_code)* #(#user_code)*
/// User code end /// User code end
/// 3
#(#user)* #(#user)*
/// 4
#(#user_hardware_tasks)* #(#user_hardware_tasks)*
/// 5
#(#user_software_tasks)* #(#user_software_tasks)*
/// 6
#(#root)* #(#root)*
/// 7
#mod_resources #mod_resources
/// 8
#(#root_hardware_tasks)* #(#root_hardware_tasks)*
/// 9
#(#root_software_tasks)* #(#root_software_tasks)*
/// 10
/// Unused /// Unused
#(#tasks)* #(#tasks)*
/// 13
#(#mod_resources_imports)*
/// 14
/// app module /// app module
#(#mod_app)* #(#mod_app)*
/// 15
#(#mod_app_resources)* #(#mod_app_resources)*
/// 16
#(#mod_app_hardware_tasks)* #(#mod_app_hardware_tasks)*
/// 17
#(#mod_app_software_tasks)* #(#mod_app_software_tasks)*
/// 18
#(#mod_app_dispatchers)* #(#mod_app_dispatchers)*
/// 19
#(#mod_app_timer_queue)* #(#mod_app_timer_queue)*
/// 20
#(#mains)* #(#mains)*
} }
) )

View file

@ -57,7 +57,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
); );
items.push(quote!( items.push(quote!(
#[doc = #doc] #[doc = #doc]
pub static mut #rq: #rq_ty = #rq_expr; static mut #rq: #rq_ty = #rq_expr;
)); ));
let arms = channel let arms = channel

View file

@ -2,7 +2,7 @@ use proc_macro2::TokenStream as TokenStream2;
use quote::quote; use quote::quote;
use rtic_syntax::ast::App; use rtic_syntax::ast::App;
use crate::analyze::Analysis; use crate::{analyze::Analysis, codegen::util};
/// Generates code that runs after `#[init]` returns /// Generates code that runs after `#[init]` returns
pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> { 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 { if analysis.late_resources.len() > 0 {
// BTreeSet wrapped in a vector // BTreeSet wrapped in a vector
for name in analysis.late_resources.first().unwrap() { for name in analysis.late_resources.first().unwrap() {
let mangled_name = util::mangle_ident(&name);
// If it's live // If it's live
let cfgs = app.late_resources[name].cfgs.clone(); let cfgs = app.late_resources[name].cfgs.clone();
if analysis.locations.get(name).is_some() { if analysis.locations.get(name).is_some() {
// Need to also include the cfgs // Need to also include the cfgs
stmts.push(quote!( stmts.push(quote!(
#(#cfgs)* #(#cfgs)*
#name.as_mut_ptr().write(late.#name); #mangled_name.as_mut_ptr().write(late.#name);
)); ));
} }
} }

View file

@ -14,12 +14,9 @@ pub fn codegen(
Vec<TokenStream2>, Vec<TokenStream2>,
// mod_resources -- the `resources` module // mod_resources -- the `resources` module
TokenStream2, TokenStream2,
// mod_resources_imports -- the `resources` module imports
Vec<TokenStream2>,
) { ) {
let mut mod_app = vec![]; let mut mod_app = vec![];
let mut mod_resources = vec![]; let mut mod_resources = vec![];
let mut mod_resources_imports = vec![];
for (name, res, expr, _) in app.resources(analysis) { for (name, res, expr, _) in app.resources(analysis) {
let cfgs = &res.cfgs; 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( mod_app.push(util::impl_mutex(
extra, extra,
cfgs, cfgs,
@ -107,11 +98,6 @@ pub fn codegen(
let mod_resources = if mod_resources.is_empty() { let mod_resources = if mod_resources.is_empty() {
quote!() quote!()
} else { } else {
// Also import the resource module
mod_resources_imports.push(quote!(
use super::resources;
));
quote!(mod resources { quote!(mod resources {
use rtic::export::Priority; use rtic::export::Priority;
@ -119,5 +105,5 @@ pub fn codegen(
}) })
}; };
(mod_app, mod_resources, mod_resources_imports) (mod_app, mod_resources)
} }

View file

@ -50,7 +50,7 @@ pub fn codegen(
mod_app.push(quote!( mod_app.push(quote!(
/// Queue version of a free-list that keeps track of empty slots in /// Queue version of a free-list that keeps track of empty slots in
/// the following buffers /// the following buffers
pub static mut #fq: #fq_ty = #fq_expr; static mut #fq: #fq_ty = #fq_expr;
)); ));
let ref elems = (0..cap) let ref elems = (0..cap)
@ -64,7 +64,7 @@ pub fn codegen(
mod_app.push(quote!( mod_app.push(quote!(
#uninit #uninit
/// Buffer that holds the instants associated to the inputs of a task /// 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] = [core::mem::MaybeUninit<<#m as rtic::Monotonic>::Instant>; #cap_lit] =
[#(#elems,)*]; [#(#elems,)*];
)); ));
@ -75,7 +75,7 @@ pub fn codegen(
mod_app.push(quote!( mod_app.push(quote!(
#uninit #uninit
/// Buffer that holds the inputs of a task /// 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,)*]; [#(#elems,)*];
)); ));
@ -113,7 +113,7 @@ pub fn codegen(
#(#attrs)* #(#attrs)*
#(#cfgs)* #(#cfgs)*
#[allow(non_snake_case)] #[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 _; use rtic::Mutex as _;
#(#stmts)* #(#stmts)*

View file

@ -31,7 +31,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
#[doc = #doc] #[doc = #doc]
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
pub enum #t { enum #t {
#(#variants,)* #(#variants,)*
} }
)); ));
@ -52,7 +52,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
items.push(quote!( items.push(quote!(
#[doc = #doc] #[doc = #doc]
pub static mut #tq: #tq_ty = rtic::export::TimerQueue( static mut #tq: #tq_ty = rtic::export::TimerQueue(
rtic::export::BinaryHeap( rtic::export::BinaryHeap(
rtic::export::iBinaryHeap::new() rtic::export::iBinaryHeap::new()
) )