Skip to content

Commit

Permalink
Proposed solution to ResetSynchronizer redundancy.
Browse files Browse the repository at this point in the history
  • Loading branch information
awygle committed Mar 5, 2020
1 parent e8f8998 commit 0b75029
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
13 changes: 11 additions & 2 deletions nmigen/lib/cdc.py
Expand Up @@ -125,13 +125,15 @@ class ResetSynchronizer(Elaboratable):
Define the ``get_reset_sync`` platform method to override the implementation of
:class:`ResetSynchronizer`, e.g. to instantiate library cells directly.
"""
def __init__(self, arst, *, domain="sync", stages=2, max_input_delay=None):
def __init__(self, arst, *, domain="sync", stages=2, max_input_delay=None, reset_less=False):

This comment has been minimized.

Copy link
@whitequark

whitequark Mar 5, 2020

Member

I strongly dislike that in the reset_less=True case, the argument domain is accepted and ignored. (It's also not what reset_less means elsewhere.) This is why I suggested domain=None, which makes it clear that no domain is being reset. (It's still a flawed solution, but it's hopefully less confusing.)

_check_stages(stages)

self.arst = arst
self.rst = Signal()

self._domain = domain
self._stages = stages
self._reset_less = reset_less

self._max_input_delay = None

Expand All @@ -150,11 +152,18 @@ def elaborate(self, platform):
for index in range(self._stages)]
for i, o in zip((0, *flops), flops):
m.d.reset_sync += o.eq(i)

m.d.comb += [
ClockSignal("reset_sync").eq(ClockSignal(self._domain)),
ResetSignal("reset_sync").eq(self.arst),
ResetSignal(self._domain).eq(flops[-1])
self.rst.eq(ResetSignal(self._domain))
]

if not self._reset_less:
m.d.comb += [
ResetSignal(self._domain).eq(flops[-1]),
]

return m


Expand Down
7 changes: 2 additions & 5 deletions nmigen/lib/fifo.py
Expand Up @@ -373,13 +373,10 @@ def elaborate(self, platform):
r_rst = Signal()

# Create clock domain for ResetSynchronizer
rst_domain = ClockDomain(name="rst_cdc", async_reset=True, local=True)
m.domains += rst_domain
rst_cdc = m.submodules.rst_cdc = \
ResetSynchronizer(w_rst, domain = "rst_cdc")
ResetSynchronizer(w_rst, domain=self._r_domain, reset_less=True)
m.d.comb += [
rst_domain.clk.eq(ClockSignal(domain = self._r_domain)),
r_rst.eq(ResetSignal(domain = "rst_cdc")),
r_rst.eq(rst_cdc.rst),
]

# Decode Gray code counter synchronized from write domain to overwrite binary
Expand Down

0 comments on commit 0b75029

Please sign in to comment.