Skip to content

Commit

Permalink
gen/fhdl/verilog: Add Verilog Timescale generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
enjoy-digital committed Nov 4, 2022
1 parent 2ae4450 commit adea787
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions litex/gen/fhdl/verilog.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ def _print_separator(msg=""):
r += "\n"
return r

# ------------------------------------------------------------------------------------------------ #
# TIMESCALE #
# ------------------------------------------------------------------------------------------------ #

def _print_timescale(time_unit="1ns", time_precision="1ps"):
r = f"`timescale {time_unit} / {time_precision}\n"
return r

# ------------------------------------------------------------------------------------------------ #
# RESERVED KEYWORDS #
# ------------------------------------------------------------------------------------------------ #
Expand Down Expand Up @@ -517,9 +525,17 @@ def __getitem__(self, k):
return (k, "true")

def convert(f, ios=set(), name="top", platform=None,
special_overrides = dict(),
attr_translate = DummyAttrTranslate(),
regular_comb = True):
# Verilog parameters.
special_overrides = dict(),
attr_translate = DummyAttrTranslate(),
regular_comb = True,
# Sim parameters.
time_unit = "1ns",
time_precision = "1ps",
):

# Build Logic.
# ------------

# Create ConvOutput.
r = ConvOutput()
Expand Down Expand Up @@ -584,11 +600,18 @@ def convert(f, ios=set(), name="top", platform=None,
# Build Verilog.
# --------------
verilog = ""
# Banner.
verilog += _print_banner(
filename = name,
device = getattr(platform, "device", "Unknown")
)

# Timescale.
verilog += _print_timescale(
time_unit = time_unit,
time_precision = time_precision
)

# Module Definition.
verilog += _print_separator("Module")
verilog += _print_module(f, ios, name, ns, attr_translate)
Expand Down Expand Up @@ -622,6 +645,7 @@ def convert(f, ios=set(), name="top", platform=None,
# Module End.
verilog += "endmodule\n"

# Trailer.
verilog += _print_trailer()

r.set_main_source(verilog)
Expand Down

0 comments on commit adea787

Please sign in to comment.