aboutsummaryrefslogtreecommitdiffstats
path: root/mpm/python/usrp_mpm/dboard_manager
diff options
context:
space:
mode:
authorSugandha Gupta <sugandha.gupta@ettus.com>2019-01-25 11:34:47 -0800
committerBrent Stapleton <brent.stapleton@ettus.com>2019-05-01 15:17:23 -0700
commit178b35569b1a25180a80a23b945b10b04c9f10f5 (patch)
tree3adb6f78ebd148867a50526c60fe7bf9694a4a72 /mpm/python/usrp_mpm/dboard_manager
parent8a400f6a30942c9d6d3596f6989720eb4cff058b (diff)
downloaduhd-178b35569b1a25180a80a23b945b10b04c9f10f5.tar.gz
uhd-178b35569b1a25180a80a23b945b10b04c9f10f5.tar.bz2
uhd-178b35569b1a25180a80a23b945b10b04c9f10f5.zip
e310/e320: Move E310 to MPM architecture and refactor
- Turns the E310 into an MPM device (like N3xx, E320) - Factor out common code between E320 and E310, maximize sharing between the two devices - Remove all pre-MPM E310 code that is no longer needed - Modify MPM to remove all existing overlays before applying new ones (this is necessary to enable idle image mode for E310) Co-authored-by: Virendra Kakade <virendra.kakade@ni.com> Signed-off-by: Virendra Kakade <virendra.kakade@ni.com>
Diffstat (limited to 'mpm/python/usrp_mpm/dboard_manager')
-rw-r--r--mpm/python/usrp_mpm/dboard_manager/CMakeLists.txt1
-rw-r--r--mpm/python/usrp_mpm/dboard_manager/__init__.py1
-rw-r--r--mpm/python/usrp_mpm/dboard_manager/e31x_db.py212
-rw-r--r--mpm/python/usrp_mpm/dboard_manager/neon.py19
4 files changed, 231 insertions, 2 deletions
diff --git a/mpm/python/usrp_mpm/dboard_manager/CMakeLists.txt b/mpm/python/usrp_mpm/dboard_manager/CMakeLists.txt
index 650a21aab..3e4f6ba76 100644
--- a/mpm/python/usrp_mpm/dboard_manager/CMakeLists.txt
+++ b/mpm/python/usrp_mpm/dboard_manager/CMakeLists.txt
@@ -19,6 +19,7 @@ set(USRP_MPM_DBMGR_FILES
${CMAKE_CURRENT_SOURCE_DIR}/dac_rh.py
${CMAKE_CURRENT_SOURCE_DIR}/eiscat.py
${CMAKE_CURRENT_SOURCE_DIR}/neon.py
+ ${CMAKE_CURRENT_SOURCE_DIR}/e31x_db.py
${CMAKE_CURRENT_SOURCE_DIR}/gain_rh.py
${CMAKE_CURRENT_SOURCE_DIR}/gaintables_rh.py
${CMAKE_CURRENT_SOURCE_DIR}/lmk_eiscat.py
diff --git a/mpm/python/usrp_mpm/dboard_manager/__init__.py b/mpm/python/usrp_mpm/dboard_manager/__init__.py
index 70e7881db..77fd84436 100644
--- a/mpm/python/usrp_mpm/dboard_manager/__init__.py
+++ b/mpm/python/usrp_mpm/dboard_manager/__init__.py
@@ -10,6 +10,7 @@ from .base import DboardManagerBase
from .magnesium import Magnesium
from .rhodium import Rhodium
from .neon import Neon
+from .e31x_db import E31x_db
from .eiscat import EISCAT
from .test import test
from .unknown import unknown
diff --git a/mpm/python/usrp_mpm/dboard_manager/e31x_db.py b/mpm/python/usrp_mpm/dboard_manager/e31x_db.py
new file mode 100644
index 000000000..358b69f88
--- /dev/null
+++ b/mpm/python/usrp_mpm/dboard_manager/e31x_db.py
@@ -0,0 +1,212 @@
+#
+# Copyright 2018 Ettus Research, a National Instruments Company
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+"""
+E310 dboard (RF and control) implementation module
+"""
+
+import threading
+import time
+from six import iterkeys, iteritems
+from usrp_mpm import lib # Pulls in everything from C++-land
+from usrp_mpm.bfrfs import BufferFS
+from usrp_mpm.dboard_manager import DboardManagerBase
+from usrp_mpm.mpmlog import get_logger
+from usrp_mpm.sys_utils.udev import get_eeprom_paths
+from usrp_mpm.sys_utils.uio import UIO
+from usrp_mpm.periph_manager.e31x_periphs import MboardRegsControl
+from usrp_mpm.mpmutils import async_exec
+
+###############################################################################
+# Main dboard control class
+###############################################################################
+class E31x_db(DboardManagerBase):
+ """
+ Holds all dboard specific information and methods of the E31x_db dboard
+ """
+ #########################################################################
+ # Overridables
+ #
+ # See DboardManagerBase for documentation on these fields
+ #########################################################################
+ pids = [0x0110]
+ rx_sensor_callback_map = {
+ 'ad9361_temperature': 'get_catalina_temp_sensor',
+ 'rssi' : 'get_rssi_sensor',
+ 'lo_lock' : 'get_lo_lock_sensor',
+ }
+ tx_sensor_callback_map = {
+ 'ad9361_temperature': 'get_catalina_temp_sensor',
+ }
+ # Maps the chipselects to the corresponding devices:
+ spi_chipselect = {"catalina": 0,
+ }
+
+ default_master_clock_rate = 16e6
+ MIN_MASTER_CLK_RATE = 220e3
+ MAX_MASTER_CLK_RATE = 61.44e6
+
+ def __init__(self, slot_idx, **kwargs):
+ super(E31x_db, self).__init__(slot_idx, **kwargs)
+ self.log = get_logger("E31x_db-{}".format(slot_idx))
+ self.log.trace("Initializing e31x daughterboard, slot index %d",
+ self.slot_idx)
+ self.rev = int(self.device_info['rev'])
+ self.log.trace("This is a rev: {}".format(chr(65 + self.rev)))
+ # These will get updated during init()
+ self.master_clock_rate = None
+ # Predeclare some attributes to make linter happy:
+ self.catalina = None
+ self.eeprom_fs = None
+ self.eeprom_path = None
+ # Now initialize all peripherals. If that doesn't work, put this class
+ # into a non-functional state (but don't crash, or we can't talk to it
+ # any more):
+ try:
+ self._init_periphs()
+ self._periphs_initialized = True
+ except Exception as ex:
+ self.log.error("Failed to initialize peripherals: %s",
+ str(ex))
+ self._periphs_initialized = False
+
+ def _init_periphs(self):
+ """
+ Initialize power and peripherals that don't need user-settings
+ """
+ self.log.debug("Loading C++ drivers...")
+ # Setup Catalina / the E31x_db Manager
+ self._device = lib.dboards.e31x_db_manager(
+ self._spi_nodes['catalina']
+ )
+ self.catalina = self._device.get_radio_ctrl()
+ self.log.trace("Loaded C++ drivers.")
+ self._init_cat_api(self.catalina)
+
+ def _init_cat_api(self, cat):
+ """
+ Propagate the C++ Catalina API into Python land.
+ """
+ def export_method(obj, method):
+ " Export a method object, including docstring "
+ meth_obj = getattr(obj, method)
+ def func(*args):
+ " Functor for storing docstring too "
+ return meth_obj(*args)
+ func.__doc__ = meth_obj.__doc__
+ return func
+ self.log.trace("Forwarding AD9361 methods to E31x_db class...")
+ for method in [
+ x for x in dir(self.catalina)
+ if not x.startswith("_") and \
+ callable(getattr(self.catalina, x))]:
+ self.log.trace("adding {}".format(method))
+ setattr(self, method, export_method(cat, method))
+
+ def init(self, args):
+ if not self._periphs_initialized:
+ error_msg = "Cannot run init(), peripherals are not initialized!"
+ self.log.error(error_msg)
+ raise RuntimeError(error_msg)
+ master_clock_rate = \
+ float(args.get('master_clock_rate',
+ self.default_master_clock_rate))
+ assert self.MIN_MASTER_CLK_RATE <= master_clock_rate <= self.MAX_MASTER_CLK_RATE, \
+ "Invalid master clock rate: {:.02f} MHz".format(
+ master_clock_rate / 1e6)
+ master_clock_rate_changed = master_clock_rate != self.master_clock_rate
+ if master_clock_rate_changed:
+ self.master_clock_rate = master_clock_rate
+ self.log.debug("Updating master clock rate to {:.02f} MHz!".format(
+ self.master_clock_rate / 1e6
+ ))
+ # Some default chains on -- needed for setup purposes
+ self.catalina.set_active_chains(True, False, True, False)
+ self.set_catalina_clock_rate(self.master_clock_rate)
+
+ return True
+
+ def get_master_clock_rate(self):
+ " Return master clock rate (== sampling rate) "
+ return self.master_clock_rate
+
+ ##########################################################################
+ # Sensors
+ ##########################################################################
+ def get_ad9361_lo_lock(self, which):
+ """
+ Return LO lock status (Boolean!) of AD9361. 'which' must be
+ either 'tx' or 'rx'
+ """
+ self.mboard_regs_label = "mboard-regs"
+ self.mboard_regs_control = MboardRegsControl(
+ self.mboard_regs_label, self.log)
+ if which == "tx":
+ locked = self. mboard_regs_control.get_ad9361_tx_lo_lock()
+ elif which == "rx":
+ locked = self. mboard_regs_control.get_ad9361_rx_lo_lock()
+ else:
+ locked = False
+ return locked
+
+ def get_lo_lock_sensor(self, which):
+ """
+ Get sensor dict with LO lock status
+ """
+ self.log.trace("Reading LO Lock.")
+ lo_locked = self.get_ad9361_lo_lock(which)
+ return {
+ 'name': 'ad9361_lock',
+ 'type': 'BOOLEAN',
+ 'unit': 'locked' if lo_locked else 'unlocked',
+ 'value': str(lo_locked).lower(),
+ }
+
+ def get_catalina_temp_sensor(self, _):
+ """
+ Get temperature sensor reading of Catalina.
+ """
+ # Note: the unused argument is channel
+ self.log.trace("Reading Catalina temperature.")
+ return {
+ 'name': 'ad9361_temperature',
+ 'type': 'REALNUM',
+ 'unit': 'C',
+ 'value': str(self.catalina.get_temperature())
+ }
+
+ def get_rssi_val(self, which):
+ """
+ Return the current RSSI of `which` chain in Catalina
+ """
+ return self.catalina.get_rssi(which)
+
+ def get_rssi_sensor(self, chan):
+ """
+ Return a sensor dictionary containing the current RSSI of `which` chain in Catalina
+ """
+ which = 'RX' + str(chan+1)
+ return {
+ 'name': 'rssi',
+ 'type': 'REALNUM',
+ 'unit': 'dB',
+ 'value': str(self.get_rssi_val(which)),
+ }
+
+ def set_catalina_clock_rate(self, rate):
+ """
+ Async call to catalina set_clock_rate
+ """
+ self.log.trace("Setting Clock rate to {}".format(rate))
+ async_exec(lib.ad9361, "set_clock_rate", self.catalina, rate)
+ return rate
+
+ def catalina_tune(self, which, freq):
+ """
+ Async call to catalina tune
+ """
+ self.log.trace("Tuning {} {}".format(which, freq))
+ async_exec(lib.ad9361, "tune", self.catalina, which, freq)
+ return self.catalina.get_freq(which)
diff --git a/mpm/python/usrp_mpm/dboard_manager/neon.py b/mpm/python/usrp_mpm/dboard_manager/neon.py
index c0eb10eae..00438503d 100644
--- a/mpm/python/usrp_mpm/dboard_manager/neon.py
+++ b/mpm/python/usrp_mpm/dboard_manager/neon.py
@@ -18,7 +18,7 @@ from usrp_mpm.mpmlog import get_logger
from usrp_mpm.sys_utils.udev import get_eeprom_paths
from usrp_mpm.sys_utils.uio import UIO
from usrp_mpm.periph_manager.e320_periphs import MboardRegsControl
-
+from usrp_mpm.mpmutils import async_exec
###############################################################################
# Main dboard control class
@@ -186,7 +186,7 @@ class Neon(DboardManagerBase):
))
# Some default chains on -- needed for setup purposes
self.catalina.set_active_chains(True, False, True, False)
- self.catalina.set_clock_rate(self.master_clock_rate)
+ self.set_catalina_clock_rate(self.master_clock_rate)
return True
@@ -321,3 +321,18 @@ class Neon(DboardManagerBase):
'value': str(self.get_rssi_val(which)),
}
+ def set_catalina_clock_rate(self, rate):
+ """
+ Async call to catalina set_clock_rate
+ """
+ self.log.trace("Setting Clock rate to {}".format(rate))
+ async_exec(lib.ad9361, "set_clock_rate", self.catalina, rate)
+ return rate
+
+ def catalina_tune(self, which, freq):
+ """
+ Async call to catalina tune
+ """
+ self.log.trace("Tuning {} {}".format(which, freq))
+ async_exec(lib.ad9361, "tune", self.catalina, which, freq)
+ return self.catalina.get_freq(which)