ProtectedSynchronousMemory constructor
- required Logic clk,
- required Logic reset,
- required List<
DataPortInterface< writePorts,Logic> > - required List<
SynchronousReadDataPortInterface< readPorts,Logic> > - required ProtectedMemoryLayout layout,
- int? entryCount,
- @Deprecated('Use entryCount instead.') int? depth,
- SynchronousMemoryFunctor? memoryFunctor,
- MemoryConfiguration? memoryConfiguration,
- int readLatency = 1,
- SynchronousRamReadUnderWrite readUnderWrite = SynchronousRamReadUnderWrite.readFirst,
- SynchronousMemoryResetBehavior requiredResetBehavior = SynchronousMemoryResetBehavior.none,
- List<
ReadyValidInterface< ? rmwWriteRequests,ProtectedMemoryWriteRequest< >Logic> > - String name = 'protected_synchronous_memory',
Creates a protected synchronous memory around an existing memory functor.
Declared logical word schemas must agree across the read and write ports and any read-modify-write requests. The backing stores packed, encoded words and need not implement those schemas or the ECC codec.
Implementation
factory ProtectedSynchronousMemory({
required Logic clk,
required Logic reset,
required List<DataPortInterface> writePorts,
required List<SynchronousReadDataPortInterface> readPorts,
required ProtectedMemoryLayout layout,
int? entryCount,
@Deprecated('Use entryCount instead.') int? depth,
SynchronousMemoryFunctor? memoryFunctor,
MemoryConfiguration? memoryConfiguration,
int readLatency = 1,
SynchronousRamReadUnderWrite readUnderWrite =
SynchronousRamReadUnderWrite.readFirst,
SynchronousMemoryResetBehavior requiredResetBehavior =
SynchronousMemoryResetBehavior.none,
List<ReadyValidInterface<ProtectedMemoryWriteRequest>>? rmwWriteRequests,
String name = 'protected_synchronous_memory',
}) {
final rmwRequests = rmwWriteRequests ?? const [];
final portShapes = [
for (final port in [...writePorts, ...readPorts])
(addrWidth: port.addrWidth, word: port.data),
for (final request in rmwRequests)
(addrWidth: request.data.addrWidth, word: request.data.data),
];
if (portShapes.isEmpty) {
throw ArgumentError('At least one read or write port is required.');
}
final addrWidth = portShapes.first.addrWidth;
final words = portShapes.map((shape) => shape.word);
if (portShapes.any((shape) => shape.addrWidth != addrWidth) ||
words.any((word) => word.width != layout.logicalWidth) ||
!rohdPayloadsCompatible(words, allowRenamedClones: true)) {
throw ArgumentError(
'Memory ports must share an address width and logical word schema.');
}
if (layout.partialWritePolicy ==
ProtectedPartialWritePolicy.readModifyWrite) {
if (rmwRequests.isEmpty) {
throw ArgumentError(
'Read-modify-write layouts require at least one ready/valid '
'protected write request.');
}
if (writePorts.isNotEmpty) {
throw ArgumentError(
'Raw write ports cannot be combined with read-modify-write '
'requests.');
}
if (readLatency != 1) {
throw ArgumentError(
'Protected read-modify-write currently requires one-cycle reads.');
}
} else if (rmwRequests.isNotEmpty) {
throw ArgumentError(
'Read-modify-write requests require the readModifyWrite policy.');
}
final hasMaskedWrites =
writePorts.any((port) => port is MaskedDataPortInterface);
if (hasMaskedWrites &&
(layout.partialWritePolicy !=
ProtectedPartialWritePolicy.independentLanes ||
layout.laneCodec.logicalWidth != 8 ||
layout.laneCodec.protectedWidth % 8 != 0)) {
throw ArgumentError(
'Masked ports require independent 8-bit logical lanes and '
'byte-granular protected lanes.');
}
final backingRequest = SynchronousMemoryRequest(
dataWidth: layout.protectedWidth,
addrWidth: addrWidth,
entryCount:
resolveRenamedArgument(entryCount, depth, 'entryCount', 'depth'),
writePortCount: writePorts.length + rmwRequests.length,
readPortCount: readPorts.length + rmwRequests.length,
maskedWritePorts: [
for (final port in writePorts) port is MaskedDataPortInterface,
// The controller implements partial writes using full physical writes.
for (final _ in rmwRequests) false,
],
readLatency: readLatency,
readUnderWrite: readUnderWrite,
requiredResetBehavior: requiredResetBehavior,
protectedPartialWritePolicy: hasMaskedWrites
? ProtectedPartialWritePolicy.independentLanes
: ProtectedPartialWritePolicy.none,
);
return ProtectedSynchronousMemory._(
clk: clk,
reset: reset,
writePorts: writePorts,
readPorts: readPorts,
rmwRequests: rmwRequests,
layout: layout,
backingRequest: backingRequest,
memoryFunctor: memoryFunctor ??
resolveMemoryConfiguration(memoryConfiguration)
.selectFunctor(backingRequest),
name: name,
);
}