RecoveryBarrier<ContextType extends Logic> constructor
Creates a recovery barrier driven by request and complete actions.
Implementation
RecoveryBarrier({
required Logic clk,
required Logic reset,
required Logic request,
required ContextType requestContext,
required Logic participantReady,
required Logic participantDone,
required Logic participantFailed,
required Logic complete,
super.name = 'recovery_barrier',
}) : participantCount = participantReady.width,
super(
definitionName: 'RecoveryBarrier_'
'P${participantReady.width}_W${requestContext.width}_'
'${payloadShapesIdentity([requestContext])}',
) {
if (participantCount < 1 ||
participantDone.width != participantCount ||
participantFailed.width != participantCount) {
throw ArgumentError(
'Participant vectors must have the same positive width.');
}
final localClk = addInput('clk', clk);
final localReset = addInput('reset', reset);
final localRequest = addInput('request', request);
final localRequestContext = addTypedInput('requestContext', requestContext);
final localParticipantReady =
addInput('participantReady', participantReady, width: participantCount);
final localParticipantDone =
addInput('participantDone', participantDone, width: participantCount);
final localParticipantFailed = addInput(
'participantFailed', participantFailed,
width: participantCount);
final localComplete = addInput('complete', complete);
addOutput('canRequest');
addOutput('completionValid');
context =
addTypedPayloadOutput(this, 'recoveryContext', localRequestContext);
addOutput('quiesce');
addOutput('start');
addOutput('active');
addOutput('busy');
addOutput('failedParticipants', width: participantCount);
addOutput('completedParticipants', width: participantCount);
const idle = 0;
const quiescing = 1;
const recovering = 2;
const completing = 3;
final phase = Logic(name: '${name}_phase', width: 2);
final retainedContext =
localRequestContext.cloneTyped(name: '${name}_retained_context');
final failures = Logic(name: '${name}_failures', width: participantCount);
final completed = Logic(name: '${name}_completed', width: participantCount);
final isIdle = phase.eq(idle);
final isQuiescing = phase.eq(quiescing);
final isRecovering = phase.eq(recovering);
final isCompleting = phase.eq(completing);
final allReady = localParticipantReady.and();
final completedAfterUpdates = completed | localParticipantDone;
final allDone = completedAfterUpdates.and();
final startNow = isQuiescing & allReady;
final requestTaken = localRequest & isIdle;
final completeTaken = localComplete & isCompleting;
canRequest <= isIdle;
completionValid <= isCompleting;
context <= retainedContext;
// A request offered while busy is ignored, and quiesce is already high.
quiesce <= ~isIdle | localRequest;
start <= startNow;
active <= isRecovering;
busy <= ~isIdle;
failedParticipants <=
mux(isIdle, Const(0, width: participantCount),
failures | localParticipantFailed);
completedParticipants <=
mux(isIdle, Const(0, width: participantCount), completedAfterUpdates);
Sequential(localClk, reset: localReset, resetValues: {
phase: idle,
retainedContext: 0,
failures: 0,
completed: 0
}, [
If(requestTaken, then: [
retainedContext < localRequestContext,
failures < localParticipantFailed,
completed < 0,
phase < quiescing
]),
If(isQuiescing, then: [
failures < failures | localParticipantFailed,
If(allReady,
then: [completed < localParticipantDone, phase < recovering])
]),
If(isRecovering, then: [
failures < failures | localParticipantFailed,
completed < completedAfterUpdates,
If(allDone, then: [phase < completing])
]),
If(isCompleting, then: [failures < failures | localParticipantFailed]),
If(completeTaken, then: [phase < idle, failures < 0, completed < 0])
]);
}