tb: fix timer reset; cosmetic fixes.

main
Jean-François Nguyen 3 years ago
parent 28a239724e
commit ea98ca49df

@ -5,47 +5,46 @@ from amaranth.asserts import *
__all__ = ["Testbench"] __all__ = ["Testbench"]




def _check_triggers(t_start, t_pre, t_post):
if not isinstance(t_start, int) or t_start <= 0:
raise ValueError("t_start must be a positive integer, not {!r}"
.format(t_start))
if not isinstance(t_post, int) or t_post < t_start:
raise ValueError("t_post must be an integer greater than or equal to t_start ({}), not {!r}"
.format(t_start, t_post))
if not isinstance(t_pre, int) or t_pre > t_post or t_pre < t_start:
raise ValueError("t_pre must be an integer between t_start and t_post (i.e. [{},{}]), "
"not {!r}".format(t_pre, t_start, t_post))


class Testbench(Elaboratable): class Testbench(Elaboratable):
def __init__(self, check, dut, *, t_post, t_pre=None, t_start=0): def __init__(self, check, dut, *, t_start=1, t_pre=None, t_post=20):
if not isinstance(t_post, int) or t_post < 0: if t_pre is None and t_post is not None:
raise ValueError("t_post must be a non-negative integer, not {!r}"
.format(t_post))
if t_pre is None:
t_pre = t_post t_pre = t_post
if not isinstance(t_pre, int) or t_pre < 0:
raise ValueError("t_pre must be a non-negative integer, not {!r}"
.format(t_pre))
if t_pre > t_post:
raise ValueError("t_pre ({}) must be lesser than or equal to t_post ({})"
.format(t_pre, t_post))
if not isinstance(t_start, int) or t_start < 0:
raise ValueError("t_start must be a non-negative integer, not {!r}"
.format(t_start))
if t_start > t_pre:
raise ValueError("t_start ({}) must be lesser than or equal to t_pre ({})"
.format(t_start, t_pre))


self.t_post = t_post _check_triggers(t_start, t_pre, t_post)
self.t_pre = t_pre
self.t_start = t_start


self.check = check self.check = check
self.dut = dut self.dut = dut
self.t_start = t_start
self.t_pre = t_pre
self.t_post = t_post


def elaborate(self, platform): def elaborate(self, platform):
m = Module() m = Module()


timer = Signal(range(self.t_post + 1)) timer = Signal(range(self.t_post + 2), reset=1)
with m.If(timer != self.t_post):
with m.If(timer <= self.t_post):
m.d.sync += timer.eq(timer + 1) m.d.sync += timer.eq(timer + 1)


m.submodules.check = ResetInserter(timer < self.t_start)(self.check) m.submodules.check = ResetInserter(timer < self.t_start)(self.check)
m.submodules.dut = self.dut m.submodules.dut = self.dut


m.d.comb += [ m.d.comb += [
self.check.dut .eq(self.dut.pfv),
self.check.pre .eq(timer == self.t_pre), self.check.pre .eq(timer == self.t_pre),
self.check.post.eq(timer == self.t_post), self.check.post.eq(timer == self.t_post),
self.check.pfv .eq(self.dut.pfv),
] ]


m.d.comb += Assume(ResetSignal() == Initial()) m.d.comb += Assume(ResetSignal() == Initial())

Loading…
Cancel
Save