From: Florent Kermarrec Date: Sun, 1 Mar 2015 15:33:46 +0000 (+0100) Subject: genlib/misc: add FlipFlop, Counter, Timeout X-Git-Tag: 24jan2021_ls180~2099^2~225 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8f81ae6826a509a878ebaf0301ac9611328f15e2;p=litex.git genlib/misc: add FlipFlop, Counter, Timeout --- diff --git a/migen/genlib/misc.py b/migen/genlib/misc.py index 3f5cebad..340de13a 100644 --- a/migen/genlib/misc.py +++ b/migen/genlib/misc.py @@ -85,3 +85,29 @@ def timeline(trigger, events): sync = [If(get_cond(e), *e[1]) for e in events] sync.append(counterlogic) return sync + +@DecorateModule(InsertReset) +@DecorateModule(InsertCE) +class FlipFlop(Module): + def __init__(self, *args, **kwargs): + self.d = Signal(*args, **kwargs) + self.q = Signal(*args, **kwargs) + self.sync += self.q.eq(self.d) + +@DecorateModule(InsertReset) +@DecorateModule(InsertCE) +class Counter(Module): + def __init__(self, *args, **kwargs): + self.value = Signal(**kwargs) + self.width = flen(self.value) + self.sync += self.value.eq(self.value+1) + +@DecorateModule(InsertReset) +@DecorateModule(InsertCE) +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))