aboutsummaryrefslogtreecommitdiffstats
path: root/mpm
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2017-11-17 11:13:42 -0800
committerMartin Braun <martin.braun@ettus.com>2017-12-22 15:05:06 -0800
commit0fdf93748aaa6ea92ec674f4b469de0a9aab4442 (patch)
treed30b06f32740e1efb97c075cdec165a73df89106 /mpm
parente75497921e8edf48512c8bb6d2659e67c6738fbc (diff)
downloaduhd-0fdf93748aaa6ea92ec674f4b469de0a9aab4442.tar.gz
uhd-0fdf93748aaa6ea92ec674f4b469de0a9aab4442.tar.bz2
uhd-0fdf93748aaa6ea92ec674f4b469de0a9aab4442.zip
mpm: Make dboard manager __init__ exception-safe
Diffstat (limited to 'mpm')
-rw-r--r--mpm/python/usrp_mpm/dboard_manager/base.py29
1 files changed, 17 insertions, 12 deletions
diff --git a/mpm/python/usrp_mpm/dboard_manager/base.py b/mpm/python/usrp_mpm/dboard_manager/base.py
index bbba27613..ef12c697a 100644
--- a/mpm/python/usrp_mpm/dboard_manager/base.py
+++ b/mpm/python/usrp_mpm/dboard_manager/base.py
@@ -79,25 +79,30 @@ class DboardManagerBase(object):
for key in ('pid', 'serial', 'rev', 'eeprom_version')
}
self.log.trace("Dboard device info: `{}'".format(self.device_info))
- self._init_spi_nodes(kwargs.get('spi_nodes', []))
+ self._spi_nodes = self._init_spi_nodes(
+ kwargs.get('spi_nodes', []),
+ self.spi_chipselect
+ )
+ self.log.debug("spidev device node map: {}".format(self._spi_nodes))
- def _init_spi_nodes(self, spi_devices):
+ def _init_spi_nodes(self, spi_devices, chip_select_map):
"""
- Populates the self._spi_nodes dictionary.
+ Populates a spi_nodes dictionary.
Note that this won't instantiate any spidev objects, it'll just map
- keys from self.spi_chipselect to spidev nodes, and do a sanity check
+ keys from chip_select_map to spidev nodes, and do a sanity check
that enough nodes are available.
"""
- if len(spi_devices) < len(self.spi_chipselect):
- self.log.error("Expected {0} spi devices, found {1} spi devices".format(
- len(self.spi_chipselect), len(spi_devices),
+ if len(spi_devices) < len(chip_select_map):
+ self.log.error("Expected {0} spi devices, found {1}".format(
+ len(chip_select_map), len(spi_devices),
))
- raise RuntimeError("Not enough SPI devices found.")
- self._spi_nodes = {}
- for k, v in iteritems(self.spi_chipselect):
- self._spi_nodes[k] = spi_devices[v]
- self.log.debug("spidev device node map: {}".format(self._spi_nodes))
+ self.log.error("Not enough SPI devices found.")
+ return {}
+ return {
+ spi_device: spi_devices[chip_select]
+ for spi_device, chip_select in iteritems(chip_select_map)
+ }
def init(self, args):
"""