MyHDL generators are standard Python generators with specialized yield statements. In hardware description languages, the equivalent statements are called sensitivity lists. The general format of yield statements in in MyHDL generators is:
yield clause [, clause ...]
When a generator executes a yield statement, its execution is suspended at that point. At the same time, each clause is a trigger object which defines the condition upon which the generator should be resumed. However, per invocation of a yield statement, the generator resumes exactly once, regardless of the number of clauses. This happens on the first trigger that occurs.
In this section, the trigger objects and their functionality will be described.
Some MyHDL objects that are described elsewhere can directly be used
as trigger objects. In particular, a signal can be used as
a trigger object. Whenever a signal changes value, the generator
resumes. Likewise, the objects referred to by the signal attributes
posedge and negedge are trigger objects. The generator
resumes on the occurrence of a positive or a negative edge on the
signal, respectively. An edge occurs when there is a change from
false to true (positive) or vice versa (negative).
For the full description of the Signal class and its
attributes, see section 7.2.1.
Furthermore, MyHDL generators can be used as clauses in yield
statements. Such a generator is forked, and starts operating
immediately, while the original generator
waits for it to complete. The original generator resumes when the
forked generator returns.
In addition, the following functions return trigger objects:
| t) |
| arg [, arg ...]) |
Finally, as a special case, the Python None object can be
present in a yield statement. It is the do-nothing
trigger object. The generator immediately resumes, as if no
yield statement were present. This can be useful if the
yield statement also has generator clauses: those generators
are forked, while the original generator resumes immediately.
About this document