You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`sim.tick()` replaces the existing `Tick()`. It returns a trigger object that either can be awaited directly, or made conditional through `.until()`.
52
54
55
+
The `testbench_helper` decorator indicates that this function is only designed to be called from testbench processes and will raise an exception if called elsewhere.
56
+
53
57
> **Note**
54
58
> This simplified example does not include any way of specifying the clock domain of the interface and as such is only directly applicable to single domain simulations.
55
59
> A way to attach clock domain information to interfaces is desireable, but out of scope for this RFC.
@@ -156,10 +160,7 @@ The async function must accept an argument `sim`, which will be passed a simulat
156
160
The new optional named argument `background` registers the testbench as a background process when true.
157
161
Processes created through `add_process` are always registered as background processes (except when registering legacy non-async generator functions).
158
162
159
-
The simulator context has the following properties and methods:
160
-
-`process_type`
161
-
- Property, `ProcessType`, indicates the type of the current process.
162
-
This property allows a generic simulation helper function to assert that it's being run under the appropriate process type.
163
+
The simulator context has the following methods:
163
164
-`get(expr: Value) -> int`
164
165
-`get(expr: ValueCastable) -> any`
165
166
- Returns the value of `expr` when awaited.
@@ -184,36 +185,45 @@ The simulator context has the following properties and methods:
184
185
- Create a combinable trigger object for advancing simulation by `interval` seconds.
185
186
-`changed(*signals)`
186
187
- Create a combinable trigger object for advancing simulation until any signal in `signals` changes.
187
-
-`edge(signal, value)`
188
+
-`edge(signal, value: int)`
188
189
- Create a combinable trigger object for advancing simulation until `signal` is changed to `value`.
189
190
`signal` must be a 1-bit signal or a 1-bit slice of a signal.
190
-
`value`is a boolean where true indicates rising edge and false indicates falling edge.
191
+
Valid values for `value`are `1` for rising edge and `0` for falling edge.
191
192
-`posedge(signal)`
192
193
-`negedge(signal)`
193
194
- Aliases for `edge(signal, 1)` and `edge(signal, 0)` respectively.
194
195
-`critical()`
195
196
- Context manager.
196
197
If the current process is a background process, `async with sim.critical():` makes it a non-background process for the duration of the statement.
197
198
198
-
The `ProcessType` enum has the following members:
199
-
-`BikeshedProcess`
200
-
- The current process is a process added by `add_process`.
201
-
-`BikeshedTestbench`
202
-
- The current process is a testbench process added by `add_testbench`.
203
-
204
-
A domain trigger object has the following methods:
199
+
A domain trigger object is immutable and has the following methods:
205
200
-`__await__()`
206
201
- Advance simulation. No value is returned.
207
202
-`until(condition)`
208
203
- Repeat the trigger until `condition` is true.
209
204
`condition` is an arbitrary Amaranth expression.
210
205
If `condition` is initially true, `await` will return immediately without advancing simulation.
211
206
The return value is an unspecified awaitable with `await` as the only defined operation.
207
+
It is only awaitable once and awaiting it returns no value.
208
+
- Example implementation:
209
+
```python
210
+
asyncdefuntil(self, condition):
211
+
whilenotawaitself._sim.get(condition):
212
+
awaitself
213
+
```
212
214
-`repeat(times: int)`
213
215
- Repeat the trigger `times` times.
216
+
Valid values are `times >=0`.
214
217
The return value is an unspecified awaitable with`await`as the only defined operation.
215
-
216
-
A combinable trigger object has the following methods:
218
+
It is only awaitable once and awaiting it returns no value.
219
+
- Example implementation:
220
+
```python
221
+
asyncdefrepeat(self, times):
222
+
for _ inrange(times):
223
+
awaitself
224
+
```
225
+
226
+
A combinable trigger objectis immutable and has the following methods:
217
227
-`__await__()`
218
228
- Advance simulation andreturn the value(s) of the trigger(s).
219
229
-`delay`and`edge` triggers return`True` when they are hit, otherwise `False`.
@@ -230,6 +240,10 @@ A combinable trigger object has the following methods:
230
240
- Create a new trigger object by copying the current objectand appending another trigger.
231
241
- Awaiting the returned trigger object pauses the process until the first of the combined triggers hit, i.e. the triggers are combined using OR semantics.
232
242
243
+
To ensure testbench helper functions are only called from a testbench process, the `amaranth.sim.testbench_helper` decorator is added.
244
+
The function wrapper expects the first positional argument (or second, after `self`or`cls`if decorating a method/classmethod) to be a simulator context, and will raise`TypeError`ifnot.
245
+
If the function is called outside a testbench process, an exception will be raised.
246
+
233
247
`Tick()`, `Delay()`, `Active()`and`Passive()`as well as the ability to pass generator coroutines as`process` are deprecated and removed in a future version.
0 commit comments