From 9e445b3583c15c7701f3167eaa8dfe4afd541691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Sat, 4 Feb 2023 16:47:17 +0100 Subject: Move rtic macros to repo root, tune xtask --- rtic-macros/src/codegen/hardware_tasks.rs | 87 +++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 rtic-macros/src/codegen/hardware_tasks.rs (limited to 'rtic-macros/src/codegen/hardware_tasks.rs') diff --git a/rtic-macros/src/codegen/hardware_tasks.rs b/rtic-macros/src/codegen/hardware_tasks.rs new file mode 100644 index 0000000..8a5a8f6 --- /dev/null +++ b/rtic-macros/src/codegen/hardware_tasks.rs @@ -0,0 +1,87 @@ +use crate::syntax::{ast::App, Context}; +use crate::{ + analyze::Analysis, + codegen::{local_resources_struct, module, shared_resources_struct}, +}; +use proc_macro2::TokenStream as TokenStream2; +use quote::quote; + +/// Generate support code for hardware tasks (`#[exception]`s and `#[interrupt]`s) +pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 { + let mut mod_app = vec![]; + let mut root = vec![]; + let mut user_tasks = vec![]; + + for (name, task) in &app.hardware_tasks { + let symbol = task.args.binds.clone(); + let priority = task.args.priority; + let cfgs = &task.cfgs; + let attrs = &task.attrs; + + mod_app.push(quote!( + #[allow(non_snake_case)] + #[no_mangle] + #(#attrs)* + #(#cfgs)* + unsafe fn #symbol() { + const PRIORITY: u8 = #priority; + + rtic::export::run(PRIORITY, || { + #name( + #name::Context::new() + ) + }); + } + )); + + // `${task}Locals` + if !task.args.local_resources.is_empty() { + let (item, constructor) = + local_resources_struct::codegen(Context::HardwareTask(name), app); + + root.push(item); + + mod_app.push(constructor); + } + + // `${task}Resources` + if !task.args.shared_resources.is_empty() { + let (item, constructor) = + shared_resources_struct::codegen(Context::HardwareTask(name), app); + + root.push(item); + + mod_app.push(constructor); + } + + // Module generation... + + root.push(module::codegen(Context::HardwareTask(name), app, analysis)); + + // End module generation + + if !task.is_extern { + let attrs = &task.attrs; + let context = &task.context; + let stmts = &task.stmts; + user_tasks.push(quote!( + #(#attrs)* + #[allow(non_snake_case)] + fn #name(#context: #name::Context) { + use rtic::Mutex as _; + use rtic::mutex::prelude::*; + + #(#stmts)* + } + )); + } + } + + quote!( + #(#mod_app)* + + #(#root)* + + #(#user_tasks)* + ) +} -- cgit v1.2.3 From e8cebff69e3fd78ade613829c10dd2328495fa44 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Mon, 20 Feb 2023 10:49:09 +0100 Subject: Added support for adding codegen to intrrupt entry and exit (needed for RISC-V) --- rtic-macros/src/codegen/hardware_tasks.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'rtic-macros/src/codegen/hardware_tasks.rs') diff --git a/rtic-macros/src/codegen/hardware_tasks.rs b/rtic-macros/src/codegen/hardware_tasks.rs index 8a5a8f6..2c5254e 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)* } )); -- cgit v1.2.3