From f719dbee29d4520514251a6cc4f81b50edbbc3c2 Mon Sep 17 00:00:00 2001 From: Robin Ole Heinemann Date: Sun, 3 Jan 2021 00:14:26 +0100 Subject: [PATCH] lib.fifo.AsyncFIFOBuffered: fix FFSynchronizer latency --- nmigen/lib/fifo.py | 2 +- tests/test_lib_fifo.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/nmigen/lib/fifo.py b/nmigen/lib/fifo.py index 98517d9..ceb254d 100644 --- a/nmigen/lib/fifo.py +++ b/nmigen/lib/fifo.py @@ -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): diff --git a/tests/test_lib_fifo.py b/tests/test_lib_fifo.py index d276b3d..f2edf30 100644 --- a/tests/test_lib_fifo.py +++ b/tests/test_lib_fifo.py @@ -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) -- 2.30.2