[En-Nut-Discussion] Cortex ix_xxx_interuptY code duplication

Uwe Bonnes bon at elektron.ikp.physik.tu-darmstadt.de
Mon Jul 16 18:12:57 CEST 2012


Hello (Ole),

at present nearly each nut/arch/cm3/dev/xxx/ih_xxx_*.c file implements it's
own xxxIrqCtl(int cmd, void *param) function.  The core of that function is
always the same, apart from a different xxxIrqEntry and xxx_IRQn
settings. Not a very maintainable situation.

E.g. for STM32 twi1, Ulrich relayed both TWI interupts to a common IrqCtl
function:

#ifdef NUT_PERFMON
static int TwoWireIrqCtl(IRQn_Type IRQn, void(*ifunc)(void*), IRQ_HANDLER *ih, int cmd, void *param);
#else
static int TwoWireIrqCtl(IRQn_Type IRQn, void(*ifunc)(void*), int cmd, void *param);
#endif

static int TwoWireIrqCtl_Ev(int cmd, void *param);

IRQ_HANDLER sig_TWI1_EV = {
#ifdef NUT_PERFMON
    0,                  /* Interrupt counter, ir_count. */
#endif
    NULL,               /* Passed argument, ir_arg. */
    NULL,               /* Handler subroutine, ir_handler. */
    TwoWireIrqCtl_Ev    /* Interrupt control, ir_ctl. */
};

/*!
 * \brief Two Wire Interface Event Interrupt Entry.
 */
static void TwoWireIrqEntry_Ev(void *arg)
{
#ifdef NUT_PERFMON
    sig_TWI1_EV.ir_count++;
#endif
    if (sig_TWI1_EV.ir_handler) {
        (sig_TWI1_EV.ir_handler) (sig_TWI1_EV.ir_arg);
    }
}

static int TwoWireIrqCtl_Ev(int cmd, void *param)
{
    return TwoWireIrqCtl(I2C1_EV_IRQn, TwoWireIrqEntry_Ev, cmd, param);
}

#ifdef NUT_PERFMON
static int TwoWireIrqCtl(IRQn_Type IRQn, void(*ifunc)(void*), IRQ_HANDLER *ih, int cmd, void *param)
#else
static int TwoWireIrqCtl(IRQn_Type IRQn, void(*ifunc)(void*), int cmd, void *param)
#endif
{
...
Shouldn't we extend above TwoWireIrqCtl() to a IrqCtl() function in
e.g. arch/cm3/os, replacing all xxxIrqCtl() functtions.

I think the additional redirection in the case of the common IrqCtl()
doesn't matter. That way, much code duplication could be avoided. And
perhaps all ih_xxx_uartY.c file be concatenated into one ih_xxx_uart.c file,
with each uartx entry safegaurded by #if defined (UARTx_BASE)". Perhas even
one file for all IRQ_HANDLERs.

NUT_IRQCTL_GETMODE/NUT_IRQCTL_SETMODE might need a special consideration, as
Ulrich marked some interrupt handlers as NUT_IRQMODE_LEVEL versus the
default NUT_IRQMODE_EDGE everywhere in nxp and mostly in stm32. Perhaps we
need to extend IRQ_HANDLER structure for a entry of the Handler
mode, and relay the mode via IrqCtl() . However I have not seen any consumer of the
NUT_IRQCTL_GETMODE/NUT_IRQCTL_SETMODE function in our codebase yet. GPIO is a
consumer for sure, but for  NXP Ole just implemented GPIO_SIGNAL redirection,
handling that case and I will probably reuse for STM.

Bye
-- 
Uwe Bonnes                bon at elektron.ikp.physik.tu-darmstadt.de

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
--------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------



More information about the En-Nut-Discussion mailing list