diff options
author | Martin Braun <martin.braun@ettus.com> | 2018-01-22 14:37:44 -0800 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2018-01-22 14:57:23 -0800 |
commit | 3b080f7ff547621ffe131f263034eac0ad8d2a40 (patch) | |
tree | 6b1bf0d4722eab4f9a68266caf648b3f04aea5f5 /mpm/lib/mykonos | |
parent | dee1d75339830b5d54971917ddc9dae2cd3dd6c8 (diff) | |
download | uhd-3b080f7ff547621ffe131f263034eac0ad8d2a40.tar.gz uhd-3b080f7ff547621ffe131f263034eac0ad8d2a40.tar.bz2 uhd-3b080f7ff547621ffe131f263034eac0ad8d2a40.zip |
mpm: ad937x: Refactor
- No functional changes
- const-ify parameters and local variables where appropriate
- Fix long lines and inconsistent formatting
Diffstat (limited to 'mpm/lib/mykonos')
-rw-r--r-- | mpm/lib/mykonos/ad937x_ctrl.cpp | 145 | ||||
-rw-r--r-- | mpm/lib/mykonos/ad937x_device.cpp | 165 | ||||
-rw-r--r-- | mpm/lib/mykonos/ad937x_device.hpp | 99 |
3 files changed, 271 insertions, 138 deletions
diff --git a/mpm/lib/mykonos/ad937x_ctrl.cpp b/mpm/lib/mykonos/ad937x_ctrl.cpp index ecb328fc8..63eef4314 100644 --- a/mpm/lib/mykonos/ad937x_ctrl.cpp +++ b/mpm/lib/mykonos/ad937x_ctrl.cpp @@ -16,6 +16,9 @@ #include <functional> #include <iostream> #include <algorithm> +#include <thread> +#include <chrono> + using namespace mpm::chips; using namespace mpm::ad937x::device; @@ -158,9 +161,17 @@ uhd::meta_range_t ad937x_ctrl::get_gain_range(const std::string &which) switch (dir) { case uhd::direction_t::RX_DIRECTION: - return uhd::meta_range_t(ad937x_device::MIN_RX_GAIN, ad937x_device::MAX_RX_GAIN, ad937x_device::RX_GAIN_STEP); + return uhd::meta_range_t( + ad937x_device::MIN_RX_GAIN, + ad937x_device::MAX_RX_GAIN, + ad937x_device::RX_GAIN_STEP + ); case uhd::direction_t::TX_DIRECTION: - return uhd::meta_range_t(ad937x_device::MIN_TX_GAIN, ad937x_device::MAX_TX_GAIN, ad937x_device::TX_GAIN_STEP); + return uhd::meta_range_t( + ad937x_device::MIN_TX_GAIN, + ad937x_device::MAX_TX_GAIN, + ad937x_device::TX_GAIN_STEP + ); default: MPM_THROW_INVALID_CODE_PATH(); return uhd::meta_range_t(); @@ -181,6 +192,7 @@ public: { /* nop */ } + virtual void begin_initialization() { std::lock_guard<std::mutex> lock(*spi_mutex); @@ -193,14 +205,20 @@ public: device.finish_initialization(); } - virtual void setup_cal(uint32_t init_cals_mask, uint32_t tracking_cals_mask, uint32_t timeout) - { + virtual void setup_cal( + const uint32_t init_cals_mask, + const uint32_t tracking_cals_mask, + const uint32_t timeout + ) { 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); + virtual std::string set_lo_source( + const std::string &which, + const std::string &source + ) { + const auto dir = _get_direction_from_antenna(which); uint8_t pll_source = 0 ; if (source == "internal"){ @@ -224,16 +242,16 @@ public: } } - virtual std::string get_lo_source(const std::string &which){ - auto dir = _get_direction_from_antenna(which); + virtual std::string get_lo_source(const std::string &which){ + const 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){ + } else if (retval == 1) { return "external"; - }else{ + } else { throw mpm::runtime_error("invalid return from get LO source"); } } @@ -286,7 +304,7 @@ public: return device.get_ilas_config_match(); } - virtual void enable_jesd_loopback(uint8_t enable) + virtual void enable_jesd_loopback(const uint8_t enable) { std::lock_guard<std::mutex> lock(*spi_mutex); device.enable_jesd_loopback(enable); @@ -300,13 +318,15 @@ public: virtual uint8_t get_device_rev() { + std::this_thread::sleep_for(std::chrono::seconds(4)); std::lock_guard<std::mutex> lock(*spi_mutex); return device.get_device_rev(); } + virtual std::string get_api_version() { std::lock_guard<std::mutex> lock(*spi_mutex); - auto api = device.get_api_version(); + const auto api = device.get_api_version(); std::ostringstream ss; ss << api.silicon_ver << "." << api.major_ver << "." @@ -319,7 +339,7 @@ public: virtual std::string get_arm_version() { std::lock_guard<std::mutex> lock(*spi_mutex); - auto arm = device.get_arm_version(); + const auto arm = device.get_arm_version(); std::ostringstream ss; ss << arm.major_ver << "." << arm.minor_ver << "." @@ -341,16 +361,16 @@ public: return ss.str(); } - virtual double set_bw_filter(const std::string &which, double value) + virtual double set_bw_filter(const std::string &which, const double value) { // TODO implement return double(); } - virtual double set_gain(const std::string &which, double value) + virtual double set_gain(const std::string &which, const double value) { - auto dir = _get_direction_from_antenna(which); - auto chain = _get_chain_from_antenna(which); + const auto dir = _get_direction_from_antenna(which); + const auto chain = _get_chain_from_antenna(which); std::lock_guard<std::mutex> lock(*spi_mutex); return device.set_gain(dir, chain, value); @@ -358,8 +378,8 @@ public: virtual double get_gain(const std::string &which) { - auto dir = _get_direction_from_antenna(which); - auto chain = _get_chain_from_antenna(which); + const auto dir = _get_direction_from_antenna(which); + const auto chain = _get_chain_from_antenna(which); std::lock_guard<std::mutex> lock(*spi_mutex); return device.get_gain(dir, chain); @@ -367,17 +387,18 @@ public: // TODO: does agc mode need to have a which parameter? // this affects all RX channels on the device - virtual void set_agc_mode(const std::string &which, const std::string &mode) - { - auto dir = _get_direction_from_antenna(which); + virtual void set_agc_mode( + const std::string &which, + const std::string &mode + ) { + const auto dir = _get_direction_from_antenna(which); if (dir != uhd::direction_t::RX_DIRECTION) { throw mpm::runtime_error("set_agc not valid for non-rx channels"); } ad937x_device::gain_mode_t gain_mode; - if (mode == "automatic") - { + if (mode == "automatic") { gain_mode = ad937x_device::gain_mode_t::AUTOMATIC; } else if (mode == "manual") { @@ -396,9 +417,8 @@ public: virtual double set_clock_rate(double value) { - auto rates = get_clock_rates(); - if (std::find(rates.cbegin(), rates.cend(), value) == rates.end()) - { + const auto rates = get_clock_rates(); + if (std::find(rates.cbegin(), rates.cend(), value) == rates.end()) { value = *(rates.cbegin()); } @@ -406,19 +426,22 @@ public: return device.set_clock_rate(value); } - virtual void enable_channel(const std::string &which, bool enable) + virtual void enable_channel(const std::string &which, const bool enable) { - auto dir = _get_direction_from_antenna(which); - auto chain = _get_chain_from_antenna(which); + const auto dir = _get_direction_from_antenna(which); + const auto chain = _get_chain_from_antenna(which); std::lock_guard<std::mutex> lock(*spi_mutex); return device.enable_channel(dir, chain, enable); } - virtual double set_freq(const std::string &which, double value, bool wait_for_lock) - { - auto dir = _get_direction_from_antenna(which); - auto clipped_value = get_rf_freq_range().clip(value); + virtual double set_freq( + const std::string &which, + const double value, + const bool wait_for_lock + ) { + const auto dir = _get_direction_from_antenna(which); + const auto clipped_value = get_rf_freq_range().clip(value); std::lock_guard<std::mutex> lock(*spi_mutex); return device.tune(dir, clipped_value, wait_for_lock); @@ -426,7 +449,7 @@ public: virtual double get_freq(const std::string &which) { - auto dir = _get_direction_from_antenna(which); + const auto dir = _get_direction_from_antenna(which); std::lock_guard<std::mutex> lock(*spi_mutex); return device.get_freq(dir); @@ -443,11 +466,14 @@ public: return device.get_pll_lock_status(pll_select); } - virtual void set_fir(const std::string &which, int8_t gain, const std::vector<int16_t> & fir) - { - auto dir = _get_direction_from_antenna(which); + virtual void set_fir( + const std::string &which, + const int8_t gain, + const std::vector<int16_t>& fir + ) { + const auto dir = _get_direction_from_antenna(which); + const auto lengths = _get_valid_fir_lengths(which); - auto lengths = _get_valid_fir_lengths(which); if (std::find(lengths.begin(), lengths.end(), fir.size()) == lengths.end()) { throw mpm::value_error("invalid filter length"); @@ -494,36 +520,39 @@ public: device.set_master_clock_rate(mcr); } - virtual void set_enable_gain_pins(const std::string &which, bool enable) - { - auto dir = _get_direction_from_antenna(which); - auto chain = _get_chain_from_antenna(which); + virtual void set_enable_gain_pins( + const std::string &which, + const bool enable + ) { + const auto dir = _get_direction_from_antenna(which); + const auto chain = _get_chain_from_antenna(which); std::lock_guard<std::mutex> lock(*spi_mutex); device.set_enable_gain_pins(dir, chain, enable); } - virtual void set_gain_pin_step_sizes(const std::string &which, double inc_step, double dec_step) - { - auto dir = _get_direction_from_antenna(which); - auto chain = _get_chain_from_antenna(which); + virtual void set_gain_pin_step_sizes( + const std::string &which, + double inc_step, + double dec_step + ) { + const auto dir = _get_direction_from_antenna(which); + const auto chain = _get_chain_from_antenna(which); - if (dir == uhd::RX_DIRECTION) - { + if (dir == uhd::RX_DIRECTION) { auto steps = _get_valid_rx_gain_steps(); inc_step = steps.clip(inc_step); dec_step = steps.clip(dec_step); } - else if (dir == uhd::TX_DIRECTION) - { + else if (dir == uhd::TX_DIRECTION) { auto steps = _get_valid_tx_gain_steps(); inc_step = steps.clip(inc_step); dec_step = steps.clip(dec_step); // double comparison here should be okay because of clipping - if (inc_step != dec_step) - { - throw mpm::value_error("TX gain increment and decrement steps must be equal"); + if (inc_step != dec_step) { + throw mpm::value_error( + "TX gain increment and decrement steps must be equal"); } } @@ -555,7 +584,11 @@ ad937x_ctrl::sptr ad937x_ctrl::make( mpm::types::regs_iface::sptr iface, mpm::ad937x::gpio::gain_pins_t gain_pins ) { - return std::make_shared<ad937x_ctrl_impl>(spi_mutex, deserializer_lane_xbar, iface, gain_pins); + return std::make_shared<ad937x_ctrl_impl>( + spi_mutex, + deserializer_lane_xbar, + iface, + gain_pins + ); } - diff --git a/mpm/lib/mykonos/ad937x_device.cpp b/mpm/lib/mykonos/ad937x_device.cpp index e6941b52d..885d45748 100644 --- a/mpm/lib/mykonos/ad937x_device.cpp +++ b/mpm/lib/mykonos/ad937x_device.cpp @@ -95,17 +95,19 @@ ad937x_device::radio_state_t ad937x_device::_move_to_config_state() // restores the state from before a call to _move_to_config_state // if ON, move to radioOn, otherwise this function is a no-op -void ad937x_device::_restore_from_config_state(const ad937x_device::radio_state_t state) -{ +void ad937x_device::_restore_from_config_state( + const ad937x_device::radio_state_t state +) { if (state == radio_state_t::ON) { start_radio(); } } -std::string ad937x_device::_get_arm_binary_path() +std::string ad937x_device::_get_arm_binary_path() const { - // TODO: possibly add more options here, for now it's always in /lib/firmware or we explode + // TODO: possibly add more options here, for now it's always in + // /lib/firmware or we explode return "/lib/firmware/adi/mykonos-m3.bin"; } @@ -113,10 +115,9 @@ std::vector<uint8_t> ad937x_device::_get_arm_binary() { const auto path = _get_arm_binary_path(); std::ifstream file(path, std::ios::binary); - if (!file.is_open()) - { - throw mpm::runtime_error("Could not open AD9371 ARM binary at path " + path); - return {}; + if (!file.is_open()) { + throw mpm::runtime_error( + "Could not open AD9371 ARM binary at path " + path); } // TODO: add check that opened file size is equal to ARM_BINARY_SIZE @@ -124,8 +125,8 @@ std::vector<uint8_t> ad937x_device::_get_arm_binary() file.read(reinterpret_cast<char*>(binary.data()), ARM_BINARY_SIZE); if (file.bad()) { - throw mpm::runtime_error("Error reading AD9371 ARM binary at path " + path); - return {}; + throw mpm::runtime_error( + "Error reading AD9371 ARM binary at path " + path); } return binary; } @@ -133,10 +134,10 @@ std::vector<uint8_t> ad937x_device::_get_arm_binary() void ad937x_device::_verify_product_id() { const uint8_t product_id = get_product_id(); - if (product_id != AD9371_PRODUCT_ID) - { + if (product_id != AD9371_PRODUCT_ID) { throw mpm::runtime_error(str( - boost::format("AD9371 product ID does not match expected ID! Read: %X Expected: %X") + boost::format("AD9371 product ID does not match expected ID! " + "Read: %X Expected: %X") % int(product_id) % int(AD9371_PRODUCT_ID) )); } @@ -144,19 +145,23 @@ void ad937x_device::_verify_product_id() void ad937x_device::_verify_multichip_sync_status(const multichip_sync_t mcs) { - const uint8_t status_expected = (mcs == multichip_sync_t::FULL) ? 0x0B : 0x0A; + const uint8_t status_expected = + (mcs == multichip_sync_t::FULL) ? 0x0B : 0x0A; const uint8_t status_mask = status_expected; // all 1s expected, mask is the same const uint8_t mcs_status = get_multichip_sync_status(); if ((mcs_status & status_mask) != status_expected) { - throw mpm::runtime_error(str(boost::format("Multichip sync failed! Read: %X Expected: %X") - % int(mcs_status) % int(status_expected))); + throw mpm::runtime_error(str( + boost::format("Multichip sync failed! Read: %X Expected: %X") + % int(mcs_status) % int(status_expected) + )); } } // RX Gain values are table entries given in mykonos_user.h -// An array of gain values is programmed at initialization, which the API will then use for its gain values +// An array of gain values is programmed at initialization, +// which the API will then use for its gain values // In general, Gain Value = (255 - Gain Table Index) uint8_t ad937x_device::_convert_rx_gain_to_mykonos(const double gain) { @@ -184,14 +189,15 @@ double ad937x_device::_convert_tx_gain_from_mykonos(const uint16_t gain) return (MAX_TX_GAIN - (static_cast<double>(gain) / 1e3)); } -void ad937x_device::_apply_gain_pins(const direction_t direction, const chain_t chain) -{ +void ad937x_device::_apply_gain_pins( + const direction_t direction, + const chain_t chain +) { // get this channels configuration const auto chan = gain_ctrl.config.at(direction).at(chain); // TX direction does not support different steps per direction - if (direction == TX_DIRECTION) - { + if (direction == TX_DIRECTION) { MPM_ASSERT_THROW(chan.inc_step == chan.dec_step); } @@ -293,22 +299,30 @@ void ad937x_device::_setup_rf(){ } -void ad937x_device::setup_cal(uint32_t init_cals_mask, uint32_t tracking_cals_mask, uint32_t timeout){ +void ad937x_device::setup_cal( + const uint32_t init_cals_mask, + const uint32_t tracking_cals_mask, + const uint32_t timeout +) { // Run and wait for init cals CALL_API(MYKONOS_runInitCals(mykonos_config.device, init_cals_mask)); uint8_t errorFlag = 0, errorCode = 0; - CALL_API(MYKONOS_waitInitCals(mykonos_config.device, timeout, &errorFlag, &errorCode)); + CALL_API(MYKONOS_waitInitCals(mykonos_config.device, + timeout, &errorFlag, &errorCode)); - if ((errorFlag != 0) || (errorCode != 0)) - { + if ((errorFlag != 0) || (errorCode != 0)) { throw mpm::runtime_error("Init cals failed!"); // TODO: add more debugging information here } - CALL_API(MYKONOS_enableTrackingCals(mykonos_config.device, tracking_cals_mask)); + CALL_API(MYKONOS_enableTrackingCals(mykonos_config.device, + tracking_cals_mask)); // ready for radioOn } -uint8_t ad937x_device::set_lo_source(const uhd::direction_t direction, const uint8_t pll_source){ +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; @@ -476,7 +490,6 @@ arm_version_t ad937x_device::get_arm_version() } - /****************************************************** Set configuration functions ******************************************************/ @@ -500,8 +513,11 @@ double ad937x_device::set_clock_rate(const double req_rate) return static_cast<double>(rate); } -void ad937x_device::enable_channel(const direction_t direction, const chain_t chain, const bool enable) -{ +void ad937x_device::enable_channel( + const direction_t direction, + const chain_t chain, + const bool enable +) { // TODO: // Turns out the only code in the API that actually sets the channel enable settings // is _initialize(). Need to figure out how to deal with this. @@ -510,8 +526,11 @@ void ad937x_device::enable_channel(const direction_t direction, const chain_t ch // always use the GPIO pins to do so. Delete this function at a later time. } -double ad937x_device::tune(const direction_t direction, const double value, const bool wait_for_lock = false) -{ +double ad937x_device::tune( + const direction_t direction, + const double value, + const bool wait_for_lock = false +) { // I'm not sure why we set the PLL value in the config AND as a function parameter // but here it is @@ -551,15 +570,21 @@ double ad937x_device::tune(const direction_t direction, const double value, cons return get_freq(direction); } -double ad937x_device::set_bw_filter(const direction_t direction, const chain_t chain, const double value) -{ +double ad937x_device::set_bw_filter( + const direction_t direction, + const chain_t chain, + const double value +) { // TODO: implement return double(); } -double ad937x_device::set_gain(const direction_t direction, const chain_t chain, const double value) -{ +double ad937x_device::set_gain( + const direction_t direction, + const chain_t chain, + const double value +) { double coerced_value; const auto state = _move_to_config_state(); switch (direction) @@ -612,8 +637,10 @@ double ad937x_device::set_gain(const direction_t direction, const chain_t chain, return get_gain(direction, chain); } -void ad937x_device::set_agc_mode(const direction_t direction, const gain_mode_t mode) -{ +void ad937x_device::set_agc_mode( + const direction_t direction, + const gain_mode_t mode +) { mykonosGainMode_t mykonos_mode; switch (direction) { @@ -662,17 +689,25 @@ void ad937x_device::set_fir( // TODO: reload this on device } -void ad937x_device::set_gain_pin_step_sizes(const direction_t direction, const chain_t chain, const double inc_step, const double dec_step) -{ +void ad937x_device::set_gain_pin_step_sizes( + const direction_t direction, + const chain_t chain, + const double inc_step, + const double dec_step +) { if (direction == RX_DIRECTION) { - gain_ctrl.config.at(direction).at(chain).inc_step = static_cast<uint8_t>(inc_step / 0.5); - gain_ctrl.config.at(direction).at(chain).dec_step = static_cast<uint8_t>(dec_step / 0.5); + gain_ctrl.config.at(direction).at(chain).inc_step = + static_cast<uint8_t>(inc_step / 0.5); + gain_ctrl.config.at(direction).at(chain).dec_step = + static_cast<uint8_t>(dec_step / 0.5); } else if (direction == TX_DIRECTION) { // !!! TX is attenuation direction, so the pins are flipped !!! - gain_ctrl.config.at(direction).at(chain).dec_step = static_cast<uint8_t>(inc_step / 0.05); - gain_ctrl.config.at(direction).at(chain).inc_step = static_cast<uint8_t>(dec_step / 0.05); + gain_ctrl.config.at(direction).at(chain).dec_step = + static_cast<uint8_t>(inc_step / 0.05); + gain_ctrl.config.at(direction).at(chain).inc_step = + static_cast<uint8_t>(dec_step / 0.05); } else { MPM_THROW_INVALID_CODE_PATH(); @@ -680,8 +715,11 @@ void ad937x_device::set_gain_pin_step_sizes(const direction_t direction, const c _apply_gain_pins(direction, chain); } -void ad937x_device::set_enable_gain_pins(const direction_t direction, const chain_t chain, const bool enable) -{ +void ad937x_device::set_enable_gain_pins( + const direction_t direction, + const chain_t chain, + const bool enable +) { gain_ctrl.config.at(direction).at(chain).enable = enable; _apply_gain_pins(direction, chain); } @@ -691,7 +729,6 @@ void ad937x_device::set_enable_gain_pins(const direction_t direction, const chai /****************************************************** Get configuration functions ******************************************************/ - double ad937x_device::get_freq(const direction_t direction) { mykonosRfPllName_t pll; @@ -709,8 +746,10 @@ double ad937x_device::get_freq(const direction_t direction) return static_cast<double>(coerced_pll); } -bool ad937x_device::get_pll_lock_status(const uint8_t pll, const bool wait_for_lock) -{ +bool ad937x_device::get_pll_lock_status( + const uint8_t pll, + const bool wait_for_lock +) { uint8_t pll_status; CALL_API(MYKONOS_checkPllsLockStatus(mykonos_config.device, &pll_status)); @@ -719,7 +758,9 @@ bool ad937x_device::get_pll_lock_status(const uint8_t pll, const bool wait_for_l return (pll_status & pll) == pll; } else { - const auto lock_time = std::chrono::steady_clock::now() + std::chrono::milliseconds(PLL_LOCK_TIMEOUT_MS); + const auto lock_time = + std::chrono::steady_clock::now() + + std::chrono::milliseconds(PLL_LOCK_TIMEOUT_MS); bool locked = false; while (not locked and lock_time > std::chrono::steady_clock::now()) { @@ -735,8 +776,10 @@ bool ad937x_device::get_pll_lock_status(const uint8_t pll, const bool wait_for_l } } -double ad937x_device::get_gain(const direction_t direction, const chain_t chain) -{ +double ad937x_device::get_gain( + const direction_t direction, + const chain_t chain +) { switch (direction) { case TX_DIRECTION: @@ -810,7 +853,8 @@ void ad937x_device::set_master_clock_rate(const mcr_t rate) 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) + 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; @@ -821,7 +865,8 @@ void ad937x_device::set_master_clock_rate(const mcr_t rate) 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) + ad937x_config_t::DEFAULT_RX_FIR + + ad937x_config_t::DEFAULT_RX_FIR_SIZE) ); mykonos_config.device->rx->rxProfile->iqRate_kHz = 125000; @@ -838,7 +883,8 @@ void ad937x_device::set_master_clock_rate(const mcr_t rate) 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) + 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; @@ -849,7 +895,8 @@ void ad937x_device::set_master_clock_rate(const mcr_t rate) 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) + 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; @@ -865,7 +912,8 @@ void ad937x_device::set_master_clock_rate(const mcr_t rate) 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) + 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; @@ -876,7 +924,8 @@ void ad937x_device::set_master_clock_rate(const mcr_t rate) 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) + 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; diff --git a/mpm/lib/mykonos/ad937x_device.hpp b/mpm/lib/mykonos/ad937x_device.hpp index 26bb01685..b0f843d39 100644 --- a/mpm/lib/mykonos/ad937x_device.hpp +++ b/mpm/lib/mykonos/ad937x_device.hpp @@ -1,5 +1,5 @@ // -// Copyright 2017 Ettus Research, National Instruments Company +// Copyright 2017-2018 Ettus Research, National Instruments Company // // SPDX-License-Identifier: GPL-3.0 // @@ -51,8 +51,15 @@ 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); + void setup_cal( + const uint32_t init_cals_mask, + const uint32_t tracking_cals_mask, + const 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(); @@ -63,33 +70,74 @@ public: uint8_t get_framer_status(); uint8_t get_deframer_status(); uint16_t get_ilas_config_match(); - void enable_jesd_loopback(uint8_t enable); + void enable_jesd_loopback(const uint8_t enable); uint8_t get_product_id(); uint8_t get_device_rev(); mpm::ad937x::device::api_version_t get_api_version(); mpm::ad937x::device::arm_version_t get_arm_version(); - double set_bw_filter(uhd::direction_t direction, mpm::ad937x::device::chain_t chain, double value); - void set_agc_mode(uhd::direction_t direction, gain_mode_t mode); - double set_clock_rate(double value); - void enable_channel(uhd::direction_t direction, mpm::ad937x::device::chain_t chain, bool enable); + double set_bw_filter( + const uhd::direction_t direction, + const mpm::ad937x::device::chain_t chain, + const double value + ); + void set_agc_mode( + const uhd::direction_t direction, + const gain_mode_t mode + ); + double set_clock_rate(const double value); + void enable_channel( + const uhd::direction_t direction, + const mpm::ad937x::device::chain_t chain, + const bool enable + ); - double set_gain(uhd::direction_t direction, mpm::ad937x::device::chain_t chain, double value); - double get_gain(uhd::direction_t direction, mpm::ad937x::device::chain_t chain); + double set_gain( + const uhd::direction_t direction, + const mpm::ad937x::device::chain_t chain, + const double value + ); + double get_gain( + const uhd::direction_t direction, + const mpm::ad937x::device::chain_t chain + ); - double tune(uhd::direction_t direction, double value, bool wait_for_lock); - double get_freq(uhd::direction_t direction); + double tune( + const uhd::direction_t direction, + const double value, + const bool wait_for_lock + ); + double get_freq(const uhd::direction_t direction); - bool get_pll_lock_status(uint8_t pll, bool wait_for_lock = false); + bool get_pll_lock_status( + const uint8_t pll, + const bool wait_for_lock=false + ); - void set_fir(uhd::direction_t direction, int8_t gain, const std::vector<int16_t> & fir); - std::vector<int16_t> get_fir(uhd::direction_t direction, int8_t &gain); + void set_fir( + const uhd::direction_t direction, + int8_t gain, + const std::vector<int16_t>& fir + ); + std::vector<int16_t> get_fir( + const uhd::direction_t direction, + int8_t &gain + ); int16_t get_temperature(); - void set_enable_gain_pins(uhd::direction_t direction, mpm::ad937x::device::chain_t chain, bool enable); - void set_gain_pin_step_sizes(uhd::direction_t direction, mpm::ad937x::device::chain_t chain, double inc_step, double dec_step); + void set_enable_gain_pins( + const uhd::direction_t direction, + const mpm::ad937x::device::chain_t chain, + const bool enable + ); + void set_gain_pin_step_sizes( + const uhd::direction_t direction, + const mpm::ad937x::device::chain_t chain, + const double inc_step, + const double dec_step + ); void update_rx_lo_source(uint8_t rxPllUseExternalLo); void update_tx_lo_source(uint8_t rxPllUseExternalLo); uint8_t get_rx_lo_source(); @@ -112,22 +160,25 @@ private: ad937x_config_t mykonos_config; ad937x_gain_ctrl_config_t gain_ctrl; - void _apply_gain_pins(uhd::direction_t direction, mpm::ad937x::device::chain_t chain); + void _apply_gain_pins( + const uhd::direction_t direction, + mpm::ad937x::device::chain_t chain + ); void _setup_rf(); void _call_api_function(const std::function<mykonosErr_t()>& func); void _call_gpio_api_function(const std::function<mykonosGpioErr_t()>& func); - std::string _get_arm_binary_path(); + std::string _get_arm_binary_path() const; std::vector<uint8_t> _get_arm_binary(); void _verify_product_id(); - void _verify_multichip_sync_status(multichip_sync_t mcs); + void _verify_multichip_sync_status(const multichip_sync_t mcs); radio_state_t _move_to_config_state(); void _restore_from_config_state(radio_state_t state); - static uint8_t _convert_rx_gain_to_mykonos(double gain); - static double _convert_rx_gain_from_mykonos(uint8_t gain); - static uint16_t _convert_tx_gain_to_mykonos(double gain); - static double _convert_tx_gain_from_mykonos(uint16_t gain); + static uint8_t _convert_rx_gain_to_mykonos(const double gain); + static double _convert_rx_gain_from_mykonos(const uint8_t gain); + static uint16_t _convert_tx_gain_to_mykonos(const double gain); + static double _convert_tx_gain_from_mykonos(const uint16_t gain); }; |