ScheduledFrameUnpacker<LogicType extends Logic> constructor
- required Logic clk,
- required Logic reset,
- required CountedFrame<
TypedLogicArray< loadFrame,LogicType, LogicValue> > - required Logic load,
- required Logic advance,
- required Logic clear,
- String name = 'scheduled_frame_unpacker',
Creates an explicitly scheduled counted-frame unpacker.
Implementation
ScheduledFrameUnpacker({
required Logic clk,
required Logic reset,
required CountedFrame<TypedLogicArray<LogicType, LogicValue>> loadFrame,
required Logic load,
required Logic advance,
required Logic clear,
String name = 'scheduled_frame_unpacker',
}) : lanes = _frameLaneCount(loadFrame),
super(
definitionName: 'ScheduledFrameUnpacker_N'
'${_frameLaneCount(loadFrame)}_W'
'${loadFrame.data.elementWidth}_'
'${payloadShapeIdentity(loadFrame)}',
name: name,
) {
if (loadFrame.countWidth < widthFor(lanes + 1)) {
throw ArgumentError.value(
loadFrame.countWidth,
'loadFrame.countWidth',
'Must represent every lane count through $lanes.',
);
}
if (!rohdPayloadsCompatible(loadFrame.data.arrayElements,
ignoreConstantNames: true)) {
throw ArgumentError('Frame lanes must have compatible payloads.');
}
clk = addInput('clk', clk);
reset = addInput('reset', reset);
this.loadFrame = addTypedInput('loadFrame', loadFrame);
this.load = addInput('load', load);
this.advance = addInput('advance', advance);
this.clear = addInput('clear', clear);
frame = addTypedPayloadOutput(
this,
'frame',
Frame<LogicType>(this.loadFrame.data.arrayElements.first.cloneTyped(),
name: '${name}_frame'));
addOutput('index', width: widthFor(lanes));
addOutput('active');
addOutput('finalElement');
addOutput('invalidCount');
final storedData =
this.loadFrame.data.cloneTyped(name: '${name}_stored_data');
final storedLast = Logic(name: '${name}_stored_last');
final storedCount = Logic(
name: '${name}_stored_count',
width: this.loadFrame.countWidth,
);
final countIsValid = this.loadFrame.validElements.neq(0) &
this.loadFrame.validElements.lte(lanes);
final validLoad =
(this.load & countIsValid & ~this.clear).named('${name}_valid_load');
final localFinalElement = active &
index.eq(
(storedCount - Const(1, width: storedCount.width))
.getRange(0, index.width),
);
frame.data <= storedData.arrayElements.selectIndex(index);
frame.last <= localFinalElement & storedLast;
finalElement <= localFinalElement;
invalidCount <= this.load & ~countIsValid;
Sequential(clk, reset: reset, resetValues: {
index: 0,
active: 0,
storedLast: 0,
storedCount: 0,
for (final lane in storedData.arrayElements) lane: 0,
}, [
If(this.clear, then: [
index < 0,
active < 0,
storedLast < 0,
storedCount < 0,
for (final lane in storedData.arrayElements) lane < 0,
], orElse: [
If(validLoad, then: [
storedData < this.loadFrame.data,
storedLast < this.loadFrame.last,
storedCount < this.loadFrame.validElements,
index < 0,
active < 1,
]),
If(this.advance & active & ~validLoad, then: [
If(localFinalElement, then: [
active < 0,
index < 0,
], orElse: [
index < index + 1,
]),
]),
]),
]);
}