diff options
author | Martin Braun <martin.braun@ettus.com> | 2021-12-06 10:01:51 +0100 |
---|---|---|
committer | Aaron Rossetto <aaron.rossetto@ni.com> | 2021-12-06 07:09:14 -0800 |
commit | 8ce91bc7383409602206128839a0cf2daa932319 (patch) | |
tree | 5730d4dc5280fe2d62c3f8f8caea3a0be20e166e /mpm/python/usrp_mpm | |
parent | e1e1aad5c5a8e8a14d8c446690e6268d40cc8ae1 (diff) | |
download | uhd-8ce91bc7383409602206128839a0cf2daa932319.tar.gz uhd-8ce91bc7383409602206128839a0cf2daa932319.tar.bz2 uhd-8ce91bc7383409602206128839a0cf2daa932319.zip |
mpm: x4xx: Add checks before accessing self.dio_control
The X4x0 MPM code doesn't always load the object for the DIO control, it
only does that when certain checks pass (EEPROM readouts need to match
expected values). Therefore, `self.dio_control` may be NoneObject during
operations, and in other areas of the code, we already check if that's
the case.
The APIs added in c36fc5f don't have these checks, which means accessing
these new APIs may result in odd exceptions when trying to dereference
a NoneType object. By adding checks for the initialization state of
`self.dio_control`, we can avoid these and either substitute better
error messages / exception messages, or return safe values.
Note that mpmd_mb_controller also accesses this object indirectly by
checking the length of the return value of get_gpio_banks(). This check
is not affected by this change, as we now are guaranteed to return an
empty list if there is no self.dio_control.
Diffstat (limited to 'mpm/python/usrp_mpm')
-rw-r--r-- | mpm/python/usrp_mpm/periph_manager/x4xx.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/mpm/python/usrp_mpm/periph_manager/x4xx.py b/mpm/python/usrp_mpm/periph_manager/x4xx.py index 65bf8142c..445d905df 100644 --- a/mpm/python/usrp_mpm/periph_manager/x4xx.py +++ b/mpm/python/usrp_mpm/periph_manager/x4xx.py @@ -561,7 +561,7 @@ class x4xx(ZynqComponents, PeriphManagerBase): self._status_monitor_thread.start() # Init complete. self.log.debug("Device info: {}".format(self.device_info)) - + def _init_dio_control(self, _): """ Turn on gpio peripherals. This may throw an error on failure, so make @@ -1028,19 +1028,22 @@ class x4xx(ZynqComponents, PeriphManagerBase): ########################################################################### # GPIO API ########################################################################### - def get_gpio_banks(self): """ Returns a list of GPIO banks over which MPM has any control """ + if self.dio_control is None: + return [] return self.dio_control.get_gpio_banks() - + def get_gpio_srcs(self, bank: str): """ Return a list of valid GPIO sources for a given bank """ + if self.dio_control is None: + return [] return self.dio_control.get_gpio_srcs(bank) - + def get_gpio_src(self, bank: str): """ Return the currently selected GPIO source for a given bank. The return @@ -1048,8 +1051,10 @@ class x4xx(ZynqComponents, PeriphManagerBase): the number of controllable GPIO pins on this bank. CUSTOM is for miscellaneous pin source, and USER_APP is for LabView pin source. """ + if self.dio_control is None: + raise RuntimeError("Unable to query GPIO source: No valid DIO board installed.") return self.dio_control.get_gpio_src(bank) - + def set_gpio_src(self, bank: str, *src): """ Set the GPIO source for a given bank. @@ -1058,6 +1063,8 @@ class x4xx(ZynqComponents, PeriphManagerBase): > set_gpio_src <bank> <srcs> > set_gpio_src GPIO0 PS DB1_RF1 PS PS MPM PS PS PS MPM USER_APP PS """ + if self.dio_control is None: + raise RuntimeError("Unable to set GPIO source: No valid DIO board installed.") self.dio_control.set_gpio_src(bank, *src) ########################################################################### |