migen/genlib/misc: replace Timeout with WaitTimer from artiq

This commit is contained in:
Florent Kermarrec 2015-05-12 15:45:16 +02:00
parent fe6eef7069
commit 88a406ebec
1 changed files with 13 additions and 9 deletions

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