Hi Jim,
About your code, if in the /* ...do some work... */ area, you modify the primask, I think the next
EnableGlobalIRQ(primask);
will be changed, I think this usage may have the risk.
Even if your /* ...do some work... */ didn't modify the primask, I think your code still not very good.
It's better to control the GlobalDisableIRQ and EnableGlobalIRQ in pair, don't have other pair between GlobalDisableIRQ and EnableGlobalIRQ.
I think you can use it like this:
void bar(void)
{
uint32_t primask = GlobalDisableIRQ();
/* ...do some work... */
EnableGlobalIRQ(primask);
foo();
primask = GlobalDisableIRQ();
/* ...do some work... */
EnableGlobalIRQ(primask);
}
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Jim,
You can use the DisableGlobalIRQ, about the primask, it will be returned after your call DisableGlobalIRQ.
You can check the DisableGlobalIRQ function:
static inline uint32_t DisableGlobalIRQ(void)
{
#if defined(CPSR_I_Msk)
uint32_t cpsr = __get_CPSR() & CPSR_I_Msk;
__disable_irq();
return cpsr;
#else
uint32_t regPrimask = __get_PRIMASK();
__disable_irq();
return regPrimask;
#endif
}
About the usage, you can refer to the following code:
uint32_t irqMaskValue;
irqMaskValue = DisableGlobalIRQ();
EnableGlobalIRQ(irqMaskValue);
Wish it helps you!
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Thanks, Kerry, but my question is about nesting calls to GlobalDisableIRQ(), such as...
void foo(void)
{
uint32_t primask = GlobalDisableIRQ();
/* ...do some work... */
EnableGlobalIRQ(primask);
}
void bar(void)
{
uint32_t primask = GlobalDisableIRQ();
/* ...do some work... */
foo();
/* ...do some work... */
EnableGlobalIRQ(primask);
}
Would the above code be valid, such that interrupts would only be re-enabled in function bar, or would interrupts be enabled in function foo, called from function bar?
Hi Jim,
About your code, if in the /* ...do some work... */ area, you modify the primask, I think the next
EnableGlobalIRQ(primask);
will be changed, I think this usage may have the risk.
Even if your /* ...do some work... */ didn't modify the primask, I think your code still not very good.
It's better to control the GlobalDisableIRQ and EnableGlobalIRQ in pair, don't have other pair between GlobalDisableIRQ and EnableGlobalIRQ.
I think you can use it like this:
void bar(void)
{
uint32_t primask = GlobalDisableIRQ();
/* ...do some work... */
EnableGlobalIRQ(primask);
foo();
primask = GlobalDisableIRQ();
/* ...do some work... */
EnableGlobalIRQ(primask);
}
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------