diff options
Diffstat (limited to 'rtic-macros/src/syntax')
| -rw-r--r-- | rtic-macros/src/syntax/ast.rs | 10 | ||||
| -rw-r--r-- | rtic-macros/src/syntax/backend.rs | 32 | ||||
| -rw-r--r-- | rtic-macros/src/syntax/backend/cortex.rs | 16 | ||||
| -rw-r--r-- | rtic-macros/src/syntax/backend/esp32c3.rs | 16 | ||||
| -rw-r--r-- | rtic-macros/src/syntax/backend/riscv_slic.rs | 16 | ||||
| -rw-r--r-- | rtic-macros/src/syntax/backend/template.rs | 15 | ||||
| -rw-r--r-- | rtic-macros/src/syntax/parse/app.rs | 28 |
7 files changed, 131 insertions, 2 deletions
diff --git a/rtic-macros/src/syntax/ast.rs b/rtic-macros/src/syntax/ast.rs index f0067b8..06feb1f 100644 --- a/rtic-macros/src/syntax/ast.rs +++ b/rtic-macros/src/syntax/ast.rs @@ -2,7 +2,7 @@ use syn::{Attribute, Expr, Ident, Item, ItemUse, Pat, PatType, Path, Stmt, Type}; -use crate::syntax::Map; +use crate::syntax::{backend::BackendArgs, Map}; /// The `#[app]` attribute #[derive(Debug)] @@ -60,11 +60,17 @@ pub struct AppArgs { /// Device pub device: Path, - /// Peripherals + /// Core peripherals + pub core: bool, + + /// Device peripherals pub peripherals: bool, /// Interrupts used to dispatch software tasks pub dispatchers: Dispatchers, + + /// Backend-specific arguments + pub backend: Option<BackendArgs>, } /// The `init`-ialization function diff --git a/rtic-macros/src/syntax/backend.rs b/rtic-macros/src/syntax/backend.rs new file mode 100644 index 0000000..460ef56 --- /dev/null +++ b/rtic-macros/src/syntax/backend.rs @@ -0,0 +1,32 @@ +#[cfg(not(any( + feature = "cortex-m-source-masking", + feature = "cortex-m-basepri", + feature = "test-template", + feature = "riscv-esp32c3", + feature = "riscv-slic", +)))] +compile_error!("No backend selected"); + +#[cfg(any(feature = "cortex-m-source-masking", feature = "cortex-m-basepri"))] +pub use cortex::*; + +#[cfg(feature = "test-template")] +pub use template::*; + +#[cfg(feature = "riscv-esp32c3")] +pub use esp32c3::*; + +#[cfg(feature = "riscv-slic")] +pub use riscv_slic::*; + +#[cfg(any(feature = "cortex-m-source-masking", feature = "cortex-m-basepri"))] +mod cortex; + +#[cfg(feature = "test-template")] +mod template; + +#[cfg(feature = "riscv-esp32c3")] +mod esp32c3; + +#[cfg(feature = "riscv-slic")] +mod riscv_slic; diff --git a/rtic-macros/src/syntax/backend/cortex.rs b/rtic-macros/src/syntax/backend/cortex.rs new file mode 100644 index 0000000..b53e927 --- /dev/null +++ b/rtic-macros/src/syntax/backend/cortex.rs @@ -0,0 +1,16 @@ +use syn::{ + parse::{Parse, ParseStream}, + Error, Result, +}; + +#[derive(Debug)] +pub struct BackendArgs(); + +impl Parse for BackendArgs { + fn parse(input: ParseStream) -> Result<Self> { + Err(Error::new( + input.span(), + "cortex backend does not accept any arguments", + )) + } +} diff --git a/rtic-macros/src/syntax/backend/esp32c3.rs b/rtic-macros/src/syntax/backend/esp32c3.rs new file mode 100644 index 0000000..33143f4 --- /dev/null +++ b/rtic-macros/src/syntax/backend/esp32c3.rs @@ -0,0 +1,16 @@ +use syn::{ + parse::{Parse, ParseStream}, + Error, Result, +}; + +#[derive(Debug)] +pub struct BackendArgs(); + +impl Parse for BackendArgs { + fn parse(input: ParseStream) -> Result<Self> { + Err(Error::new( + input.span(), + "esp32c3 backend does not accept any arguments", + )) + } +} diff --git a/rtic-macros/src/syntax/backend/riscv_slic.rs b/rtic-macros/src/syntax/backend/riscv_slic.rs new file mode 100644 index 0000000..2ed8e77 --- /dev/null +++ b/rtic-macros/src/syntax/backend/riscv_slic.rs @@ -0,0 +1,16 @@ +use syn::{ + parse::{Parse, ParseStream}, + Ident, Result, +}; + +#[derive(Debug)] +pub struct BackendArgs { + pub hart_id: Ident, +} + +impl Parse for BackendArgs { + fn parse(input: ParseStream) -> Result<Self> { + let hart_id = input.parse()?; + Ok(BackendArgs { hart_id }) + } +} diff --git a/rtic-macros/src/syntax/backend/template.rs b/rtic-macros/src/syntax/backend/template.rs new file mode 100644 index 0000000..6dad114 --- /dev/null +++ b/rtic-macros/src/syntax/backend/template.rs @@ -0,0 +1,15 @@ +use syn::{ + parse::{Parse, ParseStream}, + Result, +}; + +#[derive(Debug)] +pub struct BackendArgs { + // Define your backend-specific input here +} + +impl Parse for BackendArgs { + fn parse(input: ParseStream) -> Result<Self> { + todo!("define how to parse your backend-specific arguments") + } +} diff --git a/rtic-macros/src/syntax/parse/app.rs b/rtic-macros/src/syntax/parse/app.rs index efcafbe..469bcb8 100644 --- a/rtic-macros/src/syntax/parse/app.rs +++ b/rtic-macros/src/syntax/parse/app.rs @@ -13,6 +13,7 @@ use crate::syntax::{ App, AppArgs, Dispatcher, Dispatchers, HardwareTask, Idle, IdleArgs, Init, InitArgs, LocalResource, SharedResource, SoftwareTask, }, + backend::BackendArgs, parse::{self as syntax_parse, util}, Either, Map, Set, }; @@ -24,8 +25,10 @@ impl AppArgs { (|input: ParseStream<'_>| -> parse::Result<Self> { let mut custom = Set::new(); let mut device = None; + let mut core = true; let mut peripherals = true; let mut dispatchers = Dispatchers::new(); + let mut backend = None; loop { if input.is_empty() { @@ -59,6 +62,17 @@ impl AppArgs { } } + "core" => { + if let Ok(p) = input.parse::<LitBool>() { + core = p.value; + } else { + return Err(parse::Error::new( + ident.span(), + "unexpected argument value; this should be a boolean", + )); + } + } + "peripherals" => { if let Ok(p) = input.parse::<LitBool>() { peripherals = p.value; @@ -113,6 +127,18 @@ impl AppArgs { )); } } + + "backend" => { + if let Ok(p) = input.parse::<BackendArgs>() { + backend = Some(p); + } else { + return Err(parse::Error::new( + ident.span(), + "unable to parse backend configuration", + )); + } + } + _ => { return Err(parse::Error::new(ident.span(), "unexpected argument")); } @@ -134,8 +160,10 @@ impl AppArgs { Ok(AppArgs { device, + core, peripherals, dispatchers, + backend, }) }) .parse2(tokens) |
