re-bba-rb/re-bba/ReBba/TestBenches/DebouncerTb.py

54 lines
1.1 KiB
Python
Raw Normal View History

from ReBba.Components.Debouncer import Debouncer
from amaranth import Const
from amaranth.sim import Simulator
import os
class TestBench:
def __init__(self):
pass
def holdTest(self):
dut = self.dut
yield
yield
yield dut.input.eq(Const(1))
yield
yield dut.input.eq(Const(0))
yield
for _ in range(5):
assert(yield(dut.output) == 1)
yield
yield dut.input.eq(Const(1))
yield
yield dut.input.eq(Const(0))
yield
for _ in range(16):
assert(yield(dut.output) == 1)
yield
assert(yield(dut.output) == 0)
yield
yield
def simulate(self):
self.dut = Debouncer(15)
sim = Simulator(self.dut)
sim.add_clock(1e-6) # 1 MHz
sim.add_sync_process(self.holdTest)
with sim.write_vcd(os.path.dirname(os.path.abspath(__file__)) + "/Debouncer.vcd"):
sim.run()
def main():
bench = TestBench()
bench.simulate()
if __name__ == "__main__":
main()