Skip to content

sim: call .aclose() on TickTrigger in .until() and .repeat() #1590

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions amaranth/sim/_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,15 @@ async def until(self, condition: ValueLike):
raise TypeError(f"The shape of a condition may only be `signed` or `unsigned`, "
f"not {shape!r}")
tick = self.sample(condition).__aiter__()
done = False
while not done:
clk, rst, *values, done = await tick.__anext__()
if rst:
raise DomainReset
return tuple(values)
try:
done = False
while not done:
clk, rst, *values, done = await tick.__anext__()
if rst:
raise DomainReset
return tuple(values)
finally:
await tick.aclose()

async def repeat(self, count: int):
"""Repeat this trigger a specific number of times.
Expand Down Expand Up @@ -400,12 +403,15 @@ async def repeat(self, count: int):
if count <= 0:
raise ValueError(f"Repeat count must be a positive integer, not {count!r}")
tick = self.__aiter__()
for _ in range(count):
clk, rst, *values = await tick.__anext__()
if rst:
raise DomainReset
assert clk
return tuple(values)
try:
for _ in range(count):
clk, rst, *values = await tick.__anext__()
if rst:
raise DomainReset
assert clk
return tuple(values)
finally:
await tick.aclose()

def _collect_trigger(self):
clk_polarity = (1 if self._domain.clk_edge == "pos" else 0)
Expand Down
Loading