diff --git a/arch/arm/src/lpc214x/lpc214x_serial.c b/arch/arm/src/lpc214x/lpc214x_serial.c index 47d0e8e47a7..92675a538be 100644 --- a/arch/arm/src/lpc214x/lpc214x_serial.c +++ b/arch/arm/src/lpc214x/lpc214x_serial.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/lpc214x/lpc214x_serial.c * - * Copyright (C) 2007-2009, 2012-2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2012-2013, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -88,7 +88,7 @@ static int up_setup(struct uart_dev_s *dev); static void up_shutdown(struct uart_dev_s *dev); static int up_attach(struct uart_dev_s *dev); static void up_detach(struct uart_dev_s *dev); -static int up_interrupt(int irq, void *context, FAR void *arg); +static int up_interrupt(int irq, void *context, void *arg); static int up_ioctl(struct file *filep, int cmd, unsigned long arg); static int up_receive(struct uart_dev_s *dev, uint32_t *status); static void up_rxint(struct uart_dev_s *dev, bool enable); @@ -413,7 +413,7 @@ static int up_attach(struct uart_dev_s *dev) /* Attach and enable the IRQ */ - ret = irq_attach(priv->irq, up_interrupt, NULL); + ret = irq_attach(priv->irq, up_interrupt, dev); if (ret == OK) { /* Enable the interrupt (RX and TX interrupts are still disabled @@ -456,25 +456,14 @@ static void up_detach(struct uart_dev_s *dev) * ****************************************************************************/ -static int up_interrupt(int irq, void *context, FAR void *arg) +static int up_interrupt(int irq, void *context, void *arg) { - struct uart_dev_s *dev = NULL; + struct uart_dev_s *dev = (struct uart_dev_s *)arg; struct up_dev_s *priv; uint8_t status; int passes; - if (g_uart1priv.irq == irq) - { - dev = &g_uart1port; - } - else if (g_uart0priv.irq == irq) - { - dev = &g_uart0port; - } - else - { - PANIC(); - } + DEBUGASSERT(dev != NULL && dev->priv != NULL); priv = (struct up_dev_s *)dev->priv; /* Loop until there are no characters to be transferred or, diff --git a/arch/arm/src/lpc2378/lpc23xx_i2c.c b/arch/arm/src/lpc2378/lpc23xx_i2c.c index b877d56279a..8191179f110 100644 --- a/arch/arm/src/lpc2378/lpc23xx_i2c.c +++ b/arch/arm/src/lpc2378/lpc23xx_i2c.c @@ -298,34 +298,11 @@ static void lpc2378_stopnext(struct lpc2378_i2cdev_s *priv) static int lpc2378_i2c_interrupt(int irq, FAR void *context, FAR void *arg) { - struct lpc2378_i2cdev_s *priv; + struct lpc2378_i2cdev_s *priv = (struct lpc2378_i2cdev_s *)arg; struct i2c_msg_s *msg; uint32_t state; -#ifdef CONFIG_LPC2378_I2C0 - if (irq == I2C0_IRQ) - { - priv = &g_i2c0dev; - } - else -#endif -#ifdef CONFIG_LPC2378_I2C1 - if (irq == I2C1_IRQ) - { - priv = &g_i2c1dev; - } - else -#endif -#ifdef CONFIG_LPC2378_I2C2 - if (irq == I2C2_IRQ) - { - priv = &g_i2c2dev; - } - else -#endif - { - PANIC(); - } + DEBUGASSERT(priv != NULL); /* Reference UM10360 19.10.5 */ @@ -619,7 +596,7 @@ struct i2c_master_s *lpc2378_i2cbus_initialize(int port) /* Attach Interrupt Handler */ - irq_attach(priv->irqid, lpc2378_i2c_interrupt, NULL); + irq_attach(priv->irqid, lpc2378_i2c_interrupt, priv); /* Enable Interrupt Handler */ diff --git a/arch/arm/src/lpc2378/lpc23xx_serial.c b/arch/arm/src/lpc2378/lpc23xx_serial.c index c74b0594f50..c927b07a2c0 100644 --- a/arch/arm/src/lpc2378/lpc23xx_serial.c +++ b/arch/arm/src/lpc2378/lpc23xx_serial.c @@ -96,7 +96,7 @@ static int up_setup(struct uart_dev_s *dev); static void up_shutdown(struct uart_dev_s *dev); static int up_attach(struct uart_dev_s *dev); static void up_detach(struct uart_dev_s *dev); -static int up_interrupt(int irq, void *context, FAR void *arg); +static int up_interrupt(int irq, void *context, void *arg); static int up_ioctl(struct file *filep, int cmd, unsigned long arg); static int up_receive(struct uart_dev_s *dev, uint32_t * status); static void up_rxint(struct uart_dev_s *dev, bool enable); @@ -533,7 +533,7 @@ static int up_attach(struct uart_dev_s *dev) /* Attach and enable the IRQ */ - ret = irq_attach(priv->irq, up_interrupt, NULL); + ret = irq_attach(priv->irq, up_interrupt, dev); if (ret == OK) { /* Enable the interrupt (RX and TX interrupts are still disabled in the @@ -581,25 +581,14 @@ static void up_detach(struct uart_dev_s *dev) * ****************************************************************************/ -static int up_interrupt(int irq, void *context, FAR void *arg) +static int up_interrupt(int irq, void *context, void *arg) { - struct uart_dev_s *dev = NULL; + struct uart_dev_s *dev = (struct uart_dev_s *)arg; struct up_dev_s *priv; uint8_t status; int passes; - if (g_uart0priv.irq == irq) - { - dev = &g_uart0port; - } - else if (g_uart2priv.irq == irq) - { - dev = &g_uart2port; - } - else - { - PANIC(); - } + DEBUGASSERT(dev != NULL && dev->priv != NULL); priv = (struct up_dev_s *)dev->priv; /* Loop until there are no characters to be transferred or, until we have diff --git a/arch/arm/src/lpc31xx/lpc31_i2c.c b/arch/arm/src/lpc31xx/lpc31_i2c.c index 0e4ff893278..8d79ac56e3d 100644 --- a/arch/arm/src/lpc31xx/lpc31_i2c.c +++ b/arch/arm/src/lpc31xx/lpc31_i2c.c @@ -3,7 +3,7 @@ * * Author: David Hewson * - * Copyright (C) 2010-2011, 2014, 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2010-2011, 2014, 2016-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -186,16 +186,10 @@ static void i2c_setfrequency(struct lpc31_i2cdev_s *priv, uint32_t frequency) static int i2c_interrupt(int irq, FAR void *context, FAR void *arg) { - if (irq == LPC31_IRQ_I2C0) - { - i2c_progress(&i2cdevices[0]); - } - - if (irq == LPC31_IRQ_I2C1) - { - i2c_progress(&i2cdevices[1]); - } + struct lpc31_i2cdev_s *priv = (struct lpc31_i2cdev_s *)arg; + DEBUGASSERT(priv != NULL); + i2c_progress(priv); return OK; } @@ -585,7 +579,7 @@ struct i2c_master_s *lpc31_i2cbus_initialize(int port) /* Attach Interrupt Handler */ - irq_attach(priv->irqid, i2c_interrupt, NULL); + irq_attach(priv->irqid, i2c_interrupt, priv); /* Enable Interrupt Handler */ diff --git a/arch/arm/src/lpc43xx/lpc43_i2c.c b/arch/arm/src/lpc43xx/lpc43_i2c.c index 15a23fe1ddb..2c8fcb63bee 100644 --- a/arch/arm/src/lpc43xx/lpc43_i2c.c +++ b/arch/arm/src/lpc43xx/lpc43_i2c.c @@ -279,27 +279,11 @@ void lpc32_i2c_nextmsg(struct lpc43_i2cdev_s *priv) static int lpc43_i2c_interrupt(int irq, FAR void *context, FAR void *arg) { - struct lpc43_i2cdev_s *priv; + struct lpc43_i2cdev_s *priv = (struct lpc43_i2cdev_s *)arg; struct i2c_msg_s *msg; uint32_t state; -#ifdef CONFIG_LPC43_I2C0 - if (irq == LPC43M0_IRQ_I2C0) - { - priv = &g_i2c0dev; - } - else -#endif -#ifdef CONFIG_LPC43_I2C1 - if (irq == LPC43_IRQ_I2C1) - { - priv = &g_i2c1dev; - } - else -#endif - { - PANIC(); - } + DEBUGASSERT(priv != NULL); /* Reference UM10360 19.10.5 */ @@ -558,7 +542,7 @@ struct i2c_master_s *lpc43_i2cbus_initialize(int port) /* Attach Interrupt Handler */ - irq_attach(priv->irqid, lpc43_i2c_interrupt, NULL); + irq_attach(priv->irqid, lpc43_i2c_interrupt, priv); /* Enable Interrupt Handler */ diff --git a/arch/arm/src/lpc43xx/lpc43_serial.c b/arch/arm/src/lpc43xx/lpc43_serial.c index 151c17ba29d..bf3e9613bfb 100644 --- a/arch/arm/src/lpc43xx/lpc43_serial.c +++ b/arch/arm/src/lpc43xx/lpc43_serial.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/lpc43xx/lpc43_serial.c * - * Copyright (C) 2012-2013, 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2012-2013, 2016-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -106,7 +106,7 @@ static int up_setup(struct uart_dev_s *dev); static void up_shutdown(struct uart_dev_s *dev); static int up_attach(struct uart_dev_s *dev); static void up_detach(struct uart_dev_s *dev); -static int up_interrupt(int irq, void *context, FAR void *arg); +static int up_interrupt(int irq, void *context, void *arg); static int up_ioctl(struct file *filep, int cmd, unsigned long arg); #ifdef HAVE_RS485 static inline int up_set_rs485_mode(struct up_dev_s *priv, @@ -661,7 +661,7 @@ static int up_attach(struct uart_dev_s *dev) /* Attach and enable the IRQ */ - ret = irq_attach(priv->irq, up_interrupt, NULL); + ret = irq_attach(priv->irq, up_interrupt, dev); if (ret == OK) { /* Enable the interrupt (RX and TX interrupts are still disabled @@ -702,44 +702,14 @@ static void up_detach(struct uart_dev_s *dev) * ****************************************************************************/ -static int up_interrupt(int irq, void *context, FAR void *arg) +static int up_interrupt(int irq, void *context, void *arg) { - struct uart_dev_s *dev = NULL; + struct uart_dev_s *dev = (struct uart_dev_s *)arg; struct up_dev_s *priv; uint32_t status; int passes; -#ifdef CONFIG_LPC43_USART0 - if (g_usart0priv.irq == irq) - { - dev = &g_usart0port; - } - else -#endif -#ifdef CONFIG_LPC43_UART1 - if (g_uart1priv.irq == irq) - { - dev = &g_uart1port; - } - else -#endif -#ifdef CONFIG_LPC43_USART2 - if (g_usart2priv.irq == irq) - { - dev = &g_usart2port; - } - else -#endif -#ifdef CONFIG_LPC43_USART3 - if (g_usart3priv.irq == irq) - { - dev = &g_usart3port; - } - else -#endif - { - PANIC(); - } + DEBUGASSERT(dev != NULL && dev->priv != NULL); priv = (struct up_dev_s *)dev->priv; /* Loop until there are no characters to be transferred or, diff --git a/arch/arm/src/nuc1xx/nuc_serial.c b/arch/arm/src/nuc1xx/nuc_serial.c index 1adb0ce8315..0932cfaf99d 100644 --- a/arch/arm/src/nuc1xx/nuc_serial.c +++ b/arch/arm/src/nuc1xx/nuc_serial.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/nuc1xx/nuc_serial.c * - * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2013, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -101,7 +101,7 @@ static int up_setup(struct uart_dev_s *dev); static void up_shutdown(struct uart_dev_s *dev); static int up_attach(struct uart_dev_s *dev); static void up_detach(struct uart_dev_s *dev); -static int up_interrupt(int irq, void *context, FAR void *arg); +static int up_interrupt(int irq, void *context, void *arg); static int up_ioctl(struct file *filep, int cmd, unsigned long arg); static int up_receive(struct uart_dev_s *dev, uint32_t *status); static void up_rxint(struct uart_dev_s *dev, bool enable); @@ -568,7 +568,7 @@ static int up_attach(struct uart_dev_s *dev) /* Attach and enable the IRQ */ - ret = irq_attach(priv->irq, up_interrupt, NULL); + ret = irq_attach(priv->irq, up_interrupt, dev); if (ret == OK) { /* Enable the interrupt (RX and TX interrupts are still disabled @@ -610,9 +610,9 @@ static void up_detach(struct uart_dev_s *dev) * ****************************************************************************/ -static int up_interrupt(int irq, void *context, FAR void *arg) +static int up_interrupt(int irq, void *context, void *arg) { - struct uart_dev_s *dev = NULL; + struct uart_dev_s *dev = (struct uart_dev_s *)arg; struct nuc_dev_s *priv; uint32_t isr; uint32_t regval; @@ -620,30 +620,7 @@ static int up_interrupt(int irq, void *context, FAR void *arg) bool rxto; bool rxfe; -#ifdef CONFIG_NUC_UART0 - if (g_uart0priv.irq == irq) - { - dev = &g_uart0port; - } - else -#endif -#ifdef CONFIG_NUC_UART1 - if (g_uart1priv.irq == irq) - { - dev = &g_uart1port; - } - else -#endif -#ifdef CONFIG_NUC_UART2 - if (g_uart2priv.irq == irq) - { - dev = &g_uart2port; - } - else -#endif - { - PANIC(); - } + DEBUGASSERT(dev != NULL && dev->priv != NULL); priv = (struct nuc_dev_s *)dev->priv; /* Loop until there are no characters to be transferred or, diff --git a/arch/arm/src/sam34/sam4cm_tc.c b/arch/arm/src/sam34/sam4cm_tc.c index 330f9382b66..c366118f4d0 100644 --- a/arch/arm/src/sam34/sam4cm_tc.c +++ b/arch/arm/src/sam34/sam4cm_tc.c @@ -147,8 +147,7 @@ static inline void sam_chan_putreg(struct sam_chan_s *chan, /* Interrupt Handling *******************************************************/ -static int sam_tc_interrupt(struct sam_chan_s *tc); -static int sam_raw_interrupt(int irq, void *context, FAR void *arg); +static int sam_tc_interrupt(int irq, void *context, FAR void *arg); /* Initialization ***********************************************************/ @@ -535,14 +534,17 @@ static inline void sam_chan_putreg(struct sam_chan_s *chan, unsigned int offset, * ****************************************************************************/ -static int sam_tc_interrupt(struct sam_chan_s *chan) +static int sam_tc_interrupt(int irq, void *context, FAR void *arg) { + struct sam_chan_s *chan = (struct sam_chan_s *)arg; uint32_t sr; uint32_t imr; uint32_t pending; /* Process interrupts */ + DEBUGASSERT(chan != NULL); + /* Get the interrupt status for this channel */ sr = sam_chan_getreg(chan, SAM_TC_SR_OFFSET); @@ -575,41 +577,10 @@ static int sam_tc_interrupt(struct sam_chan_s *chan) return OK; } -/**************************************************************************** - * Name: sam_raw_interrupt - * - * Description: - * Timer block interrupt handlers - * - * Input Parameters: - * irq - * context - * - * Returned Value: - * - ****************************************************************************/ - -static int sam_raw_interrupt(int irq, void *context, FAR void *arg) -{ - int i; - struct sam_chan_s *chan; - - for (i = 0; i < ENABLED_CHANNELS; i++) - { - chan = &g_channels[i]; - - if (chan->irq == irq) - { - return sam_tc_interrupt(chan); - } - } - - return OK; -} - /**************************************************************************** * Initialization ****************************************************************************/ + /**************************************************************************** * Name: sam_tc_mckdivider * @@ -816,7 +787,7 @@ static inline struct sam_chan_s *sam_tc_initialize(int channel) /* Attach the timer interrupt handler and enable the timer interrupts */ - (void)irq_attach(chan->irq, sam_raw_interrupt, NULL); + (void)irq_attach(chan->irq, sam_tc_interrupt, chan); up_enable_irq(chan->irq); /* Now the channel is initialized */ diff --git a/arch/arm/src/sam34/sam_rtt.c b/arch/arm/src/sam34/sam_rtt.c index 8b7120cfc32..7978b01bf38 100644 --- a/arch/arm/src/sam34/sam_rtt.c +++ b/arch/arm/src/sam34/sam_rtt.c @@ -277,10 +277,10 @@ static void sam34_putreg(uint32_t val, uint32_t addr) static int sam34_interrupt(int irq, FAR void *context, FAR void *arg) { - FAR struct sam34_lowerhalf_s *priv = &g_tcdev; + FAR struct sam34_lowerhalf_s *priv = (FAR struct sam34_lowerhalf_s *)arg; tmrinfo("Entry\n"); - DEBUGASSERT(irq == SAM_IRQ_RTT); + DEBUGASSERT(priv != NULL); /* Check if the interrupt is really pending */ @@ -650,7 +650,7 @@ void sam_rttinitialize(FAR const char *devpath) priv->ops = &g_tcops; - (void)irq_attach(SAM_IRQ_RTT, sam34_interrupt, NULL); + (void)irq_attach(SAM_IRQ_RTT, sam34_interrupt, priv); /* Enable NVIC interrupt. */ diff --git a/arch/arm/src/sam34/sam_serial.c b/arch/arm/src/sam34/sam_serial.c index b3b5854878a..60f074dbf53 100644 --- a/arch/arm/src/sam34/sam_serial.c +++ b/arch/arm/src/sam34/sam_serial.c @@ -370,7 +370,7 @@ static int up_setup(struct uart_dev_s *dev); static void up_shutdown(struct uart_dev_s *dev); static int up_attach(struct uart_dev_s *dev); static void up_detach(struct uart_dev_s *dev); -static int up_interrupt(int irq, void *context, FAR void *arg); +static int up_interrupt(int irq, void *context, void *arg); static int up_ioctl(struct file *filep, int cmd, unsigned long arg); static int up_receive(struct uart_dev_s *dev, uint32_t *status); static void up_rxint(struct uart_dev_s *dev, bool enable); @@ -872,7 +872,7 @@ static int up_attach(struct uart_dev_s *dev) /* Attach and enable the IRQ */ - ret = irq_attach(priv->irq, up_interrupt, NULL); + ret = irq_attach(priv->irq, up_interrupt, dev); if (ret == OK) { /* Enable the interrupt (RX and TX interrupts are still disabled @@ -913,61 +913,16 @@ static void up_detach(struct uart_dev_s *dev) * ****************************************************************************/ -static int up_interrupt(int irq, void *context, FAR void *arg) +static int up_interrupt(int irq, void *context, void *arg) { - struct uart_dev_s *dev = NULL; + struct uart_dev_s *dev = (struct uart_dev_s *)arg; struct up_dev_s *priv; uint32_t pending; uint32_t imr; int passes; bool handled; -#ifdef CONFIG_SAM34_UART0 - if (g_uart0priv.irq == irq) - { - dev = &g_uart0port; - } - else -#endif -#ifdef CONFIG_SAM34_UART1 - if (g_uart1priv.irq == irq) - { - dev = &g_uart1port; - } - else -#endif -#ifdef CONFIG_SAM34_USART0 - if (g_usart0priv.irq == irq) - { - dev = &g_usart0port; - } - else -#endif -#ifdef CONFIG_SAM34_USART1 - if (g_usart1priv.irq == irq) - { - dev = &g_usart1port; - } - else -#endif -#ifdef CONFIG_SAM34_USART2 - if (g_usart2priv.irq == irq) - { - dev = &g_usart2port; - } - else -#endif -#ifdef CONFIG_SAM34_USART3 - if (g_usart3priv.irq == irq) - { - dev = &g_usart3port; - } - else -#endif - { - PANIC(); - } - + DEBUGASSERT(dev != NULL && dev->priv != NULL); priv = (struct up_dev_s *)dev->priv; /* Loop until there are no characters to be transferred or, until we have diff --git a/arch/arm/src/stm32/stm32f20xxx_dma.c b/arch/arm/src/stm32/stm32f20xxx_dma.c index 4ab975de781..6fb9d33cee1 100644 --- a/arch/arm/src/stm32/stm32f20xxx_dma.c +++ b/arch/arm/src/stm32/stm32f20xxx_dma.c @@ -482,7 +482,7 @@ void weak_function up_dmainitialize(void) /* Attach DMA interrupt vectors */ - (void)irq_attach(dmast->irq, stm32_dmainterrupt, NULL); + (void)irq_attach(dmast->irq, stm32_dmainterrupt, dmast); /* Disable the DMA stream */ diff --git a/arch/arm/src/stm32/stm32f40xxx_dma.c b/arch/arm/src/stm32/stm32f40xxx_dma.c index aec0712cc74..1824c76bf46 100644 --- a/arch/arm/src/stm32/stm32f40xxx_dma.c +++ b/arch/arm/src/stm32/stm32f40xxx_dma.c @@ -369,7 +369,7 @@ static void stm32_dmastreamdisable(struct stm32_dma_s *dmast) * ************************************************************************************/ -static int stm32_dmainterrupt(int irq, void *context, FAR void *arg) +static int stm32_dmainterrupt(int irq, void *context, void *arg) { struct stm32_dma_s *dmast; uint32_t status; @@ -481,7 +481,7 @@ void weak_function up_dmainitialize(void) /* Attach DMA interrupt vectors */ - (void)irq_attach(dmast->irq, stm32_dmainterrupt, NULL); + (void)irq_attach(dmast->irq, stm32_dmainterrupt, dmast); /* Disable the DMA stream */ diff --git a/arch/arm/src/stm32f7/stm32_dma.c b/arch/arm/src/stm32f7/stm32_dma.c index 8f405b0594e..e1d8256f091 100644 --- a/arch/arm/src/stm32f7/stm32_dma.c +++ b/arch/arm/src/stm32f7/stm32_dma.c @@ -482,7 +482,7 @@ void weak_function up_dmainitialize(void) /* Attach DMA interrupt vectors */ - (void)irq_attach(dmast->irq, stm32_dmainterrupt, NULL); + (void)irq_attach(dmast->irq, stm32_dmainterrupt, dmast); /* Disable the DMA stream */ diff --git a/arch/arm/src/str71x/str71x_serial.c b/arch/arm/src/str71x/str71x_serial.c index 3e5076648ed..f1688ae3838 100644 --- a/arch/arm/src/str71x/str71x_serial.c +++ b/arch/arm/src/str71x/str71x_serial.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/str71x/str71x_serial.c * - * Copyright (C) 2008-2009, 2012-2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009, 2012-2013, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -254,7 +254,7 @@ static int up_setup(struct uart_dev_s *dev); static void up_shutdown(struct uart_dev_s *dev); static int up_attach(struct uart_dev_s *dev); static void up_detach(struct uart_dev_s *dev); -static int up_interrupt(int irq, void *context, FAR void *arg); +static int up_interrupt(int irq, void *context, void *arg); static int up_ioctl(struct file *filep, int cmd, unsigned long arg); static int up_receive(struct uart_dev_s *dev, uint32_t *status); static void up_rxint(struct uart_dev_s *dev, bool enable); @@ -618,7 +618,7 @@ static int up_attach(struct uart_dev_s *dev) /* Attach and enable the IRQ */ - ret = irq_attach(priv->irq, up_interrupt, NULL); + ret = irq_attach(priv->irq, up_interrupt, dev); if (ret == OK) { /* Enable the interrupt (RX and TX interrupts are still disabled @@ -667,47 +667,15 @@ static void up_detach(struct uart_dev_s *dev) * ****************************************************************************/ -static int up_interrupt(int irq, void *context, FAR void *arg) +static int up_interrupt(int irq, void *context, void *arg) { - struct uart_dev_s *dev = NULL; + struct uart_dev_s *dev = (struct uart_dev_s *)arg; struct up_dev_s *priv; int passes; bool handled; -#ifdef CONFIG_STR71X_UART0 - if (g_uart0priv.irq == irq) - { - dev = &g_uart0port; - } - else -#endif -#ifdef CONFIG_STR71X_UART1 - if (g_uart1priv.irq == irq) - { - dev = &g_uart1port; - } - else -#endif -#ifdef CONFIG_STR71X_UART2 - if (g_uart2priv.irq == irq) - { - dev = &g_uart2port; - } - else -#endif -#ifdef CONFIG_STR71X_UART3 - if (g_uart3priv.irq == irq) - { - dev = &g_uart3port; - } - else -#endif - { - PANIC(); - } - + DEBUGASSERT(dev != NULL && dev->priv != NULL); priv = (struct up_dev_s *)dev->priv; - DEBUGASSERT(priv && dev); /* Loop until there are no characters to be transferred or, * until we have been looping for a long time. diff --git a/arch/arm/src/tiva/tiva_serial.c b/arch/arm/src/tiva/tiva_serial.c index 6a2f3e055b1..da2aedf70f4 100644 --- a/arch/arm/src/tiva/tiva_serial.c +++ b/arch/arm/src/tiva/tiva_serial.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/tiva/tiva_serial.c * - * Copyright (C) 2009-2010, 2012-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2009-2010, 2012-2014, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -322,7 +322,7 @@ static int up_setup(struct uart_dev_s *dev); static void up_shutdown(struct uart_dev_s *dev); static int up_attach(struct uart_dev_s *dev); static void up_detach(struct uart_dev_s *dev); -static int up_interrupt(int irq, void *context, FAR void *arg); +static int up_interrupt(int irq, void *context, void *arg); static int up_ioctl(struct file *filep, int cmd, unsigned long arg); static int up_receive(struct uart_dev_s *dev, uint32_t *status); static void up_rxint(struct uart_dev_s *dev, bool enable); @@ -903,7 +903,7 @@ static int up_attach(struct uart_dev_s *dev) /* Attach and enable the IRQ */ - ret = irq_attach(priv->irq, up_interrupt, NULL); + ret = irq_attach(priv->irq, up_interrupt, dev); if (ret == OK) { /* Enable the interrupt (RX and TX interrupts are still disabled @@ -946,74 +946,15 @@ static void up_detach(struct uart_dev_s *dev) * ****************************************************************************/ -static int up_interrupt(int irq, void *context, FAR void *arg) +static int up_interrupt(int irq, void *context, void *arg) { - struct uart_dev_s *dev = NULL; + struct uart_dev_s *dev = (struct uart_dev_s *)arg; struct up_dev_s *priv; uint32_t mis; int passes; bool handled; -#ifdef CONFIG_TIVA_UART0 - if (g_uart0priv.irq == irq) - { - dev = &g_uart0port; - } - else -#endif -#ifdef CONFIG_TIVA_UART1 - if (g_uart1priv.irq == irq) - { - dev = &g_uart1port; - } - else -#endif -#ifdef CONFIG_TIVA_UART2 - if (g_uart2priv.irq == irq) - { - dev = &g_uart2port; - } - else -#endif -#ifdef CONFIG_TIVA_UART3 - if (g_uart3priv.irq == irq) - { - dev = &g_uart3port; - } - else -#endif -#ifdef CONFIG_TIVA_UART4 - if (g_uart4priv.irq == irq) - { - dev = &g_uart4port; - } - else -#endif -#ifdef CONFIG_TIVA_UART5 - if (g_uart5priv.irq == irq) - { - dev = &g_uart5port; - } - else -#endif -#ifdef CONFIG_TIVA_UART6 - if (g_uart6priv.irq == irq) - { - dev = &g_uart6port; - } - else -#endif -#ifdef CONFIG_TIVA_UART7 - if (g_uart7priv.irq == irq) - { - dev = &g_uart7port; - } - else -#endif - { - PANIC(); - } - + DEBUGASSERT(dev != NULL && dev->priv != NULL); priv = (struct up_dev_s *)dev->priv; /* Loop until there are no characters to be transferred or, diff --git a/arch/avr/src/at32uc3/at32uc3_serial.c b/arch/avr/src/at32uc3/at32uc3_serial.c index eaf1c8432d7..db10ae31c4d 100644 --- a/arch/avr/src/at32uc3/at32uc3_serial.c +++ b/arch/avr/src/at32uc3/at32uc3_serial.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/avr/src/at32uc3/at32uc3_serial.c * - * Copyright (C) 2010, 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2010, 2012, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -160,7 +160,7 @@ static int up_setup(struct uart_dev_s *dev); static void up_shutdown(struct uart_dev_s *dev); static int up_attach(struct uart_dev_s *dev); static void up_detach(struct uart_dev_s *dev); -static int up_interrupt(int irq, void *context, FAR void *arg); +static int up_interrupt(int irq, void *context, void *arg); static int up_ioctl(struct file *filep, int cmd, unsigned long arg); static int up_receive(struct uart_dev_s *dev, uint32_t *status); static void up_rxint(struct uart_dev_s *dev, bool enable); @@ -408,7 +408,7 @@ static int up_attach(struct uart_dev_s *dev) /* Attach the IRQ */ - return irq_attach(priv->irq, up_interrupt, NULL); + return irq_attach(priv->irq, up_interrupt, dev); } /**************************************************************************** @@ -440,40 +440,16 @@ static void up_detach(struct uart_dev_s *dev) * ****************************************************************************/ -static int up_interrupt(int irq, void *context, FAR void *arg) +static int up_interrupt(int irq, void *context, void *arg) { - struct uart_dev_s *dev = NULL; + struct uart_dev_s *dev = (struct uart_dev_s *)arg; struct up_dev_s *priv; uint32_t csr; int passes; bool handled; -#ifdef CONFIG_AVR32_USART0_RS232 - if (g_usart0priv.irq == irq) - { - dev = &g_usart0port; - } - else -#endif -#ifdef CONFIG_AVR32_USART1_RS232 - if (g_usart1priv.irq == irq) - { - dev = &g_usart1port; - } - else -#endif -#ifdef CONFIG_AVR32_USART2_RS232 - if (g_usart2priv.irq == irq) - { - dev = &g_usart2port; - } - else -#endif - { - PANIC(); - } + DEBUGASSERT(dev != NULL && dev->priv != NULL); priv = (struct up_dev_s *)dev->priv; - DEBUGASSERT(priv); /* Loop until there are no characters to be transferred or, * until we have been looping for a long time. diff --git a/arch/hc/src/m9s12/m9s12_serial.c b/arch/hc/src/m9s12/m9s12_serial.c index 885514c3ab6..a6524534bda 100644 --- a/arch/hc/src/m9s12/m9s12_serial.c +++ b/arch/hc/src/m9s12/m9s12_serial.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/hc/src/m9s12/m9s12_serial.c * - * Copyright (C) 2009, 2011-2012, 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2011-2012, 2016-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -123,7 +123,7 @@ static int up_setup(struct uart_dev_s *dev); static void up_shutdown(struct uart_dev_s *dev); static int up_attach(struct uart_dev_s *dev); static void up_detach(struct uart_dev_s *dev); -static int up_interrupt(int irq, void *context, FAR void *arg); +static int up_interrupt(int irq, void *context, void *arg); static int up_ioctl(struct file *filep, int cmd, unsigned long arg); static int up_receive(struct uart_dev_s *dev, uint32_t *status); static void up_rxint(struct uart_dev_s *dev, bool enable); @@ -422,7 +422,7 @@ static int up_attach(struct uart_dev_s *dev) /* Attach and enable the IRQ */ - ret = irq_attach(priv->irq, up_interrupt, NULL); + ret = irq_attach(priv->irq, up_interrupt, dev); if (ret == OK) { /* Enable the Rx interrupt (the TX interrupt is still disabled @@ -465,30 +465,14 @@ static void up_detach(struct uart_dev_s *dev) * ****************************************************************************/ -static int up_interrupt(int irq, void *context, FAR void *arg) +static int up_interrupt(int irq, void *context, void *arg) { - struct uart_dev_s *dev = NULL; + struct uart_dev_s *dev = (struct uart_dev_s *)arg; struct up_dev_s *priv; int passes; bool handled; -#ifndef CONFIG_SCI0_DISABLE - if (g_sci0priv.irq == irq) - { - dev = &g_sci0port; - } - else -#endif -#ifndef CONFIG_SCI1_DISABLE - if (g_sci1priv.irq == irq) - { - dev = &g_sci1port; - } - else -#endif - { - PANIC(); - } + DEBUGASSERT(dev != NULL && dev->priv != NULL); priv = (struct up_dev_s*)dev->priv; /* Loop until there are no characters to be transferred or, diff --git a/arch/mips/src/pic32mx/pic32mx-serial.c b/arch/mips/src/pic32mx/pic32mx-serial.c index 3558ee1da3b..8e6582a1452 100644 --- a/arch/mips/src/pic32mx/pic32mx-serial.c +++ b/arch/mips/src/pic32mx/pic32mx-serial.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/mips/src/pic32mx/pic32mx-serial.c * - * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2012, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -173,7 +173,7 @@ static int up_setup(struct uart_dev_s *dev); static void up_shutdown(struct uart_dev_s *dev); static int up_attach(struct uart_dev_s *dev); static void up_detach(struct uart_dev_s *dev); -static int up_interrupt(int irq, void *context, FAR void *arg); +static int up_interrupt(int irq, void *context, void *arg); static int up_ioctl(struct file *filep, int cmd, unsigned long arg); static int up_receive(struct uart_dev_s *dev, uint32_t *status); static void up_rxint(struct uart_dev_s *dev, bool enable); @@ -413,7 +413,7 @@ static int up_attach(struct uart_dev_s *dev) /* Attach the IRQ */ - return irq_attach(priv->irq, up_interrupt, NULL); + return irq_attach(priv->irq, up_interrupt, dev); } /**************************************************************************** @@ -451,32 +451,15 @@ static void up_detach(struct uart_dev_s *dev) * ****************************************************************************/ -static int up_interrupt(int irq, void *context, FAR void *arg) +static int up_interrupt(int irq, void *context, void *arg) { - struct uart_dev_s *dev = NULL; + struct uart_dev_s *dev = (struct uart_dev_s *)arg; struct up_dev_s *priv; int passes; bool handled; -#ifdef CONFIG_PIC32MX_UART1 - if (g_uart1priv.irq == irq) - { - dev = &g_uart1port; - } - else -#endif -#ifdef CONFIG_PIC32MX_UART2 - if (g_uart2priv.irq == irq) - { - dev = &g_uart2port; - } - else -#endif - { - PANIC(); - } + DEBUGASSERT(dev != NULL && dev->priv != NULL); priv = (struct up_dev_s *)dev->priv; - DEBUGASSERT(priv); /* Loop until there are no characters to be transferred or, * until we have been looping for a long time. diff --git a/arch/mips/src/pic32mz/pic32mz-serial.c b/arch/mips/src/pic32mz/pic32mz-serial.c index 9e4b23d9d37..cfce690614e 100644 --- a/arch/mips/src/pic32mz/pic32mz-serial.c +++ b/arch/mips/src/pic32mz/pic32mz-serial.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/mips/src/pic32mz/pic32mz-serial.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -248,7 +248,6 @@ struct up_dev_s { uintptr_t uartbase; /* Base address of UART registers */ - xcpt_t handler; /* UART interrupt handler */ uint32_t baud; /* Configured baud */ uint8_t irqe; /* Error IRQ associated with this UART (for enable) */ uint8_t irqrx; /* RX IRQ associated with this UART (for enable) */ @@ -276,27 +275,7 @@ static int up_setup(struct uart_dev_s *dev); static void up_shutdown(struct uart_dev_s *dev); static int up_attach(struct uart_dev_s *dev); static void up_detach(struct uart_dev_s *dev); - -static int up_interrupt(struct uart_dev_s *priv); -#ifdef CONFIG_PIC32MZ_UART1 -static int up_uart1_interrupt(int irq, void *context, FAR void *arg); -#endif -#ifdef CONFIG_PIC32MZ_UART2 -static int up_uart2_interrupt(int irq, void *context, FAR void *arg); -#endif -#ifdef CONFIG_PIC32MZ_UART3 -static int up_uart3_interrupt(int irq, void *context, FAR void *arg); -#endif -#ifdef CONFIG_PIC32MZ_UART4 -static int up_uart4_interrupt(int irq, void *context, FAR void *arg); -#endif -#ifdef CONFIG_PIC32MZ_UART5 -static int up_uart5_interrupt(int irq, void *context, FAR void *arg); -#endif -#ifdef CONFIG_PIC32MZ_UART6 -static int up_uart6_interrupt(int irq, void *context, FAR void *arg); -#endif - +static int up_interrupt(int irq, void *context, FAR void *arg); static int up_ioctl(struct file *filep, int cmd, unsigned long arg); static int up_receive(struct uart_dev_s *dev, uint32_t *status); static void up_rxint(struct uart_dev_s *dev, bool enable); @@ -362,7 +341,6 @@ static char g_uart6txbuffer[CONFIG_UART6_TXBUFSIZE]; static struct up_dev_s g_uart1priv = { .uartbase = PIC32MZ_UART1_K1BASE, - .handler = up_uart1_interrupt, .baud = CONFIG_UART1_BAUD, .irqe = PIC32MZ_IRQ_U1E, .irqrx = PIC32MZ_IRQ_U1RX, @@ -395,7 +373,6 @@ static uart_dev_t g_uart1port = static struct up_dev_s g_uart2priv = { .uartbase = PIC32MZ_UART2_K1BASE, - .handler = up_uart2_interrupt, .baud = CONFIG_UART2_BAUD, .irqe = PIC32MZ_IRQ_U2E, .irqrx = PIC32MZ_IRQ_U2RX, @@ -428,7 +405,6 @@ static uart_dev_t g_uart2port = static struct up_dev_s g_uart3priv = { .uartbase = PIC32MZ_UART3_K1BASE, - .handler = up_uart3_interrupt, .baud = CONFIG_UART3_BAUD, .irqe = PIC32MZ_IRQ_U3E, .irqrx = PIC32MZ_IRQ_U3RX, @@ -461,7 +437,6 @@ static uart_dev_t g_uart3port = static struct up_dev_s g_uart4priv = { .uartbase = PIC32MZ_UART4_K1BASE, - .handler = up_uart4_interrupt, .baud = CONFIG_UART4_BAUD, .irqe = PIC32MZ_IRQ_U4E, .irqrx = PIC32MZ_IRQ_U4RX, @@ -494,7 +469,6 @@ static uart_dev_t g_uart4port = static struct up_dev_s g_uart5priv = { .uartbase = PIC32MZ_UART5_K1BASE, - .handler = up_uart5_interrupt, .baud = CONFIG_UART5_BAUD, .irqe = PIC32MZ_IRQ_U5E, .irqrx = PIC32MZ_IRQ_U5RX, @@ -527,7 +501,6 @@ static uart_dev_t g_uart5port = static struct up_dev_s g_uart6priv = { .uartbase = PIC32MZ_UART6_K1BASE, - .handler = up_uart6_interrupt, .baud = CONFIG_UART6_BAUD, .irqe = PIC32MZ_IRQ_U6E, .irqrx = PIC32MZ_IRQ_U6RX, @@ -675,17 +648,19 @@ static int up_attach(struct uart_dev_s *dev) struct up_dev_s *priv = (struct up_dev_s *)dev->priv; int ret; - /* Attach the IRQs */ + DEBUGASSERT(dev != NULL && dev->priv != NULL); - ret = irq_attach(priv->irqrx, priv->handler, NULL); + /* Attach the IRQ */ + + ret = irq_attach(priv->irqrx, up_interrupt, dev); if (ret == 0) { - ret = irq_attach(priv->irqtx, priv->handler, NULL); + ret = irq_attach(priv->irqtx, up_interrupt, dev); } if (ret == 0) { - ret = irq_attach(priv->irqe, priv->handler, NULL); + ret = irq_attach(priv->irqe, up_interrupt, dev); } return ret; @@ -727,13 +702,14 @@ static void up_detach(struct uart_dev_s *dev) * ****************************************************************************/ -static int up_interrupt(struct uart_dev_s *dev) +static int up_interrupt(int irq, void *context, FAR void *arg) { + struct uart_dev_s *dev = (struct uart_dev_s *)arg; struct up_dev_s *priv; - int passes; - bool handled; + int passes; + bool handled; - DEBUGASSERT(dev && dev->priv); + DEBUGASSERT(dev != NULL && dev->priv != NULL); priv = (struct up_dev_s *)dev->priv; /* Loop until there are no characters to be transferred or, @@ -830,56 +806,6 @@ static int up_interrupt(struct uart_dev_s *dev) return OK; } -/**************************************************************************** - * Name: up_uartn_interrupt - * - * Description: - * These the UART-specific interrupt handlers. They simply invoke the - * common uart interrupt handler with the correct state data. - * - ****************************************************************************/ - -#ifdef CONFIG_PIC32MZ_UART1 -static int up_uart1_interrupt(int irq, void *context, FAR void *arg) -{ - return up_interrupt(&g_uart1port); -} -#endif - -#ifdef CONFIG_PIC32MZ_UART2 -static int up_uart2_interrupt(int irq, void *context, FAR void *arg) -{ - return up_interrupt(&g_uart2port); -} -#endif - -#ifdef CONFIG_PIC32MZ_UART3 -static int up_uart3_interrupt(int irq, void *context, FAR void *arg) -{ - return up_interrupt(&g_uart3port); -} -#endif - -#ifdef CONFIG_PIC32MZ_UART4 -static int up_uart4_interrupt(int irq, void *context, FAR void *arg) -{ - return up_interrupt(&g_uart4port); -} -#endif - -#ifdef CONFIG_PIC32MZ_UART5 -static int up_uart5_interrupt(int irq, void *context, FAR void *arg) -{ - return up_interrupt(&g_uart5port); -} -#endif -#ifdef CONFIG_PIC32MZ_UART6 -static int up_uart6_interrupt(int irq, void *context, FAR void *arg) -{ - return up_interrupt(&g_uart6port); -} -#endif - /**************************************************************************** * Name: up_ioctl * diff --git a/arch/renesas/src/m16c/m16c_serial.c b/arch/renesas/src/m16c/m16c_serial.c index dad01c46050..72cf64a3a5d 100644 --- a/arch/renesas/src/m16c/m16c_serial.c +++ b/arch/renesas/src/m16c/m16c_serial.c @@ -267,12 +267,12 @@ static int up_setup(struct uart_dev_s *dev); static void up_shutdown(struct uart_dev_s *dev); static int up_attach(struct uart_dev_s *dev); static void up_detach(struct uart_dev_s *dev); -static int up_rcvinterrupt(int irq, void *context, FAR void *arg); +static int up_rcvinterrupt(int irq, void *context, void *arg); static int up_receive(struct uart_dev_s *dev, unsigned int *status); static void m16c_rxint(struct up_dev_s *dev, bool enable); static void up_rxint(struct uart_dev_s *dev, bool enable); static bool up_rxavailable(struct uart_dev_s *dev); -static int up_xmtinterrupt(int irq, void *context, FAR void *arg); +static int up_xmtinterrupt(int irq, void *context, void *arg); static void up_send(struct uart_dev_s *dev, int ch); static void m16c_txint(struct up_dev_s *dev, bool enable); static void up_txint(struct uart_dev_s *dev, bool enable); @@ -711,12 +711,12 @@ static int up_attach(struct uart_dev_s *dev) /* Attach the UART receive data available IRQ */ - ret = irq_attach(priv->rcvirq, up_rcvinterrupt, NULL); + ret = irq_attach(priv->rcvirq, up_rcvinterrupt, dev); if (ret == OK) { /* Attach the UART transmit complete IRQ */ - ret = irq_attach(priv->xmtirq, up_xmtinterrupt, NULL); + ret = irq_attach(priv->xmtirq, up_xmtinterrupt, dev); if (ret != OK) { /* Detach the ERI interrupt on failure */ @@ -764,34 +764,11 @@ static void up_detach(struct uart_dev_s *dev) * ****************************************************************************/ -static int up_rcvinterrupt(int irq, void *context, FAR void *arg) +static int up_rcvinterrupt(int irq, void *context, void *arg) { - struct uart_dev_s *dev = NULL; + struct uart_dev_s *dev = (struct uart_dev_s *)arg; -#ifdef CONFIG_M16C_UART0 - if (irq == g_uart0priv.rcvirq) - { - dev = &g_uart0port; - } - else -#endif -#ifdef CONFIG_M16C_UART1 - if (irq == g_uart1priv.rcvirq) - { - dev = &g_uart1port; - } - else -#endif -#ifdef CONFIG_M16C_UART2 - if (irq = g_uart2priv.rcvirq) - { - dev = &g_uart2port; - } - else -#endif - { - PANIC(); - } + DEBUGASSERT(dev != NULL && dev->priv != NULL); /* Handle incoming, receive bytes (RDRF: Receive Data Register Full) */ @@ -924,40 +901,17 @@ static bool up_rxavailable(struct uart_dev_s *dev) * This is the UART receive interrupt handler. It will be invoked * when an interrupt received on the 'irq' It should call * uart_transmitchars or uart_receivechar to perform the - * appropriate data transfers. The interrupt handling logic\ + * appropriate data transfers. The interrupt handling logic * must be able to map the 'irq' number into the approprite * up_dev_s structure in order to call these functions. * ****************************************************************************/ -static int up_xmtinterrupt(int irq, void *context, FAR void *arg) +static int up_xmtinterrupt(int irq, void *context, void *arg) { - struct uart_dev_s *dev = NULL; + struct uart_dev_s *dev = (struct uart_dev_s *)arg; -#ifdef CONFIG_M16C_UART0 - if (irq == g_uart0priv.xmtirq) - { - dev = &g_uart0port; - } - else -#endif -#ifdef CONFIG_M16C_UART1 - if (irq == g_uart1priv.xmtirq) - { - dev = &g_uart1port; - } - else -#endif -#ifdef CONFIG_M16C_UART2 - if (irq == g_uart2priv.xmtirq) - { - dev = &g_uart1port; - } - else -#endif - { - PANIC(); - } + DEBUGASSERT(dev != NULL && dev->priv != NULL); /* Handle outgoing, transmit bytes */ diff --git a/arch/z16/src/z16f/z16f_serial.c b/arch/z16/src/z16f/z16f_serial.c index c12f34392b9..1e24c165d17 100644 --- a/arch/z16/src/z16f/z16f_serial.c +++ b/arch/z16/src/z16f/z16f_serial.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/z16/src/z16f/z16f_serial.c * - * Copyright (C) 2008-2009, 2012, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009, 2012, 2014, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -95,8 +95,8 @@ static int z16f_setup(struct uart_dev_s *dev); static void z16f_shutdown(struct uart_dev_s *dev); static int z16f_attach(struct uart_dev_s *dev); static void z16f_detach(struct uart_dev_s *dev); -static int z16f_rxinterrupt(int irq, void *context, FAR void *arg); -static int z16f_txinterrupt(int irq, void *context, FAR void *arg); +static int z16f_rxinterrupt(int irq, void *context, void *arg); +static int z16f_txinterrupt(int irq, void *context, void *arg); static int z16f_ioctl(struct file *filep, int cmd, unsigned long arg); static int z16f_receive(struct uart_dev_s *dev, uint32_t *status); static void z16f_rxint(struct uart_dev_s *dev, bool enable); @@ -426,12 +426,12 @@ static int z16f_attach(struct uart_dev_s *dev) /* Attach the RX IRQ */ - ret = irq_attach(priv->rxirq, z16f_rxinterrupt, NULL); + ret = irq_attach(priv->rxirq, z16f_rxinterrupt, dev); if (ret == OK) { /* Attach the TX IRQ */ - ret = irq_attach(priv->txirq, z16f_txinterrupt, NULL); + ret = irq_attach(priv->txirq, z16f_txinterrupt, dev); if (ret != OK) { irq_detach(priv->rxirq); @@ -471,30 +471,13 @@ static void z16f_detach(struct uart_dev_s *dev) * ****************************************************************************/ -static int z16f_rxinterrupt(int irq, void *context, FAR void *arg) +static int z16f_rxinterrupt(int irq, void *context, void *arg) { - struct uart_dev_s *dev = NULL; + struct uart_dev_s *dev = (struct uart_dev_s *)arg; struct z16f_uart_s *priv; uint8_t status; -#ifdef CONFIG_Z16F_UART1 - if (g_uart1priv.rxirq == irq) - { - dev = &g_uart1port; - } - else -#endif -#ifdef CONFIG_Z16F_UART0 - if (g_uart0priv.rxirq == irq) - { - dev = &g_uart0port; - } - else -#endif - { - PANIC(); - } - + DEBUGASSERT(dev != NULL && dev->priv != NULL); priv = (struct z16f_uart_s*)dev->priv; /* Check the LIN-UART status 0 register to determine whether the source of @@ -528,28 +511,11 @@ static int z16f_rxinterrupt(int irq, void *context, FAR void *arg) static int z16f_txinterrupt(int irq, void *context, FAR void *arg) { - struct uart_dev_s *dev = NULL; + struct uart_dev_s *dev = (struct uart_dev_s *)arg; struct z16f_uart_s *priv; uint8_t status; -#ifdef CONFIG_Z16F_UART1 - if (g_uart1priv.txirq == irq) - { - dev = &g_uart1port; - } - else -#endif -#ifdef CONFIG_Z16F_UART0 - if (g_uart0priv.txirq == irq) - { - dev = &g_uart0port; - } - else -#endif - { - PANIC(); - } - + DEBUGASSERT(dev != NULL && dev->priv != NULL); priv = (struct z16f_uart_s*)dev->priv; /* Verify that the transmit data register is empty */ diff --git a/arch/z80/src/ez80/ez80_serial.c b/arch/z80/src/ez80/ez80_serial.c index 6f52e86df24..fa64bb32c2b 100644 --- a/arch/z80/src/ez80/ez80_serial.c +++ b/arch/z80/src/ez80/ez80_serial.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/z80/src/ez08/ez80_serial.c * - * Copyright (C) 2008-2009, 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009, 2012, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -85,7 +85,7 @@ static int ez80_setup(struct uart_dev_s *dev); static void ez80_shutdown(struct uart_dev_s *dev); static int ez80_attach(struct uart_dev_s *dev); static void ez80_detach(struct uart_dev_s *dev); -static int ez80_interrupt(int irq, void *context, FAR void *arg); +static int ez80_interrupt(int irq, void *context, void *arg); static int ez80_ioctl(struct file *filep, int cmd, unsigned long arg); static int ez80_receive(struct uart_dev_s *dev, unsigned int *status); static void ez80_rxint(struct uart_dev_s *dev, bool enable); @@ -438,7 +438,7 @@ static int ez80_attach(struct uart_dev_s *dev) /* Attach the IRQ */ - return irq_attach(priv->irq, ez80_interrupt, NULL); + return irq_attach(priv->irq, ez80_interrupt, dev); } /**************************************************************************** @@ -471,29 +471,13 @@ static void ez80_detach(struct uart_dev_s *dev) * ****************************************************************************/ -static int ez80_interrupt(int irq, void *context, FAR void *arg) +static int ez80_interrupt(int irq, void *context, void *arg) { - struct uart_dev_s *dev = NULL; - struct ez80_dev_s *priv; + struct uart_dev_s *dev = (struct uart_dev_s *)arg; + struct ez80_dev_s *priv; volatile uint32_t cause; -#ifdef CONFIG_EZ80_UART0 - if (g_uart0priv.irq == irq) - { - dev = &g_uart0port; - } - else -#endif -#ifdef CONFIG_EZ80_UART1 - if (g_uart1priv.irq == irq) - { - dev = &g_uart1port; - } - else -#endif - { - PANIC(); - } + DEBUGASSERT(dev != NULL && dev->priv != NULL); priv = (struct ez80_dev_s*)dev->priv; cause = ez80_serialin(priv, EZ80_UART_IIR) & EZ80_UARTIIR_CAUSEMASK; diff --git a/arch/z80/src/z8/z8_serial.c b/arch/z80/src/z8/z8_serial.c index bbd7b07fd30..6f6df0efae9 100644 --- a/arch/z80/src/z8/z8_serial.c +++ b/arch/z80/src/z8/z8_serial.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/z80/src/z8/z8_serial.c * - * Copyright (C) 2008-2009, 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009, 2012, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -446,12 +446,12 @@ static int z8_attach(FAR struct uart_dev_s *dev) /* Attach the RX IRQ */ - ret = irq_attach(priv->rxirq, z8_rxinterrupt, NULL); + ret = irq_attach(priv->rxirq, z8_rxinterrupt, dev); if (ret == OK) { /* Attach the TX IRQ */ - ret = irq_attach(priv->txirq, z8_txinterrupt, NULL); + ret = irq_attach(priv->txirq, z8_txinterrupt, dev); if (ret != OK) { irq_detach(priv->rxirq); @@ -490,23 +490,11 @@ static void z8_detach(FAR struct uart_dev_s *dev) static int z8_rxinterrupt(int irq, FAR void *context, FAR void *arg) { - struct uart_dev_s *dev = NULL; - struct z8_uart_s *priv; + struct uart_dev_s *dev = (struct uart_dev_s *)arg; + struct z8_uart_s *priv; uint8_t status; - if (g_uart1priv.rxirq == irq) - { - dev = &g_uart1port; - } - else if (g_uart0priv.rxirq == irq) - { - dev = &g_uart0port; - } - else - { - PANIC(); - } - + DEBUGASSERT(dev != NULL && dev->priv != NULL); priv = (struct z8_uart_s*)dev->priv; /* Check the LIN-UART status 0 register to determine whether the source of @@ -539,23 +527,11 @@ static int z8_rxinterrupt(int irq, FAR void *context, FAR void *arg) static int z8_txinterrupt(int irq, FAR void *context, FAR void *arg) { - struct uart_dev_s *dev = NULL; - struct z8_uart_s *priv; + struct uart_dev_s *dev = (struct uart_dev_s *)arg; + struct z8_uart_s *priv; uint8_t status; - if (g_uart1priv.txirq == irq) - { - dev = &g_uart1port; - } - else if (g_uart0priv.txirq == irq) - { - dev = &g_uart0port; - } - else - { - PANIC(); - } - + DEBUGASSERT(dev != NULL && dev->priv != NULL); priv = (struct z8_uart_s*)dev->priv; /* Verify that the transmit data register is empty */