Question

Background:
I am using a cortex-M3 ARM core without an OS.

My main loop waits for a flag from an interrupt handler and then executes a function doBigTask().

Within a separate interrupt handler, I want to execute another function doSmallTask(), but since this function is also non-trivial, I still want other I/O related interrupts to be handled.

My Question:
Are there any issues with simply enabling interrupts from within doSmallTask()? For example, are there any complications with exiting an interrupt handler after interrupts have already been disabled?.

Note: I'm not expecting a re-entrant interrupt to occur as doSmallTask() will finish well before the next interrupt triggers it.

int flag = 0;

void doSmallTask()
{
   asm volatile ("cpsie i");  // Enable interrupts
   // do rest of function
   // ...
}

void irqHandler1()
{
   flag = 1;
}

void irqHandler2()
{
  doSmallTask();
}

void irqHandler3()
{
  // service I/O
}

int main()
{
  while(1)
    if (flag)
    {
      doBigTask();
      flag = 0;
    }
}
Was it helpful?

Solution

First of all, your "flag" variable should be volatile since it is shared between foreground and background code.

But to answer your question, on the Cortex-M, interrupts are already enabled inside an ISR. This is to support interrupt nesting. Inside an ISR, only interrupts of a higher priority will interrupt / preempt the current ISR. So it's very important that interrupt priorities are configured properly.

Read up on the Cortex-M family's NVIC for more information. Note that the interrupt sources, and the number of supported interrupt priorities, are dependent on the silicon vendor. In theory up to 240 external interrupts are supported, in reality it's typically much less.

There was a recent blog post about ARM Cortex M interrupt priorities that explained this in more detail.

OTHER TIPS

You may change the interrupt priority. Set the priority of the irqHandler2 smaller then others.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top