From: Florent Kermarrec Date: Tue, 12 May 2015 13:45:16 +0000 (+0200) Subject: migen/genlib/misc: replace Timeout with WaitTimer from artiq X-Git-Tag: 24jan2021_ls180~2099^2~64 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=88a406ebec4f405e208484b99ab4d06ce8d812a0;p=litex.git migen/genlib/misc: replace Timeout with WaitTimer from artiq --- diff --git a/migen/genlib/misc.py b/migen/genlib/misc.py index b9e73a9a..bd782863 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))