Skip to content

Commit

Permalink
perf(timer): speed up interrupt handling
Browse files Browse the repository at this point in the history
  • Loading branch information
urish committed Sep 2, 2020
1 parent 673cbaf commit ed81059
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/peripherals/timer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ export class AVRTimer {
private tcntUpdated = false;
private countingUp = true;
private divider = 0;
private pendingInterrupt = false;

// This is the temporary register used to access 16-bit registers (section 16.3 of the datasheet)
private highByteTemp: u8 = 0;
Expand Down Expand Up @@ -302,6 +303,7 @@ export class AVRTimer {
}

set TIFR(value: u8) {
this.pendingInterrupt = value > 0;
this.cpu.data[this.config.TIFR] = value;
}

Expand Down Expand Up @@ -367,7 +369,7 @@ export class AVRTimer {
}
}
this.tcntUpdated = false;
if (this.cpu.interruptsEnabled) {
if (this.cpu.interruptsEnabled && this.pendingInterrupt) {
const { TIFR, TIMSK } = this;
if (TIFR & TOV && TIMSK & TOIE) {
avrInterrupt(this.cpu, this.config.ovfInterrupt);
Expand All @@ -381,6 +383,7 @@ export class AVRTimer {
avrInterrupt(this.cpu, this.config.compBInterrupt);
this.TIFR &= ~OCFB;
}
this.pendingInterrupt = false;
}
}

Expand Down

0 comments on commit ed81059

Please sign in to comment.