This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NVIC check if IRQ is enabled

Hi,

as far as I see, I can enable or disable external interrupts using NVIC_EnableIRQ() and NVIC_DisableIRQ. Is there a method to check if a specified external interrupt is currently enabled or disabled?

Is this done by NVIC_GetActive()?

Thanks, Tamas

  • Ok,

    I've found out that I work with CMSIS v4.30, which does not have the required method yet. As far as I see, CMSIS v5.0.1 already has a function called NVIC_GetEnableIRQ() (see here).

    So, I decided to borrow the implementation of that function, as seen below. Cited from github.com/.../core_cm4.h (as of 2017-08-03):

    /**
      \brief   Get Interrupt Enable status
      \details Returns a device specific interrupt enable status from the NVIC interrupt controller.
      \param [in]      IRQn  Device specific interrupt number.
      \return             0  Interrupt is not enabled.
      \return             1  Interrupt is enabled.
      \note    IRQn must not be negative.
     */
    __STATIC_INLINE uint32_t __NVIC_GetEnableIRQ(IRQn_Type IRQn)
    {
      if ((int32_t)(IRQn) >= 0)
      {
        return((uint32_t)(((NVIC->ISER[(((uint32_t)(int32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
      }
      else
      {
        return(0U);
      }
    }
    

    Thanks for your time, Tamas

  • No, NVIC_GetActive() will only return 1 when the interrupt is currently being serviced (directly or preempted by a higher priority). So it should always return zero in main() funtion.

    You are probably looking for the NVIC_GetEnableIRQ() function.

    Note that both functions do not work with negative IRQn like SysTick.

Related