|
2 | 2 | import warnings
|
3 | 3 |
|
4 | 4 | from .._utils import deprecated
|
5 |
| -from ..hdl import Value, ValueLike, MemoryData, ClockDomain, Fragment |
| 5 | +from ..hdl import Value, ValueLike, MemoryData, ClockDomain, Fragment, Period |
6 | 6 | from ..hdl._ir import DriverConflict
|
7 | 7 | from ._base import BaseEngine
|
8 | 8 | from ._async import DomainReset, BrokenTrigger
|
@@ -35,8 +35,8 @@ class Simulator:
|
35 | 35 |
|
36 | 36 | 2. Processes, clocks, and testbenches are added as necessary: ::
|
37 | 37 |
|
38 |
| - sim.add_clock(1e-6) |
39 |
| - sim.add_clock(1e-7, domain="fast") |
| 38 | + sim.add_clock(Period(MHz=1)) |
| 39 | + sim.add_clock(Period(MHz=10), domain="fast") |
40 | 40 | sim.add_process(process_instr_decoder)
|
41 | 41 | sim.add_testbench(testbench_cpu_execute)
|
42 | 42 |
|
@@ -118,12 +118,25 @@ def add_clock(self, period, *, phase=None, domain="sync", if_exists=False):
|
118 | 118 | if domain in self._clocked:
|
119 | 119 | raise DriverConflict(f"Domain {domain.name!r} already has a clock driving it")
|
120 | 120 |
|
121 |
| - period_fs = _seconds_to_femtos(period) |
| 121 | + if not isinstance(period, Period): |
| 122 | + # TODO(amaranth-0.7): remove |
| 123 | + warnings.warn( |
| 124 | + f"Per RFC 66, the `period` argument of `add_clock()` will only accept a `Period`" |
| 125 | + f" in the future.", |
| 126 | + DeprecationWarning, stacklevel=1) |
| 127 | + period = Period(s=period) |
| 128 | + |
122 | 129 | if phase is None:
|
123 |
| - phase_fs = _seconds_to_femtos(period / 2) |
124 |
| - else: |
125 |
| - phase_fs = _seconds_to_femtos(phase) |
126 |
| - self._engine.add_clock_process(domain.clk, phase=phase_fs, period=period_fs) |
| 130 | + phase = period / 2 |
| 131 | + elif not isinstance(phase, Period): |
| 132 | + # TODO(amaranth-0.7): remove |
| 133 | + warnings.warn( |
| 134 | + f"Per RFC 66, the `phase` argument of `add_clock()` will only accept a `Period`" |
| 135 | + f" (or `None`) in the future.", |
| 136 | + DeprecationWarning, stacklevel=1) |
| 137 | + phase = Period(s=phase) |
| 138 | + |
| 139 | + self._engine.add_clock_process(domain.clk, phase=phase.femtoseconds, period=period.femtoseconds) |
127 | 140 | self._clocked.add(domain)
|
128 | 141 |
|
129 | 142 | @staticmethod
|
@@ -315,9 +328,17 @@ def run_until(self, deadline, *, run_passive=None):
|
315 | 328 | f"The `run_passive` argument of `run_until()` has been removed as a part of "
|
316 | 329 | f"transition to RFC 36.",
|
317 | 330 | DeprecationWarning, stacklevel=1)
|
318 |
| - deadline_fs = _seconds_to_femtos(deadline) |
319 |
| - assert self._engine.now <= deadline_fs |
320 |
| - while self._engine.now < deadline_fs: |
| 331 | + |
| 332 | + if not isinstance(deadline, Period): |
| 333 | + # TODO(amaranth-0.7): remove |
| 334 | + warnings.warn( |
| 335 | + f"Per RFC 66, the `deadline` argument of `run_until()` will only accept a `Period`" |
| 336 | + f" in the future.", |
| 337 | + DeprecationWarning, stacklevel=1) |
| 338 | + deadline = Period(s=deadline) |
| 339 | + |
| 340 | + assert self._engine.now <= deadline.femtoseconds |
| 341 | + while self._engine.now < deadline.femtoseconds: |
321 | 342 | self.advance()
|
322 | 343 |
|
323 | 344 | def advance(self):
|
|
0 commit comments