From 67d5ade4fdbb2fb4a1c13715e4829412f4007d75 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Wed, 10 May 2023 14:24:32 +0200 Subject: [PATCH] Fix zero prio tasks when all async tasks have default (no) arguments --- examples/rp2040_local_i2c_init/Cargo.toml | 2 +- examples/stm32f3_blinky/Cargo.toml | 2 +- rtic-macros/Cargo.toml | 2 +- rtic-macros/src/syntax/ast.rs | 2 +- rtic-macros/ui/task-no-prio.rs | 19 +++++++++++++++++++ rtic-macros/ui/task-no-prio.stderr | 5 +++++ rtic/Cargo.toml | 4 ++-- rtic/examples/async-delay.rs | 9 --------- rtic/examples/spawn_loop.rs | 3 ++- rtic/ui/extern-interrupt-not-enough.rs | 2 +- 10 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 rtic-macros/ui/task-no-prio.rs create mode 100644 rtic-macros/ui/task-no-prio.stderr diff --git a/examples/rp2040_local_i2c_init/Cargo.toml b/examples/rp2040_local_i2c_init/Cargo.toml index 9737c99460..2d004e105c 100644 --- a/examples/rp2040_local_i2c_init/Cargo.toml +++ b/examples/rp2040_local_i2c_init/Cargo.toml @@ -10,7 +10,7 @@ edition = "2021" [dependencies.rtic] path = "../../rtic" -version = "=2.0.0-alpha.1" +version = "=2.0.0-alpha.2" features = ["thumbv6-backend"] [dependencies.rtic-monotonics] diff --git a/examples/stm32f3_blinky/Cargo.toml b/examples/stm32f3_blinky/Cargo.toml index 99f100919f..be4d03d010 100644 --- a/examples/stm32f3_blinky/Cargo.toml +++ b/examples/stm32f3_blinky/Cargo.toml @@ -9,7 +9,7 @@ version = "0.1.0" [dependencies.rtic] path = "../../rtic" -version = "=2.0.0-alpha.1" +version = "=2.0.0-alpha.2" features = ["thumbv7-backend"] [dependencies.rtic-monotonics] diff --git a/rtic-macros/Cargo.toml b/rtic-macros/Cargo.toml index 71358c0b56..f7e6c7b32c 100644 --- a/rtic-macros/Cargo.toml +++ b/rtic-macros/Cargo.toml @@ -22,7 +22,7 @@ name = "rtic-macros" readme = "../README.md" repository = "https://github.com/rtic-rs/rtic" -version = "2.0.0-alpha.0" +version = "2.0.0-alpha.2" [lib] proc-macro = true diff --git a/rtic-macros/src/syntax/ast.rs b/rtic-macros/src/syntax/ast.rs index d5510cbd5d..3f4956cc9b 100644 --- a/rtic-macros/src/syntax/ast.rs +++ b/rtic-macros/src/syntax/ast.rs @@ -242,7 +242,7 @@ pub struct SoftwareTaskArgs { impl Default for SoftwareTaskArgs { fn default() -> Self { Self { - priority: 1, + priority: 0, local_resources: LocalResources::new(), shared_resources: SharedResources::new(), } diff --git a/rtic-macros/ui/task-no-prio.rs b/rtic-macros/ui/task-no-prio.rs new file mode 100644 index 0000000000..832777730b --- /dev/null +++ b/rtic-macros/ui/task-no-prio.rs @@ -0,0 +1,19 @@ +#![no_main] + +#[rtic_macros::mock_app(device = mock)] +mod app { + #[shared] + struct Shared {} + + #[local] + struct Local {} + + #[init] + fn init(_: init::Context) -> (Shared, Local) {} + + #[idle] + fn idle(_: idle::Context) -> ! {} + + #[task] + async fn task1(_: task1::Context) {} +} diff --git a/rtic-macros/ui/task-no-prio.stderr b/rtic-macros/ui/task-no-prio.stderr new file mode 100644 index 0000000000..4ff97ec42c --- /dev/null +++ b/rtic-macros/ui/task-no-prio.stderr @@ -0,0 +1,5 @@ +error: Async task "task1" has priority 0, but `#[idle]` is defined. 0-priority async tasks are only allowed if there is no `#[idle]`. + --> ui/task-no-prio.rs:18:14 + | +18 | async fn task1(_: task1::Context) {} + | ^^^^^ diff --git a/rtic/Cargo.toml b/rtic/Cargo.toml index f28c9a721a..c2f3045089 100644 --- a/rtic/Cargo.toml +++ b/rtic/Cargo.toml @@ -22,7 +22,7 @@ name = "rtic" readme = "../README.md" repository = "https://github.com/rtic-rs/rtic" -version = "2.0.0-alpha.1" +version = "2.0.0-alpha.2" [package.metadata.docs.rs] features = ["rtic-macros/test-template"] @@ -36,7 +36,7 @@ bare-metal = "1.0.0" #portable-atomic = { version = "0.3.19" } atomic-polyfill = "1" rtic-monotonics = { path = "../rtic-monotonics", version = "1.0.0-alpha.1", optional = true } -rtic-macros = { path = "../rtic-macros", version = "2.0.0-alpha.0" } +rtic-macros = { path = "../rtic-macros", version = "2.0.0-alpha.2" } rtic-core = "1" critical-section = "1" diff --git a/rtic/examples/async-delay.rs b/rtic/examples/async-delay.rs index cdffa620ba..98d67f9c6b 100644 --- a/rtic/examples/async-delay.rs +++ b/rtic/examples/async-delay.rs @@ -34,15 +34,6 @@ mod app { (Shared {}, Local {}) } - #[idle] - fn idle(_: idle::Context) -> ! { - // debug::exit(debug::EXIT_SUCCESS); - loop { - // hprintln!("idle"); - cortex_m::asm::wfi(); // put the MCU in sleep mode until interrupt occurs - } - } - #[task] async fn foo(_cx: foo::Context) { hprintln!("hello from foo"); diff --git a/rtic/examples/spawn_loop.rs b/rtic/examples/spawn_loop.rs index 9328a94250..2da25d1472 100644 --- a/rtic/examples/spawn_loop.rs +++ b/rtic/examples/spawn_loop.rs @@ -25,6 +25,7 @@ mod app { (Shared {}, Local {}) } + #[idle] fn idle(_: idle::Context) -> ! { for _ in 0..3 { @@ -35,7 +36,7 @@ mod app { loop {} } - #[task] + #[task(priority = 1)] async fn foo(_: foo::Context) { hprintln!("foo"); } diff --git a/rtic/ui/extern-interrupt-not-enough.rs b/rtic/ui/extern-interrupt-not-enough.rs index 94c8ee116a..74ae116132 100644 --- a/rtic/ui/extern-interrupt-not-enough.rs +++ b/rtic/ui/extern-interrupt-not-enough.rs @@ -13,6 +13,6 @@ mod app { (Shared {}, Local {}) } - #[task] + #[task(priority = 1)] async fn a(_: a::Context) {} }