Skip to content

Commit 0ab8069

Browse files
committed
migen.genlib: Improve "first word fall through" docs.
* Moved "first word fall through" `fwft` to be part of _FIFOInterface. * Added documentation what the hell `fwft` stands for. * Checks the compatibility of the `fwft` argument given to the FIFO.
1 parent d3b875b commit 0ab8069

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

migen/genlib/fifo.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class _FIFOInterface:
3030
Bit width for the data.
3131
depth : int
3232
Depth of the FIFO.
33+
fwft : bool (optional)
34+
Enable the FIFO to have "first word fall through". The first
35+
word written to an otherwise empty FIFO will be put on the
36+
output without doing a read first.
3337
3438
Attributes
3539
----------
@@ -48,7 +52,8 @@ class _FIFOInterface:
4852
Acknowledge `dout`. If asserted, the next entry will be
4953
available on the next cycle (if `readable` is high then).
5054
"""
51-
def __init__(self, width, depth):
55+
56+
def __init__(self, width, depth, fwft=False):
5257
self.we = Signal()
5358
self.writable = Signal() # not full
5459
self.re = Signal()
@@ -77,7 +82,7 @@ def write(self, data):
7782
yield
7883

7984

80-
class SyncFIFO(Module, _FIFOInterface):
85+
class SyncFIFO(Module, _FIFOInterfaceWithFirstWordFallThrough):
8186
"""Synchronous FIFO (first in, first out)
8287
8388
Read and write interfaces are accessed from the same clock domain.
@@ -94,7 +99,7 @@ class SyncFIFO(Module, _FIFOInterface):
9499
__doc__ = __doc__.format(interface=_FIFOInterface.__doc__)
95100

96101
def __init__(self, width, depth, fwft=True):
97-
_FIFOInterface.__init__(self, width, depth)
102+
_FIFOInterface.__init__(self, width, depth, fwft)
98103

99104
self.level = Signal(max=depth+1)
100105
self.replace = Signal()
@@ -146,11 +151,18 @@ def __init__(self, width, depth, fwft=True):
146151

147152

148153
class SyncFIFOBuffered(Module, _FIFOInterface):
149-
"""Has an interface compatible with SyncFIFO with fwft=True,
150-
but does not use asynchronous RAM reads that are not compatible
151-
with block RAMs. Increases latency by one cycle."""
152-
def __init__(self, width, depth):
153-
_FIFOInterface.__init__(self, width, depth)
154+
"""SyncFIFO compatible with "first word fall through" without using async memory.
155+
156+
The SyncFIFOBuffered has an interface compatible with SyncFIFO with
157+
`fwft=True` but does not use asynchronous RAM reads that are not compatible
158+
with block RAMs. Increases latency by one cycle.
159+
160+
This is useful for providing a SyncFIFO when the FPGA part doesn't provide
161+
block ram with an asynchronous read port, like the Lattice iCE40 parts.
162+
"""
163+
def __init__(self, width, depth, fwft=True):
164+
assert fwft, "fwft should be set, otherwise just use a SyncFIFO."
165+
_FIFOInterface.__init__(self, width, depth, False)
154166
self.submodules.fifo = fifo = SyncFIFO(width, depth, False)
155167

156168
self.writable = fifo.writable
@@ -182,8 +194,9 @@ class AsyncFIFO(Module, _FIFOInterface):
182194
"""
183195
__doc__ = __doc__.format(interface=_FIFOInterface.__doc__)
184196

185-
def __init__(self, width, depth):
186-
_FIFOInterface.__init__(self, width, depth)
197+
def __init__(self, width, depth, fwft=False):
198+
assert not fwft, "fwft is not supported on the AsyncFIFO."
199+
_FIFOInterface.__init__(self, width, depth, fwft=False)
187200

188201
###
189202

@@ -235,8 +248,8 @@ class AsyncFIFOBuffered(Module, _FIFOInterface):
235248
"""Improves timing when it breaks due to sluggish clock-to-output
236249
delay in e.g. Xilinx block RAMs. Increases latency by one cycle."""
237250
def __init__(self, width, depth):
238-
_FIFOInterface.__init__(self, width, depth)
239-
self.submodules.fifo = fifo = AsyncFIFO(width, depth)
251+
_FIFOInterface.__init__(self, width, depth, fwft=False)
252+
self.submodules.fifo = fifo = AsyncFIFO(width, depth, fwft)
240253

241254
self.writable = fifo.writable
242255
self.din = fifo.din

0 commit comments

Comments
 (0)