From 9dee6175da45440997c8ed82fbf40f8f380dc4a7 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Fri, 12 May 2017 14:27:59 -0700 Subject: mpm: Moved device and dboard init/deinit to their own methods Also cleaned up some cruft. --- mpm/python/usrp_hwd.py | 18 +++++++++++ mpm/python/usrp_mpm/dboard_manager/base.py | 30 ++++++++++++++++-- mpm/python/usrp_mpm/dboard_manager/eiscat.py | 8 +++-- mpm/python/usrp_mpm/dboard_manager/magnesium.py | 14 +++------ mpm/python/usrp_mpm/periph_manager/base.py | 41 +++++++++++++++++-------- mpm/python/usrp_mpm/periph_manager/n310.py | 35 --------------------- 6 files changed, 84 insertions(+), 62 deletions(-) (limited to 'mpm') diff --git a/mpm/python/usrp_hwd.py b/mpm/python/usrp_hwd.py index 863c59396..27c2870df 100755 --- a/mpm/python/usrp_hwd.py +++ b/mpm/python/usrp_hwd.py @@ -50,6 +50,12 @@ def setup_arg_parser(): "used instead of whatever else the code may find", default=None ) + parser.add_argument( + '--default-args', + help="Provide a comma-separated list of key=value pairs that are" \ + "used as defaults for device initialization.", + default=None + ) return parser def parse_args(): @@ -59,6 +65,15 @@ def parse_args(): args = setup_arg_parser().parse_args() if args.override_db_pids is not None: args.override_db_pids = [int(x, 0) for x in args.override_db_pids.split(",")] + args.default_args = args.default_args or '' + try: + args.default_args = { + x.split('=')[0].strip(): x.split('=')[1].strip() if x.find('=') != -1 else '' + for x in args.default_args.split(',') + if len(x) + } + except IndexError: + log.error("Could not parse default device args: `{}'".format(args.default_args)) return args @@ -100,8 +115,10 @@ def main(): "type": mgr._get_device_info()["type"], "serial": mgr._get_device_info()["serial"] } + mgr.init(args.default_args) # TODO really this should be called by the UHD session if args.init_only: log.info("Terminating on user request before launching RPC server.") + mgr.deinit() return True log.info("Spawning discovery process...") _PROCESSES.append( @@ -113,6 +130,7 @@ def main(): signal.signal(signal.SIGTERM, kill_time) signal.signal(signal.SIGINT, kill_time) signal.pause() + mgr.deinit() # TODO Really this should be called when a device is unclaimed return True if __name__ == '__main__': diff --git a/mpm/python/usrp_mpm/dboard_manager/base.py b/mpm/python/usrp_mpm/dboard_manager/base.py index 5bf31784f..c7e116fc0 100644 --- a/mpm/python/usrp_mpm/dboard_manager/base.py +++ b/mpm/python/usrp_mpm/dboard_manager/base.py @@ -42,12 +42,16 @@ class DboardManagerBase(object): def __init__(self, slot_idx, **kwargs): self.log = get_logger('dboardManager') self.slot_idx = slot_idx + self.device_info = {} self._init_spi_nodes(kwargs.get('spi_nodes', [])) def _init_spi_nodes(self, spi_devices): """ - docstring for _init_spi_nodes + Populates the self._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 + 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( @@ -59,8 +63,30 @@ class DboardManagerBase(object): self._spi_nodes[k] = spi_devices[v] self.log.debug("spidev device node map: {}".format(self._spi_nodes)) + def init(self, args): + """ + Run the dboard initialization. This typically happens at the beginning + of a UHD session. + + Must be overridden. + + args -- A dictionary of arbitrary settings that can be used by the + dboard code. Similar to device args for UHD. + """ + raise NotImplementedError("DboardManagerBase::init() not implemented!") + + def deinit(self): + """ + Power down the dboard. Does not have be implemented. If it does, it + needs to be safe to call multiple times. + """ + self.log.info("deinit() called, but not implemented.") + def get_serial(self): - return self._eeprom.get("serial", "") + """ + Return this daughterboard's serial number as a dictionary. + """ + return self.device_info.get("serial", "") def update_ref_clock_freq(self, freq): """ diff --git a/mpm/python/usrp_mpm/dboard_manager/eiscat.py b/mpm/python/usrp_mpm/dboard_manager/eiscat.py index 7a930af79..78d5d0e18 100644 --- a/mpm/python/usrp_mpm/dboard_manager/eiscat.py +++ b/mpm/python/usrp_mpm/dboard_manager/eiscat.py @@ -30,7 +30,7 @@ N_CHANS = 8 # Chans per dboard # Power enable pins POWER_ENB = 0x200C # Address of the power enable register -PWR_CHAN_EN_2V5 = [(1< ignore them here - # 8 bytes serial - # 6 bytes mac_addr0 - # 2 bytes pad - # 6 bytes mac_addr1 - # 2 bytes pad - # 6 bytes mac_addr2 - # 2 bytes pad - # 4 bytes CRC - return struct.unpack_from("!28x 8s 6s 2x 6s 2x 6s 2x I", data) def get_interfaces(self): """ -- cgit v1.2.3