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.
Hi Bob belmont,
Thank you for your interest in NXP Semiconductor products and for the opportunity to serve you.
It's available, however, I'd highly recommend you to adopt increasing the priority of the interrupt instead of configuring the PRIMASK bit to against other interrupt interfere the current interrupt.
Have a great day,
TIC
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------