105 lines
4.6 KiB
Python
105 lines
4.6 KiB
Python
# This file is Copyright (c) 2018-2019 Florent Kermarrec <florent@enjoy-digital.fr>
|
|
# This file is Copyright (c) 2020 Antmicro <www.antmicro.com>
|
|
# 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
|
|
|
|
from test.common import DRAMMemory, MemoryTestDataMixin
|
|
|
|
|
|
class TestWishbone(MemoryTestDataMixin, unittest.TestCase):
|
|
def test_wishbone_data_width_not_smaller(self):
|
|
with self.assertRaises(AssertionError):
|
|
wb = wishbone.Interface(data_width=32)
|
|
port = LiteDRAMNativePort("both", address_width=32, data_width=wb.data_width * 2)
|
|
LiteDRAMWishbone2Native(wb, port)
|
|
|
|
def wishbone_readback_test(self, pattern, mem_expected, wishbone, port, base_address=0):
|
|
class DUT(Module):
|
|
def __init__(self):
|
|
self.port = port
|
|
self.wb = wishbone
|
|
self.submodules += LiteDRAMWishbone2Native(self.wb, self.port,
|
|
base_address=base_address)
|
|
self.mem = DRAMMemory(port.data_width, len(mem_expected))
|
|
|
|
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),
|
|
]
|
|
run_simulation(dut, generators)
|
|
self.assertEqual(dut.mem.mem, mem_expected)
|
|
|
|
def test_wishbone_8bit(self):
|
|
data = self.pattern_test_data["8bit"]
|
|
wb = wishbone.Interface(adr_width=30, data_width=8)
|
|
port = LiteDRAMNativePort("both", address_width=30, data_width=8)
|
|
self.wishbone_readback_test(data["pattern"], data["expected"], wb, port)
|
|
|
|
def test_wishbone_32bit(self):
|
|
data = self.pattern_test_data["32bit"]
|
|
wb = wishbone.Interface(adr_width=30, data_width=32)
|
|
port = LiteDRAMNativePort("both", address_width=30, data_width=32)
|
|
self.wishbone_readback_test(data["pattern"], data["expected"], wb, port)
|
|
|
|
def test_wishbone_64bit(self):
|
|
data = self.pattern_test_data["64bit"]
|
|
wb = wishbone.Interface(adr_width=30, data_width=64)
|
|
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):
|
|
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)
|
|
self.wishbone_readback_test(data["pattern"], data["expected"], wb, port)
|
|
|
|
def test_wishbone_32bit_to_8bit(self):
|
|
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)
|
|
self.wishbone_readback_test(data["pattern"], data["expected"], wb, port)
|
|
|
|
def test_wishbone_32bit_base_address(self):
|
|
data = self.pattern_test_data["32bit"]
|
|
wb = wishbone.Interface(adr_width=30, data_width=32)
|
|
port = LiteDRAMNativePort("both", address_width=30, data_width=32)
|
|
origin = 0x10000000
|
|
# add offset (in data words)
|
|
pattern = [(adr + origin//(32//8), data) for adr, data in data["pattern"]]
|
|
self.wishbone_readback_test(pattern, data["expected"], wb, port,
|
|
base_address=origin)
|
|
|
|
def test_wishbone_64bit_to_32bit_base_address(self):
|
|
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
|
|
pattern = [(adr + origin//(64//8), data) for adr, data in data["pattern"]]
|
|
self.wishbone_readback_test(pattern, data["expected"], wb, port,
|
|
base_address=origin)
|
|
|
|
def test_wishbone_32bit_to_8bit_base_address(self):
|
|
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
|
|
pattern = [(adr + origin//(32//8), data) for adr, data in data["pattern"]]
|
|
self.wishbone_readback_test(pattern, data["expected"], wb, port,
|
|
base_address=origin)
|