add debug option to check the written values

This commit is contained in:
erpalma
2018-08-13 15:44:18 -07:00
parent a463f753ee
commit ed06353021
2 changed files with 60 additions and 15 deletions

24
mmio.py
View File

@@ -61,11 +61,7 @@ class MMIO(object):
try:
self.mapping = mmap.mmap(
fd,
self._aligned_size,
flags=mmap.MAP_SHARED,
prot=mmap.PROT_WRITE,
offset=self._aligned_physaddr)
fd, self._aligned_size, flags=mmap.MAP_SHARED, prot=mmap.PROT_WRITE, offset=self._aligned_physaddr)
except OSError as e:
raise MMIOError(e.errno, "Mapping /dev/mem: " + e.strerror)
@@ -83,6 +79,24 @@ class MMIO(object):
if (offset + length) > self._aligned_size:
raise ValueError("Offset out of bounds.")
def read32(self, offset):
"""Read 32-bits from the specified `offset` in bytes, relative to the
base physical address of the MMIO region.
Args:
offset (int, long): offset from base physical address, in bytes.
Returns:
int: 32-bit value read.
Raises:
TypeError: if `offset` type is invalid.
ValueError: if `offset` is out of bounds.
"""
if not isinstance(offset, (int, long)):
raise TypeError("Invalid offset type, should be integer.")
offset = self._adjust_offset(offset)
self._validate_offset(offset, 4)
return struct.unpack("=L", self.mapping[offset:offset + 4])[0]
def write32(self, offset, value):
"""Write 32-bits to the specified `offset` in bytes, relative to the
base physical address of the MMIO region.