From 9573640db723386d029a294620c5b48c4d4d13d6 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Wed, 30 Mar 2022 09:39:30 +0200 Subject: mpm: x4xx: Fix clock/time source API In f73e327, we modified PeriphManagerBase to explicitly list all required methods as per the MPM/UHD API. This had an unintended side effect: Because the clocking methods on x4xx are imported from X4xxClockMgr, and not defined on x4xx itself, the method used to import methods from X4xxClockMgr onto x4xx would refuse to re-define API calls such as set_clock_source(), get_clock_source(), and so on. The solution is to allow _add_public_methods() to overwrite existing methods, which means we can overwrite abstract methods from PeriphManagerBase in this fashion. Without this patch, UHD sessions could fail in the following manner: >>> import uhd >>> U = uhd.usrp.MultiUSRP("type=x4xx") >>> U.get_clock_source(0) Traceback (most recent call last): File "", line 1, in U.get_clock_source(0) RuntimeError: RuntimeError: Error during RPC call to `get_clock_source'. Error message: get_clock_source() not available on this device! --- mpm/python/usrp_mpm/periph_manager/base.py | 6 ++++-- mpm/python/usrp_mpm/periph_manager/x4xx.py | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'mpm/python') diff --git a/mpm/python/usrp_mpm/periph_manager/base.py b/mpm/python/usrp_mpm/periph_manager/base.py index ff4a358b3..729952c33 100644 --- a/mpm/python/usrp_mpm/periph_manager/base.py +++ b/mpm/python/usrp_mpm/periph_manager/base.py @@ -659,7 +659,7 @@ class PeriphManagerBase(object): self.dboards.append(db_class(dboard_idx, **dboard_info)) self.log.info("Initialized %d daughterboard(s).", len(self.dboards)) - def _add_public_methods(self, src, prefix="", filter_cb=None): + def _add_public_methods(self, src, prefix="", filter_cb=None, allow_overwrite=False): """ Add public methods (=API) of src to self. To avoid naming conflicts and make relations clear, all added method names are prefixed with 'prefix'. @@ -677,6 +677,8 @@ class PeriphManagerBase(object): :param prefix: method names in dest will be prefixed with prefix :param filter_cb: A callback that returns true if the method should be added. Defaults to always returning True + :param allow_overwrite: If True, then methods from src will overwrite + existing methods on self. Use with care. """ filter_cb = filter_cb or (lambda *args: True) assert callable(filter_cb) @@ -691,7 +693,7 @@ class PeriphManagerBase(object): and filter_cb(name, getattr(src, name)) ]: destname = prefix + name - if hasattr(self, destname): + if hasattr(self, destname) and not allow_overwrite: self.log.warn("Cannot add method {} because it would " "overwrite existing method.".format(destname)) else: diff --git a/mpm/python/usrp_mpm/periph_manager/x4xx.py b/mpm/python/usrp_mpm/periph_manager/x4xx.py index 7479874dc..e72b2e41e 100644 --- a/mpm/python/usrp_mpm/periph_manager/x4xx.py +++ b/mpm/python/usrp_mpm/periph_manager/x4xx.py @@ -484,7 +484,8 @@ class x4xx(ZynqComponents, PeriphManagerBase): self._add_public_methods( self._clk_mgr, prefix="", - filter_cb=lambda name, method: not hasattr(method, '_norpc') + filter_cb=lambda name, method: not hasattr(method, '_norpc'), + allow_overwrite=True ) # Overlay must be applied after clocks have been configured -- cgit v1.2.3