validate method
Method to validate the configuration of a single register block.
Must check that its registers are mutually valid. Note that this method does not call the validate method of the individual registers in the block. It is assumed that register validation is called separately (i.e., in Csr HW construction).
Implementation
void validate() {
// at least 1 register
if (registers.isEmpty) {
throw CsrValidationException('Block $name has no registers.');
}
// no two registers with the same name
// no two registers with the same address
final issues = <String>[];
for (var i = 0; i < registers.length; i++) {
for (var j = i + 1; j < registers.length; j++) {
if (registers[i].name == registers[j].name) {
issues.add('Register ${registers[i].name} is duplicated.');
}
if (registers[i].addr == registers[j].addr) {
issues.add('Register ${registers[i].name} has a duplicate address.');
}
}
}
if (issues.isNotEmpty) {
throw CsrValidationException(issues.join('\n'));
}
}