cancel
Showing results for 
Search instead for 
Did you mean: 

__disable_irq() in ISR possible?

Schmid.M.
Senior

Hello,

I have a global variable, wich is accessed by multiple ISRs.

Can I safely disable and re-enable the interrupts within an ISR using __disable_irq() and __enable_irq()?

Or is there a more elegant way of protecting the variable access?

best regards,

Michael Schmid

5 REPLIES 5
Uwe Bonnes
Principal III

You can disable IRQs in an ISR, at the cost of increased jitter for the other ISRS. Ypu can also consider LDREX and STREX

hs2
Senior

If you have a C11 or C++11 compliant compiler you could use the provided atomic ops and data types.

KnarfB
Principal III

nested __disable_irq() and __enable_irq() can cause issues.

Have the interrupts at the same priority so they don't interfere with each other, and be brief?​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Schmid.M.
Senior

Hi,

the Interrupts have different prios. I don't want to use complicated assembler code if not neccessary, and the delay for the high prio task is not critical.

Nesting of the functions should not be a problem as well, as long as I call them only once in the ISR (if the ISR is called, i can be sure the interrupts are not disabled yet by the main task).

So then I will just use these functions, that seems to be easiest solution.

Thanks for your help =)