diff --git a/migen/genlib/misc.py b/migen/genlib/misc.py index b9e73a9ae..bd7828633 100644 --- a/migen/genlib/misc.py +++ b/migen/genlib/misc.py @@ -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))