Provide csr_data_width via the constants.
authorTim 'mithro' Ansell <mithro@mithis.com>
Fri, 16 Dec 2016 14:41:15 +0000 (15:41 +0100)
committerTim 'mithro' Ansell <mithro@mithis.com>
Sat, 17 Dec 2016 13:14:53 +0000 (14:14 +0100)
litex/soc/integration/soc_core.py
litex/soc/tools/remote/comm_udp.py
litex/soc/tools/remote/csr_builder.py
litex/soc/tools/remote/litex_client.py

index 66dec8587a6f5cf4ee504c3a0607a97cb4b89601..8e3f7a2247ee43ab778207cb6945a635479a9c17 100644 (file)
@@ -98,6 +98,7 @@ class SoCCore(Module):
 
         self.submodules.wishbone2csr = wishbone2csr.WB2CSR(
             bus_csr=csr_bus.Interface(csr_data_width, csr_address_width))
+        self.add_constant("CSR_DATA_WIDTH", csr_data_width)
         self.register_mem("csr", self.mem_map["csr"], self.wishbone2csr.wishbone)
 
         if with_uart:
index b4624b3701b06d26895b9c3f000c2ad6cd3bfdfa..10179128f9656a60e0dc253f07ee3dcc136f6189 100644 (file)
@@ -5,7 +5,7 @@ from litex.soc.tools.remote.etherbone import EtherboneReads, EtherboneWrites
 from litex.soc.tools.remote.csr_builder import CSRBuilder
 
 class CommUDP(CSRBuilder):
-    def __init__(self, server="192.168.1.50", port=1234, csr_csv="csr.csv", csr_data_width=32, debug=False):
+    def __init__(self, server="192.168.1.50", port=1234, csr_csv="csr.csv", csr_data_width=None, debug=False):
         if csr_csv is not None:
             CSRBuilder.__init__(self, self, csr_csv, csr_data_width)
         self.server = server
index e30a18ad6be92a9757a8bc7062eca8649df0f637..fa170ea595c62079a44c7b829fe710733e9a867b 100644 (file)
@@ -52,9 +52,20 @@ class CSRMemoryRegion:
 
 
 class CSRBuilder:
-    def __init__(self, comm, csr_csv, csr_data_width):
-        self.csr_data_width = csr_data_width
+    def __init__(self, comm, csr_csv, csr_data_width=None):
         self.constants = self.build_constants(csr_csv)
+
+        # Load csr_data_width from the constants, otherwise it must be provided
+        constant_csr_data_width = self.constants.d.get('csr_data_width', None)
+        if csr_data_width is None:
+            csr_data_width = constant_csr_data_width
+        if csr_data_width is None:
+            raise KeyError('csr_data_width not found in constants, please provide!')
+        if csr_data_width != constant_csr_data_width:
+            raise KeyError('csr_data_width of {} provided but {} found in constants'.format(
+                csr_data_width, constant_csr_data_width))
+
+        self.csr_data_width = csr_data_width
         self.bases = self.build_bases(csr_csv)
         self.regs = self.build_registers(csr_csv, comm.read, comm.write)
         self.mems = self.build_memories(csr_csv)
index d8b3f0ff05d606f654457775647c64afda84a638..bddbbe7f3f04d536995f7950e9d7edd7190aff93 100644 (file)
@@ -7,9 +7,11 @@ from litex.soc.tools.remote.csr_builder import CSRBuilder
 
 
 class RemoteClient(EtherboneIPC, CSRBuilder):
-    def __init__(self, host="localhost", port=1234, csr_csv="csr.csv", csr_data_width=32, debug=False):
+    def __init__(self, host="localhost", port=1234, csr_csv="csr.csv", csr_data_width=None, debug=False):
         if csr_csv is not None:
             CSRBuilder.__init__(self, self, csr_csv, csr_data_width)
+        else:
+            assert csr_data_width is not None
         self.host = host
         self.port = port
         self.debug = debug