migen/actorlib/fifo: add FIFO wrapper function
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Fri, 24 Jul 2015 11:02:54 +0000 (13:02 +0200)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Fri, 24 Jul 2015 11:02:54 +0000 (13:02 +0200)
Allow automatic instantiation of the correct fifo (SyncFIFO or AsyncFIFO) according to the clock domains passed in argument.

migen/actorlib/fifo.py

index 072e99c7dcfe8e5d7b9e3d2fd022a29c43867818..4363870fd8b7ac9cbacb634866de05579a1f9705 100644 (file)
@@ -55,3 +55,15 @@ class SyncFIFO(_FIFOActor):
 class AsyncFIFO(_FIFOActor):
     def __init__(self, layout, depth):
         _FIFOActor.__init__(self, fifo.AsyncFIFO, layout, depth)
+
+
+def FIFO(layout, depth, buffered=False,
+          sink_cd="sys", source_cd="sys"):
+    if sink_cd != source_cd:
+        if buffered:
+            ValueError("AsyncFIFO does not support buffered mode")
+        fifo = AsyncFIFO(layout, depth)
+        return ClockDomainsRenamer({"write": sink_cd, "read": source_cd})(fifo)
+    else:
+        fifo = SyncFIFO(layout, depth, buffered)
+        return ClockDomainsRenamer(sink_cd)(fifo)