mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
drivers/at86rf2xx: move TX power logic to netdev
This commit is contained in:
parent
4708478e98
commit
bc1043921d
@ -83,9 +83,9 @@ void at86rf2xx_reset(at86rf2xx_t *dev)
|
||||
}
|
||||
|
||||
/* set default channel and page */
|
||||
at86rf2xx_configure_phy(dev, AT86RF2XX_DEFAULT_CHANNEL, AT86RF2XX_DEFAULT_PAGE);
|
||||
at86rf2xx_configure_phy(dev, AT86RF2XX_DEFAULT_CHANNEL, AT86RF2XX_DEFAULT_PAGE, AT86RF2XX_DEFAULT_TXPOWER);
|
||||
/* set default TX power */
|
||||
at86rf2xx_set_txpower(dev, AT86RF2XX_DEFAULT_TXPOWER);
|
||||
at86rf2xx_set_txpower(dev, AT86RF2XX_DEFAULT_TXPOWER, AT86RF2XX_DEFAULT_CHANNEL);
|
||||
/* set default options */
|
||||
|
||||
if (!IS_ACTIVE(AT86RF2XX_BASIC_MODE)) {
|
||||
|
@ -51,43 +51,12 @@ static const uint8_t dbm_to_tx_pow_915[] = { 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x17,
|
||||
0x04, 0x03, 0x02, 0x01, 0x00, 0x86,
|
||||
0x40, 0x84, 0x83, 0x82, 0x80, 0xc1,
|
||||
0xc0 };
|
||||
static int16_t _tx_pow_to_dbm_212b(uint8_t channel, uint8_t page, uint8_t reg)
|
||||
{
|
||||
if (page == 0 || page == 2) {
|
||||
const uint8_t *dbm_to_tx_pow;
|
||||
size_t nelem;
|
||||
|
||||
if (channel == 0) {
|
||||
/* Channel 0 is 868.3 MHz */
|
||||
dbm_to_tx_pow = &dbm_to_tx_pow_868[0];
|
||||
nelem = ARRAY_SIZE(dbm_to_tx_pow_868);
|
||||
}
|
||||
else {
|
||||
/* Channels 1+ are 915 MHz */
|
||||
dbm_to_tx_pow = &dbm_to_tx_pow_915[0];
|
||||
nelem = ARRAY_SIZE(dbm_to_tx_pow_915);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < nelem; ++i) {
|
||||
if (dbm_to_tx_pow[i] == reg) {
|
||||
return (i - AT86RF2XX_TXPOWER_OFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#elif MODULE_AT86RF233
|
||||
static const int16_t tx_pow_to_dbm[] = { 4, 4, 3, 3, 2, 2, 1,
|
||||
0, -1, -2, -3, -4, -6, -8, -12, -17 };
|
||||
static const uint8_t dbm_to_tx_pow[] = { 0x0f, 0x0f, 0x0f, 0x0e, 0x0e, 0x0e,
|
||||
0x0e, 0x0d, 0x0d, 0x0d, 0x0c, 0x0c,
|
||||
0x0b, 0x0b, 0x0a, 0x09, 0x08, 0x07,
|
||||
0x06, 0x05, 0x03, 0x00 };
|
||||
#else
|
||||
static const int16_t tx_pow_to_dbm[] = { 3, 3, 2, 2, 1, 1, 0,
|
||||
-1, -2, -3, -4, -5, -7, -9, -12, -17 };
|
||||
static const uint8_t dbm_to_tx_pow[] = { 0x0f, 0x0f, 0x0f, 0x0e, 0x0e, 0x0e,
|
||||
0x0e, 0x0d, 0x0d, 0x0c, 0x0c, 0x0b,
|
||||
0x0b, 0x0a, 0x09, 0x08, 0x07, 0x06,
|
||||
@ -163,21 +132,9 @@ void at86rf2xx_set_pan(at86rf2xx_t *dev, uint16_t pan)
|
||||
at86rf2xx_reg_write(dev, AT86RF2XX_REG__PAN_ID_1, le_pan.u8[1]);
|
||||
}
|
||||
|
||||
int16_t at86rf2xx_get_txpower(const at86rf2xx_t *dev)
|
||||
{
|
||||
#if AT86RF2XX_HAVE_SUBGHZ
|
||||
uint8_t txpower = at86rf2xx_reg_read(dev, AT86RF2XX_REG__PHY_TX_PWR);
|
||||
DEBUG("txpower value: %x\n", txpower);
|
||||
return _tx_pow_to_dbm_212b(dev->netdev.chan, dev->page, txpower);
|
||||
#else
|
||||
uint8_t txpower = at86rf2xx_reg_read(dev, AT86RF2XX_REG__PHY_TX_PWR)
|
||||
& AT86RF2XX_PHY_TX_PWR_MASK__TX_PWR;
|
||||
return tx_pow_to_dbm[txpower];
|
||||
#endif
|
||||
}
|
||||
|
||||
void at86rf2xx_set_txpower(const at86rf2xx_t *dev, int16_t txpower)
|
||||
void at86rf2xx_set_txpower(const at86rf2xx_t *dev, int16_t txpower, uint8_t channel)
|
||||
{
|
||||
(void) channel;
|
||||
txpower += AT86RF2XX_TXPOWER_OFF;
|
||||
|
||||
if (txpower < 0) {
|
||||
@ -187,11 +144,11 @@ void at86rf2xx_set_txpower(const at86rf2xx_t *dev, int16_t txpower)
|
||||
txpower = AT86RF2XX_TXPOWER_MAX;
|
||||
}
|
||||
#if AT86RF2XX_HAVE_SUBGHZ
|
||||
if (dev->netdev.chan == 0) {
|
||||
if (channel == 0) {
|
||||
at86rf2xx_reg_write(dev, AT86RF2XX_REG__PHY_TX_PWR,
|
||||
dbm_to_tx_pow_868[txpower]);
|
||||
}
|
||||
else if (dev->netdev.chan < 11) {
|
||||
else if (channel < 11) {
|
||||
at86rf2xx_reg_write(dev, AT86RF2XX_REG__PHY_TX_PWR,
|
||||
dbm_to_tx_pow_915[txpower]);
|
||||
}
|
||||
|
@ -164,16 +164,17 @@ void at86rf2xx_hardware_reset(at86rf2xx_t *dev)
|
||||
&& (dev->state != AT86RF2XX_STATE_P_ON));
|
||||
}
|
||||
|
||||
void at86rf2xx_configure_phy(at86rf2xx_t *dev, uint8_t chan, uint8_t page)
|
||||
void at86rf2xx_configure_phy(at86rf2xx_t *dev, uint8_t chan, uint8_t page, int16_t txpower)
|
||||
{
|
||||
/* we must be in TRX_OFF before changing the PHY configuration */
|
||||
uint8_t prev_state = at86rf2xx_set_state(dev, AT86RF2XX_STATE_TRX_OFF);
|
||||
(void) page;
|
||||
(void) chan;
|
||||
(void) txpower;
|
||||
|
||||
#if AT86RF2XX_HAVE_SUBGHZ
|
||||
/* The TX power register must be updated after changing the channel if
|
||||
* moving between bands. */
|
||||
int16_t txpower = at86rf2xx_get_txpower(dev);
|
||||
|
||||
uint8_t trx_ctrl2 = at86rf2xx_reg_read(dev, AT86RF2XX_REG__TRX_CTRL_2);
|
||||
uint8_t rf_ctrl0 = at86rf2xx_reg_read(dev, AT86RF2XX_REG__RF_CTRL_0);
|
||||
@ -214,7 +215,7 @@ void at86rf2xx_configure_phy(at86rf2xx_t *dev, uint8_t chan, uint8_t page)
|
||||
|
||||
#if AT86RF2XX_HAVE_SUBGHZ
|
||||
/* Update the TX power register to achieve the same power (in dBm) */
|
||||
at86rf2xx_set_txpower(dev, txpower);
|
||||
at86rf2xx_set_txpower(dev, txpower, chan);
|
||||
#endif
|
||||
|
||||
/* Return to the state we had before reconfiguring */
|
||||
|
@ -492,7 +492,7 @@ static int _get(netdev_t *netdev, netopt_t opt, void *val, size_t max_len)
|
||||
switch (opt) {
|
||||
case NETOPT_TX_POWER:
|
||||
assert(max_len >= sizeof(int16_t));
|
||||
*((uint16_t *)val) = at86rf2xx_get_txpower(dev);
|
||||
*((uint16_t *)val) = netdev_ieee802154->txpower;
|
||||
res = sizeof(uint16_t);
|
||||
break;
|
||||
|
||||
@ -625,9 +625,9 @@ static int _set(netdev_t *netdev, netopt_t opt, const void *val, size_t len)
|
||||
}
|
||||
dev->netdev.chan = chan;
|
||||
#if AT86RF2XX_HAVE_SUBGHZ
|
||||
at86rf2xx_configure_phy(dev, chan, dev->page);
|
||||
at86rf2xx_configure_phy(dev, chan, dev->page, dev->netdev.txpower);
|
||||
#else
|
||||
at86rf2xx_configure_phy(dev, chan, 0);
|
||||
at86rf2xx_configure_phy(dev, chan, 0, dev->netdev.txpower);
|
||||
#endif
|
||||
/* don't set res to set netdev_ieee802154_t::chan */
|
||||
break;
|
||||
@ -641,7 +641,7 @@ static int _set(netdev_t *netdev, netopt_t opt, const void *val, size_t len)
|
||||
}
|
||||
else {
|
||||
dev->page = page;
|
||||
at86rf2xx_configure_phy(dev, dev->netdev.chan, page);
|
||||
at86rf2xx_configure_phy(dev, dev->netdev.chan, page, dev->netdev.txpower);
|
||||
res = sizeof(uint16_t);
|
||||
}
|
||||
#else
|
||||
@ -657,7 +657,8 @@ static int _set(netdev_t *netdev, netopt_t opt, const void *val, size_t len)
|
||||
|
||||
case NETOPT_TX_POWER:
|
||||
assert(len <= sizeof(int16_t));
|
||||
at86rf2xx_set_txpower(dev, *((const int16_t *)val));
|
||||
netdev_ieee802154->txpower = *((const int16_t *)val);
|
||||
at86rf2xx_set_txpower(dev, *((const int16_t *)val), dev->netdev.chan);
|
||||
res = sizeof(uint16_t);
|
||||
break;
|
||||
|
||||
|
@ -221,7 +221,7 @@ void at86rf2xx_hardware_reset(at86rf2xx_t *dev);
|
||||
*
|
||||
* @param[in,out] dev device to configure
|
||||
*/
|
||||
void at86rf2xx_configure_phy(at86rf2xx_t *dev, uint8_t chan, uint8_t page);
|
||||
void at86rf2xx_configure_phy(at86rf2xx_t *dev, uint8_t chan, uint8_t page, int16_t txpower);
|
||||
|
||||
#if AT86RF2XX_RANDOM_NUMBER_GENERATOR || defined(DOXYGEN)
|
||||
/**
|
||||
|
@ -378,15 +378,6 @@ uint8_t at86rf2xx_get_rate(at86rf2xx_t *dev);
|
||||
*/
|
||||
int at86rf2xx_set_rate(at86rf2xx_t *dev, uint8_t rate);
|
||||
|
||||
/**
|
||||
* @brief Get the configured PAN ID of the given device
|
||||
*
|
||||
* @param[in] dev device to read from
|
||||
*
|
||||
* @return the currently set PAN ID
|
||||
*/
|
||||
uint16_t at86rf2xx_get_pan(const at86rf2xx_t *dev);
|
||||
|
||||
/**
|
||||
* @brief Set the PAN ID of the given device
|
||||
*
|
||||
@ -395,15 +386,6 @@ uint16_t at86rf2xx_get_pan(const at86rf2xx_t *dev);
|
||||
*/
|
||||
void at86rf2xx_set_pan(at86rf2xx_t *dev, uint16_t pan);
|
||||
|
||||
/**
|
||||
* @brief Get the configured transmission power of the given device [in dBm]
|
||||
*
|
||||
* @param[in] dev device to read from
|
||||
*
|
||||
* @return configured transmission power in dBm
|
||||
*/
|
||||
int16_t at86rf2xx_get_txpower(const at86rf2xx_t *dev);
|
||||
|
||||
/**
|
||||
* @brief Set the transmission power of the given device [in dBm]
|
||||
*
|
||||
@ -414,8 +396,9 @@ int16_t at86rf2xx_get_txpower(const at86rf2xx_t *dev);
|
||||
*
|
||||
* @param[in] dev device to write to
|
||||
* @param[in] txpower transmission power in dBm
|
||||
* @param[in] channel the current channel
|
||||
*/
|
||||
void at86rf2xx_set_txpower(const at86rf2xx_t *dev, int16_t txpower);
|
||||
void at86rf2xx_set_txpower(const at86rf2xx_t *dev, int16_t txpower, uint8_t channel);
|
||||
|
||||
/**
|
||||
* @brief Get the configured receiver sensitivity of the given device [in dBm]
|
||||
|
Loading…
Reference in New Issue
Block a user