build/altera/quartus: add add_ip method to use Quartus QSYS files
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Thu, 15 Aug 2019 11:44:36 +0000 (13:44 +0200)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Thu, 15 Aug 2019 11:45:29 +0000 (13:45 +0200)
platform.add_ip("my_ip.qsys")

litex/build/altera/platform.py
litex/build/altera/quartus.py

index 6838e553111ae42abd35e6ea744d22e4cf87ebd5..ef85f47a6f7d7b7674ae9d1832156fc3734388cb 100644 (file)
@@ -2,6 +2,7 @@
 # This file is Copyright (c) 2019 msloniewski <marcin.sloniewski@gmail.com>
 # License: BSD
 
+import os
 
 from litex.build.generic_platform import GenericPlatform
 from litex.build.altera import common, quartus
@@ -13,11 +14,15 @@ class AlteraPlatform(GenericPlatform):
 
     def __init__(self, *args, toolchain="quartus", **kwargs):
         GenericPlatform.__init__(self, *args, **kwargs)
+        self.ips = set()
         if toolchain == "quartus":
             self.toolchain = quartus.AlteraQuartusToolchain()
         else:
             raise ValueError("Unknown toolchain")
 
+    def add_ip(self, filename):
+        self.ips.add((os.path.abspath(filename)))
+
     def get_verilog(self, *args, special_overrides=dict(), **kwargs):
         so = dict(common.altera_special_overrides)
         so.update(special_overrides)
index a8a7f64af5af6bee2b2ea3e01b5cb63b80edb635..40f0681a7699cd789ce83f302f145e73065e4ccc 100644 (file)
@@ -89,11 +89,13 @@ def _build_sdc(clocks, false_paths, vns, build_name):
     tools.write_to_file("{}.sdc".format(build_name), "\n".join(lines))
 
 
-def _build_files(device, sources, vincpaths, named_sc, named_pc, build_name):
+def _build_files(device, ips, sources, vincpaths, named_sc, named_pc, build_name):
     lines = []
+    for filename in ips:
+           lines.append("set_global_assignment -name QSYS_FILE {path} ".format(
+                path=filename.replace("\\", "/")))
     for filename, language, library in sources:
-        # Enforce use of SystemVerilog
-        # (Quartus does not support global parameters in Verilog)
+        # Enforce use of SystemVerilog since Quartus does not support global parameters in Verilog
         if language == "verilog":
             language = "systemverilog"
         lines.append(
@@ -168,9 +170,10 @@ class AlteraQuartusToolchain:
         named_sc, named_pc = platform.resolve_signals(v_output.ns)
         v_file = build_name + ".v"
         v_output.write(v_file)
-        sources = platform.sources | {(v_file, "verilog", "work")}
+        platform.add_source(v_file)
         _build_files(platform.device,
-                     sources,
+                     platform.ips,
+                     platform.sources,
                      platform.verilog_include_paths,
                      named_sc,
                      named_pc,