From: Florent Kermarrec Date: Fri, 25 Oct 2013 20:45:45 +0000 (+0200) Subject: flow/plumbing: add Multiplexer and Demultiplexer X-Git-Tag: 24jan2021_ls180~2099^2~453 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=84966af0988b029d12bfde0e97e48fbc9cf85efd;p=litex.git flow/plumbing: add Multiplexer and Demultiplexer --- diff --git a/migen/flow/plumbing.py b/migen/flow/plumbing.py index 23301631..a5af7e83 100644 --- a/migen/flow/plumbing.py +++ b/migen/flow/plumbing.py @@ -3,6 +3,14 @@ from migen.flow.actor import * from migen.genlib.record import * from migen.genlib.misc import optree +def pipe(s1, s2): + r = [ + s2.stb.eq(s1.stb), + s2.payload.eq(s1.payload), + s1.ack.eq(s2.ack) + ] + return r + class Buffer(PipelinedActor): def __init__(self, layout): self.d = Sink(layout) @@ -52,6 +60,42 @@ class Splitter(Module): for n, s in enumerate(sources): self.comb += s.stb.eq(self.sink.stb & ~already_acked[n]) +class Multiplexer(Module): + def __init__(self, n, layout): + self.source = Source(layout) + sinks = [] + for i in range(n): + sink = Sink(layout) + setattr(self, "sink"+str(i), sink) + sinks.append(sink) + self.busy = Signal() + self.sel = Signal(max=n) + + ### + + case = {} + for i, sink in enumerate(sinks): + cases[i] = [pipe(sink, self.source)] + self.comb += Case(self.sel, cases) + +class Demultiplexer(Module): + def __init__(self, layout, n): + self.sink = Sink(layout) + sources = [] + for i in range(n): + source = Source(layout) + setattr(self, "source"+str(i), source) + sources.append(source) + self.busy = Signal() + self.sel = Signal(max=n) + + ### + + cases = {} + for i, source in enumerate(sources): + cases[i] = [pipe(self.sink, source)] + self.comb += Case(self.sel, cases) + # Actors whose layout should be inferred from what their single sink is connected to. layout_sink = {Buffer, Splitter} # Actors whose layout should be inferred from what their single source is connected to.