Skip to content

Commit

Permalink
gen/genlib/misc: Add CE option to WaitTimer
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanG077 committed Sep 13, 2023
1 parent 36ce71d commit 2d3b3b7
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions litex/gen/genlib/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,28 @@ def get_cond(e):


class WaitTimer(Module):
def __init__(self, t):
self.wait = Signal()
self.done = Signal()
def __init__(self, t, has_ce=False):
self.wait = Signal() # i
self.ce = Signal() # i
self.done = Signal() # o

# # #

# Cast t to int.
t = int(t)
count = Signal(bits_for(t), reset=t)

tick = Signal()
if has_ce:
self.comb += tick.eq(~self.done & self.ce)
else:
self.comb += tick.eq(~self.done)

self.comb += self.done.eq(count == 0)

self.sync += [
If(self.wait,
If(~self.done,
If(tick,
count.eq(count - 1)
)
).Else(
Expand Down

0 comments on commit 2d3b3b7

Please sign in to comment.