Counter constructor
- List<
SumInterface> interfaces, { - required Logic clk,
- required Logic reset,
- Logic? restart,
- dynamic resetValue = 0,
- bool asyncReset = false,
- dynamic maxValue,
- dynamic minValue = 0,
- int? width,
- bool saturates = false,
- String name = 'counter',
- bool reserveName = false,
- bool reserveDefinitionName = false,
- String? definitionName,
Creates a counter that increments according to the provided interfaces.
The width can be either explicitly provided or inferred from other
values such as a maxValue, minValue, or resetValue that contain
width information (e.g. a LogicValue), or by making it large enough to
fit maxValue, or by inspecting widths of interfaces. There must be
enough information provided to determine the width.
If no maxValue is provided, one will be inferred by the maximum that can
fit inside of the width.
The restart input can be used to restart the counter to a new value, but
also continue to increment in that same cycle. This is distinct from
reset which will reset the counter, holding the count at resetValue.
If saturates is true, then it will saturate at the maxValue and
minValue. If false, will wrap around (overflow/underflow) at the
maxValue and minValue. The equalsMax, equalsMin, overflowed,
and underflowed outputs can be used to determine if the sum is at the
maximum, minimum, (would have) overflowed, or (would have) underflowed,
respectively.
Implementation
Counter(
super.interfaces, {
required Logic clk,
required Logic reset,
Logic? restart,
dynamic resetValue = 0,
this.asyncReset = false,
super.maxValue,
super.minValue = 0,
super.width,
super.saturates,
super.name = 'counter',
super.reserveName,
super.reserveDefinitionName,
String? definitionName,
}) : super(
initialValue: resetValue,
definitionName:
definitionName ?? 'Counter_L${interfaces.length}}') {
this.clk = addInput('clk', clk);
this.reset = addInput('reset', reset);
if (restart != null) {
this.restart = addInput('restart', restart);
} else {
this.restart = null;
}
addOutput('count', width: width);
_buildLogic();
}