invoking __disable_irq() within an ISR on LPC546xx

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

invoking __disable_irq() within an ISR on LPC546xx

1,123 次查看
belmontbob59
Contributor IV

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? 

标签 (2)
0 项奖励
回复
1 回复

937 次查看
jeremyzhou
NXP Employee
NXP Employee

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!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复