litex/examples/memory_sim.py

27 lines
597 B
Python
Raw Normal View History

2012-03-06 13:29:39 -05:00
from migen.fhdl.structure import *
2012-03-08 09:55:02 -05:00
from migen.sim.generic import Simulator
2012-03-06 13:29:39 -05:00
from migen.sim.icarus import Runner
class Mem:
def __init__(self):
self.a = Signal(BV(12))
self.d = Signal(BV(16))
p = MemoryPort(self.a, self.d)
self.mem = Memory(16, 2**12, p, init=list(range(20)))
def do_simulation(self, s):
value = s.rd(self.mem, s.cycle_counter)
print(value)
if value == 10:
s.interrupt = True
2012-03-06 13:29:39 -05:00
def get_fragment(self):
return Fragment(memories=[self.mem], sim=[self.do_simulation])
def main():
dut = Mem()
sim = Simulator(dut.get_fragment(), Runner())
sim.run()
main()