2012-11-17 16:26:14 -05:00
|
|
|
from migen.flow.network import *
|
2012-12-14 09:55:38 -05:00
|
|
|
from migen.flow.transactions import *
|
2012-12-16 14:26:23 -05:00
|
|
|
from migen.actorlib.sim import Dumper
|
2012-11-17 16:26:14 -05:00
|
|
|
from migen.bus import wishbone
|
|
|
|
from migen.bus.transactions import *
|
2013-04-10 16:28:53 -04:00
|
|
|
from migen.genlib.ioo import UnifiedIOSimulation
|
2012-11-17 16:26:14 -05:00
|
|
|
from migen.pytholite.transel import Register
|
2013-04-10 17:42:46 -04:00
|
|
|
from migen.pytholite.compiler import Pytholite
|
2012-11-17 16:26:14 -05:00
|
|
|
from migen.sim.generic import Simulator
|
2013-05-22 11:11:09 -04:00
|
|
|
from migen.fhdl.std import *
|
2012-11-17 16:26:14 -05:00
|
|
|
from migen.fhdl import verilog
|
|
|
|
|
2012-11-29 15:22:38 -05:00
|
|
|
layout = [("r", 32)]
|
2012-11-17 16:26:14 -05:00
|
|
|
|
|
|
|
def gen():
|
|
|
|
ds = Register(32)
|
2012-11-23 10:24:20 -05:00
|
|
|
for i in range(3):
|
|
|
|
r = TRead(i, busname="mem")
|
|
|
|
yield r
|
|
|
|
ds.store = r.data
|
|
|
|
yield Token("result", {"r": ds})
|
2012-11-23 07:10:40 -05:00
|
|
|
for i in range(5):
|
|
|
|
r = TRead(i, busname="wb")
|
2012-11-17 16:26:14 -05:00
|
|
|
yield r
|
|
|
|
ds.store = r.data
|
2012-11-17 17:19:40 -05:00
|
|
|
yield Token("result", {"r": ds})
|
2012-11-17 16:26:14 -05:00
|
|
|
|
|
|
|
class SlaveModel(wishbone.TargetModel):
|
|
|
|
def read(self, address):
|
|
|
|
return address + 4
|
|
|
|
|
2013-03-12 11:59:24 -04:00
|
|
|
class TestBench(Module):
|
|
|
|
def __init__(self, ng):
|
|
|
|
g = DataFlowGraph()
|
|
|
|
d = Dumper(layout)
|
|
|
|
g.add_connection(ng, d)
|
|
|
|
|
|
|
|
self.submodules.slave = wishbone.Target(SlaveModel())
|
2013-04-10 17:42:46 -04:00
|
|
|
self.submodules.intercon = wishbone.InterconnectPointToPoint(ng.wb, self.slave.bus)
|
2013-03-12 11:59:24 -04:00
|
|
|
self.submodules.ca = CompositeActor(g)
|
|
|
|
|
2012-11-17 16:26:14 -05:00
|
|
|
def run_sim(ng):
|
2013-03-12 11:59:24 -04:00
|
|
|
sim = Simulator(TestBench(ng))
|
2012-11-23 10:24:20 -05:00
|
|
|
sim.run(50)
|
2012-11-17 16:26:14 -05:00
|
|
|
del sim
|
|
|
|
|
2013-04-10 17:42:46 -04:00
|
|
|
def add_interfaces(obj):
|
|
|
|
obj.result = Source(layout)
|
|
|
|
obj.wb = wishbone.Interface()
|
|
|
|
obj.mem = Memory(32, 3, init=[42, 37, 81])
|
|
|
|
obj.finalize()
|
|
|
|
|
2012-11-17 16:26:14 -05:00
|
|
|
def main():
|
|
|
|
print("Simulating native Python:")
|
2013-04-10 17:42:46 -04:00
|
|
|
ng_native = UnifiedIOSimulation(gen())
|
|
|
|
add_interfaces(ng_native)
|
2012-11-17 16:26:14 -05:00
|
|
|
run_sim(ng_native)
|
|
|
|
|
2012-11-23 07:10:40 -05:00
|
|
|
print("Simulating Pytholite:")
|
2013-04-10 17:42:46 -04:00
|
|
|
ng_pytholite = Pytholite(gen)
|
|
|
|
add_interfaces(ng_pytholite)
|
2012-11-23 07:10:40 -05:00
|
|
|
run_sim(ng_pytholite)
|
2012-11-17 16:26:14 -05:00
|
|
|
|
2012-11-23 07:10:40 -05:00
|
|
|
print("Converting Pytholite to Verilog:")
|
2013-04-10 17:42:46 -04:00
|
|
|
ng_pytholite = Pytholite(gen)
|
|
|
|
add_interfaces(ng_pytholite)
|
|
|
|
print(verilog.convert(ng_pytholite))
|
2012-11-17 16:26:14 -05:00
|
|
|
|
|
|
|
main()
|