1
\$\begingroup\$

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.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Atmel SAM4S MPUs feature NVIC interrupt controller that supports only external interrupts to be linked with NMI. You can also trigger it manually, but this won't be of much use to you.

Solution is to have external circuitry that will trigger the NMI using external interrupt on power failures.

Note: If I understand your current solution you try to detect falling edges on power line. I am not sure that this will be reliable, or even fast enough (since you have debouncing filter on the input).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.