mirror of
https://github.com/enjoy-digital/litex.git
synced 2025-01-04 09:52:26 -05:00
flow/plumbing: add Multiplexer and Demultiplexer
This commit is contained in:
parent
f658802ff8
commit
84966af098
1 changed files with 44 additions and 0 deletions
|
@ -3,6 +3,14 @@ from migen.flow.actor import *
|
||||||
from migen.genlib.record import *
|
from migen.genlib.record import *
|
||||||
from migen.genlib.misc import optree
|
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):
|
class Buffer(PipelinedActor):
|
||||||
def __init__(self, layout):
|
def __init__(self, layout):
|
||||||
self.d = Sink(layout)
|
self.d = Sink(layout)
|
||||||
|
@ -52,6 +60,42 @@ class Splitter(Module):
|
||||||
for n, s in enumerate(sources):
|
for n, s in enumerate(sources):
|
||||||
self.comb += s.stb.eq(self.sink.stb & ~already_acked[n])
|
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.
|
# Actors whose layout should be inferred from what their single sink is connected to.
|
||||||
layout_sink = {Buffer, Splitter}
|
layout_sink = {Buffer, Splitter}
|
||||||
# Actors whose layout should be inferred from what their single source is connected to.
|
# Actors whose layout should be inferred from what their single source is connected to.
|
||||||
|
|
Loading…
Reference in a new issue