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):
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))
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)
--- /dev/null
+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)
# 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 = [
),
]
-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()