From 967be2a4e82b1a125b26bb72a60318a4fb2b50c4 Mon Sep 17 00:00:00 2001 From: Brent Stapleton Date: Mon, 14 Jan 2019 10:35:25 -0800 Subject: uhd: mpm: apply clang-format to all files Applying formatting changes to all .cpp and .hpp files in the following directories: ``` find host/examples/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find host/tests/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find host/lib/usrp/dboard/neon/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find host/lib/usrp/dboard/magnesium/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find host/lib/usrp/device3/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find host/lib/usrp/mpmd/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find host/lib/usrp/x300/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find host/utils/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find mpm/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file ``` Also formatted host/include/, except Cpp03 was used as a the language standard instead of Cpp11. ``` sed -i 's/ Cpp11/ Cpp03/g' .clang-format find host/include/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file ``` Formatting style was designated by the .clang-format file. --- mpm/lib/mykonos/ad937x_ctrl.cpp | 342 +++++++++++++++++----------------------- 1 file changed, 142 insertions(+), 200 deletions(-) (limited to 'mpm/lib/mykonos/ad937x_ctrl.cpp') diff --git a/mpm/lib/mykonos/ad937x_ctrl.cpp b/mpm/lib/mykonos/ad937x_ctrl.cpp index efb39c972..f4abae7a7 100644 --- a/mpm/lib/mykonos/ad937x_ctrl.cpp +++ b/mpm/lib/mykonos/ad937x_ctrl.cpp @@ -4,25 +4,24 @@ // SPDX-License-Identifier: GPL-3.0-or-later // +#include "mpm/ad937x/ad937x_ctrl.hpp" +#include "../../../host/include/uhd/utils/math.hpp" #include "ad937x_device.hpp" #include "adi/mykonos.h" -#include "mpm/ad937x/ad937x_ctrl.hpp" #include -#include "../../../host/include/uhd/utils/math.hpp" - #include -#include -#include +#include +#include #include #include -#include +#include +#include #include -#include using namespace mpm::chips; using namespace mpm::ad937x::device; -//Init cals mask +// Init cals mask const uint32_t ad937x_ctrl::TX_BB_FILTER = ::TX_BB_FILTER; const uint32_t ad937x_ctrl::ADC_TUNER = ::ADC_TUNER; const uint32_t ad937x_ctrl::TIA_3DB_CORNER = ::TIA_3DB_CORNER; @@ -41,55 +40,42 @@ const uint32_t ad937x_ctrl::RX_QEC_INIT = ::RX_QEC_INIT; const uint32_t ad937x_ctrl::DPD_INIT = ::DPD_INIT; const uint32_t ad937x_ctrl::CLGC_INIT = ::CLGC_INIT; const uint32_t ad937x_ctrl::VSWR_INIT = ::VSWR_INIT; -//Tracking Cals mask -const uint32_t ad937x_ctrl::TRACK_RX1_QEC = ::TRACK_RX1_QEC; -const uint32_t ad937x_ctrl::TRACK_RX2_QEC = ::TRACK_RX2_QEC; -const uint32_t ad937x_ctrl::TRACK_ORX1_QEC = ::TRACK_ORX1_QEC; -const uint32_t ad937x_ctrl::TRACK_ORX2_QEC = ::TRACK_ORX2_QEC; -const uint32_t ad937x_ctrl::TRACK_TX1_LOL = ::TRACK_TX1_LOL; -const uint32_t ad937x_ctrl::TRACK_TX2_LOL = ::TRACK_TX2_LOL; -const uint32_t ad937x_ctrl::TRACK_TX1_QEC = ::TRACK_TX1_QEC; -const uint32_t ad937x_ctrl::TRACK_TX2_QEC = ::TRACK_TX2_QEC; -const uint32_t ad937x_ctrl::TRACK_TX1_DPD = ::TRACK_TX1_DPD; -const uint32_t ad937x_ctrl::TRACK_TX2_DPD = ::TRACK_TX2_DPD; -const uint32_t ad937x_ctrl::TRACK_TX1_CLGC = ::TRACK_TX1_CLGC; -const uint32_t ad937x_ctrl::TRACK_TX2_CLGC = ::TRACK_TX2_CLGC; -const uint32_t ad937x_ctrl::TRACK_TX1_VSWR = ::TRACK_TX1_VSWR; -const uint32_t ad937x_ctrl::TRACK_TX2_VSWR = ::TRACK_TX2_VSWR; -const uint32_t ad937x_ctrl::TRACK_ORX1_QEC_SNLO = ::TRACK_ORX1_QEC_SNLO; -const uint32_t ad937x_ctrl::TRACK_ORX2_QEC_SNLO = ::TRACK_ORX2_QEC_SNLO; -const uint32_t ad937x_ctrl::TRACK_SRX_QEC = ::TRACK_SRX_QEC; +// Tracking Cals mask +const uint32_t ad937x_ctrl::TRACK_RX1_QEC = ::TRACK_RX1_QEC; +const uint32_t ad937x_ctrl::TRACK_RX2_QEC = ::TRACK_RX2_QEC; +const uint32_t ad937x_ctrl::TRACK_ORX1_QEC = ::TRACK_ORX1_QEC; +const uint32_t ad937x_ctrl::TRACK_ORX2_QEC = ::TRACK_ORX2_QEC; +const uint32_t ad937x_ctrl::TRACK_TX1_LOL = ::TRACK_TX1_LOL; +const uint32_t ad937x_ctrl::TRACK_TX2_LOL = ::TRACK_TX2_LOL; +const uint32_t ad937x_ctrl::TRACK_TX1_QEC = ::TRACK_TX1_QEC; +const uint32_t ad937x_ctrl::TRACK_TX2_QEC = ::TRACK_TX2_QEC; +const uint32_t ad937x_ctrl::TRACK_TX1_DPD = ::TRACK_TX1_DPD; +const uint32_t ad937x_ctrl::TRACK_TX2_DPD = ::TRACK_TX2_DPD; +const uint32_t ad937x_ctrl::TRACK_TX1_CLGC = ::TRACK_TX1_CLGC; +const uint32_t ad937x_ctrl::TRACK_TX2_CLGC = ::TRACK_TX2_CLGC; +const uint32_t ad937x_ctrl::TRACK_TX1_VSWR = ::TRACK_TX1_VSWR; +const uint32_t ad937x_ctrl::TRACK_TX2_VSWR = ::TRACK_TX2_VSWR; +const uint32_t ad937x_ctrl::TRACK_ORX1_QEC_SNLO = ::TRACK_ORX1_QEC_SNLO; +const uint32_t ad937x_ctrl::TRACK_ORX2_QEC_SNLO = ::TRACK_ORX2_QEC_SNLO; +const uint32_t ad937x_ctrl::TRACK_SRX_QEC = ::TRACK_SRX_QEC; const uint32_t ad937x_ctrl::DEFAULT_INIT_CALS_MASKS = - ad937x_ctrl::TX_BB_FILTER | - ad937x_ctrl::ADC_TUNER | - ad937x_ctrl::TIA_3DB_CORNER | - ad937x_ctrl::DC_OFFSET | - ad937x_ctrl::TX_ATTENUATION_DELAY | - ad937x_ctrl::RX_GAIN_DELAY | - ad937x_ctrl::FLASH_CAL | - ad937x_ctrl::PATH_DELAY | - ad937x_ctrl::TX_LO_LEAKAGE_INTERNAL | - ad937x_ctrl::TX_QEC_INIT | - ad937x_ctrl::LOOPBACK_RX_LO_DELAY | - ad937x_ctrl::RX_QEC_INIT - ; + ad937x_ctrl::TX_BB_FILTER | ad937x_ctrl::ADC_TUNER | ad937x_ctrl::TIA_3DB_CORNER + | ad937x_ctrl::DC_OFFSET | ad937x_ctrl::TX_ATTENUATION_DELAY + | ad937x_ctrl::RX_GAIN_DELAY | ad937x_ctrl::FLASH_CAL | ad937x_ctrl::PATH_DELAY + | ad937x_ctrl::TX_LO_LEAKAGE_INTERNAL | ad937x_ctrl::TX_QEC_INIT + | ad937x_ctrl::LOOPBACK_RX_LO_DELAY | ad937x_ctrl::RX_QEC_INIT; const uint32_t ad937x_ctrl::DEFAULT_TRACKING_CALS_MASKS = - ad937x_ctrl::TRACK_RX1_QEC | - ad937x_ctrl::TRACK_RX2_QEC | - ad937x_ctrl::TRACK_TX1_QEC | - ad937x_ctrl::TRACK_TX2_QEC - ; + ad937x_ctrl::TRACK_RX1_QEC | ad937x_ctrl::TRACK_RX2_QEC | ad937x_ctrl::TRACK_TX1_QEC + | ad937x_ctrl::TRACK_TX2_QEC; const uint32_t ad937x_ctrl::DEFAULT_INIT_CALS_TIMEOUT = 60000; static uhd::direction_t _get_direction_from_antenna(const std::string& antenna) { auto sub = antenna.substr(0, 2); if (sub == "RX") { return uhd::direction_t::RX_DIRECTION; - } - else if (sub == "TX") { + } else if (sub == "TX") { return uhd::direction_t::TX_DIRECTION; - } - else { + } else { throw mpm::runtime_error("ad937x_ctrl got an invalid channel string."); } return uhd::direction_t::RX_DIRECTION; @@ -100,11 +86,9 @@ static chain_t _get_chain_from_antenna(const std::string& antenna) auto sub = antenna.substr(2, 1); if (sub == "1") { return chain_t::ONE; - } - else if (sub == "2") { + } else if (sub == "2") { return chain_t::TWO; - } - else { + } else { throw mpm::runtime_error("ad937x_ctrl got an invalid channel string."); } return chain_t::ONE; @@ -113,15 +97,14 @@ static chain_t _get_chain_from_antenna(const std::string& antenna) std::set _get_valid_fir_lengths(const std::string& which) { auto dir = _get_direction_from_antenna(which); - switch (dir) - { - case uhd::direction_t::RX_DIRECTION: - return{ 24, 48, 72 }; - case uhd::direction_t::TX_DIRECTION: - return{ 16, 32, 48, 64, 80, 96 }; - default: - MPM_THROW_INVALID_CODE_PATH(); - return std::set(); + switch (dir) { + case uhd::direction_t::RX_DIRECTION: + return {24, 48, 72}; + case uhd::direction_t::TX_DIRECTION: + return {16, 32, 48, 64, 80, 96}; + default: + MPM_THROW_INVALID_CODE_PATH(); + return std::set(); } } @@ -152,43 +135,37 @@ uhd::meta_range_t ad937x_ctrl::get_bw_filter_range(void) std::vector ad937x_ctrl::get_clock_rates(void) { // TODO: fix - return { 125e6 }; + return {125e6}; } -uhd::meta_range_t ad937x_ctrl::get_gain_range(const std::string &which) +uhd::meta_range_t ad937x_ctrl::get_gain_range(const std::string& which) { auto dir = _get_direction_from_antenna(which); - switch (dir) - { - case uhd::direction_t::RX_DIRECTION: - return uhd::meta_range_t( - ad937x_device::MIN_RX_GAIN, + 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 - ); - case uhd::direction_t::TX_DIRECTION: - return uhd::meta_range_t( - ad937x_device::MIN_TX_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 - ); - default: - MPM_THROW_INVALID_CODE_PATH(); - return uhd::meta_range_t(); + ad937x_device::TX_GAIN_STEP); + default: + MPM_THROW_INVALID_CODE_PATH(); + return uhd::meta_range_t(); } } class ad937x_ctrl_impl : public ad937x_ctrl { public: - ad937x_ctrl_impl( - std::shared_ptr spi_mutex, + ad937x_ctrl_impl(std::shared_ptr spi_mutex, const size_t deserializer_lane_xbar, mpm::types::regs_iface::sptr iface, - mpm::ad937x::gpio::gain_pins_t gain_pins) : - spi_mutex(spi_mutex), - device(iface.get(), deserializer_lane_xbar, gain_pins), - _iface(iface) + mpm::ad937x::gpio::gain_pins_t gain_pins) + : spi_mutex(spi_mutex) + , device(iface.get(), deserializer_lane_xbar, gain_pins) + , _iface(iface) { /* nop */ } @@ -205,49 +182,45 @@ public: device.finish_initialization(); } - virtual void setup_cal( - const uint32_t init_cals_mask, - const uint32_t tracking_cals_mask, - const 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 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 - ) { + 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"){ + uint8_t pll_source = 0; + if (source == "internal") { pll_source = 0; - } - else if (source == "external") { + } else if (source == "external") { pll_source = 1; - } - else { + } else { throw mpm::runtime_error("invalid LO source"); } std::lock_guard lock(*spi_mutex); uint8_t retval = device.set_lo_source(dir, pll_source); - if (retval == 0){ + if (retval == 0) { return "internal"; - } else if (retval == 1){ + } else if (retval == 1) { return "external"; - }else{ + } else { throw mpm::runtime_error("invalid return from set LO source"); } } - virtual std::string get_lo_source(const std::string &which){ + virtual std::string get_lo_source(const std::string& which) + { const auto dir = _get_direction_from_antenna(which); std::lock_guard lock(*spi_mutex); uint8_t retval = device.get_lo_source(dir); - if (retval == 0){ + if (retval == 0) { return "internal"; } else if (retval == 1) { return "external"; @@ -328,10 +301,8 @@ public: std::lock_guard lock(*spi_mutex); const auto api = device.get_api_version(); std::ostringstream ss; - ss << api.silicon_ver << "." - << api.major_ver << "." - << api.minor_ver << "." - << api.build_ver; + ss << api.silicon_ver << "." << api.major_ver << "." << api.minor_ver << "." + << api.build_ver; return ss.str(); } @@ -341,45 +312,43 @@ public: std::lock_guard lock(*spi_mutex); const auto arm = device.get_arm_version(); std::ostringstream ss; - ss << (int)(arm.major_ver) << "." - << (int)(arm.minor_ver) << "." - << (int)(arm.rc_ver); - - switch (arm.build_type) - { - case mpm::ad937x::device::build_type_t::RELEASE: - ss << " Release"; - break; - case mpm::ad937x::device::build_type_t::DEBUG: - ss << " Debug"; - break; - case mpm::ad937x::device::build_type_t::TEST_OBJECT: - ss << " Test Object"; - break; + ss << (int)(arm.major_ver) << "." << (int)(arm.minor_ver) << "." + << (int)(arm.rc_ver); + + switch (arm.build_type) { + case mpm::ad937x::device::build_type_t::RELEASE: + ss << " Release"; + break; + case mpm::ad937x::device::build_type_t::DEBUG: + ss << " Debug"; + break; + case mpm::ad937x::device::build_type_t::TEST_OBJECT: + ss << " Test Object"; + break; } return ss.str(); } - virtual double set_bw_filter(const std::string &which, const double value) + virtual double set_bw_filter(const std::string& which, const double value) { const auto dir = _get_direction_from_antenna(which); std::lock_guard lock(*spi_mutex); return device.set_bw_filter(dir, value); } - virtual double set_gain(const std::string &which, const double value) + virtual double set_gain(const std::string& which, const double value) { - const auto dir = _get_direction_from_antenna(which); + const auto dir = _get_direction_from_antenna(which); const auto chain = _get_chain_from_antenna(which); std::lock_guard lock(*spi_mutex); return device.set_gain(dir, chain, value); } - virtual double get_gain(const std::string &which) + virtual double get_gain(const std::string& which) { - const auto dir = _get_direction_from_antenna(which); + const auto dir = _get_direction_from_antenna(which); const auto chain = _get_chain_from_antenna(which); std::lock_guard lock(*spi_mutex); @@ -388,27 +357,21 @@ 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 - ) { + 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) - { + 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") { gain_mode = ad937x_device::gain_mode_t::AUTOMATIC; - } - else if (mode == "manual") { + } else if (mode == "manual") { gain_mode = ad937x_device::gain_mode_t::MANUAL; - } - else if (mode == "hybrid") { + } else if (mode == "hybrid") { gain_mode = ad937x_device::gain_mode_t::HYBRID; - } - else { + } else { throw mpm::runtime_error("invalid agc mode"); } @@ -427,9 +390,9 @@ public: return device.set_clock_rate(value); } - virtual void enable_channel(const std::string &which, const bool enable) + virtual void enable_channel(const std::string& which, const bool enable) { - const auto dir = _get_direction_from_antenna(which); + const auto dir = _get_direction_from_antenna(which); const auto chain = _get_chain_from_antenna(which); std::lock_guard lock(*spi_mutex); @@ -437,18 +400,16 @@ public: } 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 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 lock(*spi_mutex); return device.tune(dir, clipped_value, wait_for_lock); } - virtual double get_freq(const std::string &which) + virtual double get_freq(const std::string& which) { const auto dir = _get_direction_from_antenna(which); @@ -456,27 +417,23 @@ public: return device.get_freq(dir); } - virtual bool get_lo_locked(const std::string &which) + virtual bool get_lo_locked(const std::string& which) { - const auto dir = _get_direction_from_antenna(which); - const uint8_t pll_select = (dir == uhd::RX_DIRECTION) ? - ad937x_device::RX_SYNTH : - ad937x_device::TX_SYNTH; + const auto dir = _get_direction_from_antenna(which); + const uint8_t pll_select = (dir == uhd::RX_DIRECTION) ? ad937x_device::RX_SYNTH + : ad937x_device::TX_SYNTH; std::lock_guard lock(*spi_mutex); return device.get_pll_lock_status(pll_select); } virtual void set_fir( - const std::string &which, - const int8_t gain, - const std::vector& fir - ) { - const auto dir = _get_direction_from_antenna(which); + const std::string& which, const int8_t gain, const std::vector& fir) + { + const auto dir = _get_direction_from_antenna(which); const auto lengths = _get_valid_fir_lengths(which); - if (std::find(lengths.begin(), lengths.end(), fir.size()) == lengths.end()) - { + if (std::find(lengths.begin(), lengths.end(), fir.size()) == lengths.end()) { throw mpm::value_error("invalid filter length"); } @@ -484,7 +441,7 @@ public: device.set_fir(dir, gain, fir); } - virtual std::vector get_fir(const std::string &which, int8_t &gain) + virtual std::vector get_fir(const std::string& which, int8_t& gain) { auto dir = _get_direction_from_antenna(which); @@ -504,28 +461,22 @@ public: 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)) { + } 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)) { + } 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) - )); + } 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, - const bool enable - ) { - const auto dir = _get_direction_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 lock(*spi_mutex); @@ -533,27 +484,24 @@ public: } 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 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) { 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) { + inc_step = steps.clip(inc_step); + dec_step = steps.clip(dec_step); + } 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); + 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"); + "TX gain increment and decrement steps must be equal"); } } @@ -579,17 +527,11 @@ private: mpm::types::regs_iface::sptr _iface; }; -ad937x_ctrl::sptr ad937x_ctrl::make( - std::shared_ptr spi_mutex, - const size_t deserializer_lane_xbar, - mpm::types::regs_iface::sptr iface, - mpm::ad937x::gpio::gain_pins_t gain_pins -) { +ad937x_ctrl::sptr ad937x_ctrl::make(std::shared_ptr spi_mutex, + const size_t deserializer_lane_xbar, + mpm::types::regs_iface::sptr iface, + mpm::ad937x::gpio::gain_pins_t gain_pins) +{ return std::make_shared( - spi_mutex, - deserializer_lane_xbar, - iface, - gain_pins - ); + spi_mutex, deserializer_lane_xbar, iface, gain_pins); } - -- cgit v1.2.3