litex/examples/sim/memory.py

27 lines
805 B
Python
Raw Normal View History

from migen.fhdl.std import *
2014-01-26 16:19:43 -05:00
from migen.sim.generic import run_simulation
2012-03-06 13:29:39 -05:00
2015-04-13 14:45:35 -04:00
class Mem(Module):
def __init__(self):
# Initialize the beginning of the memory with integers
# from 0 to 19.
self.specials.mem = Memory(16, 2**12, init=list(range(20)))
2014-10-17 05:08:37 -04:00
def do_simulation(self, selfp):
# Read the memory. Use the cycle counter as address.
value = selfp.mem[selfp.simulator.cycle_counter]
# Print the result. Output is:
# 0
# 1
# 2
# ...
print(value)
# Raising StopSimulation disables the current (and here, only one)
# simulation function. Simulator stops when all functions are disabled.
if value == 10:
raise StopSimulation
2012-03-06 13:29:39 -05:00
2014-01-26 16:19:43 -05:00
if __name__ == "__main__":
run_simulation(Mem())