ReadyValidResponseRetirementGate<ResponseLogicType extends Logic> constructor
- required Logic clk,
- required Logic reset,
- required Logic requestValid,
- required Logic requestKey,
- required ReadyValidInterface<
ResponseLogicType> upstream, - required ReadyValidInterface<
ResponseLogicType> downstream, - required int depth,
- required TransactionKeyGenerator<
ResponseLogicType> responseKey, - TransactionCompletionPredicate<
ResponseLogicType> responseCompletion = completesTransactionOnEveryBeat, - String name = 'ready_valid_response_retirement_gate',
Creates a keyed response retirement gate.
Implementation
ReadyValidResponseRetirementGate(
{required Logic clk,
required Logic reset,
required Logic requestValid,
required Logic requestKey,
required ReadyValidInterface<ResponseLogicType> upstream,
required ReadyValidInterface<ResponseLogicType> downstream,
required this.depth,
required TransactionKeyGenerator<ResponseLogicType> responseKey,
TransactionCompletionPredicate<ResponseLogicType> responseCompletion =
completesTransactionOnEveryBeat,
String name = 'ready_valid_response_retirement_gate'})
: super(
definitionName: 'ReadyValidResponseRetirementGate_D${depth}_'
'K${requestKey.width}_${upstream.data.name}_'
'${payloadShapesIdentity([upstream.data, downstream.data])}',
name: name) {
if (depth < 1) {
throw ArgumentError.value(depth, 'depth', 'Must be positive.');
}
if (!rohdPayloadsCompatible([upstream.data, downstream.data],
ignoreConstantNames: true)) {
throw ArgumentError('Response payloads must be compatible.');
}
upstream.requireProviderComposableWith(ReadyValidContract.validThenReady,
consumerName: '$name upstream');
downstream.requireConsumerComposableWith(ReadyValidContract.readyAndValid,
providerName: name);
final localClk = addInput('clk', clk);
final localReset = addInput('reset', reset);
final localRequestValid = addInput('requestValid', requestValid);
final localRequestKey =
addInput('requestKey', requestKey, width: requestKey.width);
this.upstream = addPairInterface(upstream, PairRole.consumer,
uniquify: (original) => 'upstream_$original');
this.downstream = addPairInterface(downstream, PairRole.provider,
uniquify: (original) => 'downstream_$original');
addOutput('requestReady');
addOutput('requestAccepted');
addOutput('headKey', width: requestKey.width);
addOutput('empty');
final responseKeyValue =
responseKey(this.upstream.data).named('${name}_response_key');
final completes = responseCompletion(this.upstream.data)
.named('${name}_response_complete');
if (responseKeyValue.width != requestKey.width || completes.width != 1) {
throw ArgumentError('Response key must match requestKey width and '
'completion must be one bit.');
}
final responseAccepted = Logic(name: '${name}_response_accepted');
final requestAccepted = Logic(name: '${name}_request_accepted');
final completesAccepted =
(responseAccepted & completes).named('${name}_completes_accepted');
final tokenFifo = Fifo(localClk, localReset,
writeEnable: requestAccepted,
writeData: localRequestKey,
readEnable: completesAccepted,
depth: depth,
name: '${name}_keys');
final keyMatches =
(~tokenFifo.empty & tokenFifo.readData.eq(responseKeyValue))
.named('${name}_key_matches');
requestReady <= ~tokenFifo.full | completesAccepted;
requestAccepted <= localRequestValid & requestReady;
headKey <= tokenFifo.readData;
empty <= tokenFifo.empty;
this.downstream.valid <= this.upstream.valid & keyMatches;
this.downstream.data <= this.upstream.data;
this.upstream.ready <= keyMatches & this.downstream.ready;
responseAccepted <= this.downstream.valid & this.downstream.ready;
}