From 76e4c820e526947e6ca91edd2477e932efed3f91 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Mon, 18 May 2015 21:19:03 +0200 Subject: [PATCH] ng_netconf: ng_at86rf2xx: set retransmissions Introduces a netconf option to configure the maximum amount of retransmissions and implements this for the at86rf2xx radios. --- drivers/include/ng_at86rf2xx.h | 21 +++++++++++++++++++ .../include/ng_at86rf2xx_registers.h | 9 ++++++++ drivers/ng_at86rf2xx/ng_at86rf2xx_getset.c | 14 +++++++++++++ drivers/ng_at86rf2xx/ng_at86rf2xx_netdev.c | 14 +++++++++++++ sys/include/net/ng_netconf.h | 2 ++ 5 files changed, 60 insertions(+) diff --git a/drivers/include/ng_at86rf2xx.h b/drivers/include/ng_at86rf2xx.h index 83bbbff5db..22291b3276 100644 --- a/drivers/include/ng_at86rf2xx.h +++ b/drivers/include/ng_at86rf2xx.h @@ -316,6 +316,27 @@ int16_t ng_at86rf2xx_get_txpower(ng_at86rf2xx_t *dev); */ void ng_at86rf2xx_set_txpower(ng_at86rf2xx_t *dev, int16_t txpower); +/** + * @brief Get the maximum number of retransmissions + * + * @param[in] dev device to read from + * + * @return configured number of retransmissions + */ +uint8_t ng_at86rf2xx_get_max_retries(ng_at86rf2xx_t *dev); + +/** + * @brief Set the maximum number of retransmissions + * + * This setting specifies the number of attempts to retransmit a frame, when it + * was not acknowledged by the recipient, before the transaction gets cancelled. + * The maximum value is 7. + * + * @param[in] dev device to write to + * @param[in] max the maximum number of retransmissions + */ +void ng_at86rf2xx_set_max_retries(ng_at86rf2xx_t *dev, uint8_t max); + /** * @brief Enable or disable driver specific options * diff --git a/drivers/ng_at86rf2xx/include/ng_at86rf2xx_registers.h b/drivers/ng_at86rf2xx/include/ng_at86rf2xx_registers.h index 73630f67ee..94c328a6da 100644 --- a/drivers/ng_at86rf2xx/include/ng_at86rf2xx_registers.h +++ b/drivers/ng_at86rf2xx/include/ng_at86rf2xx_registers.h @@ -291,6 +291,15 @@ extern "C" { #define NG_AT86RF2XX_TIMING__RESET_TO_TRX_OFF (37) /** @} */ +/** + * @brief Bitfield definitions for the XAH_CTRL_0 register + * @{ + */ +#define NG_AT86RF2XX_XAH_CTRL_0__MAX_FRAME_RETRIES (0xF0) +#define NG_AT86RF2XX_XAH_CTRL_0__MAX_CSMA_RETRIES (0x0E) +#define NG_AT86RF2XX_XAH_CTRL_0__SLOTTED_OPERATION (0x01) +/** @} */ + /** * @brief Bitfield definitions for the XAH_CTRL_1 register * @{ diff --git a/drivers/ng_at86rf2xx/ng_at86rf2xx_getset.c b/drivers/ng_at86rf2xx/ng_at86rf2xx_getset.c index 25a918db6c..0394cd3590 100644 --- a/drivers/ng_at86rf2xx/ng_at86rf2xx_getset.c +++ b/drivers/ng_at86rf2xx/ng_at86rf2xx_getset.c @@ -235,6 +235,20 @@ void ng_at86rf2xx_set_txpower(ng_at86rf2xx_t *dev, int16_t txpower) #endif } +uint8_t ng_at86rf2xx_get_max_retries(ng_at86rf2xx_t *dev) +{ + return (ng_at86rf2xx_reg_read(dev, NG_AT86RF2XX_REG__XAH_CTRL_0) >> 4); +} + +void ng_at86rf2xx_set_max_retries(ng_at86rf2xx_t *dev, uint8_t max) +{ + max = (max > 7) ? 7 : max; + uint8_t tmp = ng_at86rf2xx_reg_read(dev, NG_AT86RF2XX_REG__XAH_CTRL_0); + tmp &= ~(NG_AT86RF2XX_XAH_CTRL_0__MAX_FRAME_RETRIES); + tmp |= (max << 4); + ng_at86rf2xx_reg_write(dev, NG_AT86RF2XX_REG__XAH_CTRL_0, tmp); +} + void ng_at86rf2xx_set_option(ng_at86rf2xx_t *dev, uint16_t option, bool state) { uint8_t tmp; diff --git a/drivers/ng_at86rf2xx/ng_at86rf2xx_netdev.c b/drivers/ng_at86rf2xx/ng_at86rf2xx_netdev.c index cec284c901..87ded51896 100644 --- a/drivers/ng_at86rf2xx/ng_at86rf2xx_netdev.c +++ b/drivers/ng_at86rf2xx/ng_at86rf2xx_netdev.c @@ -445,6 +445,13 @@ static int _get(ng_netdev_t *device, ng_netconf_opt_t opt, } return sizeof(ng_netconf_enable_t); + case NETCONF_OPT_RETRANS: + if (max_len < sizeof(uint8_t)) { + return -EOVERFLOW; + } + *((uint8_t *)val) = ng_at86rf2xx_get_max_retries(dev); + return sizeof(uint8_t); + case NETCONF_OPT_PROMISCUOUSMODE: if (dev->options & NG_AT86RF2XX_OPT_PROMISCUOUS) { *((ng_netconf_enable_t *)val) = NETCONF_ENABLE; @@ -577,6 +584,13 @@ static int _set(ng_netdev_t *device, ng_netconf_opt_t opt, ((bool *)val)[0]); return sizeof(ng_netconf_enable_t); + case NETCONF_OPT_RETRANS: + if (len > sizeof(uint8_t)) { + return -EOVERFLOW; + } + ng_at86rf2xx_set_max_retries(dev, *((uint8_t *)val)); + return sizeof(uint8_t); + case NETCONF_OPT_PRELOADING: ng_at86rf2xx_set_option(dev, NG_AT86RF2XX_OPT_PRELOADING, ((bool *)val)[0]); diff --git a/sys/include/net/ng_netconf.h b/sys/include/net/ng_netconf.h index 167b221193..170cfcaa2e 100644 --- a/sys/include/net/ng_netconf.h +++ b/sys/include/net/ng_netconf.h @@ -72,6 +72,8 @@ typedef enum { * the current state */ NETCONF_OPT_AUTOACK, /**< en/disable link layer auto ACKs or read * the current state */ + NETCONF_OPT_RETRANS, /**< get/set the maximum number of + retransmissions. */ NETCONF_OPT_PROTO, /**< get/set the protocol for the layer * as type ng_nettype_t. */ NETCONF_OPT_STATE, /**< get/set the state of network devices as