PhasedRecoveryCoordinator constructor

PhasedRecoveryCoordinator({
  1. required Logic clk,
  2. required Logic reset,
  3. required ReadyValidInterface<Logic> start,
  4. required Logic quiescedMask,
  5. required Logic canceledMask,
  6. required Logic restoredMask,
  7. required int participantCount,
  8. String name = 'phased_recovery_coordinator',
})

Creates a participant-acknowledged recovery coordinator.

Implementation

PhasedRecoveryCoordinator({
  required Logic clk,
  required Logic reset,
  required ReadyValidInterface<Logic> start,
  required Logic quiescedMask,
  required Logic canceledMask,
  required Logic restoredMask,
  required this.participantCount,
  super.name = 'phased_recovery_coordinator',
}) : super(
        definitionName: _phasedRecoveryDefinitionName(participantCount),
      ) {
  if (participantCount < 1 ||
      quiescedMask.width != participantCount ||
      canceledMask.width != participantCount ||
      restoredMask.width != participantCount) {
    throw ArgumentError(
        'Participant acknowledgments must match a positive participant '
        'count.');
  }
  start.requireProviderComposableWith(ReadyValidContract.readyAndValid,
      consumerName: name);

  final localClk = addInput('clk', clk);
  final localReset = addInput('reset', reset);
  this.start = addPairInterface(start, PairRole.consumer,
      uniquify: (original) => 'start_$original');
  this.quiescedMask =
      addInput('quiescedMask', quiescedMask, width: participantCount);
  this.canceledMask =
      addInput('canceledMask', canceledMask, width: participantCount);
  this.restoredMask =
      addInput('restoredMask', restoredMask, width: participantCount);

  addOutput('phase', width: max(1, RecoveryPhase.values.length.log2Ceil));
  addOutput('busy');
  addOutput('quiesce');
  addOutput('cancel');
  addOutput('restore');
  addOutput('resume');
  addOutput('done');

  final phaseState = Logic(
      name: '${name}_state',
      width: max(1, RecoveryPhase.values.length.log2Ceil));
  final idle = Const(RecoveryPhase.idle.index, width: phaseState.width);
  final quiescing =
      Const(RecoveryPhase.quiescing.index, width: phaseState.width);
  final canceling =
      Const(RecoveryPhase.canceling.index, width: phaseState.width);
  final restoring =
      Const(RecoveryPhase.restoring.index, width: phaseState.width);
  final resuming =
      Const(RecoveryPhase.resuming.index, width: phaseState.width);
  final allParticipants = Const(
      LogicValue.filled(participantCount, LogicValue.one),
      width: participantCount);
  final allQuiesced = this.quiescedMask.eq(allParticipants);
  final allCanceled = this.canceledMask.eq(allParticipants);
  final allRestored = this.restoredMask.eq(allParticipants);

  this.start.ready <= phaseState.eq(idle);
  phase <= phaseState;
  busy <= ~phaseState.eq(idle);
  quiesce <= phaseState.eq(quiescing);
  cancel <= phaseState.eq(canceling);
  restore <= phaseState.eq(restoring);
  resume <= phaseState.eq(resuming);
  done <= phaseState.eq(resuming);

  var nextState = phaseState;
  nextState =
      mux(phaseState.eq(idle) & this.start.accepted, quiescing, nextState);
  nextState =
      mux(phaseState.eq(quiescing) & allQuiesced, canceling, nextState);
  nextState =
      mux(phaseState.eq(canceling) & allCanceled, restoring, nextState);
  nextState =
      mux(phaseState.eq(restoring) & allRestored, resuming, nextState);
  nextState = mux(phaseState.eq(resuming), idle, nextState);

  Sequential(localClk, reset: localReset, resetValues: {
    phaseState: 0
  }, [
    phaseState < nextState,
  ]);
}