diff options
author | Brent Stapleton <brent.stapleton@ettus.com> | 2018-07-20 16:07:38 -0700 |
---|---|---|
committer | Brent Stapleton <bstapleton@g.hmc.edu> | 2018-07-23 10:33:34 -0700 |
commit | 5b18614d39f5cebdd8bf3bf6e5acf3a34f204191 (patch) | |
tree | d250c2e3189628e06f1467d2b6001e620b60b8a4 /mpm/python/usrp_mpm/sys_utils | |
parent | 102fcc0ff897f6ff4ddce03b29d4b57b492d6ead (diff) | |
download | uhd-5b18614d39f5cebdd8bf3bf6e5acf3a34f204191.tar.gz uhd-5b18614d39f5cebdd8bf3bf6e5acf3a34f204191.tar.bz2 uhd-5b18614d39f5cebdd8bf3bf6e5acf3a34f204191.zip |
uio: mpm: Fixup for opening mboard-regs UIO
- Fix the syntax to open mboard-regs UIO objects, and change the open()
and close() functions to be private.
- We were calling open() twice in every context manager line- once
manually, and once in __enter__. This commit corrects those usages, and
allows the context manager to fully manage the opening and closing of
UIO objects.
Diffstat (limited to 'mpm/python/usrp_mpm/sys_utils')
-rw-r--r-- | mpm/python/usrp_mpm/sys_utils/uio.py | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/mpm/python/usrp_mpm/sys_utils/uio.py b/mpm/python/usrp_mpm/sys_utils/uio.py index c99041492..c724557e6 100644 --- a/mpm/python/usrp_mpm/sys_utils/uio.py +++ b/mpm/python/usrp_mpm/sys_utils/uio.py @@ -23,9 +23,9 @@ def open_uio(label=None, path=None, length=None, read_only=True, offset=None): """Convenience function for creating a UIO object. Use this like you would open() for a file""" uio_obj = UIO(label, path, length, read_only, offset) - uio_obj.open() + uio_obj._open() yield uio_obj - uio_obj.close() + uio_obj._close() def get_all_uio_devs(): @@ -97,17 +97,24 @@ class UIO(object): - Use the instantiation of this class as a context manager (using a `with` statement), like this: + >>> uio0 = UIO(path="/dev/uio0"): + >>> with uio0: + >>> uio0.peek32(addr) + >>> uio0.poke32(addr, value) + + Or like this: + >>> with UIO(path="/dev/uio0") as uio0: >>> uio0.peek32(addr) >>> uio0.poke32(addr, value) - - Manually call open() and close(): + - This is Highly Discouraged, but if you need to, manually call _open() and _close(): >>> uio0 = UIO(path="/dev/uio0") - >>> uio0.open() + >>> uio0._open() >>> uio0.peek32(addr) >>> uio0.poke32(addr, value) - >>> uio0.close() + >>> uio0._close() Arguments: label -- Label of the UIO device. The label is set in the device tree @@ -135,10 +142,12 @@ class UIO(object): else: self.log.trace("Using UIO device by label `{0}'".format(label)) self._path, map_info = find_uio_device(label, self.log) - offset = offset or map_info['offset'] # If we ever support multiple maps, check if this is correct... + # TODO If we ever support multiple maps, check if this is correct... + offset = offset or map_info['offset'] assert offset == 0 # ...and then remove this line length = length or map_info['size'] - self.log.trace("UIO device is being opened read-{0}.".format("only" if read_only else "write")) + self.log.trace("UIO device is being opened read-{0}.".format( + "only" if read_only else "write")) if self._path is None: self.log.error("Could not find a UIO device for label {0}".format(label)) raise RuntimeError("Could not find a UIO device for label {0}".format(label)) @@ -150,13 +159,13 @@ class UIO(object): self._ref_count = 0 def __enter__(self): - return self.open() + return self._open() def __exit__(self, exc_type, exc_value, traceback): - self.close() + self._close() return exc_type is None - def open(self): + def _open(self): """Actually open the UIO device. You need to call this before doing peeks and pokes. See also close(). @@ -169,7 +178,7 @@ class UIO(object): self._ref_count += 1 return self - def close(self): + def _close(self): """Close a UIO device. UIO devices can be problematic with regards to file descriptor leakage, |