diff options
| author | Emil Fresk <emil.fresk@gmail.com> | 2024-01-29 20:56:15 +0100 |
|---|---|---|
| committer | Emil Fresk <emil.fresk@gmail.com> | 2024-02-27 12:22:18 +0100 |
| commit | 27985009579e82673dcaf7a6a715fcf50c184863 (patch) | |
| tree | 8ae8f1cc9e8c6d2c2581467a4a537d8b84ae6552 /rtic-macros/src/codegen/bindings | |
| parent | d2e84799c743eeb4b827d8da576be45ed43d6ece (diff) | |
Make RTIC 2 work on stable by using `main`'s stack as an allocator
Diffstat (limited to 'rtic-macros/src/codegen/bindings')
| -rw-r--r-- | rtic-macros/src/codegen/bindings/cortex.rs | 24 | ||||
| -rw-r--r-- | rtic-macros/src/codegen/bindings/esp32c3.rs | 33 | ||||
| -rw-r--r-- | rtic-macros/src/codegen/bindings/template.rs | 7 |
3 files changed, 58 insertions, 6 deletions
diff --git a/rtic-macros/src/codegen/bindings/cortex.rs b/rtic-macros/src/codegen/bindings/cortex.rs index ffa0245..69b5ee5 100644 --- a/rtic-macros/src/codegen/bindings/cortex.rs +++ b/rtic-macros/src/codegen/bindings/cortex.rs @@ -29,11 +29,35 @@ fn is_exception(name: &Ident) -> bool { | "SysTick" ) } + pub fn interrupt_ident() -> Ident { let span = Span::call_site(); Ident::new("interrupt", span) } +pub fn check_stack_overflow_before_init( + _app: &App, + _analysis: &CodegenAnalysis, +) -> Vec<TokenStream2> { + vec![quote!( + // Check for stack overflow using symbols from `cortex-m-rt`. + extern "C" { + pub static _stack_start: u32; + pub static __ebss: u32; + } + + let stack_start = &_stack_start as *const _ as u32; + let ebss = &__ebss as *const _ as u32; + + if stack_start > ebss { + // No flip-link usage, check the MSP for overflow. + if rtic::export::msp::read() <= ebss { + panic!("Stack overflow after allocating executors"); + } + } + )] +} + #[cfg(feature = "cortex-m-source-masking")] mod source_masking { use super::*; diff --git a/rtic-macros/src/codegen/bindings/esp32c3.rs b/rtic-macros/src/codegen/bindings/esp32c3.rs index a8d58b7..4b14cae 100644 --- a/rtic-macros/src/codegen/bindings/esp32c3.rs +++ b/rtic-macros/src/codegen/bindings/esp32c3.rs @@ -72,7 +72,7 @@ mod esp32c3 { } pub fn pre_init_enable_interrupts(app: &App, analysis: &CodegenAnalysis) -> Vec<TokenStream2> { let mut stmts = vec![]; - let mut curr_cpu_id:u8 = 1; //cpu interrupt id 0 is reserved + let mut curr_cpu_id: u8 = 1; //cpu interrupt id 0 is reserved let rt_err = util::rt_err_ident(); let max_prio: usize = 15; //unfortunately this is not part of pac, but we know that max prio is 15. let interrupt_ids = analysis.interrupts.iter().map(|(p, (id, _))| (p, id)); @@ -158,6 +158,29 @@ mod esp32c3 { vec![] } + pub fn check_stack_overflow_before_init( + _app: &App, + _analysis: &CodegenAnalysis, + ) -> Vec<TokenStream2> { + vec![quote!( + // Check for stack overflow using symbols from `risc-v-rt`. + extern "C" { + pub static _stack_start: u32; + pub static __ebss: u32; + } + + let stack_start = &_stack_start as *const _ as u32; + let ebss = &__ebss as *const _ as u32; + + if stack_start > ebss { + // No flip-link usage, check the SP for overflow. + if rtic::export::read_sp() <= ebss { + panic!("Stack overflow after allocating executors"); + } + } + )] + } + pub fn async_entry( _app: &App, _analysis: &CodegenAnalysis, @@ -199,11 +222,9 @@ mod esp32c3 { .values() .filter_map(|task| Some((&task.args.priority, &task.args.binds))), ) { - if *name == dispatcher_name{ - let ret = &("cpu_int_".to_owned()+&curr_cpu_id.to_string()+"_handler"); - stmts.push( - quote!(#[export_name = #ret]) - ); + if *name == dispatcher_name { + let ret = &("cpu_int_".to_owned() + &curr_cpu_id.to_string() + "_handler"); + stmts.push(quote!(#[export_name = #ret])); } curr_cpu_id += 1; } diff --git a/rtic-macros/src/codegen/bindings/template.rs b/rtic-macros/src/codegen/bindings/template.rs index d929dd8..b5488b7 100644 --- a/rtic-macros/src/codegen/bindings/template.rs +++ b/rtic-macros/src/codegen/bindings/template.rs @@ -43,6 +43,13 @@ pub fn interrupt_exit(_app: &App, _analysis: &CodegenAnalysis) -> Vec<TokenStrea vec![] } +pub fn check_stack_overflow_before_init( + _app: &App, + _analysis: &CodegenAnalysis, +) -> Vec<TokenStream2> { + vec![] +} + pub fn async_entry( _app: &App, _analysis: &CodegenAnalysis, |
