From 4cd31be19d234b5d9d2f9a2ffd52d2cbf4edbda6 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 27 Feb 2017 08:55:21 -0600 Subject: [PATCH] Convert some serial drivers to use use irq_attach. --- arch/arm/src/c5471/c5471_serial.c | 21 +++------- arch/arm/src/dm320/dm320_serial.c | 24 +++-------- arch/arm/src/kinetis/kinetis_lpserial.c | 28 +++---------- arch/arm/src/kl/kl_serial.c | 36 +++------------- arch/arm/src/lpc11xx/lpc11_i2c.c | 35 +++------------- arch/arm/src/lpc11xx/lpc11_serial.c | 20 +++------ arch/arm/src/lpc17xx/lpc17_i2c.c | 35 +++------------- arch/arm/src/lpc17xx/lpc17_serial.c | 42 +++---------------- drivers/wireless/cc3000/cc3000.c | 18 ++------ .../wireless/cc3000/include/cc3000_upif.h | 2 +- 10 files changed, 50 insertions(+), 211 deletions(-) diff --git a/arch/arm/src/c5471/c5471_serial.c b/arch/arm/src/c5471/c5471_serial.c index adb654d63c..44d0dc7fd2 100644 --- a/arch/arm/src/c5471/c5471_serial.c +++ b/arch/arm/src/c5471/c5471_serial.c @@ -108,7 +108,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, unsigned int *status); static void up_rxint(struct uart_dev_s *dev, bool enable); @@ -491,7 +491,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 @@ -534,24 +534,13 @@ 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; volatile uint32_t cause; - if (g_irdapriv.irq == irq) - { - dev = &g_irdaport; - } - else if (g_modempriv.irq == irq) - { - dev = &g_modemport; - } - else - { - PANIC(); - } + DEBUGASSERT(dev != NULL && dev->priv != NULL); priv = (struct up_dev_s *)dev->priv; cause = up_inserial(priv, UART_ISR_OFFS) & 0x0000003f; diff --git a/arch/arm/src/dm320/dm320_serial.c b/arch/arm/src/dm320/dm320_serial.c index 8b30fbdd95..964e8923f0 100644 --- a/arch/arm/src/dm320/dm320_serial.c +++ b/arch/arm/src/dm320/dm320_serial.c @@ -1,8 +1,7 @@ /**************************************************************************** * arch/arm/src/dm320/dm320_serial.c - * arch/arm/src/chip/dm320_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 @@ -89,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); @@ -430,7 +429,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 @@ -472,25 +471,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; uint16_t status; int passes = 0; - 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/kinetis/kinetis_lpserial.c b/arch/arm/src/kinetis/kinetis_lpserial.c index 57dbf7c50b..69f4461172 100644 --- a/arch/arm/src/kinetis/kinetis_lpserial.c +++ b/arch/arm/src/kinetis/kinetis_lpserial.c @@ -163,7 +163,7 @@ static int kinetis_setup(struct uart_dev_s *dev); static void kinetis_shutdown(struct uart_dev_s *dev); static int kinetis_attach(struct uart_dev_s *dev); static void kinetis_detach(struct uart_dev_s *dev); -static int kinetis_interrupt(int irq, void *context); +static int kinetis_interrupt(int irq, void *context, void *arg); static int kinetis_ioctl(struct file *filep, int cmd, unsigned long arg); static int kinetis_receive(struct uart_dev_s *dev, uint32_t *status); static void kinetis_rxint(struct uart_dev_s *dev, bool enable); @@ -427,7 +427,7 @@ static int kinetis_attach(struct uart_dev_s *dev) * disabled in the LPUART_CTRL register. */ - ret = irq_attach(priv->irq, kinetis_interrupt); + ret = irq_attach(priv->irq, kinetis_interrupt, dev); if (ret == OK) { up_enable_irq(priv->irq); @@ -472,33 +472,15 @@ static void kinetis_detach(struct uart_dev_s *dev) * ****************************************************************************/ -static int kinetis_interrupt(int irq, void *context) +static int kinetis_interrupt(int irq, void *context, void *arg) { - struct uart_dev_s *dev = NULL; + struct uart_dev_s *dev = (struct uart_dev_s *dev)arg; struct kinetis_dev_s *priv; uint32_t stat; uint32_t ctrl; -#ifdef CONFIG_KINETIS_LPUART0 - if (g_lpuart0priv.irq == irq) - { - dev = &g_lpuart0port; - } - else -#endif -#ifdef CONFIG_KINETIS_LPUART1 - if (g_lpuart1priv.irq == irq) - { - dev = &g_lpuart1port; - } - else -#endif - { - PANIC(); - } - + DEBUGASSERT(dev != NULL && dev->priv != NULL); priv = (struct kinetis_dev_s *)dev->priv; - DEBUGASSERT(priv); /* Read status register and qualify it with STAT bit corresponding CTRL IE bits */ diff --git a/arch/arm/src/kl/kl_serial.c b/arch/arm/src/kl/kl_serial.c index 8849c585a8..a35328345e 100644 --- a/arch/arm/src/kl/kl_serial.c +++ b/arch/arm/src/kl/kl_serial.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/kl/kl_serial.c * - * Copyright (C) 2013-2012, 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2013-2012, 2016-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -171,7 +171,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_interrupts(int irq, void *context, FAR void *arg); +static int up_interrupts(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); @@ -455,7 +455,7 @@ static int up_attach(struct uart_dev_s *dev) * disabled in the C2 register. */ - ret = irq_attach(priv->irq, up_interrupts, NULL); + ret = irq_attach(priv->irq, up_interrupts, dev); if (ret == OK) { up_enable_irq(priv->irq); @@ -500,40 +500,16 @@ static void up_detach(struct uart_dev_s *dev) * ****************************************************************************/ -static int up_interrupts(int irq, void *context, FAR void *arg) +static int up_interrupts(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; uint8_t s1; bool handled; -#ifdef CONFIG_KL_UART0 - if (g_uart0priv.irq == irq) - { - dev = &g_uart0port; - } - else -#endif -#ifdef CONFIG_KL_UART1 - if (g_uart1priv.irq == irq) - { - dev = &g_uart1port; - } - else -#endif -#ifdef CONFIG_KL_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/arm/src/lpc11xx/lpc11_i2c.c b/arch/arm/src/lpc11xx/lpc11_i2c.c index e5e0c69bc3..b9d2d10743 100644 --- a/arch/arm/src/lpc11xx/lpc11_i2c.c +++ b/arch/arm/src/lpc11xx/lpc11_i2c.c @@ -129,7 +129,7 @@ struct lpc11_i2cdev_s static int lpc11_i2c_start(struct lpc11_i2cdev_s *priv); static void lpc11_i2c_stop(struct lpc11_i2cdev_s *priv); -static int lpc11_i2c_interrupt(int irq, FAR void *context, FAR void *arg); +static int lpc11_i2c_interrupt(int irq, FAR void *context, void *arg); static void lpc11_i2c_timeout(int argc, uint32_t arg, ...); static void lpc11_i2c_setfrequency(struct lpc11_i2cdev_s *priv, uint32_t frequency); @@ -304,7 +304,7 @@ static int lpc11_i2c_transfer(FAR struct i2c_master_s *dev, } /**************************************************************************** - * Name: lpc11_i2c_interrupt + * Name: lpc11_stopnext * * Description: * Check if we need to issue STOP at the next message @@ -334,36 +334,13 @@ static void lpc11_stopnext(struct lpc11_i2cdev_s *priv) * ****************************************************************************/ -static int lpc11_i2c_interrupt(int irq, FAR void *context, FAR void *arg) +static int lpc11_i2c_interrupt(int irq, FAR void *context, void *arg) { - struct lpc11_i2cdev_s *priv; + struct lpc11_i2cdev_s *priv = (struct lpc11_i2cdev_s *)arg; struct i2c_msg_s *msg; uint32_t state; -#ifdef CONFIG_LPC11_I2C0 - if (irq == LPC11_IRQ_I2C0) - { - priv = &g_i2c0dev; - } - else -#endif -#ifdef CONFIG_LPC11_I2C1 - if (irq == LPC11_IRQ_I2C1) - { - priv = &g_i2c1dev; - } - else -#endif -#ifdef CONFIG_LPC11_I2C2 - if (irq == LPC11_IRQ_I2C2) - { - priv = &g_i2c2dev; - } - else -#endif - { - PANIC(); - } + DEBUGASSERT(priv != NULL); /* Reference UM10360 19.10.5 */ @@ -603,7 +580,7 @@ struct i2c_master_s *lpc11_i2cbus_initialize(int port) /* Attach Interrupt Handler */ - irq_attach(priv->irqid, lpc11_i2c_interrupt, NULL); + irq_attach(priv->irqid, lpc11_i2c_interrupt, priv); /* Enable Interrupt Handler */ diff --git a/arch/arm/src/lpc11xx/lpc11_serial.c b/arch/arm/src/lpc11xx/lpc11_serial.c index 4d23438b11..cbef799afe 100644 --- a/arch/arm/src/lpc11xx/lpc11_serial.c +++ b/arch/arm/src/lpc11xx/lpc11_serial.c @@ -104,7 +104,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); @@ -515,7 +515,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 @@ -557,24 +557,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_LPC11_UART0 - if (g_uart0priv.irq == irq) - { - dev = &g_uart0port; - } - 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/lpc17xx/lpc17_i2c.c b/arch/arm/src/lpc17xx/lpc17_i2c.c index 0bd34e36b5..30763fe177 100644 --- a/arch/arm/src/lpc17xx/lpc17_i2c.c +++ b/arch/arm/src/lpc17xx/lpc17_i2c.c @@ -129,7 +129,7 @@ struct lpc17_i2cdev_s static int lpc17_i2c_start(struct lpc17_i2cdev_s *priv); static void lpc17_i2c_stop(struct lpc17_i2cdev_s *priv); -static int lpc17_i2c_interrupt(int irq, FAR void *context, FAR void *arg); +static int lpc17_i2c_interrupt(int irq, FAR void *context, void *arg); static void lpc17_i2c_timeout(int argc, uint32_t arg, ...); static void lpc17_i2c_setfrequency(struct lpc17_i2cdev_s *priv, uint32_t frequency); @@ -304,7 +304,7 @@ static int lpc17_i2c_transfer(FAR struct i2c_master_s *dev, } /**************************************************************************** - * Name: lpc17_i2c_interrupt + * Name: lpc17_stopnext * * Description: * Check if we need to issue STOP at the next message @@ -334,36 +334,13 @@ static void lpc17_stopnext(struct lpc17_i2cdev_s *priv) * ****************************************************************************/ -static int lpc17_i2c_interrupt(int irq, FAR void *context, FAR void *arg) +static int lpc17_i2c_interrupt(int irq, FAR void *context, void *arg) { - struct lpc17_i2cdev_s *priv; + struct lpc17_i2cdev_s *priv = (struct lpc17_i2cdev_s *)arg; struct i2c_msg_s *msg; uint32_t state; -#ifdef CONFIG_LPC17_I2C0 - if (irq == LPC17_IRQ_I2C0) - { - priv = &g_i2c0dev; - } - else -#endif -#ifdef CONFIG_LPC17_I2C1 - if (irq == LPC17_IRQ_I2C1) - { - priv = &g_i2c1dev; - } - else -#endif -#ifdef CONFIG_LPC17_I2C2 - if (irq == LPC17_IRQ_I2C2) - { - priv = &g_i2c2dev; - } - else -#endif - { - PANIC(); - } + DEBUGASSERT(priv != NULL); /* Reference UM10360 19.10.5 */ @@ -608,7 +585,7 @@ struct i2c_master_s *lpc17_i2cbus_initialize(int port) /* Attach Interrupt Handler */ - irq_attach(priv->irqid, lpc17_i2c_interrupt, NULL); + irq_attach(priv->irqid, lpc17_i2c_interrupt, priv); /* Enable Interrupt Handler */ diff --git a/arch/arm/src/lpc17xx/lpc17_serial.c b/arch/arm/src/lpc17xx/lpc17_serial.c index 14c7602d24..9c13a06d4a 100644 --- a/arch/arm/src/lpc17xx/lpc17_serial.c +++ b/arch/arm/src/lpc17xx/lpc17_serial.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/lpc17xx/lpc17_serial.c * - * Copyright (C) 2010-2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2010-2013, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -104,7 +104,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); @@ -999,7 +999,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 @@ -1041,44 +1041,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_LPC17_UART0 - if (g_uart0priv.irq == irq) - { - dev = &g_uart0port; - } - else -#endif -#ifdef CONFIG_LPC17_UART1 - if (g_uart1priv.irq == irq) - { - dev = &g_uart1port; - } - else -#endif -#ifdef CONFIG_LPC17_UART2 - if (g_uart2priv.irq == irq) - { - dev = &g_uart2port; - } - else -#endif -#ifdef CONFIG_LPC17_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; /* Loop until there are no characters to be transferred or, diff --git a/drivers/wireless/cc3000/cc3000.c b/drivers/wireless/cc3000/cc3000.c index 80ed10d1fa..c3df8e185c 100644 --- a/drivers/wireless/cc3000/cc3000.c +++ b/drivers/wireless/cc3000/cc3000.c @@ -748,19 +748,9 @@ static void * cc3000_worker(FAR void *arg) static int cc3000_interrupt(int irq, FAR void *context, FAR void *arg) { - FAR struct cc3000_dev_s *priv; + FAR struct cc3000_dev_s *priv = (FAR struct cc3000_dev_s *)arg; - /* Which CC3000 device caused the interrupt? */ - -#ifndef CONFIG_CC3000_MULTIPLE - priv = &g_cc3000; -#else - for (priv = g_cc3000list; - priv && priv->configs->irq != irq; - priv = priv->flink); - - ASSERT(priv != NULL); -#endif + DEBUGASSERT(priv != NULL); /* Run the worker thread */ @@ -1522,7 +1512,7 @@ errout: ****************************************************************************/ int cc3000_register(FAR struct spi_dev_s *spi, - FAR struct cc3000_config_s *config, int minor) + FAR struct cc3000_config_s *config, int minor) { FAR struct cc3000_dev_s *priv; char drvname[DEV_NAMELEN]; @@ -1577,7 +1567,7 @@ int cc3000_register(FAR struct spi_dev_s *spi, /* Attach the interrupt handler */ - ret = config->irq_attach(config, cc3000_interrupt, NULL); + ret = config->irq_attach(config, cc3000_interrupt, priv); if (ret < 0) { nerr("ERROR: Failed to attach interrupt\n"); diff --git a/include/nuttx/wireless/cc3000/include/cc3000_upif.h b/include/nuttx/wireless/cc3000/include/cc3000_upif.h index 26c2e10972..e24d572b00 100644 --- a/include/nuttx/wireless/cc3000/include/cc3000_upif.h +++ b/include/nuttx/wireless/cc3000/include/cc3000_upif.h @@ -138,7 +138,7 @@ struct cc3000_config_s * probe - Debug support */ - int (*irq_attach)(FAR struct cc3000_config_s *state, xcpt_t isr); + int (*irq_attach)(FAR struct cc3000_config_s *state, xcpt_t isr, FAR void *arg); void (*irq_enable)(FAR struct cc3000_config_s *state, bool enable); void (*irq_clear)(FAR struct cc3000_config_s *state); void (*power_enable)(FAR struct cc3000_config_s *state,bool enable);