diff options
-rw-r--r-- | mpm/include/mpm/ad937x/ad937x_ctrl.hpp | 19 | ||||
-rw-r--r-- | mpm/lib/mykonos/ad937x_ctrl.cpp | 57 | ||||
-rw-r--r-- | mpm/lib/mykonos/ad937x_device.cpp | 37 | ||||
-rw-r--r-- | mpm/lib/mykonos/ad937x_device.hpp | 2 | ||||
-rw-r--r-- | mpm/lib/mykonos/config/ad937x_config_t.cpp | 13 | ||||
-rw-r--r-- | mpm/lib/mykonos/config/ad937x_config_t.hpp | 6 | ||||
-rw-r--r-- | mpm/python/usrp_mpm/dboard_manager/magnesium.py | 30 |
7 files changed, 93 insertions, 71 deletions
diff --git a/mpm/include/mpm/ad937x/ad937x_ctrl.hpp b/mpm/include/mpm/ad937x/ad937x_ctrl.hpp index 198e4e2d8..0dfcaa3c7 100644 --- a/mpm/include/mpm/ad937x/ad937x_ctrl.hpp +++ b/mpm/include/mpm/ad937x/ad937x_ctrl.hpp @@ -107,14 +107,6 @@ public: mpm::ad937x::gpio::gain_pins_t gain_pins); virtual ~ad937x_ctrl(void) {} - //! Update rx lo source to either external or internal. 1 is external; 0 is internal - virtual void update_rx_lo_source(uint8_t rx_pll_use_external_lo) = 0; - //! Update tx lo source to either external or internal. 1 is external; 0 is internal - virtual void update_tx_lo_source(uint8_t tx_pll_use_external_lo) = 0; - //! Get rx lo source: 1 is external; 0 is internal - virtual uint8_t get_rx_lo_source() = 0 ; - //! Get tx lo source: 1 is external; 0 is internal - virtual uint8_t get_tx_lo_source() = 0 ; //! initializes the AD9371, checks basic functionality, and prepares the chip to receive a SYSREF pulse virtual void begin_initialization() = 0; @@ -129,6 +121,11 @@ public: *\param timeout init calibration timeout. default to 10s */ virtual void setup_cal(uint32_t init_cals_mask, uint32_t tracking_cals_mask, uint32_t timeout) = 0; + + //! set LO source + virtual std::string set_lo_source(const std::string &which, const std::string &source) = 0; + //! get LO source + virtual std::string get_lo_source(const std::string &which) = 0; //! resets and start the JESD deframer (JESD Rx, for RF Tx) virtual void start_jesd_rx() = 0; @@ -283,10 +280,8 @@ void export_mykonos(){ .def("set_master_clock_rate", &ad937x_ctrl::set_master_clock_rate) .def("begin_initialization", &ad937x_ctrl::begin_initialization) .def("finish_initialization", &ad937x_ctrl::finish_initialization) - .def("update_rx_lo_source", &ad937x_ctrl::update_rx_lo_source) - .def("update_tx_lo_source", &ad937x_ctrl::update_tx_lo_source) - .def("get_rx_lo_source", &ad937x_ctrl::get_rx_lo_source) - .def("get_tx_lo_source", &ad937x_ctrl::get_tx_lo_source) + .def("set_lo_source", &ad937x_ctrl::set_lo_source) + .def("get_lo_source", &ad937x_ctrl::get_lo_source) .def("setup_cal", &ad937x_ctrl::setup_cal) .def("start_jesd_rx", &ad937x_ctrl::start_jesd_rx) .def("start_jesd_tx", &ad937x_ctrl::start_jesd_tx) diff --git a/mpm/lib/mykonos/ad937x_ctrl.cpp b/mpm/lib/mykonos/ad937x_ctrl.cpp index d6062c228..2642e3858 100644 --- a/mpm/lib/mykonos/ad937x_ctrl.cpp +++ b/mpm/lib/mykonos/ad937x_ctrl.cpp @@ -189,23 +189,6 @@ public: { /* nop */ } - virtual void update_rx_lo_source(uint8_t rx_lo_source){ - std::lock_guard<std::mutex> lock(*spi_mutex); - device.update_rx_lo_source(rx_lo_source); - } - virtual void update_tx_lo_source(uint8_t tx_lo_source){ - std::lock_guard<std::mutex> lock(*spi_mutex); - device.update_tx_lo_source(tx_lo_source); - } - - virtual uint8_t get_rx_lo_source(){ - std::lock_guard<std::mutex> lock(*spi_mutex); - return device.get_rx_lo_source(); - } - virtual uint8_t get_tx_lo_source(){ - std::lock_guard<std::mutex> lock(*spi_mutex); - return device.get_tx_lo_source(); - } virtual void begin_initialization() { std::lock_guard<std::mutex> lock(*spi_mutex); @@ -223,6 +206,46 @@ public: std::lock_guard<std::mutex> lock(*spi_mutex); device.setup_cal(init_cals_mask, tracking_cals_mask, timeout); } + + virtual std::string set_lo_source(const std::string &which, const std::string &source){ + auto dir = _get_direction_from_antenna(which); + + uint8_t pll_source = 0 ; + if (source == "internal"){ + pll_source = 0; + } + else if (source == "external") { + pll_source = 1; + } + else { + throw mpm::runtime_error("invalid LO source"); + } + + std::lock_guard<std::mutex> lock(*spi_mutex); + uint8_t retval = device.set_lo_source(dir, pll_source); + if (retval == 0){ + return "internal"; + } else if (retval == 1){ + return "external"; + }else{ + throw mpm::runtime_error("invalid return from set LO source"); + } + } + + virtual std::string get_lo_source(const std::string &which){ + auto dir = _get_direction_from_antenna(which); + + std::lock_guard<std::mutex> lock(*spi_mutex); + uint8_t retval = device.get_lo_source(dir); + if (retval == 0){ + return "internal"; + } else if (retval == 1){ + return "external"; + }else{ + throw mpm::runtime_error("invalid return from get LO source"); + } + } + virtual void start_jesd_rx() { std::lock_guard<std::mutex> lock(*spi_mutex); diff --git a/mpm/lib/mykonos/ad937x_device.cpp b/mpm/lib/mykonos/ad937x_device.cpp index 1d4a80c48..a6abc9329 100644 --- a/mpm/lib/mykonos/ad937x_device.cpp +++ b/mpm/lib/mykonos/ad937x_device.cpp @@ -274,20 +274,6 @@ ad937x_device::ad937x_device( gain_ctrl(gain_pins) { } -void ad937x_device::update_rx_lo_source(uint8_t rx_lo_source){ - mykonos_config.set_rx_pll_use_external_lo(rx_lo_source); - //TODO: should we re-init after this ? -} -void ad937x_device::update_tx_lo_source(uint8_t tx_lo_source){ - mykonos_config.set_tx_pll_use_external_lo(tx_lo_source); - //TODO: should we re-init after this ? -} -uint8_t ad937x_device::get_rx_lo_source(){ - return mykonos_config.get_rx_pll_use_external_lo(); -} -uint8_t ad937x_device::get_tx_lo_source(){ - return mykonos_config.get_tx_pll_use_external_lo(); -} void ad937x_device::_setup_rf(){ // TODO: add setRfPllLoopFilter here @@ -332,6 +318,29 @@ void ad937x_device::setup_cal(uint32_t init_cals_mask, uint32_t tracking_cals_ma // ready for radioOn } +uint8_t ad937x_device::set_lo_source(const uhd::direction_t direction, const uint8_t pll_source){ + switch (direction){ + case TX_DIRECTION: + mykonos_config.device->tx->txPllUseExternalLo = pll_source; + return pll_source; + case RX_DIRECTION: + mykonos_config.device->rx->rxPllUseExternalLo = pll_source; + return pll_source; + default: + MPM_THROW_INVALID_CODE_PATH(); + } +} + +uint8_t ad937x_device::get_lo_source(const uhd::direction_t direction) const { + switch (direction){ + case TX_DIRECTION: + return mykonos_config.device->tx->txPllUseExternalLo; + case RX_DIRECTION: + return mykonos_config.device->rx->rxPllUseExternalLo; + default: + MPM_THROW_INVALID_CODE_PATH(); + } +} void ad937x_device::begin_initialization() { CALL_API(MYKONOS_initialize(mykonos_config.device)); diff --git a/mpm/lib/mykonos/ad937x_device.hpp b/mpm/lib/mykonos/ad937x_device.hpp index 60f78d2e5..9abd2942b 100644 --- a/mpm/lib/mykonos/ad937x_device.hpp +++ b/mpm/lib/mykonos/ad937x_device.hpp @@ -55,6 +55,8 @@ public: void begin_initialization(); void finish_initialization(); void setup_cal(uint32_t init_cals_mask, uint32_t tracking_cals_mask, uint32_t timeout); + uint8_t set_lo_source(const uhd::direction_t direction, const uint8_t pll_source); + uint8_t get_lo_source(const uhd::direction_t direction) const; void start_jesd_rx(); void start_jesd_tx(); void start_radio(); diff --git a/mpm/lib/mykonos/config/ad937x_config_t.cpp b/mpm/lib/mykonos/config/ad937x_config_t.cpp index a9455502c..595fda925 100644 --- a/mpm/lib/mykonos/config/ad937x_config_t.cpp +++ b/mpm/lib/mykonos/config/ad937x_config_t.cpp @@ -105,18 +105,7 @@ ad937x_config_t::ad937x_config_t(spiSettings_t* sps) : device = &_device; } -void ad937x_config_t::set_rx_pll_use_external_lo(uint8_t val){ - _rx.rxPllUseExternalLo = val; -} -uint8_t ad937x_config_t::get_rx_pll_use_external_lo(){ - return _rx.rxPllUseExternalLo; -} -void ad937x_config_t::set_tx_pll_use_external_lo(uint8_t val){ - _tx.txPllUseExternalLo = val; -} -uint8_t ad937x_config_t::get_tx_pll_use_external_lo(){ - return _tx.txPllUseExternalLo; -} + // This function sets up all the pointers in all of our local members that represent the device struct // This function should only be called during construction. void ad937x_config_t::_init_pointers() diff --git a/mpm/lib/mykonos/config/ad937x_config_t.hpp b/mpm/lib/mykonos/config/ad937x_config_t.hpp index 41d9e9b61..bbd80cc28 100644 --- a/mpm/lib/mykonos/config/ad937x_config_t.hpp +++ b/mpm/lib/mykonos/config/ad937x_config_t.hpp @@ -43,11 +43,7 @@ public: static const int16_t DEFAULT_OBSRX_FIR[DEFAULT_RX_FIR_SIZE]; static const int16_t DEFAULT_OBSRX_FIR_15366[DEFAULT_RX_FIR_SIZE]; static const int16_t DEFAULT_SNIFFER_FIR[DEFAULT_RX_FIR_SIZE]; - static const int16_t DEFAULT_SNIFFER_FIR_15366[DEFAULT_RX_FIR_SIZE]; - void set_rx_pll_use_external_lo(uint8_t val); - uint8_t get_rx_pll_use_external_lo(); - void set_tx_pll_use_external_lo(uint8_t val); - uint8_t get_tx_pll_use_external_lo(); + static const int16_t DEFAULT_SNIFFER_FIR_15366[DEFAULT_RX_FIR_SIZE]; private: // The top level device struct is non-const and contains all other structs, so everything is "public" diff --git a/mpm/python/usrp_mpm/dboard_manager/magnesium.py b/mpm/python/usrp_mpm/dboard_manager/magnesium.py index b11712303..fdcaea0de 100644 --- a/mpm/python/usrp_mpm/dboard_manager/magnesium.py +++ b/mpm/python/usrp_mpm/dboard_manager/magnesium.py @@ -597,6 +597,24 @@ class Magnesium(DboardManagerBase): self.log.debug("args[tracking_cals]=0x{:02X}".format(self._tracking_cals_mask)) self.mykonos.setup_cal(self._init_cals_mask, self._tracking_cals_mask, self._init_cals_timeout) + def init_lo_source(self, args): + """Set all LO + + This function will initialize all LO to user specified sources. + If there's no source is specified, the default one will be used. + + Arguments: + args {string:string} -- device arguments. + """ + + self.log.info("Setting up LO source..") + rx_lo_source = args.get("rx_lo_source", "internal") + tx_lo_source = args.get("tx_lo_source", "internal") + self.mykonos.set_lo_source("RX", rx_lo_source) + self.mykonos.set_lo_source("TX", tx_lo_source) + self.log.debug("RX LO source is set at {}".format(self.mykonos.get_lo_source("RX"))) + self.log.debug("TX LO source is set at {}".format(self.mykonos.get_lo_source("TX"))) + def init_jesd(self, jesdcore, args): """ Bring up the JESD link between Mykonos and the N310. @@ -608,17 +626,7 @@ class Magnesium(DboardManagerBase): self.log.trace("Pulsing Mykonos Hard Reset...") self.cpld.reset_mykonos() self.log.trace("Initializing Mykonos...") - rx_lo_source = args.get('rx_lo_source', "internal") - rx_lo = -1 - if rx_lo_source == "internal": - rx_lo = 0 - if rx_lo_source == "external": - rx_lo = 1 - if rx_lo == -1: - self.log.warning("Please specify rx LO either \"internal\" or \"external\" ") - else: - self.mykonos.update_rx_lo_source(rx_lo) - self.log.debug("RX LO SOURCE is {}".format(self.mykonos.get_rx_lo_source())) + self.init_lo_source(args) self.mykonos.begin_initialization() # Multi-chip Sync requires two SYSREF pulses at least 17us apart. jesdcore.send_sysref_pulse() |