Proper method to know function under interrupt
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.