aboutsummaryrefslogtreecommitdiffstats
path: root/mpm/python/usrp_mpm/mpmutils.py
diff options
context:
space:
mode:
authorLars Amsel <lars.amsel@ni.com>2021-06-04 08:27:50 +0200
committerAaron Rossetto <aaron.rossetto@ni.com>2021-06-10 12:01:53 -0500
commit2a575bf9b5a4942f60e979161764b9e942699e1e (patch)
tree2f0535625c30025559ebd7494a4b9e7122550a73 /mpm/python/usrp_mpm/mpmutils.py
parente17916220cc955fa219ae37f607626ba88c4afe3 (diff)
downloaduhd-2a575bf9b5a4942f60e979161764b9e942699e1e.tar.gz
uhd-2a575bf9b5a4942f60e979161764b9e942699e1e.tar.bz2
uhd-2a575bf9b5a4942f60e979161764b9e942699e1e.zip
uhd: Add support for the USRP X410
Co-authored-by: Lars Amsel <lars.amsel@ni.com> Co-authored-by: Michael Auchter <michael.auchter@ni.com> Co-authored-by: Martin Braun <martin.braun@ettus.com> Co-authored-by: Paul Butler <paul.butler@ni.com> Co-authored-by: Cristina Fuentes <cristina.fuentes-curiel@ni.com> Co-authored-by: Humberto Jimenez <humberto.jimenez@ni.com> Co-authored-by: Virendra Kakade <virendra.kakade@ni.com> Co-authored-by: Lane Kolbly <lane.kolbly@ni.com> Co-authored-by: Max Köhler <max.koehler@ni.com> Co-authored-by: Andrew Lynch <andrew.lynch@ni.com> Co-authored-by: Grant Meyerhoff <grant.meyerhoff@ni.com> Co-authored-by: Ciro Nishiguchi <ciro.nishiguchi@ni.com> Co-authored-by: Thomas Vogel <thomas.vogel@ni.com>
Diffstat (limited to 'mpm/python/usrp_mpm/mpmutils.py')
-rw-r--r--mpm/python/usrp_mpm/mpmutils.py47
1 files changed, 35 insertions, 12 deletions
diff --git a/mpm/python/usrp_mpm/mpmutils.py b/mpm/python/usrp_mpm/mpmutils.py
index 5da81ecfe..a569c85ad 100644
--- a/mpm/python/usrp_mpm/mpmutils.py
+++ b/mpm/python/usrp_mpm/mpmutils.py
@@ -8,6 +8,7 @@ Miscellaneous utilities for MPM
"""
import time
+import pyudev
from contextlib import contextmanager
def poll_with_timeout(state_check, timeout_ms, interval_ms):
@@ -90,18 +91,18 @@ def assert_compat_number(
log=None,
):
"""
- Check if a compat number pair is acceptable. A compat number is a pair of
- integers (MAJOR, MINOR). A compat number is not acceptable if the major
+ Check if a compat number tuple is acceptable. A compat number is a tuple of
+ integers (MAJOR, MINOR, BUILD). A compat number is not acceptable if the major
part differs from the expected value (regardless of how it's different) or
if the minor part is behind the expected value and fail_on_old_minor was
- given.
+ given. Build number is not checked here.
On failure, will throw a RuntimeError.
Arguments:
- expected_compat -- A tuple (major, minor) which represents the compat
- number we are expecting.
- actual_compat -- A tuple (major, minor) which represents the compat number
- that is actually available.
+ expected_compat -- A tuple (major, minor) or (major, minor, build) which
+ represents the compat number we are expecting.
+ actual_compat -- A tuple (major, minor) or (major, minor, build) which
+ represents the compat number that is actually available.
component -- A name of the component for which we are checking the compat
number, e.g. "FPGA".
fail_on_old_minor -- Will also fail if the actual minor compat number is
@@ -110,15 +111,20 @@ def assert_compat_number(
log -- Logger object. If given, will use this to report on intermediate
steps and non-fatal minor compat mismatches.
"""
- assert len(expected_compat) == 2
- assert len(actual_compat) == 2
+ valid_tuple_lengths = (2, 3)
+ assert len(expected_compat) in valid_tuple_lengths, (
+ f"Version {expected_compat} has invalid format. Valid formats are"
+ "(major, minor) or (major, minor, build)")
+ assert len(actual_compat) in valid_tuple_lengths, (
+ f"Version {expected_compat} has invalid format. Valid formats are"
+ "(major, minor) or (major, minor, build)")
log_err = lambda msg: log.error(msg) if log is not None else None
log_warn = lambda msg: log.warning(msg) if log is not None else None
expected_actual_str = "Expected: {:d}.{:d} Actual: {:d}.{:d}".format(
expected_compat[0], expected_compat[1],
actual_compat[0], actual_compat[1],
)
- component_str = "" if component is None else " for component `{}'".format(
+ component_str = "" if component is None else " for component '{}'".format(
component
)
if actual_compat[0] != expected_compat[0]:
@@ -128,7 +134,7 @@ def assert_compat_number(
log_err(err_msg)
raise RuntimeError(err_msg)
if actual_compat[1] > expected_compat[1]:
- log_warn("Actual minor compat ahead of expected compat{}. {}".format(
+ log_warn("Minor compat ahead of expected compat{}. {}".format(
component_str, expected_actual_str
))
if actual_compat[1] < expected_compat[1]:
@@ -139,7 +145,6 @@ def assert_compat_number(
log_err(err_msg)
raise RuntimeError(err_msg)
log_warn(err_msg)
- return
def str2bool(value):
"""Return a Boolean value from a string, even if the string is not simply
@@ -188,3 +193,21 @@ def lock_guard(lockable):
finally:
lockable.unlock()
+def check_fpga_state(which=0, logger=None):
+ """
+ Check if the FPGA is operational
+ :param which: the FPGA to check
+ """
+ try:
+ context = pyudev.Context()
+ fpga_mgrs = list(context.list_devices(subsystem="fpga_manager"))
+ if fpga_mgrs:
+ state = fpga_mgrs[which].attributes.asstring('state')
+ if logger is not None:
+ logger.trace("FPGA State: {}".format(state))
+ return state == "operating"
+ return False
+ except OSError as ex:
+ if logger is not None:
+ logger.error("Error while checking FPGA status: {}".format(ex))
+ return False