diff options
author | Brent Stapleton <brent.stapleton@ettus.com> | 2019-01-14 10:35:25 -0800 |
---|---|---|
committer | Brent Stapleton <brent.stapleton@ettus.com> | 2019-01-16 11:40:23 -0800 |
commit | 967be2a4e82b1a125b26bb72a60318a4fb2b50c4 (patch) | |
tree | 8a24954b54d1546dc8049a17e485adb0a605f74f /mpm/lib | |
parent | aafe4e8b742a0e21d3818f21f34e3c8613132530 (diff) | |
download | uhd-967be2a4e82b1a125b26bb72a60318a4fb2b50c4.tar.gz uhd-967be2a4e82b1a125b26bb72a60318a4fb2b50c4.tar.bz2 uhd-967be2a4e82b1a125b26bb72a60318a4fb2b50c4.zip |
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.
Diffstat (limited to 'mpm/lib')
24 files changed, 1770 insertions, 1725 deletions
diff --git a/mpm/lib/dboards/magnesium_manager.cpp b/mpm/lib/dboards/magnesium_manager.cpp index 49ab7f9ec..c9f9a93b6 100644 --- a/mpm/lib/dboards/magnesium_manager.cpp +++ b/mpm/lib/dboards/magnesium_manager.cpp @@ -4,23 +4,19 @@ // SPDX-License-Identifier: GPL-3.0-or-later // -#include <mpm/dboards/magnesium_manager.hpp> #include <mpm/ad937x/ad937x_spi_iface.hpp> +#include <mpm/dboards/magnesium_manager.hpp> using namespace mpm::dboards; using namespace mpm::chips; magnesium_manager::magnesium_manager( - const std::string &mykonos_spidev, - const size_t deserializer_lane_xbar -) : _spi_mutex(std::make_shared<std::mutex>()) - , _spi_lock(mpm::types::lockable::make(_spi_mutex)) - , _mykonos_ctrl(ad937x_ctrl::make( - _spi_mutex, - deserializer_lane_xbar, - make_ad937x_iface(mykonos_spidev), - mpm::ad937x::gpio::gain_pins_t() - )) + const std::string& mykonos_spidev, const size_t deserializer_lane_xbar) + : _spi_mutex(std::make_shared<std::mutex>()) + , _spi_lock(mpm::types::lockable::make(_spi_mutex)) + , _mykonos_ctrl(ad937x_ctrl::make(_spi_mutex, + deserializer_lane_xbar, + make_ad937x_iface(mykonos_spidev), + mpm::ad937x::gpio::gain_pins_t())) { } - diff --git a/mpm/lib/dboards/neon_manager.cpp b/mpm/lib/dboards/neon_manager.cpp index bdd82f0b7..671e44d8d 100644 --- a/mpm/lib/dboards/neon_manager.cpp +++ b/mpm/lib/dboards/neon_manager.cpp @@ -27,9 +27,9 @@ constexpr uint32_t AD9361_SPI_DATA_MASK = 0x000000FF; constexpr uint32_t AD9361_SPI_DATA_SHIFT = 0; constexpr uint32_t AD9361_SPI_NUM_BITS = 24; constexpr uint32_t AD9361_SPI_SPEED_HZ = 2000000; -constexpr int AD9361_SPI_MODE = 1; +constexpr int AD9361_SPI_MODE = 1; -} // namespace /*anon*/ +} // namespace /*! MPM-style E320 SPI Iface for AD9361 CTRL * @@ -37,10 +37,14 @@ constexpr int AD9361_SPI_MODE = 1; class e320_ad9361_io_spi : public ad9361_io { public: - e320_ad9361_io_spi(regs_iface::sptr regs_iface, uint32_t slave_num) : - _regs_iface(regs_iface), _slave_num(slave_num) { } + e320_ad9361_io_spi(regs_iface::sptr regs_iface, uint32_t slave_num) + : _regs_iface(regs_iface), _slave_num(slave_num) + { + } - ~e320_ad9361_io_spi() {/*nop*/} + ~e320_ad9361_io_spi() + { /*nop*/ + } uint8_t peek8(uint32_t reg) { @@ -57,11 +61,12 @@ private: uint32_t _slave_num; }; -neon_manager::neon_manager(const std::string &catalina_spidev) +neon_manager::neon_manager(const std::string& catalina_spidev) { // Make the MPM-style low level SPI Regs iface - auto spi_iface = mpm::spi::make_spi_regs_iface( - mpm::spi::spi_iface::make_spidev(catalina_spidev, AD9361_SPI_SPEED_HZ, AD9361_SPI_MODE), + auto spi_iface = mpm::spi::make_spi_regs_iface( + mpm::spi::spi_iface::make_spidev( + catalina_spidev, AD9361_SPI_SPEED_HZ, AD9361_SPI_MODE), AD9361_SPI_ADDR_SHIFT, AD9361_SPI_DATA_SHIFT, AD9361_SPI_READ_CMD, @@ -70,10 +75,8 @@ neon_manager::neon_manager(const std::string &catalina_spidev) auto spi_io_iface = std::make_shared<e320_ad9361_io_spi>(spi_iface, 0); // Translate from a std shared_ptr to Boost (for legacy compatability) auto spi_io_iface_boost = boost::shared_ptr<e320_ad9361_io_spi>( - spi_io_iface.get(), - [spi_io_iface](...) mutable { spi_io_iface.reset(); }); + spi_io_iface.get(), [spi_io_iface](...) mutable { spi_io_iface.reset(); }); // Make the actual Catalina Ctrl object _catalina_ctrl = ad9361_ctrl::make_spi( - boost::make_shared<e320_ad9361_client_t>(), - spi_io_iface_boost); + boost::make_shared<e320_ad9361_client_t>(), spi_io_iface_boost); } diff --git a/mpm/lib/exception.cpp b/mpm/lib/exception.cpp index 89883a980..9d3692933 100644 --- a/mpm/lib/exception.cpp +++ b/mpm/lib/exception.cpp @@ -10,26 +10,37 @@ using namespace mpm; -exception::exception(const std::string &what): - std::runtime_error(what){/* NOP */} +exception::exception(const std::string& what) : std::runtime_error(what) +{ /* NOP */ +} -#define make_exception_impl(name, class, base) \ - class::class(const std::string &what): \ - base(str(boost::format("%s: %s") % name % what)){} \ - unsigned class::code(void) const{return std::hash<std::string>()(#class) & 0xfff;} \ - class *class::dynamic_clone(void) const{return new class(*this);} \ - void class::dynamic_throw(void) const{throw *this;} - -make_exception_impl("AssertionError", assertion_error, exception) -make_exception_impl("LookupError", lookup_error, exception) -make_exception_impl("IndexError", index_error, lookup_error) -make_exception_impl("KeyError", key_error, lookup_error) -make_exception_impl("TypeError", type_error, exception) -make_exception_impl("ValueError", value_error, exception) -make_exception_impl("RuntimeError", runtime_error, exception) -make_exception_impl("NotImplementedError", not_implemented_error, runtime_error) -make_exception_impl("EnvironmentError", environment_error, exception) -make_exception_impl("IOError", io_error, environment_error) -make_exception_impl("OSError", os_error, environment_error) -make_exception_impl("SystemError", system_error, exception) +#define make_exception_impl(name, class, base) \ + class ::class(const std::string& what) \ + : base(str(boost::format("%s: %s") % name % what)) \ + { \ + } \ + unsigned class ::code(void) const \ + { \ + return std::hash<std::string>()(#class) & 0xfff; \ + } \ + class* class ::dynamic_clone(void) const \ + { \ + return new class(*this); \ + } \ + void class ::dynamic_throw(void) const \ + { \ + throw *this; \ + } +make_exception_impl("AssertionError", assertion_error, exception) make_exception_impl( + "LookupError", lookup_error, exception) make_exception_impl("IndexError", + index_error, + lookup_error) make_exception_impl("KeyError", key_error, lookup_error) + make_exception_impl("TypeError", type_error, exception) make_exception_impl( + "ValueError", value_error, exception) + make_exception_impl("RuntimeError", runtime_error, exception) make_exception_impl( + "NotImplementedError", not_implemented_error, runtime_error) + make_exception_impl("EnvironmentError", environment_error, exception) + make_exception_impl("IOError", io_error, environment_error) + make_exception_impl("OSError", os_error, environment_error) + make_exception_impl("SystemError", system_error, exception) diff --git a/mpm/lib/i2c/i2c_regs_iface.cpp b/mpm/lib/i2c/i2c_regs_iface.cpp index c476cf636..575e19d26 100644 --- a/mpm/lib/i2c/i2c_regs_iface.cpp +++ b/mpm/lib/i2c/i2c_regs_iface.cpp @@ -4,10 +4,10 @@ // SPDX-License-Identifier: GPL-3.0-or-later // -#include <mpm/types/regs_iface.hpp> +#include <mpm/exception.hpp> #include <mpm/i2c/i2c_iface.hpp> #include <mpm/i2c/i2c_regs_iface.hpp> -#include <mpm/exception.hpp> +#include <mpm/types/regs_iface.hpp> using mpm::types::regs_iface; @@ -18,26 +18,21 @@ using mpm::types::regs_iface; class i2c_regs_iface_impl : public regs_iface { public: - - i2c_regs_iface_impl( - mpm::i2c::i2c_iface::sptr i2c_iface, - const size_t reg_addr_size - ) : _i2c_iface(i2c_iface), - _reg_addr_size(reg_addr_size) + i2c_regs_iface_impl(mpm::i2c::i2c_iface::sptr i2c_iface, const size_t reg_addr_size) + : _i2c_iface(i2c_iface), _reg_addr_size(reg_addr_size) { if (reg_addr_size > 4) { throw mpm::runtime_error("reg_addr_size too largs for i2c_regs_iface"); } } - uint8_t peek8( - const uint32_t addr - ) { + uint8_t peek8(const uint32_t addr) + { uint8_t rx[1]; uint8_t tx[5]; int i = 0; for (; i < _reg_addr_size; i++) { - tx[i] = 0xff & (addr >> 8*(_reg_addr_size-i-1)); + tx[i] = 0xff & (addr >> 8 * (_reg_addr_size - i - 1)); } int err = _i2c_iface->transfer(tx, _reg_addr_size, rx, 1); @@ -48,14 +43,12 @@ public: return rx[0]; } - void poke8( - const uint32_t addr, - const uint8_t data - ) { + void poke8(const uint32_t addr, const uint8_t data) + { uint8_t tx[5]; int i = 0; for (; i < _reg_addr_size; i++) { - tx[i] = 0xff & (addr >> 8*(_reg_addr_size-i-1)); + tx[i] = 0xff & (addr >> 8 * (_reg_addr_size - i - 1)); } tx[i] = data; @@ -65,14 +58,13 @@ public: } } - uint16_t peek16( - const uint32_t addr - ) { + uint16_t peek16(const uint32_t addr) + { uint8_t rx[2]; uint8_t tx[5]; int i = 0; for (; i < _reg_addr_size; i++) { - tx[i] = 0xff & (addr >> 8*(_reg_addr_size-i-1)); + tx[i] = 0xff & (addr >> 8 * (_reg_addr_size - i - 1)); } int err = _i2c_iface->transfer(tx, _reg_addr_size, rx, 2); @@ -81,21 +73,19 @@ public: } uint16_t data = rx[0]; - data = (data << 8) | rx[1]; + data = (data << 8) | rx[1]; return data; } - void poke16( - const uint32_t addr, - const uint16_t data - ) { + void poke16(const uint32_t addr, const uint16_t data) + { uint8_t tx[6]; int i = 0; for (; i < _reg_addr_size; i++) { - tx[i] = 0xff & (addr >> 8*(_reg_addr_size-i-1)); + tx[i] = 0xff & (addr >> 8 * (_reg_addr_size - i - 1)); } - tx[i] = (data >> 8) & 0xff; - tx[i+1] = data & 0xff; + tx[i] = (data >> 8) & 0xff; + tx[i + 1] = data & 0xff; int err = _i2c_iface->transfer(tx, _reg_addr_size + 2, NULL, 0); if (err) { @@ -110,27 +100,18 @@ private: }; regs_iface::sptr mpm::i2c::make_i2c_regs_iface( - mpm::i2c::i2c_iface::sptr i2c_iface, - const size_t reg_addr_size -) { - return std::make_shared<i2c_regs_iface_impl>( - i2c_iface, - reg_addr_size - ); + mpm::i2c::i2c_iface::sptr i2c_iface, const size_t reg_addr_size) +{ + return std::make_shared<i2c_regs_iface_impl>(i2c_iface, reg_addr_size); } -mpm::types::regs_iface::sptr mpm::i2c::make_i2cdev_regs_iface( - const std::string &bus, +mpm::types::regs_iface::sptr mpm::i2c::make_i2cdev_regs_iface(const std::string& bus, const uint16_t addr, const bool ten_bit_addr, const int timeout_ms, - const size_t reg_addr_size -) { - auto i2c_iface_sptr = mpm::i2c::i2c_iface::make_i2cdev( - bus, addr, ten_bit_addr, timeout_ms - ); - return std::make_shared<i2c_regs_iface_impl>( - i2c_iface_sptr, - reg_addr_size - ); + const size_t reg_addr_size) +{ + auto i2c_iface_sptr = + mpm::i2c::i2c_iface::make_i2cdev(bus, addr, ten_bit_addr, timeout_ms); + return std::make_shared<i2c_regs_iface_impl>(i2c_iface_sptr, reg_addr_size); } diff --git a/mpm/lib/i2c/i2cdev_iface.cpp b/mpm/lib/i2c/i2cdev_iface.cpp index 5b59e06f8..b346597a8 100644 --- a/mpm/lib/i2c/i2cdev_iface.cpp +++ b/mpm/lib/i2c/i2cdev_iface.cpp @@ -5,15 +5,12 @@ // -#include <mpm/i2c/i2c_iface.hpp> -#include <mpm/exception.hpp> - #include "i2cdev.h" - #include <fcntl.h> -#include <linux/i2c.h> #include <linux/i2c-dev.h> - +#include <linux/i2c.h> +#include <mpm/exception.hpp> +#include <mpm/i2c/i2c_iface.hpp> #include <boost/format.hpp> #include <iostream> @@ -25,17 +22,15 @@ using namespace mpm::i2c; class i2cdev_iface_impl : public i2c_iface { public: - - i2cdev_iface_impl( - const std::string &device, - const uint16_t addr, - const bool ten_bit_addr, - const unsigned int timeout_ms, - const bool do_open = false - ) : _device(device), - _addr(addr), - _ten_bit_addr(ten_bit_addr), - _timeout_ms(timeout_ms) + i2cdev_iface_impl(const std::string& device, + const uint16_t addr, + const bool ten_bit_addr, + const unsigned int timeout_ms, + const bool do_open = false) + : _device(device) + , _addr(addr) + , _ten_bit_addr(ten_bit_addr) + , _timeout_ms(timeout_ms) { if (do_open) _open(); @@ -49,13 +44,12 @@ public: close(_fd); } - int transfer(uint8_t *tx, size_t tx_len, uint8_t *rx, size_t rx_len, bool do_close) + int transfer(uint8_t* tx, size_t tx_len, uint8_t* rx, size_t rx_len, bool do_close) { if (_fd < 0) _open(); - int ret = i2cdev_transfer(_fd, _addr, _ten_bit_addr, - tx, tx_len, rx, rx_len); + int ret = i2cdev_transfer(_fd, _addr, _ten_bit_addr, tx, tx_len, rx, rx_len); if (do_close) { close(_fd); @@ -63,27 +57,25 @@ public: } if (ret) { - throw mpm::runtime_error(str( - boost::format("I2C Transaction failed!") - )); + throw mpm::runtime_error(str(boost::format("I2C Transaction failed!"))); } return ret; } - int transfer(std::vector<uint8_t> *tx, std::vector<uint8_t> *rx, bool do_close) + int transfer(std::vector<uint8_t>* tx, std::vector<uint8_t>* rx, bool do_close) { uint8_t *tx_data = NULL, *rx_data = NULL; size_t tx_len = 0, rx_len = 0; if (tx) { tx_data = tx->data(); - tx_len = tx->size(); + tx_len = tx->size(); } if (rx) { rx_data = rx->data(); - rx_len = rx->size(); + rx_len = rx->size(); } int ret = transfer(tx_data, tx_len, rx_data, rx_len, do_close); @@ -97,22 +89,16 @@ private: const bool _ten_bit_addr; const unsigned int _timeout_ms; - int _open(void) { - if (i2cdev_open( - &_fd, - _device.c_str(), - _timeout_ms) < 0) - { - throw mpm::runtime_error(str( - boost::format("Could not initialize i2cdev device %s") - % _device)); + int _open(void) + { + if (i2cdev_open(&_fd, _device.c_str(), _timeout_ms) < 0) { + throw mpm::runtime_error( + str(boost::format("Could not initialize i2cdev device %s") % _device)); } - if (_fd < 0) - { - throw mpm::runtime_error(str( - boost::format("Could not open i2cdev device %s") - % _device)); + if (_fd < 0) { + throw mpm::runtime_error( + str(boost::format("Could not open i2cdev device %s") % _device)); } } }; @@ -120,14 +106,10 @@ private: /****************************************************************************** * Factory *****************************************************************************/ -i2c_iface::sptr i2c_iface::make_i2cdev( - const std::string &bus, +i2c_iface::sptr i2c_iface::make_i2cdev(const std::string& bus, const uint16_t addr, const bool ten_bit_addr, - const int timeout_ms -) { - return std::make_shared<i2cdev_iface_impl>( - bus, addr, ten_bit_addr, timeout_ms - ); + const int timeout_ms) +{ + return std::make_shared<i2cdev_iface_impl>(bus, addr, ten_bit_addr, timeout_ms); } - 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 <mpm/exception.hpp> -#include "../../../host/include/uhd/utils/math.hpp" - #include <boost/format.hpp> -#include <sstream> -#include <set> +#include <algorithm> +#include <chrono> #include <functional> #include <iostream> -#include <algorithm> +#include <set> +#include <sstream> #include <thread> -#include <chrono> 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<size_t> _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<size_t>(); + 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<size_t>(); } } @@ -152,43 +135,37 @@ uhd::meta_range_t ad937x_ctrl::get_bw_filter_range(void) std::vector<double> 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<std::mutex> spi_mutex, + ad937x_ctrl_impl(std::shared_ptr<std::mutex> 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<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 - ) { + 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<int16_t>& fir - ) { - const auto dir = _get_direction_from_antenna(which); + 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); - 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<int16_t> get_fir(const std::string &which, int8_t &gain) + virtual std::vector<int16_t> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<ad937x_ctrl_impl>( - spi_mutex, - deserializer_lane_xbar, - iface, - gain_pins - ); + 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 ceaa0b93c..144b813ae 100644 --- a/mpm/lib/mykonos/ad937x_device.cpp +++ b/mpm/lib/mykonos/ad937x_device.cpp @@ -6,28 +6,27 @@ #include "ad937x_device.hpp" #include "adi/mykonos.h" -#include "adi/mykonos_gpio.h" #include "adi/mykonos_debug/mykonos_dbgjesd.h" +#include "adi/mykonos_gpio.h" #include "config/ad937x_config_t.hpp" #include "config/ad937x_default_config.hpp" #include <boost/format.hpp> - +#include <fstream> #include <functional> #include <iostream> #include <thread> -#include <fstream> using namespace mpm::ad937x::device; using namespace mpm::ad937x::gpio; using namespace uhd; -const double ad937x_device::MIN_FREQ = 300e6; -const double ad937x_device::MAX_FREQ = 6e9; -const double ad937x_device::MIN_RX_GAIN = 0.0; -const double ad937x_device::MAX_RX_GAIN = 30.0; +const double ad937x_device::MIN_FREQ = 300e6; +const double ad937x_device::MAX_FREQ = 6e9; +const double ad937x_device::MIN_RX_GAIN = 0.0; +const double ad937x_device::MAX_RX_GAIN = 30.0; const double ad937x_device::RX_GAIN_STEP = 0.5; -const double ad937x_device::MIN_TX_GAIN = 0.0; -const double ad937x_device::MAX_TX_GAIN = 41.95; +const double ad937x_device::MIN_TX_GAIN = 0.0; +const double ad937x_device::MAX_TX_GAIN = 41.95; const double ad937x_device::TX_GAIN_STEP = 0.05; static const double RX_DEFAULT_FREQ = 2.5e9; @@ -35,9 +34,9 @@ static const double TX_DEFAULT_FREQ = 2.5e9; static const double RX_DEFAULT_GAIN = 0; static const double TX_DEFAULT_GAIN = 0; -static const uint32_t AD9371_PRODUCT_ID = 0x3; +static const uint32_t AD9371_PRODUCT_ID = 0x3; static const uint32_t AD9371_XBCZ_PRODUCT_ID = 0x1; -static const size_t ARM_BINARY_SIZE = 98304; +static const size_t ARM_BINARY_SIZE = 98304; static const uint32_t PLL_LOCK_TIMEOUT_MS = 200; @@ -46,29 +45,26 @@ Helper functions ******************************************************/ // Macro to call an API function via lambda -#define CALL_API(function_call) \ - _call_api_function([&,this]{return function_call;}) +#define CALL_API(function_call) _call_api_function([&, this] { return function_call; }) // helper function to unify error handling void ad937x_device::_call_api_function(const std::function<mykonosErr_t()>& func) { const auto error = func(); - if (error != MYKONOS_ERR_OK) - { + if (error != MYKONOS_ERR_OK) { throw mpm::runtime_error(getMykonosErrorMessage(error)); } } // Macro to call a GPIO API function via lambda #define CALL_GPIO_API(function_call) \ - _call_gpio_api_function([&,this]{return function_call;}) + _call_gpio_api_function([&, this] { return function_call; }) // helper function to unify error handling, GPIO version void ad937x_device::_call_gpio_api_function(const std::function<mykonosGpioErr_t()>& func) { const auto error = func(); - if (error != MYKONOS_ERR_GPIO_OK) - { + if (error != MYKONOS_ERR_GPIO_OK) { throw mpm::runtime_error(getGpioMykonosErrorMessage(error)); } } @@ -84,23 +80,19 @@ ad937x_device::radio_state_t ad937x_device::_move_to_config_state() { uint32_t status; CALL_API(MYKONOS_getRadioState(mykonos_config.device, &status)); - if ((status & 0x3) == 0x3) - { + if ((status & 0x3) == 0x3) { stop_radio(); return radio_state_t::ON; - } - else { + } else { return radio_state_t::OFF; } } // 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 -) { - if (state == radio_state_t::ON) - { +void ad937x_device::_restore_from_config_state(const ad937x_device::radio_state_t state) +{ + if (state == radio_state_t::ON) { start_radio(); } } @@ -117,17 +109,14 @@ 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); + 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 std::vector<uint8_t> binary(ARM_BINARY_SIZE); 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); + if (file.bad()) { + throw mpm::runtime_error("Error reading AD9371 ARM binary at path " + path); } return binary; } @@ -135,31 +124,26 @@ 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 - && product_id != AD9371_XBCZ_PRODUCT_ID) { + if (product_id != AD9371_PRODUCT_ID && product_id != AD9371_XBCZ_PRODUCT_ID) { // The XBCZ code is an exception, so we don't print it as 'Expected' // if this fails. - throw mpm::runtime_error(str( - boost::format("AD9371 product ID does not match expected ID! " - "Read: %X Expected: %X") - % int(product_id) % int(AD9371_PRODUCT_ID) - )); + throw mpm::runtime_error( + str(boost::format("AD9371 product ID does not match expected ID! " + "Read: %X Expected: %X") + % int(product_id) % int(AD9371_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_mask = status_expected; // all 1s expected, mask is the same + 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) - )); + 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))); } } @@ -193,10 +177,8 @@ 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); @@ -207,51 +189,44 @@ void ad937x_device::_apply_gain_pins( const auto state = _move_to_config_state(); - switch (direction) - { - case RX_DIRECTION: - { + switch (direction) { + case RX_DIRECTION: { std::function<decltype(MYKONOS_setRx1GainCtrlPin)> func; - switch (chain) - { - case chain_t::ONE: - func = MYKONOS_setRx1GainCtrlPin; - break; - case chain_t::TWO: - func = MYKONOS_setRx2GainCtrlPin; - break; + switch (chain) { + case chain_t::ONE: + func = MYKONOS_setRx1GainCtrlPin; + break; + case chain_t::TWO: + func = MYKONOS_setRx2GainCtrlPin; + break; } CALL_GPIO_API(func(mykonos_config.device, - chan.inc_step, - chan.dec_step, - chan.inc_pin, - chan.dec_pin, - chan.enable)); + chan.inc_step, + chan.dec_step, + chan.inc_pin, + chan.dec_pin, + chan.enable)); break; } - case TX_DIRECTION: - { + case TX_DIRECTION: { // TX sets attenuation, but the configuration should be stored correctly - switch (chain) - { - case chain_t::ONE: - // TX1 has an extra parameter "useTx1ForTx2" that we do not support - CALL_GPIO_API(MYKONOS_setTx1AttenCtrlPin( - mykonos_config.device, + switch (chain) { + case chain_t::ONE: + // TX1 has an extra parameter "useTx1ForTx2" that we do not support + CALL_GPIO_API(MYKONOS_setTx1AttenCtrlPin(mykonos_config.device, chan.inc_step, chan.inc_pin, chan.dec_pin, chan.enable, 0)); - break; - case chain_t::TWO: - CALL_GPIO_API(MYKONOS_setTx2AttenCtrlPin( - mykonos_config.device, + break; + case chain_t::TWO: + CALL_GPIO_API(MYKONOS_setTx2AttenCtrlPin(mykonos_config.device, chan.inc_step, chan.inc_pin, chan.dec_pin, chan.enable)); - break; + break; } break; } @@ -260,29 +235,27 @@ void ad937x_device::_apply_gain_pins( } - /****************************************************** Initialization functions ******************************************************/ -ad937x_device::ad937x_device( - mpm::types::regs_iface* iface, +ad937x_device::ad937x_device(mpm::types::regs_iface* iface, const size_t deserializer_lane_xbar, - const gain_pins_t gain_pins) : - full_spi_settings(iface), - mykonos_config(&full_spi_settings.spi_settings, deserializer_lane_xbar), - gain_ctrl(gain_pins) + const gain_pins_t gain_pins) + : full_spi_settings(iface) + , mykonos_config(&full_spi_settings.spi_settings, deserializer_lane_xbar) + , gain_ctrl(gain_pins) { } -void ad937x_device::_setup_rf(){ +void ad937x_device::_setup_rf() +{ // TODO: add setRfPllLoopFilter here // Set frequencies tune(uhd::RX_DIRECTION, RX_DEFAULT_FREQ, false); tune(uhd::TX_DIRECTION, TX_DEFAULT_FREQ, false); - if (!get_pll_lock_status(CLK_SYNTH | RX_SYNTH | TX_SYNTH | SNIFF_SYNTH, true)) - { + if (!get_pll_lock_status(CLK_SYNTH | RX_SYNTH | TX_SYNTH | SNIFF_SYNTH, true)) { throw mpm::runtime_error("PLLs did not lock after initial tuning!"); } @@ -299,54 +272,50 @@ void ad937x_device::_setup_rf(){ set_gain(uhd::RX_DIRECTION, chain_t::TWO, RX_DEFAULT_GAIN); set_gain(uhd::TX_DIRECTION, chain_t::ONE, TX_DEFAULT_GAIN); set_gain(uhd::TX_DIRECTION, chain_t::TWO, TX_DEFAULT_GAIN); - - } -void ad937x_device::setup_cal( - const uint32_t init_cals_mask, +void ad937x_device::setup_cal(const uint32_t init_cals_mask, const uint32_t tracking_cals_mask, - const uint32_t timeout -) { + 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)) { 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 -) { - switch (direction){ + 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(); + default: + MPM_THROW_INVALID_CODE_PATH(); } } -uint8_t ad937x_device::get_lo_source(const uhd::direction_t direction) const { - switch (direction){ +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(); + default: + MPM_THROW_INVALID_CODE_PATH(); } } void ad937x_device::begin_initialization() @@ -355,8 +324,7 @@ void ad937x_device::begin_initialization() _verify_product_id(); - if (!get_pll_lock_status(CLK_SYNTH)) - { + if (!get_pll_lock_status(CLK_SYNTH)) { throw mpm::runtime_error("AD937x CLK_SYNTH PLL failed to lock"); } @@ -370,14 +338,12 @@ void ad937x_device::finish_initialization() CALL_API(MYKONOS_initArm(mykonos_config.device)); auto binary = _get_arm_binary(); - CALL_API(MYKONOS_loadArmFromBinary( - mykonos_config.device, - binary.data(), - binary.size())); + CALL_API( + MYKONOS_loadArmFromBinary(mykonos_config.device, binary.data(), binary.size())); // TODO: check ARM version before or after the load of the ARM // currently binary has no readable version number until after it's loaded - //Run setup RF + // Run setup RF _setup_rf(); } @@ -404,7 +370,6 @@ void ad937x_device::stop_radio() } - /****************************************************** Get status functions ******************************************************/ @@ -455,8 +420,7 @@ uint8_t ad937x_device::get_device_rev() api_version_t ad937x_device::get_api_version() { api_version_t api; - CALL_API(MYKONOS_getApiVersion( - mykonos_config.device, + CALL_API(MYKONOS_getApiVersion(mykonos_config.device, &api.silicon_ver, &api.major_ver, &api.minor_ver, @@ -469,25 +433,20 @@ arm_version_t ad937x_device::get_arm_version() arm_version_t arm; mykonosBuild_t build; CALL_API(MYKONOS_getArmVersion( - mykonos_config.device, - &arm.major_ver, - &arm.minor_ver, - &arm.rc_ver, - &build)); - - switch (build) - { - case MYK_BUILD_RELEASE: - arm.build_type = mpm::ad937x::device::build_type_t::RELEASE; - break; - case MYK_BUILD_DEBUG: - arm.build_type = mpm::ad937x::device::build_type_t::DEBUG; - break; - case MYK_BUILD_TEST_OBJECT: - arm.build_type = mpm::ad937x::device::build_type_t::TEST_OBJECT; - break; - default: - MPM_THROW_INVALID_CODE_PATH(); + mykonos_config.device, &arm.major_ver, &arm.minor_ver, &arm.rc_ver, &build)); + + switch (build) { + case MYK_BUILD_RELEASE: + arm.build_type = mpm::ad937x::device::build_type_t::RELEASE; + break; + case MYK_BUILD_DEBUG: + arm.build_type = mpm::ad937x::device::build_type_t::DEBUG; + break; + case MYK_BUILD_TEST_OBJECT: + arm.build_type = mpm::ad937x::device::build_type_t::TEST_OBJECT; + break; + default: + MPM_THROW_INVALID_CODE_PATH(); } return arm; @@ -509,7 +468,7 @@ double ad937x_device::set_clock_rate(const double req_rate) { const auto rate = static_cast<uint32_t>(req_rate / 1000.0); - const auto state = _move_to_config_state(); + const auto state = _move_to_config_state(); mykonos_config.device->clocks->deviceClock_kHz = rate; CALL_API(MYKONOS_initDigitalClocks(mykonos_config.device)); _restore_from_config_state(state); @@ -518,23 +477,19 @@ double ad937x_device::set_clock_rate(const double req_rate) } void ad937x_device::enable_channel( - const direction_t direction, - const chain_t chain, - const bool enable -) { + 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. // mmeserve 8/24/2017 - // While it is possible to change the enable state after disabling the radio, we'll probably - // always use the GPIO pins to do so. Delete this function at a later time. + // While it is possible to change the enable state after disabling the radio, we'll + // probably 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 -) { + 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 @@ -542,30 +497,27 @@ double ad937x_device::tune( uint8_t locked_pll; uint64_t* config_value; const uint64_t integer_value = static_cast<uint64_t>(value); - switch (direction) - { - case TX_DIRECTION: - pll = TX_PLL; - locked_pll = TX_SYNTH; - config_value = &(mykonos_config.device->tx->txPllLoFrequency_Hz); - break; - case RX_DIRECTION: - pll = RX_PLL; - locked_pll = RX_SYNTH; - config_value = &(mykonos_config.device->rx->rxPllLoFrequency_Hz); - break; - default: - MPM_THROW_INVALID_CODE_PATH(); + switch (direction) { + case TX_DIRECTION: + pll = TX_PLL; + locked_pll = TX_SYNTH; + config_value = &(mykonos_config.device->tx->txPllLoFrequency_Hz); + break; + case RX_DIRECTION: + pll = RX_PLL; + locked_pll = RX_SYNTH; + config_value = &(mykonos_config.device->rx->rxPllLoFrequency_Hz); + break; + default: + MPM_THROW_INVALID_CODE_PATH(); } const auto state = _move_to_config_state(); - *config_value = integer_value; + *config_value = integer_value; CALL_API(MYKONOS_setRfPllFrequency(mykonos_config.device, pll, integer_value)); - if (wait_for_lock) - { - if (!get_pll_lock_status(locked_pll, true)) - { + if (wait_for_lock) { + if (!get_pll_lock_status(locked_pll, true)) { throw mpm::runtime_error("PLL did not lock"); } } @@ -574,24 +526,18 @@ double ad937x_device::tune( return get_freq(direction); } -double ad937x_device::set_bw_filter( - const direction_t direction, - const double value -) { - - switch (direction) - { - case TX_DIRECTION: - { - mykonos_config.device->tx->txProfile->rfBandwidth_Hz = value; - mykonos_config.device->tx->txProfile->txBbf3dBCorner_kHz = value/1000; - mykonos_config.device->tx->txProfile->txDac3dBCorner_kHz = value/1000; +double ad937x_device::set_bw_filter(const direction_t direction, const double value) +{ + switch (direction) { + case TX_DIRECTION: { + mykonos_config.device->tx->txProfile->rfBandwidth_Hz = value; + mykonos_config.device->tx->txProfile->txBbf3dBCorner_kHz = value / 1000; + mykonos_config.device->tx->txProfile->txDac3dBCorner_kHz = value / 1000; break; } - case RX_DIRECTION: - { - mykonos_config.device->rx->rxProfile->rfBandwidth_Hz = value; - mykonos_config.device->rx->rxProfile->rxBbf3dBCorner_kHz = value/1000; + case RX_DIRECTION: { + mykonos_config.device->rx->rxProfile->rfBandwidth_Hz = value; + mykonos_config.device->rx->rxProfile->rxBbf3dBCorner_kHz = value / 1000; break; } } @@ -603,87 +549,76 @@ double ad937x_device::set_bw_filter( double ad937x_device::set_gain( - const direction_t direction, - const chain_t chain, - const double value -) { + const direction_t direction, const chain_t chain, const double value) +{ double coerced_value; const auto state = _move_to_config_state(); - switch (direction) - { - case TX_DIRECTION: - { - const uint16_t attenuation = _convert_tx_gain_to_mykonos(value); - coerced_value = static_cast<double>(attenuation); - - std::function<mykonosErr_t(mykonosDevice_t*, uint16_t)> func; - switch (chain) - { - case chain_t::ONE: - func = MYKONOS_setTx1Attenuation; - break; - case chain_t::TWO: - func = MYKONOS_setTx2Attenuation; + switch (direction) { + case TX_DIRECTION: { + const uint16_t attenuation = _convert_tx_gain_to_mykonos(value); + coerced_value = static_cast<double>(attenuation); + + std::function<mykonosErr_t(mykonosDevice_t*, uint16_t)> func; + switch (chain) { + case chain_t::ONE: + func = MYKONOS_setTx1Attenuation; + break; + case chain_t::TWO: + func = MYKONOS_setTx2Attenuation; + break; + default: + MPM_THROW_INVALID_CODE_PATH(); + } + CALL_API(func(mykonos_config.device, attenuation)); break; - default: - MPM_THROW_INVALID_CODE_PATH(); } - CALL_API(func(mykonos_config.device, attenuation)); - break; - } - case RX_DIRECTION: - { - const uint8_t gain = _convert_rx_gain_to_mykonos(value); - coerced_value = static_cast<double>(gain); - - std::function<mykonosErr_t(mykonosDevice_t*, uint8_t)> func; - switch (chain) - { - case chain_t::ONE: - func = MYKONOS_setRx1ManualGain; - break; - case chain_t::TWO: - func = MYKONOS_setRx2ManualGain; + case RX_DIRECTION: { + const uint8_t gain = _convert_rx_gain_to_mykonos(value); + coerced_value = static_cast<double>(gain); + + std::function<mykonosErr_t(mykonosDevice_t*, uint8_t)> func; + switch (chain) { + case chain_t::ONE: + func = MYKONOS_setRx1ManualGain; + break; + case chain_t::TWO: + func = MYKONOS_setRx2ManualGain; + break; + default: + MPM_THROW_INVALID_CODE_PATH(); + } + CALL_API(func(mykonos_config.device, gain)); break; + } default: MPM_THROW_INVALID_CODE_PATH(); - } - CALL_API(func(mykonos_config.device, gain)); - break; - } - default: - MPM_THROW_INVALID_CODE_PATH(); } _restore_from_config_state(state); 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) - { - case RX_DIRECTION: - switch (mode) - { - case gain_mode_t::MANUAL: - mykonos_mode = MGC; - break; - case gain_mode_t::AUTOMATIC: - mykonos_mode = AGC; - break; - case gain_mode_t::HYBRID: - mykonos_mode = HYBRID; + switch (direction) { + case RX_DIRECTION: + switch (mode) { + case gain_mode_t::MANUAL: + mykonos_mode = MGC; + break; + case gain_mode_t::AUTOMATIC: + mykonos_mode = AGC; + break; + case gain_mode_t::HYBRID: + mykonos_mode = HYBRID; + break; + default: + MPM_THROW_INVALID_CODE_PATH(); + } break; default: MPM_THROW_INVALID_CODE_PATH(); - } - break; - default: - MPM_THROW_INVALID_CODE_PATH(); } const auto state = _move_to_config_state(); @@ -692,74 +627,67 @@ void ad937x_device::set_agc_mode( } void ad937x_device::set_fir( - const direction_t direction, - int8_t gain, - const std::vector<int16_t> & fir) -{ - switch (direction) - { - case TX_DIRECTION: - mykonos_config.tx_fir_config.set_fir(gain, fir); - break; - case RX_DIRECTION: - mykonos_config.rx_fir_config.set_fir(gain, fir); - break; - default: - MPM_THROW_INVALID_CODE_PATH(); + const direction_t direction, int8_t gain, const std::vector<int16_t>& fir) +{ + switch (direction) { + case TX_DIRECTION: + mykonos_config.tx_fir_config.set_fir(gain, fir); + break; + case RX_DIRECTION: + mykonos_config.rx_fir_config.set_fir(gain, fir); + break; + default: + MPM_THROW_INVALID_CODE_PATH(); } // 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 -) { - if (direction == RX_DIRECTION) - { +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); - } - else if (direction == TX_DIRECTION) { + } 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); - } - else { + } else { MPM_THROW_INVALID_CODE_PATH(); } _apply_gain_pins(direction, chain); } void ad937x_device::set_enable_gain_pins( - const direction_t direction, - const chain_t chain, - const bool enable -) { + 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); } - /****************************************************** Get configuration functions ******************************************************/ double ad937x_device::get_freq(const direction_t direction) { mykonosRfPllName_t pll; - switch (direction) - { - case TX_DIRECTION: pll = TX_PLL; break; - case RX_DIRECTION: pll = RX_PLL; break; - default: - MPM_THROW_INVALID_CODE_PATH(); + switch (direction) { + case TX_DIRECTION: + pll = TX_PLL; + break; + case RX_DIRECTION: + pll = RX_PLL; + break; + default: + MPM_THROW_INVALID_CODE_PATH(); } // TODO: because coerced_pll is returned as an integer, it's not accurate @@ -768,29 +696,22 @@ 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)); - if (not wait_for_lock) - { + if (not wait_for_lock) { return (pll_status & pll) == pll; - } - else { - const auto lock_time = - std::chrono::steady_clock::now() - + std::chrono::milliseconds(PLL_LOCK_TIMEOUT_MS); + } else { + 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()) - { + while (not locked and lock_time > std::chrono::steady_clock::now()) { locked = get_pll_lock_status(pll); } - if (!locked) - { + if (!locked) { // last chance locked = get_pll_lock_status(pll); } @@ -798,39 +719,32 @@ bool ad937x_device::get_pll_lock_status( } } -double ad937x_device::get_gain( - const direction_t direction, - const chain_t chain -) { - switch (direction) - { - case TX_DIRECTION: - { +double ad937x_device::get_gain(const direction_t direction, const chain_t chain) +{ + switch (direction) { + case TX_DIRECTION: { std::function<mykonosErr_t(mykonosDevice_t*, uint16_t*)> func; - switch (chain) - { - case chain_t::ONE: - func = MYKONOS_getTx1Attenuation; - break; - case chain_t::TWO: - func = MYKONOS_getTx2Attenuation; - break; + switch (chain) { + case chain_t::ONE: + func = MYKONOS_getTx1Attenuation; + break; + case chain_t::TWO: + func = MYKONOS_getTx2Attenuation; + break; } uint16_t atten; CALL_API(func(mykonos_config.device, &atten)); return _convert_tx_gain_from_mykonos(atten); } - case RX_DIRECTION: - { + case RX_DIRECTION: { std::function<mykonosErr_t(mykonosDevice_t*, uint8_t*)> func; - switch (chain) - { - case chain_t::ONE: - func = MYKONOS_getRx1Gain; - break; - case chain_t::TWO: - func = MYKONOS_getRx2Gain; - break; + switch (chain) { + case chain_t::ONE: + func = MYKONOS_getRx1Gain; + break; + case chain_t::TWO: + func = MYKONOS_getRx2Gain; + break; } uint8_t gain; CALL_API(func(mykonos_config.device, &gain)); @@ -841,18 +755,15 @@ double ad937x_device::get_gain( } } -std::vector<int16_t> ad937x_device::get_fir( - const direction_t direction, - int8_t &gain) +std::vector<int16_t> ad937x_device::get_fir(const direction_t direction, int8_t& gain) { - switch (direction) - { - case TX_DIRECTION: - return mykonos_config.tx_fir_config.get_fir(gain); - case RX_DIRECTION: - return mykonos_config.rx_fir_config.get_fir(gain); - default: - MPM_THROW_INVALID_CODE_PATH(); + switch (direction) { + case TX_DIRECTION: + return mykonos_config.tx_fir_config.get_fir(gain); + case RX_DIRECTION: + return mykonos_config.rx_fir_config.get_fir(gain); + default: + MPM_THROW_INVALID_CODE_PATH(); } } @@ -868,95 +779,89 @@ int16_t ad937x_device::get_temperature() 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(); + 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 55c6f0cad..8ee77db54 100644 --- a/mpm/lib/mykonos/ad937x_device.hpp +++ b/mpm/lib/mykonos/ad937x_device.hpp @@ -6,29 +6,27 @@ #pragma once +#include "ad937x_device_types.hpp" +#include "adi/mykonos_debug/t_mykonos_dbgjesd.h" +#include "adi/t_mykonos.h" +#include "adi/t_mykonos_gpio.h" #include "config/ad937x_config_t.hpp" #include "config/ad937x_fir.hpp" #include "config/ad937x_gain_ctrl_config.hpp" -#include "mpm/ad937x/adi_ctrl.hpp" -#include "ad937x_device_types.hpp" #include "mpm/ad937x/ad937x_ctrl_types.hpp" -#include "adi/t_mykonos.h" -#include "adi/t_mykonos_gpio.h" -#include "adi/mykonos_debug/t_mykonos_dbgjesd.h" - -#include <mpm/spi/spi_iface.hpp> +#include "mpm/ad937x/adi_ctrl.hpp" #include <mpm/exception.hpp> -#include <boost/noncopyable.hpp> +#include <mpm/spi/spi_iface.hpp> #include <boost/filesystem.hpp> -#include <memory> +#include <boost/noncopyable.hpp> #include <functional> +#include <memory> class ad937x_device : public boost::noncopyable { public: enum class gain_mode_t { MANUAL, AUTOMATIC, HYBRID }; - enum pll_t : uint8_t - { + enum pll_t : uint8_t { CLK_SYNTH = 0x01, RX_SYNTH = 0x02, TX_SYNTH = 0x04, @@ -36,30 +34,18 @@ public: CALPLL_SDM = 0x10, }; - enum mcr_t - { - MCR_122_88MHZ, - MCR_125_00MHZ, - MCR_153_60MHZ - }; + enum mcr_t { MCR_122_88MHZ, MCR_125_00MHZ, MCR_153_60MHZ }; - ad937x_device( - mpm::types::regs_iface* iface, + ad937x_device(mpm::types::regs_iface* iface, const size_t deserializer_lane_xbar, - mpm::ad937x::gpio::gain_pins_t gain_pins - ); + mpm::ad937x::gpio::gain_pins_t gain_pins); void begin_initialization(); void finish_initialization(); - 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 - ); + 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(); @@ -77,66 +63,38 @@ public: mpm::ad937x::device::api_version_t get_api_version(); mpm::ad937x::device::arm_version_t get_arm_version(); - double set_bw_filter( - const uhd::direction_t direction, - const double value - ); - void set_agc_mode( - const uhd::direction_t direction, - const gain_mode_t mode - ); + double set_bw_filter(const uhd::direction_t direction, 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( - const uhd::direction_t direction, - const mpm::ad937x::device::chain_t chain, - const double value - ); + void enable_channel(const uhd::direction_t direction, + const mpm::ad937x::device::chain_t chain, + const bool enable); + + 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 - ); + const uhd::direction_t direction, const mpm::ad937x::device::chain_t chain); double tune( - const uhd::direction_t direction, - const double value, - const bool wait_for_lock - ); + 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( - const uint8_t pll, - const bool wait_for_lock=false - ); + bool get_pll_lock_status(const uint8_t pll, const bool wait_for_lock = false); 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 - ); + 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( - 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 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(); @@ -160,9 +118,7 @@ private: ad937x_gain_ctrl_config_t gain_ctrl; void _apply_gain_pins( - const uhd::direction_t direction, - mpm::ad937x::device::chain_t chain - ); + 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); diff --git a/mpm/lib/mykonos/ad937x_device_types.hpp b/mpm/lib/mykonos/ad937x_device_types.hpp index e4330d278..bdf995c15 100644 --- a/mpm/lib/mykonos/ad937x_device_types.hpp +++ b/mpm/lib/mykonos/ad937x_device_types.hpp @@ -11,27 +11,24 @@ #include <uhd/types/direction.hpp> #include <uhd/types/ranges.hpp> -namespace mpm { - namespace ad937x { - namespace device { - enum class build_type_t { RELEASE, DEBUG, TEST_OBJECT }; - - struct api_version_t { - uint32_t silicon_ver; - uint32_t major_ver; - uint32_t minor_ver; - uint32_t build_ver; - }; - - struct arm_version_t { - uint8_t major_ver; - uint8_t minor_ver; - uint8_t rc_ver; - build_type_t build_type; - }; - - enum class chain_t { ONE, TWO }; - } - } -} - +namespace mpm { namespace ad937x { namespace device { +enum class build_type_t { RELEASE, DEBUG, TEST_OBJECT }; + +struct api_version_t +{ + uint32_t silicon_ver; + uint32_t major_ver; + uint32_t minor_ver; + uint32_t build_ver; +}; + +struct arm_version_t +{ + uint8_t major_ver; + uint8_t minor_ver; + uint8_t rc_ver; + build_type_t build_type; +}; + +enum class chain_t { ONE, TWO }; +}}} // namespace mpm::ad937x::device diff --git a/mpm/lib/mykonos/ad937x_spi_iface.cpp b/mpm/lib/mykonos/ad937x_spi_iface.cpp index d78f4951f..3944c2906 100644 --- a/mpm/lib/mykonos/ad937x_spi_iface.cpp +++ b/mpm/lib/mykonos/ad937x_spi_iface.cpp @@ -9,22 +9,17 @@ using namespace mpm::spi; -static const int MYK_SPI_SPEED_HZ = 20000000; +static const int MYK_SPI_SPEED_HZ = 20000000; static const size_t MYK_ADDR_SHIFT = 8; static const size_t MYK_DATA_SHIFT = 0; -static const size_t MYK_READ_FLAG = 1 << 23; +static const size_t MYK_READ_FLAG = 1 << 23; static const size_t MYK_WRITE_FLAG = 0; -mpm::types::regs_iface::sptr mpm::chips::make_ad937x_iface( - const std::string &spi_device -) { - return make_spi_regs_iface( - spi_iface::make_spidev(spi_device, MYK_SPI_SPEED_HZ), +mpm::types::regs_iface::sptr mpm::chips::make_ad937x_iface(const std::string& spi_device) +{ + return make_spi_regs_iface(spi_iface::make_spidev(spi_device, MYK_SPI_SPEED_HZ), MYK_ADDR_SHIFT, MYK_DATA_SHIFT, MYK_READ_FLAG, - MYK_WRITE_FLAG - ); + MYK_WRITE_FLAG); } - - diff --git a/mpm/lib/mykonos/adi_ctrl.cpp b/mpm/lib/mykonos/adi_ctrl.cpp index 2ae0ef663..83e363bc8 100644 --- a/mpm/lib/mykonos/adi_ctrl.cpp +++ b/mpm/lib/mykonos/adi_ctrl.cpp @@ -5,32 +5,28 @@ // #include "adi/common.h" - +#include <uhd/exception.hpp> #include <mpm/ad937x/adi_ctrl.hpp> #include <mpm/types/log_buf.hpp> -#include <uhd/exception.hpp> #include <boost/format.hpp> - -#include <iostream> #include <chrono> -#include <thread> +#include <iostream> #include <sstream> +#include <thread> -ad9371_spiSettings_t::ad9371_spiSettings_t( - mpm::types::regs_iface* spi_iface_ -) : - spi_iface(spi_iface_) +ad9371_spiSettings_t::ad9371_spiSettings_t(mpm::types::regs_iface* spi_iface_) + : spi_iface(spi_iface_) { - spi_settings.chipSelectIndex = 0; // set later - spi_settings.writeBitPolarity = 1; // unused + spi_settings.chipSelectIndex = 0; // set later + spi_settings.writeBitPolarity = 1; // unused spi_settings.longInstructionWord = 1; - spi_settings.MSBFirst = 1; - spi_settings.CPHA = 0; - spi_settings.CPOL = 0; - spi_settings.enSpiStreaming = 0; // unused - spi_settings.autoIncAddrUp = 0; // unused - spi_settings.fourWireMode = 1; // unused - spi_settings.spiClkFreq_Hz = 250000000; // currently unused + spi_settings.MSBFirst = 1; + spi_settings.CPHA = 0; + spi_settings.CPOL = 0; + spi_settings.enSpiStreaming = 0; // unused + spi_settings.autoIncAddrUp = 0; // unused + spi_settings.fourWireMode = 1; // unused + spi_settings.spiClkFreq_Hz = 250000000; // currently unused } // TODO: change // not implemented to meaningful errors @@ -61,7 +57,7 @@ commonErr_t CMB_hardReset(uint8_t spiChipSelectIndex) // // allows the platform HAL to work with devices with various SPI settings -commonErr_t CMB_setSPIOptions(spiSettings_t *spiSettings) +commonErr_t CMB_setSPIOptions(spiSettings_t* spiSettings) { // not implemented return COMMONERR_OK; @@ -75,22 +71,21 @@ commonErr_t CMB_setSPIChannel(uint16_t chipSelectIndex) } // single SPI byte write function -commonErr_t CMB_SPIWriteByte(spiSettings_t *spiSettings, uint16_t addr, uint8_t data) +commonErr_t CMB_SPIWriteByte(spiSettings_t* spiSettings, uint16_t addr, uint8_t data) { if (spiSettings == nullptr || spiSettings->MSBFirst == 0) { return COMMONERR_FAILED; } - ad9371_spiSettings_t *spi = ad9371_spiSettings_t::make(spiSettings); + ad9371_spiSettings_t* spi = ad9371_spiSettings_t::make(spiSettings); try { spi->spi_iface->poke8(addr, data); return COMMONERR_OK; - } catch (const std::exception &e) { + } catch (const std::exception& e) { // TODO: spit out a reasonable error here (that will survive the C API transition) std::stringstream ss; ss << "Error in CMB_SPIWriteByte: " << e.what(); - CMB_writeToLog( - ADIHAL_LOG_ERROR, + CMB_writeToLog(ADIHAL_LOG_ERROR, spiSettings->chipSelectIndex, ad9371_spi_errors_t::SPI_WRITE_ERROR, ss.str().c_str()); @@ -99,31 +94,27 @@ commonErr_t CMB_SPIWriteByte(spiSettings_t *spiSettings, uint16_t addr, uint8_t } // multi SPI byte write function (address, data pairs) -commonErr_t CMB_SPIWriteBytes(spiSettings_t *spiSettings, uint16_t *addr, uint8_t *data, uint32_t count) +commonErr_t CMB_SPIWriteBytes( + spiSettings_t* spiSettings, uint16_t* addr, uint8_t* data, uint32_t count) { - if (spiSettings == nullptr || - addr == nullptr || - data == nullptr || - spiSettings->MSBFirst == 0) - { + if (spiSettings == nullptr || addr == nullptr || data == nullptr + || spiSettings->MSBFirst == 0) { return COMMONERR_FAILED; } - ad9371_spiSettings_t *spi = ad9371_spiSettings_t::make(spiSettings); + ad9371_spiSettings_t* spi = ad9371_spiSettings_t::make(spiSettings); try { - for (size_t i = 0; i < count; ++i) - { + for (size_t i = 0; i < count; ++i) { uint32_t data_word = (0) | (addr[i] << 8) | (data[i]); spi->spi_iface->poke8(addr[i], data[i]); } return COMMONERR_OK; - } catch (const std::exception &e) { + } catch (const std::exception& e) { // TODO: spit out a reasonable error here (that will survive the C API transition) std::stringstream ss; ss << "Error in CMB_SPIWriteBytes: " << e.what(); - CMB_writeToLog( - ADIHAL_LOG_ERROR, + CMB_writeToLog(ADIHAL_LOG_ERROR, spiSettings->chipSelectIndex, ad9371_spi_errors_t::SPI_WRITE_ERROR, ss.str().c_str()); @@ -132,25 +123,21 @@ commonErr_t CMB_SPIWriteBytes(spiSettings_t *spiSettings, uint16_t *addr, uint8_ } // single SPI byte read function -commonErr_t CMB_SPIReadByte (spiSettings_t *spiSettings, uint16_t addr, uint8_t *readdata) +commonErr_t CMB_SPIReadByte(spiSettings_t* spiSettings, uint16_t addr, uint8_t* readdata) { - if (spiSettings == nullptr || - readdata == nullptr || - spiSettings->MSBFirst == 0) - { + if (spiSettings == nullptr || readdata == nullptr || spiSettings->MSBFirst == 0) { return COMMONERR_FAILED; } - ad9371_spiSettings_t *spi = ad9371_spiSettings_t::make(spiSettings); + ad9371_spiSettings_t* spi = ad9371_spiSettings_t::make(spiSettings); try { *readdata = spi->spi_iface->peek8(addr); return COMMONERR_OK; - } catch (const std::exception &e) { + } catch (const std::exception& e) { // TODO: spit out a reasonable error here (that will survive the C API transition) std::stringstream ss; ss << "Error in CMB_SPIReadByte: " << e.what(); - CMB_writeToLog( - ADIHAL_LOG_ERROR, + CMB_writeToLog(ADIHAL_LOG_ERROR, spiSettings->chipSelectIndex, ad9371_spi_errors_t::SPI_READ_ERROR, ss.str().c_str()); @@ -159,24 +146,24 @@ commonErr_t CMB_SPIReadByte (spiSettings_t *spiSettings, uint16_t addr, uint8_t } // write a field in a single register -commonErr_t CMB_SPIWriteField( - spiSettings_t *spiSettings, - uint16_t addr, uint8_t field_val, - uint8_t mask, uint8_t start_bit -) { - ad9371_spiSettings_t *spi = ad9371_spiSettings_t::make(spiSettings); +commonErr_t CMB_SPIWriteField(spiSettings_t* spiSettings, + uint16_t addr, + uint8_t field_val, + uint8_t mask, + uint8_t start_bit) +{ + ad9371_spiSettings_t* spi = ad9371_spiSettings_t::make(spiSettings); try { uint8_t current_value = spi->spi_iface->peek8(addr); - uint8_t new_value = ((current_value & ~mask) | (field_val << start_bit)); + uint8_t new_value = ((current_value & ~mask) | (field_val << start_bit)); spi->spi_iface->poke8(addr, new_value); return COMMONERR_OK; - } catch (const std::exception &e) { + } catch (const std::exception& e) { // TODO: spit out a reasonable error here (that will survive the C API transition) std::stringstream ss; ss << "Error in CMB_SPIWriteField: " << e.what(); - CMB_writeToLog( - ADIHAL_LOG_ERROR, + CMB_writeToLog(ADIHAL_LOG_ERROR, spiSettings->chipSelectIndex, ad9371_spi_errors_t::SPI_WRITE_ERROR, ss.str().c_str()); @@ -186,23 +173,23 @@ commonErr_t CMB_SPIWriteField( // read a field in a single register -commonErr_t CMB_SPIReadField( - spiSettings_t *spiSettings, - uint16_t addr, uint8_t *field_val, - uint8_t mask, uint8_t start_bit -) { - ad9371_spiSettings_t *spi = ad9371_spiSettings_t::make(spiSettings); +commonErr_t CMB_SPIReadField(spiSettings_t* spiSettings, + uint16_t addr, + uint8_t* field_val, + uint8_t mask, + uint8_t start_bit) +{ + ad9371_spiSettings_t* spi = ad9371_spiSettings_t::make(spiSettings); try { uint8_t value = spi->spi_iface->peek8(addr); - *field_val = static_cast<uint8_t>((value & mask) >> start_bit); + *field_val = static_cast<uint8_t>((value & mask) >> start_bit); return COMMONERR_OK; - } catch (const std::exception &e) { + } catch (const std::exception& e) { // TODO: spit out a reasonable error here (that will survive the C API transition) std::stringstream ss; ss << "Error in CMB_SPIReadField: " << e.what(); - CMB_writeToLog( - ADIHAL_LOG_ERROR, + CMB_writeToLog(ADIHAL_LOG_ERROR, spiSettings->chipSelectIndex, ad9371_spi_errors_t::SPI_READ_ERROR, ss.str().c_str()); @@ -223,35 +210,34 @@ commonErr_t CMB_wait_us(uint32_t time_us) return COMMONERR_OK; } -commonErr_t CMB_setTimeout_ms(spiSettings_t *spiSettings, uint32_t timeOut_ms) +commonErr_t CMB_setTimeout_ms(spiSettings_t* spiSettings, uint32_t timeOut_ms) { - ad9371_spiSettings_t *mpm_spi = ad9371_spiSettings_t::make(spiSettings); - mpm_spi->timeout_start = std::chrono::steady_clock::now(); - mpm_spi->timeout_duration = std::chrono::milliseconds(timeOut_ms); + ad9371_spiSettings_t* mpm_spi = ad9371_spiSettings_t::make(spiSettings); + mpm_spi->timeout_start = std::chrono::steady_clock::now(); + mpm_spi->timeout_duration = std::chrono::milliseconds(timeOut_ms); return COMMONERR_OK; } -commonErr_t CMB_setTimeout_us(spiSettings_t *spiSettings, uint32_t timeOut_us) +commonErr_t CMB_setTimeout_us(spiSettings_t* spiSettings, uint32_t timeOut_us) { - ad9371_spiSettings_t *mpm_spi = ad9371_spiSettings_t::make(spiSettings); - mpm_spi->timeout_start = std::chrono::steady_clock::now(); - mpm_spi->timeout_duration = std::chrono::microseconds(timeOut_us); + ad9371_spiSettings_t* mpm_spi = ad9371_spiSettings_t::make(spiSettings); + mpm_spi->timeout_start = std::chrono::steady_clock::now(); + mpm_spi->timeout_duration = std::chrono::microseconds(timeOut_us); return COMMONERR_OK; } -commonErr_t CMB_hasTimeoutExpired(spiSettings_t *spiSettings) +commonErr_t CMB_hasTimeoutExpired(spiSettings_t* spiSettings) { - ad9371_spiSettings_t *mpm_spi = ad9371_spiSettings_t::make(spiSettings); - auto current_time = std::chrono::steady_clock::now(); - if ((std::chrono::steady_clock::now() - mpm_spi->timeout_start) > mpm_spi->timeout_duration) - { + ad9371_spiSettings_t* mpm_spi = ad9371_spiSettings_t::make(spiSettings); + auto current_time = std::chrono::steady_clock::now(); + if ((std::chrono::steady_clock::now() - mpm_spi->timeout_start) + > mpm_spi->timeout_duration) { return COMMONERR_FAILED; - } - else { + } else { return COMMONERR_OK; } } // platform logging functions -commonErr_t CMB_openLog(const char *filename) +commonErr_t CMB_openLog(const char* filename) { // not implemented return COMMONERR_FAILED; @@ -263,22 +249,17 @@ commonErr_t CMB_closeLog(void) } commonErr_t CMB_writeToLog( - ADI_LOGLEVEL level, - uint8_t deviceIndex, - uint32_t errorCode, - const char *comment -) { + ADI_LOGLEVEL level, uint8_t deviceIndex, uint32_t errorCode, const char* comment) +{ mpm::types::log_level_t mpm_log_level; if (level & ADIHAL_LOG_ERROR) { mpm_log_level = mpm::types::log_level_t::ERROR; - } - else if (level & ADIHAL_LOG_WARNING) { + } else if (level & ADIHAL_LOG_WARNING) { mpm_log_level = mpm::types::log_level_t::WARNING; - } - else { + } else { mpm_log_level = mpm::types::log_level_t::TRACE; } - //FIXME: This caused segfault with the async pattern call to c++ from boost python + // FIXME: This caused segfault with the async pattern call to c++ from boost python // mpm::types::log_buf::make_singleton()->post( // mpm_log_level, // "AD937X", @@ -295,7 +276,7 @@ commonErr_t CMB_flushLog(void) } /* platform FPGA AXI register read/write functions */ -commonErr_t CMB_regRead(uint32_t offset, uint32_t *data) +commonErr_t CMB_regRead(uint32_t offset, uint32_t* data) { // not implemented return COMMONERR_FAILED; @@ -307,12 +288,12 @@ commonErr_t CMB_regWrite(uint32_t offset, uint32_t data) } /* platform DDR3 memory read/write functions */ -commonErr_t CMB_memRead(uint32_t offset, uint32_t *data, uint32_t len) +commonErr_t CMB_memRead(uint32_t offset, uint32_t* data, uint32_t len) { // not implemented return COMMONERR_FAILED; } -commonErr_t CMB_memWrite(uint32_t offset, uint32_t *data, uint32_t len) +commonErr_t CMB_memWrite(uint32_t offset, uint32_t* data, uint32_t len) { // not implemented return COMMONERR_FAILED; diff --git a/mpm/lib/mykonos/config/ad937x_config_t.cpp b/mpm/lib/mykonos/config/ad937x_config_t.cpp index 9bebeafad..97651b0b4 100644 --- a/mpm/lib/mykonos/config/ad937x_config_t.cpp +++ b/mpm/lib/mykonos/config/ad937x_config_t.cpp @@ -7,87 +7,421 @@ #include "ad937x_config_t.hpp" #include "ad937x_default_config.hpp" -const int16_t ad937x_config_t::DEFAULT_TX_FIR[DEFAULT_TX_FIR_SIZE] = - { -94, -26, 282, 177, -438, -368, 756, 732,-1170,-1337, 1758, 2479,-2648,-5088, 4064,16760, - 16759, 4110,-4881,-2247, 2888, 1917,-1440,-1296, 745, 828, -358, -474, 164, 298, -16, -94 }; - -const int16_t ad937x_config_t::DEFAULT_TX_FIR_15366[DEFAULT_TX_FIR_SIZE] = - { 4, -16, -5, 75, -13, -229, 85, 547, -293,-1158, 738, 2290,-1640,-4805, 3687,17108, - 17108, 3687,-4805,-1640, 2290, 738,-1158, -293, 547, 85, -229, -13, 75, -5, -16, 4 }; - -const int16_t ad937x_config_t::DEFAULT_RX_FIR[DEFAULT_RX_FIR_SIZE] = - { -20, 6, 66, 22, -128, -54, 240, 126, -402, -248, 634, 444, -956, -756, 1400, 1244, - -2028,-2050, 2978, 3538,-4646,-7046, 9536,30880,30880, 9536,-7046,-4646, 3538, 2978,-2050,-2028, - 1244, 1400, -756, -956, 444, 634, -248, -402, 126, 240, -54, -128, 22, 66, 6, -20 }; - -const int16_t ad937x_config_t::DEFAULT_RX_FIR_15366[DEFAULT_RX_FIR_SIZE] = - { -16, -22, 18, 74, 24, -132, -152, 132, 372, 38, -598, -474, 638, 1178, -206,-1952, - -984, 2362, 3152,-1612,-6544,-2164,12806,26836,26836,12806,-2164,-6544,-1612, 3152, 2362, -984, - -1952, -206, 1178, 638, -474, -598, 38, 372, 132, -152, -132, 24, 74, 18, -22, -16 }; - -const int16_t ad937x_config_t::DEFAULT_OBSRX_FIR[DEFAULT_RX_FIR_SIZE] = - { -14, -19, 44, 41, -89, -95, 175, 178, -303, -317, 499, 527, -779, -843, 1184, 1317, - -1781,-2059, 2760, 3350,-4962,-7433, 9822,32154,32154, 9822,-7433,-4962, 3350, 2760,-2059,-1781, - 1317, 1184, -843, -779, 527, 499, -317, -303, 178, 175, -95, -89, 41, 44, -19, -14 }; - -const int16_t ad937x_config_t::DEFAULT_OBSRX_FIR_15366[DEFAULT_RX_FIR_SIZE] = - { -2, 3, 12, -19, -28, 44, 74, -92, -169, 150, 353, -203, -671, 203, 1179, -66, - -1952, -347, 3153, 1307,-5595,-4820,11323,29525,29525,11323,-4820,-5595, 1307, 3153, -347,-1952, - -66, 1179, 203, -671, -203, 353, 150, -169, -92, 74, 44, -28, -19, 12, 3, -2 }; - -const int16_t ad937x_config_t::DEFAULT_SNIFFER_FIR[DEFAULT_RX_FIR_SIZE] = - { -1, -5, -14, -23, -16, 24, 92, 137, 80, -120, -378, -471, -174, 507, 1174, 1183, - 98,-1771,-3216,-2641, 942, 7027,13533,17738,17738,13533, 7027, 942,-2641,-3216,-1771, 98, - 1183, 1174, 507, -174, -471, -378, -120, 80, 137, 92, 24, -16, -23, -14, -5, -1 }; - -const int16_t ad937x_config_t::DEFAULT_SNIFFER_FIR_15366[DEFAULT_RX_FIR_SIZE] = - { 10, 31, 59, 71, 30, -92, -283, -456, -466, -175, 440, 1192, 1683, 1444, 198,-1871, - -3988, -4942,-3512, 958, 8118,16519,23993,28395,28395,23993,16519, 8118, 958,-3512,-4942,-3988, - -1871, 198, 1444, 1683, 1192, 440, -175, -466, -456, -283, -92, 30, 71, 59, 31, 10 }; - -ad937x_config_t::ad937x_config_t(spiSettings_t* sps, const size_t deserializer_lane_xbar) : - _rx(DEFAULT_RX_SETTINGS), - _rxProfile(DEFAULT_RX_PROFILE), - _framer(DEFAULT_FRAMER), - _rxGainCtrl(DEFAULT_RX_GAIN), - _rxPeakAgc(DEFAULT_RX_PEAK_AGC), - _rxPowerAgc(DEFAULT_RX_POWER_AGC), - _rxAgcCtrl(DEFAULT_RX_AGC_CTRL), - - _tx(DEFAULT_TX_SETTINGS), - _txProfile(DEFAULT_TX_PROFILE), - _deframer(DEFAULT_DEFRAMER), +const int16_t ad937x_config_t::DEFAULT_TX_FIR[DEFAULT_TX_FIR_SIZE] = {-94, + -26, + 282, + 177, + -438, + -368, + 756, + 732, + -1170, + -1337, + 1758, + 2479, + -2648, + -5088, + 4064, + 16760, + 16759, + 4110, + -4881, + -2247, + 2888, + 1917, + -1440, + -1296, + 745, + 828, + -358, + -474, + 164, + 298, + -16, + -94}; + +const int16_t ad937x_config_t::DEFAULT_TX_FIR_15366[DEFAULT_TX_FIR_SIZE] = {4, + -16, + -5, + 75, + -13, + -229, + 85, + 547, + -293, + -1158, + 738, + 2290, + -1640, + -4805, + 3687, + 17108, + 17108, + 3687, + -4805, + -1640, + 2290, + 738, + -1158, + -293, + 547, + 85, + -229, + -13, + 75, + -5, + -16, + 4}; + +const int16_t ad937x_config_t::DEFAULT_RX_FIR[DEFAULT_RX_FIR_SIZE] = {-20, + 6, + 66, + 22, + -128, + -54, + 240, + 126, + -402, + -248, + 634, + 444, + -956, + -756, + 1400, + 1244, + -2028, + -2050, + 2978, + 3538, + -4646, + -7046, + 9536, + 30880, + 30880, + 9536, + -7046, + -4646, + 3538, + 2978, + -2050, + -2028, + 1244, + 1400, + -756, + -956, + 444, + 634, + -248, + -402, + 126, + 240, + -54, + -128, + 22, + 66, + 6, + -20}; + +const int16_t ad937x_config_t::DEFAULT_RX_FIR_15366[DEFAULT_RX_FIR_SIZE] = {-16, + -22, + 18, + 74, + 24, + -132, + -152, + 132, + 372, + 38, + -598, + -474, + 638, + 1178, + -206, + -1952, + -984, + 2362, + 3152, + -1612, + -6544, + -2164, + 12806, + 26836, + 26836, + 12806, + -2164, + -6544, + -1612, + 3152, + 2362, + -984, + -1952, + -206, + 1178, + 638, + -474, + -598, + 38, + 372, + 132, + -152, + -132, + 24, + 74, + 18, + -22, + -16}; + +const int16_t ad937x_config_t::DEFAULT_OBSRX_FIR[DEFAULT_RX_FIR_SIZE] = {-14, + -19, + 44, + 41, + -89, + -95, + 175, + 178, + -303, + -317, + 499, + 527, + -779, + -843, + 1184, + 1317, + -1781, + -2059, + 2760, + 3350, + -4962, + -7433, + 9822, + 32154, + 32154, + 9822, + -7433, + -4962, + 3350, + 2760, + -2059, + -1781, + 1317, + 1184, + -843, + -779, + 527, + 499, + -317, + -303, + 178, + 175, + -95, + -89, + 41, + 44, + -19, + -14}; + +const int16_t ad937x_config_t::DEFAULT_OBSRX_FIR_15366[DEFAULT_RX_FIR_SIZE] = {-2, + 3, + 12, + -19, + -28, + 44, + 74, + -92, + -169, + 150, + 353, + -203, + -671, + 203, + 1179, + -66, + -1952, + -347, + 3153, + 1307, + -5595, + -4820, + 11323, + 29525, + 29525, + 11323, + -4820, + -5595, + 1307, + 3153, + -347, + -1952, + -66, + 1179, + 203, + -671, + -203, + 353, + 150, + -169, + -92, + 74, + 44, + -28, + -19, + 12, + 3, + -2}; + +const int16_t ad937x_config_t::DEFAULT_SNIFFER_FIR[DEFAULT_RX_FIR_SIZE] = {-1, + -5, + -14, + -23, + -16, + 24, + 92, + 137, + 80, + -120, + -378, + -471, + -174, + 507, + 1174, + 1183, + 98, + -1771, + -3216, + -2641, + 942, + 7027, + 13533, + 17738, + 17738, + 13533, + 7027, + 942, + -2641, + -3216, + -1771, + 98, + 1183, + 1174, + 507, + -174, + -471, + -378, + -120, + 80, + 137, + 92, + 24, + -16, + -23, + -14, + -5, + -1}; + +const int16_t ad937x_config_t::DEFAULT_SNIFFER_FIR_15366[DEFAULT_RX_FIR_SIZE] = {10, + 31, + 59, + 71, + 30, + -92, + -283, + -456, + -466, + -175, + 440, + 1192, + 1683, + 1444, + 198, + -1871, + -3988, + -4942, + -3512, + 958, + 8118, + 16519, + 23993, + 28395, + 28395, + 23993, + 16519, + 8118, + 958, + -3512, + -4942, + -3988, + -1871, + 198, + 1444, + 1683, + 1192, + 440, + -175, + -466, + -456, + -283, + -92, + 30, + 71, + 59, + 31, + 10}; + +ad937x_config_t::ad937x_config_t(spiSettings_t* sps, const size_t deserializer_lane_xbar) + : _rx(DEFAULT_RX_SETTINGS) + , _rxProfile(DEFAULT_RX_PROFILE) + , _framer(DEFAULT_FRAMER) + , _rxGainCtrl(DEFAULT_RX_GAIN) + , _rxPeakAgc(DEFAULT_RX_PEAK_AGC) + , _rxPowerAgc(DEFAULT_RX_POWER_AGC) + , _rxAgcCtrl(DEFAULT_RX_AGC_CTRL) + , + + _tx(DEFAULT_TX_SETTINGS) + , _txProfile(DEFAULT_TX_PROFILE) + , _deframer(DEFAULT_DEFRAMER) + , // TODO: Remove if ADI ever fixes this // The TX bring up requires a valid ORX profile // https://github.com/EttusResearch/uhddev/blob/f0f8f58471c3fed94279c32f00e9f8da7db40efd/mpm/lib/mykonos/adi/mykonos.c#L16590 - _obsRx(DEFAULT_ORX_SETTINGS), - _orxFramer(DEFAULT_ORX_FRAMER), - _orxProfile(DEFAULT_ORX_PROFILE), - _orxGainCtrl(DEFAULT_ORX_GAIN), - _orxPeakAgc(DEFAULT_ORX_PEAK_AGC), - _orxPowerAgc(DEFAULT_ORX_POWER_AGC), - _orxAgcCtrl(DEFAULT_ORX_AGC_CTRL), + _obsRx(DEFAULT_ORX_SETTINGS) + , _orxFramer(DEFAULT_ORX_FRAMER) + , _orxProfile(DEFAULT_ORX_PROFILE) + , _orxGainCtrl(DEFAULT_ORX_GAIN) + , _orxPeakAgc(DEFAULT_ORX_PEAK_AGC) + , _orxPowerAgc(DEFAULT_ORX_POWER_AGC) + , _orxAgcCtrl(DEFAULT_ORX_AGC_CTRL) + , // TODO: Remove if ADI ever fixes this // ORX bring up requires a valid sniffer gain control struct // https://github.com/EttusResearch/uhddev/blob/f0f8f58471c3fed94279c32f00e9f8da7db40efd/mpm/lib/mykonos/adi/mykonos.c#L5752 - _snifferGainCtrl(DEFAULT_SNIFFER_GAIN), + _snifferGainCtrl(DEFAULT_SNIFFER_GAIN) + , - _armGpio(DEFAULT_ARM_GPIO), - _gpio3v3(DEFAULT_GPIO_3V3), - _gpio(DEFAULT_GPIO), + _armGpio(DEFAULT_ARM_GPIO) + , _gpio3v3(DEFAULT_GPIO_3V3) + , _gpio(DEFAULT_GPIO) + , - _auxIo(DEFAULT_AUX_IO), - _clocks(DEFAULT_CLOCKS), + _auxIo(DEFAULT_AUX_IO) + , _clocks(DEFAULT_CLOCKS) + , - tx_fir_config(DEFAULT_TX_FIR_GAIN, std::vector<int16_t>(DEFAULT_TX_FIR, DEFAULT_TX_FIR + DEFAULT_TX_FIR_SIZE)), - rx_fir_config(DEFAULT_RX_FIR_GAIN, std::vector<int16_t>(DEFAULT_RX_FIR, DEFAULT_RX_FIR + DEFAULT_RX_FIR_SIZE)), - _orx_fir_config(DEFAULT_RX_FIR_GAIN, std::vector<int16_t>(DEFAULT_OBSRX_FIR, DEFAULT_OBSRX_FIR + DEFAULT_RX_FIR_SIZE)), - _sniffer_rx_fir_config(DEFAULT_RX_FIR_GAIN, std::vector<int16_t>(DEFAULT_SNIFFER_FIR, DEFAULT_SNIFFER_FIR + DEFAULT_RX_FIR_SIZE)) + tx_fir_config(DEFAULT_TX_FIR_GAIN, + std::vector<int16_t>(DEFAULT_TX_FIR, DEFAULT_TX_FIR + DEFAULT_TX_FIR_SIZE)) + , rx_fir_config(DEFAULT_RX_FIR_GAIN, + std::vector<int16_t>(DEFAULT_RX_FIR, DEFAULT_RX_FIR + DEFAULT_RX_FIR_SIZE)) + , _orx_fir_config(DEFAULT_RX_FIR_GAIN, + std::vector<int16_t>( + DEFAULT_OBSRX_FIR, DEFAULT_OBSRX_FIR + DEFAULT_RX_FIR_SIZE)) + , _sniffer_rx_fir_config(DEFAULT_RX_FIR_GAIN, + std::vector<int16_t>( + DEFAULT_SNIFFER_FIR, DEFAULT_SNIFFER_FIR + DEFAULT_RX_FIR_SIZE)) { - _device.spiSettings = sps; + _device.spiSettings = sps; _deframer.deserializerLaneCrossbar = deserializer_lane_xbar; _init_pointers(); @@ -95,52 +429,51 @@ ad937x_config_t::ad937x_config_t(spiSettings_t* sps, const size_t deserializer_l device = &_device; } -// 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. +// 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() { - _device.rx = &_rx; - _device.tx = &_tx; - _device.obsRx = &_obsRx; - _device.auxIo = &_auxIo; + _device.rx = &_rx; + _device.tx = &_tx; + _device.obsRx = &_obsRx; + _device.auxIo = &_auxIo; _device.clocks = &_clocks; - _rx.rxProfile = &_rxProfile; - _rx.framer = &_framer; - _rx.rxGainCtrl = &_rxGainCtrl; - _rx.rxAgcCtrl = &_rxAgcCtrl; - _rxProfile.rxFir = rx_fir_config.fir; + _rx.rxProfile = &_rxProfile; + _rx.framer = &_framer; + _rx.rxGainCtrl = &_rxGainCtrl; + _rx.rxAgcCtrl = &_rxAgcCtrl; + _rxProfile.rxFir = rx_fir_config.fir; _rxProfile.customAdcProfile = nullptr; - _rxAgcCtrl.peakAgc = &_rxPeakAgc; - _rxAgcCtrl.powerAgc = &_rxPowerAgc; + _rxAgcCtrl.peakAgc = &_rxPeakAgc; + _rxAgcCtrl.powerAgc = &_rxPowerAgc; - _tx.txProfile = &_txProfile; + _tx.txProfile = &_txProfile; _txProfile.txFir = tx_fir_config.fir; - _tx.deframer = &_deframer; + _tx.deframer = &_deframer; // AD9373 - _tx.dpdConfig = nullptr; + _tx.dpdConfig = nullptr; _tx.clgcConfig = nullptr; _tx.vswrConfig = nullptr; // TODO: ideally we set none of this information and leave the profile as nullptr // Check that the API supports this - _obsRx.orxProfile = &_orxProfile; - _obsRx.orxGainCtrl = &_orxGainCtrl; - _obsRx.orxAgcCtrl = &_orxAgcCtrl; - _orxProfile.rxFir = _orx_fir_config.fir; + _obsRx.orxProfile = &_orxProfile; + _obsRx.orxGainCtrl = &_orxGainCtrl; + _obsRx.orxAgcCtrl = &_orxAgcCtrl; + _orxProfile.rxFir = _orx_fir_config.fir; _orxProfile.customAdcProfile = nullptr; - _orxAgcCtrl.peakAgc = &_orxPeakAgc; - _orxAgcCtrl.powerAgc = &_orxPowerAgc; + _orxAgcCtrl.peakAgc = &_orxPeakAgc; + _orxAgcCtrl.powerAgc = &_orxPowerAgc; - _obsRx.snifferProfile = &_snifferProfile; - _snifferProfile.rxFir = _sniffer_rx_fir_config.fir; + _obsRx.snifferProfile = &_snifferProfile; + _snifferProfile.rxFir = _sniffer_rx_fir_config.fir; _obsRx.snifferGainCtrl = &_snifferGainCtrl; // sniffer has no AGC ctrl, so leave as null _obsRx.framer = &_orxFramer; _auxIo.gpio3v3 = &_gpio3v3; - _auxIo.gpio = &_gpio; + _auxIo.gpio = &_gpio; _auxIo.armGpio = &_armGpio; } - diff --git a/mpm/lib/mykonos/config/ad937x_config_t.hpp b/mpm/lib/mykonos/config/ad937x_config_t.hpp index 7cbabb9b5..ab5ddb894 100644 --- a/mpm/lib/mykonos/config/ad937x_config_t.hpp +++ b/mpm/lib/mykonos/config/ad937x_config_t.hpp @@ -10,11 +10,11 @@ #include "ad937x_fir.hpp" #include <boost/noncopyable.hpp> // Allocates and links the entire mykonos config struct in a single class -class ad937x_config_t : public boost::noncopyable +class ad937x_config_t : public boost::noncopyable { public: ad937x_config_t(spiSettings_t* sps, const size_t deserializer_lane_xbar); - mykonosDevice_t * device; + mykonosDevice_t* device; ad937x_fir rx_fir_config; ad937x_fir tx_fir_config; @@ -35,8 +35,9 @@ public: 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" - // a user could technically modify the pointers in the structs, but we have no way of preventing that + // The top level device struct is non-const and contains all other structs, so + // everything is "public" a user could technically modify the pointers in the structs, + // but we have no way of preventing that mykonosDevice_t _device; ad937x_fir _orx_fir_config; diff --git a/mpm/lib/mykonos/config/ad937x_default_config.hpp b/mpm/lib/mykonos/config/ad937x_default_config.hpp index e01c0c6d3..72fbd6cf5 100644 --- a/mpm/lib/mykonos/config/ad937x_default_config.hpp +++ b/mpm/lib/mykonos/config/ad937x_default_config.hpp @@ -9,368 +9,396 @@ // This file is more or less the static config provided by a run of the eval software // except all pointers have been changed to nullptr // Hopefully this helps the compiler use these as purely constants -// The pointers should be filled in if these data structures are to be actually used with the API +// The pointers should be filled in if these data structures are to be actually used with +// the API -static const mykonosRxSettings_t DEFAULT_RX_SETTINGS = -{ - nullptr, // Rx datapath profile, 3dB corner frequencies, and digital filter enables - nullptr, // Rx JESD204b framer configuration structure - nullptr, // Rx Gain control settings structure - nullptr, // Rx AGC control settings structure - RX1_RX2, // The desired Rx Channels to enable during initialization - 0, // Internal LO = 0, external LO*2 = 1 - 3500000000U, // Rx PLL LO Frequency (internal or external LO) - 0 // Flag to choose if complex baseband or real IF data are selected for Rx and ObsRx paths. Where, if > 0 = real IF data, '0' = zero IF (IQ) data +static const mykonosRxSettings_t DEFAULT_RX_SETTINGS = { + nullptr, // Rx datapath profile, 3dB corner frequencies, and digital filter enables + nullptr, // Rx JESD204b framer configuration structure + nullptr, // Rx Gain control settings structure + nullptr, // Rx AGC control settings structure + RX1_RX2, // The desired Rx Channels to enable during initialization + 0, // Internal LO = 0, external LO*2 = 1 + 3500000000U, // Rx PLL LO Frequency (internal or external LO) + 0 // Flag to choose if complex baseband or real IF data are selected for Rx and ObsRx + // paths. Where, if > 0 = real IF data, '0' = zero IF (IQ) data }; -static const mykonosRxProfile_t DEFAULT_RX_PROFILE = -{ // Rx 100MHz, IQrate 125MSPS, Dec5 - 1, // The divider used to generate the ADC clock - nullptr, // Pointer to Rx FIR filter structure - 2, // Rx FIR decimation (1,2,4) - 5, // Decimation of Dec5 or Dec4 filter (5,4) - 1, // If set, and DEC5 filter used, will use a higher rejection DEC5 FIR filter (1=Enabled, 0=Disabled) - 1, // RX Half band 1 decimation (1 or 2) - 125000, // Rx IQ data rate in kHz - 100000000, // The Rx RF passband bandwidth for the profile - 102000, // Rx BBF 3dB corner in kHz - NULL // pointer to custom ADC profile +static const mykonosRxProfile_t DEFAULT_RX_PROFILE = { + // Rx 100MHz, IQrate 125MSPS, Dec5 + 1, // The divider used to generate the ADC clock + nullptr, // Pointer to Rx FIR filter structure + 2, // Rx FIR decimation (1,2,4) + 5, // Decimation of Dec5 or Dec4 filter (5,4) + 1, // If set, and DEC5 filter used, will use a higher rejection DEC5 FIR filter + // (1=Enabled, 0=Disabled) + 1, // RX Half band 1 decimation (1 or 2) + 125000, // Rx IQ data rate in kHz + 100000000, // The Rx RF passband bandwidth for the profile + 102000, // Rx BBF 3dB corner in kHz + NULL // pointer to custom ADC profile }; -static const mykonosJesd204bFramerConfig_t DEFAULT_FRAMER = -{ - 0, // JESD204B Configuration Bank ID -extension to Device ID (Valid 0..15) - 0, // JESD204B Configuration Device ID - link identification number. (Valid 0..255) - 0, // JESD204B Configuration starting Lane ID. If more than one lane used, each lane will increment from the Lane0 ID. (Valid 0..31) - 4, // number of ADCs (0, 2, or 4) - 2 ADCs per receive chain - 20, // number of frames in a multiframe (default=32), F*K must be a multiple of 4. (F=2*M/numberOfLanes) - 1, // scrambling off if framerScramble= 0, if framerScramble>0 scramble is enabled. - 1, // 0=use internal SYSREF, 1= use external SYSREF - 0x0F, // serializerLanesEnabled - bit per lane, [0] = Lane0 enabled, [1] = Lane1 enabled - 0x4B, // serializerLaneCrossbar - 26, // serializerAmplitude - default 22 (valid (0-31) - 0, // preEmphasis - < default 4 (valid 0 - 7) - 0, // invertLanePolarity - default 0 ([0] will invert lane [0], bit1 will invert lane1) - 0, // lmfcOffset - LMFC offset value for deterministic latency setting - 0, // Flag for determining if SYSREF on relink should be set. Where, if > 0 = set, 0 = not set - 0, // Flag for determining if auto channel select for the xbar should be set. Where, if > 0 = set, '0' = not set - 0, // Selects SYNCb input source. Where, 0 = use RXSYNCB for this framer, 1 = use OBSRX_SYNCB for this framer - 1, // Flag for determining if CMOS mode for RX Sync signal is used. Where, if > 0 = CMOS, '0' = LVDS - 0, // Selects framer bit repeat or oversampling mode for lane rate matching. Where, 0 = bitRepeat mode (changes effective lanerate), 1 = overSample (maintains same lane rate between ObsRx framer and Rx framer and oversamples the ADC samples) - 1 // Flag for determining if API will calculate the appropriate settings for framer lane outputs to physical lanes. Where, if '0' = API will set automatic lane crossbar, '1' = set to manual mode and the value in serializerLaneCrossbar will be used +static const mykonosJesd204bFramerConfig_t DEFAULT_FRAMER = { + 0, // JESD204B Configuration Bank ID -extension to Device ID (Valid 0..15) + 0, // JESD204B Configuration Device ID - link identification number. (Valid 0..255) + 0, // JESD204B Configuration starting Lane ID. If more than one lane used, each lane + // will increment from the Lane0 ID. (Valid 0..31) + 4, // number of ADCs (0, 2, or 4) - 2 ADCs per receive chain + 20, // number of frames in a multiframe (default=32), F*K must be a multiple of 4. + // (F=2*M/numberOfLanes) + 1, // scrambling off if framerScramble= 0, if framerScramble>0 scramble is enabled. + 1, // 0=use internal SYSREF, 1= use external SYSREF + 0x0F, // serializerLanesEnabled - bit per lane, [0] = Lane0 enabled, [1] = Lane1 + // enabled + 0x4B, // serializerLaneCrossbar + 26, // serializerAmplitude - default 22 (valid (0-31) + 0, // preEmphasis - < default 4 (valid 0 - 7) + 0, // invertLanePolarity - default 0 ([0] will invert lane [0], bit1 will invert + // lane1) + 0, // lmfcOffset - LMFC offset value for deterministic latency setting + 0, // Flag for determining if SYSREF on relink should be set. Where, if > 0 = set, 0 = + // not set + 0, // Flag for determining if auto channel select for the xbar should be set. Where, + // if > 0 = set, '0' = not set + 0, // Selects SYNCb input source. Where, 0 = use RXSYNCB for this framer, 1 = use + // OBSRX_SYNCB for this framer + 1, // Flag for determining if CMOS mode for RX Sync signal is used. Where, if > 0 = + // CMOS, '0' = LVDS + 0, // Selects framer bit repeat or oversampling mode for lane rate matching. Where, 0 + // = bitRepeat mode (changes effective lanerate), 1 = overSample (maintains same + // lane rate between ObsRx framer and Rx framer and oversamples the ADC samples) + 1 // Flag for determining if API will calculate the appropriate settings for framer + // lane outputs to physical lanes. Where, if '0' = API will set automatic lane + // crossbar, '1' = set to manual mode and the value in serializerLaneCrossbar will + // be used }; -static const mykonosRxGainControl_t DEFAULT_RX_GAIN = -{ - MGC, // Current Rx gain control mode setting - 255, // Rx1 Gain Index, can be used in different ways for manual and AGC gain control - 255, // Rx2 Gain Index, can be used in different ways for manual and AGC gain control - 255, // Max gain index for the currently loaded Rx1 Gain table - 195, // Min gain index for the currently loaded Rx1 Gain table - 255, // Max gain index for the currently loaded Rx2 Gain table - 195, // Min gain index for the currently loaded Rx2 Gain table - 0, // Stores Rx1 RSSI value read back from the Mykonos - 0 // Stores Rx2 RSSI value read back from the Mykonos +static const mykonosRxGainControl_t DEFAULT_RX_GAIN = { + MGC, // Current Rx gain control mode setting + 255, // Rx1 Gain Index, can be used in different ways for manual and AGC gain control + 255, // Rx2 Gain Index, can be used in different ways for manual and AGC gain control + 255, // Max gain index for the currently loaded Rx1 Gain table + 195, // Min gain index for the currently loaded Rx1 Gain table + 255, // Max gain index for the currently loaded Rx2 Gain table + 195, // Min gain index for the currently loaded Rx2 Gain table + 0, // Stores Rx1 RSSI value read back from the Mykonos + 0 // Stores Rx2 RSSI value read back from the Mykonos }; -static const mykonosPeakDetAgcCfg_t DEFAULT_RX_PEAK_AGC = -{ - 0x1F, // apdHighThresh: - 0x16, // apdLowThresh - 0xB5, // hb2HighThresh - 0x80, // hb2LowThresh - 0x40, // hb2VeryLowThresh - 0x06, // apdHighThreshExceededCnt - 0x04, // apdLowThreshExceededCnt - 0x06, // hb2HighThreshExceededCnt - 0x04, // hb2LowThreshExceededCnt - 0x04, // hb2VeryLowThreshExceededCnt - 0x4, // apdHighGainStepAttack - 0x2, // apdLowGainStepRecovery - 0x4, // hb2HighGainStepAttack - 0x2, // hb2LowGainStepRecovery - 0x4, // hb2VeryLowGainStepRecovery - 0x1, // apdFastAttack - 0x1, // hb2FastAttack - 0x1, // hb2OverloadDetectEnable - 0x1, // hb2OverloadDurationCnt - 0x1 // hb2OverloadThreshCnt +static const mykonosPeakDetAgcCfg_t DEFAULT_RX_PEAK_AGC = { + 0x1F, // apdHighThresh: + 0x16, // apdLowThresh + 0xB5, // hb2HighThresh + 0x80, // hb2LowThresh + 0x40, // hb2VeryLowThresh + 0x06, // apdHighThreshExceededCnt + 0x04, // apdLowThreshExceededCnt + 0x06, // hb2HighThreshExceededCnt + 0x04, // hb2LowThreshExceededCnt + 0x04, // hb2VeryLowThreshExceededCnt + 0x4, // apdHighGainStepAttack + 0x2, // apdLowGainStepRecovery + 0x4, // hb2HighGainStepAttack + 0x2, // hb2LowGainStepRecovery + 0x4, // hb2VeryLowGainStepRecovery + 0x1, // apdFastAttack + 0x1, // hb2FastAttack + 0x1, // hb2OverloadDetectEnable + 0x1, // hb2OverloadDurationCnt + 0x1 // hb2OverloadThreshCnt }; -static const mykonosPowerMeasAgcCfg_t DEFAULT_RX_POWER_AGC = -{ - 0x01, // pmdUpperHighThresh - 0x03, // pmdUpperLowThresh - 0x0C, // pmdLowerHighThresh - 0x04, // pmdLowerLowThresh - 0x4, // pmdUpperHighGainStepAttack - 0x2, // pmdUpperLowGainStepAttack - 0x2, // pmdLowerHighGainStepRecovery - 0x4, // pmdLowerLowGainStepRecovery - 0x08, // pmdMeasDuration - 0x02 // pmdMeasConfig +static const mykonosPowerMeasAgcCfg_t DEFAULT_RX_POWER_AGC = { + 0x01, // pmdUpperHighThresh + 0x03, // pmdUpperLowThresh + 0x0C, // pmdLowerHighThresh + 0x04, // pmdLowerLowThresh + 0x4, // pmdUpperHighGainStepAttack + 0x2, // pmdUpperLowGainStepAttack + 0x2, // pmdLowerHighGainStepRecovery + 0x4, // pmdLowerLowGainStepRecovery + 0x08, // pmdMeasDuration + 0x02 // pmdMeasConfig }; -static const mykonosAgcCfg_t DEFAULT_RX_AGC_CTRL = -{ - 255, // AGC peak wait time - 195, // agcRx1MinGainIndex - 255, // agcRx2MaxGainIndex - 195, // agcRx2MinGainIndex: - 255, // agcObsRxMaxGainIndex - 203, // agcObsRxMinGainIndex - 1, // agcObsRxSelect - 1, // agcPeakThresholdMode - 1, // agcLowThsPreventGainIncrease - 30720, // agcGainUpdateCounter - 3, // agcSlowLoopSettlingDelay - 2, // agcPeakWaitTime - 0, // agcResetOnRxEnable - 0, // agcEnableSyncPulseForGainCounter - nullptr,// *peakAgc +static const mykonosAgcCfg_t DEFAULT_RX_AGC_CTRL = { + 255, // AGC peak wait time + 195, // agcRx1MinGainIndex + 255, // agcRx2MaxGainIndex + 195, // agcRx2MinGainIndex: + 255, // agcObsRxMaxGainIndex + 203, // agcObsRxMinGainIndex + 1, // agcObsRxSelect + 1, // agcPeakThresholdMode + 1, // agcLowThsPreventGainIncrease + 30720, // agcGainUpdateCounter + 3, // agcSlowLoopSettlingDelay + 2, // agcPeakWaitTime + 0, // agcResetOnRxEnable + 0, // agcEnableSyncPulseForGainCounter + nullptr, // *peakAgc nullptr // *powerAgc }; -static const mykonosTxSettings_t DEFAULT_TX_SETTINGS = -{ - nullptr, // Tx datapath profile, 3dB corner frequencies, and digital filter enables - nullptr, // Mykonos JESD204b deframer config for the Tx data path - TX1_TX2, // The desired Tx channels to enable during initialization - 0, // Internal LO=0, external LO*2 if =1 - 3500000000U, // Tx PLL LO frequency (internal or external LO) - TXATTEN_0P05_DB,// Initial and current Tx1 Attenuation - 10000, // Initial and current Tx1 Attenuation mdB - 10000, // Initial and current Tx2 Attenuation mdB - nullptr, // DPD,CLGC,VSWR settings. Only valid for AD9373 device, set pointer to NULL otherwise - nullptr, // CLGC Config Structure. Only valid for AD9373 device, set pointer to NULL otherwise - nullptr // VSWR Config Structure. Only valid for AD9373 device, set pointer to NULL otherwise +static const mykonosTxSettings_t DEFAULT_TX_SETTINGS = { + nullptr, // Tx datapath profile, 3dB corner frequencies, and digital filter enables + nullptr, // Mykonos JESD204b deframer config for the Tx data path + TX1_TX2, // The desired Tx channels to enable during initialization + 0, // Internal LO=0, external LO*2 if =1 + 3500000000U, // Tx PLL LO frequency (internal or external LO) + TXATTEN_0P05_DB, // Initial and current Tx1 Attenuation + 10000, // Initial and current Tx1 Attenuation mdB + 10000, // Initial and current Tx2 Attenuation mdB + nullptr, // DPD,CLGC,VSWR settings. Only valid for AD9373 device, set pointer to NULL + // otherwise + nullptr, // CLGC Config Structure. Only valid for AD9373 device, set pointer to NULL + // otherwise + nullptr // VSWR Config Structure. Only valid for AD9373 device, set pointer to NULL + // otherwise }; -static const mykonosTxProfile_t DEFAULT_TX_PROFILE = -{ // Tx 20/100MHz, IQrate 122.88MHz, Dec5 - DACDIV_2p5, // The divider used to generate the DAC clock - nullptr, // Pointer to Tx FIR filter structure - 2, // The Tx digital FIR filter interpolation (1,2,4) - 2, // Tx Halfband1 filter interpolation (1,2) - 1, // Tx Halfband2 filter interpolation (1,2) - 1, // TxInputHbInterpolation (1,2) - 125000, // Tx IQ data rate in kHz - 20000000, // Primary Signal BW - 102000000, // The Tx RF passband bandwidth for the profile - 722000, // The DAC filter 3dB corner in kHz - 51000, // Tx BBF 3dB corner in kHz - 0 // Enable DPD, only valid for AD9373 +static const mykonosTxProfile_t DEFAULT_TX_PROFILE = { + // Tx 20/100MHz, IQrate 122.88MHz, Dec5 + DACDIV_2p5, // The divider used to generate the DAC clock + nullptr, // Pointer to Tx FIR filter structure + 2, // The Tx digital FIR filter interpolation (1,2,4) + 2, // Tx Halfband1 filter interpolation (1,2) + 1, // Tx Halfband2 filter interpolation (1,2) + 1, // TxInputHbInterpolation (1,2) + 125000, // Tx IQ data rate in kHz + 20000000, // Primary Signal BW + 102000000, // The Tx RF passband bandwidth for the profile + 722000, // The DAC filter 3dB corner in kHz + 51000, // Tx BBF 3dB corner in kHz + 0 // Enable DPD, only valid for AD9373 }; -static const mykonosJesd204bDeframerConfig_t DEFAULT_DEFRAMER = -{ - 0, // bankId extension to Device ID (Valid 0..15) - 0, // deviceId link identification number. (Valid 0..255) - 0, // lane0Id Lane0 ID. (Valid 0..31) - 4, // M number of DACss (0, 2, or 4) - 2 DACs per transmit chain - 20, // K #frames in a multiframe (default=32), F*K=multiple of 4. (F=2*M/numberOfLanes) - 0, // Scrambling off if scramble = 0, if framerScramble > 0 scrambling is enabled - 1, // External SYSREF select. 0 = use internal SYSREF, 1 = external SYSREF - 0x0F, // Deserializer lane select bit field. Where, [0] = Lane0 enabled, [1] = Lane1 enabled, etc - 0xD2, // Lane crossbar to map physical lanes to deframer lane inputs [1:0] = Deframer Input 0 Lane section, [3:2] = Deframer Input 1 lane select, etc - 1, // Equalizer setting. Applied to all deserializer lanes. Range is 0..4 - 0, // PN inversion per each lane. bit[0] = 1 Invert PN of Lane 0, bit[1] = Invert PN of Lane 1, etc). - 0, // LMFC offset value to adjust deterministic latency. Range is 0..31 - 0, // Flag for determining if SYSREF on relink should be set. Where, if > 0 = set, '0' = not set - 0, // Flag for determining if auto channel select for the xbar should be set. Where, if > 0 = set, '0' = not set - 1, // Flag for determining if CMOS mode for TX Sync signal is used. Where, if > 0 = CMOS, '0' = LVDS - 1, // Flag for determining if API will calculate the appropriate settings for deframer lane in to physical lanes. Where, if '0' = API will set automatic lane crossbar, '1' = set to manual mode and the value in deserializerLaneCrossbar will be used +static const mykonosJesd204bDeframerConfig_t DEFAULT_DEFRAMER = { + 0, // bankId extension to Device ID (Valid 0..15) + 0, // deviceId link identification number. (Valid 0..255) + 0, // lane0Id Lane0 ID. (Valid 0..31) + 4, // M number of DACss (0, 2, or 4) - 2 DACs per transmit chain + 20, // K #frames in a multiframe (default=32), F*K=multiple of 4. + // (F=2*M/numberOfLanes) + 0, // Scrambling off if scramble = 0, if framerScramble > 0 scrambling is enabled + 1, // External SYSREF select. 0 = use internal SYSREF, 1 = external SYSREF + 0x0F, // Deserializer lane select bit field. Where, [0] = Lane0 enabled, [1] = Lane1 + // enabled, etc + 0xD2, // Lane crossbar to map physical lanes to deframer lane inputs [1:0] = Deframer + // Input 0 Lane section, [3:2] = Deframer Input 1 lane select, etc + 1, // Equalizer setting. Applied to all deserializer lanes. Range is 0..4 + 0, // PN inversion per each lane. bit[0] = 1 Invert PN of Lane 0, bit[1] = Invert PN + // of Lane 1, etc). + 0, // LMFC offset value to adjust deterministic latency. Range is 0..31 + 0, // Flag for determining if SYSREF on relink should be set. Where, if > 0 = set, '0' + // = not set + 0, // Flag for determining if auto channel select for the xbar should be set. Where, + // if > 0 = set, '0' = not set + 1, // Flag for determining if CMOS mode for TX Sync signal is used. Where, if > 0 = + // CMOS, '0' = LVDS + 1, // Flag for determining if API will calculate the appropriate settings for deframer + // lane in to physical lanes. Where, if '0' = API will set automatic lane crossbar, + // '1' = set to manual mode and the value in deserializerLaneCrossbar will be used }; -static const mykonosObsRxSettings_t DEFAULT_ORX_SETTINGS = -{ - nullptr, // ORx datapath profile, 3dB corner frequencies, and digital filter enables - nullptr, // ObsRx gain control settings structure - nullptr, // ORx AGC control settings structure - nullptr, // Sniffer datapath profile, 3dB corner frequencies, and digital filter enables - nullptr, // SnRx gain control settings structure - nullptr, // ObsRx JESD204b framer configuration structure - MYK_ORX1, // obsRxChannel TODO: fix this garbage please - OBSLO_TX_PLL, // (obsRxLoSource) The Obs Rx mixer can use the Tx Synth(TX_PLL) or Sniffer Synth (SNIFFER_PLL) - 2600000000U, // SnRx PLL LO frequency in Hz - 0, // Flag to choose if complex baseband or real IF data are selected for Rx and ObsRx paths. Where if > 0 = real IF data, '0' = complex data - nullptr, // Custom Loopback ADC profile to set the bandwidth of the ADC response - OBS_RXOFF // Default ObsRx channel to enter when radioOn called +static const mykonosObsRxSettings_t DEFAULT_ORX_SETTINGS = { + nullptr, // ORx datapath profile, 3dB corner frequencies, and digital filter enables + nullptr, // ObsRx gain control settings structure + nullptr, // ORx AGC control settings structure + nullptr, // Sniffer datapath profile, 3dB corner frequencies, and digital filter + // enables + nullptr, // SnRx gain control settings structure + nullptr, // ObsRx JESD204b framer configuration structure + MYK_ORX1, // obsRxChannel TODO: fix this garbage please + OBSLO_TX_PLL, // (obsRxLoSource) The Obs Rx mixer can use the Tx Synth(TX_PLL) or + // Sniffer Synth (SNIFFER_PLL) + 2600000000U, // SnRx PLL LO frequency in Hz + 0, // Flag to choose if complex baseband or real IF data are selected for Rx and ObsRx + // paths. Where if > 0 = real IF data, '0' = complex data + nullptr, // Custom Loopback ADC profile to set the bandwidth of the ADC response + OBS_RXOFF // Default ObsRx channel to enter when radioOn called }; -static const mykonosJesd204bFramerConfig_t DEFAULT_ORX_FRAMER = -{ - 0, // JESD204B Configuration Bank ID -extension to Device ID (Valid 0..15) - 0, // JESD204B Configuration Device ID - link identification number. (Valid 0..255) - 0, // JESD204B Configuration starting Lane ID. If more than one lane used, each lane will increment from the Lane0 ID. (Valid 0..31) - 2, // number of ADCs (0, 2, or 4) - 2 ADCs per receive chain - 32, // number of frames in a multiframe (default=32), F*K must be a multiple of 4. (F=2*M/numberOfLanes) - 1, // scrambling off if framerScramble= 0, if framerScramble>0 scramble is enabled. - 1, // 0=use internal SYSREF, 1= use external SYSREF - 0x00, // serializerLanesEnabled - bit per lane, [0] = Lane0 enabled, [1] = Lane1 enabled - 0xE4, // Lane crossbar to map framer lane outputs to physical lanes - 22, // serializerAmplitude - default 22 (valid (0-31) - 4, // preEmphasis - < default 4 (valid 0 - 7) - 0, // invertLanePolarity - default 0 ([0] will invert lane [0], bit1 will invert lane1) - 0, // lmfcOffset - LMFC_Offset offset value for deterministic latency setting - 0, // Flag for determining if SYSREF on relink should be set. Where, if > 0 = set, 0 = not set - 0, // Flag for determining if auto channel select for the xbar should be set. Where, if > 0 = set, '0' = not set - 1, // Selects SYNCb input source. Where, 0 = use RXSYNCB for this framer, 1 = use OBSRX_SYNCB for this framer - 0, // Flag for determining if CMOS mode for RX Sync signal is used. Where, if > 0 = CMOS, '0' = LVDS - 1, // Selects framer bit repeat or oversampling mode for lane rate matching. Where, 0 = bitRepeat mode (changes effective lanerate), 1 = overSample (maintains same lane rate between ObsRx framer and Rx framer and oversamples the ADC samples) - 1 // Flag for determining if API will calculate the appropriate settings for framer lane outputs to physical lanes. Where, if '0' = API will set automatic lane crossbar, '1' = set to manual mode and the value in serializerLaneCrossbar will be used +static const mykonosJesd204bFramerConfig_t DEFAULT_ORX_FRAMER = { + 0, // JESD204B Configuration Bank ID -extension to Device ID (Valid 0..15) + 0, // JESD204B Configuration Device ID - link identification number. (Valid 0..255) + 0, // JESD204B Configuration starting Lane ID. If more than one lane used, each lane + // will increment from the Lane0 ID. (Valid 0..31) + 2, // number of ADCs (0, 2, or 4) - 2 ADCs per receive chain + 32, // number of frames in a multiframe (default=32), F*K must be a multiple of 4. + // (F=2*M/numberOfLanes) + 1, // scrambling off if framerScramble= 0, if framerScramble>0 scramble is enabled. + 1, // 0=use internal SYSREF, 1= use external SYSREF + 0x00, // serializerLanesEnabled - bit per lane, [0] = Lane0 enabled, [1] = Lane1 + // enabled + 0xE4, // Lane crossbar to map framer lane outputs to physical lanes + 22, // serializerAmplitude - default 22 (valid (0-31) + 4, // preEmphasis - < default 4 (valid 0 - 7) + 0, // invertLanePolarity - default 0 ([0] will invert lane [0], bit1 will invert + // lane1) + 0, // lmfcOffset - LMFC_Offset offset value for deterministic latency setting + 0, // Flag for determining if SYSREF on relink should be set. Where, if > 0 = set, 0 = + // not set + 0, // Flag for determining if auto channel select for the xbar should be set. Where, + // if > 0 = set, '0' = not set + 1, // Selects SYNCb input source. Where, 0 = use RXSYNCB for this framer, 1 = use + // OBSRX_SYNCB for this framer + 0, // Flag for determining if CMOS mode for RX Sync signal is used. Where, if > 0 = + // CMOS, '0' = LVDS + 1, // Selects framer bit repeat or oversampling mode for lane rate matching. Where, 0 + // = bitRepeat mode (changes effective lanerate), 1 = overSample (maintains same + // lane rate between ObsRx framer and Rx framer and oversamples the ADC samples) + 1 // Flag for determining if API will calculate the appropriate settings for framer + // lane outputs to physical lanes. Where, if '0' = API will set automatic lane + // crossbar, '1' = set to manual mode and the value in serializerLaneCrossbar will + // be used }; -static const mykonosORxGainControl_t DEFAULT_ORX_GAIN = -{ - MGC, // Current ORx gain control mode setting - 255, // ORx1 Gain Index, can be used in different ways for manual and AGC gain control - 255, // ORx2 Gain Index, can be used in different ways for manual and AGC gain control - 255, // Max gain index for the currently loaded ORx Gain table - 237 // Min gain index for the currently loaded ORx Gain table +static const mykonosORxGainControl_t DEFAULT_ORX_GAIN = { + MGC, // Current ORx gain control mode setting + 255, // ORx1 Gain Index, can be used in different ways for manual and AGC gain control + 255, // ORx2 Gain Index, can be used in different ways for manual and AGC gain control + 255, // Max gain index for the currently loaded ORx Gain table + 237 // Min gain index for the currently loaded ORx Gain table }; -static const mykonosAgcCfg_t DEFAULT_ORX_AGC_CTRL = -{ - 255, // agcRx1MaxGainIndex - 195, // agcRx1MinGainIndex - 255, // agcRx2MaxGainIndex - 195, // agcRx2MinGainIndex: - 255, // agcObsRxMaxGainIndex - 203, // agcObsRxMinGainIndex - 1, // agcObsRxSelect - 1, // agcPeakThresholdMode - 1, // agcLowThsPreventGainIncrease - 30720, // agcGainUpdateCounter - 3, // agcSlowLoopSettlingDelay - 4, // agcPeakWaitTime - 0, // agcResetOnRxEnable - 0, // agcEnableSyncPulseForGainCounter - nullptr,// *peakAgc +static const mykonosAgcCfg_t DEFAULT_ORX_AGC_CTRL = { + 255, // agcRx1MaxGainIndex + 195, // agcRx1MinGainIndex + 255, // agcRx2MaxGainIndex + 195, // agcRx2MinGainIndex: + 255, // agcObsRxMaxGainIndex + 203, // agcObsRxMinGainIndex + 1, // agcObsRxSelect + 1, // agcPeakThresholdMode + 1, // agcLowThsPreventGainIncrease + 30720, // agcGainUpdateCounter + 3, // agcSlowLoopSettlingDelay + 4, // agcPeakWaitTime + 0, // agcResetOnRxEnable + 0, // agcEnableSyncPulseForGainCounter + nullptr, // *peakAgc nullptr // *powerAgc }; -static const mykonosPeakDetAgcCfg_t DEFAULT_ORX_PEAK_AGC = -{ - 0x2A, // apdHighThresh: - 0x16, // apdLowThresh - 0xB5, // hb2HighThresh - 0x72, // hb2LowThresh - 0x40, // hb2VeryLowThresh - 0x03, // apdHighThreshExceededCnt - 0x03, // apdLowThreshExceededCnt - 0x03, // hb2HighThreshExceededCnt - 0x03, // hb2LowThreshExceededCnt - 0x03, // hb2VeryLowThreshExceededCnt - 0x4, // apdHighGainStepAttack - 0x2, // apdLowGainStepRecovery - 0x4, // hb2HighGainStepAttack - 0x2, // hb2LowGainStepRecovery - 0x4, // hb2VeryLowGainStepRecovery - 0x0, // apdFastAttack - 0x0, // hb2FastAttack - 0x1, // hb2OverloadDetectEnable - 0x1, // hb2OverloadDurationCnt - 0x1 // hb2OverloadThreshCnt +static const mykonosPeakDetAgcCfg_t DEFAULT_ORX_PEAK_AGC = { + 0x2A, // apdHighThresh: + 0x16, // apdLowThresh + 0xB5, // hb2HighThresh + 0x72, // hb2LowThresh + 0x40, // hb2VeryLowThresh + 0x03, // apdHighThreshExceededCnt + 0x03, // apdLowThreshExceededCnt + 0x03, // hb2HighThreshExceededCnt + 0x03, // hb2LowThreshExceededCnt + 0x03, // hb2VeryLowThreshExceededCnt + 0x4, // apdHighGainStepAttack + 0x2, // apdLowGainStepRecovery + 0x4, // hb2HighGainStepAttack + 0x2, // hb2LowGainStepRecovery + 0x4, // hb2VeryLowGainStepRecovery + 0x0, // apdFastAttack + 0x0, // hb2FastAttack + 0x1, // hb2OverloadDetectEnable + 0x1, // hb2OverloadDurationCnt + 0x1 // hb2OverloadThreshCnt }; -static const mykonosPowerMeasAgcCfg_t DEFAULT_ORX_POWER_AGC = -{ - 0x01, // pmdUpperHighThresh - 0x03, // pmdUpperLowThresh - 0x0C, // pmdLowerHighThresh - 0x04, // pmdLowerLowThresh - 0x0, // pmdUpperHighGainStepAttack - 0x0, // pmdUpperLowGainStepAttack - 0x0, // pmdLowerHighGainStepRecovery - 0x0, // pmdLowerLowGainStepRecovery - 0x08, // pmdMeasDuration - 0x02 // pmdMeasConfig +static const mykonosPowerMeasAgcCfg_t DEFAULT_ORX_POWER_AGC = { + 0x01, // pmdUpperHighThresh + 0x03, // pmdUpperLowThresh + 0x0C, // pmdLowerHighThresh + 0x04, // pmdLowerLowThresh + 0x0, // pmdUpperHighGainStepAttack + 0x0, // pmdUpperLowGainStepAttack + 0x0, // pmdLowerHighGainStepRecovery + 0x0, // pmdLowerLowGainStepRecovery + 0x08, // pmdMeasDuration + 0x02 // pmdMeasConfig }; -static const mykonosSnifferGainControl_t DEFAULT_SNIFFER_GAIN = -{ - MGC, // Current Sniffer gain control mode setting - 255, // Current Sniffer gain index. Can be used differently for Manual Gain control/AGC - 255, // Max gain index for the currently loaded Sniffer Gain table - 203 // Min gain index for the currently loaded Sniffer Gain table +static const mykonosSnifferGainControl_t DEFAULT_SNIFFER_GAIN = { + MGC, // Current Sniffer gain control mode setting + 255, // Current Sniffer gain index. Can be used differently for Manual Gain + // control/AGC + 255, // Max gain index for the currently loaded Sniffer Gain table + 203 // Min gain index for the currently loaded Sniffer Gain table }; -static const mykonosRxProfile_t DEFAULT_ORX_PROFILE = -{// ORX 100MHz, IQrate 125MSPS, Dec5 - 1, // The divider used to generate the ADC clock - nullptr, // Pointer to Rx FIR filter structure or NULL - 2, // Rx FIR decimation (1,2,4) - 5, // Decimation of Dec5 or Dec4 filter (5,4) - 0, // If set, and DEC5 filter used, will use a higher rejection DEC5 FIR filter (1=Enabled, 0=Disabled) - 1, // RX Half band 1 decimation (1 or 2) - 125000, // Rx IQ data rate in kHz - 100000000, // The Rx RF passband bandwidth for the profile - 102000, // Rx BBF 3dB corner in kHz - nullptr // pointer to custom ADC profile +static const mykonosRxProfile_t DEFAULT_ORX_PROFILE = { + // ORX 100MHz, IQrate 125MSPS, Dec5 + 1, // The divider used to generate the ADC clock + nullptr, // Pointer to Rx FIR filter structure or NULL + 2, // Rx FIR decimation (1,2,4) + 5, // Decimation of Dec5 or Dec4 filter (5,4) + 0, // If set, and DEC5 filter used, will use a higher rejection DEC5 FIR filter + // (1=Enabled, 0=Disabled) + 1, // RX Half band 1 decimation (1 or 2) + 125000, // Rx IQ data rate in kHz + 100000000, // The Rx RF passband bandwidth for the profile + 102000, // Rx BBF 3dB corner in kHz + nullptr // pointer to custom ADC profile }; -static const mykonosArmGpioConfig_t DEFAULT_ARM_GPIO = -{ - 1, // useRx2EnablePin; //!< 0= RX1_ENABLE controls RX1 and RX2, 1 = separate RX1_ENABLE/RX2_ENABLE pins - 1, // useTx2EnablePin; //!< 0= TX1_ENABLE controls TX1 and TX2, 1 = separate TX1_ENABLE/TX2_ENABLE pins - 0, // txRxPinMode; //!< 0= ARM command mode, 1 = Pin mode to power up Tx/Rx chains - 0, // orxPinMode; //!< 0= ARM command mode, 1 = Pin mode to power up ObsRx receiver +static const mykonosArmGpioConfig_t DEFAULT_ARM_GPIO = { + 1, // useRx2EnablePin; //!< 0= RX1_ENABLE controls RX1 and RX2, 1 = separate + // RX1_ENABLE/RX2_ENABLE pins + 1, // useTx2EnablePin; //!< 0= TX1_ENABLE controls TX1 and TX2, 1 = separate + // TX1_ENABLE/TX2_ENABLE pins + 0, // txRxPinMode; //!< 0= ARM command mode, 1 = Pin mode to power up Tx/Rx chains + 0, // orxPinMode; //!< 0= ARM command mode, 1 = Pin mode to power up ObsRx + // receiver - //Mykonos ARM input GPIO pins -- Only valid if orxPinMode = 1 - 0, // orxTriggerPin; //!< Select desired GPIO pin (valid 4-15) - 0, // orxMode2Pin; //!< Select desired GPIO pin (valid 0-18) - 0, // orxMode1Pin; //!< Select desired GPIO pin (valid 0-18) - 0, // orxMode0Pin; //!< Select desired GPIO pin (valid 0-18) + // Mykonos ARM input GPIO pins -- Only valid if orxPinMode = 1 + 0, // orxTriggerPin; //!< Select desired GPIO pin (valid 4-15) + 0, // orxMode2Pin; //!< Select desired GPIO pin (valid 0-18) + 0, // orxMode1Pin; //!< Select desired GPIO pin (valid 0-18) + 0, // orxMode0Pin; //!< Select desired GPIO pin (valid 0-18) // Mykonos ARM output GPIO pins -- always available, even when pin mode not enabled - 0, // rx1EnableAck; //!< Select desired GPIO pin (0-15), [4] = Output Enable - 0, // rx2EnableAck; //!< Select desired GPIO pin (0-15), [4] = Output Enable - 0, // tx1EnableAck; //!< Select desired GPIO pin (0-15), [4] = Output Enable - 0, // tx2EnableAck; //!< Select desired GPIO pin (0-15), [4] = Output Enable - 0, // orx1EnableAck; //!< Select desired GPIO pin (0-15), [4] = Output Enable - 0, // orx2EnableAck; //!< Select desired GPIO pin (0-15), [4] = Output Enable - 0, // srxEnableAck; //!< Select desired GPIO pin (0-15), [4] = Output Enable - 0 // txObsSelect; //!< Select desired GPIO pin (0-15), [4] = Output Enable - // When 2Tx are used with only 1 ORx input, this GPIO tells the BBIC which Tx channel is - // active for calibrations, so BBIC can route correct RF Tx path into the single ORx input + 0, // rx1EnableAck; //!< Select desired GPIO pin (0-15), [4] = Output Enable + 0, // rx2EnableAck; //!< Select desired GPIO pin (0-15), [4] = Output Enable + 0, // tx1EnableAck; //!< Select desired GPIO pin (0-15), [4] = Output Enable + 0, // tx2EnableAck; //!< Select desired GPIO pin (0-15), [4] = Output Enable + 0, // orx1EnableAck; //!< Select desired GPIO pin (0-15), [4] = Output Enable + 0, // orx2EnableAck; //!< Select desired GPIO pin (0-15), [4] = Output Enable + 0, // srxEnableAck; //!< Select desired GPIO pin (0-15), [4] = Output Enable + 0 // txObsSelect; //!< Select desired GPIO pin (0-15), [4] = Output Enable + // When 2Tx are used with only 1 ORx input, this GPIO tells the BBIC which Tx + // channel is active for calibrations, so BBIC can route correct RF Tx path into the + // single ORx input }; -static const mykonosGpio3v3_t DEFAULT_GPIO_3V3 = -{ - 0, //!< Oe per pin, 1=output, 0 = input - GPIO3V3_BITBANG_MODE, //!< Mode for GPIO3V3[3:0] - GPIO3V3_BITBANG_MODE, //!< Mode for GPIO3V3[7:4] - GPIO3V3_BITBANG_MODE, //!< Mode for GPIO3V3[11:8] +static const mykonosGpio3v3_t DEFAULT_GPIO_3V3 = { + 0, //!< Oe per pin, 1=output, 0 = input + GPIO3V3_BITBANG_MODE, //!< Mode for GPIO3V3[3:0] + GPIO3V3_BITBANG_MODE, //!< Mode for GPIO3V3[7:4] + GPIO3V3_BITBANG_MODE, //!< Mode for GPIO3V3[11:8] }; -static const mykonosGpioLowVoltage_t DEFAULT_GPIO = -{ - 0, // Oe per pin, 1=output, 0 = input - GPIO_MONITOR_MODE, // Mode for GPIO[3:0] - GPIO_MONITOR_MODE, // Mode for GPIO[7:4] - GPIO_MONITOR_MODE, // Mode for GPIO[11:8] - GPIO_MONITOR_MODE, // Mode for GPIO[15:12] - GPIO_MONITOR_MODE, // Mode for GPIO[18:16] +static const mykonosGpioLowVoltage_t DEFAULT_GPIO = { + 0, // Oe per pin, 1=output, 0 = input + GPIO_MONITOR_MODE, // Mode for GPIO[3:0] + GPIO_MONITOR_MODE, // Mode for GPIO[7:4] + GPIO_MONITOR_MODE, // Mode for GPIO[11:8] + GPIO_MONITOR_MODE, // Mode for GPIO[15:12] + GPIO_MONITOR_MODE, // Mode for GPIO[18:16] }; -static const mykonosAuxIo_t DEFAULT_AUX_IO = -{ - 0, // auxDacEnable uint16_t - { 0,0,0,0,0,0,0,0,0,0 }, // auxDacValue uint16[10] - { 0,0,0,0,0,0,0,0,0,0 }, // auxDacSlope uint8[10] - { 0,0,0,0,0,0,0,0,0,0 }, // auxDacVref uint8[10] - nullptr, // *mykonosGpio3v3_t - nullptr, // *mykonosGpioLowVoltage_t - nullptr // *mykonosArmGpioConfig_t +static const mykonosAuxIo_t DEFAULT_AUX_IO = { + 0, // auxDacEnable uint16_t + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // auxDacValue uint16[10] + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // auxDacSlope uint8[10] + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // auxDacVref uint8[10] + nullptr, // *mykonosGpio3v3_t + nullptr, // *mykonosGpioLowVoltage_t + nullptr // *mykonosArmGpioConfig_t }; -static const mykonosDigClocks_t DEFAULT_CLOCKS = -{ - 125000, // CLKPLL and device reference clock frequency in kHz - 10000000, // CLKPLL VCO frequency in kHz - VCODIV_2, // CLKPLL VCO divider - 4 // CLKPLL high speed clock divider +static const mykonosDigClocks_t DEFAULT_CLOCKS = { + 125000, // CLKPLL and device reference clock frequency in kHz + 10000000, // CLKPLL VCO frequency in kHz + VCODIV_2, // CLKPLL VCO divider + 4 // CLKPLL high speed clock divider }; - - diff --git a/mpm/lib/mykonos/config/ad937x_fir.cpp b/mpm/lib/mykonos/config/ad937x_fir.cpp index 01c8772eb..6803f5369 100644 --- a/mpm/lib/mykonos/config/ad937x_fir.cpp +++ b/mpm/lib/mykonos/config/ad937x_fir.cpp @@ -6,21 +6,16 @@ #include "ad937x_fir.hpp" -ad937x_fir::ad937x_fir() : - ad937x_fir(0, { 1, 0 }) +ad937x_fir::ad937x_fir() : ad937x_fir(0, {1, 0}) {} + +ad937x_fir::ad937x_fir(int8_t gain, const std::vector<int16_t>& coefficients) + : // These two constructors will be run in the order they are declared in the class + // definition see C++ standard 12.6.2 section 13.3 + _fir_coefficients(coefficients) + , _fir({gain, + static_cast<uint8_t>(_fir_coefficients.size()), + _fir_coefficients.data()}) { - -} - -ad937x_fir::ad937x_fir(int8_t gain, const std::vector<int16_t>& coefficients) : - // These two constructors will be run in the order they are declared in the class definition - // see C++ standard 12.6.2 section 13.3 - _fir_coefficients(coefficients), - _fir({gain, - static_cast<uint8_t>(_fir_coefficients.size()), - _fir_coefficients.data()}) -{ - } // ad937x_fir.fir should not be accessed during this operation @@ -29,11 +24,11 @@ void ad937x_fir::set_fir(int8_t gain, const std::vector<int16_t>& coefficients) _fir.gain_dB = gain; _fir_coefficients = coefficients; - _fir.coefs = _fir_coefficients.data(); - _fir.numFirCoefs = static_cast<uint8_t>(_fir_coefficients.size()); + _fir.coefs = _fir_coefficients.data(); + _fir.numFirCoefs = static_cast<uint8_t>(_fir_coefficients.size()); } -std::vector<int16_t> ad937x_fir::get_fir(int8_t &gain) const +std::vector<int16_t> ad937x_fir::get_fir(int8_t& gain) const { gain = _fir.gain_dB; return _fir_coefficients; diff --git a/mpm/lib/mykonos/config/ad937x_fir.hpp b/mpm/lib/mykonos/config/ad937x_fir.hpp index c3fda6fb7..df122701d 100644 --- a/mpm/lib/mykonos/config/ad937x_fir.hpp +++ b/mpm/lib/mykonos/config/ad937x_fir.hpp @@ -15,11 +15,12 @@ class ad937x_fir { std::vector<int16_t> _fir_coefficients; mykonosFir_t _fir; + public: mykonosFir_t* const fir = &_fir; ad937x_fir(); ad937x_fir(int8_t gain, const std::vector<int16_t>& coefficients); void set_fir(int8_t gain, const std::vector<int16_t>& coefficients); - std::vector<int16_t> get_fir(int8_t &gain) const; + std::vector<int16_t> get_fir(int8_t& gain) const; }; diff --git a/mpm/lib/mykonos/config/ad937x_gain_ctrl_config.cpp b/mpm/lib/mykonos/config/ad937x_gain_ctrl_config.cpp index d4fbef0ad..bc8dcb21a 100644 --- a/mpm/lib/mykonos/config/ad937x_gain_ctrl_config.cpp +++ b/mpm/lib/mykonos/config/ad937x_gain_ctrl_config.cpp @@ -11,121 +11,158 @@ using namespace mpm::ad937x::device; using namespace uhd; const uint8_t ad937x_gain_ctrl_channel_t::DEFAULT_GAIN_STEP = 1; -const bool ad937x_gain_ctrl_channel_t::DEFAULT_ENABLE = 0; +const bool ad937x_gain_ctrl_channel_t::DEFAULT_ENABLE = 0; // rx uses gain, tx uses attenuation -enum class pin_direction_t -{ +enum class pin_direction_t { INCREASE, DECREASE, }; mykonosGpioSelect_t _convert_gain_pin(gain_pin_t pin) { - switch (pin) - { - case gain_pin_t::PIN0: return MYKGPIO0; - case gain_pin_t::PIN1: return MYKGPIO1; - case gain_pin_t::PIN2: return MYKGPIO2; - case gain_pin_t::PIN3: return MYKGPIO3; - case gain_pin_t::PIN4: return MYKGPIO4; - case gain_pin_t::PIN5: return MYKGPIO5; - case gain_pin_t::PIN6: return MYKGPIO6; - case gain_pin_t::PIN7: return MYKGPIO7; - case gain_pin_t::PIN8: return MYKGPIO8; - case gain_pin_t::PIN9: return MYKGPIO9; - case gain_pin_t::PIN10: return MYKGPIO10; - case gain_pin_t::PIN11: return MYKGPIO11; - case gain_pin_t::PIN12: return MYKGPIO12; - case gain_pin_t::PIN13: return MYKGPIO13; - case gain_pin_t::PIN14: return MYKGPIO14; - case gain_pin_t::PIN15: return MYKGPIO15; - case gain_pin_t::PIN16: return MYKGPIO16; - case gain_pin_t::PIN17: return MYKGPIO17; - case gain_pin_t::PIN18: return MYKGPIO18; - default: return MYKGPIONAN; + switch (pin) { + case gain_pin_t::PIN0: + return MYKGPIO0; + case gain_pin_t::PIN1: + return MYKGPIO1; + case gain_pin_t::PIN2: + return MYKGPIO2; + case gain_pin_t::PIN3: + return MYKGPIO3; + case gain_pin_t::PIN4: + return MYKGPIO4; + case gain_pin_t::PIN5: + return MYKGPIO5; + case gain_pin_t::PIN6: + return MYKGPIO6; + case gain_pin_t::PIN7: + return MYKGPIO7; + case gain_pin_t::PIN8: + return MYKGPIO8; + case gain_pin_t::PIN9: + return MYKGPIO9; + case gain_pin_t::PIN10: + return MYKGPIO10; + case gain_pin_t::PIN11: + return MYKGPIO11; + case gain_pin_t::PIN12: + return MYKGPIO12; + case gain_pin_t::PIN13: + return MYKGPIO13; + case gain_pin_t::PIN14: + return MYKGPIO14; + case gain_pin_t::PIN15: + return MYKGPIO15; + case gain_pin_t::PIN16: + return MYKGPIO16; + case gain_pin_t::PIN17: + return MYKGPIO17; + case gain_pin_t::PIN18: + return MYKGPIO18; + default: + return MYKGPIONAN; } } -ad937x_gain_ctrl_channel_t::ad937x_gain_ctrl_channel_t(mykonosGpioSelect_t inc_pin, mykonosGpioSelect_t dec_pin) : - enable(DEFAULT_ENABLE), - inc_step(DEFAULT_GAIN_STEP), - dec_step(DEFAULT_GAIN_STEP), - inc_pin(inc_pin), - dec_pin(dec_pin) +ad937x_gain_ctrl_channel_t::ad937x_gain_ctrl_channel_t( + mykonosGpioSelect_t inc_pin, mykonosGpioSelect_t dec_pin) + : enable(DEFAULT_ENABLE) + , inc_step(DEFAULT_GAIN_STEP) + , dec_step(DEFAULT_GAIN_STEP) + , inc_pin(inc_pin) + , dec_pin(dec_pin) { - } -mykonosGpioSelect_t _get_gain_pin( - direction_t direction, +mykonosGpioSelect_t _get_gain_pin(direction_t direction, chain_t chain, pin_direction_t pin_direction, - const gain_pins_t & gain_pins) + const gain_pins_t& gain_pins) { - switch (direction) - { - case RX_DIRECTION: - switch (chain) - { - case chain_t::ONE: - switch (pin_direction) - { - case pin_direction_t::INCREASE: return _convert_gain_pin(gain_pins.rx1_inc_gain_pin); - case pin_direction_t::DECREASE: return _convert_gain_pin(gain_pins.rx1_dec_gain_pin); - } - case chain_t::TWO: - switch (pin_direction) - { - case pin_direction_t::INCREASE: return _convert_gain_pin(gain_pins.rx2_inc_gain_pin); - case pin_direction_t::DECREASE: return _convert_gain_pin(gain_pins.rx2_dec_gain_pin); + switch (direction) { + case RX_DIRECTION: + switch (chain) { + case chain_t::ONE: + switch (pin_direction) { + case pin_direction_t::INCREASE: + return _convert_gain_pin(gain_pins.rx1_inc_gain_pin); + case pin_direction_t::DECREASE: + return _convert_gain_pin(gain_pins.rx1_dec_gain_pin); + } + case chain_t::TWO: + switch (pin_direction) { + case pin_direction_t::INCREASE: + return _convert_gain_pin(gain_pins.rx2_inc_gain_pin); + case pin_direction_t::DECREASE: + return _convert_gain_pin(gain_pins.rx2_dec_gain_pin); + } } - } - // !!! TX is attenuation direction, so the pins are flipped !!! - case TX_DIRECTION: - switch (chain) - { - case chain_t::ONE: - switch (pin_direction) - { - case pin_direction_t::INCREASE: return _convert_gain_pin(gain_pins.tx1_dec_gain_pin); - case pin_direction_t::DECREASE: return _convert_gain_pin(gain_pins.tx1_inc_gain_pin); + // !!! TX is attenuation direction, so the pins are flipped !!! + case TX_DIRECTION: + switch (chain) { + case chain_t::ONE: + switch (pin_direction) { + case pin_direction_t::INCREASE: + return _convert_gain_pin(gain_pins.tx1_dec_gain_pin); + case pin_direction_t::DECREASE: + return _convert_gain_pin(gain_pins.tx1_inc_gain_pin); + } + case chain_t::TWO: + switch (pin_direction) { + case pin_direction_t::INCREASE: + return _convert_gain_pin(gain_pins.tx2_dec_gain_pin); + case pin_direction_t::DECREASE: + return _convert_gain_pin(gain_pins.tx2_inc_gain_pin); + } } - case chain_t::TWO: - switch (pin_direction) - { - case pin_direction_t::INCREASE: return _convert_gain_pin(gain_pins.tx2_dec_gain_pin); - case pin_direction_t::DECREASE: return _convert_gain_pin(gain_pins.tx2_inc_gain_pin); - } - } - default: - return MYKGPIONAN; + default: + return MYKGPIONAN; } } ad937x_gain_ctrl_config_t::ad937x_gain_ctrl_config_t(gain_pins_t gain_pins) { - config.emplace(std::piecewise_construct, std::forward_as_tuple(RX_DIRECTION), std::forward_as_tuple()); - config.emplace(std::piecewise_construct, std::forward_as_tuple(TX_DIRECTION), std::forward_as_tuple()); + config.emplace(std::piecewise_construct, + std::forward_as_tuple(RX_DIRECTION), + std::forward_as_tuple()); + config.emplace(std::piecewise_construct, + std::forward_as_tuple(TX_DIRECTION), + std::forward_as_tuple()); - config.at(RX_DIRECTION).emplace(std::piecewise_construct, std::forward_as_tuple(chain_t::ONE), - std::forward_as_tuple( - _get_gain_pin(RX_DIRECTION, chain_t::ONE, pin_direction_t::INCREASE, gain_pins), - _get_gain_pin(RX_DIRECTION, chain_t::ONE, pin_direction_t::DECREASE, gain_pins))); - config.at(RX_DIRECTION).emplace(std::piecewise_construct, std::forward_as_tuple(chain_t::TWO), - std::forward_as_tuple( - _get_gain_pin(RX_DIRECTION, chain_t::TWO, pin_direction_t::INCREASE, gain_pins), - _get_gain_pin(RX_DIRECTION, chain_t::TWO, pin_direction_t::DECREASE, gain_pins))); + config.at(RX_DIRECTION) + .emplace(std::piecewise_construct, + std::forward_as_tuple(chain_t::ONE), + std::forward_as_tuple( + _get_gain_pin( + RX_DIRECTION, chain_t::ONE, pin_direction_t::INCREASE, gain_pins), + _get_gain_pin( + RX_DIRECTION, chain_t::ONE, pin_direction_t::DECREASE, gain_pins))); + config.at(RX_DIRECTION) + .emplace(std::piecewise_construct, + std::forward_as_tuple(chain_t::TWO), + std::forward_as_tuple( + _get_gain_pin( + RX_DIRECTION, chain_t::TWO, pin_direction_t::INCREASE, gain_pins), + _get_gain_pin( + RX_DIRECTION, chain_t::TWO, pin_direction_t::DECREASE, gain_pins))); - config.at(TX_DIRECTION).emplace(std::piecewise_construct, std::forward_as_tuple(chain_t::ONE), - std::forward_as_tuple( - _get_gain_pin(TX_DIRECTION, chain_t::ONE, pin_direction_t::INCREASE, gain_pins), - _get_gain_pin(TX_DIRECTION, chain_t::ONE, pin_direction_t::DECREASE, gain_pins))); - config.at(TX_DIRECTION).emplace(std::piecewise_construct, std::forward_as_tuple(chain_t::TWO), - std::forward_as_tuple( - _get_gain_pin(TX_DIRECTION, chain_t::TWO, pin_direction_t::INCREASE, gain_pins), - _get_gain_pin(TX_DIRECTION, chain_t::TWO, pin_direction_t::DECREASE, gain_pins))); + config.at(TX_DIRECTION) + .emplace(std::piecewise_construct, + std::forward_as_tuple(chain_t::ONE), + std::forward_as_tuple( + _get_gain_pin( + TX_DIRECTION, chain_t::ONE, pin_direction_t::INCREASE, gain_pins), + _get_gain_pin( + TX_DIRECTION, chain_t::ONE, pin_direction_t::DECREASE, gain_pins))); + config.at(TX_DIRECTION) + .emplace(std::piecewise_construct, + std::forward_as_tuple(chain_t::TWO), + std::forward_as_tuple( + _get_gain_pin( + TX_DIRECTION, chain_t::TWO, pin_direction_t::INCREASE, gain_pins), + _get_gain_pin( + TX_DIRECTION, chain_t::TWO, pin_direction_t::DECREASE, gain_pins))); } - diff --git a/mpm/lib/mykonos/config/ad937x_gain_ctrl_config.hpp b/mpm/lib/mykonos/config/ad937x_gain_ctrl_config.hpp index 380efb0de..12851af92 100644 --- a/mpm/lib/mykonos/config/ad937x_gain_ctrl_config.hpp +++ b/mpm/lib/mykonos/config/ad937x_gain_ctrl_config.hpp @@ -8,31 +8,29 @@ #include "../ad937x_device_types.hpp" #include "../adi/t_mykonos.h" - #include "mpm/ad937x/ad937x_ctrl_types.hpp" - -#include <vector> #include <unordered_map> +#include <vector> -// C++14 requires std::hash includes a specialization for enums, but gcc doesn't do that yet -// Remove this when that happens +// C++14 requires std::hash includes a specialization for enums, but gcc doesn't do that +// yet Remove this when that happens namespace std { - template <> struct hash<uhd::direction_t> +template <> struct hash<uhd::direction_t> +{ + size_t operator()(const uhd::direction_t& x) const { - size_t operator()(const uhd::direction_t & x) const - { - return static_cast<std::size_t>(x); - } - }; + return static_cast<std::size_t>(x); + } +}; - template <> struct hash<mpm::ad937x::device::chain_t> +template <> struct hash<mpm::ad937x::device::chain_t> +{ + size_t operator()(const mpm::ad937x::device::chain_t& x) const { - size_t operator()(const mpm::ad937x::device::chain_t & x) const - { - return static_cast<std::size_t>(x); - } - }; -} + return static_cast<std::size_t>(x); + } +}; +} // namespace std // collection of the 5 attributes that define the gain pins for a channel in Mykonos struct ad937x_gain_ctrl_channel_t @@ -54,9 +52,8 @@ private: struct ad937x_gain_ctrl_config_t { std::unordered_map<uhd::direction_t, - std::unordered_map<mpm::ad937x::device::chain_t, ad937x_gain_ctrl_channel_t>> config; + std::unordered_map<mpm::ad937x::device::chain_t, ad937x_gain_ctrl_channel_t>> + config; ad937x_gain_ctrl_config_t(mpm::ad937x::gpio::gain_pins_t gain_pins); }; - - diff --git a/mpm/lib/spi/spi_regs_iface.cpp b/mpm/lib/spi/spi_regs_iface.cpp index a1b5d29f8..842f45d42 100644 --- a/mpm/lib/spi/spi_regs_iface.cpp +++ b/mpm/lib/spi/spi_regs_iface.cpp @@ -4,10 +4,10 @@ // SPDX-License-Identifier: GPL-3.0-or-later // -#include <mpm/types/regs_iface.hpp> +#include <mpm/exception.hpp> #include <mpm/spi/spi_iface.hpp> #include <mpm/spi/spi_regs_iface.hpp> -#include <mpm/exception.hpp> +#include <mpm/types/regs_iface.hpp> using mpm::types::regs_iface; @@ -18,29 +18,23 @@ using mpm::types::regs_iface; class spi_regs_iface_impl : public regs_iface { public: - - spi_regs_iface_impl( - mpm::spi::spi_iface::sptr spi_iface, + spi_regs_iface_impl(mpm::spi::spi_iface::sptr spi_iface, uint32_t addr_shift, uint32_t data_shift, uint32_t read_flags, - uint32_t write_flags = 0 - ) : _spi_iface(spi_iface), - _addr_shift(addr_shift), - _data_shift(data_shift), - _read_flags(read_flags), - _write_flags(write_flags) + uint32_t write_flags = 0) + : _spi_iface(spi_iface) + , _addr_shift(addr_shift) + , _data_shift(data_shift) + , _read_flags(read_flags) + , _write_flags(write_flags) { /* nop */ } - uint8_t peek8( - const uint32_t addr - ) { - uint32_t transaction = 0 - | (addr << _addr_shift) - | _read_flags - ; + uint8_t peek8(const uint32_t addr) + { + uint32_t transaction = 0 | (addr << _addr_shift) | _read_flags; uint32_t data = _spi_iface->transfer24_8(transaction); if ((data & 0xFFFFFF00) != 0) { @@ -50,26 +44,17 @@ public: return data; } - void poke8( - const uint32_t addr, - const uint8_t data - ) { - uint32_t transaction = 0 - | _write_flags - | (addr << _addr_shift) - | (data << _data_shift) - ; + void poke8(const uint32_t addr, const uint8_t data) + { + uint32_t transaction = 0 | _write_flags | (addr << _addr_shift) + | (data << _data_shift); _spi_iface->transfer24_8(transaction); } - uint16_t peek16( - const uint32_t addr - ) { - uint32_t transaction = 0 - | (addr << _addr_shift) - | _read_flags - ; + uint16_t peek16(const uint32_t addr) + { + uint32_t transaction = 0 | (addr << _addr_shift) | _read_flags; uint32_t data = _spi_iface->transfer24_16(transaction); if ((data & 0xFFFF0000) != 0) { @@ -79,15 +64,10 @@ public: return data; } - void poke16( - const uint32_t addr, - const uint16_t data - ) { - uint32_t transaction = 0 - | _write_flags - | (addr << _addr_shift) - | (data << _data_shift) - ; + void poke16(const uint32_t addr, const uint16_t data) + { + uint32_t transaction = 0 | _write_flags | (addr << _addr_shift) + | (data << _data_shift); _spi_iface->transfer24_16(transaction); } @@ -101,39 +81,25 @@ private: uint32_t _write_flags; }; -regs_iface::sptr mpm::spi::make_spi_regs_iface( - mpm::spi::spi_iface::sptr spi_iface, +regs_iface::sptr mpm::spi::make_spi_regs_iface(mpm::spi::spi_iface::sptr spi_iface, uint32_t addr_shift, uint32_t data_shift, uint32_t read_flags, - uint32_t write_flags -) { + uint32_t write_flags) +{ return std::make_shared<spi_regs_iface_impl>( - spi_iface, - addr_shift, - data_shift, - read_flags, - write_flags - ); + spi_iface, addr_shift, data_shift, read_flags, write_flags); } -mpm::types::regs_iface::sptr mpm::spi::make_spidev_regs_iface( - const std::string &device, +mpm::types::regs_iface::sptr mpm::spi::make_spidev_regs_iface(const std::string& device, const int speed_hz, const int spi_mode, uint32_t addr_shift, uint32_t data_shift, uint32_t read_flags, - uint32_t write_flags -) { - auto spi_iface_sptr = mpm::spi::spi_iface::make_spidev( - device, speed_hz, spi_mode - ); + uint32_t write_flags) +{ + auto spi_iface_sptr = mpm::spi::spi_iface::make_spidev(device, speed_hz, spi_mode); return std::make_shared<spi_regs_iface_impl>( - spi_iface_sptr, - addr_shift, - data_shift, - read_flags, - write_flags - ); + spi_iface_sptr, addr_shift, data_shift, read_flags, write_flags); } diff --git a/mpm/lib/spi/spidev_iface.cpp b/mpm/lib/spi/spidev_iface.cpp index 8b629e7b6..c8a2133e8 100644 --- a/mpm/lib/spi/spidev_iface.cpp +++ b/mpm/lib/spi/spidev_iface.cpp @@ -5,14 +5,13 @@ // -#include <mpm/spi/spi_iface.hpp> #include <mpm/exception.hpp> +#include <mpm/spi/spi_iface.hpp> extern "C" { #include "spidev.h" } #include <fcntl.h> #include <linux/spi/spidev.h> - #include <boost/format.hpp> #include <iostream> @@ -24,29 +23,18 @@ using namespace mpm::spi; class spidev_iface_impl : public spi_iface { public: - spidev_iface_impl( - const std::string &device, - const int max_speed_hz, - const int spi_mode - ) : _speed(max_speed_hz), - _mode(spi_mode) + const std::string& device, const int max_speed_hz, const int spi_mode) + : _speed(max_speed_hz), _mode(spi_mode) { - if (init_spi( - &_fd, - device.c_str(), - _mode, _speed, _bits, _delay) < 0) - { - throw mpm::runtime_error(str( - boost::format("Could not initialize spidev device %s") - % device)); + if (init_spi(&_fd, device.c_str(), _mode, _speed, _bits, _delay) < 0) { + throw mpm::runtime_error( + str(boost::format("Could not initialize spidev device %s") % device)); } - if (_fd < 0) - { - throw mpm::runtime_error(str( - boost::format("Could not open spidev device %s") - % device)); + if (_fd < 0) { + throw mpm::runtime_error( + str(boost::format("Could not open spidev device %s") % device)); } } @@ -55,53 +43,37 @@ public: close(_fd); } - uint32_t transfer24_8( - const uint32_t data_ - ) { + uint32_t transfer24_8(const uint32_t data_) + { int ret(0); - uint32_t data = data_; - uint8_t *tx_data = reinterpret_cast<uint8_t *>(&data); + uint32_t data = data_; + uint8_t* tx_data = reinterpret_cast<uint8_t*>(&data); // Create tx and rx buffers: uint8_t tx[] = {tx_data[2], tx_data[1], tx_data[0]}; // FIXME guarantee endianness uint8_t rx[3]; // Buffer length must match tx buffer - if (transfer( - _fd, - &tx[0], &rx[0], - 3, - _speed, _bits, _delay - ) != 0) { - throw mpm::runtime_error(str( - boost::format("SPI Transaction failed!") - )); + if (transfer(_fd, &tx[0], &rx[0], 3, _speed, _bits, _delay) != 0) { + throw mpm::runtime_error(str(boost::format("SPI Transaction failed!"))); } return uint32_t(rx[2]); } - uint32_t transfer24_16( - const uint32_t data_ - ) { + uint32_t transfer24_16(const uint32_t data_) + { int ret(0); - uint32_t data = data_; - uint8_t *tx_data = reinterpret_cast<uint8_t *>(&data); + uint32_t data = data_; + uint8_t* tx_data = reinterpret_cast<uint8_t*>(&data); // Create tx and rx buffers: uint8_t tx[] = {tx_data[2], tx_data[1], tx_data[0]}; // FIXME guarantee endianness uint8_t rx[3]; // Buffer length must match tx buffer - if (transfer( - _fd, - &tx[0], &rx[0], - 3, - _speed, _bits, _delay - ) != 0) { - throw mpm::runtime_error(str( - boost::format("SPI Transaction failed!") - )); + if (transfer(_fd, &tx[0], &rx[0], 3, _speed, _bits, _delay) != 0) { + throw mpm::runtime_error(str(boost::format("SPI Transaction failed!"))); } return uint32_t(rx[1] << 8 | rx[2]); @@ -111,7 +83,7 @@ private: int _fd; const uint32_t _mode; uint32_t _speed = 2000000; - uint8_t _bits = 8; + uint8_t _bits = 8; uint16_t _delay = 0; }; @@ -119,12 +91,7 @@ private: * Factory *****************************************************************************/ spi_iface::sptr spi_iface::make_spidev( - const std::string &device, - const int speed_hz, - const int spi_mode -) { - return std::make_shared<spidev_iface_impl>( - device, speed_hz, spi_mode - ); + const std::string& device, const int speed_hz, const int spi_mode) +{ + return std::make_shared<spidev_iface_impl>(device, speed_hz, spi_mode); } - diff --git a/mpm/lib/types/lockable.cpp b/mpm/lib/types/lockable.cpp index 8710e8752..cdba9e335 100644 --- a/mpm/lib/types/lockable.cpp +++ b/mpm/lib/types/lockable.cpp @@ -11,9 +11,7 @@ using namespace mpm::types; class lockable_impl : public lockable { public: - lockable_impl( - std::shared_ptr<std::mutex> spi_mutex - ) : _spi_mutex(spi_mutex) + lockable_impl(std::shared_ptr<std::mutex> spi_mutex) : _spi_mutex(spi_mutex) { /* nop */ } @@ -32,11 +30,7 @@ private: std::shared_ptr<std::mutex> _spi_mutex; }; -lockable::sptr lockable::make( - std::shared_ptr<std::mutex> spi_mutex -) { - return std::make_shared<lockable_impl>( - spi_mutex - ); +lockable::sptr lockable::make(std::shared_ptr<std::mutex> spi_mutex) +{ + return std::make_shared<lockable_impl>(spi_mutex); } - diff --git a/mpm/lib/types/log_buf.cpp b/mpm/lib/types/log_buf.cpp index f1ef0cbee..8e3f183cc 100644 --- a/mpm/lib/types/log_buf.cpp +++ b/mpm/lib/types/log_buf.cpp @@ -9,15 +9,11 @@ using namespace mpm::types; void log_buf::post( - const log_level_t log_level, - const std::string &component, - const std::string &message -) { + const log_level_t log_level, const std::string& component, const std::string& message) +{ { std::lock_guard<std::mutex> l(_buf_lock); - _buf.push_back( - log_message(log_level, component, message) - ); + _buf.push_back(log_message(log_level, component, message)); } if (bool(_notify_callback)) { @@ -25,9 +21,8 @@ void log_buf::post( } } -void log_buf::set_notify_callback( - std::function<void(void)> callback -) { +void log_buf::set_notify_callback(std::function<void(void)> callback) +{ _notify_callback = callback; } @@ -35,20 +30,12 @@ std::tuple<log_level_t, std::string, std::string> log_buf::pop() { std::lock_guard<std::mutex> l(_buf_lock); if (_buf.empty()) { - return std::make_tuple( - log_level_t::NONE, - "", - "" - ); + return std::make_tuple(log_level_t::NONE, "", ""); } auto last_msg = _buf.front(); _buf.pop_front(); - return std::make_tuple( - last_msg.log_level, - last_msg.component, - last_msg.message - ); + return std::make_tuple(last_msg.log_level, last_msg.component, last_msg.message); } log_buf::sptr log_buf::make() @@ -61,4 +48,3 @@ log_buf::sptr log_buf::make_singleton() static auto log_sptr = log_buf::make(); return log_sptr; } - diff --git a/mpm/lib/types/mmap_regs_iface.cpp b/mpm/lib/types/mmap_regs_iface.cpp index 96457d7ad..18fa2abfa 100644 --- a/mpm/lib/types/mmap_regs_iface.cpp +++ b/mpm/lib/types/mmap_regs_iface.cpp @@ -4,30 +4,26 @@ // SPDX-License-Identifier: GPL-3.0-or-later // -#include <mpm/types/mmap_regs_iface.hpp> +#include <fcntl.h> #include <mpm/exception.hpp> -#include <boost/format.hpp> -#include <iostream> -#include <sys/types.h> -#include <sys/stat.h> +#include <mpm/types/mmap_regs_iface.hpp> #include <sys/mman.h> +#include <sys/stat.h> +#include <sys/types.h> #include <unistd.h> -#include <fcntl.h> +#include <boost/format.hpp> +#include <iostream> #include <sstream> using namespace mpm::types; -mmap_regs_iface::mmap_regs_iface( - const std::string &path, +mmap_regs_iface::mmap_regs_iface(const std::string& path, const size_t length, const size_t offset, const bool read_only, - const bool open_now -) : _path(path) - , _length(length) - , _offset(offset) - , _read_only(read_only) + const bool open_now) + : _path(path), _length(length), _offset(offset), _read_only(read_only) { if (open_now) { open(); @@ -53,26 +49,23 @@ void mmap_regs_iface::open() } if (!_mmap) { - _mmap = (uint32_t *) ::mmap( - NULL, + _mmap = (uint32_t*)::mmap(NULL, _length, PROT_READ | (_read_only ? 0 : PROT_WRITE), MAP_SHARED, _fd, - (off_t) _offset - ); - if (((void *) _mmap) == MAP_FAILED) { + (off_t)_offset); + if (((void*)_mmap) == MAP_FAILED) { throw mpm::runtime_error("Failed to mmap!"); } } - log(mpm::types::log_level_t::TRACE, _path, - "Opened mmap_regs_iface"); + log(mpm::types::log_level_t::TRACE, _path, "Opened mmap_regs_iface"); } void mmap_regs_iface::close() { if (_mmap) { - int err = munmap((void *) _mmap, _length); + int err = munmap((void*)_mmap, _length); if (err) { throw mpm::runtime_error("Couldn't munmap!"); } @@ -85,14 +78,11 @@ void mmap_regs_iface::close() } _fd = -1; } - log(mpm::types::log_level_t::TRACE, _path, - "Closed mmap_regs_iface"); + log(mpm::types::log_level_t::TRACE, _path, "Closed mmap_regs_iface"); } -void mmap_regs_iface::poke32( - const uint32_t addr, - const uint32_t data -) { +void mmap_regs_iface::poke32(const uint32_t addr, const uint32_t data) +{ MPM_ASSERT_THROW(_mmap); _mmap[addr / sizeof(uint32_t)] = data; } @@ -104,14 +94,8 @@ uint32_t mmap_regs_iface::peek32(const uint32_t addr) } void mmap_regs_iface::log( - mpm::types::log_level_t level, - const std::string path, - const char *comment -) { + mpm::types::log_level_t level, const std::string path, const char* comment) +{ mpm::types::log_buf::make_singleton()->post( - level, - "MMAP_REGS_IFACE", - str(boost::format("[UIO %s] %s") - % path % comment) - ); + level, "MMAP_REGS_IFACE", str(boost::format("[UIO %s] %s") % path % comment)); } diff --git a/mpm/lib/xbar_iface.cpp b/mpm/lib/xbar_iface.cpp index cff5ed2e7..05d1e2053 100644 --- a/mpm/lib/xbar_iface.cpp +++ b/mpm/lib/xbar_iface.cpp @@ -5,41 +5,48 @@ // #include "mpm/xbar_iface.hpp" +#include <fcntl.h> #include <mpm/exception.hpp> -#include <boost/format.hpp> #include <sys/ioctl.h> -#include <fcntl.h> +#include <boost/format.hpp> using namespace mpm; std::mutex xbar_iface::_lock; // Initialize lock for all objects -xbar_iface::xbar_iface(const std::string &device){ +xbar_iface::xbar_iface(const std::string& device) +{ _fd = open(device.c_str(), O_RDWR); } -xbar_iface::~xbar_iface(){ +xbar_iface::~xbar_iface() +{ close(_fd); } -void xbar_iface::set_route(uint8_t dst_addr, uint8_t dst_port) { +void xbar_iface::set_route(uint8_t dst_addr, uint8_t dst_port) +{ std::lock_guard<std::mutex> lock(_lock); rfnoc_crossbar_cmd cmd = {.dest_addr = dst_addr, .dest_port = dst_port}; - int err = ioctl(_fd, RFNCBWROUTIOC, &cmd); + int err = ioctl(_fd, RFNCBWROUTIOC, &cmd); if (err < 0) { - throw mpm::os_error(str(boost::format("setting crossbar route failed! Error: %d") % err)); + throw mpm::os_error( + str(boost::format("setting crossbar route failed! Error: %d") % err)); } } -void xbar_iface::del_route(uint8_t dst_addr, uint8_t dst_port){ +void xbar_iface::del_route(uint8_t dst_addr, uint8_t dst_port) +{ std::lock_guard<std::mutex> lock(_lock); rfnoc_crossbar_cmd cmd = {.dest_addr = dst_addr, .dest_port = dst_port}; - int err = ioctl(_fd, RFNCDELROUTIOC, &cmd); - if (err < 0){ - throw mpm::os_error(str(boost::format("deleting crossbar route failed! Error: %d") % err)); + int err = ioctl(_fd, RFNCDELROUTIOC, &cmd); + if (err < 0) { + throw mpm::os_error( + str(boost::format("deleting crossbar route failed! Error: %d") % err)); } } -xbar_iface::sptr xbar_iface::make(const std::string &device){ +xbar_iface::sptr xbar_iface::make(const std::string& device) +{ return std::make_shared<xbar_iface>(device); } |