From c978c51da241f468dd1e02705b038c4655a4674e Mon Sep 17 00:00:00 2001 From: Joakim Gebart <joakim.gebart@eistec.se> Date: Mon, 20 Jul 2015 10:57:17 +0200 Subject: [PATCH] drivers/ng_at86rf2xx: Refactor set_freq implementation for 212B Uses BPSK-40 for all frequencies. --- drivers/ng_at86rf2xx/ng_at86rf2xx_getset.c | 60 +++++++++++----------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/drivers/ng_at86rf2xx/ng_at86rf2xx_getset.c b/drivers/ng_at86rf2xx/ng_at86rf2xx_getset.c index 668b9c59a3..3cee746e34 100644 --- a/drivers/ng_at86rf2xx/ng_at86rf2xx_getset.c +++ b/drivers/ng_at86rf2xx/ng_at86rf2xx_getset.c @@ -138,38 +138,38 @@ ng_at86rf2xx_freq_t ng_at86rf2xx_get_freq(ng_at86rf2xx_t *dev) void ng_at86rf2xx_set_freq(ng_at86rf2xx_t *dev, ng_at86rf2xx_freq_t freq) { - uint8_t tmp1 = 0, tmp2 = 0; - tmp1 = ng_at86rf2xx_reg_read(dev, NG_AT86RF2XX_REG__TRX_CTRL_2); - tmp1 &= ~(NG_AT86RF2XX_TRX_CTRL_2_MASK__FREQ_MODE); - tmp2 = ng_at86rf2xx_reg_read(dev, NG_AT86RF2XX_REG__RF_CTRL_0); + uint8_t trx_ctrl2 = 0, rf_ctrl0 = 0; + trx_ctrl2 = ng_at86rf2xx_reg_read(dev, NG_AT86RF2XX_REG__TRX_CTRL_2); + trx_ctrl2 &= ~(NG_AT86RF2XX_TRX_CTRL_2_MASK__FREQ_MODE); + rf_ctrl0 = ng_at86rf2xx_reg_read(dev, NG_AT86RF2XX_REG__RF_CTRL_0); /* Erase previous conf for GC_TX_OFFS */ - tmp2 &= ~NG_AT86RF2XX_RF_CTRL_0_MASK__GC_TX_OFFS; - - if (freq == NG_AT86RF2XX_FREQ_915MHZ) { - dev->freq = NG_AT86RF2XX_FREQ_915MHZ; - /* settings used by Linux 4.0rc at86rf212b driver - BPSK-40*/ - tmp1 |= NG_AT86RF2XX_TRX_CTRL_2_MASK__SUB_MODE - | NG_AT86RF2XX_TRX_CTRL_2_MASK__OQPSK_SCRAM_EN; - tmp2 |= NG_AT86RF2XX_RF_CTRL_0_GC_TX_OFFS__2DB; - - if (dev->chan == 0) { - ng_at86rf2xx_set_chan(dev,NG_AT86RF2XX_DEFAULT_CHANNEL); - } else { - ng_at86rf2xx_set_chan(dev,dev->chan); - } - } else if (freq == NG_AT86RF2XX_FREQ_868MHZ) { - dev->freq = NG_AT86RF2XX_FREQ_868MHZ; - /* OQPSK-SIN-RC-100 IEEE802.15.4 for 868,3MHz */ - tmp1 |= NG_AT86RF2XX_TRX_CTRL_2_MASK__BPSK_OQPSK; - tmp2 |= NG_AT86RF2XX_RF_CTRL_0_GC_TX_OFFS__1DB; - - /* Channel = 0 for 868MHz means 868.3MHz, only one available */ - ng_at86rf2xx_set_chan(dev,0x00); - } else { - return; + rf_ctrl0 &= ~NG_AT86RF2XX_RF_CTRL_0_MASK__GC_TX_OFFS; + + trx_ctrl2 |= NG_AT86RF2XX_TRX_CTRL_2_MASK__SUB_MODE; + rf_ctrl0 |= NG_AT86RF2XX_RF_CTRL_0_GC_TX_OFFS__2DB; + + switch(freq) { + case NG_AT86RF2XX_FREQ_915MHZ: + if (dev->chan == 0) { + ng_at86rf2xx_set_chan(dev,NG_AT86RF2XX_DEFAULT_CHANNEL); + } else { + ng_at86rf2xx_set_chan(dev,dev->chan); + } + break; + + case NG_AT86RF2XX_FREQ_868MHZ: + /* Channel = 0 for 868MHz means 868.3MHz, only one available */ + ng_at86rf2xx_set_chan(dev,0x00); + break; + + default: + DEBUG("ng_at86rf2xx: Trying to set unknown frequency 0x%lx\n", + (unsigned long) freq); + return; } - ng_at86rf2xx_reg_write(dev, NG_AT86RF2XX_REG__TRX_CTRL_2, tmp1); - ng_at86rf2xx_reg_write(dev, NG_AT86RF2XX_REG__RF_CTRL_0, tmp2); + dev->freq = freq; + ng_at86rf2xx_reg_write(dev, NG_AT86RF2XX_REG__TRX_CTRL_2, trx_ctrl2); + ng_at86rf2xx_reg_write(dev, NG_AT86RF2XX_REG__RF_CTRL_0, rf_ctrl0); } #endif -- GitLab