ReadyValidAtomicCommitBoundary<CommitType extends Logic> constructor
- required Logic clk,
- required Logic reset,
- required ReadyValidInterface<
CommitType> candidate, - required ReadyValidInterface<
CommitType> commitOutput, - List<
AtomicCommitEffect< effects = const [],CommitType> > - Logic? flush,
- AtomicCommitReplayKey<
CommitType> ? replayKey, - String policyIdentity = 'default',
- String name = 'ready_valid_atomic_commit_boundary',
Creates a registered atomic commit boundary.
When using replayKey, provide a distinct policyIdentity to identify
the key selection in the generated definition.
Implementation
ReadyValidAtomicCommitBoundary({
required Logic clk,
required Logic reset,
required ReadyValidInterface<CommitType> candidate,
required ReadyValidInterface<CommitType> commitOutput,
List<AtomicCommitEffect<CommitType>> effects = const [],
Logic? flush,
AtomicCommitReplayKey<CommitType>? replayKey,
String policyIdentity = 'default',
super.name = 'ready_valid_atomic_commit_boundary',
}) : effects = List.unmodifiable(effects),
super(
definitionName: _atomicCommitDefinitionName(
candidate,
commitOutput,
effects,
replayKey != null,
policyIdentity,
),
) {
if (candidate.data.width < 1 ||
!rohdPayloadsCompatible([candidate.data, commitOutput.data],
ignoreConstantNames: true)) {
throw ArgumentError(
'Atomic commit candidate and output payload widths must match.',
);
}
if (!RegExp(r'^[A-Za-z][A-Za-z0-9_]*$').hasMatch(policyIdentity)) {
throw ArgumentError.value(
policyIdentity,
'policyIdentity',
'Must be a valid SystemVerilog identifier fragment.',
);
}
if (replayKey != null && policyIdentity == 'default') {
throw ArgumentError.value(policyIdentity, 'policyIdentity',
'A replay key requires a distinct policy identity.');
}
final localClk = addInput('clk', clk);
final localReset = addInput('reset', reset);
final localFlush = addInput('flush', flush ?? Const(0));
this.candidate = addPairInterface(candidate, PairRole.consumer,
uniquify: (original) => 'candidate_$original');
this.commitOutput = addPairInterface(commitOutput, PairRole.provider,
uniquify: (original) => 'commitOutput_$original');
final pending = Logic(name: '${name}_pending');
final pendingCandidate =
this.candidate.data.cloneTyped(name: '${name}_pendingCandidate');
final replayGuard = Logic(name: '${name}_replayGuard');
final offeredReplayKey = replayKey?.call(this.candidate.data);
final pendingReplayKey = replayKey?.call(pendingCandidate);
final replayKeyRegister = Logic(
name: '${name}_replayKey',
width: offeredReplayKey?.width ?? 1,
);
addOutput('occupied') <= pending;
addOutput('captured');
addOutput('commit');
for (var index = 0; index < effects.length; index++) {
effects[index].connect(
this,
pendingCandidate,
portPrefix: 'effect_${index}_${effects[index].definitionIdentity}',
);
}
Logic effectsReady = Const(1);
final requiredEffects = <Logic>[];
for (final effect in effects) {
final required = effect.required(pendingCandidate);
requiredEffects.add(required);
effectsReady = effectsReady & (~required | effect.ready);
}
final repeatsCommittedCandidate = replayKey == null
? Const(0)
: replayGuard &
this.candidate.valid &
offeredReplayKey!.eq(replayKeyRegister);
this.candidate.ready <= ~pending & ~localFlush;
final capture = this.candidate.accepted & ~repeatsCommittedCandidate;
final commit =
pending & ~localFlush & this.commitOutput.ready & effectsReady;
this.commitOutput.valid <= commit;
this.commitOutput.data <= pendingCandidate;
for (var index = 0; index < effects.length; index++) {
effects[index].setValid(commit & requiredEffects[index]);
}
output('captured') <= capture;
output('commit') <= commit;
Sequential(
localClk,
reset: localReset,
resetValues: {
pending: 0,
pendingCandidate: 0,
replayGuard: 0,
replayKeyRegister: 0,
},
[
If(
localFlush,
then: [
pending < 0,
replayGuard < 0,
],
orElse: [
if (replayKey != null)
If(
replayGuard &
(~this.candidate.valid |
offeredReplayKey!.neq(replayKeyRegister)),
then: [replayGuard < 0],
),
If(
commit,
then: [
pending < 0,
if (replayKey != null) ...[
replayGuard < 1,
replayKeyRegister < pendingReplayKey,
],
],
orElse: [
If(
capture,
then: [
pending < 1,
pendingCandidate < this.candidate.data,
],
),
],
),
],
),
],
);
}