From 75e87f65a847f22a9f0cfb0cc0708aa99c48ccc7 Mon Sep 17 00:00:00 2001 From: Andrew Wygle Date: Fri, 24 Apr 2020 16:15:39 -0700 Subject: [PATCH] AsyncFIFO: disable read from dual-port Memory when FIFO empty Avoids CDC hazard described in issue #217. --- nmigen/lib/fifo.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nmigen/lib/fifo.py b/nmigen/lib/fifo.py index b8a07cfb3..efb361af4 100644 --- a/nmigen/lib/fifo.py +++ b/nmigen/lib/fifo.py @@ -369,10 +369,12 @@ def elaborate(self, platform): w_port.en.eq(do_write), self.w_rdy.eq(~w_full), ] + # There is a CDC hazard associated with simultaneous read and write from a dual port BRAM. + # We avoid this by disabling `r_port.en` when `r_empty` is true. m.d.comb += [ r_port.addr.eq(consume_r_nxt[:-1]), self.r_data.eq(r_port.data), - r_port.en.eq(1), + r_port.en.eq(~r_empty), self.r_rdy.eq(~r_empty), ]