Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Routing interrupts to different handlers in runtime #3114

Open
elrafoon opened this issue Jun 24, 2024 · 0 comments
Open

Routing interrupts to different handlers in runtime #3114

elrafoon opened this issue Jun 24, 2024 · 0 comments

Comments

@elrafoon
Copy link

Recently on NRF52832 I needed to route interrupt to one of two handlers - buffered uart driver, unbuffered uart driver - depending on program state.

I came up up with this solution:

static UARTE0_UART_IRQ_TARGET: AtomicBool = AtomicBool::new(false);

struct Uarte0Uart0Irq {}

unsafe impl
    typelevel::Binding<typelevel::UARTE0_UART0, uarte::InterruptHandler<peripherals::UARTE0>>
    for Uarte0Uart0Irq
{
}

unsafe impl
    typelevel::Binding<
        typelevel::UARTE0_UART0,
        buffered_uarte::InterruptHandler<peripherals::UARTE0>,
    > for Uarte0Uart0Irq
{
}

#[allow(non_snake_case)]
#[no_mangle]
unsafe extern "C" fn UARTE0_UART0() {
    if UARTE0_UART_IRQ_TARGET.load(atomic::Ordering::SeqCst) {
        buffered_uarte::InterruptHandler::<peripherals::UARTE0>::on_interrupt()
    } else {
        uarte::InterruptHandler::<peripherals::UARTE0>::on_interrupt()
    }
}

This works good, but it's quite large and ugly code.
Maybe I'm completely missing some already available abstraction.

Could it be replaced with something more elegant?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant