aboutsummaryrefslogtreecommitdiff
path: root/macros/src/codegen.rs
diff options
context:
space:
mode:
authorGravatar bors[bot] <26634292+bors[bot]@users.noreply.github.com> 2021-04-08 08:15:05 +0000
committerGravatar GitHub <noreply@github.com> 2021-04-08 08:15:05 +0000
commit83cdf00eecb0f14857b5e0f28e884b2120eabb18 (patch)
tree17f732cbb06dd480bd0881d0ec627cc173ba5bfc /macros/src/codegen.rs
parent6c8257bb73de0f68072467447692a1f7dff555f9 (diff)
parent51500a1d7096395be9162599fae647ec121db91d (diff)
downloadrtic-83cdf00eecb0f14857b5e0f28e884b2120eabb18.tar.gz
rtic-83cdf00eecb0f14857b5e0f28e884b2120eabb18.tar.zst
rtic-83cdf00eecb0f14857b5e0f28e884b2120eabb18.zip
Merge #466
466: Fix for type aliases in `mod app`, UB in `spawn_at`, and `#[cfg]` in hardware tasks r=AfoHT a=korken89 Type aliases such as the following did not work in `0.6-alpha`: ```rust use rtic::app; #[app(device = lm3s6965, dispatchers = [SSI0])] mod app { type Test = u32; #[task] fn t1(_: t1::Context, _val: Test) {} } ``` Plus that accessing associated constants of monotonic timers was not working as it should dues to the syntax and codegen transforming: ```rust #[monotonic(binds = SysTick, default = true)] type MyMono = DwtSystick<8_000_000>; // 8 MHz ``` into ```rust mod MyMono { // ... } ``` causing the original `type MyMono` to not exist anymore. This PR fixes this and adds test to check for this by doing the following expansion instead: ```rust #[monotonic(binds = SysTick, default = true)] type MyMono = DwtSystick<8_000_000>; // 8 MHz ``` into ```rust type MyMono = DwtSystick<8_000_000>; mod monotonics { mod MyMono { // ... } // And other monotonics go here as well } ``` **Breaking change** This causes a breaking change in accessing the `MyMono::now()` method which now exists under `monotonics::MyMono::now()`. --- Moreover a UB issue was found and fixed in `spawn_at` and hardware tasks properly propagate `#[cfg]`s. Closes #460 Closes #462 Closes #463 Co-authored-by: Emil Fresk <emil.fresk@gmail.com>
Diffstat (limited to 'macros/src/codegen.rs')
-rw-r--r--macros/src/codegen.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs
index c5d95687..cf728a7d 100644
--- a/macros/src/codegen.rs
+++ b/macros/src/codegen.rs
@@ -112,8 +112,6 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
let user_imports = &app.user_imports;
quote! {
- pub use rtic::Monotonic as _;
-
#[doc = #doc]
#[allow(non_snake_case)]
pub mod #name {
@@ -143,6 +141,18 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
})
.collect();
+ let monotonics = if !monotonic_parts.is_empty() {
+ quote!(
+ pub use rtic::Monotonic as _;
+
+ /// Holds static methods for each monotonic.
+ pub mod monotonics {
+ #(#monotonic_parts)*
+ }
+ )
+ } else {
+ quote!()
+ };
let rt_err = util::rt_err_ident();
quote!(
@@ -151,7 +161,7 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
/// Always include the device crate which contains the vector table
use #device as #rt_err;
- #(#monotonic_parts)*
+ #monotonics
#(#user_imports)*