Csr constructor
- CsrInstanceConfig config
Factory constructor for Csr.
Because LogicStructure requires a List<Logic> upon construction, the factory method assists in creating the List upfront before the LogicStructure constructor is called.
Implementation
factory Csr(
CsrInstanceConfig config,
) {
final fields = <Logic>[];
final rsvds = <int>[];
var currIdx = 0;
var rsvdCount = 0;
// semantically a register with no fields means that
// there is one read/write field that is the entire register
if (config.fields.isEmpty) {
fields.add(Logic(name: 'data', width: config.width));
}
// there is at least one field explicitly defined so
// process them individually
else {
for (final field in config.fields) {
if (field.start > currIdx) {
fields.add(
Logic(name: 'rsvd_$rsvdCount', width: field.start - currIdx));
rsvds.add(fields.length - 1);
rsvdCount++;
}
fields.add(Logic(name: field.name, width: field.width));
currIdx = field.start + field.width;
}
if (currIdx < config.width) {
fields
.add(Logic(name: 'rsvd_$rsvdCount', width: config.width - currIdx));
rsvds.add(fields.length - 1);
}
}
return Csr._(
config: config,
rsvdIndices: rsvds,
fields: fields,
);
}