ShiftRegister constructor
Creates a new shift register with specified depth which is only active
when enabled.
If reset is provided, it will reset synchronously with clk or
aynchronously if asyncReset is true. The reset will reset all stages
to a default of 0 or to the provided resetValue. If resetValue is a
List the stages will reset to the corresponding value in the list.
Implementation
ShiftRegister(
Logic dataIn, {
required Logic clk,
required this.depth,
Logic? enable,
Logic? reset,
bool asyncReset = false,
dynamic resetValue,
this.dataName = 'data',
super.reserveName,
super.reserveDefinitionName,
String? definitionName,
}) : width = dataIn.width,
super(
name: '${dataName}_shift_register',
definitionName: definitionName ??
'ShiftRegister_W${dataIn.width}'
'_D$depth') {
dataIn = addInput('${dataName}_in', dataIn, width: width);
clk = addInput('clk', clk);
addOutput('${dataName}_out', width: width);
final Map<Logic, dynamic>? resetValues;
final List<Logic>? resetValueList;
if (reset != null) {
reset = addInput('reset', reset);
resetValueList =
makeResetValues(resetValue, numEntries: depth, entryWidth: width);
resetValues = {};
} else {
resetValueList = null;
resetValues = null;
}
var dataStage = dataIn;
var conds = <Conditional>[];
for (var i = 0; i < depth; i++) {
final stageI = addOutput(_stageName(i), width: width);
conds.add(stageI < dataStage);
resetValues?[stageI] = resetValueList![i];
dataStage = stageI;
}
if (enable != null) {
enable = addInput('enable', enable);
conds = [If(enable, then: conds)];
}
Sequential.multi(
[clk],
reset: reset,
resetValues: resetValues,
asyncReset: asyncReset,
conds,
);
dataOut <= dataStage;
}