You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
598 B
Python
25 lines
598 B
Python
from amaranth import *
|
|
|
|
|
|
__all__ = ["Timer"]
|
|
|
|
|
|
class Timer(Elaboratable):
|
|
def __init__(self, start):
|
|
if not isinstance(start, int) or start < 0:
|
|
raise TypeError("Start value must be a non-negative integer, not {!r}"
|
|
.format(start))
|
|
|
|
self.ctr = Signal(range(start + 1), reset=start, reset_less=True)
|
|
self.zero = Signal()
|
|
|
|
def elaborate(self, platform):
|
|
m = Module()
|
|
|
|
with m.If(self.ctr != 0):
|
|
m.d.sync += self.ctr.eq(self.ctr - 1)
|
|
|
|
m.d.comb += self.zero.eq(self.ctr == 0)
|
|
|
|
return m
|