fifo: add support for depth=2
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Mon, 26 May 2014 22:17:34 +0000 (00:17 +0200)
committerSebastien Bourdeauducq <sb@m-labs.hk>
Sun, 15 Jun 2014 21:58:46 +0000 (23:58 +0200)
migen/genlib/fifo.py

index 5059694cc33551810c63ac2aab8ad7cc340f5980..27d3c679505624ecf582266394c8cc3d28b715d4 100644 (file)
@@ -217,12 +217,16 @@ class AsyncFIFO(Module, _FIFOInterface):
                        NoRetiming(consume.q),
                        MultiReg(consume.q, consume_wdomain, "write")
                ]
-               self.comb += [
-                       self.writable.eq((produce.q[-1] == consume_wdomain[-1])
-                        | (produce.q[-2] == consume_wdomain[-2])
-                        | (produce.q[:-2] != consume_wdomain[:-2])),
-                       self.readable.eq(consume.q != produce_rdomain)
-               ]
+               if depth_bits == 1:
+                       self.comb += self.writable.eq((produce.q[-1] == consume_wdomain[-1])
+                               | (produce.q[-2] == consume_wdomain[-2]))
+               else:
+                       self.comb += [
+                               self.writable.eq((produce.q[-1] == consume_wdomain[-1])
+                               | (produce.q[-2] == consume_wdomain[-2])
+                               | (produce.q[:-2] != consume_wdomain[:-2]))
+                       ]
+               self.comb += self.readable.eq(consume.q != produce_rdomain)
 
                storage = Memory(self.width, depth)
                self.specials += storage