# How to use the Non Maskable Interrupt on SAM4S?

I'm trying to use the NMI on a SAM4S (Cortex M4), but I'm finding some hard time to make it work. The main objective is to jump to the NMI handler whenever the power is about to go down, so that I can perform a clean shutdown, saving data that could be lost otherwise.

At the moment, I'm using a PIO controller to jump to an interrupt when a power fail is detected. The code is something like this:

gpio_configure_pin( POWERFAIL_PORT_IDX,POWERFAIL_PORT_FLAGS);
pio_set_input(PIOA, POWERFAIL_PORT,(PIO_PULLUP|PIO_DEBOUNCE));
pio_set_debounce_filter(PIOA,POWERFAIL_PORT, 100);
pio_handler_set(PIOA, ID_PIOA,POWERFAIL_PORT , PIO_IT_FALL_EDGE, Powerfail_Interrupt_Handle);
pio_enable_interrupt(PIOA, POWERFAIL_PORT);
NVIC_EnableIRQ(PIOA_IRQn);


I'd like to set this interruption with maximum priority using the NMI. That way, this interruption would be active all the time, even after calling __disable_irq() in some parts of the code. Until now, I searched the SAM4S datasheet and ASF sources/examples, but I was unable to find any obvious way to do it, or simply realize if it's possible.