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))