From 6ef96b17bca5e7be7fbbf5cc32d8866739f80b19 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Mon, 21 Mar 2022 15:21:08 +0100 Subject: [PATCH] soc/interconnect/csr: Fix CSRConstant read method (And add test_csr_constant to test_csr). --- litex/soc/interconnect/csr.py | 1 + test/test_csr.py | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/litex/soc/interconnect/csr.py b/litex/soc/interconnect/csr.py index ab1730a0e..1beaac0ff 100644 --- a/litex/soc/interconnect/csr.py +++ b/litex/soc/interconnect/csr.py @@ -68,6 +68,7 @@ class CSRConstant(DUID): def read(self): """Read method for simulation.""" + yield return self.value.value # CSR ---------------------------------------------------------------------------------------------- diff --git a/test/test_csr.py b/test/test_csr.py index 1fe1d5547..e426a1a7d 100644 --- a/test/test_csr.py +++ b/test/test_csr.py @@ -26,9 +26,10 @@ def csr32_read(dut, adr): class CSRModule(Module, csr.AutoCSR): def __init__(self): - self._csr = csr.CSR() - self._storage = csr.CSRStorage(32, reset=0x12345678, write_from_dev=True) - self._status = csr.CSRStatus(32, reset=0x12345678) + self._csr = csr.CSR() + self._constant = csr.CSRConstant(0x12345678) + self._storage = csr.CSRStorage(32, reset=0x12345678, write_from_dev=True) + self._status = csr.CSRStatus(32, reset=0x12345678) # # # @@ -61,6 +62,13 @@ class CSRDUT(Module): self.csr, self.csrbankarray.get_buses()) class TestCSR(unittest.TestCase): + def test_csr_constant(self): + def generator(dut): + self.assertEqual(hex((yield from dut.csrmodule._constant.read())), hex(0x12345678)) + + dut = CSRDUT() + run_simulation(dut, generator(dut)) + def test_csr_storage(self): def generator(dut): # check init value