litex/examples/dataflow/misc.py

38 lines
877 B
Python
Raw Normal View History

2012-06-17 15:19:47 -04:00
from migen.flow.network import *
2012-12-14 09:55:38 -05:00
from migen.flow.transactions import *
2012-06-22 09:01:47 -04:00
from migen.actorlib import misc
2012-06-17 15:19:47 -04:00
from migen.actorlib.sim import *
2014-01-26 16:19:43 -05:00
from migen.sim.generic import run_simulation
2012-06-17 15:19:47 -04:00
def source_gen():
for i in range(10):
v = i + 5
print("==> " + str(v))
2013-04-10 13:12:42 -04:00
yield Token("source", {"maximum": v})
class SimSource(SimActor):
def __init__(self):
self.source = Source([("maximum", 32)])
SimActor.__init__(self, source_gen())
2012-06-17 15:19:47 -04:00
def sink_gen():
while True:
t = Token("sink")
yield t
print(t.value["value"])
2013-04-10 13:12:42 -04:00
class SimSink(SimActor):
def __init__(self):
self.sink = Sink([("value", 32)])
SimActor.__init__(self, sink_gen())
2014-01-26 16:19:43 -05:00
if __name__ == "__main__":
2013-04-10 13:12:42 -04:00
source = SimSource()
2012-12-12 16:20:48 -05:00
loop = misc.IntSequence(32)
2013-04-10 13:12:42 -04:00
sink = SimSink()
2012-06-17 15:19:47 -04:00
g = DataFlowGraph()
g.add_connection(source, loop)
g.add_connection(loop, sink)
comp = CompositeActor(g)
2014-01-26 16:19:43 -05:00
run_simulation(comp, ncycles=500)