2016-05-26 05:10:03 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2016-12-16 10:46:03 -05:00
|
|
|
import random
|
|
|
|
|
2016-05-03 13:24:33 -04:00
|
|
|
from litex.gen import *
|
|
|
|
|
|
|
|
from litex.soc.interconnect.stream import *
|
|
|
|
|
2016-06-15 11:51:46 -04:00
|
|
|
from litedram.common import LiteDRAMWritePort, LiteDRAMReadPort
|
2016-05-03 13:24:33 -04:00
|
|
|
from litedram.frontend.bist import LiteDRAMBISTGenerator
|
|
|
|
from litedram.frontend.bist import LiteDRAMBISTChecker
|
2016-12-19 10:42:34 -05:00
|
|
|
from litedram.frontend.bist import LiteDRAMBISTCheckerScope
|
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
|
|
|
|
2016-05-03 13:24:33 -04:00
|
|
|
class TB(Module):
|
|
|
|
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)
|
2016-12-17 05:49:22 -05:00
|
|
|
self.submodules.generator = LiteDRAMBISTGenerator(self.write_port, random=True)
|
|
|
|
self.submodules.checker = LiteDRAMBISTChecker(self.read_port, random=True)
|
2016-12-19 10:42:34 -05:00
|
|
|
self.submodules.checker_scope = LiteDRAMBISTCheckerScope(self.checker)
|
2016-12-17 05:49:22 -05:00
|
|
|
|
|
|
|
|
2016-12-16 10:46:03 -05:00
|
|
|
def main_generator(dut, mem):
|
|
|
|
# Populate memory with random data
|
|
|
|
random.seed(0)
|
|
|
|
for i in range(0, len(mem.mem)):
|
|
|
|
mem.mem[i] = random.randint(0, 2**mem.width)
|
|
|
|
|
2016-05-03 13:24:33 -04:00
|
|
|
# write
|
2016-12-16 10:58:01 -05:00
|
|
|
yield from reset_bist_module(dut.generator)
|
2016-12-16 10:46:03 -05:00
|
|
|
|
2016-05-03 13:24:33 -04:00
|
|
|
yield dut.generator.base.storage.eq(16)
|
2016-05-03 16:22:11 -04:00
|
|
|
yield dut.generator.length.storage.eq(64)
|
2016-05-23 08:17:22 -04:00
|
|
|
for i in range(8):
|
|
|
|
yield
|
2016-12-16 10:48:28 -05:00
|
|
|
yield dut.generator.start.re.eq(1)
|
2016-05-03 13:24:33 -04:00
|
|
|
yield
|
2016-12-16 10:48:28 -05:00
|
|
|
yield dut.generator.start.re.eq(0)
|
2016-05-23 08:17:22 -04:00
|
|
|
for i in range(8):
|
|
|
|
yield
|
2016-05-03 13:24:33 -04:00
|
|
|
while((yield dut.generator.done.status) == 0):
|
|
|
|
yield
|
2016-12-16 10:46:03 -05:00
|
|
|
done = yield dut.generator.done.status
|
|
|
|
assert done, done
|
|
|
|
|
|
|
|
# read with no errors
|
2016-12-16 10:58:01 -05:00
|
|
|
yield from reset_bist_module(dut.checker)
|
2016-12-17 12:14:16 -05:00
|
|
|
errors = yield dut.checker.err_count.status
|
2016-12-16 10:46:03 -05:00
|
|
|
assert errors == 0, errors
|
|
|
|
|
|
|
|
yield dut.checker.base.storage.eq(16)
|
|
|
|
yield dut.checker.length.storage.eq(64)
|
|
|
|
for i in range(8):
|
|
|
|
yield
|
2016-12-16 10:58:01 -05:00
|
|
|
yield from toggle_re(dut.checker.start)
|
2016-12-16 10:46:03 -05:00
|
|
|
for i in range(8):
|
|
|
|
yield
|
|
|
|
while((yield dut.checker.done.status) == 0):
|
|
|
|
yield
|
|
|
|
done = yield dut.checker.done.status
|
|
|
|
assert done, done
|
2016-12-17 12:14:16 -05:00
|
|
|
errors = yield dut.checker.err_count.status
|
2016-12-16 10:46:03 -05:00
|
|
|
assert errors == 0, errors
|
|
|
|
|
|
|
|
yield
|
|
|
|
yield
|
|
|
|
|
|
|
|
# read with one error
|
2016-12-16 10:58:01 -05:00
|
|
|
yield from reset_bist_module(dut.checker)
|
2016-12-17 12:14:16 -05:00
|
|
|
errors = yield dut.checker.err_count.status
|
2016-12-16 10:46:03 -05:00
|
|
|
assert errors == 0, errors
|
|
|
|
|
2016-12-17 05:49:22 -05:00
|
|
|
print("mem.mem[20]", hex(mem.mem[20]))
|
|
|
|
assert mem.mem[20] == 0xffff000f, hex(mem.mem[20])
|
|
|
|
mem.mem[20] = 0x200 # Make position 20 an error
|
2016-12-16 10:46:03 -05:00
|
|
|
|
2016-05-03 13:24:33 -04:00
|
|
|
yield dut.checker.base.storage.eq(16)
|
2016-05-03 16:22:11 -04:00
|
|
|
yield dut.checker.length.storage.eq(64)
|
2016-05-23 08:17:22 -04:00
|
|
|
for i in range(8):
|
|
|
|
yield
|
2016-12-16 10:58:01 -05:00
|
|
|
yield from toggle_re(dut.checker.start)
|
2016-05-23 08:17:22 -04:00
|
|
|
for i in range(8):
|
|
|
|
yield
|
2016-05-03 13:24:33 -04:00
|
|
|
while((yield dut.checker.done.status) == 0):
|
|
|
|
yield
|
2016-12-16 10:46:03 -05:00
|
|
|
done = yield dut.checker.done.status
|
|
|
|
assert done, done
|
2016-12-17 12:14:16 -05:00
|
|
|
errors = yield dut.checker.err_count.status
|
2016-12-16 10:46:03 -05:00
|
|
|
assert errors == 1, errors
|
|
|
|
|
2016-05-03 16:22:11 -04:00
|
|
|
yield
|
2016-12-16 10:46:03 -05:00
|
|
|
yield
|
|
|
|
|
2016-12-17 05:49:22 -05:00
|
|
|
# read with two errors
|
|
|
|
yield from reset_bist_module(dut.checker)
|
2016-12-17 12:14:16 -05:00
|
|
|
errors = yield dut.checker.err_count.status
|
2016-12-17 05:49:22 -05:00
|
|
|
assert errors == 0, errors
|
|
|
|
|
|
|
|
print("mem.mem[21]", hex(mem.mem[21]))
|
|
|
|
assert mem.mem[21] == 0xfff1ff1f, hex(mem.mem[21])
|
|
|
|
mem.mem[21] = 0x210 # Make position 21 an error
|
|
|
|
|
|
|
|
yield dut.checker.base.storage.eq(16)
|
|
|
|
yield dut.checker.length.storage.eq(64)
|
|
|
|
for i in range(8):
|
|
|
|
yield
|
|
|
|
yield from toggle_re(dut.checker.start)
|
|
|
|
for i in range(8):
|
|
|
|
yield
|
|
|
|
while((yield dut.checker.done.status) == 0):
|
|
|
|
yield
|
|
|
|
done = yield dut.checker.done.status
|
|
|
|
assert done, done
|
2016-12-17 12:14:16 -05:00
|
|
|
errors = yield dut.checker.err_count.status
|
2016-12-17 05:49:22 -05:00
|
|
|
assert errors == 2, errors
|
|
|
|
|
|
|
|
yield
|
|
|
|
yield
|
|
|
|
|
2016-12-19 10:42:34 -05:00
|
|
|
# check the scoped signals
|
2016-12-17 05:49:22 -05:00
|
|
|
yield from reset_bist_module(dut.checker)
|
2016-12-17 12:14:16 -05:00
|
|
|
errors = yield dut.checker.err_count.status
|
2016-12-17 05:49:22 -05:00
|
|
|
assert errors == 0, errors
|
|
|
|
|
|
|
|
yield dut.checker.base.storage.eq(16)
|
|
|
|
yield dut.checker.length.storage.eq(64)
|
|
|
|
for i in range(8):
|
|
|
|
yield
|
|
|
|
yield from toggle_re(dut.checker.start)
|
|
|
|
for i in range(8):
|
|
|
|
yield
|
2016-12-19 10:42:34 -05:00
|
|
|
while((yield dut.checker_scope.data_error) == 0):
|
2016-12-17 05:49:22 -05:00
|
|
|
yield
|
|
|
|
|
2016-12-19 10:42:34 -05:00
|
|
|
err_addr = yield dut.checker_scope.data_address
|
2016-12-17 06:01:58 -05:00
|
|
|
assert err_addr == 20, err_addr
|
2016-12-19 10:42:34 -05:00
|
|
|
err_expect = yield dut.checker_scope.data_expected
|
2016-12-17 11:49:47 -05:00
|
|
|
assert err_expect == 0xffff000f, hex(err_expect)
|
2016-12-19 10:42:34 -05:00
|
|
|
err_actual = yield dut.checker_scope.data_actual
|
2016-12-17 06:01:58 -05:00
|
|
|
assert err_actual == 0x200, err_actual
|
2016-12-17 11:49:47 -05:00
|
|
|
yield
|
2016-12-17 12:14:16 -05:00
|
|
|
errors = yield dut.checker.core.err_count
|
2016-12-17 11:49:47 -05:00
|
|
|
assert errors == 1, errors
|
2016-12-17 05:49:22 -05:00
|
|
|
|
2016-12-19 10:42:34 -05:00
|
|
|
while((yield dut.checker_scope.data_error) == 0):
|
2016-12-17 05:49:22 -05:00
|
|
|
yield
|
|
|
|
|
2016-12-19 10:42:34 -05:00
|
|
|
err_addr = yield dut.checker_scope.data_address
|
2016-12-17 06:01:58 -05:00
|
|
|
assert err_addr == 21, err_addr
|
2016-12-19 10:42:34 -05:00
|
|
|
err_expect = yield dut.checker_scope.data_expected
|
2016-12-17 11:49:47 -05:00
|
|
|
assert err_expect == 0xfff1ff1f, hex(err_expect)
|
2016-12-19 10:42:34 -05:00
|
|
|
err_actual = yield dut.checker_scope.data_actual
|
2016-12-17 11:49:47 -05:00
|
|
|
assert err_actual == 0x210, hex(err_actual)
|
|
|
|
yield
|
2016-12-17 12:14:16 -05:00
|
|
|
errors = yield dut.checker.core.err_count
|
2016-12-17 11:49:47 -05:00
|
|
|
assert errors == 2, errors
|
2016-12-17 05:49:22 -05:00
|
|
|
|
|
|
|
while((yield dut.checker.done.status) == 0):
|
|
|
|
yield
|
2016-12-17 12:14:16 -05:00
|
|
|
|
2016-12-17 05:49:22 -05:00
|
|
|
done = yield dut.checker.done.status
|
|
|
|
assert done, done
|
2016-12-17 12:14:16 -05:00
|
|
|
errors = yield dut.checker.err_count.status
|
2016-12-17 05:49:22 -05:00
|
|
|
assert errors == 2, errors
|
|
|
|
|
|
|
|
yield
|
|
|
|
yield
|
|
|
|
|
2016-05-03 13:24:33 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
tb = TB()
|
2016-05-03 16:22:11 -04:00
|
|
|
mem = DRAMMemory(32, 128)
|
2016-05-03 13:24:33 -04:00
|
|
|
generators = {
|
2016-12-17 05:49:22 -05:00
|
|
|
"sys" : [
|
|
|
|
main_generator(tb, mem),
|
|
|
|
mem.write_generator(tb.write_port),
|
|
|
|
mem.read_generator(tb.read_port),
|
|
|
|
],
|
2016-05-03 13:24:33 -04:00
|
|
|
}
|
|
|
|
clocks = {"sys": 10}
|
|
|
|
run_simulation(tb, generators, clocks, vcd_name="sim.vcd")
|