ReadyValidJoin<FirstLogicType extends Logic, SecondLogicType extends Logic> constructor
- required Logic clk,
- required Logic reset,
- required ReadyValidInterface<
FirstLogicType> first, - required ReadyValidInterface<
SecondLogicType> second, - required ReadyValidInterface<
JoinedPayload< downstream,FirstLogicType, SecondLogicType> > - Logic? firstAdmission,
- Logic? secondAdmission,
- String name = 'ready_valid_join',
Creates a buffered two-input join.
Implementation
ReadyValidJoin({
required Logic clk,
required Logic reset,
required ReadyValidInterface<FirstLogicType> first,
required ReadyValidInterface<SecondLogicType> second,
required ReadyValidInterface<JoinedPayload<FirstLogicType, SecondLogicType>>
downstream,
Logic? firstAdmission,
Logic? secondAdmission,
String name = 'ready_valid_join',
}) : super(
definitionName: 'ReadyValidJoin_'
'A${firstAdmission == null ? 0 : 1}'
'${secondAdmission == null ? 0 : 1}_'
'${_routingPayloadIdentity([
first.data,
second.data,
downstream.data,
])}',
name: name,
) {
if (!rohdPayloadsCompatible([first.data, downstream.data.first],
ignoreConstantNames: true) ||
!rohdPayloadsCompatible([second.data, downstream.data.second],
ignoreConstantNames: true)) {
throw ArgumentError(
'Joined input and output payloads must be compatible.');
}
first.requireProviderComposableWith(
ReadyValidContract.readyAndValid,
consumerName: '$name first input',
);
second.requireProviderComposableWith(
ReadyValidContract.readyAndValid,
consumerName: '$name second input',
);
downstream.requireConsumerComposableWith(
ReadyValidContract.irrevocable,
providerName: name,
);
final localClk = addInput('clk', clk);
final localReset = addInput('reset', reset);
final localFirstAdmission = firstAdmission == null
? Const(1)
: addInput('firstAdmission', firstAdmission);
final localSecondAdmission = secondAdmission == null
? Const(1)
: addInput('secondAdmission', secondAdmission);
addOutput('firstOccupied');
addOutput('secondOccupied');
this.first = addPairInterface(
first,
PairRole.consumer,
uniquify: (original) => 'first_$original',
);
this.second = addPairInterface(
second,
PairRole.consumer,
uniquify: (original) => 'second_$original',
);
this.downstream = addPairInterfaceFrom(
IrrevocableReadyValidInterface<
JoinedPayload<FirstLogicType, SecondLogicType>>(
downstream.data.cloneTyped(),
),
downstream,
PairRole.provider,
uniquify: (original) => 'downstream_$original',
);
final storedFirst = this.first.data.cloneTyped();
final storedSecond = this.second.data.cloneTyped();
final firstAccepted = this.first.accepted;
final secondAccepted = this.second.accepted;
final outputAccepted = this.downstream.accepted;
final nextFirstOccupied =
((firstOccupied & ~outputAccepted) | firstAccepted).named(
'${name}_next_first_occupied',
);
final nextSecondOccupied =
((secondOccupied & ~outputAccepted) | secondAccepted).named(
'${name}_next_second_occupied',
);
this.first.ready <= ~firstOccupied & localFirstAdmission;
this.second.ready <= ~secondOccupied & localSecondAdmission;
this.downstream.valid <= firstOccupied & secondOccupied;
this.downstream.data.first <= storedFirst;
this.downstream.data.second <= storedSecond;
Sequential(
localClk,
reset: localReset,
resetValues: {firstOccupied: 0, secondOccupied: 0},
[
If(firstAccepted, then: [storedFirst < this.first.data]),
If(secondAccepted, then: [storedSecond < this.second.data]),
firstOccupied < nextFirstOccupied,
secondOccupied < nextSecondOccupied,
],
);
}