SynchronousReadOnlyMemory<LogicType extends Logic> constructor
- required Logic clk,
- required Logic reset,
- required List<
SynchronousReadDataPortInterface< readPorts,LogicType> > - required int entryCount,
- required List<
int> initialWords, - int readLatency = 1,
- MemoryConfiguration? memoryConfiguration,
- String? externalDefinitionName,
- Map<
String, String> ? externalParameters, - String name = 'synchronous_read_only_memory',
Creates a synchronous ROM with one or more independent read ports.
Implementation
SynchronousReadOnlyMemory({
required Logic clk,
required Logic reset,
required List<SynchronousReadDataPortInterface<LogicType>> readPorts,
required this.entryCount,
required List<int> initialWords,
this.readLatency = 1,
MemoryConfiguration? memoryConfiguration,
String? externalDefinitionName,
Map<String, String>? externalParameters,
super.name = 'synchronous_read_only_memory',
}) : dataWidth = readPorts.isEmpty ? 0 : readPorts.first.dataWidth,
addrWidth = readPorts.isEmpty ? 0 : readPorts.first.addrWidth,
backing = _resolveBacking(memoryConfiguration, externalDefinitionName),
super(
definitionName: 'SynchronousReadOnlyMemory'
'_R${readPorts.length}'
'_D$entryCount'
'_W${readPorts.isEmpty ? 0 : readPorts.first.dataWidth}'
'_A${readPorts.isEmpty ? 0 : readPorts.first.addrWidth}'
'_L$readLatency'
'_B${_resolveBacking(
memoryConfiguration,
externalDefinitionName,
).name}',
) {
if (readPorts.isEmpty) {
throw ArgumentError('A ROM requires at least one read port.');
}
if (entryCount < 1 || dataWidth < 1 || addrWidth < 1 || readLatency < 1) {
throw ArgumentError('ROM geometry and latency must be positive.');
}
if ((BigInt.one << addrWidth) < BigInt.from(entryCount)) {
throw ArgumentError('Address width cannot represent ROM entry count.');
}
if (readPorts.any((port) => port.addrWidth != addrWidth)) {
throw ArgumentError('All ROM ports must have matching address widths.');
}
if (!rohdPayloadsCompatible(readPorts.map((port) => port.data))) {
throw ArgumentError('All ROM ports must share one payload schema.');
}
if (initialWords.length > entryCount) {
throw ArgumentError.value(
initialWords,
'initialWords',
'Cannot exceed ROM entry count.',
);
}
final maximumWord = (BigInt.one << dataWidth) - BigInt.one;
if (initialWords.any(
(word) => word < 0 || BigInt.from(word) > maximumWord,
)) {
throw ArgumentError.value(
initialWords,
'initialWords',
'Words must be unsigned values of dataWidth bits.',
);
}
final localClk = addInput('clk', clk);
final localReset = addInput('reset', reset);
this.readPorts = [
for (var index = 0; index < readPorts.length; index++)
addInterface<SynchronousReadDataPortInterface<LogicType>,
DataPortGroup>(
readPorts[index],
inputTags: {DataPortGroup.control},
outputTags: {DataPortGroup.data},
uniquify: (original) => 'read_${index}_$original',
),
];
switch (backing) {
case MemoryBacking.flop || MemoryBacking.automatic:
_buildPipeline(
localClk,
localReset,
_constantWords([
...initialWords,
...List<int>.filled(entryCount - initialWords.length, 0)
]));
case MemoryBacking.model:
_buildPipeline(
localClk, localReset, _modelWords(localClk, initialWords));
case MemoryBacking.sram:
_ExternalSynchronousReadOnlyMemory(
clk: localClk,
reset: localReset,
readPorts: this.readPorts,
entryCount: entryCount,
dataWidth: dataWidth,
addrWidth: addrWidth,
readLatency: readLatency,
definitionName: externalDefinitionName!,
parameters: externalParameters,
name: '${name}_external',
);
}
}