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 7607416769..0394cd3590 100644 --- a/drivers/ng_at86rf2xx/ng_at86rf2xx_getset.c +++ b/drivers/ng_at86rf2xx/ng_at86rf2xx_getset.c @@ -190,7 +190,7 @@ int16_t ng_at86rf2xx_get_txpower(ng_at86rf2xx_t *dev) { #ifdef MODULE_NG_AT86RF212B uint8_t txpower = ng_at86rf2xx_reg_read(dev, NG_AT86RF2XX_REG__PHY_TX_PWR); - printf("txpower value: %x\n", txpower); + DEBUG("txpower value: %x\n", txpower); return tx_pow_to_dbm(dev->freq, txpower); #else uint8_t txpower = ng_at86rf2xx_reg_read(dev, NG_AT86RF2XX_REG__PHY_TX_PWR) @@ -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 26bdb98c95..d1cef90dbe 100644 --- a/drivers/ng_at86rf2xx/ng_at86rf2xx_netdev.c +++ b/drivers/ng_at86rf2xx/ng_at86rf2xx_netdev.c @@ -452,6 +452,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; @@ -584,6 +591,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