Convert more drivers to use use irq_attach with argument.

This commit is contained in:
Gregory Nutt 2017-02-27 10:44:13 -06:00
parent a581e9206d
commit b4ff7391f8
5 changed files with 37 additions and 196 deletions

View File

@ -78,13 +78,15 @@ struct stm32_lower_s
{
const struct vs1053_lower_s lower; /* Low-level MCU interface */
xcpt_t handler; /* VS1053 interrupt handler */
FAR void *arg; /* Interrupt handler argument */
};
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
static int up_attach(FAR const struct vs1053_lower_s *lower, xcpt_t handler);
static int up_attach(FAR const struct vs1053_lower_s *lower, xcpt_t handler,
FAR void *arg);
static void up_enable(FAR const struct vs1053_lower_s *lower);
static void up_disable(FAR const struct vs1053_lower_s *lower);
static void up_reset(FAR const struct vs1053_lower_s *lower, bool state);
@ -110,6 +112,7 @@ static struct stm32_lower_s g_vs1053lower =
.irq = GPIO_VS1053_DREQ_IRQ
},
.handler = NULL,
.arg = NULL,
};
/****************************************************************************
@ -120,11 +123,13 @@ static struct stm32_lower_s g_vs1053lower =
* Name: struct vs1053_lower_s methods
****************************************************************************/
static int up_attach(FAR const struct vs1053_lower_s *lower, xcpt_t handler)
static int up_attach(FAR const struct vs1053_lower_s *lower, xcpt_t handler,
FAR void *arg)
{
FAR struct stm32_lower_s *priv = (FAR struct stm32_lower_s *)lower;
priv->handler = handler; /* Save the handler for later */
priv->arg = arg; /* Along with the handler argument */
return 0;
}

View File

@ -217,13 +217,6 @@ static const struct audio_ops_s g_audioops =
vs1053_release /* release */
};
/* ISR context pointers */
static struct vs1053_struct_s *g_isrdata[CONFIG_VS1053_DEVICE_COUNT] =
{
NULL,
};
/* Volume control log table. This table is in increments of 2% of
* requested volume level and is the register value that should be
* programmed to the VS1053 to achieve that volume pecentage.
@ -1215,32 +1208,12 @@ err_out:
*
****************************************************************************/
static int vs1053_dreq_isr(int irq, FAR void *context)
static int vs1053_dreq_isr(int irq, FAR void *context, FAR void *arg)
{
struct vs1053_struct_s *dev = NULL;
struct vs1053_struct_s *dev = (struct vs1053_struct_s *)arg;
struct audio_msg_s msg;
/* Get the driver context */
#if CONFIG_VS1053_DEVICE_COUNT == 1
dev = g_isrdata[0]; /* Simple case */
#else
/* More complex case */
{
int x;
for (x = 0; x < CONFIG_VS1053_DEVICE_COUNT; x++)
{
if (g_isrdata[x]->hw_lower->irq == irq)
{
dev = g_isrdata[x];
break;
}
}
DEBUGASSERT(dev);
}
#endif
DEBUGASSERT(dev != NULL);
/* Now create a message and send it to the workerthread */
@ -1909,33 +1882,10 @@ struct audio_lowerhalf_s *vs1053_initialize(FAR struct spi_dev_s *spi,
}
/* Attach our ISR to this device */
dev->hw_lower->attach(dev->hw_lower, vs1053_dreq_isr);
/* Find a slot to save the device context for ISR lookup */
dev->hw_lower->attach(dev->hw_lower, vs1053_dreq_isr, dev);
#if CONFIG_VS1053_DEVICE_COUNT == 1
g_isrdata[0] = dev; /* The simple case */
#else
/* The more complex case */
{
int x;
/* Initialize the ISR data if not alrady */
for (x = 0; x < CONFIG_VS1053_DEVICE_COUNT; x++)
{
/* Find an empty slot */
if (g_isrdata[x] == NULL)
{
g_isrdata[x] = dev;
break;
}
}
}
#endif
/* Do some initialization of the codec */
/* Do some initialization of the codec */
vs1053_shutdown(&dev->lower); /* Go to shutdown state */
}

View File

@ -85,14 +85,6 @@
#define BUF ((struct eth_hdr_s *)cs89x0->cs_dev.d_buf)
/* If there is only one CS89x0 instance, then mapping the CS89x0 IRQ to
* a driver state instance is trivial.
*/
#if CONFIG_CS89x0_NINTERFACES == 1
# define cs89x0_mapirq(irq) g_cs89x0[0]
#endif
#define PKTBUF_SIZE (MAX_NET_DEV_MTU + CONFIG_NET_GUARDSIZE)
/****************************************************************************
@ -123,9 +115,6 @@ static int cs89x0_txpoll(struct net_driver_s *dev);
static void cs89x0_receive(struct cs89x0_driver_s *cs89x0);
static void cs89x0_txdone(struct cs89x0_driver_s *cs89x0, uint16_t isq);
#if CONFIG_CS89x0_NINTERFACES > 1
static inline FAR struct cs89x0_driver_s *cs89x0_mapirq(int irq);
#endif
static int cs89x0_interrupt(int irq, FAR void *context, FAR void *arg);
/* Watchdog timer expirations */
@ -621,40 +610,6 @@ static void cs89x0_txdone(struct cs89x0_driver_s *cs89x0, uint16_t isq)
(void)devif_poll(&cs89x0->cs_dev, cs89x0_txpoll);
}
/****************************************************************************
* Function: cs89x0_mapirq
*
* Description:
* Map an IRQ number to a CS89x0 device state instance. This is only
* necessary to handler the case where the architecture includes more than
* on CS89x0 chip.
*
* Parameters:
* irq - Number of the IRQ that generated the interrupt
*
* Returned Value:
* A reference to device state structure (NULL if irq does not correspond
* to any CS89x0 device).
*
* Assumptions:
*
****************************************************************************/
#if CONFIG_CS89x0_NINTERFACES > 1
static inline FAR struct cs89x0_driver_s *cs89x0_mapirq(int irq)
{
int i;
for (i = 0; i < CONFIG_CS89x0_NINTERFACES; i++)
{
if (g_cs89x0[i] && g_cs89x0[i].irq == irq)
{
return g_cs89x0[i];
}
}
return NULL;
}
#endif
/****************************************************************************
* Function: cs89x0_interrupt
*
@ -674,15 +629,10 @@ static inline FAR struct cs89x0_driver_s *cs89x0_mapirq(int irq)
static int cs89x0_interrupt(int irq, FAR void *context, FAR void *arg)
{
register struct cs89x0_driver_s *cs89x0 = s89x0_mapirq(irq);
FAR struct cs89x0_driver_s *cs89x0 = (FAR struct cs89x0_driver_s *)arg;
uint16_t isq;
#ifdef CONFIG_DEBUG_FEATURES
if (!cs89x0)
{
return -ENODEV;
}
#endif
DEBUGASSERT(cs89x0 != NULL);
/* Read and process all of the events from the ISQ */
@ -1023,7 +973,7 @@ int cs89x0_initialize(FAR const cs89x0_driver_s *cs89x0, int devno)
/* Attach the IRQ to the driver */
if (irq_attach(cs89x0->irq, cs89x0_interrupt, NULL))
if (irq_attach(cs89x0->irq, cs89x0_interrupt, cs89x0))
{
/* We could not attach the ISR to the ISR */

View File

@ -2,7 +2,7 @@
* drivers/serial/uart_16550.c
* Serial driver for 16550 UART
*
* Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
* Copyright (C) 2011, 2013, 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -74,10 +74,8 @@ struct u16550_s
uint32_t baud; /* Configured baud */
uint32_t uartclk; /* UART clock frequency */
#endif
#ifndef CONFIG_SUPPRESS_SERIAL_INTS
uart_datawidth_t ier; /* Saved IER value */
uint8_t irq; /* IRQ associated with this UART */
#endif
#ifndef CONFIG_16550_SUPRESS_CONFIG
uint8_t parity; /* 0=none, 1=odd, 2=even */
uint8_t bits; /* Number of bits (7 or 8) */
@ -89,21 +87,19 @@ struct u16550_s
* Private Function Prototypes
****************************************************************************/
static int u16550_setup(struct uart_dev_s *dev);
static void u16550_shutdown(struct uart_dev_s *dev);
static int u16550_attach(struct uart_dev_s *dev);
static void u16550_detach(struct uart_dev_s *dev);
#ifndef CONFIG_SUPPRESS_SERIAL_INTS
static int u16550_interrupt(int irq, void *context, FAR void *arg);
#endif
static int u16550_ioctl(struct file *filep, int cmd, unsigned long arg);
static int u16550_receive(struct uart_dev_s *dev, uint32_t *status);
static void u16550_rxint(struct uart_dev_s *dev, bool enable);
static bool u16550_rxavailable(struct uart_dev_s *dev);
static void u16550_send(struct uart_dev_s *dev, int ch);
static void u16550_txint(struct uart_dev_s *dev, bool enable);
static bool u16550_txready(struct uart_dev_s *dev);
static bool u16550_txempty(struct uart_dev_s *dev);
static int u16550_setup(FAR struct uart_dev_s *dev);
static void u16550_shutdown(FAR struct uart_dev_s *dev);
static int u16550_attach(FAR struct uart_dev_s *dev);
static void u16550_detachFAR struct uart_dev_s *dev);
static int u16550_interrupt(int irq, FAR void *context, FAR void *arg);
static int u16550_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
static int u16550_receive(FAR struct uart_dev_s *dev, uint32_t *status);
static void u16550_rxint(FAR struct uart_dev_s *dev, bool enable);
static bool u16550_rxavailable(FAR struct uart_dev_s *dev);
static void u16550_send(FAR struct uart_dev_s *dev, int ch);
static void u16550_txint(FAR struct uart_dev_s *dev, bool enable);
static bool u16550_txready(FAR struct uart_dev_s *dev);
static bool u16550_txempty(FAR struct uart_dev_s *dev);
/****************************************************************************
* Private Data
@ -157,9 +153,7 @@ static struct u16550_s g_uart0priv =
.baud = CONFIG_16550_UART0_BAUD,
.uartclk = CONFIG_16550_UART0_CLOCK,
#endif
#ifndef CONFIG_SUPPRESS_SERIAL_INTS
.irq = CONFIG_16550_UART0_IRQ,
#endif
#ifndef CONFIG_16550_SUPRESS_CONFIG
.parity = CONFIG_16550_UART0_PARITY,
.bits = CONFIG_16550_UART0_BITS,
@ -194,9 +188,7 @@ static struct u16550_s g_uart1priv =
.baud = CONFIG_16550_UART1_BAUD,
.uartclk = CONFIG_16550_UART1_CLOCK,
#endif
#ifndef CONFIG_SUPPRESS_SERIAL_INTS
.irq = CONFIG_16550_UART1_IRQ,
#endif
#ifndef CONFIG_16550_SUPRESS_CONFIG
.parity = CONFIG_16550_UART1_PARITY,
.bits = CONFIG_16550_UART1_BITS,
@ -231,9 +223,7 @@ static struct u16550_s g_uart2priv =
.baud = CONFIG_16550_UART2_BAUD,
.uartclk = CONFIG_16550_UART2_CLOCK,
#endif
#ifndef CONFIG_SUPPRESS_SERIAL_INTS
.irq = CONFIG_16550_UART2_IRQ,
#endif
#ifndef CONFIG_16550_SUPRESS_CONFIG
.parity = CONFIG_16550_UART2_PARITY,
.bits = CONFIG_16550_UART2_BITS,
@ -268,9 +258,7 @@ static struct u16550_s g_uart3priv =
.baud = CONFIG_16550_UART3_BAUD,
.uartclk = CONFIG_16550_UART3_CLOCK,
#endif
#ifndef CONFIG_SUPPRESS_SERIAL_INTS
.irq = CONFIG_16550_UART3_IRQ,
#endif
#ifndef CONFIG_16550_SUPRESS_CONFIG
.parity = CONFIG_16550_UART3_PARITY,
.bits = CONFIG_16550_UART3_BITS,
@ -483,7 +471,6 @@ static inline void u16550_serialout(FAR struct u16550_s *priv, int offset,
* Name: u16550_disableuartint
****************************************************************************/
#ifndef CONFIG_SUPPRESS_SERIAL_INTS
static inline void u16550_disableuartint(FAR struct u16550_s *priv,
FAR uart_datawidth_t *ier)
{
@ -495,23 +482,16 @@ static inline void u16550_disableuartint(FAR struct u16550_s *priv,
priv->ier &= ~UART_IER_ALLIE;
u16550_serialout(priv, UART_IER_OFFSET, priv->ier);
}
#else
# define u16550_disableuartint(priv,ier)
#endif
/****************************************************************************
* Name: u16550_restoreuartint
****************************************************************************/
#ifndef CONFIG_SUPPRESS_SERIAL_INTS
static inline void u16550_restoreuartint(FAR struct u16550_s *priv, uint32_t ier)
{
priv->ier |= ier & UART_IER_ALLIE;
u16550_serialout(priv, UART_IER_OFFSET, priv->ier);
}
#else
# define u16550_restoreuartint(priv,ier)
#endif
/****************************************************************************
* Name: u16550_enablebreaks
@ -586,9 +566,7 @@ static int u16550_setup(struct uart_dev_s *dev)
/* Set up the IER */
#ifndef CONFIG_SUPPRESS_SERIAL_INTS
priv->ier = u16550_serialin(priv, UART_IER_OFFSET);
#endif
/* Set up the LCR */
@ -682,13 +660,12 @@ static void u16550_shutdown(struct uart_dev_s *dev)
static int u16550_attach(struct uart_dev_s *dev)
{
#ifndef CONFIG_SUPPRESS_SERIAL_INTS
FAR struct u16550_s *priv = (FAR struct u16550_s *)dev->priv;
int ret;
/* Attach and enable the IRQ */
ret = irq_attach(priv->irq, u16550_interrupt, NULL);
ret = irq_attach(priv->irq, u16550_interrupt, dev);
#ifndef CONFIG_ARCH_NOINTC
if (ret == OK)
{
@ -700,9 +677,6 @@ static int u16550_attach(struct uart_dev_s *dev)
}
#endif
return ret;
#else
return OK;
#endif
}
/****************************************************************************
@ -717,13 +691,10 @@ static int u16550_attach(struct uart_dev_s *dev)
static void u16550_detach(FAR struct uart_dev_s *dev)
{
#ifndef CONFIG_SUPPRESS_SERIAL_INTS
FAR struct u16550_s *priv = (FAR struct u16550_s *)dev->priv;
#ifndef CONFIG_ARCH_NOINTC
up_disable_irq(priv->irq);
#endif
irq_detach(priv->irq);
#endif
}
/****************************************************************************
@ -738,42 +709,14 @@ static void u16550_detach(FAR struct uart_dev_s *dev)
*
****************************************************************************/
#ifndef CONFIG_SUPPRESS_SERIAL_INTS
static int u16550_interrupt(int irq, void *context, FAR void *arg)
static int u16550_interrupt(int irq, FAR void *context, FAR void *arg)
{
struct uart_dev_s *dev = NULL;
struct uart_dev_s *dev = (struct uart_dev_s *)arg;
struct u16550_s *priv;
uint32_t status;
int passes;
#ifdef CONFIG_16550_UART0
if (g_uart0priv.irq == irq)
{
dev = &g_uart0port;
}
else
#endif
#ifdef CONFIG_16550_UART1
if (g_uart1priv.irq == irq)
{
dev = &g_uart1port;
}
else
#endif
#ifdef CONFIG_16550_UART2
if (g_uart2priv.irq == irq)
{
dev = &g_uart2port;
}
else
#endif
#ifdef CONFIG_16550_UART3
if (g_uart3priv.irq == irq)
{
dev = &g_uart3port;
}
#endif
ASSERT(dev != NULL);
DEBUGASSERT(dev != NULL && dev->priv != NULL);
priv = (FAR struct u16550_s *)dev->priv;
/* Loop until there are no characters to be transferred or,
@ -856,7 +799,6 @@ static int u16550_interrupt(int irq, void *context, FAR void *arg)
return OK;
}
#endif
/****************************************************************************
* Name: u16550_ioctl
@ -959,7 +901,6 @@ static int u16550_receive(struct uart_dev_s *dev, uint32_t *status)
static void u16550_rxint(struct uart_dev_s *dev, bool enable)
{
#ifndef CONFIG_SUPPRESS_SERIAL_INTS
FAR struct u16550_s *priv = (FAR struct u16550_s *)dev->priv;
if (enable)
{
@ -969,8 +910,8 @@ static void u16550_rxint(struct uart_dev_s *dev, bool enable)
{
priv->ier &= ~UART_IER_ERBFI;
}
u16550_serialout(priv, UART_IER_OFFSET, priv->ier);
#endif
}
/****************************************************************************
@ -1011,7 +952,6 @@ static void u16550_send(struct uart_dev_s *dev, int ch)
static void u16550_txint(struct uart_dev_s *dev, bool enable)
{
#ifndef CONFIG_SUPPRESS_SERIAL_INTS
FAR struct u16550_s *priv = (FAR struct u16550_s *)dev->priv;
irqstate_t flags;
@ -1034,7 +974,6 @@ static void u16550_txint(struct uart_dev_s *dev, bool enable)
}
leave_critical_section(flags);
#endif
}
/****************************************************************************
@ -1161,11 +1100,9 @@ void up_serialinit(void)
int up_putc(int ch)
{
FAR struct u16550_s *priv = (FAR struct u16550_s *)CONSOLE_DEV.priv;
#ifndef CONFIG_SUPPRESS_SERIAL_INTS
uart_datawidth_t ier;
u16550_disableuartint(priv, &ier);
#endif
/* Check for LF */
@ -1177,9 +1114,7 @@ int up_putc(int ch)
}
u16550_putc(priv, ch);
#ifndef CONFIG_SUPPRESS_SERIAL_INTS
u16550_restoreuartint(priv, ier);
#endif
return ch;
}
#endif

View File

@ -66,7 +66,8 @@
struct vs1053_lower_s
{
int (*attach)(FAR const struct vs1053_lower_s *lower, xcpt_t handler);
int (*attach)(FAR const struct vs1053_lower_s *lower, xcpt_t handler,
FAR void *arg);
void (*enable)(FAR const struct vs1053_lower_s *lower);
void (*disable)(FAR const struct vs1053_lower_s *lower);
void (*reset)(FAR const struct vs1053_lower_s *lower, bool state);