Hi
The NVIC configuration for the KL46 is essentially identical to that used by any other Cortex m0/m3/m4/m7 processor. The only thing that needs to be known (for individual processors) is the actual mapping of the interrupt ID to the source (eg. first DMA channel is 0 for all Kinetis parts with it, but the PORTA interrupt on the KL46 is 30 but 59 on a K21, etc. etc.)
The Cortex m4 Kinetis parts have 16 levels of priority and the Cortex m0+ ones only 4 so there is one difference in the code used to configure interrupts (see __NVIC_PRIORITY_SHIFT)
#define __NVIC_PRIORITY_SHIFT 6 // for KE,KEA, KL parts (priorities 0..3)
#define __NVIC_PRIORITY_SHIFT 4 // or other Kinetis parts (priorities 0..15)
To entere an interrupt handler (with its priority) a call can be used such as:
fnEnterInterrupt(irq_PIT_ID, _PRIORITY3, _PIT_Interrupt);
where irq_PIT_ID is 22 for the KL46 and _PIT_Interrupt() is the handling routine. Generic code will map the irq_PIT_ID to the chip so that there is no porting required between chips.
The following is a generic configuration for the NVIC (peripherals also need their own interrupt configured before it enters to the NVIC layer of course):
extern void fnEnterInterrupt(int iInterruptID, unsigned char ucPriority, void (*InterruptFunc)(void))
{
volatile unsigned long *ptrIntSet = IRQ0_31_SER_ADD;
volatile unsigned char *ptrPriority = IRQ0_3_PRIORITY_REGISTER_ADD;
#if !defined INTERRUPT_VECTORS_IN_FLASH
VECTOR_TABLE *ptrVect = (VECTOR_TABLE *)VECTOR_TABLE_OFFSET_REG;
void (**processor_ints)(void);
#endif
#if !defined INTERRUPT_VECTORS_IN_FLASH
processor_ints = (void (**)(void))&ptrVect->processor_interrupts;
processor_ints += iInterruptID;
*processor_ints = InterruptFunc;
#endif
ptrPriority += iInterruptID;
*ptrPriority = (ucPriority << __NVIC_PRIORITY_SHIFT);
ptrIntSet += (iInterruptID/32);
*ptrIntSet = (0x01 << (iInterruptID%32));
}
Notice that INTERRUPT_VECTORS_IN_FLASH removes entering the actual handler address in case these are fixed in Flash, although it is more flexible (and faster) to have then in SRAM.
Regards
Mark
Kinetis for professionals: http://www.utasker.com/kinetis.html