Pass a struct as an argument to the interrupt function in ARM

Hello, I am using s32k142 with freertos (ARM CM4), and i have configured an interrupt on one of the pins (falling edge), and i want to pass an argument for the ISR like this:

intc_register_handler(PORTC_IRQn, (isr_t)port_c_isr, &board);

instead of this:

intc_register_handler(PORTC_IRQn, (isr_t)port_c_isr, NULL);

But the problem is that in the definition of intc_register_handler the parameter is not handled:

void intc_register_handler(unsigned long irq, const isr_t handler, /*@unused@*/ void *priv)
int sirq = (int)irq;


__VECTOR_RAM[sirq + 16] = (uint32_t)handler;

When i saw in other projects that we have which are using MPC57xx, it is done this way:

void intc_register_handler(unsigned long irq, const isr_t handler, void *priv)
    __VECTOR_RAM[irq] = (uint32_t)handler;
    __VECTOR_PRIVATE[irq] = priv;

and __VECTOR_PRIVATE is defined in the FreeRtos port like this:

/* __VECTOR_PRIVATE for interrupt management
 * used by vPortISRHandler

Is there some similar way to do it for CM4 ?

Thank you

By definition, any entry into the IVT lf your MCU can not have parameters. If you want parametrized ISRs, you need to provide a wrapper layer that decodes your instances, for example like so:

IVT delarations:


void UART1Handler(void)

void UART2Handler(void)

Some eco systems have built-in support for this. If the one you use does not, you need to write the wrappers yourself.

1 Like

These are probably your wrappers that @RAc mentioned. It should work for CM4 as well - just ensure that when the registered handler is called, the data you are storing in __VECTOR_PRIVATE is passed as parameter.