migen/genlib/misc: replace Timeout with WaitTimer from artiq
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Tue, 12 May 2015 13:45:16 +0000 (15:45 +0200)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Tue, 12 May 2015 14:14:58 +0000 (16:14 +0200)
migen/genlib/misc.py

index b9e73a9aee64ed89eef48283346714e5c2f80ed4..bd7828633250a5c94c2c4280e204c95217ee9ec4 100644 (file)
@@ -118,12 +118,16 @@ class Counter(Module):
         self.sync += self.value.eq(self.value+increment)
 
 
-@ResetInserter()
-@CEInserter()
-class Timeout(Module):
-    def __init__(self, length):
-        self.reached = Signal()
-        ###
-        value = Signal(max=length)
-        self.sync += If(~self.reached, value.eq(value+1))
-        self.comb += self.reached.eq(value == (length-1))
+class WaitTimer(Module):
+    def __init__(self, t):
+        self.wait = Signal()
+        self.done = Signal()
+
+        # # #
+
+        count = Signal(bits_for(t), reset=t)
+        self.comb += self.done.eq(count == 0)
+        self.sync += \
+            If(self.wait,
+                If(~self.done, count.eq(count - 1))
+            ).Else(count.eq(count.reset))