litex/misoclib/mem/sdram/test/refresher.py

48 lines
1.3 KiB
Python
Raw Normal View History

2012-03-30 10:40:51 -04:00
from random import Random
2013-05-22 11:10:13 -04:00
from migen.fhdl.std import *
from migen.sim.generic import run_simulation
2012-03-30 10:40:51 -04:00
from misoclib.mem.sdram.core.lasmicon.refresher import *
2012-03-30 10:40:51 -04:00
from common import CommandLogger
2015-04-13 10:47:22 -04:00
2013-07-15 11:45:55 -04:00
class Granter(Module):
def __init__(self, req, ack):
self.req = req
self.ack = ack
self.state = 0
self.prng = Random(92837)
def do_simulation(self, selfp):
elts = ["@" + str(selfp.simulator.cycle_counter)]
if self.state == 0:
if selfp.req:
elts.append("Refresher requested access")
self.state = 1
elif self.state == 1:
if self.prng.randrange(0, 5) == 0:
elts.append("Granted access to refresher")
selfp.ack = 1
self.state = 2
elif self.state == 2:
if not selfp.req:
elts.append("Refresher released access")
selfp.ack = 0
self.state = 0
if len(elts) > 1:
print("\t".join(elts))
2013-07-15 11:45:55 -04:00
2015-04-13 10:47:22 -04:00
2013-07-15 11:45:55 -04:00
class TB(Module):
def __init__(self):
self.submodules.dut = Refresher(13, 2, tRP=3, tREFI=100, tRFC=5)
self.submodules.logger = CommandLogger(self.dut.cmd)
self.submodules.granter = Granter(self.dut.req, self.dut.ack)
2012-03-30 10:40:51 -04:00
if __name__ == "__main__":
run_simulation(TB(), ncycles=400)