Signal: allow to use integral Enum for reset value.

This commit is contained in:
Staf Verhaegen 2020-01-10 13:28:19 +01:00 committed by whitequark
parent 8184efd612
commit e4e26717be
2 changed files with 14 additions and 1 deletions

View file

@ -797,7 +797,7 @@ class Signal(Value, DUID):
name this ``Signal`` is assigned to. Name collisions are automatically resolved by
prepending names of objects that contain this ``Signal`` and by appending integer
sequences.
reset : int
reset : int or integral Enum
Reset (synchronous) or default (combinatorial) value.
When this ``Signal`` is assigned to in synchronous context and the corresponding clock
domain is reset, the ``Signal`` assumes the given value. When this ``Signal`` is unassigned
@ -834,6 +834,11 @@ class Signal(Value, DUID):
attrs=None, decoder=None, src_loc_at=0):
super().__init__(src_loc_at=src_loc_at)
if isinstance(reset, Enum):
reset = reset.value
if not isinstance(reset, int):
raise TypeError("Reset value has to be an int or an integral Enum")
# TODO(nmigen-0.2): move this to nmigen.compat and make it a deprecated extension
if min is not None or max is not None:
warnings.warn("instead of `Signal(min={min}, max={max})`, "