2013-04-24 13:13:36 -04:00
|
|
|
from random import Random
|
|
|
|
|
2013-05-22 11:11:09 -04:00
|
|
|
from migen.fhdl.std import *
|
2013-04-24 13:13:36 -04:00
|
|
|
from migen.genlib.cdc import GrayCounter
|
2014-01-26 16:19:43 -05:00
|
|
|
from migen.sim.generic import run_simulation
|
2013-04-24 13:13:36 -04:00
|
|
|
|
|
|
|
class TB(Module):
|
2015-04-13 14:07:07 -04:00
|
|
|
def __init__(self, width=3):
|
|
|
|
self.width = width
|
|
|
|
self.submodules.gc = GrayCounter(self.width)
|
|
|
|
self.prng = Random(7345)
|
2013-04-24 13:13:36 -04:00
|
|
|
|
2015-04-13 14:07:07 -04:00
|
|
|
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)
|
2013-04-24 13:13:36 -04:00
|
|
|
|
2014-01-26 16:19:43 -05:00
|
|
|
if __name__ == "__main__":
|
2015-04-13 14:07:07 -04:00
|
|
|
run_simulation(TB(), ncycles=35)
|