diff options
Diffstat (limited to 'mpm/lib')
-rw-r--r-- | mpm/lib/mykonos/ad937x_ctrl.cpp | 22 | ||||
-rw-r--r-- | mpm/lib/mykonos/ad937x_device.cpp | 166 | ||||
-rw-r--r-- | mpm/lib/mykonos/ad937x_device.hpp | 9 |
3 files changed, 114 insertions, 83 deletions
diff --git a/mpm/lib/mykonos/ad937x_ctrl.cpp b/mpm/lib/mykonos/ad937x_ctrl.cpp index 2642e3858..1dd118e8b 100644 --- a/mpm/lib/mykonos/ad937x_ctrl.cpp +++ b/mpm/lib/mykonos/ad937x_ctrl.cpp @@ -19,7 +19,9 @@ #include "adi/mykonos.h" #include "mpm/ad937x/ad937x_ctrl.hpp" #include <mpm/exception.hpp> +#include "../../../host/include/uhd/utils/math.hpp" +#include <boost/format.hpp> #include <sstream> #include <set> #include <functional> @@ -482,8 +484,24 @@ public: virtual void set_master_clock_rate(const double rate) { std::lock_guard<std::mutex> lock(*spi_mutex); - // FIXME: Add check for valid rates - device.set_master_clock_rate(rate); + ad937x_device::mcr_t mcr; + if (uhd::math::frequencies_are_equal(rate, 122.88e6)) { + mcr = ad937x_device::MCR_122_88MHZ; + } + else if (uhd::math::frequencies_are_equal(rate, 125e6)) { + mcr = ad937x_device::MCR_125_00MHZ; + } + else if (uhd::math::frequencies_are_equal(rate, 153.6e6)) { + mcr = ad937x_device::MCR_153_60MHZ; + } + else { + throw mpm::value_error(boost::str( + boost::format("Requested invalid master clock rate: %f MHz") + % (rate / 1e6) + )); + } + + device.set_master_clock_rate(mcr); } virtual void set_enable_gain_pins(const std::string &which, bool enable) diff --git a/mpm/lib/mykonos/ad937x_device.cpp b/mpm/lib/mykonos/ad937x_device.cpp index a6abc9329..6f493902d 100644 --- a/mpm/lib/mykonos/ad937x_device.cpp +++ b/mpm/lib/mykonos/ad937x_device.cpp @@ -810,86 +810,92 @@ int16_t ad937x_device::get_temperature() } -void ad937x_device::set_master_clock_rate(const double rate) -{ - if (rate == 125000000) - { - mykonos_config.device->clocks->deviceClock_kHz = 125000; - mykonos_config.device->clocks->clkPllVcoFreq_kHz = 10000000; - mykonos_config.device->clocks->clkPllVcoDiv = ::VCODIV_2; - set_fir(TX_DIRECTION, - mykonos_config.device->tx->txProfile->txFir->gain_dB, - std::vector<int16_t>(ad937x_config_t::DEFAULT_TX_FIR, - ad937x_config_t::DEFAULT_TX_FIR + ad937x_config_t::DEFAULT_TX_FIR_SIZE) - ); - mykonos_config.device->tx->txProfile->iqRate_kHz = 125000; - mykonos_config.device->tx->txProfile->primarySigBandwidth_Hz = 20000000; - mykonos_config.device->tx->txProfile->rfBandwidth_Hz = 102000000; - mykonos_config.device->tx->txProfile->txDac3dBCorner_kHz = 722000; - mykonos_config.device->tx->txProfile->txBbf3dBCorner_kHz = 51000; - - set_fir(RX_DIRECTION, - mykonos_config.device->rx->rxProfile->rxFir->gain_dB, - std::vector<int16_t>(ad937x_config_t::DEFAULT_RX_FIR, - ad937x_config_t::DEFAULT_RX_FIR + ad937x_config_t::DEFAULT_RX_FIR_SIZE) - ); - - mykonos_config.device->rx->rxProfile->iqRate_kHz = 125000; - mykonos_config.device->rx->rxProfile->rxBbf3dBCorner_kHz = 102000; - - mykonos_config.device->obsRx->orxProfile->iqRate_kHz = 125000; - mykonos_config.device->obsRx->orxProfile->rxBbf3dBCorner_kHz = 102000; - } else if (rate == 122880000){ - mykonos_config.device->clocks->deviceClock_kHz = 122880; - mykonos_config.device->clocks->clkPllVcoFreq_kHz = 9830400; - mykonos_config.device->clocks->clkPllVcoDiv = ::VCODIV_2; - set_fir(TX_DIRECTION, - mykonos_config.device->tx->txProfile->txFir->gain_dB, - std::vector<int16_t>(ad937x_config_t::DEFAULT_TX_FIR, - ad937x_config_t::DEFAULT_TX_FIR + ad937x_config_t::DEFAULT_TX_FIR_SIZE) - ); - mykonos_config.device->tx->txProfile->iqRate_kHz = 122880; - mykonos_config.device->tx->txProfile->primarySigBandwidth_Hz = 20000000; - mykonos_config.device->tx->txProfile->rfBandwidth_Hz = 100000000; - mykonos_config.device->tx->txProfile->txDac3dBCorner_kHz = 710539; - mykonos_config.device->tx->txProfile->txBbf3dBCorner_kHz = 50000; - - set_fir(RX_DIRECTION, - mykonos_config.device->rx->rxProfile->rxFir->gain_dB, - std::vector<int16_t>(ad937x_config_t::DEFAULT_RX_FIR, - ad937x_config_t::DEFAULT_RX_FIR + ad937x_config_t::DEFAULT_RX_FIR_SIZE) - ); - mykonos_config.device->rx->rxProfile->iqRate_kHz = 122880; - mykonos_config.device->rx->rxProfile->rxBbf3dBCorner_kHz = 100000; - - mykonos_config.device->obsRx->orxProfile->iqRate_kHz = 122880; - mykonos_config.device->obsRx->orxProfile->rxBbf3dBCorner_kHz = 100000; - } else if (rate == 153660000){ - mykonos_config.device->clocks->deviceClock_kHz = 153600; - mykonos_config.device->clocks->clkPllVcoFreq_kHz = 6144000; - mykonos_config.device->clocks->clkPllVcoDiv = ::VCODIV_1; - set_fir(TX_DIRECTION, - mykonos_config.device->tx->txProfile->txFir->gain_dB, - std::vector<int16_t>(ad937x_config_t::DEFAULT_TX_FIR_15366, - ad937x_config_t::DEFAULT_TX_FIR_15366 + ad937x_config_t::DEFAULT_TX_FIR_SIZE) - ); - mykonos_config.device->tx->txProfile->iqRate_kHz = 153600; - mykonos_config.device->tx->txProfile->primarySigBandwidth_Hz = 10000000; - mykonos_config.device->tx->txProfile->rfBandwidth_Hz = 100000000; - mykonos_config.device->tx->txProfile->txDac3dBCorner_kHz = 100000; - mykonos_config.device->tx->txProfile->txBbf3dBCorner_kHz = 100000; - - set_fir(RX_DIRECTION, - mykonos_config.device->rx->rxProfile->rxFir->gain_dB, - std::vector<int16_t>(ad937x_config_t::DEFAULT_RX_FIR_15366, - ad937x_config_t::DEFAULT_RX_FIR_15366 + ad937x_config_t::DEFAULT_RX_FIR_SIZE) - ); - mykonos_config.device->rx->rxProfile->iqRate_kHz = 153600; - mykonos_config.device->rx->rxProfile->rxBbf3dBCorner_kHz = 100000; - - mykonos_config.device->obsRx->orxProfile->iqRate_kHz = 153600; - mykonos_config.device->obsRx->orxProfile->rxBbf3dBCorner_kHz = 225000; - } else { +void ad937x_device::set_master_clock_rate(const mcr_t rate) +{ + switch (rate) { + case MCR_125_00MHZ: { + mykonos_config.device->clocks->deviceClock_kHz = 125000; + mykonos_config.device->clocks->clkPllVcoFreq_kHz = 10000000; + mykonos_config.device->clocks->clkPllVcoDiv = ::VCODIV_2; + set_fir(TX_DIRECTION, + mykonos_config.device->tx->txProfile->txFir->gain_dB, + std::vector<int16_t>(ad937x_config_t::DEFAULT_TX_FIR, + ad937x_config_t::DEFAULT_TX_FIR + ad937x_config_t::DEFAULT_TX_FIR_SIZE) + ); + mykonos_config.device->tx->txProfile->iqRate_kHz = 125000; + mykonos_config.device->tx->txProfile->primarySigBandwidth_Hz = 20000000; + mykonos_config.device->tx->txProfile->rfBandwidth_Hz = 102000000; + mykonos_config.device->tx->txProfile->txDac3dBCorner_kHz = 722000; + mykonos_config.device->tx->txProfile->txBbf3dBCorner_kHz = 51000; + + set_fir(RX_DIRECTION, + mykonos_config.device->rx->rxProfile->rxFir->gain_dB, + std::vector<int16_t>(ad937x_config_t::DEFAULT_RX_FIR, + ad937x_config_t::DEFAULT_RX_FIR + ad937x_config_t::DEFAULT_RX_FIR_SIZE) + ); + + mykonos_config.device->rx->rxProfile->iqRate_kHz = 125000; + mykonos_config.device->rx->rxProfile->rxBbf3dBCorner_kHz = 102000; + + mykonos_config.device->obsRx->orxProfile->iqRate_kHz = 125000; + mykonos_config.device->obsRx->orxProfile->rxBbf3dBCorner_kHz = 102000; + break; + } + case MCR_122_88MHZ: { + mykonos_config.device->clocks->deviceClock_kHz = 122880; + mykonos_config.device->clocks->clkPllVcoFreq_kHz = 9830400; + mykonos_config.device->clocks->clkPllVcoDiv = ::VCODIV_2; + set_fir(TX_DIRECTION, + mykonos_config.device->tx->txProfile->txFir->gain_dB, + std::vector<int16_t>(ad937x_config_t::DEFAULT_TX_FIR, + ad937x_config_t::DEFAULT_TX_FIR + ad937x_config_t::DEFAULT_TX_FIR_SIZE) + ); + mykonos_config.device->tx->txProfile->iqRate_kHz = 122880; + mykonos_config.device->tx->txProfile->primarySigBandwidth_Hz = 20000000; + mykonos_config.device->tx->txProfile->rfBandwidth_Hz = 100000000; + mykonos_config.device->tx->txProfile->txDac3dBCorner_kHz = 710539; + mykonos_config.device->tx->txProfile->txBbf3dBCorner_kHz = 50000; + + set_fir(RX_DIRECTION, + mykonos_config.device->rx->rxProfile->rxFir->gain_dB, + std::vector<int16_t>(ad937x_config_t::DEFAULT_RX_FIR, + ad937x_config_t::DEFAULT_RX_FIR + ad937x_config_t::DEFAULT_RX_FIR_SIZE) + ); + mykonos_config.device->rx->rxProfile->iqRate_kHz = 122880; + mykonos_config.device->rx->rxProfile->rxBbf3dBCorner_kHz = 100000; + + mykonos_config.device->obsRx->orxProfile->iqRate_kHz = 122880; + mykonos_config.device->obsRx->orxProfile->rxBbf3dBCorner_kHz = 100000; + break; + } + case MCR_153_60MHZ: { + mykonos_config.device->clocks->deviceClock_kHz = 153600; + mykonos_config.device->clocks->clkPllVcoFreq_kHz = 6144000; + mykonos_config.device->clocks->clkPllVcoDiv = ::VCODIV_1; + set_fir(TX_DIRECTION, + mykonos_config.device->tx->txProfile->txFir->gain_dB, + std::vector<int16_t>(ad937x_config_t::DEFAULT_TX_FIR_15366, + ad937x_config_t::DEFAULT_TX_FIR_15366 + ad937x_config_t::DEFAULT_TX_FIR_SIZE) + ); + mykonos_config.device->tx->txProfile->iqRate_kHz = 153600; + mykonos_config.device->tx->txProfile->primarySigBandwidth_Hz = 10000000; + mykonos_config.device->tx->txProfile->rfBandwidth_Hz = 100000000; + mykonos_config.device->tx->txProfile->txDac3dBCorner_kHz = 100000; + mykonos_config.device->tx->txProfile->txBbf3dBCorner_kHz = 100000; + + set_fir(RX_DIRECTION, + mykonos_config.device->rx->rxProfile->rxFir->gain_dB, + std::vector<int16_t>(ad937x_config_t::DEFAULT_RX_FIR_15366, + ad937x_config_t::DEFAULT_RX_FIR_15366 + ad937x_config_t::DEFAULT_RX_FIR_SIZE) + ); + mykonos_config.device->rx->rxProfile->iqRate_kHz = 153600; + mykonos_config.device->rx->rxProfile->rxBbf3dBCorner_kHz = 100000; + + mykonos_config.device->obsRx->orxProfile->iqRate_kHz = 153600; + mykonos_config.device->obsRx->orxProfile->rxBbf3dBCorner_kHz = 225000; + break; + } + default: MPM_THROW_INVALID_CODE_PATH(); } } diff --git a/mpm/lib/mykonos/ad937x_device.hpp b/mpm/lib/mykonos/ad937x_device.hpp index 9abd2942b..059079475 100644 --- a/mpm/lib/mykonos/ad937x_device.hpp +++ b/mpm/lib/mykonos/ad937x_device.hpp @@ -47,6 +47,13 @@ public: CALPLL_SDM = 0x10, }; + enum mcr_t + { + MCR_122_88MHZ, + MCR_125_00MHZ, + MCR_153_60MHZ + }; + ad937x_device( mpm::types::regs_iface* iface, mpm::ad937x::gpio::gain_pins_t gain_pins @@ -97,7 +104,7 @@ public: void update_tx_lo_source(uint8_t rxPllUseExternalLo); uint8_t get_rx_lo_source(); uint8_t get_tx_lo_source(); - void set_master_clock_rate(const double rate); + void set_master_clock_rate(const mcr_t rate); const static double MIN_FREQ; const static double MAX_FREQ; const static double MIN_RX_GAIN; |