CircularPointer constructor
Creates a wrapping pointer over slots slots.
Implementation
CircularPointer(
Logic clk,
Logic reset,
Logic increment, {
required this.slots,
super.name = 'circular_pointer',
super.reserveName,
super.reserveDefinitionName,
String? definitionName,
}) : super(
definitionName:
definitionName ?? 'CircularPointer_S${slots}_W${increment.width}',
) {
if (slots < 2) {
throw RohdHclException('CircularPointer needs at least 2 slots, got '
'$slots.');
}
clk = addInput('clk', clk);
reset = addInput('reset', reset);
increment = addInput('increment', increment, width: increment.width);
final pointerWidth = widthFor(slots);
final sumWidth =
(pointerWidth > increment.width ? pointerWidth : increment.width) + 2;
final current = Logic(name: 'current', width: pointerWidth);
final sum = (current.zeroExtend(sumWidth) + increment.zeroExtend(sumWidth))
.named('sum', naming: Naming.mergeable);
final wrap = sum
.gte(Const(slots, width: sumWidth))
.named('wrapped', naming: Naming.mergeable);
final next = mux(wrap, sum - Const(slots, width: sumWidth), sum)
.slice(pointerWidth - 1, 0);
Sequential(clk, reset: reset, [
current < next,
]);
addOutput('pointer', width: pointerWidth) <= current;
addOutput('wrapped') <= wrap;
}