From: Robin Ole Heinemann Date: Sat, 2 Jan 2021 23:14:26 +0000 (+0100) Subject: lib.fifo.AsyncFIFOBuffered: fix FFSynchronizer latency X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f719dbee29d4520514251a6cc4f81b50edbbc3c2;p=nmigen.git lib.fifo.AsyncFIFOBuffered: fix FFSynchronizer latency --- 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)