2013-05-22 11:11:09 -04:00
|
|
|
from migen.fhdl.std import *
|
2012-06-08 11:54:03 -04:00
|
|
|
from migen.flow.actor import *
|
2012-12-14 09:55:38 -05:00
|
|
|
from migen.flow.transactions import *
|
2012-06-08 11:54:03 -04:00
|
|
|
from migen.flow.network import *
|
|
|
|
from migen.actorlib.sim import *
|
2014-01-26 16:19:43 -05:00
|
|
|
from migen.sim.generic import run_simulation
|
2012-06-08 11:54:03 -04:00
|
|
|
|
|
|
|
def source_gen():
|
2015-04-13 14:07:07 -04:00
|
|
|
for i in range(10):
|
|
|
|
print("Sending: " + str(i))
|
|
|
|
yield Token("source", {"value": i})
|
2012-06-08 11:54:03 -04:00
|
|
|
|
2013-04-10 13:12:42 -04:00
|
|
|
class SimSource(SimActor):
|
2015-04-13 14:07:07 -04:00
|
|
|
def __init__(self):
|
|
|
|
self.source = Source([("value", 32)])
|
|
|
|
SimActor.__init__(self, source_gen())
|
2013-04-10 13:12:42 -04:00
|
|
|
|
2012-06-08 11:54:03 -04:00
|
|
|
def sink_gen():
|
2015-04-13 14:07:07 -04:00
|
|
|
while True:
|
|
|
|
t = Token("sink")
|
|
|
|
yield t
|
|
|
|
print("Received: " + str(t.value["value"]))
|
2012-06-08 11:54:03 -04:00
|
|
|
|
2013-04-10 13:12:42 -04:00
|
|
|
class SimSink(SimActor):
|
2015-04-13 14:07:07 -04:00
|
|
|
def __init__(self):
|
|
|
|
self.sink = Sink([("value", 32)])
|
|
|
|
SimActor.__init__(self, sink_gen())
|
2013-04-10 13:12:42 -04:00
|
|
|
|
|
|
|
class TB(Module):
|
2015-04-13 14:07:07 -04:00
|
|
|
def __init__(self):
|
|
|
|
self.source = SimSource()
|
|
|
|
self.sink = SimSink()
|
|
|
|
g = DataFlowGraph()
|
|
|
|
g.add_connection(self.source, self.sink)
|
|
|
|
self.submodules.comp = CompositeActor(g)
|
2013-04-10 13:12:42 -04:00
|
|
|
|
2015-04-13 14:07:07 -04:00
|
|
|
def do_simulation(self, selfp):
|
|
|
|
if self.source.token_exchanger.done:
|
|
|
|
raise StopSimulation
|
2014-01-27 18:03:56 -05:00
|
|
|
|
2014-01-26 16:19:43 -05:00
|
|
|
if __name__ == "__main__":
|
2015-04-13 14:07:07 -04:00
|
|
|
run_simulation(TB())
|