litex/examples/dataflow/misc.py

32 lines
790 B
Python
Raw Normal View History

2012-06-17 15:19:47 -04:00
from migen.flow.network 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():
source = ActorNode(SimActor(source_gen(), ("source", Source, [("value", BV(32))])))
2012-06-22 09:01:47 -04:00
loop = ActorNode(misc.IntSequence(32))
2012-06-17 15:19:47 -04:00
sink = ActorNode(SimActor(sink_gen(), ("sink", Sink, [("value", BV(32))])))
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()