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 91ec2d5
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions litex/gen/genlib/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,27 @@ 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 91ec2d5

Please sign in to comment.