Skip to content

Commit 804b00c

Browse files
zypwhitequark
authored andcommitted
build: Replace default_clk_frequency with default_clk_period.
1 parent b488e62 commit 804b00c

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

amaranth/build/plat.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import textwrap
66
import re
77
import jinja2
8+
import warnings
89

910
from .. import __version__
1011
from .._toolchain import *
@@ -45,11 +46,25 @@ def default_clk_constraint(self):
4546

4647
@property
4748
def default_clk_frequency(self):
49+
# TODO(amaranth-0.7): remove
50+
warnings.warn(
51+
f"Per RFC 66, `default_clk_frequency` is deprecated. Use `default_clk_period` instead."
52+
f" instead.",
53+
DeprecationWarning, stacklevel=1)
54+
55+
constraint = self.default_clk_constraint
56+
if constraint is None:
57+
raise AttributeError("Platform '{}' does not constrain its default clock"
58+
.format(type(self).__qualname__))
59+
return constraint.period.hertz
60+
61+
@property
62+
def default_clk_period(self):
4863
constraint = self.default_clk_constraint
4964
if constraint is None:
5065
raise AttributeError("Platform '{}' does not constrain its default clock"
5166
.format(type(self).__qualname__))
52-
return constraint.frequency
67+
return constraint.period
5368

5469
def add_file(self, filename, content):
5570
if not isinstance(filename, str):

amaranth/vendor/_siliconblue.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Currently owned by Lattice, originally designed and built by a startup called SiliconBlue, which
22
# was acquired by Lattice. The primitives are prefixed with `SB_` for that reason.
33

4+
import math
45
from abc import abstractmethod
56

67
from ..hdl import *
@@ -382,21 +383,21 @@ def create_missing_domain(self, name):
382383
i_CLKHFPU=1,
383384
p_CLKHF_DIV=f"0b{self.hfosc_div:02b}",
384385
o_CLKHF=clk_i)
385-
delay = int(100e-6 * self.default_clk_frequency)
386+
delay = 1 + math.ceil(Period(us=100) / self.default_clk_period)
386387
# Internal low-speed clock: 10 KHz.
387388
elif self.default_clk == "SB_LFOSC":
388389
clk_i = Signal()
389390
m.submodules += Instance("SB_LFOSC",
390391
i_CLKLFEN=1,
391392
i_CLKLFPU=1,
392393
o_CLKLF=clk_i)
393-
delay = int(100e-6 * self.default_clk_frequency)
394+
delay = 1 + math.ceil(Period(us=100) / self.default_clk_period)
394395
# User-defined clock signal.
395396
else:
396397
clk_io = self.request(self.default_clk, dir="-")
397398
m.submodules.clk_buf = clk_buf = io.Buffer("i", clk_io)
398399
clk_i = clk_buf.i
399-
delay = int(15e-6 * self.default_clk_frequency)
400+
delay = 1 + math.ceil(Period(us=15) / self.default_clk_period)
400401

401402
if self.default_rst is not None:
402403
rst_io = self.request(self.default_rst, dir="-")

docs/_code/led_blinker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def elaborate(self, platform):
77

88
led = platform.request("led")
99

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

1313
with m.If(timer == half_freq):

0 commit comments

Comments
 (0)