Skip to main content
Schmid.M.
Associate III
November 26, 2020
Question

__disable_irq() in ISR possible?

  • November 26, 2020
  • 5 replies
  • 1248 views

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

    This topic has been closed for replies.

    5 replies

    Uwe Bonnes
    Chief
    November 26, 2020

    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
    Visitor II
    November 26, 2020

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

    KnarfB
    Super User
    November 26, 2020

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

    Tesla DeLorean
    Guru
    November 26, 2020

    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Schmid.M.
    Schmid.M.Author
    Associate III
    November 26, 2020

    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 =)