Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib.fifo.AsyncFFSynchronizer: check input and output signal width #517

Merged
merged 1 commit into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 12 additions & 4 deletions nmigen/lib/cdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,24 @@ class AsyncFFSynchronizer(Elaboratable):
def __init__(self, i, o, *, o_domain="sync", stages=2, async_edge="pos", max_input_delay=None):
_check_stages(stages)

if len(i) != 1:
raise ValueError("AsyncFFSynchronizer input width must be 1, not {}"
.format(len(i)))
if len(o) != 1:
raise ValueError("AsyncFFSynchronizer output width must be 1, not {}"
.format(len(o)))

if async_edge not in ("pos", "neg"):
raise ValueError("AsyncFFSynchronizer async edge must be one of 'pos' or 'neg', "
"not {!r}"
.format(async_edge))

self.i = i
self.o = o

self._o_domain = o_domain
self._stages = stages

if async_edge not in ("pos", "neg"):
raise ValueError("AsyncFFSynchronizer async edge must be one of 'pos' or 'neg', "
"not {!r}"
.format(async_edge))
self._edge = async_edge

self._max_input_delay = max_input_delay
Expand Down
8 changes: 8 additions & 0 deletions tests/test_lib_cdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ def test_edge_wrong(self):
r"^AsyncFFSynchronizer async edge must be one of 'pos' or 'neg', not 'xxx'$"):
AsyncFFSynchronizer(Signal(), Signal(), o_domain="sync", async_edge="xxx")

def test_width_wrong(self):
with self.assertRaisesRegex(ValueError,
r"^AsyncFFSynchronizer input width must be 1, not 2$"):
AsyncFFSynchronizer(Signal(2), Signal(), o_domain="sync")
with self.assertRaisesRegex(ValueError,
r"^AsyncFFSynchronizer output width must be 1, not 2$"):
AsyncFFSynchronizer(Signal(), Signal(2), o_domain="sync")

def test_pos_edge(self):
i = Signal()
o = Signal()
Expand Down