aboutsummaryrefslogtreecommitdiff
path: root/src/peripherals/twi.ts
diff options
context:
space:
mode:
authorUri Shaked2020-12-09 15:46:53 +0200
committerUri Shaked2020-12-09 15:49:41 +0200
commit9c1288f18889ae3bd10869a9f6ebc53defa3024b (patch)
tree1857fe48d3e2d32a39cfe810a0dfdd7d96526b3a /src/peripherals/twi.ts
parentrefactor: central interrupt handling #38 (diff)
downloadavr8js-9c1288f18889ae3bd10869a9f6ebc53defa3024b.tar.gz
avr8js-9c1288f18889ae3bd10869a9f6ebc53defa3024b.tar.bz2
avr8js-9c1288f18889ae3bd10869a9f6ebc53defa3024b.zip
perf!: centeral timekeeping
This should improve performance, especially when running simulations with multiple peripherals. For instance, the demo project now runs at ~322%, up from ~185% in AVR8js 0.13.1. BREAKING CHANGE: `tick()` methods were removed from individual peripherals. You now need to call `cpu.tick()` instead.
Diffstat (limited to '')
-rw-r--r--src/peripherals/twi.ts13
1 files changed, 2 insertions, 11 deletions
diff --git a/src/peripherals/twi.ts b/src/peripherals/twi.ts
index 914b67f..000bd2a 100644
--- a/src/peripherals/twi.ts
+++ b/src/peripherals/twi.ts
@@ -95,8 +95,6 @@ export class NoopTWIEventHandler implements TWIEventHandler {
export class AVRTWI {
public eventHandler: TWIEventHandler = new NoopTWIEventHandler(this);
- private nextTick: (() => void) | null = null;
-
// Interrupts
private TWI: AVRInterruptConfig = {
address: this.config.twiInterrupt,
@@ -116,7 +114,7 @@ export class AVRTWI {
const { status } = this;
if (clearInt && value & TWCR_TWEN) {
const twdrValue = this.cpu.data[this.config.TWDR];
- this.nextTick = () => {
+ this.cpu.addClockEvent(() => {
if (value & TWCR_TWSTA) {
this.eventHandler.start(status !== STATUS_TWI_IDLE);
} else if (value & TWCR_TWSTO) {
@@ -129,19 +127,12 @@ export class AVRTWI {
const ack = !!(value & TWCR_TWEA);
this.eventHandler.readByte(ack);
}
- };
+ }, 0);
return true;
}
};
}
- tick() {
- if (this.nextTick) {
- this.nextTick();
- this.nextTick = null;
- }
- }
-
get prescaler() {
switch (this.cpu.data[this.config.TWSR] & TWSR_TWPS_MASK) {
case 0: