lib.fifo.AsyncFIFOBuffered: fix FFSynchronizer latency
authorRobin Ole Heinemann <robin.ole.heinemann@gmail.com>
Sat, 2 Jan 2021 23:14:26 +0000 (00:14 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 31 Dec 2021 15:25:14 +0000 (15:25 +0000)
nmigen/lib/fifo.py
tests/test_lib_fifo.py

index 98517d9ffe4db5b0b00c0f449cfb11333fcd1e9a..ceb254d19d7f3f50af76731e1876975f8dbee2bc 100644 (file)
@@ -513,7 +513,7 @@ class AsyncFIFOBuffered(Elaboratable, FIFOInterface):
         m.d[self._r_domain] += self.r_level.eq(fifo.r_level + r_consume_buffered)
 
         w_consume_buffered = Signal()
-        m.submodules.consume_buffered_cdc = FFSynchronizer(r_consume_buffered, w_consume_buffered, o_domain=self._w_domain)
+        m.submodules.consume_buffered_cdc = FFSynchronizer(r_consume_buffered, w_consume_buffered, o_domain=self._w_domain, stages=4)
         m.d.comb += self.w_level.eq(fifo.w_level + w_consume_buffered)
 
         with m.If(self.r_en | ~self.r_rdy):
index d276b3d17b4fa25da3231dd747da6deffc11236b..f2edf3022e9c4b35e266ecf3b9fa59f4a635d400 100644 (file)
@@ -344,6 +344,10 @@ class AsyncFIFOSimCase(FHDLTestCase):
         fifo = AsyncFIFOBuffered(width=32, depth=9, r_domain="read", w_domain="write")
         self.check_async_fifo_level(fifo, fill_in=5, expected_level=5)
 
+    def test_async_buffered_fifo_level_only_three(self):
+        fifo = AsyncFIFOBuffered(width=32, depth=9, r_domain="read", w_domain="write")
+        self.check_async_fifo_level(fifo, fill_in=3, expected_level=3)
+
     def test_async_buffered_fifo_level_full(self):
         fifo = AsyncFIFOBuffered(width=32, depth=9, r_domain="read", w_domain="write")
         self.check_async_fifo_level(fifo, fill_in=10, expected_level=9)