ExternalTrueDualPortSynchronousMemory constructor

ExternalTrueDualPortSynchronousMemory({
  1. required Logic clk,
  2. required Logic reset,
  3. required List<TrueDualPortMemoryPort<Logic>> ports,
  4. required int entryCount,
  5. required String definitionName,
  6. int readLatency = 1,
  7. TrueDualPortWriteConflictPolicy writeConflictPolicy = TrueDualPortWriteConflictPolicy.disallow,
  8. SynchronousRamReadUnderWrite readUnderWrite = SynchronousRamReadUnderWrite.readFirst,
  9. Map<String, String>? parameters,
  10. String name = 'external_true_dual_port_synchronous_memory',
})

Creates a late-bound true dual-port memory instance.

Implementation

ExternalTrueDualPortSynchronousMemory({
  required Logic clk,
  required Logic reset,
  required List<TrueDualPortMemoryPort> ports,
  required this.entryCount,
  required super.definitionName,
  this.readLatency = 1,
  this.writeConflictPolicy = TrueDualPortWriteConflictPolicy.disallow,
  this.readUnderWrite = SynchronousRamReadUnderWrite.readFirst,
  Map<String, String>? parameters,
  super.name = 'external_true_dual_port_synchronous_memory',
})  : dataWidth = ports.isEmpty ? 0 : ports.first.dataWidth,
      addrWidth = ports.isEmpty ? 0 : ports.first.addrWidth,
      super(parameters: {
        'DEPTH': '$entryCount',
        'WIDTH': '${ports.isEmpty ? 0 : ports.first.dataWidth}',
        'ADDR_WIDTH': '${ports.isEmpty ? 0 : ports.first.addrWidth}',
        'READ_LATENCY': '$readLatency',
        'WRITE_CONFLICT_POLICY': '"${writeConflictPolicy.name}"',
        'READ_UNDER_WRITE': '"${readUnderWrite.systemVerilogParameter}"',
        ...?parameters,
      }) {
  if (ports.length != 2) {
    throw ArgumentError('Exactly two true dual-port memory ports required.');
  }
  if (entryCount < 1 || dataWidth < 1 || addrWidth < 1 || readLatency < 1) {
    throw ArgumentError('Memory geometry and latency must be positive.');
  }
  if ((BigInt.one << addrWidth) < BigInt.from(entryCount)) {
    throw ArgumentError('Address width cannot represent memory entry count.');
  }
  if (ports.any((port) => port.addrWidth != addrWidth)) {
    throw ArgumentError(
        'All true dual-port ports must have matching address widths.');
  }
  if (!rohdPayloadsCompatible([
    for (final port in ports) ...[port.writeData, port.readData],
  ])) {
    throw ArgumentError(
        'All true dual-port ports must share one payload schema.');
  }
  final maskWidths = ports.map((port) => port.maskWidth).toSet();
  if (maskWidths.length != 1) {
    throw ArgumentError('All true dual-port ports must have matching masks.');
  }

  addInput('clk', clk);
  addInput('reset', reset);
  for (var index = 0; index < 2; index++) {
    addInterface(
      ports[index],
      inputTags: {
        TrueDualPortMemoryGroup.request,
        TrueDualPortMemoryGroup.writeData,
      },
      outputTags: {TrueDualPortMemoryGroup.response},
      uniquify: (original) => '${original}_$index',
    );
  }
}