from litex.build.lattice import common
-def _format_constraint(c):
- pass
-
-
-def _format_pcf(signame, pin, others, resname):
- return "set_io " + signame + " " + pin + "\n"
-
-
def _build_pcf(named_sc, named_pc):
r = ""
for sig, pins, others, resname in named_sc:
if len(pins) > 1:
- for i, p in enumerate(pins):
- r += _format_pcf(sig + "[" + str(i) + "]", p, others, resname)
+ for bit, pin in enumerate(pins):
+ r += "set_io {}[{}] {}\n".format(sig, bit, pin)
else:
- r += _format_pcf(sig, pins[0], others, resname)
+ r += "set_io {} {}\n".format(sig, pins[0])
if named_pc:
r += "\n" + "\n\n".join(named_pc)
return r
-def _build_script(source, build_template, build_name, pnr_pkg_opts,
- icetime_pkg_opts, freq_constraint):
+def _build_pre_pack(vns, freq_cstrs):
+ r = ""
+ for sig in freq_cstrs:
+ r += """ctx.addClock("{}", {})\n""".format(vns.get_name(sig), freq_cstrs[sig])
+ return r
+
+
+def _build_script(source, build_template, build_name, **kwargs):
if sys.platform in ("win32", "cygwin"):
script_ext = ".bat"
build_script_contents = "@echo off\nrem Autogenerated by Migen\n\n"
for s in build_template:
s_fail = s + "{fail_stmt}\n" # Required so Windows scripts fail early.
build_script_contents += s_fail.format(build_name=build_name,
- pnr_pkg_opts=pnr_pkg_opts,
- icetime_pkg_opts=icetime_pkg_opts,
- freq_constraint=freq_constraint,
- fail_stmt=fail_stmt)
+ fail_stmt=fail_stmt,
+ **kwargs)
build_script_file = "build_" + build_name + script_ext
tools.write_to_file(build_script_file, build_script_contents,
self.yosys_template = [
"{read_files}",
"attrmap -tocase keep -imap keep=\"true\" keep=1 -imap keep=\"false\" keep=0 -remove keep=0",
- "synth_ice40 -top top -blif {build_name}.blif",
+ "synth_ice40 -top {build_name} -blif {build_name}.blif",
]
self.build_template = [
self.nextpnr_yosys_template = [
"{read_files}",
"attrmap -tocase keep -imap keep=\"true\" keep=1 -imap keep=\"false\" keep=0 -remove keep=0",
- "synth_ice40 -top top -json {build_name}.json",
+ "synth_ice40 {synth_opts} -top {build_name} -json {build_name}.json",
]
self.nextpnr_build_template = [
"yosys -q -l {build_name}.rpt {build_name}.ys",
- "nextpnr-ice40 {pnr_pkg_opts} --pcf {build_name}.pcf --json {build_name}.json --asc {build_name}.txt --freq {freq_constraint}",
+ "nextpnr-ice40 {pnr_pkg_opts} --pcf {build_name}.pcf --json {build_name}.json --asc {build_name}.txt --pre-pack {build_name}_pre_pack.py",
"icepack {build_name}.txt {build_name}.bin"
]
# platform.device should be of the form "ice40-{lp384, hx1k, etc}-{tq144, etc}"
def build(self, platform, fragment, build_dir="build", build_name="top",
- toolchain_path=None, use_nextpnr=True, run=True, **kwargs):
+ toolchain_path=None, use_nextpnr=True, synth_opts="", run=True, **kwargs):
os.makedirs(build_dir, exist_ok=True)
cwd = os.getcwd()
os.chdir(build_dir)
else:
chosen_yosys_template = self.yosys_template
ys_contents = "\n".join(_.format(build_name=build_name,
- read_files=self.gen_read_files(platform, v_file))
+ read_files=self.gen_read_files(platform, v_file),
+ synth_opts=synth_opts)
for _ in chosen_yosys_template)
ys_name = build_name + ".ys"
pnr_pkg_opts = "-d " + self.get_size_string(series_size) + \
" -P " + package
icetime_pkg_opts = "-P " + package + " -d " + series_size
+
+ if use_nextpnr:
+ tools.write_to_file(build_name + "_pre_pack.py",
+ _build_pre_pack(v_output.ns, self.freq_constraints))
+ # icetime can only handle a single global constraint, so we test against the fastest
+ # clock; though imprecise, if the global design satisfies the fastest clock, we can
+ # be sure all other constraints are satisfied.
freq_constraint = str(max(self.freq_constraints.values(),
default=0.0))
chosen_build_template = self.nextpnr_build_template
else:
chosen_build_template = self.build_template
- script = _build_script(False, chosen_build_template, build_name,
- pnr_pkg_opts, icetime_pkg_opts, freq_constraint)
+ script = _build_script(source=False,
+ build_template=chosen_build_template,
+ build_name=build_name,
+ pnr_pkg_opts=pnr_pkg_opts,
+ icetime_pkg_opts=icetime_pkg_opts,
+ freq_constraint=freq_constraint)
if run:
_run_script(script)
"hx1k": ["vq100", "cb132", "tq144"],
"lp8k": ["cm81", "cm81:4k", "cm121", "cm121:4k", "cm225",
"cm225:4k"],
- "hx8k": ["cb132", "cb132:4k", "tq144:4k", "cm225", "ct256"],
+ "hx8k": ["bg121", "bg121:4k", "cb132", "cb132:4k", "cm121",
+ "cm121:4k", "cm225", "cm225:4k", "cm81", "cm81:4k",
+ "ct256", "tq144:4k"],
"up3k": ["sg48", "uwg30"],
"up5k": ["sg48", "uwg30"],
}
filename))
return "\n".join(read_files)
- # icetime can only handle a single global constraint. Pending more
- # finely-tuned analysis features in arachne-pnr and IceStorm, save
- # all the constraints in a dictionary and test against the fastest clk.
- # Though imprecise, if the global design satisfies the fastest clock,
- # we can be sure all other constraints are satisfied.
def add_period_constraint(self, platform, clk, period):
new_freq = 1000.0/period