aboutsummaryrefslogtreecommitdiff
path: root/src/peripherals/timer.spec.ts
diff options
context:
space:
mode:
authorUri Shaked2020-12-25 01:45:03 +0200
committerUri Shaked2020-12-25 01:45:03 +0200
commitcf6d4910d1cd320b93d26548fcd500a8b1b2864b (patch)
tree981d9ff79688b2f68c58243a4699819729bb6137 /src/peripherals/timer.spec.ts
parent0.14.5 (diff)
downloadavr8js-cf6d4910d1cd320b93d26548fcd500a8b1b2864b.tar.gz
avr8js-cf6d4910d1cd320b93d26548fcd500a8b1b2864b.tar.bz2
avr8js-cf6d4910d1cd320b93d26548fcd500a8b1b2864b.zip
fix(timer): Output Compare sometimes misses Compare Match #79
fix #79
Diffstat (limited to '')
-rw-r--r--src/peripherals/timer.spec.ts31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/peripherals/timer.spec.ts b/src/peripherals/timer.spec.ts
index 1b4d4d7..cdb2c4c 100644
--- a/src/peripherals/timer.spec.ts
+++ b/src/peripherals/timer.spec.ts
@@ -541,6 +541,37 @@ describe('timer', () => {
expect(gpioCallback).toHaveBeenCalledWith(6, PinOverrideMode.Set, 0x2b);
});
+ it('should not miss Compare Match when executing multi-cycle instruction (issue #79)', () => {
+ const { program, instructionCount } = asmProgram(`
+ LDI r16, 0x10 ; OCR0A = 0x10; // <- TOP value
+ OUT 0x27, r16
+ ; Set waveform generation mode (WGM) to normal, enable OC0A (Set on match)
+ LDI r16, 0xc0 ; TCCR0A = (1 << COM0A1) | (1 << COM0A0);
+ OUT 0x24, r16
+ LDI r16, 0x1 ; TCCR0B = (1 << CS00);
+ OUT 0x25, r16
+ LDI r16, 0xf ; TCNT0 = 0xf;
+ OUT 0x26, r16
+ RJMP 1 ; TCNT0 will be 0x11 (RJMP takes 2 cycles)
+ `);
+
+ const cpu = new CPU(program);
+ new AVRTimer(cpu, timer0Config);
+
+ // Listen to Port D's internal callback
+ const gpioCallback = jest.fn();
+ cpu.gpioTimerHooks[PORTD] = gpioCallback;
+
+ const runner = new TestProgramRunner(cpu);
+ runner.runInstructions(instructionCount);
+
+ expect(cpu.readData(TCNT0)).toEqual(0x11);
+ expect(gpioCallback).toHaveBeenCalledWith(6, PinOverrideMode.Enable, 0x2b);
+
+ // Verify that Compare Match has occured and set the OC0A pin (PD6 on ATmega328p)
+ expect(gpioCallback).toHaveBeenCalledWith(6, PinOverrideMode.Set, 0x2b);
+ });
+
it('should only update OCR0A when TCNT0=TOP in PWM Phase Correct mode (issue #76)', () => {
const { program, instructionCount } = asmProgram(`
LDI r16, 0x4 ; OCR0A = 0x4;