use syn::{Attribute, Expr, Ident, Item, ItemUse, Pat, PatType, Path, Stmt, Type};
use crate::Map;
#[derive(Debug)]
#[non_exhaustive]
pub struct App {
pub args: AppArgs,
pub name: Ident,
pub init: Init,
pub idle: Option<Idle>,
pub monotonics: Map<Monotonic>,
pub shared_resources: Map<SharedResource>,
pub local_resources: Map<LocalResource>,
pub user_imports: Vec<ItemUse>,
pub user_code: Vec<Item>,
pub hardware_tasks: Map<HardwareTask>,
pub software_tasks: Map<SoftwareTask>,
}
pub type ExternInterrupts = Map<ExternInterrupt>;
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct ExternInterrupt {
pub attrs: Vec<Attribute>,
}
#[derive(Debug)]
pub struct AppArgs {
pub device: Option<Path>,
pub peripherals: bool,
pub extern_interrupts: ExternInterrupts,
}
#[derive(Debug)]
#[non_exhaustive]
pub struct Init {
pub args: InitArgs,
pub attrs: Vec<Attribute>,
pub name: Ident,
pub context: Box<Pat>,
pub stmts: Vec<Stmt>,
pub user_shared_struct: Ident,
pub user_local_struct: Ident,
}
#[derive(Debug)]
#[non_exhaustive]
pub struct InitArgs {
pub local_resources: LocalResources,
}
impl Default for InitArgs {
fn default() -> Self {
Self {
local_resources: LocalResources::new(),
}
}
}
#[derive(Debug)]
#[non_exhaustive]
pub struct Idle {
pub args: IdleArgs,
pub attrs: Vec<Attribute>,
pub name: Ident,
pub context: Box<Pat>,
pub stmts: Vec<Stmt>,
}
#[derive(Debug)]
#[non_exhaustive]
pub struct IdleArgs {
pub local_resources: LocalResources,
pub shared_resources: SharedResources,
}
impl Default for IdleArgs {
fn default() -> Self {
Self {
local_resources: LocalResources::new(),
shared_resources: SharedResources::new(),
}
}
}
#[derive(Debug)]
pub struct SharedResourceProperties {
pub lock_free: bool,
}
#[derive(Debug)]
#[non_exhaustive]
pub struct SharedResource {
pub cfgs: Vec<Attribute>,
pub docs: Vec<Attribute>,
pub attrs: Vec<Attribute>,
pub ty: Box<Type>,
pub properties: SharedResourceProperties,
}
#[derive(Debug)]
#[non_exhaustive]
pub struct LocalResource {
pub cfgs: Vec<Attribute>,
pub docs: Vec<Attribute>,
pub attrs: Vec<Attribute>,
pub ty: Box<Type>,
}
#[derive(Debug)]
#[non_exhaustive]
pub struct Monotonic {
pub cfgs: Vec<Attribute>,
pub ident: Ident,
pub ty: Box<Type>,
pub args: MonotonicArgs,
}
#[derive(Debug)]
#[non_exhaustive]
pub struct MonotonicArgs {
pub binds: Ident,
pub priority: Option<u8>,
pub default: bool,
}
#[derive(Debug)]
#[non_exhaustive]
pub struct SoftwareTask {
pub args: SoftwareTaskArgs,
pub cfgs: Vec<Attribute>,
pub attrs: Vec<Attribute>,
pub context: Box<Pat>,
pub inputs: Vec<PatType>,
pub stmts: Vec<Stmt>,
pub is_extern: bool,
}
#[derive(Debug)]
#[non_exhaustive]
pub struct SoftwareTaskArgs {
pub capacity: u8,
pub priority: u8,
pub local_resources: LocalResources,
pub shared_resources: SharedResources,
}
impl Default for SoftwareTaskArgs {
fn default() -> Self {
Self {
capacity: 1,
priority: 1,
local_resources: LocalResources::new(),
shared_resources: SharedResources::new(),
}
}
}
#[derive(Debug)]
#[non_exhaustive]
pub struct HardwareTask {
pub args: HardwareTaskArgs,
pub cfgs: Vec<Attribute>,
pub attrs: Vec<Attribute>,
pub context: Box<Pat>,
pub stmts: Vec<Stmt>,
pub is_extern: bool,
}
#[derive(Debug)]
#[non_exhaustive]
pub struct HardwareTaskArgs {
pub binds: Ident,
pub priority: u8,
pub local_resources: LocalResources,
pub shared_resources: SharedResources,
}
#[derive(Debug)]
#[non_exhaustive]
pub struct Local {
pub attrs: Vec<Attribute>,
pub cfgs: Vec<Attribute>,
pub ty: Box<Type>,
pub expr: Box<Expr>,
}
#[derive(Debug)]
#[non_exhaustive]
pub enum TaskLocal {
External,
Declared(Local),
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Access {
Exclusive,
Shared,
}
impl Access {
pub fn is_exclusive(&self) -> bool {
*self == Access::Exclusive
}
pub fn is_shared(&self) -> bool {
*self == Access::Shared
}
}
pub type SharedResources = Map<Access>;
pub type LocalResources = Map<TaskLocal>;