Skip to content

Commit ce508a1

Browse files
Merge branch 'master' into master
2 parents 06ddfb7 + 31055fa commit ce508a1

File tree

17 files changed

+55
-17
lines changed

17 files changed

+55
-17
lines changed

book/en/src/by-example.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ All examples in this part of the book are accessible at the
77
The examples are runnable on QEMU (emulating a Cortex M3 target),
88
thus no special hardware required to follow along.
99

10-
[repoexamples]: https://github.com/rtic-rs/rtic/tree/master/examples
10+
[repoexamples]: https://github.com/rtic-rs/rtic/tree/master/rtic/examples
1111

1212
## Running an example
1313

rtic-macros/src/analyze.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use syn::Ident;
1111
pub struct Analysis {
1212
parent: analyze::Analysis,
1313
pub interrupts: BTreeMap<Priority, (Ident, Dispatcher)>,
14+
pub max_async_prio: Option<u8>,
1415
}
1516

1617
impl ops::Deref for Analysis {
@@ -42,8 +43,16 @@ pub fn app(analysis: analyze::Analysis, app: &App) -> Analysis {
4243
.map(|p| (p, available_interrupt.pop().expect("UNREACHABLE")))
4344
.collect();
4445

46+
let max_async_prio = app
47+
.hardware_tasks
48+
.iter()
49+
.map(|(_, task)| task.args.priority)
50+
.min()
51+
.map(|v| v - 1); // One less than the smallest HW task
52+
4553
Analysis {
4654
parent: analysis,
4755
interrupts,
56+
max_async_prio,
4857
}
4958
}

rtic-macros/src/codegen.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,16 @@ pub fn app(app: &App, analysis: &Analysis) -> TokenStream2 {
4545
let device = &app.args.device;
4646

4747
let rt_err = util::rt_err_ident();
48+
let async_limit = bindings::async_prio_limit(app, analysis);
4849

4950
quote!(
5051
/// The RTIC application module
5152
pub mod #name {
5253
/// Always include the device crate which contains the vector table
5354
use #device as #rt_err;
5455

56+
#(#async_limit)*
57+
5558
#(#user_imports)*
5659

5760
#(#user_code)*

rtic-macros/src/codegen/bindings/cortex.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,3 +322,19 @@ pub fn interrupt_entry(_app: &App, _analysis: &CodegenAnalysis) -> Vec<TokenStre
322322
pub fn interrupt_exit(_app: &App, _analysis: &CodegenAnalysis) -> Vec<TokenStream2> {
323323
vec![]
324324
}
325+
326+
pub fn async_prio_limit(app: &App, analysis: &CodegenAnalysis) -> Vec<TokenStream2> {
327+
let max = if let Some(max) = analysis.max_async_prio {
328+
quote!(#max)
329+
} else {
330+
// No limit
331+
let device = &app.args.device;
332+
quote!(1 << #device::NVIC_PRIO_BITS)
333+
};
334+
335+
vec![quote!(
336+
/// Holds the maximum priority level for use by async HAL drivers.
337+
#[no_mangle]
338+
static RTIC_ASYNC_MAX_LOGICAL_PRIO: u8 = #max;
339+
)]
340+
}

rtic-macros/src/codegen/bindings/template.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,7 @@ pub fn interrupt_entry(_app: &App, _analysis: &CodegenAnalysis) -> Vec<TokenStre
4242
pub fn interrupt_exit(_app: &App, _analysis: &CodegenAnalysis) -> Vec<TokenStream2> {
4343
vec![]
4444
}
45+
46+
pub fn async_prio_limit(app: &App, _analysis: &CodegenAnalysis) -> Vec<TokenStream2> {
47+
vec![]
48+
}

rtic-macros/src/syntax/parse.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,13 @@ fn task_args(tokens: TokenStream2) -> parse::Result<Either<HardwareTaskArgs, Sof
289289
// Handle comma: ,
290290
let _: Token![,] = content.parse()?;
291291
}
292-
let priority = priority.unwrap_or(1);
293292
let shared_resources = shared_resources.unwrap_or_default();
294293
let local_resources = local_resources.unwrap_or_default();
295294

296295
Ok(if let Some(binds) = binds {
296+
// Hardware tasks can't run at anything lower than 1
297+
let priority = priority.unwrap_or(1);
298+
297299
if priority == 0 {
298300
return Err(parse::Error::new(
299301
prio_span.unwrap(),
@@ -308,6 +310,9 @@ fn task_args(tokens: TokenStream2) -> parse::Result<Either<HardwareTaskArgs, Sof
308310
local_resources,
309311
})
310312
} else {
313+
// Software tasks start at idle priority
314+
let priority = priority.unwrap_or(0);
315+
311316
Either::Right(SoftwareTaskArgs {
312317
priority,
313318
shared_resources,

rtic-monotonics/src/rp2040.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl embedded_hal_async::delay::DelayUs for Timer {
138138

139139
/// Register the Timer interrupt for the monotonic.
140140
#[macro_export]
141-
macro_rules! make_rp2040_monotonic_handler {
141+
macro_rules! create_rp2040_monotonic_token {
142142
() => {{
143143
#[no_mangle]
144144
#[allow(non_snake_case)]

rtic-monotonics/src/systick.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl embedded_hal_async::delay::DelayUs for Systick {
156156

157157
/// Register the Systick interrupt for the monotonic.
158158
#[macro_export]
159-
macro_rules! make_systick_handler {
159+
macro_rules! create_systick_token {
160160
() => {{
161161
#[no_mangle]
162162
#[allow(non_snake_case)]

rtic/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ For each category, *Added*, *Changed*, *Fixed* add new entries at the top!
1515

1616
- `cortex-m` set as an optional dependency
1717
- Moved `cortex-m`-related utilities from `rtic/lib.rs` to `rtic/export.rs`
18+
- Make async task priorities start at 0, instead of 1, to always start at the lowest priority
1819

1920
## [v1.1.4] - 2023-02-26
2021

rtic/examples/async-delay.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ mod app {
2424
fn init(cx: init::Context) -> (Shared, Local) {
2525
hprintln!("init");
2626

27-
let systick_token = rtic_monotonics::make_systick_handler!();
27+
let systick_token = rtic_monotonics::create_systick_token!();
2828
Systick::start(cx.core.SYST, 12_000_000, systick_token);
2929

3030
foo::spawn().ok();

rtic/examples/async-task.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ mod app {
5353
hprintln!("hello from hw");
5454
}
5555

56-
#[task(shared = [a])]
56+
#[task(shared = [a], priority = 1)]
5757
async fn async_task(cx: async_task::Context) {
5858
let async_task::SharedResources { a: _, .. } = cx.shared;
5959
hprintln!("hello from async");
6060
}
6161

62-
#[task]
62+
#[task(priority = 1)]
6363
async fn async_task_args(_cx: async_task_args::Context, a: u32, b: i32) {
6464
hprintln!("hello from async with args a: {}, b: {}", a, b);
6565
}

rtic/examples/async-timeout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ mod app {
2727
fn init(cx: init::Context) -> (Shared, Local) {
2828
hprintln!("init");
2929

30-
let systick_token = rtic_monotonics::make_systick_handler!();
30+
let systick_token = rtic_monotonics::create_systick_token!();
3131
Systick::start(cx.core.SYST, 12_000_000, systick_token);
3232

3333
foo::spawn().ok();

rtic/examples/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ mod app {
6262
}
6363

6464
// `local_to_foo` can only be accessed from this context
65-
#[task(local = [local_to_foo])]
65+
#[task(local = [local_to_foo], priority = 1)]
6666
async fn foo(cx: foo::Context) {
6767
let local_to_foo = cx.local.local_to_foo;
6868
*local_to_foo += 1;
@@ -74,7 +74,7 @@ mod app {
7474
}
7575

7676
// `local_to_bar` can only be accessed from this context
77-
#[task(local = [local_to_bar])]
77+
#[task(local = [local_to_bar], priority = 1)]
7878
async fn bar(cx: bar::Context) {
7979
let local_to_bar = cx.local.local_to_bar;
8080
*local_to_bar += 1;

rtic/examples/destructure.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ mod app {
3838
}
3939

4040
// Direct destructure
41-
#[task(shared = [&a, &b, &c])]
41+
#[task(shared = [&a, &b, &c], priority = 1)]
4242
async fn foo(cx: foo::Context) {
4343
let a = cx.shared.a;
4444
let b = cx.shared.b;
@@ -48,7 +48,7 @@ mod app {
4848
}
4949

5050
// De-structure-ing syntax
51-
#[task(shared = [&a, &b, &c])]
51+
#[task(shared = [&a, &b, &c], priority = 1)]
5252
async fn bar(cx: bar::Context) {
5353
let bar::SharedResources { a, b, c, .. } = cx.shared;
5454

rtic/examples/locals.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ mod app {
6262
}
6363

6464
// `local_to_foo` can only be accessed from this context
65-
#[task(local = [local_to_foo])]
65+
#[task(local = [local_to_foo], priority = 1)]
6666
async fn foo(cx: foo::Context) {
6767
let local_to_foo = cx.local.local_to_foo;
6868
*local_to_foo += 1;
@@ -74,7 +74,7 @@ mod app {
7474
}
7575

7676
// `local_to_bar` can only be accessed from this context
77-
#[task(local = [local_to_bar])]
77+
#[task(local = [local_to_bar], priority = 1)]
7878
async fn bar(cx: bar::Context) {
7979
let local_to_bar = cx.local.local_to_bar;
8080
*local_to_bar += 1;

rtic/examples/not-sync.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ mod app {
5454
loop {}
5555
}
5656

57-
#[task(shared = [&shared])]
57+
#[task(shared = [&shared], priority = 1)]
5858
async fn foo(c: foo::Context) {
5959
let shared: &NotSync = c.shared.shared;
6060
hprintln!("foo a {}", shared.data);
6161
}
6262

63-
#[task(shared = [&shared])]
63+
#[task(shared = [&shared], priority = 1)]
6464
async fn bar(c: bar::Context) {
6565
let shared: &NotSync = c.shared.shared;
6666
hprintln!("bar a {}", shared.data);

rtic/examples/static.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ mod app {
5151
}
5252
}
5353

54-
#[task(local = [p, state: u32 = 0])]
54+
#[task(local = [p, state: u32 = 0], priority = 1)]
5555
async fn foo(c: foo::Context) {
5656
*c.local.state += 1;
5757

0 commit comments

Comments
 (0)