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 *
|
|
|
|
|
2016-06-15 11:51:46 -04:00
|
|
|
from litedram.common import LiteDRAMWritePort, LiteDRAMReadPort
|
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
|
|
|
|
2017-01-17 06:53:29 -05:00
|
|
|
|
|
|
|
class DUT(Module):
|
2016-05-03 13:24:33 -04:00
|
|
|
def __init__(self):
|
2016-06-15 11:51:46 -04:00
|
|
|
self.write_port = LiteDRAMWritePort(aw=32, dw=32)
|
|
|
|
self.read_port = LiteDRAMReadPort(aw=32, dw=32)
|
2017-01-17 08:31:24 -05:00
|
|
|
self.submodules.generator = _LiteDRAMBISTGenerator(self.write_port, True)
|
|
|
|
self.submodules.checker = _LiteDRAMBISTChecker(self.read_port, True)
|
2016-12-17 05:49:22 -05:00
|
|
|
|
|
|
|
|
2017-01-17 08:31:24 -05:00
|
|
|
def main_generator(dut, mem):
|
|
|
|
generator = BISTDriver(dut.generator)
|
|
|
|
checker = BISTDriver(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
|
2016-12-17 05:49:22 -05:00
|
|
|
|
2017-01-17 08:35:34 -05:00
|
|
|
# corrupt memory (using generator)
|
|
|
|
yield from generator.reset()
|
|
|
|
yield from generator.run(16 + 60, 64)
|
2016-12-17 05:49:22 -05:00
|
|
|
|
2017-01-17 08:14:50 -05:00
|
|
|
# read (4 errors)
|
2017-01-17 08:31:24 -05:00
|
|
|
yield from checker.reset()
|
|
|
|
yield from checker.run(16, 64)
|
|
|
|
assert checker.errors == 4
|
2016-12-17 05:49:22 -05:00
|
|
|
|
2017-01-17 08:14:50 -05:00
|
|
|
# read (no errors)
|
2017-01-17 08:31:24 -05:00
|
|
|
yield from checker.reset()
|
2017-01-17 08:35:34 -05:00
|
|
|
yield from checker.run(16 + 60, 64)
|
2017-01-17 08:31:24 -05:00
|
|
|
assert checker.errors == 0
|
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):
|
|
|
|
def test(self):
|
|
|
|
dut = DUT()
|
|
|
|
mem = DRAMMemory(32, 128)
|
|
|
|
generators = {
|
|
|
|
"sys" : [
|
|
|
|
main_generator(dut, mem),
|
|
|
|
mem.write_generator(dut.write_port),
|
|
|
|
mem.read_generator(dut.read_port)
|
|
|
|
]
|
|
|
|
}
|
|
|
|
clocks = {"sys": 10}
|
|
|
|
run_simulation(dut, generators, clocks, vcd_name="sim.vcd")
|