From c8aff362377210ecefaba48b66b7477a93631bde Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Tue, 5 May 2015 22:49:04 +0200 Subject: [PATCH 1/2] netconf: added option to en/disable the SFD IRQ Also includes the implementation for the AT86RF231 --- drivers/ng_at86rf2xx/ng_at86rf2xx_netdev.c | 7 ++++ sys/include/net/ng_netconf.h | 40 ++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/drivers/ng_at86rf2xx/ng_at86rf2xx_netdev.c b/drivers/ng_at86rf2xx/ng_at86rf2xx_netdev.c index 30c75194a5..7d4f710501 100644 --- a/drivers/ng_at86rf2xx/ng_at86rf2xx_netdev.c +++ b/drivers/ng_at86rf2xx/ng_at86rf2xx_netdev.c @@ -357,6 +357,7 @@ static int _get(ng_netdev_t *device, ng_netconf_opt_t opt, ng_at86rf2xx_t *dev = (ng_at86rf2xx_t *) device; switch (opt) { + uint8_t irq_mask; case NETCONF_OPT_ADDRESS: if (max_len < sizeof(uint16_t)) { @@ -487,6 +488,12 @@ static int _get(ng_netdev_t *device, ng_netconf_opt_t opt, } return sizeof(ng_netconf_enable_t); + case NETCONT_OPT_SFD_INT: + irq_mask = ng_at86rf2xx_reg_read(dev, NG_AT86RF2XX_REG__IRQ_MASK); + ng_at86rf2xx_reg_write(dev, NG_AT86RF2XX_REG__IRQ_MASK, + (irq_mask ^ NG_AT86RF2XX_IRQ_STATUS_MASK__RX_START)); + return sizeof(ng_netconf_enable_t); + default: return -ENOTSUP; } diff --git a/sys/include/net/ng_netconf.h b/sys/include/net/ng_netconf.h index eb092d3b13..0ebbf65b58 100644 --- a/sys/include/net/ng_netconf.h +++ b/sys/include/net/ng_netconf.h @@ -17,6 +17,7 @@ * @brief Definition of global configuration options * * @author Hauke Petersen + * @author Oliver Hahm */ #ifndef NG_NET_CONF_H_ @@ -78,6 +79,45 @@ typedef enum { NETCONF_OPT_RAWMODE, /**< en/disable the pre-processing of data in a network device driver as type ng_nettype_t */ + + /** + * @brief en/disable the interrupt at reception start. + * + * It is mostly triggered after the preamble is correctly received + * + * @note not all transceivers may support this interrupt + */ + NETCONF_OPT_RX_START_IRQ, + + /** + * @brief en/disable the interrupt after packet reception. + * + * This interrupt is triggered after a complete packet is received. + * + * @note in case a transceiver does not support this interrupt, the event + * may be triggered by the driver + */ + NETCONF_OPT_RX_END_IRQ, + + /** + * @brief en/disable the interrupt right in the beginning of transmission. + * + * This interrupt is triggered when the transceiver starts to send out the + * packet. + * + * @note in case a transceiver does not support this interrupt, the event + * may be triggered by the driver + */ + NETCONF_OPT_TX_START_IRQ, + + /** + * @brief en/disable the interrupt after packet transmission. + * + * This interrupt is triggered when the full packet is transmitted. + * + * @note not all transceivers may support this interrupt + */ + NETCONF_OPT_TX_END_IRQ, /* add more options if needed */ } ng_netconf_opt_t; From a97ee2b0a4e45e2b6f80ab72e86dab1916fb6865 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Tue, 5 May 2015 22:50:14 +0200 Subject: [PATCH 2/2] at86rf231: disable SFD IRQ by default --- drivers/ng_at86rf2xx/ng_at86rf2xx.c | 3 +- drivers/ng_at86rf2xx/ng_at86rf2xx_getset.c | 12 ++++++ drivers/ng_at86rf2xx/ng_at86rf2xx_netdev.c | 47 ++++++++++++++++++---- 3 files changed, 52 insertions(+), 10 deletions(-) diff --git a/drivers/ng_at86rf2xx/ng_at86rf2xx.c b/drivers/ng_at86rf2xx/ng_at86rf2xx.c index 7707fb69c0..0995b15ffc 100644 --- a/drivers/ng_at86rf2xx/ng_at86rf2xx.c +++ b/drivers/ng_at86rf2xx/ng_at86rf2xx.c @@ -154,8 +154,7 @@ void ng_at86rf2xx_reset(ng_at86rf2xx_t *dev) ng_at86rf2xx_reg_write(dev, NG_AT86RF2XX_REG__TRX_CTRL_2, tmp); /* enable interrupts */ ng_at86rf2xx_reg_write(dev, NG_AT86RF2XX_REG__IRQ_MASK, - (NG_AT86RF2XX_IRQ_STATUS_MASK__RX_START | - NG_AT86RF2XX_IRQ_STATUS_MASK__TRX_END)); + NG_AT86RF2XX_IRQ_STATUS_MASK__TRX_END); /* go into RX state */ ng_at86rf2xx_set_state(dev, NG_AT86RF2XX_STATE_RX_AACK_ON); diff --git a/drivers/ng_at86rf2xx/ng_at86rf2xx_getset.c b/drivers/ng_at86rf2xx/ng_at86rf2xx_getset.c index cdfaf41267..067d5ca4c4 100644 --- a/drivers/ng_at86rf2xx/ng_at86rf2xx_getset.c +++ b/drivers/ng_at86rf2xx/ng_at86rf2xx_getset.c @@ -154,6 +154,12 @@ void ng_at86rf2xx_set_option(ng_at86rf2xx_t *dev, uint16_t option, bool state) tmp &= ~(NG_AT86RF2XX_CSMA_SEED_1__AACK_DIS_ACK); ng_at86rf2xx_reg_write(dev, NG_AT86RF2XX_REG__CSMA_SEED_1, tmp); break; + case NG_AT86RF2XX_OPT_TELL_RX_START: + DEBUG("[ng_at86rf2xx] opt: enabling SFD IRQ\n"); + tmp = ng_at86rf2xx_reg_read(dev, NG_AT86RF2XX_REG__IRQ_MASK); + tmp |= NG_AT86RF2XX_IRQ_STATUS_MASK__RX_START; + ng_at86rf2xx_reg_write(dev, NG_AT86RF2XX_REG__IRQ_MASK, tmp); + break; default: /* do nothing */ break; @@ -185,6 +191,12 @@ void ng_at86rf2xx_set_option(ng_at86rf2xx_t *dev, uint16_t option, bool state) tmp |= NG_AT86RF2XX_CSMA_SEED_1__AACK_DIS_ACK; ng_at86rf2xx_reg_write(dev, NG_AT86RF2XX_REG__CSMA_SEED_1, tmp); break; + case NG_AT86RF2XX_OPT_TELL_RX_START: + DEBUG("[ng_at86rf2xx] opt: disabling SFD IRQ\n"); + tmp = ng_at86rf2xx_reg_read(dev, NG_AT86RF2XX_REG__IRQ_MASK); + tmp &= ~NG_AT86RF2XX_IRQ_STATUS_MASK__RX_START; + ng_at86rf2xx_reg_write(dev, NG_AT86RF2XX_REG__IRQ_MASK, tmp); + break; default: /* do nothing */ break; diff --git a/drivers/ng_at86rf2xx/ng_at86rf2xx_netdev.c b/drivers/ng_at86rf2xx/ng_at86rf2xx_netdev.c index 7d4f710501..2ee80a69ff 100644 --- a/drivers/ng_at86rf2xx/ng_at86rf2xx_netdev.c +++ b/drivers/ng_at86rf2xx/ng_at86rf2xx_netdev.c @@ -357,7 +357,6 @@ static int _get(ng_netdev_t *device, ng_netconf_opt_t opt, ng_at86rf2xx_t *dev = (ng_at86rf2xx_t *) device; switch (opt) { - uint8_t irq_mask; case NETCONF_OPT_ADDRESS: if (max_len < sizeof(uint16_t)) { @@ -488,10 +487,24 @@ static int _get(ng_netdev_t *device, ng_netconf_opt_t opt, } return sizeof(ng_netconf_enable_t); - case NETCONT_OPT_SFD_INT: - irq_mask = ng_at86rf2xx_reg_read(dev, NG_AT86RF2XX_REG__IRQ_MASK); - ng_at86rf2xx_reg_write(dev, NG_AT86RF2XX_REG__IRQ_MASK, - (irq_mask ^ NG_AT86RF2XX_IRQ_STATUS_MASK__RX_START)); + case NETCONF_OPT_RX_START_IRQ: + *((ng_netconf_enable_t *)val) = + !!(dev->options & NG_AT86RF2XX_OPT_TELL_RX_START); + return sizeof(ng_netconf_enable_t); + + case NETCONF_OPT_RX_END_IRQ: + *((ng_netconf_enable_t *)val) = + !!(dev->options & NG_AT86RF2XX_OPT_TELL_RX_END); + return sizeof(ng_netconf_enable_t); + + case NETCONF_OPT_TX_START_IRQ: + *((ng_netconf_enable_t *)val) = + !!(dev->options & NG_AT86RF2XX_OPT_TELL_TX_START); + return sizeof(ng_netconf_enable_t); + + case NETCONF_OPT_TX_END_IRQ: + *((ng_netconf_enable_t *)val) = + !!(dev->options & NG_AT86RF2XX_OPT_TELL_TX_END); return sizeof(ng_netconf_enable_t); default: @@ -606,6 +619,26 @@ static int _set(ng_netdev_t *device, ng_netconf_opt_t opt, ((bool *)val)[0]); return sizeof(ng_netconf_enable_t); + case NETCONF_OPT_RX_START_IRQ: + ng_at86rf2xx_set_option(dev, NG_AT86RF2XX_OPT_TELL_RX_START, + ((bool *)val)[0]); + return sizeof(ng_netconf_enable_t); + + case NETCONF_OPT_RX_END_IRQ: + ng_at86rf2xx_set_option(dev, NG_AT86RF2XX_OPT_TELL_RX_END, + ((bool *)val)[0]); + return sizeof(ng_netconf_enable_t); + + case NETCONF_OPT_TX_START_IRQ: + ng_at86rf2xx_set_option(dev, NG_AT86RF2XX_OPT_TELL_TX_START, + ((bool *)val)[0]); + return sizeof(ng_netconf_enable_t); + + case NETCONF_OPT_TX_END_IRQ: + ng_at86rf2xx_set_option(dev, NG_AT86RF2XX_OPT_TELL_TX_END, + ((bool *)val)[0]); + return sizeof(ng_netconf_enable_t); + default: return -ENOTSUP; } @@ -650,9 +683,7 @@ static void _isr_event(ng_netdev_t *device, uint32_t event_type) state = ng_at86rf2xx_get_state(dev); if (irq_mask & NG_AT86RF2XX_IRQ_STATUS_MASK__RX_START) { - if (dev->event_cb && (dev->options & NG_AT86RF2XX_OPT_TELL_RX_START)) { - dev->event_cb(NETDEV_EVENT_RX_STARTED, NULL); - } + dev->event_cb(NETDEV_EVENT_RX_STARTED, NULL); DEBUG("[ng_at86rf2xx] EVT - RX_START\n"); } if (irq_mask & NG_AT86RF2XX_IRQ_STATUS_MASK__TRX_END) {