run method
- Phase phase
override
Executes this Component's activities related to running the test.
Overrides of run must call super.run in an unawaited fashion.
For example:
@override
Future<void> run(Phase phase) async {
unawaited(super.run(phase));
// New code goes here!
}
Implementation
@override
Future<void> run(Phase phase) async {
unawaited(super.run(phase));
final snapshot = Simulator.preTick.listen((_) {
for (final probe in _creditChecks) {
probe.startingCredits.setAll(0, probe.checker.credits);
}
});
Simulator.registerEndOfSimulationAction(snapshot.cancel);
var previous = _LinkState.closed;
var awaitingRelease = sys.resetN.value != LogicValue.one;
while (!Simulator.simulationHasEnded) {
await sys.clk.nextPosedge;
if (Simulator.simulationHasEnded) {
return;
}
_cycle++;
final resetN = sys.resetN.previousValue;
if (resetN != LogicValue.one) {
if (resetN != LogicValue.zero) {
_report('RESETn must be known.');
}
previous = _LinkState.closed;
awaitingRelease = true;
_requests.clear();
_completions.clear();
continue;
}
if (awaitingRelease) {
_checkRelease();
awaitingRelease = false;
continue;
}
final request = _known(link.lm.openReq);
final ack = _known(link.lm.openAck);
final askClose = _known(link.lm.askClose);
if (request == null || ack == null) {
continue;
}
final state = switch ((request.toBool(), ack.toBool())) {
(false, false) => _LinkState.closed,
(true, false) => _LinkState.opening,
(true, true) => _LinkState.open,
(false, true) => _LinkState.closing,
};
final next =
_LinkState.values[(previous.index + 1) % _LinkState.values.length];
if (state != previous && state != next) {
_report('Illegal LTI link transition '
'${previous.name} -> ${state.name}.');
}
if (askClose == LogicValue.one && ack == LogicValue.zero) {
_report('LMASKCLOSE requires LMOPENACK.');
}
if (previous == _LinkState.open &&
request == LogicValue.zero &&
(_requests.isNotEmpty || _completions.isNotEmpty)) {
_report('LMOPENREQ dropped with outstanding LTI transactions.');
}
if (state == _LinkState.closed) {
_requests.clear();
_completions.clear();
}
previous = state;
final transfers = <LtiTransportInterface, int>{
for (final probe in _creditChecks)
if (_sampleChannel(probe, state) case final vc?) probe.channel: vc,
};
// LC cannot use a response from this edge. LR can use a new LA,
// provided there is no older matching request.
if (transfers.containsKey(link.lc)) {
final tag = _known(link.lc.ctag)?.toBigInt();
if (tag != null && !_consume(_completions, tag)) {
_report('LC tag $tag has no earlier outstanding LR response.');
}
}
final responseVc = transfers[link.lr];
final responseId = responseVc == null ? null : _id(link.lr.id);
final matchesOlder = _requests.containsKey((responseVc, responseId));
if (matchesOlder && responseVc != null && responseId != null) {
_sampleResponse(responseVc, responseId);
}
if (transfers[link.la] case final vc?) {
_sampleRequest(vc);
}
if (!matchesOlder && responseVc != null && responseId != null) {
_sampleResponse(responseVc, responseId);
}
if (link.lt case final lt? when transfers.containsKey(lt)) {
_known(lt.ctag);
}
}
}