Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/nmigen
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 8184efd61215
Choose a base ref
...
head repository: m-labs/nmigen
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e4e26717beed
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Jan 11, 2020

  1. Signal: allow to use integral Enum for reset value.

    Fatsie authored and whitequark committed Jan 11, 2020
    Copy the full SHA
    e4e2671 View commit details
Showing with 14 additions and 1 deletion.
  1. +6 −1 nmigen/hdl/ast.py
  2. +8 −0 nmigen/test/test_hdl_ast.py
7 changes: 6 additions & 1 deletion nmigen/hdl/ast.py
Original file line number Diff line number Diff line change
@@ -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 @@ def __init__(self, shape=None, *, name=None, reset=0, reset_less=False, min=None
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})`, "
8 changes: 8 additions & 0 deletions nmigen/test/test_hdl_ast.py
Original file line number Diff line number Diff line change
@@ -755,6 +755,14 @@ def test_reset(self):
self.assertEqual(s1.reset, 0b111)
self.assertEqual(s1.reset_less, True)

def test_reset_enum(self):
s1 = Signal(2, reset=UnsignedEnum.BAR)
self.assertEqual(s1.reset, 2)
with self.assertRaises(TypeError,
msg="Reset value has to be an int or an integral Enum"
):
Signal(1, reset=StringEnum.FOO)

def test_reset_narrow(self):
with self.assertWarns(SyntaxWarning,
msg="Reset value 8 requires 4 bits to represent, but the signal only has 3 bits"):