GrantRetainer constructor
Creates ownership-retention hardware in the containing module.
Implementation
GrantRetainer({
required Logic clk,
required Logic reset,
required Logic candidate,
required Logic requests,
required Logic capture,
required Logic release,
String name = 'grant_retainer',
}) {
if (candidate.width < 1 || candidate.width != requests.width) {
throw ArgumentError(
'Candidate and request vectors must have the same positive width.',
);
}
if (clk.width != 1 ||
reset.width != 1 ||
capture.width != 1 ||
release.width != 1) {
throw ArgumentError('Grant-retainer control signals must be one bit.');
}
retainedOwner =
Logic(name: '${name}_retained_owner', width: candidate.width);
locked = Logic(name: '${name}_locked');
selection = Logic(name: '${name}_selection', width: candidate.width)
..gets(mux(locked, retainedOwner, candidate));
grant = Logic(name: '${name}_grant', width: candidate.width)
..gets(selection & requests);
Sequential(
clk,
reset: reset,
resetValues: {
locked: 0,
retainedOwner: 0,
},
[
If(locked & release, then: [
locked < 0,
], orElse: [
If(~locked & capture & candidate.or(), then: [
locked < 1,
retainedOwner < candidate,
]),
]),
],
);
}