AT86RF23x: Clean-up, standardize lower half interface. Take advantage of new OS features for interrupt parameter passing.

This commit is contained in:
Gregory Nutt
2017-03-27 10:28:03 -06:00
parent 16c3ea1f53
commit b315f0d851
2 changed files with 36 additions and 28 deletions
+15 -18
View File
@@ -146,7 +146,7 @@ static int at86rf23x_regdump(FAR struct at86rf23x_dev_s *dev);
static void at86rf23x_irqwork_rx(FAR struct at86rf23x_dev_s *dev); static void at86rf23x_irqwork_rx(FAR struct at86rf23x_dev_s *dev);
static void at86rf23x_irqwork_tx(FAR struct at86rf23x_dev_s *dev); static void at86rf23x_irqwork_tx(FAR struct at86rf23x_dev_s *dev);
static void at86rf23x_irqworker(FAR void *arg); static void at86rf23x_irqworker(FAR void *arg);
static int at86rf23x_interrupt(int irq, FAR void *context); static int at86rf23x_interrupt(int irq, FAR void *context, FAR void *arg);
/* Driver operations */ /* Driver operations */
@@ -1221,11 +1221,11 @@ static int at86rf23x_resetrf(FAR struct at86rf23x_dev_s *dev)
/* Reset the radio */ /* Reset the radio */
lower->reset(lower, 0); lower->reset(lower, false);
lower->slptr(lower, 0); lower->slptr(lower, false);
up_udelay(RF23X_TIME_RESET); up_udelay(RF23X_TIME_RESET);
lower->reset(lower, 1); lower->reset(lower, true);
/* Dummy read of IRQ register */ /* Dummy read of IRQ register */
@@ -1287,13 +1287,11 @@ static int at86rf23x_rxenable(FAR struct ieee802154_radio_s *ieee, bool state,
* *
****************************************************************************/ ****************************************************************************/
static int at86rf23x_interrupt(int irq, FAR void *context) static int at86rf23x_interrupt(int irq, FAR void *context, FAR void *arg)
{ {
/* To support multiple devices, retrieve the priv structure using the irq FAR struct at86rf23x_dev_s *dev = (FAR struct at86rf23x_dev_s *)arg;
* number.
*/
register FAR struct at86rf23x_dev_s *dev = &g_at86rf23x_devices[0]; DEBUGASSERT(dev != NULL);
/* In complex environments, we cannot do SPI transfers from the interrupt /* In complex environments, we cannot do SPI transfers from the interrupt
* handler because semaphores are probably used to lock the SPI bus. In * handler because semaphores are probably used to lock the SPI bus. In
@@ -1309,8 +1307,7 @@ static int at86rf23x_interrupt(int irq, FAR void *context)
* Interrupts are re-enabled in enc_irqworker() when the work is completed. * Interrupts are re-enabled in enc_irqworker() when the work is completed.
*/ */
dev->lower->irq(dev->lower, NULL, FALSE); dev->lower->enable(dev->lower, false);
//dev->lower->enable(dev->lower, FALSE);
return work_queue(HPWORK, &dev->irqwork, at86rf23x_irqworker, return work_queue(HPWORK, &dev->irqwork, at86rf23x_irqworker,
(FAR void *)dev, 0); (FAR void *)dev, 0);
@@ -1393,11 +1390,11 @@ static void at86rf23x_irqworker(FAR void *arg)
{ {
wlerr("ERROR: Unknown IRQ Status: %d\n", irq_status); wlerr("ERROR: Unknown IRQ Status: %d\n", irq_status);
/* Re enable the IRQ even if we don't know how to handle previous /* Re-enable the IRQ even if we don't know how to handle previous
* status. * status.
*/ */
dev->lower->irq(dev->lower, NULL, true); dev->lower->enable(dev->lower, true);
} }
} }
@@ -1428,9 +1425,9 @@ static void at86rf23x_irqwork_rx(FAR struct at86rf23x_dev_s *dev)
* soon. * soon.
*/ */
/* Re enable the IRQ */ /* Re-enable the IRQ */
dev->lower->irq(dev->lower, NULL, true); dev->lower->enable(dev->lower, true);
} }
/**************************************************************************** /****************************************************************************
@@ -1452,7 +1449,7 @@ static void at86rf23x_irqwork_tx(FAR struct at86rf23x_dev_s *dev)
/* Re enable the IRQ */ /* Re enable the IRQ */
dev->lower->irq(dev->lower, NULL, true); dev->lower->enable(dev->lower, true);
sem_post(&dev->ieee.txsem); sem_post(&dev->ieee.txsem);
} }
@@ -1528,7 +1525,7 @@ FAR struct ieee802154_radio_s *at86rf23x_init(FAR struct spi_dev_s *spi,
/* Attach irq */ /* Attach irq */
if (lower->irq(lower, at86rf23x_interrupt, false) != OK) if (lower->attach(lower, at86rf23x_interrupt, dev) != OK)
{ {
return NULL; return NULL;
} }
@@ -1598,6 +1595,6 @@ FAR struct ieee802154_radio_s *at86rf23x_init(FAR struct spi_dev_s *spi,
/* Enable Radio IRQ */ /* Enable Radio IRQ */
lower->irq(lower, at86rf23x_interrupt, true); lower->enable(lower, true);
return &dev->ieee; return &dev->ieee;
} }
+21 -10
View File
@@ -37,25 +37,36 @@
#ifndef __INCLUDE_NUTTX_IEEE802154_AT86RF23X_H #ifndef __INCLUDE_NUTTX_IEEE802154_AT86RF23X_H
#define __INCLUDE_NUTTX_IEEE802154_AT86RF23X_H #define __INCLUDE_NUTTX_IEEE802154_AT86RF23X_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdbool.h>
/****************************************************************************
* Public Types
****************************************************************************/
/* The at86rf23x provides interrupts to the MCU via a GPIO pin. The /* The at86rf23x provides interrupts to the MCU via a GPIO pin. The
* following structure provides an MCU-independent mechanixm for controlling * following structure provides an MCU-independent mechanixm for controlling
* the at86rf23x GPIO interrupt. * the at86rf23x GPIO interrupt.
* *
* The at86rf23x interrupt is an active low, *level* interrupt. From Datasheet: * The at86rf23x interrupt is an active low, *level* interrupt. From Datasheet:
* "Note 1: The INTEDGE polarity defaults to: * "Note 1: The INTEDGE polarity defaults to: 0 = Falling Edge. Ensure that
* 0 = Falling Edge. Ensure that the inter- * the interrupt polarity matches the interrupt pin polarity of the host
* rupt polarity matches the interrupt pin * microcontroller.
* polarity of the host microcontroller. * "Note 2: The INT pin will remain high or low, depending on INTEDGE polarity
* Note 2: The INT pin will remain high or low, * setting, until INTSTAT register is read."
* depending on INTEDGE polarity setting,
* until INTSTAT register is read."
*/ */
struct at86rf23x_lower_s struct at86rf23x_lower_s
{ {
int (*irq)(FAR const struct at86rf23x_lower_s *lower, xcpt_t handler, int state); int (*attach)(FAR const struct at86rf23x_lower_s *lower, xcpt_t handler,
void (*slptr)(FAR const struct at86rf23x_lower_s *lower, int state); FAR void *arg);
void (*reset)(FAR const struct at86rf23x_lower_s *lower, int state); void (*enable)(FAR const struct at86rf23x_lower_s *lower, bool state);
void (*slptr)(FAR const struct at86rf23x_lower_s *lower, bool state);
void (*reset)(FAR const struct at86rf23x_lower_s *lower, bool state);
}; };
#ifdef __cplusplus #ifdef __cplusplus