2019-07-23 10:36:21 -04:00
|
|
|
# This file is Copyright (c) 2019 Florent Kermarrec <florent@enjoy-digital.fr>
|
|
|
|
# License: BSD
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
from migen import *
|
|
|
|
|
|
|
|
from litedram.core.multiplexer import cmd_request_rw_layout
|
2019-08-14 02:07:10 -04:00
|
|
|
from litedram.core.refresher import RefreshSequencer, RefreshTimer, Refresher
|
2019-07-23 10:36:21 -04:00
|
|
|
|
|
|
|
|
|
|
|
def c2bool(c):
|
|
|
|
return {"-": 1, "_": 0}[c]
|
|
|
|
|
|
|
|
class TestRefresh(unittest.TestCase):
|
2019-08-14 02:07:10 -04:00
|
|
|
def refresh_sequencer_test(self, trp, trfc, starts, dones, cmds):
|
2019-07-23 10:36:21 -04:00
|
|
|
cmd = Record(cmd_request_rw_layout(a=16, ba=3))
|
|
|
|
def generator(dut):
|
|
|
|
dut.errors = 0
|
|
|
|
for start, done, cas, ras in zip(starts, dones, cmds.cas, cmds.ras):
|
|
|
|
yield dut.start.eq(c2bool(start))
|
|
|
|
yield
|
|
|
|
if (yield dut.done) != c2bool(done):
|
|
|
|
dut.errors += 1
|
|
|
|
if (yield cmd.cas) != c2bool(cas):
|
|
|
|
dut.errors += 1
|
|
|
|
if (yield cmd.ras) != c2bool(ras):
|
|
|
|
dut.errors += 1
|
2019-08-14 02:07:10 -04:00
|
|
|
dut = RefreshSequencer(cmd, trp, trfc)
|
2019-07-23 10:36:21 -04:00
|
|
|
run_simulation(dut, [generator(dut)])
|
|
|
|
self.assertEqual(dut.errors, 0)
|
|
|
|
|
2019-08-14 02:07:10 -04:00
|
|
|
def test_refresh_sequencer(self):
|
2019-07-23 10:36:21 -04:00
|
|
|
trp = 1
|
|
|
|
trfc = 2
|
2019-07-23 16:30:53 -04:00
|
|
|
class Obj: pass
|
|
|
|
cmds = Obj()
|
2019-07-23 10:36:21 -04:00
|
|
|
starts = "_-______________"
|
2019-07-24 02:01:54 -04:00
|
|
|
cmds.cas = "___-____________"
|
|
|
|
cmds.ras = "__--____________"
|
|
|
|
dones = "_____-__________"
|
2019-08-14 02:07:10 -04:00
|
|
|
self.refresh_sequencer_test(trp, trfc, starts, dones, cmds)
|
2019-07-23 15:42:21 -04:00
|
|
|
|
|
|
|
def refresh_timer_test(self, trefi):
|
|
|
|
def generator(dut):
|
|
|
|
dut.errors = 0
|
2019-07-24 02:18:04 -04:00
|
|
|
for i in range(16*trefi):
|
|
|
|
if i%trefi == (trefi - 1):
|
2019-07-23 15:42:21 -04:00
|
|
|
if (yield dut.refresh.done) != 1:
|
|
|
|
dut.errors += 1
|
|
|
|
else:
|
|
|
|
if (yield dut.refresh.done) != 0:
|
|
|
|
dut.errors += 1
|
2019-07-24 02:18:04 -04:00
|
|
|
yield
|
2019-07-23 15:42:21 -04:00
|
|
|
|
|
|
|
class DUT(Module):
|
|
|
|
def __init__(self, trefi):
|
|
|
|
self.submodules.refresh = RefreshTimer(trefi)
|
|
|
|
self.comb += self.refresh.wait.eq(~self.refresh.done)
|
|
|
|
|
|
|
|
dut = DUT(trefi)
|
|
|
|
run_simulation(dut, [generator(dut)])
|
|
|
|
self.assertEqual(dut.errors, 0)
|
|
|
|
|
|
|
|
def test_refresh_timer(self):
|
|
|
|
for i in range(1, 32):
|
|
|
|
self.refresh_timer_test(i)
|
2019-07-23 16:30:53 -04:00
|
|
|
|
2019-09-11 02:38:17 -04:00
|
|
|
def refresher_test(self, postponing):
|
2019-07-23 16:30:53 -04:00
|
|
|
class Obj: pass
|
|
|
|
settings = Obj()
|
|
|
|
settings.with_refresh = True
|
2019-09-11 02:38:17 -04:00
|
|
|
settings.refresh_zqcs_freq = 1e0
|
2019-08-14 02:07:10 -04:00
|
|
|
settings.timing = Obj()
|
2019-07-23 16:30:53 -04:00
|
|
|
settings.timing.tREFI = 64
|
|
|
|
settings.timing.tRP = 1
|
|
|
|
settings.timing.tRFC = 2
|
2019-09-09 09:07:38 -04:00
|
|
|
settings.timing.tZQCS = 64
|
2019-07-23 16:30:53 -04:00
|
|
|
settings.geom = Obj()
|
|
|
|
settings.geom.addressbits = 16
|
|
|
|
settings.geom.bankbits = 3
|
|
|
|
settings.phy = Obj()
|
|
|
|
settings.phy.nranks = 1
|
|
|
|
|
|
|
|
def generator(dut):
|
|
|
|
dut.errors = 0
|
|
|
|
yield dut.cmd.ready.eq(1)
|
|
|
|
for i in range(16):
|
|
|
|
while (yield dut.cmd.valid) == 0:
|
|
|
|
yield
|
|
|
|
cmd_valid_gap = 0
|
|
|
|
while (yield dut.cmd.valid) == 1:
|
|
|
|
cmd_valid_gap += 1
|
|
|
|
yield
|
|
|
|
while (yield dut.cmd.valid) == 0:
|
|
|
|
cmd_valid_gap += 1
|
|
|
|
yield
|
2019-09-11 02:38:17 -04:00
|
|
|
if cmd_valid_gap != postponing*settings.timing.tREFI:
|
2019-08-14 03:57:24 -04:00
|
|
|
print(cmd_valid_gap)
|
2019-07-23 16:30:53 -04:00
|
|
|
dut.errors += 1
|
|
|
|
|
2019-09-11 02:38:17 -04:00
|
|
|
dut = Refresher(settings, clk_freq=100e6, postponing=postponing)
|
2019-07-23 16:30:53 -04:00
|
|
|
run_simulation(dut, [generator(dut)])
|
|
|
|
self.assertEqual(dut.errors, 0)
|
2019-08-14 03:57:24 -04:00
|
|
|
|
|
|
|
def test_refresher(self):
|
|
|
|
for i in [1, 2, 4, 8]:
|
2019-09-11 02:38:17 -04:00
|
|
|
self.refresher_test(postponing=i)
|