diff options
author | Martin Braun <martin.braun@ettus.com> | 2017-04-26 17:25:23 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2017-12-22 15:03:52 -0800 |
commit | af6d2409499da5ffb0da1cb4d3d50293774937e8 (patch) | |
tree | 6408dc6254fb33e6e855fd3086ae9e7a6e41655f | |
parent | 658bdb71d89d1d8cd4be88f7f1b28c44682f5850 (diff) | |
download | uhd-af6d2409499da5ffb0da1cb4d3d50293774937e8.tar.gz uhd-af6d2409499da5ffb0da1cb4d3d50293774937e8.tar.bz2 uhd-af6d2409499da5ffb0da1cb4d3d50293774937e8.zip |
mpm: Improved udev identification of SPI device nodes
-rw-r--r-- | mpm/python/usrp_mpm/dboard_manager/__init__.py | 4 | ||||
-rw-r--r-- | mpm/python/usrp_mpm/dboard_manager/base.py | 2 | ||||
-rw-r--r-- | mpm/python/usrp_mpm/dboard_manager/magnesium.py | 39 | ||||
-rw-r--r-- | mpm/python/usrp_mpm/periph_manager/base.py | 4 | ||||
-rw-r--r-- | mpm/python/usrp_mpm/periph_manager/udev.py | 2 |
5 files changed, 22 insertions, 29 deletions
diff --git a/mpm/python/usrp_mpm/dboard_manager/__init__.py b/mpm/python/usrp_mpm/dboard_manager/__init__.py index f21e5258c..e1ae5d3e0 100644 --- a/mpm/python/usrp_mpm/dboard_manager/__init__.py +++ b/mpm/python/usrp_mpm/dboard_manager/__init__.py @@ -18,12 +18,12 @@ dboards module __init__.py """ from .. import libpyusrp_periphs as lib -from .magnesium import magnesium +from .magnesium import Magnesium from .eiscat import eiscat from .test import test from .unknown import unknown HW_PIDS = { eiscat.hw_pid: eiscat, - magnesium.hw_pid: magnesium, + Magnesium.hw_pid: Magnesium, } diff --git a/mpm/python/usrp_mpm/dboard_manager/base.py b/mpm/python/usrp_mpm/dboard_manager/base.py index 0e8d1b7e4..52d2f22a3 100644 --- a/mpm/python/usrp_mpm/dboard_manager/base.py +++ b/mpm/python/usrp_mpm/dboard_manager/base.py @@ -17,7 +17,7 @@ """ dboard base implementation module """ -import struct + from ..mpmlog import get_logger class DboardManagerBase(object): diff --git a/mpm/python/usrp_mpm/dboard_manager/magnesium.py b/mpm/python/usrp_mpm/dboard_manager/magnesium.py index cee2f0915..9d645a354 100644 --- a/mpm/python/usrp_mpm/dboard_manager/magnesium.py +++ b/mpm/python/usrp_mpm/dboard_manager/magnesium.py @@ -20,55 +20,48 @@ magnesium dboard implementation module import struct import time +from six import iteritems from . import lib # Pulls in everything from C++-land from .base import DboardManagerBase from .. import nijesdcore from ..uio import UIO +from ..mpmlog import get_logger -class magnesium(DboardManagerBase): +class Magnesium(DboardManagerBase): """ Holds all dboard specific information and methods of the magnesium dboard """ hw_pid = 2 special_eeprom_addrs = {"special0": "something"} - spi_chipselect = {"0": "lmk", "1": "mykonos",} - spidevs = {} - lmk = "" - mykonos = "" - random = "" + # Maps the chipselects to the corresponding devices: + spi_chipselect = {"lmk": 0, "mykonos": 1} def __init__(self, spi_devices, eeprom_data, *args, **kwargs): - super(magnesium, self).__init__(*args, **kwargs) + super(Magnesium, self).__init__(*args, **kwargs) + self.log = get_logger("Magnesium") # eeprom_data is a tuple (head_dict, raw_data) 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), )) - exit(1) - for spi in spi_devices: - device = self.spi_chipselect.get(spi[-1], None) - # if self.chipselect is None: - # self.log.error("Unexpected chipselect {0}".format(spi[-1])) - # exit(1) - setattr(self, device, spi) - self.log.debug("Setting spi device for {device}: {spidev}".format( - device=device, spidev=spi - )) + 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)) def init_device(self): """ Execute necessary init dance to bring up dboard """ - self.log.debug("initialize hardware") + self.log.debug("Loading C++ drivers...") self._device = lib.dboards.magnesium_manager( - # self.lmk.encode('ascii'), self.mykonos.encode('ascii') - '/dev/spidev0.0', - '/dev/spidev0.1', + self._spi_nodes['lmk'], + self._spi_nodes['mykonos'], ) self.lmk = self._device.get_clock_ctrl() self.mykonos = self._device.get_radio_ctrl() - - # uio_path, uio_size = get_uio_node("misc-enet-regs0") + self.log.debug("Loaded C++ drivers.") self.log.debug("Getting Mg A uio...") self.radio_regs = UIO(label="jesd204b-regs", read_only=False) self.log.info("Radio-register UIO object successfully generated!") diff --git a/mpm/python/usrp_mpm/periph_manager/base.py b/mpm/python/usrp_mpm/periph_manager/base.py index 459f8833f..4815bd88d 100644 --- a/mpm/python/usrp_mpm/periph_manager/base.py +++ b/mpm/python/usrp_mpm/periph_manager/base.py @@ -77,8 +77,8 @@ class PeriphManagerBase(object): # I know spidev masters on the dboard slots hw_pid = 2 if hw_pid in dboard_manager.HW_PIDS: - spi_devices = get_spidev_nodes("e0006000.spi") - self.log.debug("found spidev nodes: {0}".format(spi_devices)) + spi_devices = sorted(get_spidev_nodes("e0006000.spi")) + self.log.debug("Found spidev nodes: {0}".format(spi_devices)) dboard = dboard_manager.HW_PIDS.get(hw_pid, dboard_manager.unknown) self.dboards.update({dboard_slot: dboard(spi_devices, eeprom_data)}) diff --git a/mpm/python/usrp_mpm/periph_manager/udev.py b/mpm/python/usrp_mpm/periph_manager/udev.py index 6801d2163..9d64b1b64 100644 --- a/mpm/python/usrp_mpm/periph_manager/udev.py +++ b/mpm/python/usrp_mpm/periph_manager/udev.py @@ -38,7 +38,7 @@ def get_spidev_nodes(spi_master): """ context = pyudev.Context() parent = pyudev.Device.from_name(context, "platform", spi_master) - paths = [device.sys_path + paths = [device.device_node.encode('ascii') for device in context.list_devices(parent=parent, subsystem="spidev")] return paths |