litex/examples/pytholite/uio.py

70 lines
1.6 KiB
Python
Raw Normal View History

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
from migen.fhdl import verilog
layout = [("r", 32)]
2012-11-17 16:26:14 -05:00
def gen():
ds = Register(32)
for i in range(3):
r = TRead(i, busname="mem")
yield r
ds.store = r.data
yield Token("result", {"r": ds})
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
def run_sim(ng):
g = DataFlowGraph()
2012-11-23 18:00:07 -05:00
d = Dumper(layout)
2012-12-12 16:20:48 -05:00
g.add_connection(ng, d)
2012-11-17 16:26:14 -05:00
slave = wishbone.Target(SlaveModel())
intercon = wishbone.InterconnectPointToPoint(ng.buses["wb"], slave.bus)
c = CompositeActor(g)
fragment = slave.get_fragment() + intercon.get_fragment() + c.get_fragment()
2013-02-09 11:04:53 -05:00
sim = Simulator(fragment)
sim.run(50)
2012-11-17 16:26:14 -05:00
del sim
def main():
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(),
dataflow=dataflow,
buses=buses)
2012-11-17 16:26:14 -05:00
run_sim(ng_native)
print("Simulating Pytholite:")
ng_pytholite = make_pytholite(gen,
dataflow=dataflow,
buses=buses)
run_sim(ng_pytholite)
2012-11-17 16:26:14 -05:00
print("Converting Pytholite to Verilog:")
print(verilog.convert(ng_pytholite.get_fragment()))
2012-11-17 16:26:14 -05:00
main()