From: Florent Kermarrec Date: Mon, 16 Mar 2015 20:13:54 +0000 (+0100) Subject: mibuild/lattice: use new Toolchain/Platform architecture X-Git-Tag: 24jan2021_ls180~2099^2~183 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d6041879dd42b44feca0720bbbd5e97d21ccec72;p=litex.git mibuild/lattice: use new Toolchain/Platform architecture --- diff --git a/mibuild/lattice/__init__.py b/mibuild/lattice/__init__.py index e69de29b..02116134 100644 --- a/mibuild/lattice/__init__.py +++ b/mibuild/lattice/__init__.py @@ -0,0 +1,2 @@ +from mibuild.lattice.platform import LatticePlatform +from mibuild.lattice.programmer import LatticeProgrammer diff --git a/mibuild/lattice/common.py b/mibuild/lattice/common.py new file mode 100644 index 00000000..2eef69d3 --- /dev/null +++ b/mibuild/lattice/common.py @@ -0,0 +1 @@ +lattice_special_overrides = {} diff --git a/mibuild/lattice/diamond.py b/mibuild/lattice/diamond.py index f39ddd32..dbbc99ae 100644 --- a/mibuild/lattice/diamond.py +++ b/mibuild/lattice/diamond.py @@ -5,7 +5,9 @@ import os, subprocess, shutil from migen.fhdl.structure import _Fragment from mibuild.generic_platform import * + from mibuild import tools +from mibuild.lattice import common def _format_constraint(c): if isinstance(c, Pins): @@ -61,23 +63,22 @@ def _run_diamond(build_name, source, ver=None): if r != 0: raise OSError("Subprocess failed") -class LatticeDiamondPlatform(GenericPlatform): - bitstream_ext = ".bit" - def build(self, fragment, build_dir="build", build_name="top", +class LatticeDiamondToolchain: + def build(self, platform, fragment, build_dir="build", build_name="top", diamond_path="/opt/Diamond", run=True): tools.mkdir_noerror(build_dir) os.chdir(build_dir) if not isinstance(fragment, _Fragment): fragment = fragment.get_fragment() - self.finalize(fragment) + platform.finalize(fragment) - v_src, vns = self.get_verilog(fragment) - named_sc, named_pc = self.resolve_signals(vns) + v_src, vns = platform.get_verilog(fragment) + named_sc, named_pc = platform.resolve_signals(vns) v_file = build_name + ".v" tools.write_to_file(v_file, v_src) - sources = self.sources + [(v_file, "verilog")] - _build_files(self.device, sources, self.verilog_include_paths, build_name) + sources = platform.sources + [(v_file, "verilog")] + _build_files(platform.device, sources, platform.verilog_include_paths, build_name) tools.write_to_file(build_name + ".lpf", _build_lpf(named_sc, named_pc)) @@ -88,6 +89,6 @@ class LatticeDiamondPlatform(GenericPlatform): return vns - def add_period_constraint(self, clk, period): + def add_period_constraint(self, platform, clk, period): # TODO: handle differential clk - self.add_platform_command("""FREQUENCY PORT "{clk}" {freq} MHz;""".format(freq=str(float(1/period)*1000), clk="{clk}"), clk=clk) \ No newline at end of file + platform.add_platform_command("""FREQUENCY PORT "{clk}" {freq} MHz;""".format(freq=str(float(1/period)*1000), clk="{clk}"), clk=clk) diff --git a/mibuild/lattice/platform.py b/mibuild/lattice/platform.py new file mode 100644 index 00000000..f3586daa --- /dev/null +++ b/mibuild/lattice/platform.py @@ -0,0 +1,25 @@ +from mibuild.generic_platform import GenericPlatform +from mibuild.lattice import common, diamond + +class LatticePlatform(GenericPlatform): + bitstream_ext = ".bit" + + def __init__(self, *args, toolchain="diamond", **kwargs): + GenericPlatform.__init__(self, *args, **kwargs) + if toolchain == "diamond": + self.toolchain = diamond.LatticeDiamondToolchain() + else: + raise ValueError("Unknown toolchain") + + def get_verilog(self, *args, special_overrides=dict(), **kwargs): + so = dict(common.lattice_special_overrides) + so.update(special_overrides) + return GenericPlatform.get_verilog(self, *args, special_overrides=so, **kwargs) + + def build(self, *args, **kwargs): + return self.toolchain.build(self, *args, **kwargs) + + def add_period_constraint(self, clk, period): + if hasattr(clk, "p"): + clk = clk.p + self.toolchain.add_period_constraint(self, clk, period) diff --git a/mibuild/platforms/versa.py b/mibuild/platforms/versa.py index 6cd58bf9..050afb4f 100644 --- a/mibuild/platforms/versa.py +++ b/mibuild/platforms/versa.py @@ -2,7 +2,7 @@ # License: BSD from mibuild.generic_platform import * -from mibuild.lattice.diamond import LatticeDiamondPlatform +from mibuild.lattice import LatticePlatform from mibuild.lattice.programmer import LatticeProgrammer _io = [ @@ -23,12 +23,12 @@ _io = [ ), ] -class Platform(LatticeDiamondPlatform): +class Platform(LatticePlatform): default_clk_name = "clk100" default_clk_period = 10 def __init__(self): - LatticeDiamondPlatform.__init__(self, "LFE3-35EA-6FN484C", _io) + LatticePlatform.__init__(self, "LFE3-35EA-6FN484C", _io) def create_programmer(self): return LatticeProgrammer()