Ryan
I think that your code is functionally OK.
You could also consider:
extern void routine(int iInterruptID, void (*InterruptFunc)(void))
{
void (**processor_ints)(void) = (void (**)(void))VECTOR_TABLE_OFFSET_REG;
processor_ints += iInterruptID;
*processor_ints = InterruptFunc;
}
extern void routine(int iInterruptID, void (*InterruptFunc)(void))
{
VECTOR_TABLE *ptrVect = (VECTOR_TABLE *)VECTOR_TABLE_OFFSET_REG;
void (**processor_ints)(void);
processor_ints = (void (**)(void))&ptrVect->processor_interrupts;
processor_ints += iInterruptID;
*processor_ints = InterruptFunc;
}
As reference, below is the interrupt handler entry function from the uTasker project which includes also interrupt priority (for M4 and M0+), and interrupt unmasking and compatibility with Flash and RAM locations, as well as Kinetis parts with INTMUX module. INTMUX video is at https://youtu.be/zKa5BoOhBrg
Regards
Mark
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 INTMUX0_AVAILABLE
if (iInterruptID >= irq_INTMUX0_0_ID) {
KINETIS_INTMUX *ptrINTMUX = (KINETIS_INTMUX *)INTMUX0_BLOCK;
int iChannel = (iInterruptID - irq_INTMUX0_0_ID);
#if defined KINETIS_WITH_PCC
PCC_INTMUX0 |= PCC_CGC;
#else
POWER_UP_ATOMIC(6, INTMUX0);
#endif
ptrINTMUX += iChannel;
ptrINTMUX->INTMUX_CHn_IER_31_0 |= (1 << ucPriority);
#if !defined INTERRUPT_VECTORS_IN_FLASH
processor_ints = (void(**)(void))&ptrVect->processor_interrupts;
processor_ints += (irq_INTMUX0_3_ID + 1 + ucPriority);
*processor_ints = InterruptFunc;
#endif
iInterruptID = (irq_INTMUX0_0_ID + iChannel);
switch (iChannel) {
case 0:
InterruptFunc = fnINTMUX0;
ucPriority = PRIORITY_INTMUX0_0_INT;
break;
case 1:
InterruptFunc = fnINTMUX1;
ucPriority = PRIORITY_INTMUX0_1_INT;
break;
case 2:
InterruptFunc = fnINTMUX2;
ucPriority = PRIORITY_INTMUX0_2_INT;
break;
case 3:
InterruptFunc = fnINTMUX3;
ucPriority = PRIORITY_INTMUX0_3_INT;
break;
default:
_EXCEPTION("Illegal INTMUX0 channel!");
break;
}
}
#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));
}