aboutsummaryrefslogtreecommitdiff
path: root/macros
diff options
context:
space:
mode:
Diffstat (limited to 'macros')
-rw-r--r--macros/Cargo.toml2
-rw-r--r--macros/src/check.rs14
-rw-r--r--macros/src/codegen.rs2
-rw-r--r--macros/src/codegen/init.rs28
-rw-r--r--macros/src/codegen/module.rs6
-rw-r--r--macros/src/codegen/post_init.rs3
-rw-r--r--macros/src/codegen/util.rs8
-rw-r--r--macros/src/lib.rs2
8 files changed, 46 insertions, 19 deletions
diff --git a/macros/Cargo.toml b/macros/Cargo.toml
index 3af48c76..6996bef4 100644
--- a/macros/Cargo.toml
+++ b/macros/Cargo.toml
@@ -22,5 +22,5 @@ proc-macro2 = "1"
proc-macro-error = "1"
quote = "1"
syn = "1"
-rtic-syntax = { git = "https://github.com/rtic-rs/rtic-syntax", branch = "master", version = "0.5.0-alpha.0" }
+rtic-syntax = { git = "https://github.com/rtic-rs/rtic-syntax", branch = "new_monotonic", version = "0.5.0-alpha.0" }
diff --git a/macros/src/check.rs b/macros/src/check.rs
index e3161cb9..42bd90db 100644
--- a/macros/src/check.rs
+++ b/macros/src/check.rs
@@ -62,18 +62,6 @@ pub fn app(app: &App, _analysis: &Analysis) -> parse::Result<Extra> {
for (name, task) in &app.hardware_tasks {
let name_s = task.args.binds.to_string();
match &*name_s {
- "SysTick" => {
- // If the timer queue is used, then SysTick is unavailable
- if app.args.monotonic.is_some() {
- return Err(parse::Error::new(
- name.span(),
- "this exception can't be used because it's being used by the runtime",
- ));
- } else {
- // OK
- }
- }
-
"NonMaskableInt" | "HardFault" => {
return Err(parse::Error::new(
name.span(),
@@ -88,7 +76,7 @@ pub fn app(app: &App, _analysis: &Analysis) -> parse::Result<Extra> {
if let Some(device) = app.args.device.clone() {
Ok(Extra {
device,
- monotonic: app.args.monotonic.clone(),
+ monotonic: None,
peripherals: app.args.peripherals,
})
} else {
diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs
index 3cddf570..52940bc3 100644
--- a/macros/src/codegen.rs
+++ b/macros/src/codegen.rs
@@ -61,8 +61,6 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
use super::*;
#[no_mangle]
unsafe extern "C" fn #main() -> ! {
- let _TODO: () = ();
-
#(#assertion_stmts)*
#(#pre_init_stmts)*
diff --git a/macros/src/codegen/init.rs b/macros/src/codegen/init.rs
index 6376ce31..6b57add1 100644
--- a/macros/src/codegen/init.rs
+++ b/macros/src/codegen/init.rs
@@ -58,6 +58,24 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> CodegenResult {
}
));
+ let monotonic_types: Vec<_> = app
+ .monotonics
+ .iter()
+ .map(|(_, monotonic)| {
+ let mono = &monotonic.ty;
+ quote! {#mono}
+ })
+ .collect();
+ let monotonics = util::monotonics_ident(&name);
+
+ root_init.push(quote!(
+ /// Monotonics used by the system
+ #[allow(non_snake_case)]
+ pub struct #monotonics(
+ #(#monotonic_types),*
+ );
+ ));
+
let mut locals_pat = None;
let mut locals_new = None;
if !init.locals.is_empty() {
@@ -72,10 +90,16 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> CodegenResult {
let attrs = &init.attrs;
let stmts = &init.stmts;
let locals_pat = locals_pat.iter();
+
+ let mut user_init_return = vec![quote! {#name::LateResources}];
+ if !app.monotonics.is_empty() {
+ user_init_return.push(quote! {#name::Monotonics});
+ }
+
let user_init = Some(quote!(
#(#attrs)*
#[allow(non_snake_case)]
- fn #name(#(#locals_pat,)* #context: #name::Context) -> #name::LateResources {
+ fn #name(#(#locals_pat,)* #context: #name::Context) -> (#(#user_init_return,)*) {
#(#stmts)*
}
));
@@ -92,7 +116,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> CodegenResult {
let app_path = quote! {crate::#app_name};
let locals_new = locals_new.iter();
let call_init = Some(
- quote!(let late = #app_path::#name(#(#locals_new,)* #name::Context::new(core.into()));),
+ quote!(let (late, monotonics) = #app_path::#name(#(#locals_new,)* #name::Context::new(core.into()));),
);
root_init.push(module::codegen(
diff --git a/macros/src/codegen/module.rs b/macros/src/codegen/module.rs
index 2ff4801e..d398a1a8 100644
--- a/macros/src/codegen/module.rs
+++ b/macros/src/codegen/module.rs
@@ -131,11 +131,17 @@ pub fn codegen(
if let Context::Init = ctxt {
let init = &app.inits.first().unwrap();
let late_resources = util::late_resources_ident(&init.name);
+ let monotonics = util::monotonics_ident(&init.name);
items.push(quote!(
#[doc(inline)]
pub use super::#late_resources as LateResources;
));
+
+ items.push(quote!(
+ #[doc(inline)]
+ pub use super::#monotonics as Monotonics;
+ ));
}
let doc = match ctxt {
diff --git a/macros/src/codegen/post_init.rs b/macros/src/codegen/post_init.rs
index 5545944d..9174daeb 100644
--- a/macros/src/codegen/post_init.rs
+++ b/macros/src/codegen/post_init.rs
@@ -25,6 +25,9 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> {
}
}
+ // Forget the monotonics so they won't be dropped.
+ stmts.push(quote!(core::mem::forget(monotonics);));
+
// Enable the interrupts -- this completes the `init`-ialization phase
stmts.push(quote!(rtic::export::interrupt::enable();));
diff --git a/macros/src/codegen/util.rs b/macros/src/codegen/util.rs
index fb8f1a84..4273ee2c 100644
--- a/macros/src/codegen/util.rs
+++ b/macros/src/codegen/util.rs
@@ -111,6 +111,14 @@ pub fn late_resources_ident(init: &Ident) -> Ident {
)
}
+/// Generates a pre-reexport identifier for the "monotonics" struct
+pub fn monotonics_ident(init: &Ident) -> Ident {
+ Ident::new(
+ &format!("{}Monotonics", init.to_string()),
+ Span::call_site(),
+ )
+}
+
/// Mangle an ident
pub fn mangle_ident(ident: &Ident) -> Ident {
Ident::new(
diff --git a/macros/src/lib.rs b/macros/src/lib.rs
index dc37eaea..c9136e55 100644
--- a/macros/src/lib.rs
+++ b/macros/src/lib.rs
@@ -1,4 +1,4 @@
-#![deny(warnings)]
+// #![deny(warnings)]
extern crate proc_macro;