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 *
|
|
|
|
from migen.uio.ioo import UnifiedIOSimulation
|
|
|
|
from migen.pytholite.transel import Register
|
|
|
|
from migen.pytholite.compiler import make_pytholite
|
|
|
|
from migen.sim.generic import Simulator
|
2013-03-12 11:59:24 -04:00
|
|
|
from migen.fhdl.module import Module
|
2013-02-22 11:56:35 -05:00
|
|
|
from migen.fhdl.specials import Memory
|
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())
|
|
|
|
self.submodules.intercon = wishbone.InterconnectPointToPoint(ng.buses["wb"], self.slave.bus)
|
|
|
|
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
|
|
|
|
|
|
|
|
def main():
|
2012-11-23 10:24:20 -05:00
|
|
|
mem = Memory(32, 3, init=[42, 37, 81])
|
|
|
|
dataflow = [("result", Source, layout)]
|
|
|
|
buses = {
|
|
|
|
"wb": wishbone.Interface(),
|
|
|
|
"mem": mem
|
|
|
|
}
|
|
|
|
|
2012-11-17 16:26:14 -05:00
|
|
|
print("Simulating native Python:")
|
|
|
|
ng_native = UnifiedIOSimulation(gen(),
|
2012-11-23 10:24:20 -05:00
|
|
|
dataflow=dataflow,
|
|
|
|
buses=buses)
|
2012-11-17 16:26:14 -05:00
|
|
|
run_sim(ng_native)
|
|
|
|
|
2012-11-23 07:10:40 -05:00
|
|
|
print("Simulating Pytholite:")
|
|
|
|
ng_pytholite = make_pytholite(gen,
|
2012-11-23 10:24:20 -05:00
|
|
|
dataflow=dataflow,
|
|
|
|
buses=buses)
|
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 13:12:42 -04:00
|
|
|
ng_pytholite = make_pytholite(gen,
|
|
|
|
dataflow=dataflow,
|
|
|
|
buses=buses)
|
2012-11-23 07:10:40 -05:00
|
|
|
print(verilog.convert(ng_pytholite.get_fragment()))
|
2012-11-17 16:26:14 -05:00
|
|
|
|
|
|
|
main()
|