build/lattice/icestorm/add_period_constraint: improve
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Tue, 31 Dec 2019 09:25:51 +0000 (10:25 +0100)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Tue, 31 Dec 2019 09:30:09 +0000 (10:30 +0100)
- store period in ns.
- pass clocks to_build_pre_pack and do the convertion to MHz there.
- improve error message.

litex/build/lattice/icestorm.py

index c78574086343785eca5351a38ed4ea897f82cb53..9a66026102b8b1fc4937e4c132df893d27d4a9c6 100644 (file)
@@ -29,10 +29,10 @@ def _build_pcf(named_sc, named_pc):
 
 # Timing Constraints (in pre_pack file) ------------------------------------------------------------
 
-def _build_pre_pack(vns, freq_cstrs):
+def _build_pre_pack(vns, clocks):
     r = ""
-    for sig in freq_cstrs:
-        r += """ctx.addClock("{}", {})\n""".format(vns.get_name(sig), freq_cstrs[sig])
+    for clk, period in clocks.items():
+        r += """ctx.addClock("{}", {})\n""".format(vns.get_name(clk), 1e3/period)
     return r
 
 # Yosys/Nextpnr Helpers/Templates ------------------------------------------------------------------
@@ -193,12 +193,9 @@ class LatticeIceStormToolchain:
         return v_output.ns
 
     def add_period_constraint(self, platform, clk, period):
-        clk_ns = 1e3/period
         clk.attr.add("keep")
         if clk in self.clocks:
-            if clk_ns != self.clocks[clk]:
-                raise ValueError(
-                    "A period constraint already exists"
-                    "(wanted: {:.2f}ns, got {:.2f}ns)".format(
-                        clk_ns, self.clocks[clk]))
-        self.clocks[clk] = clk_ns
+            if period != self.clocks[clk]:
+                raise ValueError("Clock already constrained to {:.2f}ns, new constraint to {:.2f}ns"
+                    .format(self.clocks[clk], period))
+        self.clocks[clk] = period