back.pysim: check for a clock being added twice.
This commit adds a best-effort error for a common mistake of adding a clock driving the same domain twice, such as a result of a copy-paste error. Fixes #27.
This commit is contained in:
parent
d2d8c2b8bf
commit
066dd799e8
2 changed files with 12 additions and 0 deletions
|
|
@ -366,6 +366,7 @@ class Simulator:
|
|||
self._delta = 0.
|
||||
self._epsilon = 1e-10
|
||||
self._fastest_clock = self._epsilon
|
||||
self._all_clocks = set() # {str/domain}
|
||||
self._state = _State()
|
||||
|
||||
self._processes = set() # {process}
|
||||
|
|
@ -426,6 +427,9 @@ class Simulator:
|
|||
def add_clock(self, period, phase=None, domain="sync"):
|
||||
if self._fastest_clock == self._epsilon or period < self._fastest_clock:
|
||||
self._fastest_clock = period
|
||||
if domain in self._all_clocks:
|
||||
raise ValueError("Domain '{}' already has a clock driving it"
|
||||
.format(domain))
|
||||
|
||||
half_period = period / 2
|
||||
if phase is None:
|
||||
|
|
@ -440,6 +444,7 @@ class Simulator:
|
|||
yield clk.eq(0)
|
||||
yield Delay(half_period)
|
||||
self.add_process(clk_process)
|
||||
self._all_clocks.add(domain)
|
||||
|
||||
def __enter__(self):
|
||||
if self._vcd_file:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue