mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-12-24 02:49:34 +01:00
Namespace cleanup
This commit is contained in:
parent
f96b25fdf2
commit
f076b33bb9
11 changed files with 31 additions and 63 deletions
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)*
|
||||
}
|
||||
)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)*
|
||||
|
|
|
@ -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()
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue