2020-08-23 09:52:08 -04:00
|
|
|
#
|
|
|
|
# This file is part of LiteDRAM.
|
|
|
|
#
|
|
|
|
# Copyright (c) 2017-2019 Florent Kermarrec <florent@enjoy-digital.fr>
|
|
|
|
# Copyright (c) 2020 Antmicro <www.antmicro.com>
|
|
|
|
# SPDX-License-Identifier: BSD-2-Clause
|
2019-07-13 04:31:30 -04:00
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
from migen import *
|
|
|
|
|
|
|
|
from litex.soc.interconnect.stream import *
|
|
|
|
|
2020-05-07 04:04:34 -04:00
|
|
|
from litedram.common import LiteDRAMNativePort, LiteDRAMNativeWritePort, LiteDRAMNativeReadPort
|
2020-08-05 05:10:42 -04:00
|
|
|
from litedram.frontend.adapter import LiteDRAMNativePortConverter, LiteDRAMNativePortCDC
|
2019-07-13 04:31:30 -04:00
|
|
|
|
|
|
|
from test.common import *
|
|
|
|
|
|
|
|
from litex.gen.sim import *
|
|
|
|
|
|
|
|
|
2019-07-13 04:52:41 -04:00
|
|
|
class ConverterDUT(Module):
|
2020-05-07 04:08:21 -04:00
|
|
|
def __init__(self, user_data_width, native_data_width, mem_depth, separate_rw=True, read_latency=0):
|
2020-05-07 04:04:34 -04:00
|
|
|
self.separate_rw = separate_rw
|
|
|
|
if separate_rw:
|
|
|
|
self.write_user_port = LiteDRAMNativeWritePort(address_width=32, data_width=user_data_width)
|
|
|
|
self.write_crossbar_port = LiteDRAMNativeWritePort(address_width=32, data_width=native_data_width)
|
|
|
|
self.read_user_port = LiteDRAMNativeReadPort( address_width=32, data_width=user_data_width)
|
|
|
|
self.read_crossbar_port = LiteDRAMNativeReadPort( address_width=32, data_width=native_data_width)
|
2020-05-07 04:08:21 -04:00
|
|
|
self.write_driver = NativePortDriver(self.write_user_port)
|
|
|
|
self.read_driver = NativePortDriver(self.read_user_port)
|
2020-05-07 04:04:34 -04:00
|
|
|
else:
|
|
|
|
self.write_user_port = LiteDRAMNativePort(mode="both", address_width=32, data_width=user_data_width)
|
|
|
|
self.write_crossbar_port = LiteDRAMNativePort(mode="both", address_width=32, data_width=native_data_width)
|
2020-05-07 04:08:21 -04:00
|
|
|
self.write_driver = NativePortDriver(self.write_user_port)
|
2020-05-07 04:04:34 -04:00
|
|
|
self.read_user_port = self.write_user_port
|
|
|
|
self.read_crossbar_port = self.write_crossbar_port
|
2020-05-07 04:08:21 -04:00
|
|
|
self.read_driver = self.write_driver
|
|
|
|
|
|
|
|
self.driver_generators = [self.write_driver.write_data_handler(),
|
|
|
|
self.read_driver.read_data_handler(latency=read_latency)]
|
2019-07-13 04:52:41 -04:00
|
|
|
|
2020-04-13 13:38:29 -04:00
|
|
|
# Memory
|
2020-03-23 09:17:01 -04:00
|
|
|
self.memory = DRAMMemory(native_data_width, mem_depth)
|
|
|
|
|
2020-03-24 06:55:24 -04:00
|
|
|
def do_finalize(self):
|
2020-05-07 04:04:34 -04:00
|
|
|
if self.separate_rw:
|
|
|
|
self.submodules.write_converter = LiteDRAMNativePortConverter(
|
|
|
|
self.write_user_port, self.write_crossbar_port)
|
|
|
|
self.submodules.read_converter = LiteDRAMNativePortConverter(
|
|
|
|
self.read_user_port, self.read_crossbar_port)
|
|
|
|
else:
|
|
|
|
self.submodules.converter = LiteDRAMNativePortConverter(
|
|
|
|
self.write_user_port, self.write_crossbar_port)
|
2020-03-24 06:55:24 -04:00
|
|
|
|
2020-05-11 09:28:32 -04:00
|
|
|
def read(self, address, **kwargs):
|
|
|
|
return (yield from self.read_driver.read(address, **kwargs))
|
2020-03-24 07:04:53 -04:00
|
|
|
|
2020-05-11 09:28:32 -04:00
|
|
|
def write(self, address, data, **kwargs):
|
2020-03-24 07:04:53 -04:00
|
|
|
if self.write_user_port.data_width > self.write_crossbar_port.data_width:
|
2020-05-11 09:28:32 -04:00
|
|
|
kwargs["data_with_cmd"] = True
|
|
|
|
return (yield from self.write_driver.write(address, data, **kwargs))
|
2020-03-23 09:17:01 -04:00
|
|
|
|
2020-04-13 12:39:52 -04:00
|
|
|
|
2020-03-24 06:55:24 -04:00
|
|
|
class CDCDUT(ConverterDUT):
|
|
|
|
def do_finalize(self):
|
2020-04-13 12:39:52 -04:00
|
|
|
# Change clock domains
|
|
|
|
self.write_user_port.clock_domain = "user"
|
|
|
|
self.read_user_port.clock_domain = "user"
|
2020-03-24 06:55:24 -04:00
|
|
|
self.write_crossbar_port.clock_domain = "native"
|
2020-04-13 12:39:52 -04:00
|
|
|
self.read_crossbar_port.clock_domain = "native"
|
2020-03-24 06:55:24 -04:00
|
|
|
|
2020-04-13 12:39:52 -04:00
|
|
|
# Add CDC
|
2020-03-24 06:55:24 -04:00
|
|
|
self.submodules.write_converter = LiteDRAMNativePortCDC(
|
2020-04-13 12:39:52 -04:00
|
|
|
port_from = self.write_user_port,
|
|
|
|
port_to = self.write_crossbar_port)
|
2020-03-24 06:55:24 -04:00
|
|
|
self.submodules.read_converter = LiteDRAMNativePortCDC(
|
2020-04-13 12:39:52 -04:00
|
|
|
port_from = self.read_user_port,
|
|
|
|
port_to = self.read_crossbar_port)
|
2020-03-24 06:55:24 -04:00
|
|
|
|
|
|
|
|
2020-08-05 05:10:42 -04:00
|
|
|
class TestAdapter(MemoryTestDataMixin, unittest.TestCase):
|
2020-05-11 10:44:50 -04:00
|
|
|
def test_down_converter_ratio_must_be_integer(self):
|
2020-03-23 09:17:01 -04:00
|
|
|
with self.assertRaises(ValueError) as cm:
|
2020-03-24 06:55:24 -04:00
|
|
|
dut = ConverterDUT(user_data_width=64, native_data_width=24, mem_depth=128)
|
|
|
|
dut.finalize()
|
2020-03-23 09:17:01 -04:00
|
|
|
self.assertIn("ratio must be an int", str(cm.exception).lower())
|
|
|
|
|
2020-05-11 10:44:50 -04:00
|
|
|
def test_up_converter_ratio_must_be_integer(self):
|
2020-03-23 09:17:01 -04:00
|
|
|
with self.assertRaises(ValueError) as cm:
|
2020-03-24 06:55:24 -04:00
|
|
|
dut = ConverterDUT(user_data_width=32, native_data_width=48, mem_depth=128)
|
|
|
|
dut.finalize()
|
2020-03-23 09:17:01 -04:00
|
|
|
self.assertIn("ratio must be an int", str(cm.exception).lower())
|
|
|
|
|
2020-05-07 04:08:21 -04:00
|
|
|
def converter_readback_test(self, dut, pattern, mem_expected, main_generator=None):
|
2020-03-23 09:17:01 -04:00
|
|
|
assert len(set(adr for adr, _ in pattern)) == len(pattern), "Pattern has duplicates!"
|
2019-07-13 04:31:30 -04:00
|
|
|
|
2020-05-07 04:08:21 -04:00
|
|
|
if main_generator is None:
|
|
|
|
def main_generator(dut):
|
|
|
|
for adr, data in pattern:
|
|
|
|
yield from dut.write(adr, data)
|
2020-03-23 09:17:01 -04:00
|
|
|
|
2020-05-11 09:28:32 -04:00
|
|
|
for adr, _ in pattern[:-1]:
|
2020-05-07 04:08:21 -04:00
|
|
|
yield from dut.read(adr, wait_data=False)
|
2020-05-11 09:28:32 -04:00
|
|
|
# use cmd.last to indicate last command in the sequence
|
|
|
|
# this is needed for the cases in up-converter when it cannot be deduced
|
|
|
|
# that port_to.cmd should be sent
|
|
|
|
adr, _ = pattern[-1]
|
|
|
|
yield from dut.read(adr, wait_data=False, last=1)
|
2020-05-07 04:08:21 -04:00
|
|
|
|
|
|
|
yield from dut.write_driver.wait_all()
|
|
|
|
yield from dut.read_driver.wait_all()
|
2019-07-13 04:31:30 -04:00
|
|
|
|
|
|
|
generators = [
|
2020-05-07 04:08:21 -04:00
|
|
|
main_generator(dut),
|
|
|
|
*dut.driver_generators,
|
2019-07-13 04:31:30 -04:00
|
|
|
dut.memory.write_handler(dut.write_crossbar_port),
|
2020-03-23 09:17:01 -04:00
|
|
|
dut.memory.read_handler(dut.read_crossbar_port),
|
2020-05-07 04:08:21 -04:00
|
|
|
timeout_generator(1000),
|
2019-07-13 04:31:30 -04:00
|
|
|
]
|
2020-05-07 04:04:34 -04:00
|
|
|
run_simulation(dut, generators, vcd_name='sim.vcd')
|
2020-03-23 09:17:01 -04:00
|
|
|
self.assertEqual(dut.memory.mem, mem_expected)
|
2020-05-07 04:08:21 -04:00
|
|
|
self.assertEqual(dut.read_driver.rdata, [data for adr, data in pattern])
|
2020-05-07 04:04:34 -04:00
|
|
|
|
2020-05-07 04:08:21 -04:00
|
|
|
def converter_test(self, test_data, user_data_width, native_data_width, **kwargs):
|
2020-05-11 09:28:32 -04:00
|
|
|
for separate_rw in [True, False]:
|
2020-05-07 04:04:34 -04:00
|
|
|
with self.subTest(separate_rw=separate_rw):
|
|
|
|
data = self.pattern_test_data[test_data]
|
|
|
|
dut = ConverterDUT(user_data_width=user_data_width, native_data_width=native_data_width,
|
2020-05-07 04:08:21 -04:00
|
|
|
mem_depth=len(data["expected"]), separate_rw=separate_rw, **kwargs)
|
2020-05-07 04:04:34 -04:00
|
|
|
self.converter_readback_test(dut, data["pattern"], data["expected"])
|
|
|
|
|
2020-03-23 09:17:01 -04:00
|
|
|
def test_converter_1to1(self):
|
2020-04-13 12:39:52 -04:00
|
|
|
# Verify 64-bit to 64-bit identify-conversion.
|
2020-05-07 04:04:34 -04:00
|
|
|
self.converter_test(test_data="64bit", user_data_width=64, native_data_width=64)
|
2020-03-23 09:17:01 -04:00
|
|
|
|
|
|
|
def test_converter_2to1(self):
|
2020-04-13 12:39:52 -04:00
|
|
|
# Verify 64-bit to 32-bit down-conversion.
|
2020-05-07 04:04:34 -04:00
|
|
|
self.converter_test(test_data="64bit_to_32bit", user_data_width=64, native_data_width=32)
|
2020-03-23 09:17:01 -04:00
|
|
|
|
|
|
|
def test_converter_4to1(self):
|
2020-04-13 12:39:52 -04:00
|
|
|
# Verify 32-bit to 8-bit down-conversion.
|
2020-05-07 04:04:34 -04:00
|
|
|
self.converter_test(test_data="32bit_to_8bit", user_data_width=32, native_data_width=8)
|
2020-03-23 09:17:01 -04:00
|
|
|
|
|
|
|
def test_converter_8to1(self):
|
2020-04-13 12:39:52 -04:00
|
|
|
# Verify 64-bit to 8-bit down-conversion.
|
2020-05-07 04:04:34 -04:00
|
|
|
self.converter_test(test_data="64bit_to_8bit", user_data_width=64, native_data_width=8)
|
2020-03-23 09:17:01 -04:00
|
|
|
|
|
|
|
def test_converter_1to2(self):
|
2020-04-13 12:39:52 -04:00
|
|
|
# Verify 8-bit to 16-bit up-conversion.
|
2020-05-07 04:04:34 -04:00
|
|
|
self.converter_test(test_data="8bit_to_16bit", user_data_width=8, native_data_width=16)
|
2020-03-23 09:17:01 -04:00
|
|
|
|
|
|
|
def test_converter_1to4(self):
|
2020-04-13 12:39:52 -04:00
|
|
|
# Verify 32-bit to 128-bit up-conversion.
|
2020-05-07 04:04:34 -04:00
|
|
|
self.converter_test(test_data="32bit_to_128bit", user_data_width=32, native_data_width=128)
|
2020-03-23 09:17:01 -04:00
|
|
|
|
|
|
|
def test_converter_1to8(self):
|
2020-04-13 12:39:52 -04:00
|
|
|
# Verify 32-bit to 256-bit up-conversion.
|
2020-05-07 04:04:34 -04:00
|
|
|
self.converter_test(test_data="32bit_to_256bit", user_data_width=32, native_data_width=256)
|
2020-03-23 09:17:01 -04:00
|
|
|
|
2020-05-11 10:44:50 -04:00
|
|
|
def test_up_converter_read_latencies(self):
|
2020-05-07 04:08:21 -04:00
|
|
|
# Verify that up-conversion works with different port reader latencies
|
|
|
|
cases = {
|
|
|
|
"1to2": dict(test_data="8bit_to_16bit", user_data_width=8, native_data_width=16),
|
|
|
|
"1to4": dict(test_data="32bit_to_128bit", user_data_width=32, native_data_width=128),
|
|
|
|
"1to8": dict(test_data="32bit_to_256bit", user_data_width=32, native_data_width=256),
|
|
|
|
}
|
|
|
|
for latency in [0, 1]:
|
|
|
|
with self.subTest(latency=latency):
|
|
|
|
for conversion, kwargs in cases.items():
|
|
|
|
with self.subTest(conversion=conversion):
|
|
|
|
self.converter_test(**kwargs, read_latency=latency)
|
|
|
|
|
2020-05-11 10:44:50 -04:00
|
|
|
def test_down_converter_read_latencies(self):
|
2020-05-07 04:08:21 -04:00
|
|
|
# Verify that down-conversion works with different port reader latencies
|
|
|
|
cases = {
|
|
|
|
"2to1": dict(test_data="64bit_to_32bit", user_data_width=64, native_data_width=32),
|
|
|
|
"4to1": dict(test_data="32bit_to_8bit", user_data_width=32, native_data_width=8),
|
|
|
|
"8to1": dict(test_data="64bit_to_8bit", user_data_width=64, native_data_width=8),
|
|
|
|
}
|
|
|
|
for latency in [0, 1]:
|
|
|
|
with self.subTest(latency=latency):
|
|
|
|
for conversion, kwargs in cases.items():
|
|
|
|
with self.subTest(conversion=conversion):
|
|
|
|
self.converter_test(**kwargs, read_latency=latency)
|
|
|
|
|
|
|
|
def test_up_converter_write_complete_sequence(self):
|
|
|
|
# Verify up-conversion when master sends full sequences (of `ratio` length)
|
|
|
|
def main_generator(dut):
|
|
|
|
yield from dut.write(0x00, 0x11) # first
|
|
|
|
yield from dut.write(0x01, 0x22)
|
|
|
|
yield from dut.write(0x02, 0x33)
|
|
|
|
yield from dut.write(0x03, 0x44)
|
|
|
|
yield from dut.write(0x04, 0x55) # second
|
|
|
|
yield from dut.write(0x05, 0x66)
|
|
|
|
yield from dut.write(0x06, 0x77)
|
|
|
|
yield from dut.write(0x07, 0x88)
|
|
|
|
|
|
|
|
yield from dut.write_driver.wait_all()
|
|
|
|
for _ in range(8): # wait for memory
|
|
|
|
yield
|
|
|
|
|
|
|
|
mem_expected = [
|
|
|
|
# data address
|
|
|
|
0x44332211, # 0x00
|
|
|
|
0x88776655, # 0x04
|
|
|
|
0x00000000, # 0x08
|
|
|
|
0x00000000, # 0x0c
|
|
|
|
]
|
|
|
|
|
2020-05-11 09:28:32 -04:00
|
|
|
for separate_rw in [True, False]:
|
2020-05-07 04:08:21 -04:00
|
|
|
with self.subTest(separate_rw=separate_rw):
|
|
|
|
dut = ConverterDUT(user_data_width=8, native_data_width=32,
|
|
|
|
mem_depth=len(mem_expected), separate_rw=separate_rw)
|
|
|
|
self.converter_readback_test(dut, pattern=[], mem_expected=mem_expected,
|
|
|
|
main_generator=main_generator)
|
|
|
|
|
|
|
|
def test_up_converter_write_with_manual_flush(self):
|
2020-05-11 09:28:32 -04:00
|
|
|
# Verify that up-conversion writes incomplete data when it receives cmd.last
|
2020-05-07 04:08:21 -04:00
|
|
|
def main_generator(dut):
|
|
|
|
yield from dut.write(0x00, 0x11, wait_data=False)
|
|
|
|
yield from dut.write(0x01, 0x22, wait_data=False)
|
2020-05-11 09:28:32 -04:00
|
|
|
yield from dut.write(0x02, 0x33, wait_data=False, last=1)
|
2020-05-07 04:08:21 -04:00
|
|
|
|
|
|
|
yield from dut.write_driver.wait_all()
|
|
|
|
for _ in range(8): # wait for memory
|
|
|
|
yield
|
|
|
|
|
|
|
|
mem_expected = [
|
|
|
|
# data address
|
|
|
|
0x00332211, # 0x00
|
|
|
|
0x00000000, # 0x04
|
|
|
|
0x00000000, # 0x08
|
|
|
|
0x00000000, # 0x0c
|
|
|
|
]
|
|
|
|
|
2020-05-11 09:28:32 -04:00
|
|
|
for separate_rw in [True, False]:
|
2020-05-07 04:08:21 -04:00
|
|
|
with self.subTest(separate_rw=separate_rw):
|
|
|
|
dut = ConverterDUT(user_data_width=8, native_data_width=32,
|
|
|
|
mem_depth=len(mem_expected), separate_rw=separate_rw)
|
|
|
|
self.converter_readback_test(dut, pattern=[], mem_expected=mem_expected,
|
|
|
|
main_generator=main_generator)
|
|
|
|
|
|
|
|
def test_up_converter_auto_flush_on_address_change(self):
|
|
|
|
# Verify that up-conversion automatically flushes the cmd if the (shifted) address changes
|
|
|
|
def main_generator(dut):
|
|
|
|
yield from dut.write(0x00, 0x11, wait_data=False) # -> 0x00
|
|
|
|
yield from dut.write(0x01, 0x22, wait_data=False) # -> 0x00
|
|
|
|
yield from dut.write(0x02, 0x33, wait_data=False) # -> 0x00
|
|
|
|
yield from dut.write(0x04, 0x55, wait_data=False) # -> 0x01
|
|
|
|
yield from dut.write(0x05, 0x66, wait_data=False) # -> 0x01
|
|
|
|
yield from dut.write(0x06, 0x77, wait_data=False) # -> 0x01
|
|
|
|
yield from dut.write(0x07, 0x88, wait_data=False) # -> 0x01
|
|
|
|
|
|
|
|
yield from dut.write_driver.wait_all()
|
|
|
|
for _ in range(8): # wait for memory
|
|
|
|
yield
|
|
|
|
|
|
|
|
mem_expected = [
|
|
|
|
# data address
|
|
|
|
0x00332211, # 0x00
|
|
|
|
0x88776655, # 0x04
|
|
|
|
0x00000000, # 0x08
|
|
|
|
0x00000000, # 0x0c
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2020-05-11 09:28:32 -04:00
|
|
|
for separate_rw in [True, False]:
|
2020-05-07 04:08:21 -04:00
|
|
|
with self.subTest(separate_rw=separate_rw):
|
|
|
|
dut = ConverterDUT(user_data_width=8, native_data_width=32,
|
|
|
|
mem_depth=len(mem_expected), separate_rw=separate_rw)
|
|
|
|
self.converter_readback_test(dut, pattern=[], mem_expected=mem_expected,
|
|
|
|
main_generator=main_generator)
|
|
|
|
|
|
|
|
def test_up_converter_auto_flush_on_cmd_we_change(self):
|
|
|
|
# Verify that up-conversion automatically flushes the cmd when command type (write/read) changes
|
|
|
|
def main_generator(dut):
|
|
|
|
yield from dut.write(0x00, 0x11, wait_data=False)
|
|
|
|
yield from dut.write(0x01, 0x22, wait_data=False)
|
2020-05-11 10:11:40 -04:00
|
|
|
yield from dut.read(0x00, wait_data=False)
|
|
|
|
yield from dut.read(0x01, wait_data=False)
|
|
|
|
yield from dut.read(0x02, wait_data=False)
|
|
|
|
yield from dut.read(0x03, wait_data=False)
|
2020-05-07 04:08:21 -04:00
|
|
|
|
|
|
|
yield from dut.write_driver.wait_all()
|
|
|
|
yield from dut.read_driver.wait_all()
|
|
|
|
for _ in range(8): # wait for memory
|
|
|
|
yield
|
|
|
|
|
|
|
|
mem_expected = [
|
|
|
|
# data address
|
2020-05-11 10:11:40 -04:00
|
|
|
0x00002211, # 0x00
|
|
|
|
0x00000000, # 0x04
|
2020-05-07 04:08:21 -04:00
|
|
|
0x00000000, # 0x08
|
|
|
|
0x00000000, # 0x0c
|
|
|
|
]
|
|
|
|
pattern = [
|
2020-05-11 10:11:40 -04:00
|
|
|
(0x00, 0x11),
|
|
|
|
(0x01, 0x22),
|
|
|
|
(0x02, 0x00),
|
|
|
|
(0x03, 0x00),
|
2020-05-07 04:08:21 -04:00
|
|
|
]
|
|
|
|
|
2020-05-11 10:11:40 -04:00
|
|
|
# with separate_rw=True we will fail because read will happen before write completes
|
|
|
|
dut = ConverterDUT(user_data_width=8, native_data_width=32,
|
|
|
|
mem_depth=len(mem_expected), separate_rw=False)
|
|
|
|
self.converter_readback_test(dut, pattern=pattern, mem_expected=mem_expected,
|
|
|
|
main_generator=main_generator)
|
2020-05-07 04:08:21 -04:00
|
|
|
|
|
|
|
def test_up_converter_write_with_gap(self):
|
|
|
|
# Verify that the up-converter can mask data properly when sending non-sequential writes
|
|
|
|
def main_generator(dut):
|
|
|
|
yield from dut.write(0x00, 0x11, wait_data=False)
|
|
|
|
yield from dut.write(0x02, 0x22, wait_data=False)
|
2020-05-11 09:28:32 -04:00
|
|
|
yield from dut.write(0x03, 0x33, wait_data=False, last=1)
|
2020-05-07 04:08:21 -04:00
|
|
|
|
|
|
|
yield from dut.write_driver.wait_all()
|
|
|
|
for _ in range(8): # wait for memory
|
|
|
|
yield
|
|
|
|
|
|
|
|
mem_expected = [
|
|
|
|
# data, address
|
|
|
|
0x33220011, # 0x00
|
|
|
|
0x00000000, # 0x04
|
|
|
|
0x00000000, # 0x08
|
|
|
|
0x00000000, # 0x0c
|
|
|
|
]
|
|
|
|
|
|
|
|
for separate_rw in [True, False]:
|
|
|
|
with self.subTest(separate_rw=separate_rw):
|
|
|
|
dut = ConverterDUT(user_data_width=8, native_data_width=32,
|
|
|
|
mem_depth=len(mem_expected), separate_rw=separate_rw)
|
|
|
|
self.converter_readback_test(dut, pattern=[], mem_expected=mem_expected,
|
|
|
|
main_generator=main_generator)
|
|
|
|
|
2020-05-11 10:44:50 -04:00
|
|
|
def test_up_converter_not_aligned(self):
|
2020-05-07 04:08:21 -04:00
|
|
|
data = self.pattern_test_data["8bit_to_32bit_not_aligned"]
|
|
|
|
dut = ConverterDUT(user_data_width=8, native_data_width=32,
|
|
|
|
mem_depth=len(data["expected"]), separate_rw=False)
|
|
|
|
self.converter_readback_test(dut, data["pattern"], data["expected"])
|
2020-03-24 06:55:24 -04:00
|
|
|
|
|
|
|
def cdc_readback_test(self, dut, pattern, mem_expected, clocks):
|
|
|
|
assert len(set(adr for adr, _ in pattern)) == len(pattern), "Pattern has duplicates!"
|
|
|
|
read_data = []
|
|
|
|
|
|
|
|
@passive
|
|
|
|
def read_handler(read_port):
|
|
|
|
yield read_port.rdata.ready.eq(1)
|
|
|
|
while True:
|
|
|
|
if (yield read_port.rdata.valid):
|
|
|
|
read_data.append((yield read_port.rdata.data))
|
|
|
|
yield
|
|
|
|
|
|
|
|
def main_generator(dut, pattern):
|
|
|
|
for adr, data in pattern:
|
2020-03-24 07:04:53 -04:00
|
|
|
yield from dut.write(adr, data)
|
2020-03-24 06:55:24 -04:00
|
|
|
|
|
|
|
for adr, _ in pattern:
|
2020-05-07 04:08:21 -04:00
|
|
|
yield from dut.read(adr, wait_data=False)
|
2020-03-24 06:55:24 -04:00
|
|
|
|
2020-05-07 04:08:21 -04:00
|
|
|
yield from dut.write_driver.wait_all()
|
|
|
|
yield from dut.read_driver.wait_all()
|
2020-03-24 06:55:24 -04:00
|
|
|
|
|
|
|
generators = {
|
|
|
|
"user": [
|
|
|
|
main_generator(dut, pattern),
|
|
|
|
read_handler(dut.read_user_port),
|
2020-05-07 04:08:21 -04:00
|
|
|
*dut.driver_generators,
|
2020-03-24 06:55:24 -04:00
|
|
|
timeout_generator(5000),
|
|
|
|
],
|
|
|
|
"native": [
|
|
|
|
dut.memory.write_handler(dut.write_crossbar_port),
|
|
|
|
dut.memory.read_handler(dut.read_crossbar_port),
|
|
|
|
],
|
|
|
|
}
|
|
|
|
run_simulation(dut, generators, clocks)
|
|
|
|
self.assertEqual(dut.memory.mem, mem_expected)
|
|
|
|
self.assertEqual(read_data, [data for adr, data in pattern])
|
|
|
|
|
|
|
|
def test_port_cdc_same_clocks(self):
|
2020-04-13 12:39:52 -04:00
|
|
|
# Verify CDC with same clocks (frequency and phase).
|
2020-03-24 06:55:24 -04:00
|
|
|
data = self.pattern_test_data["32bit"]
|
2020-04-13 12:39:52 -04:00
|
|
|
dut = CDCDUT(user_data_width=32, native_data_width=32, mem_depth=len(data["expected"]))
|
2020-03-24 06:55:24 -04:00
|
|
|
clocks = {
|
|
|
|
"user": 10,
|
|
|
|
"native": (7, 3),
|
|
|
|
}
|
|
|
|
self.cdc_readback_test(dut, data["pattern"], data["expected"], clocks=clocks)
|
|
|
|
|
|
|
|
def test_port_cdc_different_period(self):
|
2020-04-13 12:39:52 -04:00
|
|
|
# Verify CDC with different clock frequencies.
|
2020-03-24 06:55:24 -04:00
|
|
|
data = self.pattern_test_data["32bit"]
|
2020-04-13 12:39:52 -04:00
|
|
|
dut = CDCDUT(user_data_width=32, native_data_width=32, mem_depth=len(data["expected"]))
|
2020-03-24 06:55:24 -04:00
|
|
|
clocks = {
|
|
|
|
"user": 10,
|
|
|
|
"native": 7,
|
|
|
|
}
|
|
|
|
self.cdc_readback_test(dut, data["pattern"], data["expected"], clocks=clocks)
|
|
|
|
|
|
|
|
def test_port_cdc_out_of_phase(self):
|
2020-04-13 12:39:52 -04:00
|
|
|
# Verify CDC with different clock phases.
|
2020-03-24 06:55:24 -04:00
|
|
|
data = self.pattern_test_data["32bit"]
|
2020-04-13 12:39:52 -04:00
|
|
|
dut = CDCDUT(user_data_width=32, native_data_width=32, mem_depth=len(data["expected"]))
|
2020-03-24 06:55:24 -04:00
|
|
|
clocks = {
|
|
|
|
"user": 10,
|
|
|
|
"native": (7, 3),
|
|
|
|
}
|
|
|
|
self.cdc_readback_test(dut, data["pattern"], data["expected"], clocks=clocks)
|