actorlib: add fifo
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Tue, 3 Sep 2013 22:01:33 +0000 (00:01 +0200)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Wed, 4 Sep 2013 15:15:22 +0000 (17:15 +0200)
migen/actorlib/fifo.py [new file with mode: 0644]

diff --git a/migen/actorlib/fifo.py b/migen/actorlib/fifo.py
new file mode 100644 (file)
index 0000000..3d6f036
--- /dev/null
@@ -0,0 +1,41 @@
+from migen.fhdl.std import *
+from migen.flow.actor import *
+from migen.genlib import fifo
+
+def FIFOWrapper(sink, source, fifo):
+       return [
+                       sink.ack.eq(fifo.writable),
+                       fifo.we.eq(sink.stb & sink.ack),
+                       fifo.din.eq(sink.payload),
+
+                       source.stb.eq(fifo.readable),
+                       source.payload.eq(fifo.dout),
+                       fifo.re.eq(source.ack)
+       ]
+
+class SyncFIFO(Module):
+       def __init__(self, layout, depth):
+
+               self.sink = Sink(layout)
+               self.source = Source(layout)
+               self.busy = Signal()
+
+               _fifo = fifo.SyncFIFO(layout, depth)            
+
+               self.submodules += _fifo
+
+               self.comb += FIFOWrapper(self.sink, self.source, _fifo)
+
+class AsyncFIFO(Module):
+       def __init__(self, layout, depth, cd_write="write", cd_read="read"):
+
+               self.sink = Sink(layout)
+               self.source = Source(layout)
+               self.busy = Signal()
+
+               _fifo = RenameClockDomains(fifo.AsyncFIFO(layout, depth),
+                       {"write": cd_write, "read": cd_read})
+               self.submodules += _fifo
+
+               self.comb += FIFOWrapper(self.sink, self.source, _fifo)
+               
\ No newline at end of file