build/platform: allow doing a loose lookup_request (return None instead of Constraint...
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Tue, 5 May 2020 09:23:46 +0000 (11:23 +0200)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Tue, 5 May 2020 09:23:46 +0000 (11:23 +0200)
In the platforms, insead of doing:
self.lookup_request("eth_clocks").rx
we can now do:
self.lookup_request("eth_clocks:rx")

This allows some try/except simplifications on constraints.

litex/build/altera/platform.py
litex/build/generic_platform.py
litex/build/lattice/platform.py
litex/build/microsemi/platform.py
litex/build/xilinx/platform.py

index a95dcf4b9a04da9072e455c01418582f1fcff7a3..2f03fc720a62e5bdf61975f1666da0993a496726 100644 (file)
@@ -33,6 +33,7 @@ class AlteraPlatform(GenericPlatform):
         return self.toolchain.build(self, *args, **kwargs)
 
     def add_period_constraint(self, clk, period):
+        if clk is None: return
         if hasattr(clk, "p"):
             clk = clk.p
         self.toolchain.add_period_constraint(self, clk, period)
index d540cc38a4e533c9d763bc6cf5a9fd25a0b6f643..7c489efea0d88d2065c1d95c374c907da49afbae 100644 (file)
@@ -205,13 +205,21 @@ class ConstraintManager:
         self.matched.append((resource, obj))
         return obj
 
-    def lookup_request(self, name, number=None):
+    def lookup_request(self, name, number=None, loose=False):
+        subname = None
+        if ":" in name: name, subname = name.split(":")
         for resource, obj in self.matched:
             if resource[0] == name and (number is None or
                                         resource[1] == number):
-                return obj
+                if subname is not None:
+                    return getattr(obj, subname)
+                else:
+                    return obj
 
-        raise ConstraintError("Resource not found: {}:{}".format(name, number))
+        if loose:
+            return None
+        else:
+            raise ConstraintError("Resource not found: {}:{}".format(name, number))
 
     def add_platform_command(self, command, **signals):
         self.platform_commands.append((command, signals))
index 71ff2a653533ce8e196298f1457441e4554d0939..7380b45e063f9928845aa1489aa25e0679e07dbf 100644 (file)
@@ -34,6 +34,7 @@ class LatticePlatform(GenericPlatform):
         return self.toolchain.build(self, *args, **kwargs)
 
     def add_period_constraint(self, clk, period):
+        if clk is None: return
         if hasattr(clk, "p"):
             clk = clk.p
         self.toolchain.add_period_constraint(self, clk, period)
index 65d2c996d55ccc0b9f4c771f2d4d43f459aad9ad..c8f13bd8903d2a16ec7bb6a3469b8d6a9e2f2304 100644 (file)
@@ -28,6 +28,7 @@ class MicrosemiPlatform(GenericPlatform):
         return self.toolchain.build(self, *args, **kwargs)
 
     def add_period_constraint(self, clk, period):
+        if clk is None: return
         clk.attr.add("keep")
         if hasattr(clk, "p"):
             clk = clk.p
index cf7bbeb502ca6347072fb34539badad0dec4fee6..d5e3d8f854541b18c9fb1cc71226d738ea1e415b 100644 (file)
@@ -48,6 +48,7 @@ class XilinxPlatform(GenericPlatform):
         return self.toolchain.build(self, *args, **kwargs)
 
     def add_period_constraint(self, clk, period):
+        if clk is None: return
         if hasattr(clk, "p"):
             clk = clk.p
         self.toolchain.add_period_constraint(self, clk, period)