ReadyValidMemoryPortArbiter<LogicType extends Logic> constructor
- required Logic clk,
- required Logic reset,
- required List<
ReadyValidInterface< readRequests,Logic> > - required List<
ReadyValidInterface< readResponses,LogicType> > - required List<
ReadyValidInterface< writeRequests,MemoryWriteRequest< >LogicType> > - required int depth,
- required int maximumOutstandingReads,
- SynchronousMemoryFunctor? memoryFunctor,
- MemoryConfiguration? memoryConfiguration,
- int readLatency = 1,
- int responseBufferDepth = 1,
- MemoryArbitrationPolicy policy = MemoryArbitrationPolicy.fixedPriority,
- SynchronousRamReadUnderWrite readUnderWrite = SynchronousRamReadUnderWrite.readFirst,
- String name = 'ready_valid_memory_port_arbiter',
Creates a bounded 1R1W memory port arbiter.
Implementation
ReadyValidMemoryPortArbiter({
required Logic clk,
required Logic reset,
required List<ReadyValidInterface<Logic>> readRequests,
required List<ReadyValidInterface<LogicType>> readResponses,
required List<ReadyValidInterface<MemoryWriteRequest<LogicType>>>
writeRequests,
required this.depth,
required this.maximumOutstandingReads,
SynchronousMemoryFunctor? memoryFunctor,
MemoryConfiguration? memoryConfiguration,
this.readLatency = 1,
this.responseBufferDepth = 1,
this.policy = MemoryArbitrationPolicy.fixedPriority,
this.readUnderWrite = SynchronousRamReadUnderWrite.readFirst,
super.name = 'ready_valid_memory_port_arbiter',
}) : dataWidth = readResponses.isEmpty ? 0 : readResponses.first.data.width,
addrWidth = readRequests.isEmpty ? 0 : readRequests.first.data.width,
super(
definitionName: schemaQualifiedDefinitionName(
'ReadyValidMemoryPortArbiter_R${readRequests.length}'
'_W${writeRequests.length}_D$depth'
'_A${readRequests.isEmpty ? 0 : readRequests.first.data.width}'
'_L${readLatency}_M$maximumOutstandingReads'
'_B${responseBufferDepth}_P${policy.name}'
'_U${readUnderWrite.name}_S${_memoryPortArbiterMemoryIdentity(
memoryFunctor,
memoryConfiguration,
dataWidth: readResponses.firstOrNull?.data.width ?? 1,
addrWidth: readRequests.firstOrNull?.data.width ?? 1,
depth: depth,
readLatency: readLatency,
readUnderWrite: readUnderWrite,
)}_',
[
...readResponses.map((response) => response.data),
...writeRequests.map((request) => request.data.data),
],
),
) {
if (readRequests.isEmpty || readResponses.isEmpty) {
throw ArgumentError(
'At least one read request and response is required.');
}
if (readRequests.length != readResponses.length) {
throw ArgumentError('Every read request client requires one response.');
}
if (readRequests.any((request) => request.data.width != addrWidth)) {
throw ArgumentError('Read request addresses must be $addrWidth bits.');
}
if (!rohdPayloadsCompatible([
...readResponses.map((response) => response.data),
...writeRequests.map((request) => request.data.data),
])) {
throw ArgumentError(
'Read responses and write data must share one payload schema.');
}
final localClk = addInput('clk', clk);
final localReset = addInput('reset', reset);
final clientCount = readRequests.length;
this.readRequests = UnmodifiableListView([
for (var client = 0; client < clientCount; client++)
addPairInterface(readRequests[client], PairRole.consumer,
uniquify: (original) => 'readRequest_${client}_$original')
]);
this.writeRequests = UnmodifiableListView([
for (var client = 0; client < writeRequests.length; client++)
addPairInterface(writeRequests[client], PairRole.consumer,
uniquify: (original) => 'writeRequest_${client}_$original')
]);
this.readResponses = UnmodifiableListView([
for (var client = 0; client < clientCount; client++)
addPairInterfaceFrom(
IrrevocableReadyValidInterface<LogicType>(
cloneInterfacePayload(readResponses[client].data)),
readResponses[client],
PairRole.provider,
uniquify: (original) => 'readResponse_${client}_$original',
),
]);
final readOffers = [
for (var client = 0; client < clientCount; client++)
Logic(name: '${name}_read_offer_$client'),
];
final readAddresses = [
for (var client = 0; client < clientCount; client++)
this
.readRequests[client]
.data
.cloneTyped(name: '${name}_read_address_$client'),
];
final consumeResponses = [
for (var client = 0; client < clientCount; client++)
Logic(name: '${name}_consume_response_$client'),
];
final writeOffers = [
for (var client = 0; client < this.writeRequests.length; client++)
Logic(name: '${name}_write_offer_$client'),
];
final writePayloads = [
for (var client = 0; client < this.writeRequests.length; client++)
this
.writeRequests[client]
.data
.cloneTyped(name: '${name}_write_request_$client'),
];
final responseEgress =
ReadyValidEgressAttachmentPolicy<LogicType>(coreGatesTransfer: true);
core = MemoryPortArbiter<LogicType>(
clk: localClk,
reset: localReset,
readOffers: readOffers,
readAddresses: readAddresses,
consumeResponses: [
for (var client = 0; client < clientCount; client++)
responseEgress.transferControl(consumeResponses[client],
name: 'consumeResponse_$client'),
],
writeOffers: writeOffers,
writeRequests: writePayloads,
responseSchema: this.readResponses.first.data,
depth: depth,
maximumOutstandingReads: maximumOutstandingReads,
memoryFunctor: memoryFunctor,
memoryConfiguration: memoryConfiguration,
readLatency: readLatency,
responseBufferDepth: responseBufferDepth,
policy: policy,
readUnderWrite: readUnderWrite,
name: '${name}_core',
);
// The core arbitrates the raw offers, so each grant depends on its offer
// and the core qualifies every action itself.
for (var client = 0; client < clientCount; client++) {
ReadyValidIngressAttachmentPolicy<Logic>(
supportsSameCycleReplacement: false,
coreGatesAccept: true,
).attach(
upstream: this.readRequests[client],
canAccept: core.readAccepted[client],
accept: readOffers[client],
payload: readAddresses[client],
);
// Each response endpoint keeps its own declared schema.
final response = this
.readResponses[client]
.data
.cloneTyped(name: '${name}_response_$client')
..gets(core.responseData[client]);
responseEgress.attach(
downstream: this.readResponses[client],
offerValid: core.responseAvailable[client],
payload: response,
transfer: consumeResponses[client],
);
}
for (var client = 0; client < this.writeRequests.length; client++) {
ReadyValidIngressAttachmentPolicy<MemoryWriteRequest>(
supportsSameCycleReplacement: false,
coreGatesAccept: true,
).attach(
upstream: this.writeRequests[client],
canAccept: core.writeAccepted[client],
accept: writeOffers[client],
payload: writePayloads[client],
);
}
addOutput('outstandingReads', width: core.outstandingReads.width) <=
core.outstandingReads;
addOutput('unexpectedResponse') <= core.unexpectedResponse;
addOutput('responseOverflow') <= core.responseOverflow!;
}