2012-06-08 15:31:05 -04:00
|
|
|
from random import Random
|
2012-01-15 10:41:15 -05:00
|
|
|
|
|
|
|
from migen.flow.network import *
|
2012-12-14 09:55:38 -05:00
|
|
|
from migen.flow.transactions import *
|
2012-06-12 15:04:47 -04:00
|
|
|
from migen.actorlib import dma_wishbone, dma_asmi
|
2012-06-08 15:31:05 -04:00
|
|
|
from migen.actorlib.sim import *
|
2012-06-12 13:55:57 -04:00
|
|
|
from migen.bus import wishbone, asmibus
|
2012-06-08 15:31:05 -04:00
|
|
|
from migen.sim.generic import Simulator
|
|
|
|
from migen.sim.icarus import Runner
|
|
|
|
|
2012-06-12 13:55:57 -04:00
|
|
|
class MyModel:
|
2012-06-10 10:40:33 -04:00
|
|
|
def read(self, address):
|
|
|
|
return address + 4
|
2012-06-12 13:55:57 -04:00
|
|
|
|
|
|
|
class MyModelWB(MyModel, wishbone.TargetModel):
|
|
|
|
def __init__(self):
|
|
|
|
self.prng = Random(763627)
|
|
|
|
|
2012-06-10 10:40:33 -04:00
|
|
|
def can_ack(self, bus):
|
|
|
|
return self.prng.randrange(0, 2)
|
2012-06-08 15:31:05 -04:00
|
|
|
|
2012-06-12 13:55:57 -04:00
|
|
|
class MyModelASMI(MyModel, asmibus.TargetModel):
|
|
|
|
pass
|
|
|
|
|
2012-06-08 15:31:05 -04:00
|
|
|
def adrgen_gen():
|
|
|
|
for i in range(10):
|
|
|
|
print("Address: " + str(i))
|
|
|
|
yield Token("address", {"a": i})
|
|
|
|
|
|
|
|
def dumper_gen():
|
|
|
|
while True:
|
|
|
|
t = Token("data")
|
|
|
|
yield t
|
|
|
|
print("Received: " + str(t.value["d"]))
|
|
|
|
|
2012-06-12 13:55:57 -04:00
|
|
|
def trgen_gen():
|
|
|
|
for i in range(10):
|
|
|
|
a = i
|
|
|
|
d = i+10
|
|
|
|
print("Address: " + str(a) + " Data: " + str(d))
|
|
|
|
yield Token("address_data", {"a": a, "d": d})
|
|
|
|
|
|
|
|
def wishbone_sim(efragment, master, end_simulation):
|
|
|
|
peripheral = wishbone.Target(MyModelWB())
|
|
|
|
tap = wishbone.Tap(peripheral.bus)
|
2012-12-12 16:20:48 -05:00
|
|
|
interconnect = wishbone.InterconnectPointToPoint(master.bus, peripheral.bus)
|
2012-06-12 15:04:47 -04:00
|
|
|
def _end_simulation(s):
|
|
|
|
s.interrupt = end_simulation(s)
|
2012-06-12 13:55:57 -04:00
|
|
|
fragment = efragment \
|
|
|
|
+ peripheral.get_fragment() \
|
|
|
|
+ tap.get_fragment() \
|
|
|
|
+ interconnect.get_fragment() \
|
2012-06-12 15:04:47 -04:00
|
|
|
+ Fragment(sim=[_end_simulation])
|
|
|
|
sim = Simulator(fragment, Runner())
|
|
|
|
sim.run()
|
|
|
|
|
|
|
|
def asmi_sim(efragment, hub, end_simulation):
|
|
|
|
def _end_simulation(s):
|
|
|
|
s.interrupt = end_simulation(s)
|
2012-11-28 16:42:01 -05:00
|
|
|
peripheral = asmibus.Target(MyModelASMI(), hub)
|
2012-06-12 15:04:47 -04:00
|
|
|
tap = asmibus.Tap(hub)
|
|
|
|
def _end_simulation(s):
|
|
|
|
s.interrupt = end_simulation(s)
|
|
|
|
fragment = efragment \
|
|
|
|
+ peripheral.get_fragment() \
|
|
|
|
+ tap.get_fragment() \
|
|
|
|
+ Fragment(sim=[_end_simulation])
|
2012-06-12 13:55:57 -04:00
|
|
|
sim = Simulator(fragment, Runner())
|
|
|
|
sim.run()
|
|
|
|
|
|
|
|
def test_wb_reader():
|
|
|
|
print("*** Testing Wishbone reader")
|
2012-12-12 16:20:48 -05:00
|
|
|
adrgen = SimActor(adrgen_gen(), ("address", Source, [("a", 30)]))
|
|
|
|
reader = dma_wishbone.Reader()
|
|
|
|
dumper = SimActor(dumper_gen(), ("data", Sink, [("d", 32)]))
|
2012-06-08 16:49:49 -04:00
|
|
|
g = DataFlowGraph()
|
|
|
|
g.add_connection(adrgen, reader)
|
|
|
|
g.add_connection(reader, dumper)
|
2012-06-08 15:31:05 -04:00
|
|
|
comp = CompositeActor(g)
|
|
|
|
|
2012-06-12 15:04:47 -04:00
|
|
|
wishbone_sim(comp.get_fragment(), reader,
|
2012-12-12 16:20:48 -05:00
|
|
|
lambda s: adrgen.token_exchanger.done and not s.rd(comp.busy))
|
2012-06-08 15:31:05 -04:00
|
|
|
|
2012-06-12 13:55:57 -04:00
|
|
|
def test_wb_writer():
|
|
|
|
print("*** Testing Wishbone writer")
|
2012-12-12 16:20:48 -05:00
|
|
|
trgen = SimActor(trgen_gen(), ("address_data", Source, [("a", 30), ("d", 32)]))
|
|
|
|
writer = dma_wishbone.Writer()
|
2012-06-08 16:49:49 -04:00
|
|
|
g = DataFlowGraph()
|
|
|
|
g.add_connection(trgen, writer)
|
2012-06-08 15:31:05 -04:00
|
|
|
comp = CompositeActor(g)
|
|
|
|
|
2012-06-12 15:04:47 -04:00
|
|
|
wishbone_sim(comp.get_fragment(), writer,
|
2012-12-12 16:20:48 -05:00
|
|
|
lambda s: trgen.token_exchanger.done and not s.rd(comp.busy))
|
2012-06-12 15:04:47 -04:00
|
|
|
|
2012-07-12 13:45:12 -04:00
|
|
|
def test_asmi_reader(nslots):
|
|
|
|
print("*** Testing ASMI reader (nslots={})".format(nslots))
|
2012-06-12 15:04:47 -04:00
|
|
|
|
|
|
|
hub = asmibus.Hub(32, 32)
|
2012-07-12 13:45:12 -04:00
|
|
|
port = hub.get_port(nslots)
|
2012-06-12 15:04:47 -04:00
|
|
|
hub.finalize()
|
|
|
|
|
2012-12-12 16:20:48 -05:00
|
|
|
adrgen = SimActor(adrgen_gen(), ("address", Source, [("a", 32)]))
|
|
|
|
reader = dma_asmi.Reader(port)
|
|
|
|
dumper = SimActor(dumper_gen(), ("data", Sink, [("d", 32)]))
|
2012-06-12 15:04:47 -04:00
|
|
|
g = DataFlowGraph()
|
|
|
|
g.add_connection(adrgen, reader)
|
|
|
|
g.add_connection(reader, dumper)
|
|
|
|
comp = CompositeActor(g)
|
|
|
|
|
|
|
|
asmi_sim(hub.get_fragment() + comp.get_fragment(), hub,
|
2012-12-12 16:20:48 -05:00
|
|
|
lambda s: adrgen.token_exchanger.done and not s.rd(comp.busy))
|
2012-06-08 15:31:05 -04:00
|
|
|
|
2012-06-12 13:55:57 -04:00
|
|
|
test_wb_reader()
|
|
|
|
test_wb_writer()
|
2012-07-12 13:45:12 -04:00
|
|
|
test_asmi_reader(1)
|
|
|
|
test_asmi_reader(2)
|