CsrBlockModel constructor
- required CsrBlockConfig config,
- required Logic clk,
- required Logic reset,
- required DataPortInterface<
Logic> ? frontWrite, - required DataPortInterface<
Logic> ? frontRead, - bool allowLargerRegisters = false,
- int logicalRegisterIncrement = 1,
- BigInt? wideLogicalRegisterIncrement,
- BigInt? addressExtent,
- bool asyncReset = false,
- Set<
String> ? hardwareRegisters, - bool reserveName = false,
- bool reserveDefinitionName = false,
- 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,
);
}