2020-08-23 09:52:08 -04:00
|
|
|
#
|
|
|
|
# This file is part of LiteDRAM.
|
|
|
|
#
|
|
|
|
# Copyright (c) 2019 Florent Kermarrec <florent@enjoy-digital.fr>
|
|
|
|
# SPDX-License-Identifier: BSD-2-Clause
|
2019-09-09 05:42:30 -04:00
|
|
|
|
|
|
|
import os
|
2021-01-19 07:50:37 -05:00
|
|
|
import difflib
|
2019-09-09 05:42:30 -04:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
from litedram.init import get_sdram_phy_c_header, get_sdram_phy_py_header
|
|
|
|
|
|
|
|
|
2021-01-19 07:50:37 -05:00
|
|
|
def compare_with_reference(test_case, content, filename):
|
|
|
|
ref_filename = os.path.join("test", "reference", filename)
|
|
|
|
with open(ref_filename, "r") as f:
|
|
|
|
reference = f.read().split("\n")
|
|
|
|
content = content.split("\n")
|
|
|
|
diff = list(difflib.unified_diff(content, reference, fromfile=filename, tofile=ref_filename))
|
|
|
|
msg = "Unified diff:\n" + "\n".join(diff)
|
|
|
|
test_case.assertEqual(len(diff), 0, msg=msg)
|
2019-09-09 05:42:30 -04:00
|
|
|
|
2021-05-18 05:26:19 -04:00
|
|
|
def update_c_reference(content, filename):
|
|
|
|
f = open(os.path.join("test", "reference", filename), "w")
|
|
|
|
f.write(content)
|
|
|
|
f.close()
|
2019-09-09 05:42:30 -04:00
|
|
|
|
|
|
|
class TestInit(unittest.TestCase):
|
|
|
|
def test_sdr(self):
|
2022-05-10 04:38:55 -04:00
|
|
|
from litex_boards.targets.scarabhardware_minispartan6 import BaseSoC
|
2020-04-13 13:38:29 -04:00
|
|
|
soc = BaseSoC()
|
2023-01-10 08:45:19 -05:00
|
|
|
c_header = get_sdram_phy_c_header(
|
|
|
|
phy_settings = soc.sdram.controller.settings.phy,
|
|
|
|
timing_settings = soc.sdram.controller.settings.timing,
|
|
|
|
geom_settings = soc.sdram.controller.settings.geom,
|
|
|
|
)
|
|
|
|
py_header = get_sdram_phy_py_header(
|
|
|
|
phy_settings = soc.sdram.controller.settings.phy,
|
|
|
|
timing_settings = soc.sdram.controller.settings.timing
|
|
|
|
)
|
2021-05-18 05:26:19 -04:00
|
|
|
#update_c_reference(c_header, "sdr_init.h")
|
2021-01-19 07:50:37 -05:00
|
|
|
compare_with_reference(self, c_header, "sdr_init.h")
|
|
|
|
compare_with_reference(self, py_header, "sdr_init.py")
|
2019-09-09 05:42:30 -04:00
|
|
|
|
|
|
|
def test_ddr3(self):
|
2022-05-10 04:38:55 -04:00
|
|
|
from litex_boards.targets.xilinx_kc705 import BaseSoC
|
2020-04-13 13:38:29 -04:00
|
|
|
soc = BaseSoC()
|
2023-01-10 08:45:19 -05:00
|
|
|
c_header = get_sdram_phy_c_header(
|
|
|
|
phy_settings = soc.sdram.controller.settings.phy,
|
|
|
|
timing_settings = soc.sdram.controller.settings.timing,
|
|
|
|
geom_settings = soc.sdram.controller.settings.geom,
|
|
|
|
)
|
|
|
|
py_header = get_sdram_phy_py_header(
|
|
|
|
phy_settings = soc.sdram.controller.settings.phy,
|
|
|
|
timing_settings = soc.sdram.controller.settings.timing
|
|
|
|
)
|
2021-05-18 05:26:19 -04:00
|
|
|
#update_c_reference(c_header, "ddr3_init.h")
|
2021-01-19 07:50:37 -05:00
|
|
|
compare_with_reference(self, c_header, "ddr3_init.h")
|
|
|
|
compare_with_reference(self, py_header, "ddr3_init.py")
|
2019-09-09 05:42:30 -04:00
|
|
|
|
|
|
|
def test_ddr4(self):
|
2022-05-10 04:38:55 -04:00
|
|
|
from litex_boards.targets.xilinx_kcu105 import BaseSoC
|
2020-04-13 13:38:29 -04:00
|
|
|
soc = BaseSoC(max_sdram_size=0x4000000)
|
2023-01-10 08:45:19 -05:00
|
|
|
c_header = get_sdram_phy_c_header(
|
|
|
|
phy_settings = soc.sdram.controller.settings.phy,
|
|
|
|
timing_settings = soc.sdram.controller.settings.timing,
|
|
|
|
geom_settings = soc.sdram.controller.settings.geom,
|
|
|
|
)
|
|
|
|
py_header = get_sdram_phy_py_header(
|
|
|
|
phy_settings = soc.sdram.controller.settings.phy,
|
|
|
|
timing_settings = soc.sdram.controller.settings.timing
|
|
|
|
)
|
2021-05-18 05:26:19 -04:00
|
|
|
#update_c_reference(c_header, "ddr4_init.h")
|
2021-01-19 07:50:37 -05:00
|
|
|
compare_with_reference(self, c_header, "ddr4_init.h")
|
|
|
|
compare_with_reference(self, py_header, "ddr4_init.py")
|