2020-04-27 02:52 AM
Hi,
Currently, I am looking for the method to detect this function is under ISR or not.
And I found that there has two snipset code,
<Example 1>
uint8_t isUnderInterrupt(void)
{
uint8_t status = THREAD_MODE;
if (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk)
{
status = ISR_MODE;
}
return status;
}
After I studying programming manual, I think above function is proper method to detect
this function is under ISR or not (If there has wrong thought, please correct me, thank you).
And I check some web example, someone uses freeRTOS with M3 MCU and the Example 2 using different way to implement it, but even I check programming manual, I cannot understand it,
<Example 2>
if (0 == __get_CONTROL())
{
// Under ISR
}
else
{
// Under Normal
}
How can using read out CONTROL register bit (SPSEL, nPRIV) to know MCU is under ISR? (M3 with freeRTOS).
By the way, if Example 2 is good method to know, when I use M4 MCU with FPU, the CONTROL register bit is (FPCA, SPSEL, nPRIV) the Example 2 is still work?
Please to give me some suggestion to guide me which method is proper one when using in M4 with FPU under freeRTOS, thank you so much.
2020-04-27 03:33 AM
If you use FreeRTOS, just call xPortIsInsideInterrupt.
"Some web example" is not a reliable source ;)
-- pa
2020-04-27 03:33 PM
The currently executing interrupt, if any, is stored in the VECTACTIVE bits in SCB->ICSR. This is a cortex register, look there for the details.
// return true if we're in an interrupt
inline bool InInterrupt() {
return SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk;
}
2020-05-11 02:37 AM
Hi,
Thank you all~~~
All your suggestion is very useful : )