2012-01-06 11:24:05 -05:00
|
|
|
from migen.fhdl.structure import *
|
2013-04-01 16:15:23 -04:00
|
|
|
from migen.fhdl.module import Module
|
2012-01-06 11:24:05 -05:00
|
|
|
from migen.flow.actor import *
|
2013-02-22 17:19:37 -05:00
|
|
|
from migen.genlib.record import *
|
|
|
|
from migen.genlib.misc import optree
|
2012-01-06 11:24:05 -05:00
|
|
|
|
2012-06-07 08:44:43 -04:00
|
|
|
class Buffer(PipelinedActor):
|
2012-01-09 09:14:42 -05:00
|
|
|
def __init__(self, layout):
|
2012-12-18 08:54:33 -05:00
|
|
|
PipelinedActor.__init__(self, 1,
|
2012-01-15 09:09:44 -05:00
|
|
|
("d", Sink, layout), ("q", Source, layout))
|
2012-01-06 11:24:05 -05:00
|
|
|
|
|
|
|
def get_process_fragment(self):
|
2012-01-15 09:09:44 -05:00
|
|
|
sigs_d = self.token("d").flatten()
|
|
|
|
sigs_q = self.token("q").flatten()
|
2012-01-06 18:33:28 -05:00
|
|
|
sync = [If(self.pipe_ce, Cat(*sigs_q).eq(Cat(*sigs_d)))]
|
2012-01-06 11:24:05 -05:00
|
|
|
return Fragment(sync=sync)
|
|
|
|
|
2013-04-01 16:15:23 -04:00
|
|
|
class Combinator(Module, Actor):
|
2012-06-16 11:30:54 -04:00
|
|
|
def __init__(self, layout, subrecords):
|
2013-04-01 16:15:23 -04:00
|
|
|
eps = [("source", Source, layout)]
|
|
|
|
eps += [("sink"+str(n), Sink, layout_partial(layout, r))
|
2012-06-07 08:44:43 -04:00
|
|
|
for n, r in enumerate(subrecords)]
|
2012-12-18 08:54:33 -05:00
|
|
|
Actor.__init__(self, *eps)
|
2012-01-06 11:24:05 -05:00
|
|
|
|
2013-04-01 16:15:23 -04:00
|
|
|
###
|
|
|
|
|
2012-01-15 09:09:44 -05:00
|
|
|
source = self.endpoints["source"]
|
2013-04-01 16:15:23 -04:00
|
|
|
sinks = [self.endpoints["sink"+str(n)]
|
2012-01-15 09:09:44 -05:00
|
|
|
for n in range(len(self.endpoints)-1)]
|
2013-04-01 16:15:23 -04:00
|
|
|
self.comb += [source.stb.eq(optree("&", [sink.stb for sink in sinks]))]
|
|
|
|
self.comb += [sink.ack.eq(source.ack & source.stb) for sink in sinks]
|
|
|
|
self.comb += [source.token.eq(sink.token) for sink in sinks]
|
2012-01-06 11:24:05 -05:00
|
|
|
|
2013-04-01 16:15:23 -04:00
|
|
|
class Splitter(Module, Actor):
|
2012-06-16 11:30:54 -04:00
|
|
|
def __init__(self, layout, subrecords):
|
2013-04-01 16:15:23 -04:00
|
|
|
eps = [("sink", Sink, layout)]
|
|
|
|
eps += [("source"+str(n), Source, layout_partial(layout, *r))
|
|
|
|
for n, r in enumerate(subrecords)]
|
2012-12-18 08:54:33 -05:00
|
|
|
Actor.__init__(self, *eps)
|
2012-01-06 11:24:05 -05:00
|
|
|
|
2013-04-01 16:15:23 -04:00
|
|
|
###
|
|
|
|
|
2012-06-16 15:23:42 -04:00
|
|
|
sources = [self.endpoints[e] for e in self.sources()]
|
|
|
|
sink = self.endpoints[self.sinks()[0]]
|
2013-04-01 16:15:23 -04:00
|
|
|
|
|
|
|
self.comb += [source.token.eq(sink.token) for source in sources]
|
2012-06-16 15:23:42 -04:00
|
|
|
|
2012-11-29 15:22:38 -05:00
|
|
|
already_acked = Signal(len(sources))
|
2013-04-01 16:15:23 -04:00
|
|
|
self.sync += If(sink.stb,
|
2012-06-16 15:23:42 -04:00
|
|
|
already_acked.eq(already_acked | Cat(*[s.ack for s in sources])),
|
|
|
|
If(sink.ack, already_acked.eq(0))
|
|
|
|
)
|
2013-04-01 16:15:23 -04:00
|
|
|
self.comb += sink.ack.eq(optree("&",
|
2012-06-16 15:23:42 -04:00
|
|
|
[s.ack | already_acked[n] for n, s in enumerate(sources)]))
|
|
|
|
for n, s in enumerate(sources):
|
2013-04-01 16:15:23 -04:00
|
|
|
self.comb += s.stb.eq(sink.stb & ~already_acked[n])
|
2012-06-16 11:30:54 -04:00
|
|
|
|
|
|
|
# Actors whose layout should be inferred from what their single sink is connected to.
|
2012-06-16 15:23:42 -04:00
|
|
|
layout_sink = {Buffer, Splitter}
|
2012-06-16 11:30:54 -04:00
|
|
|
# Actors whose layout should be inferred from what their single source is connected to.
|
|
|
|
layout_source = {Buffer, Combinator}
|
|
|
|
# All actors.
|
|
|
|
actors = layout_sink | layout_source
|