CsrBlockModel constructor

CsrBlockModel({
  1. required CsrBlockConfig config,
  2. required Logic clk,
  3. required Logic reset,
  4. required DataPortInterface<Logic>? frontWrite,
  5. required DataPortInterface<Logic>? frontRead,
  6. bool allowLargerRegisters = false,
  7. int logicalRegisterIncrement = 1,
  8. BigInt? wideLogicalRegisterIncrement,
  9. BigInt? addressExtent,
  10. bool asyncReset = false,
  11. Set<String>? hardwareRegisters,
  12. bool reserveName = false,
  13. bool reserveDefinitionName = false,
  14. String? definitionName,
})

Constructs a software block without an enclosing CsrTop.

hardwareRegisters is null to expose all accessible backdoors, or a set of block/register names. An empty set exposes none.

Implementation

CsrBlockModel({
  required CsrBlockConfig super.config,
  required super.clk,
  required super.reset,
  required super.frontWrite,
  required super.frontRead,
  super.allowLargerRegisters,
  super.logicalRegisterIncrement,
  super.wideLogicalRegisterIncrement,
  BigInt? addressExtent,
  bool asyncReset = false,
  Set<String>? hardwareRegisters,
  super.reserveName,
  super.reserveDefinitionName,
  String? definitionName,
}) : super(
          definitionName:
              definitionName ?? 'CsrBlockModel_${config.name}_block') {
  final remaining = Set<String>.of(hardwareRegisters ?? const {});
  final hardware = <BigInt, CsrBackdoorInterface>{};
  for (final register in config.registers) {
    final key = '${config.name}/${register.name}';
    if (hardwareRegisters != null && !hardwareRegisters.contains(key)) {
      continue;
    }
    remaining.remove(key);
    if (!register.backdoorAccessible) {
      if (hardwareRegisters != null) {
        throw ArgumentError('CSR $key has no hardware backdoor access.');
      }
      continue;
    }
    final external = CsrBackdoorInterface(config: register);
    final internal = addInterfacePorts(external,
        outputTags: {CsrBackdoorPortGroup.read},
        inputTags: {CsrBackdoorPortGroup.write},
        uniquify: (original) =>
            '${name}_${register.name}_backdoor_$original');
    backdoorInterfaces.add(external);
    _byName[register.name] = external;
    hardware[register.addr] = internal;
  }
  if (remaining.isNotEmpty) {
    throw ArgumentError('Unknown hardware CSR selection: $remaining.');
  }
  model = CsrModel(
    description: CsrModelDescription.fromBlock(
      config,
      instanceName: name,
      frontRead: frontRead == null
          ? null
          : MemoryPortGeometry(
              addrWidth: frontRead!.addrWidth,
              dataWidth: frontRead!.dataWidth),
      frontWrite: frontWrite == null
          ? null
          : MemoryPortGeometry(
              addrWidth: frontWrite!.addrWidth,
              dataWidth: frontWrite!.dataWidth),
      hardwareRegisters: hardwareRegisters,
      wideLogicalRegisterIncrement: logicalRegisterIncrement,
      allowLargerRegisters: allowLargerRegisters,
      addressExtent: addressExtent,
      asyncReset: asyncReset,
    ),
    clk: clk,
    reset: reset,
    frontRead: frontRead,
    frontWrite: frontWrite,
    hardware: hardware,
  );
}