carmcortex-mcmsis

On core_cm4.h why is there casting like ((uint32_t)(int32_t)IRQn)?


In the following code from core_cm4.h why is there a double cast ((uint32_t)(int32_t)IRQn)?

For example in the following function:

__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
{
  NVIC->ISER[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
}

What is the purpose of this?


Solution

  • Since CM4 software implements negative interrupt sources for core, you have to cast value first to 32bit signed integer and later to unsigned 32bit to make proper right shift with padding zeros on the left side of number.

    CM4 uses -15 to -1 as CM4-Core sources and from 0 to next as vendor specific sources.