litex/examples/dataflow/misc.py

33 lines
787 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 *
from migen.sim.generic import Simulator
from migen.sim.icarus import Runner
def source_gen():
for i in range(10):
v = i + 5
print("==> " + str(v))
yield Token("source", {"value": v})
def sink_gen():
while True:
t = Token("sink")
yield t
print(t.value["value"])
def main():
2012-12-12 16:20:48 -05:00
source = SimActor(source_gen(), ("source", Source, [("value", 32)]))
loop = misc.IntSequence(32)
sink = SimActor(sink_gen(), ("sink", Sink, [("value", 32)]))
2012-06-17 15:19:47 -04:00
g = DataFlowGraph()
g.add_connection(source, loop)
g.add_connection(loop, sink)
comp = CompositeActor(g)
fragment = comp.get_fragment()
sim = Simulator(fragment, Runner())
sim.run(500)
main()