Macro svd2rust::interrupt

source ·
macro_rules! interrupt {
    ($NAME:ident, $path:path) => { ... };
    ($NAME:ident, $path:path, locals: {
        $($lvar:ident: $lty:ty = $lval:expr;)+
    }) => { ... };
}
Expand description

Assigns a handler to an interrupt

NOTE The interrupt! macro on Cortex-M and MSP430 device crates is closer in syntax to the exception! macro. This documentation doesn’t apply to it. For the exact syntax of this macro check the documentation of the device crate you are using.

This macro takes two arguments: the name of an interrupt and the path to the function that will be used as the handler of that interrupt. That function must have signature fn().

Optionally, a third argument may be used to declare interrupt local data. The handler will have exclusive access to these local variables on each invocation. If the third argument is used then the signature of the handler function must be fn(&mut $NAME::Locals) where $NAME is the first argument passed to the macro.

§Example

interrupt!(TIM2, periodic);

fn periodic() {
    print!(".");
}

interrupt!(TIM3, tick, locals: {
    tick: bool = false;
});

fn tick(locals: &mut TIM3::Locals) {
    locals.tick = !locals.tick;

    if locals.tick {
        println!("Tick");
    } else {
        println!("Tock");
    }
}