From 9c1288f18889ae3bd10869a9f6ebc53defa3024b Mon Sep 17 00:00:00 2001 From: Uri Shaked Date: Wed, 9 Dec 2020 15:46:53 +0200 Subject: 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. --- src/peripherals/twi.ts | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'src/peripherals/twi.ts') 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: -- cgit v1.2.3