ReadyValidResponseRetirementGate<ResponseLogicType extends Logic> constructor

ReadyValidResponseRetirementGate<ResponseLogicType extends Logic>({
  1. required Logic clk,
  2. required Logic reset,
  3. required Logic requestValid,
  4. required Logic requestKey,
  5. required ReadyValidInterface<ResponseLogicType> upstream,
  6. required ReadyValidInterface<ResponseLogicType> downstream,
  7. required int depth,
  8. required TransactionKeyGenerator<ResponseLogicType> responseKey,
  9. TransactionCompletionPredicate<ResponseLogicType> responseCompletion = completesTransactionOnEveryBeat,
  10. 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;
}