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>
|
|
|
|
# License: BSD
|
|
|
|
|
2017-01-17 06:53:29 -05:00
|
|
|
import unittest
|
2016-12-16 10:46:03 -05:00
|
|
|
import random
|
|
|
|
|
2018-02-23 07:39:23 -05:00
|
|
|
from migen import *
|
2016-05-03 13:24:33 -04:00
|
|
|
|
|
|
|
from litex.soc.interconnect.stream import *
|
|
|
|
|
2018-08-28 05:50:11 -04:00
|
|
|
from litedram.common import *
|
|
|
|
from litedram.frontend.bist import *
|
2017-01-17 08:14:50 -05:00
|
|
|
from litedram.frontend.bist import _LiteDRAMBISTGenerator
|
|
|
|
from litedram.frontend.bist import _LiteDRAMBISTChecker
|
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
|
|
|
|
2018-08-09 04:54:42 -04:00
|
|
|
from litex.gen.sim import *
|
|
|
|
|
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
|
|
|
|
2018-08-28 05:50:11 -04:00
|
|
|
def run(self, base, length):
|
|
|
|
yield self.module.base.eq(base)
|
2020-02-11 08:24:02 -05:00
|
|
|
yield self.module.end.eq(base + 0x100000)
|
2018-08-28 05:50:11 -04:00
|
|
|
yield self.module.length.eq(length)
|
2020-02-11 08:24:02 -05:00
|
|
|
yield self.module.run.eq(1)
|
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
|
|
|
|
2017-01-17 06:53:29 -05:00
|
|
|
class TestBIST(unittest.TestCase):
|
2018-08-28 05:50:11 -04:00
|
|
|
def test_generator(self):
|
|
|
|
port = LiteDRAMNativeWritePort(address_width=32, data_width=32)
|
|
|
|
|
|
|
|
def main_generator(dut):
|
|
|
|
self.errors = 0
|
|
|
|
|
|
|
|
# test incr
|
|
|
|
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
|
|
|
|
|
|
|
|
# test random
|
|
|
|
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
|
|
|
|
|
|
|
|
# dut
|
|
|
|
dut = Generator(23, n_state=23, taps=[17, 22])
|
|
|
|
|
|
|
|
# simulation
|
|
|
|
generators = [main_generator(dut)]
|
2019-07-23 15:46:03 -04:00
|
|
|
run_simulation(dut, main_generator(dut))
|
2018-08-28 05:50:11 -04:00
|
|
|
self.assertEqual(self.errors, 0)
|
|
|
|
|
|
|
|
def test_bist(self):
|
|
|
|
class DUT(Module):
|
|
|
|
def __init__(self):
|
|
|
|
self.write_port = LiteDRAMNativeWritePort(address_width=32, data_width=32)
|
|
|
|
self.read_port = LiteDRAMNativeReadPort(address_width=32, data_width=32)
|
|
|
|
self.submodules.generator = _LiteDRAMBISTGenerator(self.write_port)
|
|
|
|
self.submodules.checker = _LiteDRAMBISTChecker(self.read_port)
|
|
|
|
|
|
|
|
def main_generator(dut, mem):
|
|
|
|
generator = GenCheckDriver(dut.generator)
|
|
|
|
checker = GenCheckDriver(dut.checker)
|
|
|
|
|
|
|
|
# write
|
|
|
|
yield from generator.reset()
|
|
|
|
yield from generator.run(16, 64)
|
|
|
|
|
|
|
|
# read (no errors)
|
|
|
|
yield from checker.reset()
|
|
|
|
yield from checker.run(16, 64)
|
|
|
|
assert checker.errors == 0
|
|
|
|
|
|
|
|
# corrupt memory (using generator)
|
|
|
|
yield from generator.reset()
|
|
|
|
yield from generator.run(16 + 60, 64)
|
|
|
|
|
|
|
|
# read (4 errors)
|
|
|
|
yield from checker.reset()
|
|
|
|
yield from checker.run(16, 64)
|
|
|
|
assert checker.errors != 0
|
|
|
|
|
|
|
|
# read (no errors)
|
|
|
|
yield from checker.reset()
|
|
|
|
yield from checker.run(16 + 60, 64)
|
|
|
|
assert checker.errors == 0
|
|
|
|
|
|
|
|
# dut
|
2017-01-17 06:53:29 -05:00
|
|
|
dut = DUT()
|
|
|
|
mem = DRAMMemory(32, 128)
|
2018-08-28 05:50:11 -04:00
|
|
|
|
|
|
|
# simulation
|
|
|
|
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)
|
2018-08-28 05:50:11 -04:00
|
|
|
]
|
2019-07-23 15:46:03 -04:00
|
|
|
run_simulation(dut, generators)
|