def txxd_controller_random_test(self, txxd, loops): def generator(dut, valid_rand): prng = random.Random(42) for l in range(loops): while prng.randrange(100) < valid_rand: yield yield dut.valid.eq(1) yield yield dut.valid.eq(0) @passive def checker(dut): dut.ready_gaps = [] while True: while (yield dut.ready) != 0: yield ready_gap = 1 while (yield dut.ready) != 1: ready_gap += 1 yield dut.ready_gaps.append(ready_gap) dut = tXXDController(txxd) run_simulation(dut, [generator(dut, valid_rand=90), checker(dut)]) self.assertEqual(min(dut.ready_gaps), txxd)
def txxd_controller_test(self, txxd, valids, readys): def generator(dut): dut.errors = 0 for valid, ready in zip(valids, readys): yield dut.valid.eq(c2bool(valid)) yield if (yield dut.ready) != c2bool(ready): dut.errors += 1 dut = tXXDController(txxd) run_simulation(dut, [generator(dut)]) self.assertEqual(dut.errors, 0)
def __init__(self, t): self.trigger = Signal() self.ready = Signal() self.ready_p = Signal() ready_d = Signal() triggered = Signal() tctrl = tXXDController(t) self.submodules += tctrl self.sync += If(self.trigger, triggered.eq(1)), self.comb += [ self.ready.eq(triggered & tctrl.ready), self.ready_p.eq(edge(self, self.ready)), tctrl.valid.eq(edge(self, self.trigger)), ]