diff options
author | 2020-05-29 14:50:28 +0200 | |
---|---|---|
committer | 2020-05-29 14:50:28 +0200 | |
commit | 0ad311074e3d49a66174f59c47c4d6183ce7e3a0 (patch) | |
tree | 0dc14a960059209d864629c3134c318c978f1686 | |
parent | 1e827e24d024e910b44f6cc6db278e4c66a77683 (diff) | |
download | rtic-0ad311074e3d49a66174f59c47c4d6183ce7e3a0.tar.gz rtic-0ad311074e3d49a66174f59c47c4d6183ce7e3a0.tar.zst rtic-0ad311074e3d49a66174f59c47c4d6183ce7e3a0.zip |
allow handlers to be named 'main'
`#[init]`, `#[idle]` and `#[task]` handlers can now be named `main`
fixes #311
-rw-r--r-- | examples/t-htask-main.rs | 20 | ||||
-rw-r--r-- | examples/t-idle-main.rs | 20 | ||||
-rw-r--r-- | examples/t-init-main.rs | 15 | ||||
-rw-r--r-- | examples/t-stask-main.rs | 24 | ||||
-rw-r--r-- | macros/src/codegen/dispatchers.rs | 2 | ||||
-rw-r--r-- | macros/src/codegen/idle.rs | 2 | ||||
-rw-r--r-- | macros/src/codegen/init.rs | 2 |
7 files changed, 82 insertions, 3 deletions
diff --git a/examples/t-htask-main.rs b/examples/t-htask-main.rs new file mode 100644 index 00000000..d229d818 --- /dev/null +++ b/examples/t-htask-main.rs @@ -0,0 +1,20 @@ +#![deny(unsafe_code)] +#![deny(warnings)] +#![no_main] +#![no_std] + +use cortex_m_semihosting::debug; +use panic_semihosting as _; + +#[rtfm::app(device = lm3s6965)] +const APP: () = { + #[init] + fn init(_: init::Context) { + rtfm::pend(lm3s6965::Interrupt::UART0) + } + + #[task(binds = UART0)] + fn main(_: main::Context) { + debug::exit(debug::EXIT_SUCCESS); + } +}; diff --git a/examples/t-idle-main.rs b/examples/t-idle-main.rs new file mode 100644 index 00000000..d1bb1483 --- /dev/null +++ b/examples/t-idle-main.rs @@ -0,0 +1,20 @@ +#![deny(unsafe_code)] +#![deny(warnings)] +#![no_main] +#![no_std] + +use cortex_m_semihosting::debug; +use panic_semihosting as _; + +#[rtfm::app(device = lm3s6965)] +const APP: () = { + #[init] + fn init(_: init::Context) { + } + + #[idle] + fn main(_: main::Context) -> ! { + debug::exit(debug::EXIT_SUCCESS); + loop {} + } +}; diff --git a/examples/t-init-main.rs b/examples/t-init-main.rs new file mode 100644 index 00000000..e0d94d5f --- /dev/null +++ b/examples/t-init-main.rs @@ -0,0 +1,15 @@ +#![deny(unsafe_code)] +#![deny(warnings)] +#![no_main] +#![no_std] + +use cortex_m_semihosting::debug; +use panic_semihosting as _; + +#[rtfm::app(device = lm3s6965)] +const APP: () = { + #[init] + fn main(_: main::Context) { + debug::exit(debug::EXIT_SUCCESS); + } +}; diff --git a/examples/t-stask-main.rs b/examples/t-stask-main.rs new file mode 100644 index 00000000..b55161ea --- /dev/null +++ b/examples/t-stask-main.rs @@ -0,0 +1,24 @@ +#![deny(unsafe_code)] +#![deny(warnings)] +#![no_main] +#![no_std] + +use cortex_m_semihosting::debug; +use panic_semihosting as _; + +#[rtfm::app(device = lm3s6965)] +const APP: () = { + #[init(spawn = [main])] + fn init(cx: init::Context) { + cx.spawn.main().ok(); + } + + #[task] + fn main(_: main::Context) { + debug::exit(debug::EXIT_SUCCESS); + } + + extern "C" { + fn UART0(); + } +}; diff --git a/macros/src/codegen/dispatchers.rs b/macros/src/codegen/dispatchers.rs index 9a9cb102..1400786b 100644 --- a/macros/src/codegen/dispatchers.rs +++ b/macros/src/codegen/dispatchers.rs @@ -141,7 +141,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream #let_instant #fq.split().0.enqueue_unchecked(index); let priority = &rtfm::export::Priority::new(PRIORITY); - #name( + crate::#name( #locals_new #name::Context::new(priority #instant) #(,#pats)* diff --git a/macros/src/codegen/idle.rs b/macros/src/codegen/idle.rs index 35a72523..72432f67 100644 --- a/macros/src/codegen/idle.rs +++ b/macros/src/codegen/idle.rs @@ -72,7 +72,7 @@ pub fn codegen( )); let locals_new = locals_new.iter(); - let call_idle = quote!(#name( + let call_idle = quote!(crate::#name( #(#locals_new,)* #name::Context::new(&rtfm::export::Priority::new(0)) )); diff --git a/macros/src/codegen/init.rs b/macros/src/codegen/init.rs index 9c8ce31c..fc2faa34 100644 --- a/macros/src/codegen/init.rs +++ b/macros/src/codegen/init.rs @@ -105,7 +105,7 @@ pub fn codegen( let locals_new = locals_new.iter(); let call_init = - Some(quote!(let late = #name(#(#locals_new,)* #name::Context::new(core.into()));)); + Some(quote!(let late = crate::#name(#(#locals_new,)* #name::Context::new(core.into()));)); root_init.push(module::codegen(Context::Init(core), needs_lt, app, extra)); |