Abstract HWIO Base Class#
All hardware i/o implementations extend from the HWIO
abstract base class.
Methods that require implementation#
All HWIO shall implement the _read_impl()
and _write_impl() methods.
- abstractmethod HWIO._read_impl(addr: int, size: int) int#
Implementation of a hardware read operation. Classes that extend
HWIOshall provide an implementation for this method.Callers will guarantee that
addris aligned tosize.- Parameters:
addr (int) – Address offset
size (int) – Access size in bytes. Typical sizes are 1, 2, 4 or 8 bytes. If a given size is not supported, the implementation shall raise
NotImplementedError
- Returns:
Read value
- Return type:
int
- abstractmethod HWIO._write_impl(addr: int, value: int, size: int) None#
Implementation of a hardware write operation. Classes that extend
HWIOshall provide an implementation for this method.Callers will guarantee that
addris aligned tosize.- Parameters:
addr (int) – Address offset
value (int) – Value to write
size (int) – Access size in bytes. Typical sizes are 1, 2, 4 or 8 bytes. If a given size is not supported, the implementation shall raise
NotImplementedError
Methods that may be overridden#
If a HWIO interface is able to execute native block memory copy operations, it
is recommended to override the _read_bytes_impl() and
_write_bytes_impl() methods.
- HWIO._read_bytes_impl(addr: int, size: int) bytearray#
Implementation of a raw data read operation Classes that extend
HWIOmay choose to provide an alternate implementation for this method if it proves to be more efficient.- Parameters:
offset (int) – Address offset
size (int) – Number of bytes to read
- Returns:
Read data
- Return type:
bytearray
- HWIO._write_bytes_impl(addr: int, data: bytes | bytearray) None#
Implementation of a raw data write operation Classes that extend
HWIOmay choose to provide an alternate implementation for this method if it proves to be more efficient.- Parameters:
offset (int) – Address offset
data (bytes) – Buffer of data to write
HWIO#
Calling HWIO methods directly is seldom useful as you would usually interact with the RAL API instead. Even so, bypassing the RAL is sometimes necessary, so here is a reference to the public HWIO API.
- class peakrdl_pyral_runtime.hwio.HWIO(offset: int = 0)#
Abstract base class for all Hardware I/O (HWIO) implementations.
- Parameters:
offset (int) – Additional address offset to add to all HWIO transactions
- read(offset: int, size: int = 4) int#
Read a single register.
- Parameters:
offset (int) – Address offset
size (int) – Size of the access in bytes. Shall be 1, 2, 4, or 8.
- Returns:
Read value
- Return type:
int
- read_bytes(offset: int, size: int) bytearray#
Read a buffer of bytes from the device. User shall make no assumptions on what underlying access size will be used.
- Parameters:
offset (int) – Address offset
size (int) – Number of bytes to read
- Returns:
Read data
- Return type:
bytearray
- read_list(offset: int, n_words: int, size: int = 4) list[int]#
Read a contiguous list of words from the hardware
- Parameters:
offset (int) – Address offset.
n_words (int) – Number of words to read.
size (int) – Size of the read access in bytes to use for each entry. Shall be 1, 2, 4, or 8.
- Returns:
List of values read
- Return type:
list[int]
- write(offset: int, value: int, size: int = 4) None#
Write a single register.
- Parameters:
offset (int) – Address offset
data (int) – Value to write
size (int) – Size of the access in bytes. Shall be 1, 2, 4, or 8.
- write_bytes(offset: int, data: bytes | bytearray) None#
Write a buffer of bytes to the device. User shall make no assumptions on what underlying access size will be used.
- Parameters:
offset (int) – Address offset
data (bytes) – Buffer of data to write
- write_list(offset: int, data: list[int], size: int = 4) None#
Write a contiguous list of words to the hardware
- Parameters:
offset (int) – Address offset.
data (list[int]) – List of words to write.
size (int) – Size of the write access in bytes to use for each entry. Shall be 1, 2, 4, or 8.