examples/graycounter: use new simulator
authorSebastien Bourdeauducq <sb@m-labs.hk>
Sat, 12 Sep 2015 07:14:21 +0000 (15:14 +0800)
committerSebastien Bourdeauducq <sb@m-labs.hk>
Sat, 12 Sep 2015 07:14:21 +0000 (15:14 +0800)
examples/basic/graycounter.py

index 8a0f7243a949cd6e996a2e2809ecee4143d33903..d361635048334eca7b6e9e81322e216dc6294d46 100644 (file)
@@ -2,19 +2,18 @@ from random import Random
 
 from migen.fhdl.std import *
 from migen.genlib.cdc import GrayCounter
-from migen.sim.generic import run_simulation
+from migen.sim import Simulator
 
 
-class TB(Module):
-    def __init__(self, width=3):
-        self.width = width
-        self.submodules.gc = GrayCounter(self.width)
-        self.prng = Random(7345)
+def tb(dut):
+    prng = Random(7345)
+    for i in range(35):
+        print("{0:0{1}b} CE={2} bin={3}".format((yield dut.q),
+            flen(dut.q), (yield dut.ce), (yield dut.q_binary)))
+        yield dut.ce, prng.getrandbits(1)
+        yield
 
-    def do_simulation(self, selfp):
-        print("{0:0{1}b} CE={2} bin={3}".format(selfp.gc.q,
-            self.width, selfp.gc.ce, selfp.gc.q_binary))
-        selfp.gc.ce = self.prng.getrandbits(1)
 
 if __name__ == "__main__":
-    run_simulation(TB(), ncycles=35)
+    dut = GrayCounter(3)
+    Simulator(dut, tb(dut)).run()