Mirrored HWIO Wrapper#
- class peakrdl_pyral_runtime.hwio.mirror.MirroredHWIOWrapper(hwio: HWIO)#
Wrapping HWIO implementations with the
MirroredHWIOWrapperclass provide a mechanism to maintain a mirrored state of hardware’s memory map.This can be useful when interfacing with devices that have costly access times. For example, rather than reading from the hardware when performing a read-modify-write operation, one could use this mirror to retain the assumed state of the register being modified.
Any HWIO interface can be mirrored by wrapping it in this class as follows:
my_hwio = MirroredHWIOWrapper(OpenOCDHWIO())
By default, behavior is as follows:
- Read operations
Perform a read using the
hwioclass provided to this wrapper.Update the mirrored state with the value read
Return the value
- Write operations
Update the mirrored state with the value provided
Write the value using the
hwioclass provided to this wrapper.
The above behavior can be augmented using the
read_from_mirror()andwrite_to_mirror_only()context managers.Important
The mirroring mechanism this class implements makes no attempt to model the hardware’s register map behavior beyond what is described above. Be careful when mirroring hardware registers that have access side-effects such as read-clear, write-1-to-clear, volatile fields, etc.
Any advanced modeling of the hardware is out of scope for this project.
- hwio#
Reference to the original HWIO class being wrapped.
- read_from_mirror() Generator[None, Any, None]#
Provides a context manager where, when entered, will redirect any read operations that target this HWIO to pull values from the mirrored state rather than the actual hardware.
x = ral.my_reg.read() # Returns value read from the hardware with my_hwio.read_from_mirror(): x = ral.my_reg.read() # Returns value from the mirror instead of hardware
- write_to_mirror_only() Generator[None, Any, None]#
Provides a context manager where, when entered, will skip writes to the hardware and only update the mirrored state.
ral.my_reg.write(123) # Writes value to both the hardware and mirror with my_hwio.write_to_mirror_only(): ral.my_reg.write(123) # Writes value to mirror only