self._propagate_domains_down()
return new_domains
- def _insert_domain_resets(self):
- from .xfrm import ResetInserter
-
- resets = {cd.name: cd.rst for cd in self.domains.values() if cd.rst is not None}
- return ResetInserter(resets)(self)
-
def _lower_domain_signals(self):
from .xfrm import DomainLowerer
fragment = SampleLowerer()(self)
new_domains = fragment._propagate_domains(missing_domain)
fragment._resolve_hierarchy_conflicts()
- fragment = fragment._insert_domain_resets()
fragment = fragment._lower_domain_signals()
if ports is None:
fragment._propagate_ports(ports=(), all_undef_as_ports=True)
return not isinstance(value, (ClockSignal, ResetSignal))
def on_ClockSignal(self, value):
- cd = self._resolve(value.domain, value)
- return cd.clk
+ domain = self._resolve(value.domain, value)
+ return domain.clk
def on_ResetSignal(self, value):
- cd = self._resolve(value.domain, value)
- if cd.rst is None:
+ domain = self._resolve(value.domain, value)
+ if domain.rst is None:
if value.allow_reset_less:
return Const(0)
else:
raise DomainError("Signal {!r} refers to reset of reset-less domain '{}'"
.format(value, value.domain))
- return cd.rst
+ return domain.rst
+
+ def _insert_resets(self, fragment):
+ for domain_name, signals in fragment.drivers.items():
+ if domain_name is None:
+ continue
+ domain = fragment.domains[domain_name]
+ if domain.rst is None:
+ continue
+ stmts = [signal.eq(Const(signal.reset, signal.nbits))
+ for signal in signals if not signal.reset_less]
+ fragment.add_statements(Switch(domain.rst, {1: stmts}))
def on_fragment(self, fragment):
self.domains = fragment.domains
new_fragment = super().on_fragment(fragment)
+ self._insert_resets(new_fragment)
return new_fragment
""")
def test_lower_drivers(self):
+ sync = ClockDomain()
pix = ClockDomain()
f = Fragment()
- f.add_domains(pix)
+ f.add_domains(sync, pix)
f.add_driver(ClockSignal("pix"), None)
f.add_driver(ResetSignal("pix"), "sync")
def test_lower(self):
sync = ClockDomain()
f = Fragment()
+ f.add_domains(sync)
f.add_statements(
self.uv.eq(1)
)
(switch (sig c)
(case 1 (eq (sig s) (const 1'd0)))
)
+ (switch (sig rst)
+ (case 1 (eq (sig s) (const 1'd0)))
+ )
)
""")