AnsweredAssumed Answered

invoking __disable_irq() within an ISR on LPC546xx

Question asked by bob belmont on Jul 18, 2018
Latest reply on Jul 19, 2018 by jeremyzhou

I want to perform an atomic operation on a memory buffer that can be accessed from multiple ISRs. I was thinking of  providing a function that would be called from these ISRs to perform the atomic operation. i.e. :


void foo(void) {     int was_masked = __disable_irq();     /* ... perform atomic operation ... */     if (!was_masked)         __enable_irq(); }

the function 'foo' would be invoked from multiple ISRs.

Is this safe / advisable to do so ? I've read from another thread (see below) that this is not safe. The sentence that brings me concern is :  "As a rule, one should NOT be altering PRIMASK within an interrupt-service routine -- ONLY fiddle with interrupt controls within 'main code' (to protect atomic operations): NOT in interrupt context --"

Could someone please provide me with guidance ?  thank you.


How does “CPSID” (used to control interrupts) work?