aboutsummaryrefslogtreecommitdiffstats
path: root/mpm
diff options
context:
space:
mode:
authorMichael Auchter <michael.auchter@ni.com>2019-09-24 09:50:22 -0500
committerAaron Rossetto <aaron.rossetto@ni.com>2021-02-11 12:26:10 -0600
commit5ef29d93966aecb3c678aa5ee92cf60b0db835e5 (patch)
tree29aeb0513c2e7e27e486e092cb48cb85d936566e /mpm
parent9ffdd46974fa83db7ef4a76202e6708f776a327a (diff)
downloaduhd-5ef29d93966aecb3c678aa5ee92cf60b0db835e5.tar.gz
uhd-5ef29d93966aecb3c678aa5ee92cf60b0db835e5.tar.bz2
uhd-5ef29d93966aecb3c678aa5ee92cf60b0db835e5.zip
mpm: deduplicate dboard eeprom handling
The _get_dboard_eeprom_info implementations are the same with the exception of how the dboard eeprom is actually read. Break that out into a _read_dboard_eeprom method to reduce code duplication. The base class now defines a lambda expression for the eeprom reader which can be changed in subclasses. Co-authored-by: Lars Amsel <lars.amsel@ni.com> Co-authored-by: Michael Auchter <michael.auchter@ni.com>
Diffstat (limited to 'mpm')
-rw-r--r--mpm/python/usrp_mpm/periph_manager/base.py42
-rw-r--r--mpm/python/usrp_mpm/periph_manager/e31x.py26
2 files changed, 29 insertions, 39 deletions
diff --git a/mpm/python/usrp_mpm/periph_manager/base.py b/mpm/python/usrp_mpm/periph_manager/base.py
index a6bffafed..c2da31b8f 100644
--- a/mpm/python/usrp_mpm/periph_manager/base.py
+++ b/mpm/python/usrp_mpm/periph_manager/base.py
@@ -86,6 +86,16 @@ class PeriphManagerBase(object):
# read. It's usually safe to not override this, as EEPROMs typically aren't
# that big.
mboard_eeprom_max_len = None
+ # lambda expression for motherboard EEPROM readers. path is the only dynamic
+ # parameter that is passed to the reader. Subclasses change the lambda
+ # expression to use EEPROM readers with different signatures.
+ mboard_eeprom_reader = lambda path: eeprom.read_eeprom(
+ path,
+ PeriphManagerBase.mboard_eeprom_offset,
+ eeprom.MboardEEPROM.eeprom_header_format,
+ eeprom.MboardEEPROM.eeprom_header_keys,
+ PeriphManagerBase.mboard_eeprom_magic,
+ PeriphManagerBase.mboard_eeprom_max_len)
# This is the *default* mboard info. The keys from this dict will be copied
# into the current device info before it actually gets initialized. This
# means that keys from this dict could be overwritten during the
@@ -130,6 +140,16 @@ class PeriphManagerBase(object):
# read. It's usually safe to not override this, as EEPROMs typically aren't
# that big.
dboard_eeprom_max_len = None
+ # lambda expression for daughterboard EEPROM readers. path is the only
+ # dynamic parameter that is passed to the reader. Subclasses change the
+ # lambda expression to use EEPROM readers with different signatures.
+ dboard_eeprom_reader = lambda path: eeprom.read_eeprom(
+ path,
+ PeriphManagerBase.dboard_eeprom_offset,
+ eeprom.DboardEEPROM.eeprom_header_format,
+ eeprom.DboardEEPROM.eeprom_header_keys,
+ PeriphManagerBase.dboard_eeprom_magic,
+ PeriphManagerBase.dboard_eeprom_max_len)
# If the dboard requires spidev access, the following attribute is a list
# of SPI master addrs (typically something like 'e0006000.spi'). You
# usually want the length of this list to be as long as the number of
@@ -285,14 +305,8 @@ class PeriphManagerBase(object):
self.mboard_eeprom_addr)
return {}, b''
self.log.trace("Found mboard EEPROM path: %s", eeprom_paths[0])
- (eeprom_head, eeprom_rawdata) = eeprom.read_eeprom(
- eeprom_paths[0],
- self.mboard_eeprom_offset,
- eeprom.MboardEEPROM.eeprom_header_format,
- eeprom.MboardEEPROM.eeprom_header_keys,
- self.mboard_eeprom_magic,
- self.mboard_eeprom_max_len,
- )
+ (eeprom_head, eeprom_rawdata) = \
+ self.__class__.mboard_eeprom_reader(eeprom_paths[0])
self.log.trace("Found EEPROM metadata: `{}'"
.format(str(eeprom_head)))
self.log.trace("Read {} bytes of EEPROM data."
@@ -381,13 +395,8 @@ class PeriphManagerBase(object):
dboard_info = []
for dboard_idx, dboard_eeprom_path in enumerate(dboard_eeprom_paths):
self.log.debug("Reading EEPROM info for dboard %d...", dboard_idx)
- dboard_eeprom_md, dboard_eeprom_rawdata = eeprom.read_eeprom(
- dboard_eeprom_path,
- self.dboard_eeprom_offset,
- eeprom.DboardEEPROM.eeprom_header_format,
- eeprom.DboardEEPROM.eeprom_header_keys,
- self.dboard_eeprom_magic,
- self.dboard_eeprom_max_len,
+ dboard_eeprom_md, dboard_eeprom_rawdata = self._read_dboard_eeprom(
+ dboard_eeprom_path
)
self.log.trace("Found dboard EEPROM metadata: `{}'"
.format(str(dboard_eeprom_md)))
@@ -406,6 +415,9 @@ class PeriphManagerBase(object):
})
return dboard_info
+ def _read_dboard_eeprom(self, dboard_eeprom_path):
+ return self.__class__.dboard_eeprom_reader(dboard_eeprom_path)
+
def _update_default_args(self, default_args):
"""
Pipe the default_args (that get passed into us from the RPC server)
diff --git a/mpm/python/usrp_mpm/periph_manager/e31x.py b/mpm/python/usrp_mpm/periph_manager/e31x.py
index 17cd09c16..94d6f7529 100644
--- a/mpm/python/usrp_mpm/periph_manager/e31x.py
+++ b/mpm/python/usrp_mpm/periph_manager/e31x.py
@@ -361,18 +361,8 @@ class e31x(ZynqComponents, PeriphManagerBase):
self.log.trace("Read %d bytes of EEPROM data.", len(eeprom_rawdata))
return eeprom_head, eeprom_rawdata
- def _get_dboard_eeprom_info(self):
- """
- Read back EEPROM info from the daughterboards
- """
- assert self.dboard_eeprom_addr
- self.log.trace("Identifying dboard EEPROM paths from `{}'..."
- .format(self.dboard_eeprom_addr))
- dboard_eeprom_path = \
- get_eeprom_paths(self.dboard_eeprom_addr)[self.dboard_eeprom_path_index]
- self.log.trace("Using dboard EEPROM paths: {}".format(dboard_eeprom_path))
- self.log.debug("Reading EEPROM info for dboard...")
- dboard_eeprom_md, dboard_eeprom_rawdata = e31x_legacy_eeprom.read_eeprom(
+ def _read_dboard_eeprom(self, dboard_eeprom_path):
+ return e31x_legacy_eeprom.read_eeprom(
False, # is not motherboard.
dboard_eeprom_path,
self.dboard_eeprom_offset,
@@ -380,18 +370,6 @@ class e31x(ZynqComponents, PeriphManagerBase):
e31x_legacy_eeprom.DboardEEPROM.eeprom_header_keys,
self.dboard_eeprom_max_len
)
- self.log.trace("Read %d bytes of dboard EEPROM data.",
- len(dboard_eeprom_rawdata))
- db_pid = dboard_eeprom_md.get('pid')
- if db_pid is None:
- self.log.warning("No DB PID found in dboard EEPROM!")
- else:
- self.log.debug("Found DB PID in EEPROM: 0x{:04X}".format(db_pid))
- return [{
- 'eeprom_md': dboard_eeprom_md,
- 'eeprom_rawdata': dboard_eeprom_rawdata,
- 'pid': db_pid,
- }]
###########################################################################
# Session init and deinit