2013-05-22 11:11:09 -04:00
|
|
|
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
|
|
|
|
2013-07-24 12:47:25 -04:00
|
|
|
class Mem(Module):
|
2012-03-06 13:29:39 -05:00
|
|
|
def __init__(self):
|
2012-03-10 13:38:39 -05:00
|
|
|
# Initialize the beginning of the memory with integers
|
|
|
|
# from 0 to 19.
|
2013-07-24 12:47:25 -04:00
|
|
|
self.specials.mem = Memory(16, 2**12, init=list(range(20)))
|
2012-03-06 13:29:39 -05:00
|
|
|
|
2014-01-26 16:19:43 -05:00
|
|
|
def do_simulation(self, selfp):
|
2012-03-10 13:38:39 -05:00
|
|
|
# Read the memory. Use the cycle counter as address.
|
2014-01-26 16:19:43 -05:00
|
|
|
value = selfp.mem[selfp.simulator.cycle_counter]
|
2012-03-10 13:38:39 -05:00
|
|
|
# Print the result. Output is:
|
|
|
|
# 0
|
|
|
|
# 1
|
|
|
|
# 2
|
|
|
|
# ...
|
2012-03-06 13:43:59 -05:00
|
|
|
print(value)
|
2014-01-26 16:19:43 -05:00
|
|
|
# Raising StopSimulation disables the current (and here, only one)
|
|
|
|
# simulation function. Simulator stops when all functions are disabled.
|
2012-03-06 13:43:59 -05:00
|
|
|
if value == 10:
|
2014-01-26 16:19:43 -05:00
|
|
|
raise StopSimulation
|
2012-03-06 13:29:39 -05:00
|
|
|
|
2014-01-26 16:19:43 -05:00
|
|
|
if __name__ == "__main__":
|
|
|
|
run_simulation(Mem())
|