2019-06-23 17:56:50 -04:00
|
|
|
# This file is Copyright (c) 2016-2018 Florent Kermarrec <florent@enjoy-digital.fr>
|
|
|
|
# This file is Copyright (c) 2016 Tim 'mithro' Ansell <mithro@mithis.com>
|
2020-03-19 04:13:28 -04:00
|
|
|
# This file is Copyright (c) 2020 Antmicro <www.antmicro.com>
|
2019-06-23 17:56:50 -04:00
|
|
|
# License: BSD
|
|
|
|
|
2017-01-17 06:53:29 -05:00
|
|
|
import unittest
|
2016-12-16 10:46:03 -05:00
|
|
|
|
2018-02-23 07:39:23 -05:00
|
|
|
from migen import *
|
2016-05-03 13:24:33 -04:00
|
|
|
|
2020-03-19 04:13:28 -04:00
|
|
|
from litex.gen.sim import *
|
2016-05-03 13:24:33 -04:00
|
|
|
|
2018-08-28 05:50:11 -04:00
|
|
|
from litedram.common import *
|
|
|
|
from litedram.frontend.bist import *
|
2020-03-12 12:04:22 -04:00
|
|
|
from litedram.frontend.bist import _LiteDRAMBISTGenerator, _LiteDRAMBISTChecker, \
|
|
|
|
_LiteDRAMPatternGenerator, _LiteDRAMPatternChecker
|
2016-05-03 13:24:33 -04:00
|
|
|
|
2016-12-16 10:58:01 -05:00
|
|
|
from test.common import *
|
2016-05-23 07:30:38 -04:00
|
|
|
|
2017-01-17 06:53:29 -05:00
|
|
|
|
2018-08-28 05:50:11 -04:00
|
|
|
class GenCheckDriver:
|
|
|
|
def __init__(self, module):
|
|
|
|
self.module = module
|
2016-12-17 05:49:22 -05:00
|
|
|
|
2018-08-28 05:50:11 -04:00
|
|
|
def reset(self):
|
|
|
|
yield self.module.reset.eq(1)
|
|
|
|
yield
|
|
|
|
yield self.module.reset.eq(0)
|
|
|
|
yield
|
2016-12-17 05:49:22 -05:00
|
|
|
|
2020-03-13 11:13:36 -04:00
|
|
|
def configure(self, base, length, end=None, random_addr=None, random_data=None):
|
2020-04-13 13:38:29 -04:00
|
|
|
# For non-pattern generators/checkers
|
2020-03-11 10:18:44 -04:00
|
|
|
if end is None:
|
|
|
|
end = base + 0x100000
|
2018-08-28 05:50:11 -04:00
|
|
|
yield self.module.base.eq(base)
|
2020-03-11 10:18:44 -04:00
|
|
|
yield self.module.end.eq(end)
|
2018-08-28 05:50:11 -04:00
|
|
|
yield self.module.length.eq(length)
|
2020-03-13 11:13:36 -04:00
|
|
|
if random_addr is not None:
|
|
|
|
yield self.module.random_addr.eq(random_addr)
|
|
|
|
if random_data is not None:
|
|
|
|
yield self.module.random_data.eq(random_data)
|
2020-03-13 04:58:02 -04:00
|
|
|
|
|
|
|
def run(self):
|
2018-08-28 05:50:11 -04:00
|
|
|
yield self.module.start.eq(1)
|
|
|
|
yield
|
|
|
|
yield self.module.start.eq(0)
|
|
|
|
yield
|
|
|
|
while((yield self.module.done) == 0):
|
|
|
|
yield
|
|
|
|
if hasattr(self.module, "errors"):
|
|
|
|
self.errors = (yield self.module.errors)
|
2016-12-17 05:49:22 -05:00
|
|
|
|
2016-05-03 13:24:33 -04:00
|
|
|
|
2020-03-16 11:02:24 -04:00
|
|
|
class GenCheckCSRDriver:
|
|
|
|
def __init__(self, module):
|
|
|
|
self.module = module
|
|
|
|
|
|
|
|
def reset(self):
|
|
|
|
yield from self.module.reset.write(1)
|
|
|
|
yield from self.module.reset.write(0)
|
|
|
|
|
|
|
|
def configure(self, base, length, end=None, random_addr=None, random_data=None):
|
2020-04-13 13:38:29 -04:00
|
|
|
# For non-pattern generators/checkers
|
2020-03-16 11:02:24 -04:00
|
|
|
if end is None:
|
|
|
|
end = base + 0x100000
|
|
|
|
yield from self.module.base.write(base)
|
|
|
|
yield from self.module.end.write(end)
|
|
|
|
yield from self.module.length.write(length)
|
|
|
|
if random_addr is not None:
|
|
|
|
yield from self.module.random.addr.write(random_addr)
|
|
|
|
if random_data is not None:
|
|
|
|
yield from self.module.random.data.write(random_data)
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
yield from self.module.start.write(1)
|
|
|
|
yield
|
|
|
|
yield from self.module.start.write(0)
|
|
|
|
yield
|
|
|
|
while((yield from self.module.done.read()) == 0):
|
|
|
|
yield
|
|
|
|
if hasattr(self.module, "errors"):
|
|
|
|
self.errors = (yield from self.module.errors.read())
|
|
|
|
|
|
|
|
|
2020-03-19 04:13:28 -04:00
|
|
|
class TestBIST(MemoryTestDataMixin, unittest.TestCase):
|
2020-03-13 08:58:01 -04:00
|
|
|
|
2020-03-17 09:23:08 -04:00
|
|
|
# Generator ------------------------------------------------------------------------------------
|
|
|
|
|
2018-08-28 05:50:11 -04:00
|
|
|
def test_generator(self):
|
2020-04-14 13:44:50 -04:00
|
|
|
# Verify Generator is behaving correctly in the incr/random modes.
|
2018-08-28 05:50:11 -04:00
|
|
|
def main_generator(dut):
|
|
|
|
self.errors = 0
|
|
|
|
|
2020-04-13 13:38:29 -04:00
|
|
|
# Test incr
|
2018-08-28 05:50:11 -04:00
|
|
|
yield dut.ce.eq(1)
|
|
|
|
yield dut.random_enable.eq(0)
|
|
|
|
yield
|
|
|
|
for i in range(1024):
|
|
|
|
data = (yield dut.o)
|
|
|
|
if data != i:
|
|
|
|
self.errors += 1
|
|
|
|
yield
|
|
|
|
|
2020-04-13 13:38:29 -04:00
|
|
|
# Test random
|
2018-08-28 05:50:11 -04:00
|
|
|
datas = []
|
|
|
|
yield dut.ce.eq(1)
|
|
|
|
yield dut.random_enable.eq(1)
|
|
|
|
for i in range(1024):
|
|
|
|
data = (yield dut.o)
|
|
|
|
if data in datas:
|
|
|
|
self.errors += 1
|
|
|
|
datas.append(data)
|
|
|
|
yield
|
|
|
|
|
2020-04-13 13:38:29 -04:00
|
|
|
# DUT
|
2018-08-28 05:50:11 -04:00
|
|
|
dut = Generator(23, n_state=23, taps=[17, 22])
|
|
|
|
|
2020-04-13 13:38:29 -04:00
|
|
|
# Simulation
|
2018-08-28 05:50:11 -04:00
|
|
|
generators = [main_generator(dut)]
|
2020-03-11 10:18:44 -04:00
|
|
|
run_simulation(dut, generators)
|
2018-08-28 05:50:11 -04:00
|
|
|
self.assertEqual(self.errors, 0)
|
|
|
|
|
2020-03-17 09:23:08 -04:00
|
|
|
def generator_test(self, mem_expected, data_width, pattern=None, config_args=None,
|
|
|
|
check_mem=True):
|
|
|
|
assert pattern is None or config_args is None, \
|
|
|
|
"_LiteDRAMBISTGenerator xor _LiteDRAMPatternGenerator"
|
2020-03-11 10:18:44 -04:00
|
|
|
|
|
|
|
class DUT(Module):
|
|
|
|
def __init__(self):
|
|
|
|
self.write_port = LiteDRAMNativeWritePort(address_width=32, data_width=data_width)
|
2020-03-13 11:13:36 -04:00
|
|
|
if pattern is not None:
|
2020-03-17 09:23:08 -04:00
|
|
|
self.submodules.generator = _LiteDRAMPatternGenerator(self.write_port, pattern)
|
2020-03-13 11:13:36 -04:00
|
|
|
else:
|
|
|
|
self.submodules.generator = _LiteDRAMBISTGenerator(self.write_port)
|
|
|
|
self.mem = DRAMMemory(data_width, len(mem_expected))
|
2020-03-11 10:18:44 -04:00
|
|
|
|
2020-03-13 11:13:36 -04:00
|
|
|
def main_generator(driver):
|
|
|
|
yield from driver.reset()
|
|
|
|
if pattern is None:
|
|
|
|
yield from driver.configure(**config_args)
|
|
|
|
yield from driver.run()
|
2020-03-11 10:18:44 -04:00
|
|
|
yield
|
|
|
|
|
|
|
|
dut = DUT()
|
|
|
|
generators = [
|
2020-03-13 11:13:36 -04:00
|
|
|
main_generator(GenCheckDriver(dut.generator)),
|
2020-03-11 10:18:44 -04:00
|
|
|
dut.mem.write_handler(dut.write_port),
|
|
|
|
]
|
2020-03-13 11:13:36 -04:00
|
|
|
run_simulation(dut, generators)
|
|
|
|
if check_mem:
|
|
|
|
self.assertEqual(dut.mem.mem, mem_expected)
|
|
|
|
return dut
|
2020-03-11 10:18:44 -04:00
|
|
|
|
2020-03-17 09:23:08 -04:00
|
|
|
# _LiteDRAMBISTGenerator -----------------------------------------------------------------------
|
|
|
|
|
2020-03-13 06:58:26 -04:00
|
|
|
def test_bist_generator_8bit(self):
|
2020-04-14 13:44:50 -04:00
|
|
|
# Verify BISTGenerator with a 8-bit datapath.
|
2020-03-17 04:45:28 -04:00
|
|
|
data = self.bist_test_data["8bit"]
|
|
|
|
self.generator_test(data.pop("expected"), data_width=8, config_args=data)
|
2020-03-13 06:58:26 -04:00
|
|
|
|
|
|
|
def test_bist_generator_range_must_be_pow2(self):
|
2020-03-13 08:58:01 -04:00
|
|
|
# NOTE:
|
|
|
|
# in the current implementation (end - start) must be a power of 2,
|
|
|
|
# but it would be better if this restriction didn't hold, this test
|
|
|
|
# is here just to notice the change if it happens unintentionally
|
|
|
|
# and may be removed if we start supporting arbitrary ranges
|
2020-03-17 04:45:28 -04:00
|
|
|
data = self.bist_test_data["8bit"]
|
|
|
|
data["end"] += 1
|
|
|
|
reference = data.pop("expected")
|
2020-03-13 11:13:36 -04:00
|
|
|
dut = self.generator_test(reference, data_width=8, config_args=data, check_mem=False)
|
|
|
|
self.assertNotEqual(dut.mem.mem, reference)
|
2020-03-13 08:58:01 -04:00
|
|
|
|
|
|
|
def test_bist_generator_32bit(self):
|
2020-04-14 13:44:50 -04:00
|
|
|
# Verify BISTGenerator with a 32-bit datapath.
|
2020-03-17 04:45:28 -04:00
|
|
|
data = self.bist_test_data["32bit"]
|
|
|
|
self.generator_test(data.pop("expected"), data_width=32, config_args=data)
|
2020-03-13 06:58:26 -04:00
|
|
|
|
|
|
|
def test_bist_generator_64bit(self):
|
2020-04-14 13:44:50 -04:00
|
|
|
# Verify BISTGenerator with a 64-bit datapath.
|
2020-03-17 04:45:28 -04:00
|
|
|
data = self.bist_test_data["64bit"]
|
|
|
|
self.generator_test(data.pop("expected"), data_width=64, config_args=data)
|
2020-03-13 08:58:01 -04:00
|
|
|
|
|
|
|
def test_bist_generator_32bit_address_masked(self):
|
2020-04-14 13:44:50 -04:00
|
|
|
# Verify BISTGenerator with a 32-bit datapath and masked address.
|
2020-03-17 04:45:28 -04:00
|
|
|
data = self.bist_test_data["32bit_masked"]
|
|
|
|
self.generator_test(data.pop("expected"), data_width=32, config_args=data)
|
2020-03-13 08:58:01 -04:00
|
|
|
|
|
|
|
def test_bist_generator_32bit_long_sequential(self):
|
2020-04-14 13:44:50 -04:00
|
|
|
# Verify BISTGenerator with a 32-bit datapath and long sequential pattern.
|
2020-03-17 04:45:28 -04:00
|
|
|
data = self.bist_test_data["32bit_long_sequential"]
|
|
|
|
self.generator_test(data.pop("expected"), data_width=32, config_args=data)
|
2020-03-13 06:58:26 -04:00
|
|
|
|
2020-03-11 10:18:44 -04:00
|
|
|
def test_bist_generator_random_data(self):
|
2020-04-14 13:44:50 -04:00
|
|
|
# Verify BISTGenerator with a 32-bit datapath and random pattern.
|
2020-03-17 04:45:28 -04:00
|
|
|
data = self.bist_test_data["32bit"]
|
|
|
|
data["random_data"] = True
|
2020-03-17 09:23:08 -04:00
|
|
|
dut = self.generator_test(data.pop("expected"), data_width=32, config_args=data,
|
|
|
|
check_mem=False)
|
2020-04-13 13:38:29 -04:00
|
|
|
# Only check that there are no duplicates and that data is not a simple sequence
|
2020-03-13 11:13:36 -04:00
|
|
|
mem = [val for val in dut.mem.mem if val != 0]
|
2020-03-17 04:45:28 -04:00
|
|
|
self.assertEqual(len(set(mem)), len(mem), msg="Duplicate values in memory")
|
|
|
|
self.assertNotEqual(mem, list(range(len(mem))), msg="Values are a sequence")
|
2020-03-11 10:18:44 -04:00
|
|
|
|
2020-03-17 08:08:34 -04:00
|
|
|
def test_bist_generator_random_addr(self):
|
2020-04-14 13:44:50 -04:00
|
|
|
# Verify BISTGenerator with a 32-bit datapath and random address.
|
2020-03-17 04:45:28 -04:00
|
|
|
data = self.bist_test_data["32bit"]
|
|
|
|
data["random_addr"] = True
|
2020-03-17 09:23:08 -04:00
|
|
|
dut = self.generator_test(data.pop("expected"), data_width=32, config_args=data,
|
|
|
|
check_mem=False)
|
2020-04-13 13:38:29 -04:00
|
|
|
# With random address and address wrapping (generator.end) we _can_ have duplicates
|
2020-03-11 10:18:44 -04:00
|
|
|
# we can at least check that the values written are not an ordered sequence
|
2020-03-13 11:13:36 -04:00
|
|
|
mem = [val for val in dut.mem.mem if val != 0]
|
2020-03-17 04:45:28 -04:00
|
|
|
self.assertNotEqual(mem, list(range(len(mem))), msg="Values are a sequence")
|
|
|
|
self.assertLess(max(mem), data["length"], msg="Too big value found")
|
2020-03-12 12:04:22 -04:00
|
|
|
|
2020-03-17 09:23:08 -04:00
|
|
|
# _LiteDRAMPatternGenerator --------------------------------------------------------------------
|
|
|
|
|
2020-03-12 12:04:22 -04:00
|
|
|
def test_pattern_generator_8bit(self):
|
2020-04-14 13:44:50 -04:00
|
|
|
# Verify PatternGenerator with a 8-bit datapath.
|
2020-03-17 04:45:28 -04:00
|
|
|
data = self.pattern_test_data["8bit"]
|
|
|
|
self.generator_test(data["expected"], data_width=8, pattern=data["pattern"])
|
2020-03-13 08:58:01 -04:00
|
|
|
|
|
|
|
def test_pattern_generator_32bit(self):
|
2020-04-14 13:44:50 -04:00
|
|
|
# Verify PatternGenerator with a 32-bit datapath.
|
2020-03-17 04:45:28 -04:00
|
|
|
data = self.pattern_test_data["32bit"]
|
|
|
|
self.generator_test(data["expected"], data_width=32, pattern=data["pattern"])
|
2020-03-13 11:13:36 -04:00
|
|
|
|
|
|
|
def test_pattern_generator_64bit(self):
|
2020-04-14 13:44:50 -04:00
|
|
|
# Verify PatternGenerator with a 64-bit datapath.
|
2020-03-17 04:45:28 -04:00
|
|
|
data = self.pattern_test_data["64bit"]
|
|
|
|
self.generator_test(data["expected"], data_width=64, pattern=data["pattern"])
|
2020-03-12 12:04:22 -04:00
|
|
|
|
2020-03-13 11:13:36 -04:00
|
|
|
def test_pattern_generator_32bit_not_aligned(self):
|
2020-04-14 13:44:50 -04:00
|
|
|
# Verify PatternGenerator with a 32-bit datapath and un-aligned addresses.
|
2020-03-17 04:45:28 -04:00
|
|
|
data = self.pattern_test_data["32bit_not_aligned"]
|
|
|
|
self.generator_test(data["expected"], data_width=32, pattern=data["pattern"])
|
2020-03-13 08:58:01 -04:00
|
|
|
|
2020-03-13 11:13:36 -04:00
|
|
|
def test_pattern_generator_32bit_duplicates(self):
|
2020-04-14 13:44:50 -04:00
|
|
|
# Verify PatternGenerator with a 32-bit datapath and duplicate addresses.
|
2020-03-17 04:45:28 -04:00
|
|
|
data = self.pattern_test_data["32bit_duplicates"]
|
|
|
|
self.generator_test(data["expected"], data_width=32, pattern=data["pattern"])
|
2020-03-12 12:04:22 -04:00
|
|
|
|
2020-03-13 11:13:36 -04:00
|
|
|
def test_pattern_generator_32bit_sequential(self):
|
2020-04-14 13:44:50 -04:00
|
|
|
# Verify PatternGenerator with a 32-bit datapath and sequential pattern.
|
2020-03-17 04:45:28 -04:00
|
|
|
data = self.pattern_test_data["32bit_sequential"]
|
|
|
|
self.generator_test(data["expected"], data_width=32, pattern=data["pattern"])
|
2020-03-12 12:04:22 -04:00
|
|
|
|
2020-03-17 09:23:08 -04:00
|
|
|
# _LiteDRAMBISTChecker -------------------------------------------------------------------------
|
|
|
|
|
2020-03-13 11:13:36 -04:00
|
|
|
def checker_test(self, memory, data_width, pattern=None, config_args=None, check_errors=False):
|
2020-03-17 09:23:08 -04:00
|
|
|
assert pattern is None or config_args is None, \
|
|
|
|
"_LiteDRAMBISTChecker xor _LiteDRAMPatternChecker"
|
2020-03-13 08:58:01 -04:00
|
|
|
|
|
|
|
class DUT(Module):
|
|
|
|
def __init__(self):
|
|
|
|
self.read_port = LiteDRAMNativeReadPort(address_width=32, data_width=data_width)
|
|
|
|
if pattern is not None:
|
|
|
|
self.submodules.checker = _LiteDRAMPatternChecker(self.read_port, init=pattern)
|
|
|
|
else:
|
|
|
|
self.submodules.checker = _LiteDRAMBISTChecker(self.read_port)
|
|
|
|
self.mem = DRAMMemory(data_width, len(memory), init=memory)
|
|
|
|
|
2020-03-13 11:13:36 -04:00
|
|
|
def main_generator(driver):
|
|
|
|
yield from driver.reset()
|
2020-03-13 08:58:01 -04:00
|
|
|
if pattern is None:
|
2020-03-13 11:13:36 -04:00
|
|
|
yield from driver.configure(**config_args)
|
|
|
|
yield from driver.run()
|
2020-03-13 08:58:01 -04:00
|
|
|
yield
|
|
|
|
|
|
|
|
dut = DUT()
|
|
|
|
checker = GenCheckDriver(dut.checker)
|
|
|
|
generators = [
|
|
|
|
main_generator(checker),
|
|
|
|
dut.mem.read_handler(dut.read_port),
|
|
|
|
]
|
2020-03-13 11:13:36 -04:00
|
|
|
run_simulation(dut, generators)
|
|
|
|
if check_errors:
|
|
|
|
self.assertEqual(checker.errors, 0)
|
|
|
|
return dut, checker
|
2020-03-13 08:58:01 -04:00
|
|
|
|
|
|
|
def test_bist_checker_8bit(self):
|
2020-04-14 13:44:50 -04:00
|
|
|
# Verify BISTChecker with a 8-bit datapath.
|
2020-03-17 04:45:28 -04:00
|
|
|
data = self.bist_test_data["8bit"]
|
|
|
|
memory = data.pop("expected")
|
2020-03-13 11:13:36 -04:00
|
|
|
self.checker_test(memory, data_width=8, config_args=data)
|
2020-03-13 08:58:01 -04:00
|
|
|
|
|
|
|
def test_bist_checker_32bit(self):
|
2020-04-14 13:44:50 -04:00
|
|
|
# Verify BISTChecker with a 32-bit datapath.
|
2020-03-17 04:45:28 -04:00
|
|
|
data = self.bist_test_data["32bit"]
|
|
|
|
memory = data.pop("expected")
|
2020-03-13 11:13:36 -04:00
|
|
|
self.checker_test(memory, data_width=32, config_args=data)
|
2020-03-13 08:58:01 -04:00
|
|
|
|
|
|
|
def test_bist_checker_64bit(self):
|
2020-04-14 13:44:50 -04:00
|
|
|
# Verify BISTChecker with a 64-bit datapath.
|
|
|
|
data = self.bist_test_data["64bit"]
|
2020-03-17 04:45:28 -04:00
|
|
|
memory = data.pop("expected")
|
2020-04-14 13:44:50 -04:00
|
|
|
self.checker_test(memory, data_width=64, config_args=data)
|
2020-03-13 08:58:01 -04:00
|
|
|
|
2020-03-17 09:23:08 -04:00
|
|
|
# _LiteDRAMPatternChecker ----------------------------------------------------------------------
|
|
|
|
|
2020-03-13 08:58:01 -04:00
|
|
|
def test_pattern_checker_8bit(self):
|
2020-04-14 13:44:50 -04:00
|
|
|
# Verify PatternChecker with a 8-bit datapath.
|
2020-03-17 04:45:28 -04:00
|
|
|
data = self.pattern_test_data["8bit"]
|
|
|
|
self.checker_test(memory=data["expected"], data_width=8, pattern=data["pattern"])
|
2020-03-13 08:58:01 -04:00
|
|
|
|
|
|
|
def test_pattern_checker_32bit(self):
|
2020-04-14 13:44:50 -04:00
|
|
|
# Verify PatternChecker with a 32-bit datapath.
|
2020-03-17 04:45:28 -04:00
|
|
|
data = self.pattern_test_data["32bit"]
|
|
|
|
self.checker_test(memory=data["expected"], data_width=32, pattern=data["pattern"])
|
2020-03-13 08:58:01 -04:00
|
|
|
|
|
|
|
def test_pattern_checker_64bit(self):
|
2020-04-14 13:44:50 -04:00
|
|
|
# Verify PatternChecker with a 64-bit datapath.
|
2020-03-17 04:45:28 -04:00
|
|
|
data = self.pattern_test_data["64bit"]
|
|
|
|
self.checker_test(memory=data["expected"], data_width=64, pattern=data["pattern"])
|
2020-03-13 08:58:01 -04:00
|
|
|
|
|
|
|
def test_pattern_checker_32bit_not_aligned(self):
|
2020-04-14 13:44:50 -04:00
|
|
|
# Verify PatternChecker with a 32-bit datapath and un-aligned addresses.
|
2020-03-17 04:45:28 -04:00
|
|
|
data = self.pattern_test_data["32bit_not_aligned"]
|
|
|
|
self.checker_test(memory=data["expected"], data_width=32, pattern=data["pattern"])
|
2020-03-13 08:58:01 -04:00
|
|
|
|
|
|
|
def test_pattern_checker_32bit_duplicates(self):
|
2020-04-14 13:44:50 -04:00
|
|
|
# Verify PatternChecker with a 32-bit datapath and duplicate addresses.
|
2020-03-17 04:45:28 -04:00
|
|
|
data = self.pattern_test_data["32bit_duplicates"]
|
|
|
|
num_duplicates = len(data["pattern"]) - len(set(adr for adr, _ in data["pattern"]))
|
|
|
|
dut, checker = self.checker_test(
|
|
|
|
memory=data["expected"], data_width=32, pattern=data["pattern"], check_errors=False)
|
2020-03-13 11:13:36 -04:00
|
|
|
self.assertEqual(checker.errors, num_duplicates)
|
2020-03-13 08:58:01 -04:00
|
|
|
|
2020-03-17 09:23:08 -04:00
|
|
|
# LiteDRAMBISTGenerator and LiteDRAMBISTChecker ------------------------------------------------
|
|
|
|
|
2020-03-16 11:02:24 -04:00
|
|
|
def bist_test(self, generator, checker, mem):
|
|
|
|
# write
|
|
|
|
yield from generator.reset()
|
2020-04-14 12:14:05 -04:00
|
|
|
yield from generator.configure(base=16, length=64)
|
2020-03-16 11:02:24 -04:00
|
|
|
yield from generator.run()
|
|
|
|
|
2020-04-13 13:38:29 -04:00
|
|
|
# Read (no errors)
|
2020-03-16 11:02:24 -04:00
|
|
|
yield from checker.reset()
|
2020-04-14 12:14:05 -04:00
|
|
|
yield from checker.configure(base=16, length=64)
|
2020-03-16 11:02:24 -04:00
|
|
|
yield from checker.run()
|
|
|
|
self.assertEqual(checker.errors, 0)
|
|
|
|
|
2020-04-13 13:38:29 -04:00
|
|
|
# Corrupt memory (using generator)
|
2020-03-16 11:02:24 -04:00
|
|
|
yield from generator.reset()
|
2020-04-14 12:14:05 -04:00
|
|
|
yield from generator.configure(base=16 + 48, length=64)
|
2020-03-16 11:02:24 -04:00
|
|
|
yield from generator.run()
|
|
|
|
|
2020-04-13 13:38:29 -04:00
|
|
|
# Read (errors)
|
2020-03-16 11:02:24 -04:00
|
|
|
yield from checker.reset()
|
2020-04-14 12:14:05 -04:00
|
|
|
yield from checker.configure(base=16, length=64)
|
2020-03-16 11:02:24 -04:00
|
|
|
yield from checker.run()
|
2020-04-13 13:38:29 -04:00
|
|
|
# Errors for words:
|
2020-03-16 11:02:24 -04:00
|
|
|
# from (16 + 48) / 4 = 16 (corrupting generator start)
|
|
|
|
# to (16 + 64) / 4 = 20 (first generator end)
|
|
|
|
self.assertEqual(checker.errors, 4)
|
|
|
|
|
2020-04-13 13:38:29 -04:00
|
|
|
# Read (no errors)
|
2020-03-16 11:02:24 -04:00
|
|
|
yield from checker.reset()
|
2020-04-14 12:14:05 -04:00
|
|
|
yield from checker.configure(base=16 + 48, length=64)
|
2020-03-16 11:02:24 -04:00
|
|
|
yield from checker.run()
|
|
|
|
self.assertEqual(checker.errors, 0)
|
|
|
|
|
|
|
|
def test_bist_base(self):
|
2020-04-14 13:44:50 -04:00
|
|
|
# Verify BIST (Generator and Checker) with control from the logic.
|
2018-08-28 05:50:11 -04:00
|
|
|
class DUT(Module):
|
|
|
|
def __init__(self):
|
|
|
|
self.write_port = LiteDRAMNativeWritePort(address_width=32, data_width=32)
|
2020-04-13 13:38:29 -04:00
|
|
|
self.read_port = LiteDRAMNativeReadPort(address_width=32, data_width=32)
|
2018-08-28 05:50:11 -04:00
|
|
|
self.submodules.generator = _LiteDRAMBISTGenerator(self.write_port)
|
2020-04-13 13:38:29 -04:00
|
|
|
self.submodules.checker = _LiteDRAMBISTChecker(self.read_port)
|
2018-08-28 05:50:11 -04:00
|
|
|
|
|
|
|
def main_generator(dut, mem):
|
|
|
|
generator = GenCheckDriver(dut.generator)
|
2020-04-13 13:38:29 -04:00
|
|
|
checker = GenCheckDriver(dut.checker)
|
2020-03-16 11:02:24 -04:00
|
|
|
yield from self.bist_test(generator, checker, mem)
|
|
|
|
|
2020-04-13 13:38:29 -04:00
|
|
|
# DUT
|
2020-03-16 11:02:24 -04:00
|
|
|
dut = DUT()
|
|
|
|
mem = DRAMMemory(32, 48)
|
|
|
|
|
2020-04-13 13:38:29 -04:00
|
|
|
# Simulation
|
2020-03-16 11:02:24 -04:00
|
|
|
generators = [
|
|
|
|
main_generator(dut, mem),
|
|
|
|
mem.write_handler(dut.write_port),
|
|
|
|
mem.read_handler(dut.read_port)
|
2020-03-17 04:45:28 -04:00
|
|
|
]
|
2020-03-16 11:02:24 -04:00
|
|
|
run_simulation(dut, generators)
|
2018-08-28 05:50:11 -04:00
|
|
|
|
2020-03-16 11:02:24 -04:00
|
|
|
def test_bist_csr(self):
|
2020-04-14 13:44:50 -04:00
|
|
|
# Verify BIST (Generator and Checker) with control from CSRs.
|
2020-03-16 11:02:24 -04:00
|
|
|
class DUT(Module):
|
|
|
|
def __init__(self):
|
|
|
|
self.write_port = LiteDRAMNativeWritePort(address_width=32, data_width=32)
|
2020-04-13 13:38:29 -04:00
|
|
|
self.read_port = LiteDRAMNativeReadPort(address_width=32, data_width=32)
|
2020-03-16 11:02:24 -04:00
|
|
|
self.submodules.generator = LiteDRAMBISTGenerator(self.write_port)
|
2020-04-13 13:38:29 -04:00
|
|
|
self.submodules.checker = LiteDRAMBISTChecker(self.read_port)
|
2020-03-16 11:02:24 -04:00
|
|
|
|
|
|
|
def main_generator(dut, mem):
|
|
|
|
generator = GenCheckCSRDriver(dut.generator)
|
2020-04-13 13:38:29 -04:00
|
|
|
checker = GenCheckCSRDriver(dut.checker)
|
2020-03-16 11:02:24 -04:00
|
|
|
yield from self.bist_test(generator, checker, mem)
|
2018-08-28 05:50:11 -04:00
|
|
|
|
2020-04-13 13:38:29 -04:00
|
|
|
# DUT
|
2017-01-17 06:53:29 -05:00
|
|
|
dut = DUT()
|
2020-03-16 11:02:24 -04:00
|
|
|
mem = DRAMMemory(32, 48)
|
2018-08-28 05:50:11 -04:00
|
|
|
|
2020-04-13 13:38:29 -04:00
|
|
|
# Simulation
|
2018-08-28 05:50:11 -04:00
|
|
|
generators = [
|
|
|
|
main_generator(dut, mem),
|
2018-08-28 07:40:50 -04:00
|
|
|
mem.write_handler(dut.write_port),
|
|
|
|
mem.read_handler(dut.read_port)
|
2020-03-17 04:45:28 -04:00
|
|
|
]
|
2019-07-23 15:46:03 -04:00
|
|
|
run_simulation(dut, generators)
|
2020-03-16 11:02:24 -04:00
|
|
|
|
2020-03-24 09:27:29 -04:00
|
|
|
def test_bist_csr_cdc(self):
|
2020-04-14 13:44:50 -04:00
|
|
|
# Verify BIST (Generator and Checker) with control from CSRs in a different clock domain.
|
2020-03-24 09:27:29 -04:00
|
|
|
class DUT(Module):
|
|
|
|
def __init__(self):
|
2020-04-13 13:38:29 -04:00
|
|
|
port_kwargs = dict(address_width=32, data_width=32, clock_domain="async")
|
2020-03-24 09:27:29 -04:00
|
|
|
self.write_port = LiteDRAMNativeWritePort(**port_kwargs)
|
2020-04-13 13:38:29 -04:00
|
|
|
self.read_port = LiteDRAMNativeReadPort(**port_kwargs)
|
2020-03-24 09:27:29 -04:00
|
|
|
self.submodules.generator = LiteDRAMBISTGenerator(self.write_port)
|
2020-04-13 13:38:29 -04:00
|
|
|
self.submodules.checker = LiteDRAMBISTChecker(self.read_port)
|
2020-03-24 09:27:29 -04:00
|
|
|
|
|
|
|
def main_generator(dut, mem):
|
|
|
|
generator = GenCheckCSRDriver(dut.generator)
|
2020-04-13 13:38:29 -04:00
|
|
|
checker = GenCheckCSRDriver(dut.checker)
|
2020-03-24 09:27:29 -04:00
|
|
|
yield from self.bist_test(generator, checker, mem)
|
|
|
|
|
2020-04-13 13:38:29 -04:00
|
|
|
# DUT
|
2020-03-24 09:27:29 -04:00
|
|
|
dut = DUT()
|
|
|
|
mem = DRAMMemory(32, 48)
|
|
|
|
|
|
|
|
generators = {
|
|
|
|
"sys": [
|
|
|
|
main_generator(dut, mem),
|
|
|
|
],
|
|
|
|
"async": [
|
|
|
|
mem.write_handler(dut.write_port),
|
|
|
|
mem.read_handler(dut.read_port)
|
|
|
|
]
|
|
|
|
}
|
|
|
|
clocks = {
|
|
|
|
"sys": 10,
|
|
|
|
"async": (7, 3),
|
|
|
|
}
|
|
|
|
run_simulation(dut, generators, clocks)
|