Browse Source

Implemented the NETOPT_CCA_THRESHOLD option for AT86RF231

cc430
Kévin Roussel 7 years ago
parent
commit
8bfd856abe
  1. 26
      drivers/at86rf2xx/at86rf2xx_getset.c
  2. 19
      drivers/at86rf2xx/at86rf2xx_netdev.c
  3. 10
      drivers/at86rf2xx/include/at86rf2xx_registers.h
  4. 23
      drivers/include/at86rf2xx.h

26
drivers/at86rf2xx/at86rf2xx_getset.c

@ -17,6 +17,7 @@
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
* @author Baptiste Clenet <bapclenet@gmail.com>
* @author Daniel Krebs <github@daniel-krebs.net>
* @author Kévin Roussel <Kevin.Roussel@inria.fr>
*
* @}
*/
@ -310,6 +311,31 @@ void at86rf2xx_set_csma_seed(at86rf2xx_t *dev, uint8_t entropy[2])
at86rf2xx_reg_write(dev, AT86RF2XX_REG__CSMA_SEED_1, tmp);
}
int8_t at86rf2xx_get_cca_threshold(at86rf2xx_t *dev)
{
int8_t tmp = at86rf2xx_reg_read(dev, AT86RF2XX_REG__CCA_THRES);
tmp &= AT86RF2XX_CCA_THRES_MASK__CCA_ED_THRES;
tmp <<= 1;
return (RSSI_BASE_VAL + tmp);
}
void at86rf2xx_set_cca_threshold(at86rf2xx_t *dev, int8_t value)
{
/* ensure the given value is negative, since a CCA threshold > 0 is
just impossible: thus, any positive value given is considered
to be the absolute value of the actually wanted threshold */
if (value > 0) {
value = -value;
}
/* transform the dBm value in the form
that will fit in the AT86RF2XX_REG__CCA_THRES register */
value -= RSSI_BASE_VAL;
value >>= 1;
value &= AT86RF2XX_CCA_THRES_MASK__CCA_ED_THRES;
value |= AT86RF2XX_CCA_THRES_MASK__RSVD_HI_NIBBLE;
at86rf2xx_reg_write(dev, AT86RF2XX_REG__CCA_THRES, value);
}
void at86rf2xx_set_option(at86rf2xx_t *dev, uint16_t option, bool state)
{
uint8_t tmp;

19
drivers/at86rf2xx/at86rf2xx_netdev.c

@ -15,6 +15,7 @@
*
* @author Thomas Eichinger <thomas.eichinger@fu-berlin.de>
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
* @author Kévin Roussel <Kevin.Roussel@inria.fr>
*
* @}
*/
@ -569,6 +570,15 @@ static int _get(gnrc_netdev_t *device, netopt_t opt, void *val, size_t max_len)
}
break;
case NETOPT_CCA_THRESHOLD:
if (max_len < sizeof(int8_t)) {
res = -EOVERFLOW;
} else {
*((int8_t *)val) = at86rf2xx_get_cca_threshold(dev);
res = sizeof(int8_t);
}
break;
default:
res = -ENOTSUP;
}
@ -762,6 +772,15 @@ static int _set(gnrc_netdev_t *device, netopt_t opt, void *val, size_t len)
}
break;
case NETOPT_CCA_THRESHOLD:
if (len > sizeof(int8_t)) {
res = -EOVERFLOW;
} else {
at86rf2xx_set_cca_threshold(dev, *((int8_t *)val));
res = sizeof(int8_t);
}
break;
default:
res = -ENOTSUP;
}

10
drivers/at86rf2xx/include/at86rf2xx_registers.h

@ -18,6 +18,7 @@
* @author Thomas Eichinger <thomas.eichinger@fu-berlin.de>
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
* @author Kaspar Schleiser <kaspar@schleiser.de>
* @author Kévin Roussel <Kevin.Roussel@inria.fr>
*/
#ifndef AT86RF2XX_REGISTERS_H_
@ -241,6 +242,15 @@ extern "C" {
#define AT86RF2XX_PHY_CC_CCA_DEFAULT__CCA_MODE (0x20)
/** @} */
/**
* @brief Bitfield definitions for the CCA_THRES register
* @{
*/
#define AT86RF2XX_CCA_THRES_MASK__CCA_ED_THRES (0x0F)
#define AT86RF2XX_CCA_THRES_MASK__RSVD_HI_NIBBLE (0xC0)
/** @} */
/**
* @brief Bitfield definitions for the PHY_TX_PWR register
* @{

23
drivers/include/at86rf2xx.h

@ -22,6 +22,7 @@
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
* @author Kaspar Schleiser <kaspar@schleiser.de>
* @author Daniel Krebs <github@daniel-krebs.net>
* @author Kévin Roussel <Kevin.Roussel@inria.fr>
*/
#ifndef AT86RF2XX_H_
@ -80,6 +81,11 @@ extern "C" {
*/
#define AT86RF2XX_DEFAULT_TXPOWER (0U)
/**
* @brief Base (minimal) RSSI value in dBm
*/
#define RSSI_BASE_VAL (-91)
/**
* @brief Flags for device internal states (see datasheet)
* @{
@ -377,6 +383,23 @@ void at86rf2xx_set_csma_backoff_exp(at86rf2xx_t *dev, uint8_t min, uint8_t max);
*/
void at86rf2xx_set_csma_seed(at86rf2xx_t *dev, uint8_t entropy[2]);
/**
* @brief Get the CCA threshold value
*
* @param[in] dev device to read value from
*
* @return the current CCA threshold value
*/
int8_t at86rf2xx_get_cca_threshold(at86rf2xx_t *dev);
/**
* @brief Set the CCA threshold value
*
* @param[in] dev device to write to
* @param[in] value the new CCA threshold value
*/
void at86rf2xx_set_cca_threshold(at86rf2xx_t *dev, int8_t value);
/**
* @brief Enable or disable driver specific options
*

Loading…
Cancel
Save