litex/examples/pytholite/uio.py

71 lines
1.7 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 *
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-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
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
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))
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)
print("Simulating Pytholite:")
2013-04-10 17:42:46 -04:00
ng_pytholite = Pytholite(gen)
add_interfaces(ng_pytholite)
run_sim(ng_pytholite)
2012-11-17 16:26:14 -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()