6 years, 4 months ago.

Disable other pin Interrupts during ISR

Hi All

In my application the MCU must be in deepsleep and should only wake up after pin interrupt. During the ISR no other interrupts should work AND!!! also they should not be executed after the ISR. So completely ignored!

Example: pin1 executes ISR_1. there is a 1second wait ( yes, i'm using wait in ISR ;-) )

During this wait-state pin-2-key is pressed. This press MUST be ignored. It should not interrupt the wait of ISR1 and should not run after ISR_1 as well.

I'm using code like this for ISR functions:

< code >

void isr_1 ()

{ isr1.disable_irq (); isr2.disable_irq (); isr3.disable_irq ();

do_something () ;

wait (1);

isr1.enable_irq (); isr2.enable_irq (); isr3.enable_irq (); }

< /code >

mbed library is from last week , Revision 635:a11c037, lpc11u24 board

With this code, the isr_1 is not "interrupted" by isr_2, BUT the isr_2 will be executed direct after isr_1. This is a wrong behavior for me. It should be ignored.

What should I do to get it work like I want?

Regards dimashek

There is no need for you to disable and re-enable interrupts, an interrupt won't interrupt an interrupt unless it's higher priority. Mbed defaults to all interrupts having the same priority.

I think what you need to do is change how your code is structured so that the interrupts happen but get ignored. Which means you need to exit your first ISR rather than waiting there, that way other button presses will get processed before your 1 second time out. But it also means that the code to process them can decide to do nothing.

Syntax for the Timeout could well be wrong, I'm going from memory here.

volatile bool isrInProgress = false;
Timeout isrEnd;

void isr_1() {
  if(isrInProgress)   // if another key press is happening then exit the isr
    return;
  isrInProgress = true;
  doSomething();
  isrEnd.attach(&waitOver(),1);  // something will happen in 1 seconds time.
}

void waitOver() {  // after 1 second start to allow other key presses again.
  isrInProgress = false;
}
posted by Andy A 28 Nov 2017

1 Answer

6 years, 4 months ago.

Mbed has critical sections, which will disable interrupts. Enter a critical section when your ISR fires, and exit the critical section when you're done.

See https://docs.mbed.com/docs/mbed-os-handbook/en/latest/concepts/thread_safety/#critical-sections and https://github.com/ARMmbed/mbed-os/blob/master/platform/mbed_critical.h.

We also use it internally in Mbed OS 5, example here.