2012-06-08 15:31:05 -04:00
|
|
|
from random import Random
|
2012-01-15 10:41:15 -05:00
|
|
|
|
2013-05-22 11:11:09 -04:00
|
|
|
from migen.fhdl.std import *
|
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 *
|
2014-01-26 16:19:43 -05:00
|
|
|
from migen.actorlib import dma_wishbone
|
2012-06-08 15:31:05 -04:00
|
|
|
from migen.actorlib.sim import *
|
2014-01-26 16:19:43 -05:00
|
|
|
from migen.bus import wishbone
|
|
|
|
from migen.sim.generic import run_simulation
|
2012-06-08 15:31:05 -04:00
|
|
|
|
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
|
|
|
|
|
|
|
def adrgen_gen():
|
|
|
|
for i in range(10):
|
2013-04-28 12:06:36 -04:00
|
|
|
print("Address: " + hex(i))
|
2012-06-08 15:31:05 -04:00
|
|
|
yield Token("address", {"a": i})
|
|
|
|
|
2013-04-10 13:12:42 -04:00
|
|
|
class SimAdrGen(SimActor):
|
|
|
|
def __init__(self, nbits):
|
|
|
|
self.address = Source([("a", nbits)])
|
|
|
|
SimActor.__init__(self, adrgen_gen())
|
|
|
|
|
2012-06-08 15:31:05 -04:00
|
|
|
def dumper_gen():
|
|
|
|
while True:
|
2012-12-14 13:16:22 -05:00
|
|
|
t = Token("data", idle_wait=True)
|
2012-06-08 15:31:05 -04:00
|
|
|
yield t
|
2013-04-28 12:06:36 -04:00
|
|
|
print("Received: " + hex(t.value["d"]))
|
2012-06-08 15:31:05 -04:00
|
|
|
|
2013-04-10 13:12:42 -04:00
|
|
|
class SimDumper(SimActor):
|
|
|
|
def __init__(self):
|
|
|
|
self.data = Sink([("d", 32)])
|
2014-10-17 05:08:37 -04:00
|
|
|
SimActor.__init__(self, dumper_gen())
|
2013-04-10 13:12:42 -04:00
|
|
|
|
2012-06-12 13:55:57 -04:00
|
|
|
def trgen_gen():
|
|
|
|
for i in range(10):
|
|
|
|
a = i
|
|
|
|
d = i+10
|
2013-04-28 12:06:36 -04:00
|
|
|
print("Address: " + hex(a) + " Data: " + hex(d))
|
2012-06-12 13:55:57 -04:00
|
|
|
yield Token("address_data", {"a": a, "d": d})
|
|
|
|
|
2013-04-10 13:12:42 -04:00
|
|
|
class SimTrGen(SimActor):
|
2013-04-28 12:06:36 -04:00
|
|
|
def __init__(self, a_nbits):
|
|
|
|
self.address_data = Source([("a", a_nbits), ("d", 32)])
|
2013-04-10 13:12:42 -04:00
|
|
|
SimActor.__init__(self, trgen_gen())
|
|
|
|
|
|
|
|
class TBWishbone(Module):
|
|
|
|
def __init__(self, master):
|
|
|
|
self.submodules.peripheral = wishbone.Target(MyModelWB())
|
|
|
|
self.submodules.tap = wishbone.Tap(self.peripheral.bus)
|
|
|
|
self.submodules.interconnect = wishbone.InterconnectPointToPoint(master.bus,
|
|
|
|
self.peripheral.bus)
|
|
|
|
|
|
|
|
class TBWishboneReader(TBWishbone):
|
|
|
|
def __init__(self):
|
|
|
|
self.adrgen = SimAdrGen(30)
|
|
|
|
self.reader = dma_wishbone.Reader()
|
|
|
|
self.dumper = SimDumper()
|
|
|
|
g = DataFlowGraph()
|
|
|
|
g.add_connection(self.adrgen, self.reader)
|
|
|
|
g.add_connection(self.reader, self.dumper)
|
|
|
|
self.submodules.comp = CompositeActor(g)
|
|
|
|
TBWishbone.__init__(self, self.reader)
|
|
|
|
|
|
|
|
class TBWishboneWriter(TBWishbone):
|
|
|
|
def __init__(self):
|
2013-04-28 12:06:36 -04:00
|
|
|
self.trgen = SimTrGen(30)
|
2013-04-10 13:12:42 -04:00
|
|
|
self.writer = dma_wishbone.Writer()
|
|
|
|
g = DataFlowGraph()
|
|
|
|
g.add_connection(self.trgen, self.writer)
|
|
|
|
self.submodules.comp = CompositeActor(g)
|
|
|
|
TBWishbone.__init__(self, self.writer)
|
|
|
|
|
2012-06-12 13:55:57 -04:00
|
|
|
def test_wb_reader():
|
|
|
|
print("*** Testing Wishbone reader")
|
2014-09-07 02:09:51 -04:00
|
|
|
run_simulation(TBWishboneReader(), 100)
|
2012-06-08 15:31:05 -04:00
|
|
|
|
2012-06-12 13:55:57 -04:00
|
|
|
def test_wb_writer():
|
|
|
|
print("*** Testing Wishbone writer")
|
2014-09-07 02:09:51 -04:00
|
|
|
run_simulation(TBWishboneWriter(), 100)
|
2014-01-26 16:19:43 -05:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
test_wb_reader()
|
|
|
|
test_wb_writer()
|