From e8cebff69e3fd78ade613829c10dd2328495fa44 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Mon, 20 Feb 2023 10:49:09 +0100 Subject: [PATCH] Added support for adding codegen to intrrupt entry and exit (needed for RISC-V) --- rtic-macros/src/codegen/async_dispatchers.rs | 15 ++++++++++++++- rtic-macros/src/codegen/bindings/cortex.rs | 8 ++++++++ rtic-macros/src/codegen/hardware_tasks.rs | 11 ++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/rtic-macros/src/codegen/async_dispatchers.rs b/rtic-macros/src/codegen/async_dispatchers.rs index a12ad325fc..bdbfeaa7a2 100644 --- a/rtic-macros/src/codegen/async_dispatchers.rs +++ b/rtic-macros/src/codegen/async_dispatchers.rs @@ -1,5 +1,11 @@ use crate::syntax::ast::App; -use crate::{analyze::Analysis, codegen::util}; +use crate::{ + analyze::Analysis, + codegen::{ + bindings::{interrupt_entry, interrupt_exit}, + util, + }, +}; use proc_macro2::TokenStream as TokenStream2; use quote::quote; @@ -59,18 +65,25 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 { if level > 0 { let doc = format!("Interrupt handler to dispatch async tasks at priority {level}"); let attribute = &interrupts.get(&level).expect("UNREACHABLE").1.attrs; + let entry_stmts = interrupt_entry(app, analysis); + let exit_stmts = interrupt_exit(app, analysis); + items.push(quote!( #[allow(non_snake_case)] #[doc = #doc] #[no_mangle] #(#attribute)* unsafe fn #dispatcher_name() { + #(#entry_stmts)* + /// The priority of this interrupt handler const PRIORITY: u8 = #level; rtic::export::run(PRIORITY, || { #(#stmts)* }); + + #(#exit_stmts)* } )); } else { diff --git a/rtic-macros/src/codegen/bindings/cortex.rs b/rtic-macros/src/codegen/bindings/cortex.rs index f028cee7cb..d5eb12e21f 100644 --- a/rtic-macros/src/codegen/bindings/cortex.rs +++ b/rtic-macros/src/codegen/bindings/cortex.rs @@ -312,3 +312,11 @@ pub fn architecture_specific_analysis(app: &App, _: &SyntaxAnalysis) -> parse::R Ok(()) } + +pub fn interrupt_entry(_app: &App, _analysis: &CodegenAnalysis) -> Vec { + vec![] +} + +pub fn interrupt_exit(_app: &App, _analysis: &CodegenAnalysis) -> Vec { + vec![] +} diff --git a/rtic-macros/src/codegen/hardware_tasks.rs b/rtic-macros/src/codegen/hardware_tasks.rs index 8a5a8f6cf4..2c5254e967 100644 --- a/rtic-macros/src/codegen/hardware_tasks.rs +++ b/rtic-macros/src/codegen/hardware_tasks.rs @@ -1,7 +1,10 @@ use crate::syntax::{ast::App, Context}; use crate::{ analyze::Analysis, - codegen::{local_resources_struct, module, shared_resources_struct}, + codegen::{ + bindings::{interrupt_entry, interrupt_exit}, + local_resources_struct, module, shared_resources_struct, + }, }; use proc_macro2::TokenStream as TokenStream2; use quote::quote; @@ -17,6 +20,8 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 { let priority = task.args.priority; let cfgs = &task.cfgs; let attrs = &task.attrs; + let entry_stmts = interrupt_entry(app, analysis); + let exit_stmts = interrupt_exit(app, analysis); mod_app.push(quote!( #[allow(non_snake_case)] @@ -24,6 +29,8 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 { #(#attrs)* #(#cfgs)* unsafe fn #symbol() { + #(#entry_stmts)* + const PRIORITY: u8 = #priority; rtic::export::run(PRIORITY, || { @@ -31,6 +38,8 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 { #name::Context::new() ) }); + + #(#exit_stmts)* } ));