2020-03-19 10:59:39 -04:00
|
|
|
# This file is Copyright (c) 2018-2019 Florent Kermarrec <florent@enjoy-digital.fr>
|
2020-04-13 13:38:29 -04:00
|
|
|
# This file is Copyright (c) 2020 Antmicro <www.antmicro.com>
|
2020-03-19 10:59:39 -04:00
|
|
|
# License: BSD
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
from migen import *
|
|
|
|
from litex.gen.sim import run_simulation
|
|
|
|
from litex.soc.interconnect import wishbone
|
|
|
|
|
|
|
|
from litedram.frontend.wishbone import LiteDRAMWishbone2Native
|
|
|
|
from litedram.common import LiteDRAMNativePort
|
|
|
|
|
2020-03-20 09:15:33 -04:00
|
|
|
from test.common import DRAMMemory, MemoryTestDataMixin
|
2020-03-19 10:59:39 -04:00
|
|
|
|
|
|
|
|
2020-03-20 09:15:33 -04:00
|
|
|
class TestWishbone(MemoryTestDataMixin, unittest.TestCase):
|
|
|
|
def wishbone_readback_test(self, pattern, mem_expected, wishbone, port, base_address=0):
|
2020-03-19 10:59:39 -04:00
|
|
|
class DUT(Module):
|
|
|
|
def __init__(self):
|
|
|
|
self.port = port
|
2020-04-13 13:38:29 -04:00
|
|
|
self.wb = wishbone
|
2020-04-14 15:48:44 -04:00
|
|
|
self.submodules += LiteDRAMWishbone2Native(
|
|
|
|
wishbone = self.wb,
|
|
|
|
port = self.port,
|
|
|
|
base_address = base_address)
|
2020-03-20 09:15:33 -04:00
|
|
|
self.mem = DRAMMemory(port.data_width, len(mem_expected))
|
2020-03-19 10:59:39 -04:00
|
|
|
|
|
|
|
def main_generator(dut):
|
|
|
|
for adr, data in pattern:
|
|
|
|
yield from dut.wb.write(adr, data)
|
|
|
|
data_r = (yield from dut.wb.read(adr))
|
|
|
|
self.assertEqual(data_r, data)
|
|
|
|
|
|
|
|
dut = DUT()
|
|
|
|
generators = [
|
|
|
|
main_generator(dut),
|
|
|
|
dut.mem.write_handler(dut.port),
|
|
|
|
dut.mem.read_handler(dut.port),
|
|
|
|
]
|
2020-05-07 04:08:21 -04:00
|
|
|
run_simulation(dut, generators, vcd_name='sim.vcd')
|
2020-03-19 10:59:39 -04:00
|
|
|
self.assertEqual(dut.mem.mem, mem_expected)
|
|
|
|
|
2020-03-20 09:15:33 -04:00
|
|
|
def test_wishbone_8bit(self):
|
2020-04-14 15:48:44 -04:00
|
|
|
# Verify Wishbone with 8-bit data width.
|
2020-03-20 09:15:33 -04:00
|
|
|
data = self.pattern_test_data["8bit"]
|
2020-04-13 13:38:29 -04:00
|
|
|
wb = wishbone.Interface(adr_width=30, data_width=8)
|
2020-03-20 09:15:33 -04:00
|
|
|
port = LiteDRAMNativePort("both", address_width=30, data_width=8)
|
|
|
|
self.wishbone_readback_test(data["pattern"], data["expected"], wb, port)
|
|
|
|
|
|
|
|
def test_wishbone_32bit(self):
|
2020-04-14 15:48:44 -04:00
|
|
|
# Verify Wishbone with 32-bit data width.
|
2020-03-20 09:15:33 -04:00
|
|
|
data = self.pattern_test_data["32bit"]
|
2020-04-13 13:38:29 -04:00
|
|
|
wb = wishbone.Interface(adr_width=30, data_width=32)
|
2020-03-20 09:15:33 -04:00
|
|
|
port = LiteDRAMNativePort("both", address_width=30, data_width=32)
|
|
|
|
self.wishbone_readback_test(data["pattern"], data["expected"], wb, port)
|
|
|
|
|
|
|
|
def test_wishbone_64bit(self):
|
2020-04-14 15:48:44 -04:00
|
|
|
# Verify Wishbone with 64-bit data width.
|
2020-03-20 09:15:33 -04:00
|
|
|
data = self.pattern_test_data["64bit"]
|
2020-04-13 13:38:29 -04:00
|
|
|
wb = wishbone.Interface(adr_width=30, data_width=64)
|
2020-03-20 09:15:33 -04:00
|
|
|
port = LiteDRAMNativePort("both", address_width=30, data_width=64)
|
|
|
|
self.wishbone_readback_test(data["pattern"], data["expected"], wb, port)
|
|
|
|
|
|
|
|
def test_wishbone_64bit_to_32bit(self):
|
2020-04-14 15:48:44 -04:00
|
|
|
# Verify Wishbone with 64-bit data width down-converted to 32-bit data width.
|
2020-03-20 09:15:33 -04:00
|
|
|
data = self.pattern_test_data["64bit_to_32bit"]
|
2020-04-13 13:38:29 -04:00
|
|
|
wb = wishbone.Interface(adr_width=30, data_width=64)
|
2020-03-19 10:59:39 -04:00
|
|
|
port = LiteDRAMNativePort("both", address_width=30, data_width=32)
|
2020-03-20 09:15:33 -04:00
|
|
|
self.wishbone_readback_test(data["pattern"], data["expected"], wb, port)
|
|
|
|
|
|
|
|
def test_wishbone_32bit_to_8bit(self):
|
2020-04-14 15:48:44 -04:00
|
|
|
# Verify Wishbone with 32-bit data width down-converted to 8-bit data width.
|
2020-03-20 09:15:33 -04:00
|
|
|
data = self.pattern_test_data["32bit_to_8bit"]
|
2020-04-13 13:38:29 -04:00
|
|
|
wb = wishbone.Interface(adr_width=30, data_width=32)
|
2020-03-20 09:15:33 -04:00
|
|
|
port = LiteDRAMNativePort("both", address_width=30, data_width=8)
|
|
|
|
self.wishbone_readback_test(data["pattern"], data["expected"], wb, port)
|
|
|
|
|
2020-05-13 06:45:46 -04:00
|
|
|
def test_wishbone_8bit_to_32bit(self):
|
|
|
|
# Verify Wishbone with 8-bit data width up-converted to 32-bit data width.
|
|
|
|
data = self.pattern_test_data["8bit_to_32bit"]
|
|
|
|
wb = wishbone.Interface(adr_width=30, data_width=8)
|
|
|
|
port = LiteDRAMNativePort("both", address_width=30, data_width=32)
|
|
|
|
self.wishbone_readback_test(data["pattern"], data["expected"], wb, port)
|
|
|
|
|
|
|
|
def test_wishbone_32bit_to_64bit(self):
|
|
|
|
# Verify Wishbone with 32-bit data width up-converted to 64-bit data width.
|
|
|
|
data = self.pattern_test_data["32bit_to_64bit"]
|
|
|
|
wb = wishbone.Interface(adr_width=30, data_width=32)
|
|
|
|
port = LiteDRAMNativePort("both", address_width=30, data_width=64)
|
|
|
|
self.wishbone_readback_test(data["pattern"], data["expected"], wb, port)
|
|
|
|
|
2020-03-20 09:15:33 -04:00
|
|
|
def test_wishbone_32bit_base_address(self):
|
2020-04-14 15:48:44 -04:00
|
|
|
# Verify Wishbone with 32-bit data width and non-zero base address.
|
2020-04-13 13:38:29 -04:00
|
|
|
data = self.pattern_test_data["32bit"]
|
|
|
|
wb = wishbone.Interface(adr_width=30, data_width=32)
|
|
|
|
port = LiteDRAMNativePort("both", address_width=30, data_width=32)
|
2020-03-20 09:15:33 -04:00
|
|
|
origin = 0x10000000
|
|
|
|
# add offset (in data words)
|
|
|
|
pattern = [(adr + origin//(32//8), data) for adr, data in data["pattern"]]
|
2020-04-14 15:48:44 -04:00
|
|
|
self.wishbone_readback_test(pattern, data["expected"], wb, port, base_address=origin)
|
2020-03-20 09:15:33 -04:00
|
|
|
|
|
|
|
def test_wishbone_64bit_to_32bit_base_address(self):
|
2020-04-14 15:48:44 -04:00
|
|
|
# Verify Wishbone with 64-bit data width down-converted to 32-bit data width and non-zero base address.
|
2020-04-13 13:38:29 -04:00
|
|
|
data = self.pattern_test_data["64bit_to_32bit"]
|
|
|
|
wb = wishbone.Interface(adr_width=30, data_width=64)
|
|
|
|
port = LiteDRAMNativePort("both", address_width=30, data_width=32)
|
|
|
|
origin = 0x10000000
|
2020-03-20 09:15:33 -04:00
|
|
|
pattern = [(adr + origin//(64//8), data) for adr, data in data["pattern"]]
|
2020-04-14 15:48:44 -04:00
|
|
|
self.wishbone_readback_test(pattern, data["expected"], wb, port, base_address=origin)
|
2020-03-20 09:15:33 -04:00
|
|
|
|
|
|
|
def test_wishbone_32bit_to_8bit_base_address(self):
|
2020-04-14 15:48:44 -04:00
|
|
|
# Verify Wishbone with 32-bit data width down-converted to 8-bit data width and non-zero base address.
|
2020-04-13 13:38:29 -04:00
|
|
|
data = self.pattern_test_data["32bit_to_8bit"]
|
|
|
|
wb = wishbone.Interface(adr_width=30, data_width=32)
|
|
|
|
port = LiteDRAMNativePort("both", address_width=30, data_width=8)
|
|
|
|
origin = 0x10000000
|
2020-03-20 09:15:33 -04:00
|
|
|
pattern = [(adr + origin//(32//8), data) for adr, data in data["pattern"]]
|
2020-04-14 15:48:44 -04:00
|
|
|
self.wishbone_readback_test(pattern, data["expected"], wb, port, base_address=origin)
|