ReadyValidElasticPipeline<LogicType extends Logic> constructor
- required Logic clk,
- required Logic reset,
- required ReadyValidInterface<
LogicType> upstream, - required ReadyValidInterface<
LogicType> downstream, - required int depth,
- bool fallThrough = false,
- String name = 'ready_valid_pipeline',
Creates a pipeline of registered or fall-through stages.
Implementation
ReadyValidElasticPipeline(
{required Logic clk,
required Logic reset,
required ReadyValidInterface<LogicType> upstream,
required ReadyValidInterface<LogicType> downstream,
required this.depth,
this.fallThrough = false,
String name = 'ready_valid_pipeline'})
: super(
definitionName: 'ReadyValidElasticPipeline_D${depth}_'
'${fallThrough ? 'F' : 'R'}_'
'I${upstream.data.name}_O${downstream.data.name}_'
'${payloadShapesIdentity([upstream.data, downstream.data])}',
name: name) {
if (depth < 1) {
throw ArgumentError.value(depth, 'depth', 'Must be at least one.');
}
downstream.validatePayloadCompatibility(upstream.data);
this.clk = addInput('clk', clk);
this.reset = addInput('reset', reset);
this.upstream = addPairInterfacePorts(upstream, PairRole.consumer,
uniquify: (original) => 'upstream_$original');
this.downstream = addPairInterfaceFrom(
IrrevocableReadyValidInterface<LogicType>(downstream.data.cloneTyped()),
downstream,
PairRole.provider,
uniquify: (original) => 'downstream_$original',
);
final occupancyWidth = max(1, (depth + 1).log2Ceil);
addOutput('occupancy', width: occupancyWidth);
addOutput('empty');
addOutput('full');
var stageUpstream = this.upstream;
for (var index = 0; index < depth; index++) {
final lastStage = index == depth - 1;
final stageDownstream = lastStage
? this.downstream
: ReadyValidInterface<LogicType>(upstream.data.cloneTyped());
if (fallThrough) {
ReadyValidFallThroughBuffer<LogicType>(
clk: this.clk,
reset: this.reset,
upstream: stageUpstream,
downstream: stageDownstream,
name: '${name}_stage_$index');
} else {
ReadyValidRegister<LogicType>(
clk: this.clk,
reset: this.reset,
upstream: stageUpstream,
downstream: stageDownstream,
name: '${name}_stage_$index');
}
stageUpstream = stageDownstream;
}
final inputAccepted = this.upstream.accepted;
final outputAccepted = this.downstream.accepted;
final inputOnlyAccepted =
(inputAccepted & ~outputAccepted).named('${name}_input_only_accepted');
final outputOnlyAccepted =
(~inputAccepted & outputAccepted).named('${name}_output_only_accepted');
empty <= occupancy.eq(0);
full <= occupancy.eq(depth);
Sequential(this.clk, reset: this.reset, resetValues: {
occupancy: 0
}, [
If(inputOnlyAccepted, then: [occupancy < occupancy + 1]),
If(outputOnlyAccepted, then: [occupancy < occupancy - 1]),
]);
}