2012-03-23 11:41:30 -04:00
|
|
|
# Copyright (C) 2012 Vermeer Manufacturing Co.
|
|
|
|
# License: GPLv3 with additional permissions (see README).
|
|
|
|
|
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):
|
2012-03-10 13:38:39 -05:00
|
|
|
# Initialize the beginning of the memory with integers
|
|
|
|
# from 0 to 19.
|
2012-11-26 12:19:10 -05:00
|
|
|
self.mem = Memory(16, 2**12, init=list(range(20)))
|
2012-03-06 13:29:39 -05:00
|
|
|
|
|
|
|
def do_simulation(self, s):
|
2012-03-10 13:38:39 -05:00
|
|
|
# Read the memory. Use the cycle counter as address.
|
2012-03-06 13:43:59 -05:00
|
|
|
value = s.rd(self.mem, s.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)
|
2012-03-10 13:38:39 -05:00
|
|
|
# Demonstrate how to interrupt the simulator.
|
2012-03-06 13:43:59 -05:00
|
|
|
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())
|
2012-03-10 13:38:39 -05:00
|
|
|
# No need for a cycle limit here, we use sim.interrupt instead.
|
2012-03-06 13:29:39 -05:00
|
|
|
sim.run()
|
|
|
|
|
|
|
|
main()
|