Skip to content

Commit

Permalink
Guart single/multiple interrupt sources in interrupt_binding macro
Browse files Browse the repository at this point in the history
  • Loading branch information
jbeaurivage committed Dec 11, 2023
1 parent ad00652 commit 9ce5451
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
26 changes: 22 additions & 4 deletions hal/src/async_hal/interrupts.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
use core::mem;
use core::sync::atomic::{compiler_fence, Ordering};
use cortex_m::interrupt::InterruptNumber;
use cortex_m::peripheral::NVIC;
use crate::typelevel::Sealed;
use core::{
mem,
sync::atomic::{compiler_fence, Ordering},
};
use cortex_m::{interrupt::InterruptNumber, peripheral::NVIC};
use critical_section::CriticalSection;
use paste::paste;
use seq_macro::seq;

/// Marker trait indicating that an interrupt source has one binding and
/// one handler.
pub trait SingleInterruptSource: Sealed {}

/// Marker trait indicating that an interrupt source has multiple bindings and
/// handlers.
pub trait MultipleInterruptSources: Sealed {}

macro_rules! declare_interrupts {
($($(#[$cfg:meta])* $irqs:ident),* $(,)?) => {
$(
Expand All @@ -14,12 +24,17 @@ macro_rules! declare_interrupts {
#[doc=stringify!($irqs)]
#[doc=" typelevel interrupt."]
pub enum $irqs {}

$(#[$cfg])*
impl $crate::typelevel::Sealed for $irqs{}

$(#[$cfg])*
impl $crate::async_hal::interrupts::Interrupt for $irqs {
const IRQ: crate::pac::Interrupt = crate::pac::Interrupt::$irqs;
}

$(#[$cfg])*
impl $crate::async_hal::interrupts::SingleInterruptSource for $irqs {}
)*
}
}
Expand Down Expand Up @@ -55,6 +70,9 @@ macro_rules! declare_multiple_interrupts {
$($crate::pac::Interrupt::$irq.set_priority(prio);)+
}
}

$(#[$cfg])*
impl $crate::async_hal::interrupts::MultipleInterruptSources for $name {}
}
};
}
Expand Down
10 changes: 7 additions & 3 deletions hal/src/async_hal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub mod timer;
/// use atsamd_hal::bind_interrupts;
///
/// bind_interrupts!(struct Irqs {
/// SERCOM0 => sercom::InterruptHandler;
/// SERCOM0 => artsamd_hal::sercom::i2c::InterruptHandler;
/// });
/// ```
#[macro_export]
Expand All @@ -34,7 +34,9 @@ macro_rules! bind_interrupts {
}

$(
unsafe impl $crate::async_hal::interrupts::Binding<$crate::async_hal::interrupts::$irq, $handler> for $name {}
unsafe impl $crate::async_hal::interrupts::Binding<$crate::async_hal::interrupts::$irq, $handler> for $name
where $crate::async_hal::interrupts::$irq: $crate::async_hal::interrupts::SingleInterruptSource
{}
)*
)*
};
Expand All @@ -51,6 +53,8 @@ macro_rules! bind_interrupts {
}
)+

unsafe impl $crate::async_hal::interrupts::Binding<$crate::async_hal::interrupts::$int_source, $handler> for $name {}
unsafe impl $crate::async_hal::interrupts::Binding<$crate::async_hal::interrupts::$int_source, $handler> for $name
where $crate::async_hal::interrupts::$int_source: $crate::async_hal::interrupts::MultipleInterruptSources
{}
};
}

0 comments on commit 9ce5451

Please sign in to comment.