ReadyValidSelectiveFork<LogicType extends Logic> constructor
- required Logic clk,
- required Logic reset,
- required ReadyValidInterface<
LogicType> upstream, - required List<
ReadyValidInterface< downstreams,LogicType> > - required Logic selection,
- String name = 'ready_valid_selective_fork',
Creates a selective fork with per-output completion tracking.
Implementation
ReadyValidSelectiveFork({
required Logic clk,
required Logic reset,
required ReadyValidInterface<LogicType> upstream,
required List<ReadyValidInterface<LogicType>> downstreams,
required Logic selection,
String name = 'ready_valid_selective_fork',
}) : outputCount = downstreams.length,
super(
definitionName: 'ReadyValidSelectiveFork_selective_fork_core_'
'N${downstreams.length}_'
'${_routingPayloadIdentity([
upstream.data,
for (final downstream in downstreams) downstream.data,
])}',
name: name,
) {
if (downstreams.isEmpty) {
throw ArgumentError.value(
downstreams,
'downstreams',
'Must not be empty.',
);
}
if (selection.width != downstreams.length) {
throw ArgumentError.value(
selection,
'selection',
'Must have one bit for each downstream interface.',
);
}
_validateFanoutPayloads(
upstream.data, downstreams.map((downstream) => downstream.data));
upstream.requireProviderComposableWith(
ReadyValidContract.readyAndValid,
consumerName: name,
);
for (var index = 0; index < downstreams.length; index++) {
downstreams[index].requireConsumerComposableWith(
ReadyValidContract.irrevocable,
providerName: name,
);
}
final localClk = addInput('clk', clk);
final localReset = addInput('reset', reset);
this.upstream = addPairInterface(
upstream,
PairRole.consumer,
uniquify: (original) => 'upstream_$original',
);
this.selection = addInput('selection', selection, width: selection.width);
this.downstreams = UnmodifiableListView([
for (var index = 0; index < outputCount; index++)
addPairInterfaceFrom(
IrrevocableReadyValidInterface<LogicType>(
downstreams[index].data.cloneTyped(),
),
downstreams[index],
PairRole.provider,
uniquify: (original) => 'downstream_${index}_$original',
),
]);
addOutput('occupied');
final load = Logic(name: '${name}_load');
final advance = Logic(name: '${name}_advance', width: outputCount);
final payload = this.upstream.data.cloneTyped();
final coreFunctor = SelectiveForkCoreFunctor<LogicType>(
outputCount: outputCount,
);
final binding = coreFunctor.construct(
SelectiveForkCoreRequest<LogicType>(
clk: localClk,
reset: localReset,
payload: payload,
selection: this.selection,
load: load,
advance: advance,
),
name: '${name}_core',
);
payload <= this.upstream.data;
load <= this.upstream.valid & binding.canLoad;
advance <=
binding.outputValidMask &
this
.downstreams
.map((downstream) => downstream.ready)
.toList()
.rconcat();
occupied <= binding.occupied;
this.upstream.ready <= binding.canLoad;
for (var index = 0; index < outputCount; index++) {
this.downstreams[index].valid <= binding.outputValidMask[index];
this.downstreams[index].data <= binding.retainedPayload;
}
}