avl._core.memory module
- class avl._core.memory.Memory(width: int = 32)[source]
- __init__(width: int = 32) None[source]
Initialize the memory model.
- Parameters:
width (int) – Width of the memory in bits (default is 32).
- Raises:
ValueError – If width is not a positive integer.
- set_init_fn(fn: callable) None[source]
Set the initialization policy for the memory
Defined as a lambda function that takes an address and returns a value.
- Parameters:
fn (callable) – Function to initialize memory at a given address.
- Raises:
ValueError – If fn is not callable.
- Example:
memory.set_init_fn(lambda address: 0)
- set_endianness(endianness: str) None[source]
Set the endianness of the memory (little / big).
- Parameters:
endianness (str) – Endianness, can be ‘little’ or ‘big’.
- Raises:
ValueError – If endianness is not ‘little’ or ‘big’.
- add_range(start: int, end: int) None[source]
Add a memory range.
- Parameters:
start (int) – Start address of the memory range.
end (int) – End address of the memory range.
- Raises:
ValueError – If start address is not less than end address.
- miss(address: int) None[source]
Action to be taken when a memory miss occurs. This method raises a ValueError indicating that the address was not found in memory. Expect user to override this method to implement custom behavior.
- Parameters:
address (int) – Address that caused the miss.
- Raises:
ValueError – Always raised to indicate a memory miss.
- read(address: int, num_bytes: int = None) int[source]
Read a value from the memory at the specified address.
Calls miss() if the address is not found in memory.
- Parameters:
address (int) – Address to read from.
- Returns:
Value at the specified address.
- Return type:
int
- write(address: int, value: int, num_bytes: int = None, strobe: int = None) None[source]
Write a value to the memory at the specified address.
Calls miss() if the address is not found in memory.
- Parameters:
address (int) – Address to write to.
value (int) – Value to write.
num_bytes (int, optional) – Number of bytes to write (default is width // 8).
strobe (int, optional) – Strobe signal
- export_to_file(filename: str, fmt: str = None) None[source]
Export memory contents to a file.
If fmt is not specified, it will be inferred from the file extension.
- Parameters:
filename (str) – Path to the file where memory contents will be saved.
fmt (str, optional) – Format of the file, can be ‘vhex’ or ‘vbin’.
- Raises:
ValueError – If format is not supported.