Skip to content

Commit

Permalink
build: Replace default_clk_frequency with default_clk_period.
Browse files Browse the repository at this point in the history
  • Loading branch information
zyp committed Sep 17, 2024
1 parent 2dfb5de commit 07485f3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
17 changes: 16 additions & 1 deletion amaranth/build/plat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import textwrap
import re
import jinja2
import warnings

from .. import __version__
from .._toolchain import *
Expand Down Expand Up @@ -45,11 +46,25 @@ def default_clk_constraint(self):

@property
def default_clk_frequency(self):
# TODO(amaranth-0.7): remove
warnings.warn(
f"Per RFC 66, `default_clk_frequency` is deprecated. Use `default_clk_period` instead."
f" instead.",
DeprecationWarning, stacklevel=1)

constraint = self.default_clk_constraint
if constraint is None:
raise AttributeError("Platform '{}' does not constrain its default clock"
.format(type(self).__qualname__))
return constraint.period.hertz

@property
def default_clk_period(self):
constraint = self.default_clk_constraint
if constraint is None:
raise AttributeError("Platform '{}' does not constrain its default clock"
.format(type(self).__qualname__))
return constraint.frequency
return constraint.period

def add_file(self, filename, content):
if not isinstance(filename, str):
Expand Down
6 changes: 3 additions & 3 deletions amaranth/vendor/_siliconblue.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,21 +382,21 @@ def create_missing_domain(self, name):
i_CLKHFPU=1,
p_CLKHF_DIV=f"0b{self.hfosc_div:02b}",
o_CLKHF=clk_i)
delay = int(100e-6 * self.default_clk_frequency)
delay = Period(us=100) // self.default_clk_period
# Internal low-speed clock: 10 KHz.
elif self.default_clk == "SB_LFOSC":
clk_i = Signal()
m.submodules += Instance("SB_LFOSC",
i_CLKLFEN=1,
i_CLKLFPU=1,
o_CLKLF=clk_i)
delay = int(100e-6 * self.default_clk_frequency)
delay = Period(us=100) // self.default_clk_period
# User-defined clock signal.
else:
clk_io = self.request(self.default_clk, dir="-")
m.submodules.clk_buf = clk_buf = io.Buffer("i", clk_io)
clk_i = clk_buf.i
delay = int(15e-6 * self.default_clk_frequency)
delay = Period(us=15) // self.default_clk_period

if self.default_rst is not None:
rst_io = self.request(self.default_rst, dir="-")
Expand Down
2 changes: 1 addition & 1 deletion docs/_code/led_blinker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def elaborate(self, platform):

led = platform.request("led")

half_freq = int(platform.default_clk_frequency // 2)
half_freq = int(platform.default_clk_period.hertz // 2)
timer = Signal(range(half_freq + 1))

with m.If(timer == half_freq):
Expand Down

0 comments on commit 07485f3

Please sign in to comment.