csr/fields: add access parameter
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Sat, 14 Sep 2019 19:57:23 +0000 (21:57 +0200)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Sat, 14 Sep 2019 20:16:18 +0000 (22:16 +0200)
litex/soc/interconnect/csr.py

index e7713f72d518596f7c9b9e912711ae69ab88bea8..0723bc83f599acca8ecc0bc55cf8363d79ab5dd1 100644 (file)
@@ -123,24 +123,32 @@ class _CompoundCSR(_CSRBase, Module):
 
 
 class CSRField(Signal):
-    def __init__(self, name, size=1, offset=None, reset=0, description=None, pulse=False, values=None):
+    def __init__(self, name, size=1, offset=None, reset=0, description=None, pulse=False, access=None, values=None):
         assert name == name.lower()
+        assert access in [None, "write-only", "read-only", "read-write"]
         self.name        = name
         self.size        = size
         self.offset      = offset
         self.reset_value = reset
         self.description = description
+        self.access      = access
         self.pulse       = pulse
         self.values      = values
         Signal.__init__(self, size, name=name, reset=reset)
 
 
 class CSRFieldCompound:
-    def __init__(self, fields):
+    def __init__(self, fields, access):
         self.check_names(fields)
         self.check_ordering_overlap(fields)
         self.fields = fields
         for field in fields:
+            if field.access is None:
+                field.access = access
+            elif access == "read-only":
+                assert field.access == "read-only"
+            elif access == "read-write":
+                assert field.access in ["read-write", "write-only"]
             setattr(self, field.name, field)
 
     @staticmethod
@@ -210,7 +218,7 @@ class CSRStatus(_CompoundCSR):
 
     def __init__(self, size=1, reset=0, fields=[], name=None, description=None):
         if fields != []:
-            self.fields = CSRFieldCompound(fields)
+            self.fields = CSRFieldCompound(fields, "read-only")
             size  = self.fields.get_size()
             reset = self.fields.get_reset()
         _CompoundCSR.__init__(self, size, name)
@@ -287,7 +295,7 @@ class CSRStorage(_CompoundCSR):
 
     def __init__(self, size=1, reset=0, fields=[], atomic_write=False, write_from_dev=False, alignment_bits=0, name=None, description=None):
         if fields != []:
-            self.fields = CSRFieldCompound(fields)
+            self.fields = CSRFieldCompound(fields, "read-write")
             size  = self.fields.get_size()
             reset = self.fields.get_reset()
         _CompoundCSR.__init__(self, size, name)