From 36c4134a26063248a2ef47f5ac8defe50d9476b1 Mon Sep 17 00:00:00 2001 From: Uri Shaked Date: Wed, 9 Dec 2020 00:51:13 +0200 Subject: refactor: central interrupt handling #38 --- src/peripherals/twi.spec.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/peripherals/twi.spec.ts') diff --git a/src/peripherals/twi.spec.ts b/src/peripherals/twi.spec.ts index 1a2b2ae..e43ae38 100644 --- a/src/peripherals/twi.spec.ts +++ b/src/peripherals/twi.spec.ts @@ -48,9 +48,11 @@ describe('TWI', () => { it('should trigger data an interrupt if TWINT is set', () => { const cpu = new CPU(new Uint16Array(1024)); const twi = new AVRTWI(cpu, twiConfig, FREQ_16MHZ); - cpu.writeData(TWCR, TWINT | TWIE); + cpu.writeData(TWCR, TWIE); cpu.data[SREG] = 0x80; // SREG: I------- + twi.completeStart(); // This will set the TWINT flag twi.tick(); + cpu.tick(); expect(cpu.pc).toEqual(0x30); // 2-wire Serial Interface Vector expect(cpu.cycles).toEqual(2); expect(cpu.data[TWCR] & TWINT).toEqual(0); @@ -63,6 +65,7 @@ describe('TWI', () => { jest.spyOn(twi.eventHandler, 'start'); cpu.writeData(TWCR, TWINT | TWSTA | TWEN); twi.tick(); + cpu.tick(); expect(twi.eventHandler.start).toHaveBeenCalledWith(false); }); -- cgit v1.2.3 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.spec.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/peripherals/twi.spec.ts') diff --git a/src/peripherals/twi.spec.ts b/src/peripherals/twi.spec.ts index e43ae38..2628b57 100644 --- a/src/peripherals/twi.spec.ts +++ b/src/peripherals/twi.spec.ts @@ -51,7 +51,6 @@ describe('TWI', () => { cpu.writeData(TWCR, TWIE); cpu.data[SREG] = 0x80; // SREG: I------- twi.completeStart(); // This will set the TWINT flag - twi.tick(); cpu.tick(); expect(cpu.pc).toEqual(0x30); // 2-wire Serial Interface Vector expect(cpu.cycles).toEqual(2); @@ -64,7 +63,7 @@ describe('TWI', () => { const twi = new AVRTWI(cpu, twiConfig, FREQ_16MHZ); jest.spyOn(twi.eventHandler, 'start'); cpu.writeData(TWCR, TWINT | TWSTA | TWEN); - twi.tick(); + cpu.cycles++; cpu.tick(); expect(twi.eventHandler.start).toHaveBeenCalledWith(false); }); @@ -173,7 +172,7 @@ describe('TWI', () => { `); const cpu = new CPU(program); const twi = new AVRTWI(cpu, twiConfig, FREQ_16MHZ); - const runner = new TestProgramRunner(cpu, twi, onTestBreak); + const runner = new TestProgramRunner(cpu, onTestBreak); twi.eventHandler = { start: jest.fn(), stop: jest.fn(), @@ -342,7 +341,7 @@ describe('TWI', () => { `); const cpu = new CPU(program); const twi = new AVRTWI(cpu, twiConfig, FREQ_16MHZ); - const runner = new TestProgramRunner(cpu, twi, onTestBreak); + const runner = new TestProgramRunner(cpu, onTestBreak); twi.eventHandler = { start: jest.fn(), stop: jest.fn(), -- cgit v1.2.3