lib.fifo.AsyncFIFOBuffered: fix output register accounting
authorRobin Ole Heinemann <robin.ole.heinemann@gmail.com>
Sat, 2 Jan 2021 23:17:48 +0000 (00:17 +0100)
committerwhitequark <whitequark@whitequark.org>
Wed, 6 Jan 2021 01:05:46 +0000 (01:05 +0000)
nmigen/lib/fifo.py
tests/test_lib_fifo.py

index ceb254d19d7f3f50af76731e1876975f8dbee2bc..0cab22587ad5a700a4e8c1b4d211dee4ac6c5729 100644 (file)
@@ -509,7 +509,7 @@ class AsyncFIFOBuffered(Elaboratable, FIFOInterface):
         ]
 
         r_consume_buffered = Signal()
-        m.d.comb += r_consume_buffered.eq(self.r_rdy - self.r_en)
+        m.d.comb += r_consume_buffered.eq((self.r_rdy - self.r_en) & self.r_rdy)
         m.d[self._r_domain] += self.r_level.eq(fifo.r_level + r_consume_buffered)
 
         w_consume_buffered = Signal()
index f2edf3022e9c4b35e266ecf3b9fa59f4a635d400..0e322c1abdeb712a7968890cd395e3d55b649e04 100644 (file)
@@ -305,7 +305,7 @@ class AsyncFIFOSimCase(FHDLTestCase):
         simulator.add_sync_process(testbench)
         simulator.run()
 
-    def check_async_fifo_level(self, fifo, fill_in, expected_level):
+    def check_async_fifo_level(self, fifo, fill_in, expected_level, read=False):
         write_done = Signal()
 
         def write_process():
@@ -320,6 +320,8 @@ class AsyncFIFOSimCase(FHDLTestCase):
             yield write_done.eq(1)
 
         def read_process():
+            if read:
+                yield fifo.r_en.eq(1)
             while not (yield write_done):
                 yield Tick("read")
             self.assertEqual((yield fifo.r_level), expected_level)
@@ -351,3 +353,7 @@ class AsyncFIFOSimCase(FHDLTestCase):
     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)
+
+    def test_async_buffered_fifo_level_empty(self):
+        fifo = AsyncFIFOBuffered(width=32, depth=9, r_domain="read", w_domain="write")
+        self.check_async_fifo_level(fifo, fill_in=0, expected_level=0, read=True)