2019-06-06 05:53:17 -06:00
|
|
|
from abc import abstractproperty
|
|
|
|
|
2019-08-04 17:27:47 -06:00
|
|
|
from ..hdl import *
|
build.plat,vendor: always synchronize reset in default sync domain.
This change achieves two related goals.
First, default_rst is no longer assumed to be synchronous to
default_clk, which is the safer option, since it can be connected to
e.g. buttons on some evaluation boards.
Second, since the power-on / configuration reset is inherently
asynchronous to any user clock, the default create_missing_domain()
behavior is to use a reset synchronizer with `0` as input. Since,
like all reset synchronizers, it uses Signal(reset=1) for its
synchronization stages, after power-on reset it keeps its subordinate
clock domain in reset, and releases it after fabric flops start
toggling.
The latter change is helpful to architectures that lack an end-of-
configuration signal, i.e. most of them. ECP5 was already using
a similar scheme (and is not changed here). Xilinx devices with EOS
use EOS to drive a BUFGMUX, which is more efficient than using
a global reset when the design does not need one; Xilinx devices
without EOS use the new scheme. iCE40 requires a post-configuration
timer because of BRAM silicon bug, and was changed to add a reset
synchronizer if user clock is provided.
2019-10-09 14:02:33 -06:00
|
|
|
from ..lib.cdc import ResetSynchronizer
|
2019-06-06 05:53:17 -06:00
|
|
|
from ..build import *
|
|
|
|
|
|
|
|
|
|
|
|
__all__ = ["Xilinx7SeriesPlatform"]
|
|
|
|
|
|
|
|
|
|
|
|
class Xilinx7SeriesPlatform(TemplatedPlatform):
|
|
|
|
"""
|
2020-08-02 10:48:26 -06:00
|
|
|
Vivado toolchain
|
|
|
|
----------------
|
|
|
|
|
2019-06-06 05:53:17 -06:00
|
|
|
Required tools:
|
|
|
|
* ``vivado``
|
|
|
|
|
2019-07-06 18:41:03 -06:00
|
|
|
The environment is populated by running the script specified in the environment variable
|
2019-09-21 06:23:53 -06:00
|
|
|
``NMIGEN_ENV_Vivado``, if present.
|
2019-07-06 18:41:03 -06:00
|
|
|
|
2019-06-06 05:53:17 -06:00
|
|
|
Available overrides:
|
|
|
|
* ``script_after_read``: inserts commands after ``read_xdc`` in Tcl script.
|
|
|
|
* ``script_after_synth``: inserts commands after ``synth_design`` in Tcl script.
|
|
|
|
* ``script_after_place``: inserts commands after ``place_design`` in Tcl script.
|
|
|
|
* ``script_after_route``: inserts commands after ``route_design`` in Tcl script.
|
|
|
|
* ``script_before_bitstream``: inserts commands before ``write_bitstream`` in Tcl script.
|
|
|
|
* ``script_after_bitstream``: inserts commands after ``write_bitstream`` in Tcl script.
|
|
|
|
* ``add_constraints``: inserts commands in XDC file.
|
2019-08-21 15:31:19 -06:00
|
|
|
* ``vivado_opts``: adds extra options for ``vivado``.
|
2019-06-06 05:53:17 -06:00
|
|
|
|
|
|
|
Build products:
|
|
|
|
* ``{{name}}.log``: Vivado log.
|
|
|
|
* ``{{name}}_timing_synth.rpt``: Vivado report.
|
|
|
|
* ``{{name}}_utilization_hierarchical_synth.rpt``: Vivado report.
|
|
|
|
* ``{{name}}_utilization_synth.rpt``: Vivado report.
|
|
|
|
* ``{{name}}_utilization_hierarchical_place.rpt``: Vivado report.
|
|
|
|
* ``{{name}}_utilization_place.rpt``: Vivado report.
|
|
|
|
* ``{{name}}_io.rpt``: Vivado report.
|
|
|
|
* ``{{name}}_control_sets.rpt``: Vivado report.
|
|
|
|
* ``{{name}}_clock_utilization.rpt``: Vivado report.
|
|
|
|
* ``{{name}}_route_status.rpt``: Vivado report.
|
|
|
|
* ``{{name}}_drc.rpt``: Vivado report.
|
2020-02-06 12:38:21 -07:00
|
|
|
* ``{{name}}_methodology.rpt``: Vivado report.
|
2019-06-06 05:53:17 -06:00
|
|
|
* ``{{name}}_timing.rpt``: Vivado report.
|
|
|
|
* ``{{name}}_power.rpt``: Vivado report.
|
|
|
|
* ``{{name}}_route.dcp``: Vivado design checkpoint.
|
2019-07-07 15:36:32 -06:00
|
|
|
* ``{{name}}.bit``: binary bitstream with metadata.
|
|
|
|
* ``{{name}}.bin``: binary bitstream.
|
2020-08-02 10:48:26 -06:00
|
|
|
|
|
|
|
Symbiflow toolchain
|
|
|
|
-------------------
|
|
|
|
|
|
|
|
Required tools:
|
2021-01-31 11:08:44 -07:00
|
|
|
* ``symbiflow_synth``
|
|
|
|
* ``symbiflow_pack``
|
|
|
|
* ``symbiflow_place``
|
|
|
|
* ``symbiflow_route``
|
|
|
|
* ``symbiflow_write_fasm``
|
|
|
|
* ``symbiflow_write_bitstream``
|
2020-08-02 10:48:26 -06:00
|
|
|
|
|
|
|
The environment is populated by running the script specified in the environment variable
|
|
|
|
``NMIGEN_ENV_Symbiflow``, if present.
|
|
|
|
|
|
|
|
Available overrides:
|
|
|
|
* ``add_constraints``: inserts commands in XDC file.
|
2019-06-06 05:53:17 -06:00
|
|
|
"""
|
|
|
|
|
2020-08-02 10:48:26 -06:00
|
|
|
toolchain = None # selected when creating platform
|
2019-07-06 18:41:03 -06:00
|
|
|
|
2019-06-25 09:51:52 -06:00
|
|
|
device = abstractproperty()
|
2019-06-06 05:53:17 -06:00
|
|
|
package = abstractproperty()
|
2019-06-25 09:51:52 -06:00
|
|
|
speed = abstractproperty()
|
2019-06-06 05:53:17 -06:00
|
|
|
|
2020-08-24 05:03:59 -06:00
|
|
|
@property
|
|
|
|
def _part(self):
|
|
|
|
return "{}{}-{}".format(self.device, self.package, self.speed)
|
|
|
|
|
2020-08-02 10:48:26 -06:00
|
|
|
# Vivado templates
|
|
|
|
|
|
|
|
_vivado_required_tools = ["vivado"]
|
|
|
|
_vivado_file_templates = {
|
2019-06-06 05:53:17 -06:00
|
|
|
**TemplatedPlatform.build_script_templates,
|
2019-09-12 15:49:08 -06:00
|
|
|
"build_{{name}}.sh": r"""
|
|
|
|
# {{autogenerated}}
|
|
|
|
set -e{{verbose("x")}}
|
|
|
|
if [ -z "$BASH" ] ; then exec /bin/bash "$0" "$@"; fi
|
|
|
|
[ -n "${{platform._toolchain_env_var}}" ] && . "${{platform._toolchain_env_var}}"
|
|
|
|
{{emit_commands("sh")}}
|
|
|
|
""",
|
2019-06-06 05:53:17 -06:00
|
|
|
"{{name}}.v": r"""
|
|
|
|
/* {{autogenerated}} */
|
2020-05-21 02:57:30 -06:00
|
|
|
{{emit_verilog()}}
|
2019-09-24 08:54:22 -06:00
|
|
|
""",
|
|
|
|
"{{name}}.debug.v": r"""
|
|
|
|
/* {{autogenerated}} */
|
2020-05-21 02:57:30 -06:00
|
|
|
{{emit_debug_verilog()}}
|
2019-06-06 05:53:17 -06:00
|
|
|
""",
|
|
|
|
"{{name}}.tcl": r"""
|
|
|
|
# {{autogenerated}}
|
2020-08-24 05:03:59 -06:00
|
|
|
create_project -force -name {{name}} -part {{platform._part}}
|
2020-11-09 22:30:21 -07:00
|
|
|
{% for file in platform.iter_files(".v", ".sv", ".vhd", ".vhdl") -%}
|
2020-05-02 04:41:18 -06:00
|
|
|
add_files {{file|tcl_escape}}
|
2019-06-06 05:53:17 -06:00
|
|
|
{% endfor %}
|
|
|
|
add_files {{name}}.v
|
|
|
|
read_xdc {{name}}.xdc
|
2020-11-09 22:30:21 -07:00
|
|
|
{% for file in platform.iter_files(".xdc") -%}
|
2020-05-02 04:41:18 -06:00
|
|
|
read_xdc {{file|tcl_escape}}
|
2019-07-02 01:47:40 -06:00
|
|
|
{% endfor %}
|
2019-06-06 05:53:17 -06:00
|
|
|
{{get_override("script_after_read")|default("# (script_after_read placeholder)")}}
|
2019-09-23 14:27:42 -06:00
|
|
|
synth_design -top {{name}}
|
2019-09-23 18:47:54 -06:00
|
|
|
foreach cell [get_cells -quiet -hier -filter {nmigen.vivado.false_path == "TRUE"}] {
|
|
|
|
set_false_path -to $cell
|
|
|
|
}
|
|
|
|
foreach cell [get_cells -quiet -hier -filter {nmigen.vivado.max_delay != ""}] {
|
|
|
|
set clock [get_clocks -of_objects \
|
|
|
|
[all_fanin -flat -startpoints_only [get_pin $cell/D]]]
|
|
|
|
if {[llength $clock] != 0} {
|
|
|
|
set_max_delay -datapath_only -from $clock \
|
|
|
|
-to [get_cells $cell] [get_property nmigen.vivado.max_delay $cell]
|
|
|
|
}
|
|
|
|
}
|
2019-06-06 05:53:17 -06:00
|
|
|
{{get_override("script_after_synth")|default("# (script_after_synth placeholder)")}}
|
|
|
|
report_timing_summary -file {{name}}_timing_synth.rpt
|
|
|
|
report_utilization -hierarchical -file {{name}}_utilization_hierachical_synth.rpt
|
|
|
|
report_utilization -file {{name}}_utilization_synth.rpt
|
|
|
|
opt_design
|
|
|
|
place_design
|
|
|
|
{{get_override("script_after_place")|default("# (script_after_place placeholder)")}}
|
|
|
|
report_utilization -hierarchical -file {{name}}_utilization_hierarchical_place.rpt
|
|
|
|
report_utilization -file {{name}}_utilization_place.rpt
|
|
|
|
report_io -file {{name}}_io.rpt
|
|
|
|
report_control_sets -verbose -file {{name}}_control_sets.rpt
|
|
|
|
report_clock_utilization -file {{name}}_clock_utilization.rpt
|
|
|
|
route_design
|
|
|
|
{{get_override("script_after_route")|default("# (script_after_route placeholder)")}}
|
|
|
|
phys_opt_design
|
|
|
|
report_timing_summary -no_header -no_detailed_paths
|
|
|
|
write_checkpoint -force {{name}}_route.dcp
|
|
|
|
report_route_status -file {{name}}_route_status.rpt
|
|
|
|
report_drc -file {{name}}_drc.rpt
|
2020-02-06 12:38:21 -07:00
|
|
|
report_methodology -file {{name}}_methodology.rpt
|
2019-06-06 05:53:17 -06:00
|
|
|
report_timing_summary -datasheet -max_paths 10 -file {{name}}_timing.rpt
|
|
|
|
report_power -file {{name}}_power.rpt
|
|
|
|
{{get_override("script_before_bitstream")|default("# (script_before_bitstream placeholder)")}}
|
2020-12-12 15:08:57 -07:00
|
|
|
write_bitstream -force -bin_file {{name}}.bit
|
2019-06-06 05:53:17 -06:00
|
|
|
{{get_override("script_after_bitstream")|default("# (script_after_bitstream placeholder)")}}
|
|
|
|
quit
|
|
|
|
""",
|
|
|
|
"{{name}}.xdc": r"""
|
|
|
|
# {{autogenerated}}
|
|
|
|
{% for port_name, pin_name, attrs in platform.iter_port_constraints_bits() -%}
|
2020-05-02 04:41:18 -06:00
|
|
|
set_property LOC {{pin_name}} [get_ports {{port_name|tcl_escape}}]
|
2019-06-06 05:53:17 -06:00
|
|
|
{% for attr_name, attr_value in attrs.items() -%}
|
2020-05-02 04:41:18 -06:00
|
|
|
set_property {{attr_name}} {{attr_value|tcl_escape}} [get_ports {{port_name|tcl_escape}}]
|
2019-06-06 05:53:17 -06:00
|
|
|
{% endfor %}
|
|
|
|
{% endfor %}
|
2020-02-06 16:37:15 -07:00
|
|
|
{% for net_signal, port_signal, frequency in platform.iter_clock_constraints() -%}
|
|
|
|
{% if port_signal is not none -%}
|
2020-05-02 04:41:18 -06:00
|
|
|
create_clock -name {{port_signal.name|ascii_escape}} -period {{1000000000/frequency}} [get_ports {{port_signal.name|tcl_escape}}]
|
2020-02-06 16:37:15 -07:00
|
|
|
{% else -%}
|
2020-05-02 04:41:18 -06:00
|
|
|
create_clock -name {{net_signal.name|ascii_escape}} -period {{1000000000/frequency}} [get_nets {{net_signal|hierarchy("/")|tcl_escape}}]
|
2020-02-06 16:37:15 -07:00
|
|
|
{% endif %}
|
2019-06-06 05:53:17 -06:00
|
|
|
{% endfor %}
|
2019-06-06 16:54:52 -06:00
|
|
|
{{get_override("add_constraints")|default("# (add_constraints placeholder)")}}
|
2019-06-06 05:53:17 -06:00
|
|
|
"""
|
|
|
|
}
|
2020-08-02 10:48:26 -06:00
|
|
|
_vivado_command_templates = [
|
2019-06-06 05:53:17 -06:00
|
|
|
r"""
|
2019-10-13 07:53:24 -06:00
|
|
|
{{invoke_tool("vivado")}}
|
2019-06-06 05:53:17 -06:00
|
|
|
{{verbose("-verbose")}}
|
2019-07-06 17:09:46 -06:00
|
|
|
{{get_override("vivado_opts")|options}}
|
2019-06-06 05:53:17 -06:00
|
|
|
-mode batch
|
|
|
|
-log {{name}}.log
|
|
|
|
-source {{name}}.tcl
|
|
|
|
"""
|
|
|
|
]
|
|
|
|
|
2020-08-02 10:48:26 -06:00
|
|
|
# Symbiflow templates
|
|
|
|
|
|
|
|
_symbiflow_part_map = {
|
|
|
|
"xc7a35ticsg324-1L": "xc7a35tcsg324-1", # Arty-A7
|
|
|
|
}
|
|
|
|
|
|
|
|
_symbiflow_required_tools = [
|
2021-01-31 11:08:44 -07:00
|
|
|
"symbiflow_synth",
|
|
|
|
"symbiflow_pack",
|
|
|
|
"symbiflow_place",
|
|
|
|
"symbiflow_route",
|
|
|
|
"symbiflow_write_fasm",
|
|
|
|
"symbiflow_write_bitstream"
|
2020-08-02 10:48:26 -06:00
|
|
|
]
|
|
|
|
_symbiflow_file_templates = {
|
|
|
|
**TemplatedPlatform.build_script_templates,
|
|
|
|
"{{name}}.v": r"""
|
|
|
|
/* {{autogenerated}} */
|
|
|
|
{{emit_verilog()}}
|
|
|
|
""",
|
|
|
|
"{{name}}.debug.v": r"""
|
|
|
|
/* {{autogenerated}} */
|
|
|
|
{{emit_debug_verilog()}}
|
|
|
|
""",
|
|
|
|
"{{name}}.pcf": r"""
|
|
|
|
# {{autogenerated}}
|
|
|
|
{% for port_name, pin_name, attrs in platform.iter_port_constraints_bits() -%}
|
|
|
|
set_io {{port_name}} {{pin_name}}
|
|
|
|
{% endfor %}
|
|
|
|
""",
|
|
|
|
"{{name}}.xdc": r"""
|
|
|
|
# {{autogenerated}}
|
|
|
|
{% for port_name, pin_name, attrs in platform.iter_port_constraints_bits() -%}
|
|
|
|
{% for attr_name, attr_value in attrs.items() -%}
|
|
|
|
set_property {{attr_name}} {{attr_value}} [get_ports {{port_name|tcl_escape}} }]
|
|
|
|
{% endfor %}
|
|
|
|
{% endfor %}
|
|
|
|
{{get_override("add_constraints")|default("# (add_constraints placeholder)")}}
|
|
|
|
""",
|
|
|
|
"{{name}}.sdc": r"""
|
|
|
|
# {{autogenerated}}
|
|
|
|
{% for net_signal, port_signal, frequency in platform.iter_clock_constraints() -%}
|
|
|
|
{% if port_signal is none -%}
|
|
|
|
create_clock -period {{1000000000/frequency}} {{net_signal.name|ascii_escape}}
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
|
|
|
"""
|
|
|
|
}
|
|
|
|
_symbiflow_command_templates = [
|
|
|
|
r"""
|
2021-01-31 11:08:44 -07:00
|
|
|
{{invoke_tool("symbiflow_synth")}}
|
2020-08-02 10:48:26 -06:00
|
|
|
-t {{name}}
|
2020-11-09 22:30:21 -07:00
|
|
|
-v {% for file in platform.iter_files(".v", ".sv", ".vhd", ".vhdl") -%} {{file}} {% endfor %} {{name}}.v
|
2020-08-02 10:48:26 -06:00
|
|
|
-p {{platform._symbiflow_part_map.get(platform._part, platform._part)}}
|
|
|
|
-x {{name}}.xdc
|
|
|
|
""",
|
|
|
|
r"""
|
2021-01-31 11:08:44 -07:00
|
|
|
{{invoke_tool("symbiflow_pack")}}
|
2020-08-02 10:48:26 -06:00
|
|
|
-e {{name}}.eblif
|
|
|
|
-P {{platform._symbiflow_part_map.get(platform._part, platform._part)}}
|
|
|
|
-s {{name}}.sdc
|
|
|
|
""",
|
|
|
|
r"""
|
2021-01-31 11:08:44 -07:00
|
|
|
{{invoke_tool("symbiflow_place")}}
|
2020-08-02 10:48:26 -06:00
|
|
|
-e {{name}}.eblif
|
|
|
|
-p {{name}}.pcf
|
|
|
|
-n {{name}}.net
|
|
|
|
-P {{platform._symbiflow_part_map.get(platform._part, platform._part)}}
|
|
|
|
-s {{name}}.sdc
|
|
|
|
""",
|
|
|
|
r"""
|
2021-01-31 11:08:44 -07:00
|
|
|
{{invoke_tool("symbiflow_route")}}
|
2020-08-02 10:48:26 -06:00
|
|
|
-e {{name}}.eblif
|
|
|
|
-P {{platform._symbiflow_part_map.get(platform._part, platform._part)}}
|
|
|
|
-s {{name}}.sdc
|
|
|
|
""",
|
|
|
|
r"""
|
2021-01-31 11:08:44 -07:00
|
|
|
{{invoke_tool("symbiflow_write_fasm")}}
|
2020-08-02 10:48:26 -06:00
|
|
|
-e {{name}}.eblif
|
|
|
|
-P {{platform._symbiflow_part_map.get(platform._part, platform._part)}}
|
|
|
|
""",
|
|
|
|
r"""
|
2021-01-31 11:08:44 -07:00
|
|
|
{{invoke_tool("symbiflow_write_bitstream")}}
|
2020-08-02 10:48:26 -06:00
|
|
|
-f {{name}}.fasm
|
|
|
|
-p {{platform._symbiflow_part_map.get(platform._part, platform._part)}}
|
|
|
|
-b {{name}}.bit
|
|
|
|
"""
|
|
|
|
]
|
|
|
|
|
|
|
|
# Common logic
|
|
|
|
|
|
|
|
def __init__(self, *, toolchain="Vivado"):
|
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
assert toolchain in ("Vivado", "Symbiflow")
|
|
|
|
self.toolchain = toolchain
|
|
|
|
|
|
|
|
@property
|
|
|
|
def required_tools(self):
|
|
|
|
if self.toolchain == "Vivado":
|
|
|
|
return self._vivado_required_tools
|
|
|
|
if self.toolchain == "Symbiflow":
|
|
|
|
return self._symbiflow_required_tools
|
|
|
|
assert False
|
|
|
|
|
|
|
|
@property
|
|
|
|
def file_templates(self):
|
|
|
|
if self.toolchain == "Vivado":
|
|
|
|
return self._vivado_file_templates
|
|
|
|
if self.toolchain == "Symbiflow":
|
|
|
|
return self._symbiflow_file_templates
|
|
|
|
assert False
|
|
|
|
|
|
|
|
@property
|
|
|
|
def command_templates(self):
|
|
|
|
if self.toolchain == "Vivado":
|
|
|
|
return self._vivado_command_templates
|
|
|
|
if self.toolchain == "Symbiflow":
|
|
|
|
return self._symbiflow_command_templates
|
|
|
|
assert False
|
|
|
|
|
2019-08-03 12:36:58 -06:00
|
|
|
def create_missing_domain(self, name):
|
2019-08-04 17:27:47 -06:00
|
|
|
# Xilinx devices have a global write enable (GWE) signal that asserted during configuraiton
|
|
|
|
# and deasserted once it ends. Because it is an asynchronous signal (GWE is driven by logic
|
|
|
|
# syncronous to configuration clock, which is not used by most designs), even though it is
|
|
|
|
# a low-skew global network, its deassertion may violate a setup/hold constraint with
|
|
|
|
# relation to a user clock. The recommended solution is to use a BUFGCE driven by the EOS
|
|
|
|
# signal. For details, see:
|
|
|
|
# * https://www.xilinx.com/support/answers/44174.html
|
|
|
|
# * https://www.xilinx.com/support/documentation/white_papers/wp272.pdf
|
|
|
|
if name == "sync" and self.default_clk is not None:
|
|
|
|
clk_i = self.request(self.default_clk).i
|
|
|
|
if self.default_rst is not None:
|
|
|
|
rst_i = self.request(self.default_rst).i
|
|
|
|
|
|
|
|
m = Module()
|
2020-08-02 10:48:26 -06:00
|
|
|
|
|
|
|
if self.toolchain == "Vivado":
|
|
|
|
ready = Signal()
|
|
|
|
m.submodules += Instance("STARTUPE2", o_EOS=ready)
|
|
|
|
m.domains += ClockDomain("sync", reset_less=self.default_rst is None)
|
2020-08-26 04:18:02 -06:00
|
|
|
# Actually use BUFGCTRL configured as BUFGCE, since using BUFGCE causes
|
|
|
|
# sim/synth mismatches with Vivado 2019.2, and the suggested workaround
|
|
|
|
# (SIM_DEVICE parameter) breaks Vivado 2017.4.
|
2020-08-02 10:48:26 -06:00
|
|
|
m.submodules += Instance("BUFGCTRL",
|
2020-08-26 04:18:02 -06:00
|
|
|
p_SIM_DEVICE="7SERIES",
|
2020-08-02 10:48:26 -06:00
|
|
|
i_I0=clk_i, i_S0=C(1, 1), i_CE0=ready, i_IGNORE0=C(0, 1),
|
|
|
|
i_I1=C(1, 1), i_S1=C(0, 1), i_CE1=C(0, 1), i_IGNORE1=C(1, 1),
|
|
|
|
o_O=ClockSignal("sync")
|
|
|
|
)
|
|
|
|
elif self.toolchain == "Symbiflow":
|
|
|
|
cd_sync = ClockDomain("sync", reset_less=self.default_rst is None)
|
|
|
|
m.domains += cd_sync
|
|
|
|
m.submodules += Instance("BUFG", i_I=clk_i, o_O=cd_sync.clk)
|
|
|
|
self.add_clock_constraint(cd_sync.clk, self.default_clk_frequency)
|
|
|
|
else:
|
|
|
|
assert False
|
|
|
|
|
2019-08-04 17:27:47 -06:00
|
|
|
if self.default_rst is not None:
|
build.plat,vendor: always synchronize reset in default sync domain.
This change achieves two related goals.
First, default_rst is no longer assumed to be synchronous to
default_clk, which is the safer option, since it can be connected to
e.g. buttons on some evaluation boards.
Second, since the power-on / configuration reset is inherently
asynchronous to any user clock, the default create_missing_domain()
behavior is to use a reset synchronizer with `0` as input. Since,
like all reset synchronizers, it uses Signal(reset=1) for its
synchronization stages, after power-on reset it keeps its subordinate
clock domain in reset, and releases it after fabric flops start
toggling.
The latter change is helpful to architectures that lack an end-of-
configuration signal, i.e. most of them. ECP5 was already using
a similar scheme (and is not changed here). Xilinx devices with EOS
use EOS to drive a BUFGMUX, which is more efficient than using
a global reset when the design does not need one; Xilinx devices
without EOS use the new scheme. iCE40 requires a post-configuration
timer because of BRAM silicon bug, and was changed to add a reset
synchronizer if user clock is provided.
2019-10-09 14:02:33 -06:00
|
|
|
m.submodules.reset_sync = ResetSynchronizer(rst_i, domain="sync")
|
2019-08-04 17:27:47 -06:00
|
|
|
return m
|
2019-08-03 12:36:58 -06:00
|
|
|
|
2020-05-19 22:58:03 -06:00
|
|
|
def add_clock_constraint(self, clock, frequency):
|
|
|
|
super().add_clock_constraint(clock, frequency)
|
2020-05-21 02:57:30 -06:00
|
|
|
clock.attrs["keep"] = "TRUE"
|
2020-05-19 22:58:03 -06:00
|
|
|
|
2019-08-22 14:54:42 -06:00
|
|
|
def _get_xdr_buffer(self, m, pin, *, i_invert=False, o_invert=False):
|
2019-06-13 06:33:24 -06:00
|
|
|
def get_dff(clk, d, q):
|
|
|
|
# SDR I/O is performed by packing a flip-flop into the pad IOB.
|
|
|
|
for bit in range(len(q)):
|
|
|
|
m.submodules += Instance("FDCE",
|
2019-11-18 07:58:39 -07:00
|
|
|
a_IOB="TRUE",
|
2019-06-13 06:33:24 -06:00
|
|
|
i_C=clk,
|
|
|
|
i_CE=Const(1),
|
|
|
|
i_CLR=Const(0),
|
|
|
|
i_D=d[bit],
|
2019-11-18 07:58:39 -07:00
|
|
|
o_Q=q[bit]
|
2019-06-13 06:33:24 -06:00
|
|
|
)
|
2019-06-06 05:53:17 -06:00
|
|
|
|
2019-06-13 06:33:24 -06:00
|
|
|
def get_iddr(clk, d, q1, q2):
|
|
|
|
for bit in range(len(q1)):
|
|
|
|
m.submodules += Instance("IDDR",
|
|
|
|
p_DDR_CLK_EDGE="SAME_EDGE_PIPELINED",
|
|
|
|
p_SRTYPE="ASYNC",
|
|
|
|
p_INIT_Q1=0, p_INIT_Q2=0,
|
|
|
|
i_C=clk,
|
|
|
|
i_CE=Const(1),
|
|
|
|
i_S=Const(0), i_R=Const(0),
|
|
|
|
i_D=d[bit],
|
|
|
|
o_Q1=q1[bit], o_Q2=q2[bit]
|
|
|
|
)
|
2019-06-11 11:57:55 -06:00
|
|
|
|
2019-06-13 06:33:24 -06:00
|
|
|
def get_oddr(clk, d1, d2, q):
|
|
|
|
for bit in range(len(q)):
|
|
|
|
m.submodules += Instance("ODDR",
|
|
|
|
p_DDR_CLK_EDGE="SAME_EDGE",
|
|
|
|
p_SRTYPE="ASYNC",
|
|
|
|
p_INIT=0,
|
|
|
|
i_C=clk,
|
|
|
|
i_CE=Const(1),
|
|
|
|
i_S=Const(0), i_R=Const(0),
|
|
|
|
i_D1=d1[bit], i_D2=d2[bit],
|
|
|
|
o_Q=q[bit]
|
|
|
|
)
|
|
|
|
|
2019-08-22 14:54:42 -06:00
|
|
|
def get_ineg(y, invert):
|
|
|
|
if invert:
|
|
|
|
a = Signal.like(y, name_suffix="_n")
|
|
|
|
m.d.comb += y.eq(~a)
|
2019-06-13 06:33:24 -06:00
|
|
|
return a
|
|
|
|
else:
|
|
|
|
return y
|
|
|
|
|
2019-08-22 14:54:42 -06:00
|
|
|
def get_oneg(a, invert):
|
|
|
|
if invert:
|
|
|
|
y = Signal.like(a, name_suffix="_n")
|
|
|
|
m.d.comb += y.eq(~a)
|
|
|
|
return y
|
|
|
|
else:
|
|
|
|
return a
|
|
|
|
|
2019-06-13 06:33:24 -06:00
|
|
|
if "i" in pin.dir:
|
|
|
|
if pin.xdr < 2:
|
2019-08-22 14:54:42 -06:00
|
|
|
pin_i = get_ineg(pin.i, i_invert)
|
2019-06-13 06:33:24 -06:00
|
|
|
elif pin.xdr == 2:
|
2019-08-22 14:54:42 -06:00
|
|
|
pin_i0 = get_ineg(pin.i0, i_invert)
|
|
|
|
pin_i1 = get_ineg(pin.i1, i_invert)
|
2019-06-13 06:33:24 -06:00
|
|
|
if "o" in pin.dir:
|
|
|
|
if pin.xdr < 2:
|
2019-08-22 14:54:42 -06:00
|
|
|
pin_o = get_oneg(pin.o, o_invert)
|
2019-06-13 06:33:24 -06:00
|
|
|
elif pin.xdr == 2:
|
2019-08-22 14:54:42 -06:00
|
|
|
pin_o0 = get_oneg(pin.o0, o_invert)
|
|
|
|
pin_o1 = get_oneg(pin.o1, o_invert)
|
2019-06-11 11:57:55 -06:00
|
|
|
|
2019-06-15 10:01:37 -06:00
|
|
|
i = o = t = None
|
|
|
|
if "i" in pin.dir:
|
|
|
|
i = Signal(pin.width, name="{}_xdr_i".format(pin.name))
|
|
|
|
if "o" in pin.dir:
|
|
|
|
o = Signal(pin.width, name="{}_xdr_o".format(pin.name))
|
|
|
|
if pin.dir in ("oe", "io"):
|
|
|
|
t = Signal(1, name="{}_xdr_t".format(pin.name))
|
2019-06-13 06:33:24 -06:00
|
|
|
|
2019-06-11 11:57:55 -06:00
|
|
|
if pin.xdr == 0:
|
|
|
|
if "i" in pin.dir:
|
2019-06-15 10:01:37 -06:00
|
|
|
i = pin_i
|
2019-06-11 11:57:55 -06:00
|
|
|
if "o" in pin.dir:
|
2019-06-15 10:01:37 -06:00
|
|
|
o = pin_o
|
2019-06-11 11:57:55 -06:00
|
|
|
if pin.dir in ("oe", "io"):
|
2019-06-15 10:01:37 -06:00
|
|
|
t = ~pin.oe
|
2019-06-11 11:57:55 -06:00
|
|
|
elif pin.xdr == 1:
|
|
|
|
if "i" in pin.dir:
|
2019-06-13 06:33:24 -06:00
|
|
|
get_dff(pin.i_clk, i, pin_i)
|
2019-06-11 11:57:55 -06:00
|
|
|
if "o" in pin.dir:
|
2019-06-13 06:33:24 -06:00
|
|
|
get_dff(pin.o_clk, pin_o, o)
|
2019-06-11 11:57:55 -06:00
|
|
|
if pin.dir in ("oe", "io"):
|
2019-06-15 09:55:10 -06:00
|
|
|
get_dff(pin.o_clk, ~pin.oe, t)
|
2019-06-11 11:57:55 -06:00
|
|
|
elif pin.xdr == 2:
|
|
|
|
if "i" in pin.dir:
|
2019-06-13 06:33:24 -06:00
|
|
|
get_iddr(pin.i_clk, i, pin_i0, pin_i1)
|
2019-06-11 11:57:55 -06:00
|
|
|
if "o" in pin.dir:
|
2019-06-13 06:33:24 -06:00
|
|
|
get_oddr(pin.o_clk, pin_o0, pin_o1, o)
|
2019-06-11 11:57:55 -06:00
|
|
|
if pin.dir in ("oe", "io"):
|
2019-06-15 09:55:10 -06:00
|
|
|
get_dff(pin.o_clk, ~pin.oe, t)
|
2019-06-11 11:57:55 -06:00
|
|
|
else:
|
|
|
|
assert False
|
2019-06-13 06:33:24 -06:00
|
|
|
|
2019-06-15 09:55:10 -06:00
|
|
|
return (i, o, t)
|
2019-06-11 11:57:55 -06:00
|
|
|
|
2019-06-12 08:42:39 -06:00
|
|
|
def get_input(self, pin, port, attrs, invert):
|
2019-06-06 05:53:17 -06:00
|
|
|
self._check_feature("single-ended input", pin, attrs,
|
2019-06-11 11:57:55 -06:00
|
|
|
valid_xdrs=(0, 1, 2), valid_attrs=True)
|
2019-06-06 05:53:17 -06:00
|
|
|
m = Module()
|
2019-08-22 14:54:42 -06:00
|
|
|
i, o, t = self._get_xdr_buffer(m, pin, i_invert=invert)
|
2020-07-31 07:17:39 -06:00
|
|
|
for bit in range(pin.width):
|
2019-07-21 01:49:21 -06:00
|
|
|
m.submodules["{}_{}".format(pin.name, bit)] = Instance("IBUF",
|
2020-07-31 07:17:39 -06:00
|
|
|
i_I=port.io[bit],
|
2019-06-15 10:07:40 -06:00
|
|
|
o_O=i[bit]
|
|
|
|
)
|
2019-06-06 05:53:17 -06:00
|
|
|
return m
|
|
|
|
|
2019-06-12 08:42:39 -06:00
|
|
|
def get_output(self, pin, port, attrs, invert):
|
2019-06-06 05:53:17 -06:00
|
|
|
self._check_feature("single-ended output", pin, attrs,
|
2019-06-11 11:57:55 -06:00
|
|
|
valid_xdrs=(0, 1, 2), valid_attrs=True)
|
2019-06-06 05:53:17 -06:00
|
|
|
m = Module()
|
2019-08-22 14:54:42 -06:00
|
|
|
i, o, t = self._get_xdr_buffer(m, pin, o_invert=invert)
|
2020-08-02 10:48:26 -06:00
|
|
|
if self.toolchain == "Vivado":
|
|
|
|
for bit in range(pin.width):
|
|
|
|
m.submodules["{}_{}".format(pin.name, bit)] = Instance("OBUF",
|
|
|
|
i_I=o[bit],
|
|
|
|
o_O=port.io[bit]
|
|
|
|
)
|
|
|
|
elif self.toolchain == "Symbiflow":
|
|
|
|
m.d.comb += port.eq(self._invert_if(invert, o))
|
|
|
|
else:
|
|
|
|
assert False
|
2019-06-06 05:53:17 -06:00
|
|
|
return m
|
|
|
|
|
2019-06-12 08:42:39 -06:00
|
|
|
def get_tristate(self, pin, port, attrs, invert):
|
2020-08-26 08:57:31 -06:00
|
|
|
if self.toolchain == "Symbiflow":
|
2020-08-02 10:48:26 -06:00
|
|
|
return super().get_tristate(pin, port, attrs, invert)
|
|
|
|
|
2019-06-06 05:53:17 -06:00
|
|
|
self._check_feature("single-ended tristate", pin, attrs,
|
2019-06-11 11:57:55 -06:00
|
|
|
valid_xdrs=(0, 1, 2), valid_attrs=True)
|
2019-06-06 05:53:17 -06:00
|
|
|
m = Module()
|
2019-08-22 14:54:42 -06:00
|
|
|
i, o, t = self._get_xdr_buffer(m, pin, o_invert=invert)
|
2020-07-31 07:17:39 -06:00
|
|
|
for bit in range(pin.width):
|
2019-07-21 01:49:21 -06:00
|
|
|
m.submodules["{}_{}".format(pin.name, bit)] = Instance("OBUFT",
|
2019-06-15 09:55:10 -06:00
|
|
|
i_T=t,
|
2019-06-11 11:57:55 -06:00
|
|
|
i_I=o[bit],
|
2020-07-31 07:17:39 -06:00
|
|
|
o_O=port.io[bit]
|
2019-06-06 05:53:17 -06:00
|
|
|
)
|
|
|
|
return m
|
|
|
|
|
2019-06-12 08:42:39 -06:00
|
|
|
def get_input_output(self, pin, port, attrs, invert):
|
2020-08-26 08:57:31 -06:00
|
|
|
if self.toolchain == "Symbiflow":
|
2020-08-02 10:48:26 -06:00
|
|
|
return super().get_input_output(pin, port, attrs, invert)
|
|
|
|
|
2019-06-06 05:53:17 -06:00
|
|
|
self._check_feature("single-ended input/output", pin, attrs,
|
2019-06-11 11:57:55 -06:00
|
|
|
valid_xdrs=(0, 1, 2), valid_attrs=True)
|
2019-06-06 05:53:17 -06:00
|
|
|
m = Module()
|
2019-08-22 14:54:42 -06:00
|
|
|
i, o, t = self._get_xdr_buffer(m, pin, i_invert=invert, o_invert=invert)
|
2020-07-31 07:17:39 -06:00
|
|
|
for bit in range(pin.width):
|
2019-07-21 01:49:21 -06:00
|
|
|
m.submodules["{}_{}".format(pin.name, bit)] = Instance("IOBUF",
|
2019-06-15 09:55:10 -06:00
|
|
|
i_T=t,
|
2019-06-11 11:57:55 -06:00
|
|
|
i_I=o[bit],
|
|
|
|
o_O=i[bit],
|
2020-07-31 07:17:39 -06:00
|
|
|
io_IO=port.io[bit]
|
2019-06-06 05:53:17 -06:00
|
|
|
)
|
|
|
|
return m
|
|
|
|
|
2020-07-31 07:17:39 -06:00
|
|
|
def get_diff_input(self, pin, port, attrs, invert):
|
2020-08-26 08:57:31 -06:00
|
|
|
if self.toolchain == "Symbiflow":
|
2020-08-02 10:48:26 -06:00
|
|
|
return super().get_diff_input(pin, port, attrs, invert)
|
|
|
|
|
2019-06-06 05:53:17 -06:00
|
|
|
self._check_feature("differential input", pin, attrs,
|
2019-06-11 11:57:55 -06:00
|
|
|
valid_xdrs=(0, 1, 2), valid_attrs=True)
|
2019-06-06 05:53:17 -06:00
|
|
|
m = Module()
|
2019-08-22 14:54:42 -06:00
|
|
|
i, o, t = self._get_xdr_buffer(m, pin, i_invert=invert)
|
2020-07-31 07:17:39 -06:00
|
|
|
for bit in range(pin.width):
|
2019-07-21 01:49:21 -06:00
|
|
|
m.submodules["{}_{}".format(pin.name, bit)] = Instance("IBUFDS",
|
2020-07-31 07:17:39 -06:00
|
|
|
i_I=port.p[bit], i_IB=port.n[bit],
|
2019-06-11 11:57:55 -06:00
|
|
|
o_O=i[bit]
|
2019-06-06 05:53:17 -06:00
|
|
|
)
|
|
|
|
return m
|
|
|
|
|
2020-07-31 07:17:39 -06:00
|
|
|
def get_diff_output(self, pin, port, attrs, invert):
|
2020-08-26 08:57:31 -06:00
|
|
|
if self.toolchain == "Symbiflow":
|
2020-08-02 10:48:26 -06:00
|
|
|
return super().get_diff_output(pin, port, attrs, invert)
|
|
|
|
|
2019-06-06 05:53:17 -06:00
|
|
|
self._check_feature("differential output", pin, attrs,
|
2019-06-11 11:57:55 -06:00
|
|
|
valid_xdrs=(0, 1, 2), valid_attrs=True)
|
2019-06-06 05:53:17 -06:00
|
|
|
m = Module()
|
2019-08-22 14:54:42 -06:00
|
|
|
i, o, t = self._get_xdr_buffer(m, pin, o_invert=invert)
|
2020-07-31 07:17:39 -06:00
|
|
|
for bit in range(pin.width):
|
2019-07-21 01:49:21 -06:00
|
|
|
m.submodules["{}_{}".format(pin.name, bit)] = Instance("OBUFDS",
|
2019-06-11 11:57:55 -06:00
|
|
|
i_I=o[bit],
|
2020-07-31 07:17:39 -06:00
|
|
|
o_O=port.p[bit], o_OB=port.n[bit]
|
2019-06-06 05:53:17 -06:00
|
|
|
)
|
|
|
|
return m
|
|
|
|
|
2020-07-31 07:17:39 -06:00
|
|
|
def get_diff_tristate(self, pin, port, attrs, invert):
|
2020-08-26 08:57:31 -06:00
|
|
|
if self.toolchain == "Symbiflow":
|
2020-08-02 10:48:26 -06:00
|
|
|
return super().get_diff_tristate(pin, port, attrs, invert)
|
|
|
|
|
2019-06-06 05:53:17 -06:00
|
|
|
self._check_feature("differential tristate", pin, attrs,
|
2019-06-11 11:57:55 -06:00
|
|
|
valid_xdrs=(0, 1, 2), valid_attrs=True)
|
2019-06-06 05:53:17 -06:00
|
|
|
m = Module()
|
2019-08-22 14:54:42 -06:00
|
|
|
i, o, t = self._get_xdr_buffer(m, pin, o_invert=invert)
|
2020-07-31 07:17:39 -06:00
|
|
|
for bit in range(pin.width):
|
2019-07-21 01:49:21 -06:00
|
|
|
m.submodules["{}_{}".format(pin.name, bit)] = Instance("OBUFTDS",
|
2019-06-15 09:55:10 -06:00
|
|
|
i_T=t,
|
2019-06-11 11:57:55 -06:00
|
|
|
i_I=o[bit],
|
2020-07-31 07:17:39 -06:00
|
|
|
o_O=port.p[bit], o_OB=port.n[bit]
|
2019-06-06 05:53:17 -06:00
|
|
|
)
|
|
|
|
return m
|
|
|
|
|
2020-07-31 07:17:39 -06:00
|
|
|
def get_diff_input_output(self, pin, port, attrs, invert):
|
2020-08-26 08:57:31 -06:00
|
|
|
if self.toolchain == "Symbiflow":
|
2020-08-02 10:48:26 -06:00
|
|
|
return super().get_diff_input_output(pin, port, attrs, invert)
|
|
|
|
|
2019-06-06 05:53:17 -06:00
|
|
|
self._check_feature("differential input/output", pin, attrs,
|
2019-06-11 11:57:55 -06:00
|
|
|
valid_xdrs=(0, 1, 2), valid_attrs=True)
|
2019-06-06 05:53:17 -06:00
|
|
|
m = Module()
|
2019-08-22 14:54:42 -06:00
|
|
|
i, o, t = self._get_xdr_buffer(m, pin, i_invert=invert, o_invert=invert)
|
2020-07-31 07:17:39 -06:00
|
|
|
for bit in range(pin.width):
|
2019-07-21 01:49:21 -06:00
|
|
|
m.submodules["{}_{}".format(pin.name, bit)] = Instance("IOBUFDS",
|
2019-06-15 09:55:10 -06:00
|
|
|
i_T=t,
|
2019-06-11 11:57:55 -06:00
|
|
|
i_I=o[bit],
|
|
|
|
o_O=i[bit],
|
2020-07-31 07:17:39 -06:00
|
|
|
io_IO=port.p[bit], io_IOB=port.n[bit]
|
2019-06-06 05:53:17 -06:00
|
|
|
)
|
|
|
|
return m
|
2019-09-20 09:13:27 -06:00
|
|
|
|
2019-09-23 18:47:54 -06:00
|
|
|
# The synchronizer implementations below apply two separate but related timing constraints.
|
|
|
|
#
|
|
|
|
# First, the ASYNC_REG attribute prevents inference of shift registers from synchronizer FFs,
|
|
|
|
# and constraints the FFs to be placed as close as possible, ideally in one CLB. This attribute
|
|
|
|
# only affects the synchronizer FFs themselves.
|
|
|
|
#
|
|
|
|
# Second, the nmigen.vivado.false_path or nmigen.vivado.max_delay attribute affects the path
|
|
|
|
# into the synchronizer. If maximum input delay is specified, a datapath-only maximum delay
|
|
|
|
# constraint is applied, limiting routing delay (and therefore skew) at the synchronizer input.
|
|
|
|
# Otherwise, a false path constraint is used to omit the input path from the timing analysis.
|
|
|
|
|
2019-09-23 08:17:44 -06:00
|
|
|
def get_ff_sync(self, ff_sync):
|
2019-09-20 09:13:27 -06:00
|
|
|
m = Module()
|
2019-09-23 10:42:44 -06:00
|
|
|
flops = [Signal(ff_sync.i.shape(), name="stage{}".format(index),
|
|
|
|
reset=ff_sync._reset, reset_less=ff_sync._reset_less,
|
|
|
|
attrs={"ASYNC_REG": "TRUE"})
|
|
|
|
for index in range(ff_sync._stages)]
|
2019-09-23 18:47:54 -06:00
|
|
|
if ff_sync._max_input_delay is None:
|
|
|
|
flops[0].attrs["nmigen.vivado.false_path"] = "TRUE"
|
|
|
|
else:
|
2019-09-24 06:30:02 -06:00
|
|
|
flops[0].attrs["nmigen.vivado.max_delay"] = str(ff_sync._max_input_delay * 1e9)
|
2019-09-23 10:42:44 -06:00
|
|
|
for i, o in zip((ff_sync.i, *flops), flops):
|
2019-09-23 08:17:44 -06:00
|
|
|
m.d[ff_sync._o_domain] += o.eq(i)
|
2019-09-23 10:42:44 -06:00
|
|
|
m.d.comb += ff_sync.o.eq(flops[-1])
|
2019-09-20 09:13:27 -06:00
|
|
|
return m
|
2019-09-23 14:15:29 -06:00
|
|
|
|
2020-03-08 15:37:40 -06:00
|
|
|
def get_async_ff_sync(self, async_ff_sync):
|
2019-09-23 14:15:29 -06:00
|
|
|
m = Module()
|
2020-03-08 15:37:40 -06:00
|
|
|
m.domains += ClockDomain("async_ff", async_reset=True, local=True)
|
2019-09-23 14:15:29 -06:00
|
|
|
flops = [Signal(1, name="stage{}".format(index), reset=1,
|
|
|
|
attrs={"ASYNC_REG": "TRUE"})
|
2020-03-08 15:37:40 -06:00
|
|
|
for index in range(async_ff_sync._stages)]
|
|
|
|
if async_ff_sync._max_input_delay is None:
|
2019-09-23 18:47:54 -06:00
|
|
|
flops[0].attrs["nmigen.vivado.false_path"] = "TRUE"
|
|
|
|
else:
|
2020-03-08 15:37:40 -06:00
|
|
|
flops[0].attrs["nmigen.vivado.max_delay"] = str(async_ff_sync._max_input_delay * 1e9)
|
2019-09-23 14:15:29 -06:00
|
|
|
for i, o in zip((0, *flops), flops):
|
2020-03-08 15:37:40 -06:00
|
|
|
m.d.async_ff += o.eq(i)
|
|
|
|
|
2020-03-12 14:28:41 -06:00
|
|
|
if async_ff_sync._edge == "pos":
|
2020-03-15 03:33:22 -06:00
|
|
|
m.d.comb += ResetSignal("async_ff").eq(async_ff_sync.i)
|
2020-03-08 15:37:40 -06:00
|
|
|
else:
|
2020-03-15 03:33:22 -06:00
|
|
|
m.d.comb += ResetSignal("async_ff").eq(~async_ff_sync.i)
|
2020-03-08 15:37:40 -06:00
|
|
|
|
2019-09-23 14:15:29 -06:00
|
|
|
m.d.comb += [
|
2020-08-25 21:19:13 -06:00
|
|
|
ClockSignal("async_ff").eq(ClockSignal(async_ff_sync._o_domain)),
|
2020-03-08 15:37:40 -06:00
|
|
|
async_ff_sync.o.eq(flops[-1])
|
2019-09-23 14:15:29 -06:00
|
|
|
]
|
2020-03-08 15:37:40 -06:00
|
|
|
|
2019-09-23 14:15:29 -06:00
|
|
|
return m
|