2017-01-17 06:53:29 -05:00
|
|
|
import unittest
|
2016-05-26 05:10:03 -04:00
|
|
|
|
2016-05-23 11:20:42 -04:00
|
|
|
from litex.gen import *
|
|
|
|
|
|
|
|
from litex.soc.interconnect.stream import *
|
|
|
|
|
|
|
|
from litedram.common import PhySettings, LiteDRAMPort
|
|
|
|
from litedram.core import *
|
|
|
|
from litedram.modules import SDRAMModule
|
|
|
|
from litedram.frontend.crossbar import LiteDRAMCrossbar
|
2017-01-17 09:18:10 -05:00
|
|
|
from litedram.frontend.bist import _LiteDRAMBISTGenerator
|
|
|
|
from litedram.frontend.bist import _LiteDRAMBISTChecker
|
2016-05-26 05:03:55 -04:00
|
|
|
from litedram.frontend.adaptation import LiteDRAMPortCDC
|
|
|
|
|
2016-05-23 11:20:42 -04:00
|
|
|
from litedram.phy.model import SDRAMPHYModel
|
|
|
|
|
2016-12-16 10:58:01 -05:00
|
|
|
from test.common import *
|
|
|
|
|
|
|
|
|
2016-05-23 11:20:42 -04:00
|
|
|
class SimModule(SDRAMModule):
|
|
|
|
# geometry
|
2016-05-28 07:00:52 -04:00
|
|
|
nbanks = 2
|
2016-05-23 11:20:42 -04:00
|
|
|
nrows = 2048
|
2016-05-28 07:00:52 -04:00
|
|
|
ncols = 2
|
2016-05-23 11:20:42 -04:00
|
|
|
# timings
|
|
|
|
tRP = 1
|
|
|
|
tRCD = 1
|
|
|
|
tWR = 1
|
|
|
|
tWTR = 1
|
|
|
|
tREFI = 1
|
|
|
|
tRFC = 1
|
|
|
|
|
|
|
|
|
|
|
|
class TB(Module):
|
|
|
|
def __init__(self):
|
2016-05-26 05:03:55 -04:00
|
|
|
# phy
|
2016-05-23 11:20:42 -04:00
|
|
|
sdram_module = SimModule(1000, "1:1")
|
|
|
|
phy_settings = PhySettings(
|
|
|
|
memtype="SDR",
|
|
|
|
dfi_databits=1*16,
|
|
|
|
nphases=1,
|
|
|
|
rdphase=0,
|
|
|
|
wrphase=0,
|
|
|
|
rdcmdphase=0,
|
|
|
|
wrcmdphase=0,
|
|
|
|
cl=2,
|
|
|
|
read_latency=4,
|
|
|
|
write_latency=0
|
|
|
|
)
|
2017-01-17 06:53:29 -05:00
|
|
|
self.submodules.sdrphy = SDRAMPHYModel(sdram_module,
|
|
|
|
phy_settings,
|
|
|
|
we_granularity=0)
|
2016-05-28 07:00:52 -04:00
|
|
|
|
2016-05-26 05:03:55 -04:00
|
|
|
# controller
|
2016-05-23 11:20:42 -04:00
|
|
|
self.submodules.controller = LiteDRAMController(
|
|
|
|
phy_settings,
|
|
|
|
sdram_module.geom_settings,
|
|
|
|
sdram_module.timing_settings,
|
|
|
|
ControllerSettings(with_refresh=False))
|
|
|
|
self.comb += self.controller.dfi.connect(self.sdrphy.dfi)
|
|
|
|
self.submodules.crossbar = LiteDRAMCrossbar(self.controller.interface,
|
|
|
|
self.controller.nrowbits)
|
2016-05-28 07:00:52 -04:00
|
|
|
|
2017-01-17 06:53:29 -05:00
|
|
|
# ports
|
2016-06-15 11:51:46 -04:00
|
|
|
write_user_port = self.crossbar.get_port("write", cd="write")
|
|
|
|
read_user_port = self.crossbar.get_port("read", cd="read")
|
2016-05-28 07:00:52 -04:00
|
|
|
|
|
|
|
# generator / checker
|
2017-01-17 09:18:10 -05:00
|
|
|
self.submodules.generator = _LiteDRAMBISTGenerator(write_user_port, True)
|
|
|
|
self.submodules.checker = _LiteDRAMBISTChecker(read_user_port, True)
|
2016-05-23 11:20:42 -04:00
|
|
|
|
|
|
|
|
|
|
|
def main_generator(dut):
|
2017-01-17 09:18:10 -05:00
|
|
|
generator = BISTDriver(dut.generator)
|
|
|
|
checker = BISTDriver(dut.checker)
|
2017-01-17 06:53:29 -05:00
|
|
|
|
2017-01-17 09:18:10 -05:00
|
|
|
for i in range(16):
|
|
|
|
yield
|
2017-01-17 06:53:29 -05:00
|
|
|
|
2016-05-23 11:20:42 -04:00
|
|
|
# write
|
2017-01-17 09:18:10 -05:00
|
|
|
yield from generator.reset()
|
|
|
|
yield from generator.run(16, 16)
|
|
|
|
|
|
|
|
# read (no errors)
|
|
|
|
yield from checker.reset()
|
|
|
|
yield from checker.run(16, 16)
|
|
|
|
assert checker.errors == 0
|
2017-01-17 06:53:29 -05:00
|
|
|
|
|
|
|
|
|
|
|
class TestBISTAsync(unittest.TestCase):
|
|
|
|
def test(self):
|
|
|
|
tb = TB()
|
|
|
|
generators = {"sys" : [main_generator(tb)]}
|
|
|
|
clocks = {"sys": 10,
|
|
|
|
"write": 12,
|
|
|
|
"read": 8}
|
|
|
|
run_simulation(tb, generators, clocks, vcd_name="sim.vcd")
|
|
|
|
self.assertEqual(dut.checker.error_count.status, 0)
|