build: add Inverted property to IOs to ease inverting signals and propagate property...
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Sat, 6 Jan 2018 00:33:02 +0000 (01:33 +0100)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Sat, 6 Jan 2018 00:33:02 +0000 (01:33 +0100)
litex/build/generic_platform.py
litex/build/xilinx/vivado.py

index 226bc9a431de25c2deedb2725b5556b98eea9528..1ab5935e586e68fa31dc2b7e98e067ada9b19651 100644 (file)
@@ -49,6 +49,12 @@ class Misc:
         return "{}({})".format(self.__class__.__name__, repr(self.misc))
 
 
+class Inverted:
+    def __repr__(self):
+        return "{}()".format(self.__class__.__name__)
+
+
+
 class Subsignal:
     def __init__(self, name, *constraints):
         self.name = name
@@ -78,6 +84,7 @@ def _lookup(description, name, number):
 
 def _resource_type(resource):
     t = None
+    i = None
     for element in resource[2:]:
         if isinstance(element, Pins):
             assert(t is None)
@@ -85,17 +92,23 @@ def _resource_type(resource):
         elif isinstance(element, Subsignal):
             if t is None:
                 t = []
+            if i is None:
+                i = []
 
             assert(isinstance(t, list))
             n_bits = None
+            inverted = False
             for c in element.constraints:
                 if isinstance(c, Pins):
                     assert(n_bits is None)
                     n_bits = len(c.identifiers)
+                if isinstance(c, Inverted):
+                    inverted = True
 
             t.append((element.name, n_bits))
+            i.append((element.name, inverted))
 
-    return t
+    return t, i
 
 
 class ConnectorManager:
@@ -160,7 +173,7 @@ class ConstraintManager:
 
     def request(self, name, number=None):
         resource = _lookup(self.available, name, number)
-        rt = _resource_type(resource)
+        rt, ri = _resource_type(resource)
         if number is None:
             resource_name = name
         else:
@@ -169,8 +182,14 @@ class ConstraintManager:
             obj = Signal(rt, name_override=resource_name)
         else:
             obj = Record(rt, name=resource_name)
+            for name, inverted in ri:
+                if inverted:
+                    getattr(obj, name).inverted = True
 
         for element in resource[2:]:
+            if isinstance(element, Inverted):
+                if isinstance(obj, Signal):
+                    obj.inverted = True
             if isinstance(element, PlatformInfo):
                 obj.platform_info = element.info
                 break
index b626328edb28faad5930808a4c47ad458eff3818..4b9fedfa1a7a5f9b0f2f5adc8a395da7d6ca58b1 100644 (file)
@@ -20,6 +20,8 @@ def _format_constraint(c):
         return "set_property DRIVE " + str(c.strength)
     elif isinstance(c, Misc):
         return "set_property " + c.misc.replace("=", " ")
+    elif isinstance(c, Inverted):
+        return ""
     else:
         raise ValueError("unknown constraint {}".format(c))