From df9ca47ed1301eb131fdc0dbdd1e2ab052549aff Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Tue, 2 May 2017 12:54:55 -0700 Subject: mpm: eiscat: magnesium: Removed C++-only SPI ifaces - EISCAT is now Python only with the exception of the definition of the SPI ifaces - Magnesium uses a Python-generated SPI iface - Removed SPI lock from EISCAT dboard --- mpm/include/mpm/chips/CMakeLists.txt | 8 +-- mpm/include/mpm/chips/lmk04828_spi_iface.hpp | 33 ----------- mpm/include/mpm/dboards/eiscat_manager.hpp | 70 ------------------------ mpm/include/mpm/dboards/magnesium_manager.hpp | 11 +--- mpm/lib/chips/CMakeLists.txt | 6 +- mpm/lib/chips/lmk04828_spi_iface.cpp | 40 -------------- mpm/lib/dboards/CMakeLists.txt | 2 - mpm/lib/dboards/eiscat_manager.cpp | 36 ------------ mpm/lib/dboards/magnesium_manager.cpp | 3 - mpm/python/pyusrp_periphs.cpp | 3 - mpm/python/usrp_mpm/dboard_manager/eiscat.py | 59 ++++++++++++++------ mpm/python/usrp_mpm/dboard_manager/lmk_eiscat.py | 5 +- mpm/python/usrp_mpm/dboard_manager/magnesium.py | 15 ++++- 13 files changed, 64 insertions(+), 227 deletions(-) delete mode 100644 mpm/include/mpm/chips/lmk04828_spi_iface.hpp delete mode 100644 mpm/include/mpm/dboards/eiscat_manager.hpp delete mode 100644 mpm/lib/chips/lmk04828_spi_iface.cpp delete mode 100644 mpm/lib/dboards/eiscat_manager.cpp diff --git a/mpm/include/mpm/chips/CMakeLists.txt b/mpm/include/mpm/chips/CMakeLists.txt index 35df8d624..e0c0fb18c 100644 --- a/mpm/include/mpm/chips/CMakeLists.txt +++ b/mpm/include/mpm/chips/CMakeLists.txt @@ -14,7 +14,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -INSTALL(FILES - lmk04828_spi_iface.hpp - DESTINATION ${INCLUDE_DIR}/mpm/lmk04828 -) +#INSTALL(FILES + + #DESTINATION ${INCLUDE_DIR}/mpm/lmk04828 +#) diff --git a/mpm/include/mpm/chips/lmk04828_spi_iface.hpp b/mpm/include/mpm/chips/lmk04828_spi_iface.hpp deleted file mode 100644 index ae897f02f..000000000 --- a/mpm/include/mpm/chips/lmk04828_spi_iface.hpp +++ /dev/null @@ -1,33 +0,0 @@ -// -// Copyright 2017 Ettus Research (National Instruments) -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - -#pragma once - -#include - -namespace mpm { namespace chips { - - /*! Return a peek/poke interface to the LMK04828 - * - * Assumption is it is attached to a spidev - */ - mpm::types::regs_iface::sptr make_lmk04828_iface( - const std::string &spi_device - ); - -}}; /* namespace mpm::chips */ - diff --git a/mpm/include/mpm/dboards/eiscat_manager.hpp b/mpm/include/mpm/dboards/eiscat_manager.hpp deleted file mode 100644 index 42f80ff8e..000000000 --- a/mpm/include/mpm/dboards/eiscat_manager.hpp +++ /dev/null @@ -1,70 +0,0 @@ -// -// Copyright 2017 Ettus Research (National Instruments) -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - -#pragma once - -#include -#include -#include -#include - -namespace mpm { namespace dboards { - class eiscat_manager// : public dboard_periph_manager - { - public: - eiscat_manager( - const std::string &lmk_spidev, - const std::string &adc0_spidev, - const std::string &adc1_spidev - //const std::string &phdac_spidev, - ); - - /*! Return a reference to the SPI mutex - */ - mpm::types::lockable::sptr get_spi_lock() { return _spi_lock; } - - /*! Return a reference to the clock chip controls - */ - mpm::types::regs_iface::sptr get_clock_ctrl(){ return _clock_ctrl; } - - mpm::types::regs_iface::sptr get_adc0_ctrl(){ return _adc0_ctrl; } - mpm::types::regs_iface::sptr get_adc1_ctrl(){ return _adc1_ctrl; } - - private: - std::shared_ptr _spi_mutex; - - mpm::types::lockable::sptr _spi_lock; - mpm::types::regs_iface::sptr _clock_ctrl; - mpm::types::regs_iface::sptr _adc0_ctrl; - mpm::types::regs_iface::sptr _adc1_ctrl; - //mpm::types::regs_iface::sptr _phdac_ctrl; - }; - -}}; /* namespace mpm::dboards */ - -#ifdef LIBMPM_PYTHON -void export_eiscat(){ - LIBMPM_BOOST_PREAMBLE("eiscat") - using namespace mpm::dboards; - bp::class_("eiscat_manager", bp::init()) - .def("get_spi_lock", &mpm::dboards::eiscat_manager::get_spi_lock) - .def("get_clock_ctrl", &mpm::dboards::eiscat_manager::get_clock_ctrl) - .def("get_adc0_ctrl", &mpm::dboards::eiscat_manager::get_adc0_ctrl) - .def("get_adc1_ctrl", &mpm::dboards::eiscat_manager::get_adc1_ctrl) - ; -} -#endif diff --git a/mpm/include/mpm/dboards/magnesium_manager.hpp b/mpm/include/mpm/dboards/magnesium_manager.hpp index beb5a3cc2..60a38b853 100644 --- a/mpm/include/mpm/dboards/magnesium_manager.hpp +++ b/mpm/include/mpm/dboards/magnesium_manager.hpp @@ -28,7 +28,6 @@ namespace mpm { namespace dboards { { public: magnesium_manager( - const std::string &lmk_spidev, const std::string &mykonos_spidev ); @@ -36,10 +35,6 @@ namespace mpm { namespace dboards { */ mpm::types::lockable::sptr get_spi_lock() { return _spi_lock; } - /*! Return a reference to the clock chip controls - */ - mpm::types::regs_iface::sptr get_clock_ctrl(){ return _clock_ctrl; } - /*! Return a reference to the radio chip controls */ mpm::chips::ad937x_ctrl::sptr get_radio_ctrl(){ return _mykonos_ctrl; } @@ -47,10 +42,9 @@ namespace mpm { namespace dboards { private: std::shared_ptr _spi_mutex; - // TODO: cpld control + // TODO: cpld control, or maybe it goes into Python mpm::types::lockable::sptr _spi_lock; - mpm::types::regs_iface::sptr _clock_ctrl; mpm::chips::ad937x_ctrl::sptr _mykonos_ctrl; }; @@ -60,9 +54,8 @@ namespace mpm { namespace dboards { void export_magnesium(){ LIBMPM_BOOST_PREAMBLE("dboards") using namespace mpm::dboards; - bp::class_("magnesium_manager", bp::init()) + bp::class_("magnesium_manager", bp::init()) .def("get_spi_lock", &mpm::dboards::magnesium_manager::get_spi_lock) - .def("get_clock_ctrl", &mpm::dboards::magnesium_manager::get_clock_ctrl) .def("get_radio_ctrl", &mpm::dboards::magnesium_manager::get_radio_ctrl) ; } diff --git a/mpm/lib/chips/CMakeLists.txt b/mpm/lib/chips/CMakeLists.txt index 519ab1fe8..db6559ad1 100644 --- a/mpm/lib/chips/CMakeLists.txt +++ b/mpm/lib/chips/CMakeLists.txt @@ -50,6 +50,6 @@ #SET(LIBUHD_PYTHON_GEN_SOURCE_DEPS) # Define the object -USRP_PERIPHS_ADD_OBJECT(chips - lmk04828_spi_iface.cpp -) +#USRP_PERIPHS_ADD_OBJECT(chips + #lmk04828_spi_iface.cpp +#) diff --git a/mpm/lib/chips/lmk04828_spi_iface.cpp b/mpm/lib/chips/lmk04828_spi_iface.cpp deleted file mode 100644 index 6f21a0f46..000000000 --- a/mpm/lib/chips/lmk04828_spi_iface.cpp +++ /dev/null @@ -1,40 +0,0 @@ -// -// Copyright 2017 Ettus Research (National Instruments) -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - -#include -#include - -using namespace mpm::spi; - -static const int LMK_SPI_SPEED_HZ = 1000000; -static const size_t LMK_ADDR_SHIFT = 8; -static const size_t LMK_DATA_SHIFT = 0; -static const size_t LMK_READ_FLAG = 1 << 23; -static const size_t LMK_WRITE_FLAG = 0; - -mpm::types::regs_iface::sptr mpm::chips::make_lmk04828_iface( - const std::string &spi_device -) { - return make_spi_regs_iface( - spi_iface::make_spidev(spi_device, LMK_SPI_SPEED_HZ), - LMK_ADDR_SHIFT, - LMK_DATA_SHIFT, - LMK_READ_FLAG, - LMK_WRITE_FLAG - ); -} - diff --git a/mpm/lib/dboards/CMakeLists.txt b/mpm/lib/dboards/CMakeLists.txt index 4ca21ee37..b615d9289 100644 --- a/mpm/lib/dboards/CMakeLists.txt +++ b/mpm/lib/dboards/CMakeLists.txt @@ -19,9 +19,7 @@ # This file included, use CMake directory variables ######################################################################## - USRP_PERIPHS_ADD_OBJECT(dboards magnesium_manager.cpp - eiscat_manager.cpp ) diff --git a/mpm/lib/dboards/eiscat_manager.cpp b/mpm/lib/dboards/eiscat_manager.cpp deleted file mode 100644 index f3a9794f8..000000000 --- a/mpm/lib/dboards/eiscat_manager.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// -// Copyright 2017 Ettus Research (National Instruments) -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - -#include -#include - -using namespace mpm::dboards; -using namespace mpm::chips; - -eiscat_manager::eiscat_manager( - const std::string &lmk_spidev, - const std::string &adc0_spidev, - const std::string &adc1_spidev -) : _spi_mutex(std::make_shared()) - , _spi_lock(mpm::types::lockable::make(_spi_mutex)) - , _clock_ctrl(mpm::chips::make_lmk04828_iface(lmk_spidev)) - , _adc0_ctrl(mpm::chips::make_lmk04828_iface(adc0_spidev)) - , _adc1_ctrl(mpm::chips::make_lmk04828_iface(adc1_spidev)) -{ - -} - diff --git a/mpm/lib/dboards/magnesium_manager.cpp b/mpm/lib/dboards/magnesium_manager.cpp index f66364aec..cb215f893 100644 --- a/mpm/lib/dboards/magnesium_manager.cpp +++ b/mpm/lib/dboards/magnesium_manager.cpp @@ -16,18 +16,15 @@ // #include -#include #include using namespace mpm::dboards; using namespace mpm::chips; magnesium_manager::magnesium_manager( - const std::string &lmk_spidev, const std::string &mykonos_spidev ) : _spi_mutex(std::make_shared()) , _spi_lock(mpm::types::lockable::make(_spi_mutex)) - , _clock_ctrl(mpm::chips::make_lmk04828_iface(lmk_spidev)) , _mykonos_ctrl(ad937x_ctrl::make( _spi_mutex, make_ad937x_iface(mykonos_spidev), diff --git a/mpm/python/pyusrp_periphs.cpp b/mpm/python/pyusrp_periphs.cpp index c48860ebe..c50b8e14f 100644 --- a/mpm/python/pyusrp_periphs.cpp +++ b/mpm/python/pyusrp_periphs.cpp @@ -31,9 +31,7 @@ #include #include #include -#include #include -#include #include namespace bp = boost::python; @@ -48,5 +46,4 @@ BOOST_PYTHON_MODULE(libpyusrp_periphs) export_mykonos(); export_xbar(); export_magnesium(); - export_eiscat(); } diff --git a/mpm/python/usrp_mpm/dboard_manager/eiscat.py b/mpm/python/usrp_mpm/dboard_manager/eiscat.py index 55caa79f9..8db939747 100644 --- a/mpm/python/usrp_mpm/dboard_manager/eiscat.py +++ b/mpm/python/usrp_mpm/dboard_manager/eiscat.py @@ -40,6 +40,24 @@ PWR2_5V_ADC1_SPI_EN = 1<<13 ADC_RESET = 0x2008 +def create_spidev_iface(dev_node): + """ + Create a regs iface from a spidev node + """ + SPI_SPEED_HZ = 1000000 + SPI_ADDR_SHIFT = 8 + SPI_DATA_SHIFT = 0 + SPI_READ_FLAG = 1<<23 + SPI_WRIT_FLAG = 0 + return lib.spi.make_spidev_regs_iface( + dev_node, + SPI_SPEED_HZ, + SPI_ADDR_SHIFT, + SPI_DATA_SHIFT, + SPI_READ_FLAG, + SPI_WRIT_FLAG + ) + class ADS54J56(object): """ Controls for ADS54J56 ADC @@ -323,36 +341,41 @@ class EISCAT(DboardManagerBase): )) raise RuntimeError("Not enough SPI devices found.") self._spi_nodes = {} + self._spi_ifaces = {} + self.log.trace("Loading SPI interfaces...") for k, v in iteritems(self.spi_chipselect): self._spi_nodes[k] = spi_devices[v] + self._spi_ifaces[k] = create_spidev_iface(self._spi_nodes[k]) + self.log.info("Loaded SPI interfaces!") self.log.debug("spidev device node map: {}".format(self._spi_nodes)) + # Define some attributes so that PyLint stays quiet: + self.radio_regs = None + self.jesd_cores = None + self.lmk = None + self.adc0 = None + self.adc1 = None def init_device(self): """ Execute necessary actions to bring up the daughterboard + + This assumes that an appropriate overlay was loaded. """ - self.log.debug("Loading C++ drivers...") - self._device = lib.eiscat.eiscat_manager( - self._spi_nodes['lmk'], - self._spi_nodes['adc0'], - self._spi_nodes['adc1'], - # self._spi_nodes['phasedac'], - ) - self.lmk_regs = self._device.get_clock_ctrl() - self.adc0_regs = self._device.get_adc0_ctrl() - self.adc1_regs = self._device.get_adc1_ctrl() - self.spi_lock = self._device.get_spi_lock() - self.log.debug("Loaded C++ drivers.") - self.log.debug("Getting uio...") + self.log.trace("Loading SPI interfaces...") + for chip, spi_dev_node in iteritems(self._spi_nodes): + self._spi_ifaces[chip] = create_spidev_iface(spi_dev_node) + self.log.info("Loaded SPI interfaces!") + self.log.debug("spidev device node map: {}".format(self._spi_nodes)) + self.log.trace("Getting uio...") self.radio_regs = UIO(label="jesd204b-regs", read_only=False) # Create JESD cores. They will also test the UIO regs on initialization. self.jesd_cores = [ JesdCoreEiscat( self.radio_regs, "A", # TODO fix hard-coded slot number - x, + core_idx, self.log - ) for x in xrange(2) + ) for core_idx in xrange(2) ] self.log.info("Radio-register UIO object successfully generated!") @@ -362,7 +385,7 @@ class EISCAT(DboardManagerBase): self.mmcm = MMCM(self.radio_regs, self.log) self._init_power(self.radio_regs) self.mmcm.reset() - self.lmk = LMK04828EISCAT(self.lmk_regs, self.spi_lock, "A") # Initializes LMK + self.lmk = LMK04828EISCAT(self._spi_ifaces['lmk'], "A") # Initializes LMK if not self.mmcm.enable(): self.log.error("Could not re-enable MMCM!") raise RuntimeError("Could not re-enable MMCM!") @@ -370,8 +393,8 @@ class EISCAT(DboardManagerBase): # Initialize ADCs and JESD cores for i in xrange(2): self.jesd_cores[i].init() - self.adc0 = ADS54J56(self.adc0_regs, self.log) - self.adc1 = ADS54J56(self.adc1_regs, self.log) + self.adc0 = ADS54J56(self._spi_ifaces['adc0'], self.log) + self.adc1 = ADS54J56(self._spi_ifaces['adc1'], self.log) self.adc0.reset() self.adc1.reset() self.log.info("ADCs resetted!") diff --git a/mpm/python/usrp_mpm/dboard_manager/lmk_eiscat.py b/mpm/python/usrp_mpm/dboard_manager/lmk_eiscat.py index 733f8fbef..f5114607a 100644 --- a/mpm/python/usrp_mpm/dboard_manager/lmk_eiscat.py +++ b/mpm/python/usrp_mpm/dboard_manager/lmk_eiscat.py @@ -27,11 +27,10 @@ class LMK04828EISCAT(object): """ LMK04828 controls for EISCAT daughterboard """ - def __init__(self, regs_iface, spi_lock, slot=None): + def __init__(self, regs_iface, slot=None): slot = slot or "-A" self.log = get_logger("LMK04828"+slot) self.regs_iface = regs_iface - self.spi_lock = spi_lock self.init() self.config() @@ -221,8 +220,6 @@ class LMK04828EISCAT(object): # """ # Enable SYSREF pulses # """ - # self.spi_lock.lock() # self.poke8(0x139, 0x2) # self.poke8(0x144, 0xFF) # self.poke8(0x143, 0x52) - # self.spi_lock.unlock() diff --git a/mpm/python/usrp_mpm/dboard_manager/magnesium.py b/mpm/python/usrp_mpm/dboard_manager/magnesium.py index f6db4885c..aa667e1e0 100644 --- a/mpm/python/usrp_mpm/dboard_manager/magnesium.py +++ b/mpm/python/usrp_mpm/dboard_manager/magnesium.py @@ -56,10 +56,21 @@ class Magnesium(DboardManagerBase): """ self.log.debug("Loading C++ drivers...") self._device = lib.dboards.magnesium_manager( - self._spi_nodes['lmk'], self._spi_nodes['mykonos'], ) - self.lmk = self._device.get_clock_ctrl() + SPI_SPEED_HZ = 1000000 + SPI_ADDR_SHIFT = 8 + SPI_DATA_SHIFT = 0 + SPI_READ_FLAG = 1<<23 + SPI_WRIT_FLAG = 0 + self.lmk = lib.spi.make_spidev_regs_iface( + dev_node, + SPI_SPEED_HZ, + SPI_ADDR_SHIFT, + SPI_DATA_SHIFT, + SPI_READ_FLAG, + SPI_WRIT_FLAG + ) self.mykonos = self._device.get_radio_ctrl() self.log.debug("Loaded C++ drivers.") self.log.debug("Getting Mg A uio...") -- cgit v1.2.3