Skip to content

Commit ae7edf3

Browse files
committed
RFC #36: Clarifications and minor changes.
1 parent ea26684 commit ae7edf3

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

text/0036-async-testbench-functions.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ To allow a background process to ensure an operation is finished before end of s
9393

9494
```python
9595
async def packet_reader(sim, stream):
96-
while True
96+
while True:
9797
# Wait until stream has valid data.
9898
await sim.tick().until(stream.valid)
9999

@@ -133,8 +133,8 @@ Flop with configurable edge reset and posedge clock as a process:
133133
clk = Signal(); rst = Signal(); d = Signal(); q = Signal()
134134
def dff(rst_edge):
135135
async def process(sim):
136-
async for clk_val, rst_val in sim.posedge(clk).edge(rst, rst_edge):
137-
await sim.set(q, 0 if rst_val == rst_edge else await sim.get(d))
136+
async for clk_hit, rst_hit in sim.posedge(clk).edge(rst, rst_edge):
137+
await sim.set(q, 0 if rst_hit else await sim.get(d))
138138
return process
139139
sim.add_process(dff(rst_edge=0))
140140
```
@@ -162,16 +162,16 @@ The simulator context have the following methods:
162162
- `set(expr: ValueCastable, value: any)`
163163
- Set `expr` to `value` when awaited.
164164
When `expr` is a value-castable, the value will be converted through `.const()`.
165-
- `memory_read(instance: MemoryInstance, address)`
165+
- `memory_read(instance: MemoryInstance, address: int)`
166166
- Read the value from `address` in `instance` when awaited.
167-
- `memory_write(instance: MemoryInstance, address, value, mask=None)`
167+
- `memory_write(instance: MemoryInstance, address: int, value: int, mask:int = None)`
168168
- Write `value` to `address` in `instance` when awaited. If `mask` is given, only the corresponding bits are written.
169-
- `delay(interval)`
169+
- `delay(interval: float)`
170170
- Create a trigger object for advancing simulation by `interval` seconds.
171171
- `tick(domain="sync", *, context=None)`
172-
- Create a trigger object for advancing simulation by one tick of `domain`.
172+
- Create a trigger object for advancing simulation until the next active edge of the `domain` clock.
173173
When an elaboratable is passed to `context`, `domain` will be resolved from its perspective.
174-
- If `domain` is asynchronously reset while this is being awaited, `AsyncReset` is raised.
174+
- If `domain` is asynchronously reset while this is being awaited, `amaranth.sim.AsyncReset` is raised.
175175
- `changed(*signals)`
176176
- Create a trigger object for advancing simulation until any signal in `signals` changes.
177177
- `edge(signal, value)`
@@ -180,19 +180,18 @@ The simulator context have the following methods:
180180
- `posedge(signal)`
181181
- `negedge(signal)`
182182
- Aliases for `edge(signal, 1)` and `edge(signal, 0)` respectively.
183-
184-
`signal` is changed to `value`. `None` is a wildcard and will trigger on any change.
185183
- `critical()`
186-
- Return a context manager that ensures simulation won't terminate in the middle of the enclosed scope.
184+
- Context manager.
185+
If the current process is a background process, `async with sim.critical():` makes it a non-background process for the duration of the statement.
187186

188187
A trigger object has the following methods:
189188
- `__await__()`
190189
- Advance simulation and return the value(s) of the trigger(s).
191-
- `delay` and `tick` triggers return `True` when they are hit, otherwise `False`.
192-
- `changed` and `edge` triggers return the current value of the signals they are monitoring.
190+
- `delay`, `tick` and `edge` triggers return `True` when they are hit, otherwise `False`.
191+
- `changed` triggers return the current value of the signals they are monitoring.
193192
- `__aiter__()`
194-
- Return an async generator that repeatedly invokes `__await__()` and yields the returned values.
195-
- `delay(interval)`
193+
- Return an async generator that is equivalent to repeatedly awaiting the trigger object in an infinite loop.
194+
- `delay(interval: float)`
196195
- `tick(domain="sync", *, context=None)`
197196
- `changed(*signals)`
198197
- `edge(signal, value)`
@@ -203,6 +202,7 @@ A trigger object has the following methods:
203202
- Repeat the trigger until `condition` is true.
204203
`condition` is an arbitrary Amaranth expression.
205204
If `condition` is initially true, `await` will return immediately without advancing simulation.
205+
The return value is an unspecified awaitable with `await` as the only defined operation.
206206

207207
`Tick()`, `Delay()`, `Active()` and `Passive()` as well as the ability to pass generator coroutines as `process` are deprecated and removed in a future version.
208208

@@ -226,6 +226,7 @@ Other python libraries like [cocotb](https://docs.cocotb.org/en/stable/coroutine
226226
[unresolved-questions]: #unresolved-questions
227227

228228
- Bikeshed all the names.
229+
- (@whitequark) Should we go for `posedge` (Verilog convention) or `pos_edge` (Python convention)?
229230

230231
## Future possibilities
231232
[future-possibilities]: #future-possibilities

0 commit comments

Comments
 (0)