Skip to content

Commit 31055fa

Browse files
bors[bot]korken89
andauthored
Merge #719
719: Adding a limit that async HALs can read and have as max prio r=AfoHT a=korken89 Co-authored-by: Emil Fresk <emil.fresk@gmail.com>
2 parents 2a17a05 + 323b847 commit 31055fa

4 files changed

Lines changed: 32 additions & 0 deletions

File tree

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+
}

0 commit comments

Comments
 (0)