This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How I can detect that code executed inside of interrupt?

Other Parts Discussed in Thread: RM46L852

Hello!

I have FreeRTOS and have some functions what can be called inside interrupt handling. FreeRTOS have different functions for ISR and normal mode. How I can understand inside my function what I'm inside interrupt. For STM32 I use next function

inline static bool isInterrupt(void) {
    return (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) != 0;
}

  • For a Cortex-R4, I can't see a Vectored Interrupt Controller (VIM) register which indicates if a vector is currently active. Therefore, suggest using the Mode bits in the Current Program Status Register (CPSR) to determine if currently inside an interrupt or not.

    The following has been tried on a RM46L852 in a FreeRTOS example, and returns true when called from a FIQ or IRQ interrupt context and false when called from a task context:

    #define MODE_BITS 0x1F
    #define FIQ_MODE  0x11
    #define IRQ_MODE  0x12
    
    inline static bool isInterrupt (void)
    {
    	const uint32 mode = _get_CPSR() & MODE_BITS;
    
    	return (mode == FIQ_MODE) || (mode == IRQ_MODE);
    }