Serializer constructor
Build a Serializer that takes the array deserialized
and sequences it
onto the serialized output.
Delivers one element per clock while enable
is high (if connected). If flopInput
is true, the
Serializer is configured to latch the input data and hold it until
done is asserted after the full LogicArray
deserialized
is
transferred. This will delay the serialized output by one cycle.
Implementation
Serializer(LogicArray deserialized,
{required Logic clk,
required Logic reset,
Logic? enable,
bool flopInput = false,
super.name = 'serializer'}) {
clk = addInput('clk', clk);
reset = addInput('reset', reset);
if (enable != null) {
enable = addInput('enable', enable);
}
deserialized = addInputArray('deserialized', deserialized,
dimensions: deserialized.dimensions,
elementWidth: deserialized.elementWidth);
addOutput('count', width: log2Ceil(deserialized.dimensions[0]));
addOutput('done');
final reducedDimensions = List<int>.from(deserialized.dimensions)
..removeAt(0);
if (deserialized.dimensions.length > 1) {
addOutputArray('serialized',
dimensions: reducedDimensions,
elementWidth: deserialized.elementWidth);
} else {
addOutput('serialized', width: deserialized.elementWidth);
}
final cnt = Counter.simple(
clk: clk,
reset: reset,
enable: enable,
maxValue: deserialized.elements.length - 1);
final latchInput = (enable ?? Const(1)) & ~cnt.count.or();
count <=
(flopInput
? flop(clk, reset: reset, en: enable, cnt.count)
: cnt.count);
final dataOutput =
LogicArray(deserialized.dimensions, deserialized.elementWidth);
for (var i = 0; i < deserialized.elements.length; i++) {
dataOutput.elements[i] <=
(flopInput
? flop(
clk, reset: reset, en: latchInput, deserialized.elements[i])
: deserialized.elements[i]);
}
serialized <= dataOutput.elements.selectIndex(count);
done <=
(flopInput
? flop(clk, reset: reset, en: enable, cnt.equalsMax)
: cnt.equalsMax);
}