aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Román Cárdenas <rcardenas.rod@gmail.com> 2023-03-29 21:07:36 +0200
committerGravatar GitHub <noreply@github.com> 2023-03-29 21:07:36 +0200
commitce508a1882b1cc8735c4fd901a0ad868da5fe77b (patch)
treee17930b11f05f3bfaba59f3e579dd4f49aae4b91
parent06ddfb7ab8d04fa519bf66a40ec7a98a5e04aa07 (diff)
parent31055fa64a6e178caa45f8a8e862ded6a68d3e55 (diff)
downloadrtic-ce508a1882b1cc8735c4fd901a0ad868da5fe77b.tar.gz
rtic-ce508a1882b1cc8735c4fd901a0ad868da5fe77b.tar.zst
rtic-ce508a1882b1cc8735c4fd901a0ad868da5fe77b.zip
Merge branch 'master' into master
-rw-r--r--book/en/src/by-example.md2
-rw-r--r--rtic-macros/src/analyze.rs9
-rw-r--r--rtic-macros/src/codegen.rs3
-rw-r--r--rtic-macros/src/codegen/bindings/cortex.rs16
-rw-r--r--rtic-macros/src/codegen/bindings/template.rs4
-rw-r--r--rtic-macros/src/syntax/parse.rs7
-rw-r--r--rtic-monotonics/src/rp2040.rs2
-rw-r--r--rtic-monotonics/src/systick.rs2
-rw-r--r--rtic/CHANGELOG.md1
-rw-r--r--rtic/examples/async-delay.rs2
-rw-r--r--rtic/examples/async-task.rs4
-rw-r--r--rtic/examples/async-timeout.rs2
-rw-r--r--rtic/examples/common.rs4
-rw-r--r--rtic/examples/destructure.rs4
-rw-r--r--rtic/examples/locals.rs4
-rw-r--r--rtic/examples/not-sync.rs4
-rw-r--r--rtic/examples/static.rs2
17 files changed, 55 insertions, 17 deletions
diff --git a/book/en/src/by-example.md b/book/en/src/by-example.md
index a2e5b278..e5cf67a0 100644
--- a/book/en/src/by-example.md
+++ b/book/en/src/by-example.md
@@ -7,7 +7,7 @@ All examples in this part of the book are accessible at the
The examples are runnable on QEMU (emulating a Cortex M3 target),
thus no special hardware required to follow along.
-[repoexamples]: https://github.com/rtic-rs/rtic/tree/master/examples
+[repoexamples]: https://github.com/rtic-rs/rtic/tree/master/rtic/examples
## Running an example
diff --git a/rtic-macros/src/analyze.rs b/rtic-macros/src/analyze.rs
index 65774f6c..2227308d 100644
--- a/rtic-macros/src/analyze.rs
+++ b/rtic-macros/src/analyze.rs
@@ -11,6 +11,7 @@ use syn::Ident;
pub struct Analysis {
parent: analyze::Analysis,
pub interrupts: BTreeMap<Priority, (Ident, Dispatcher)>,
+ pub max_async_prio: Option<u8>,
}
impl ops::Deref for Analysis {
@@ -42,8 +43,16 @@ pub fn app(analysis: analyze::Analysis, app: &App) -> Analysis {
.map(|p| (p, available_interrupt.pop().expect("UNREACHABLE")))
.collect();
+ let max_async_prio = app
+ .hardware_tasks
+ .iter()
+ .map(|(_, task)| task.args.priority)
+ .min()
+ .map(|v| v - 1); // One less than the smallest HW task
+
Analysis {
parent: analysis,
interrupts,
+ max_async_prio,
}
}
diff --git a/rtic-macros/src/codegen.rs b/rtic-macros/src/codegen.rs
index 48ee5e33..c04f2131 100644
--- a/rtic-macros/src/codegen.rs
+++ b/rtic-macros/src/codegen.rs
@@ -45,6 +45,7 @@ pub fn app(app: &App, analysis: &Analysis) -> TokenStream2 {
let device = &app.args.device;
let rt_err = util::rt_err_ident();
+ let async_limit = bindings::async_prio_limit(app, analysis);
quote!(
/// The RTIC application module
@@ -52,6 +53,8 @@ pub fn app(app: &App, analysis: &Analysis) -> TokenStream2 {
/// Always include the device crate which contains the vector table
use #device as #rt_err;
+ #(#async_limit)*
+
#(#user_imports)*
#(#user_code)*
diff --git a/rtic-macros/src/codegen/bindings/cortex.rs b/rtic-macros/src/codegen/bindings/cortex.rs
index 767befa9..eba2afca 100644
--- a/rtic-macros/src/codegen/bindings/cortex.rs
+++ b/rtic-macros/src/codegen/bindings/cortex.rs
@@ -322,3 +322,19 @@ pub fn interrupt_entry(_app: &App, _analysis: &CodegenAnalysis) -> Vec<TokenStre
pub fn interrupt_exit(_app: &App, _analysis: &CodegenAnalysis) -> Vec<TokenStream2> {
vec![]
}
+
+pub fn async_prio_limit(app: &App, analysis: &CodegenAnalysis) -> Vec<TokenStream2> {
+ let max = if let Some(max) = analysis.max_async_prio {
+ quote!(#max)
+ } else {
+ // No limit
+ let device = &app.args.device;
+ quote!(1 << #device::NVIC_PRIO_BITS)
+ };
+
+ vec![quote!(
+ /// Holds the maximum priority level for use by async HAL drivers.
+ #[no_mangle]
+ static RTIC_ASYNC_MAX_LOGICAL_PRIO: u8 = #max;
+ )]
+}
diff --git a/rtic-macros/src/codegen/bindings/template.rs b/rtic-macros/src/codegen/bindings/template.rs
index 18f88fe0..a33bae8e 100644
--- a/rtic-macros/src/codegen/bindings/template.rs
+++ b/rtic-macros/src/codegen/bindings/template.rs
@@ -42,3 +42,7 @@ pub fn interrupt_entry(_app: &App, _analysis: &CodegenAnalysis) -> Vec<TokenStre
pub fn interrupt_exit(_app: &App, _analysis: &CodegenAnalysis) -> Vec<TokenStream2> {
vec![]
}
+
+pub fn async_prio_limit(app: &App, _analysis: &CodegenAnalysis) -> Vec<TokenStream2> {
+ vec![]
+}
diff --git a/rtic-macros/src/syntax/parse.rs b/rtic-macros/src/syntax/parse.rs
index 72eeeaf6..823bd82e 100644
--- a/rtic-macros/src/syntax/parse.rs
+++ b/rtic-macros/src/syntax/parse.rs
@@ -289,11 +289,13 @@ fn task_args(tokens: TokenStream2) -> parse::Result<Either<HardwareTaskArgs, Sof
// Handle comma: ,
let _: Token![,] = content.parse()?;
}
- let priority = priority.unwrap_or(1);
let shared_resources = shared_resources.unwrap_or_default();
let local_resources = local_resources.unwrap_or_default();
Ok(if let Some(binds) = binds {
+ // Hardware tasks can't run at anything lower than 1
+ let priority = priority.unwrap_or(1);
+
if priority == 0 {
return Err(parse::Error::new(
prio_span.unwrap(),
@@ -308,6 +310,9 @@ fn task_args(tokens: TokenStream2) -> parse::Result<Either<HardwareTaskArgs, Sof
local_resources,
})
} else {
+ // Software tasks start at idle priority
+ let priority = priority.unwrap_or(0);
+
Either::Right(SoftwareTaskArgs {
priority,
shared_resources,
diff --git a/rtic-monotonics/src/rp2040.rs b/rtic-monotonics/src/rp2040.rs
index 6aa66ce0..9d2f4f35 100644
--- a/rtic-monotonics/src/rp2040.rs
+++ b/rtic-monotonics/src/rp2040.rs
@@ -138,7 +138,7 @@ impl embedded_hal_async::delay::DelayUs for Timer {
/// Register the Timer interrupt for the monotonic.
#[macro_export]
-macro_rules! make_rp2040_monotonic_handler {
+macro_rules! create_rp2040_monotonic_token {
() => {{
#[no_mangle]
#[allow(non_snake_case)]
diff --git a/rtic-monotonics/src/systick.rs b/rtic-monotonics/src/systick.rs
index b228e204..f4345d43 100644
--- a/rtic-monotonics/src/systick.rs
+++ b/rtic-monotonics/src/systick.rs
@@ -156,7 +156,7 @@ impl embedded_hal_async::delay::DelayUs for Systick {
/// Register the Systick interrupt for the monotonic.
#[macro_export]
-macro_rules! make_systick_handler {
+macro_rules! create_systick_token {
() => {{
#[no_mangle]
#[allow(non_snake_case)]
diff --git a/rtic/CHANGELOG.md b/rtic/CHANGELOG.md
index 1a677296..2d0a392f 100644
--- a/rtic/CHANGELOG.md
+++ b/rtic/CHANGELOG.md
@@ -15,6 +15,7 @@ For each category, *Added*, *Changed*, *Fixed* add new entries at the top!
- `cortex-m` set as an optional dependency
- Moved `cortex-m`-related utilities from `rtic/lib.rs` to `rtic/export.rs`
+- Make async task priorities start at 0, instead of 1, to always start at the lowest priority
## [v1.1.4] - 2023-02-26
diff --git a/rtic/examples/async-delay.rs b/rtic/examples/async-delay.rs
index 7b3667b0..cdffa620 100644
--- a/rtic/examples/async-delay.rs
+++ b/rtic/examples/async-delay.rs
@@ -24,7 +24,7 @@ mod app {
fn init(cx: init::Context) -> (Shared, Local) {
hprintln!("init");
- let systick_token = rtic_monotonics::make_systick_handler!();
+ let systick_token = rtic_monotonics::create_systick_token!();
Systick::start(cx.core.SYST, 12_000_000, systick_token);
foo::spawn().ok();
diff --git a/rtic/examples/async-task.rs b/rtic/examples/async-task.rs
index b70151a2..1ca18021 100644
--- a/rtic/examples/async-task.rs
+++ b/rtic/examples/async-task.rs
@@ -53,13 +53,13 @@ mod app {
hprintln!("hello from hw");
}
- #[task(shared = [a])]
+ #[task(shared = [a], priority = 1)]
async fn async_task(cx: async_task::Context) {
let async_task::SharedResources { a: _, .. } = cx.shared;
hprintln!("hello from async");
}
- #[task]
+ #[task(priority = 1)]
async fn async_task_args(_cx: async_task_args::Context, a: u32, b: i32) {
hprintln!("hello from async with args a: {}, b: {}", a, b);
}
diff --git a/rtic/examples/async-timeout.rs b/rtic/examples/async-timeout.rs
index e07e9c6f..7690408e 100644
--- a/rtic/examples/async-timeout.rs
+++ b/rtic/examples/async-timeout.rs
@@ -27,7 +27,7 @@ mod app {
fn init(cx: init::Context) -> (Shared, Local) {
hprintln!("init");
- let systick_token = rtic_monotonics::make_systick_handler!();
+ let systick_token = rtic_monotonics::create_systick_token!();
Systick::start(cx.core.SYST, 12_000_000, systick_token);
foo::spawn().ok();
diff --git a/rtic/examples/common.rs b/rtic/examples/common.rs
index ed6cb7dd..27ad0ad9 100644
--- a/rtic/examples/common.rs
+++ b/rtic/examples/common.rs
@@ -62,7 +62,7 @@ mod app {
}
// `local_to_foo` can only be accessed from this context
- #[task(local = [local_to_foo])]
+ #[task(local = [local_to_foo], priority = 1)]
async fn foo(cx: foo::Context) {
let local_to_foo = cx.local.local_to_foo;
*local_to_foo += 1;
@@ -74,7 +74,7 @@ mod app {
}
// `local_to_bar` can only be accessed from this context
- #[task(local = [local_to_bar])]
+ #[task(local = [local_to_bar], priority = 1)]
async fn bar(cx: bar::Context) {
let local_to_bar = cx.local.local_to_bar;
*local_to_bar += 1;
diff --git a/rtic/examples/destructure.rs b/rtic/examples/destructure.rs
index b5d564bc..dd1633c0 100644
--- a/rtic/examples/destructure.rs
+++ b/rtic/examples/destructure.rs
@@ -38,7 +38,7 @@ mod app {
}
// Direct destructure
- #[task(shared = [&a, &b, &c])]
+ #[task(shared = [&a, &b, &c], priority = 1)]
async fn foo(cx: foo::Context) {
let a = cx.shared.a;
let b = cx.shared.b;
@@ -48,7 +48,7 @@ mod app {
}
// De-structure-ing syntax
- #[task(shared = [&a, &b, &c])]
+ #[task(shared = [&a, &b, &c], priority = 1)]
async fn bar(cx: bar::Context) {
let bar::SharedResources { a, b, c, .. } = cx.shared;
diff --git a/rtic/examples/locals.rs b/rtic/examples/locals.rs
index 2408f90c..f01027cf 100644
--- a/rtic/examples/locals.rs
+++ b/rtic/examples/locals.rs
@@ -62,7 +62,7 @@ mod app {
}
// `local_to_foo` can only be accessed from this context
- #[task(local = [local_to_foo])]
+ #[task(local = [local_to_foo], priority = 1)]
async fn foo(cx: foo::Context) {
let local_to_foo = cx.local.local_to_foo;
*local_to_foo += 1;
@@ -74,7 +74,7 @@ mod app {
}
// `local_to_bar` can only be accessed from this context
- #[task(local = [local_to_bar])]
+ #[task(local = [local_to_bar], priority = 1)]
async fn bar(cx: bar::Context) {
let local_to_bar = cx.local.local_to_bar;
*local_to_bar += 1;
diff --git a/rtic/examples/not-sync.rs b/rtic/examples/not-sync.rs
index cd6b0bf5..1a798642 100644
--- a/rtic/examples/not-sync.rs
+++ b/rtic/examples/not-sync.rs
@@ -54,13 +54,13 @@ mod app {
loop {}
}
- #[task(shared = [&shared])]
+ #[task(shared = [&shared], priority = 1)]
async fn foo(c: foo::Context) {
let shared: &NotSync = c.shared.shared;
hprintln!("foo a {}", shared.data);
}
- #[task(shared = [&shared])]
+ #[task(shared = [&shared], priority = 1)]
async fn bar(c: bar::Context) {
let shared: &NotSync = c.shared.shared;
hprintln!("bar a {}", shared.data);
diff --git a/rtic/examples/static.rs b/rtic/examples/static.rs
index a98e2e5e..aa39940e 100644
--- a/rtic/examples/static.rs
+++ b/rtic/examples/static.rs
@@ -51,7 +51,7 @@ mod app {
}
}
- #[task(local = [p, state: u32 = 0])]
+ #[task(local = [p, state: u32 = 0], priority = 1)]
async fn foo(c: foo::Context) {
*c.local.state += 1;