Commit f7a67ccf3f44ecc8c18f9b07b2baa2219f3b6f8d
authorMike Playle <mike@mythik.co.uk>
Thu, 1 Feb 2018 22:09:28 +0000 (22:09 +0000)
committerMike Playle <mike@mythik.co.uk>
Thu, 1 Feb 2018 22:31:47 +0000 (22:31 +0000)
compare match

simavr/sim/avr_timer.c

index 96b40e13f69133dcc7faa32d1698367fd221d673..ef199fcc04a2701e1ffbef9090237e2dc5b8b48a 100644 (file)
@@ -83,23 +83,27 @@ avr_timer_comp(
        uint8_t mode = avr_regbit_get(avr, p->comp[comp].com);
        avr_irq_t * irq = &p->io.irq[TIMER_IRQ_OUT_COMP + comp];
 
+        uint32_t flags = 0;
+        if (p->comp[comp].com_pin.reg) // we got a physical pin
+                flags |= AVR_IOPORT_OUTPUT;
+        AVR_LOG(avr, LOG_TRACE, "Timer comp: irq %p, mode %d @%d\n", irq, mode, when);
        switch (mode) {
                case avr_timer_com_normal: // Normal mode OCnA disconnected
                        break;
                case avr_timer_com_toggle: // Toggle OCnA on compare match
                        if (p->comp[comp].com_pin.reg)  // we got a physical pin
                                avr_raise_irq(irq,
-                                               AVR_IOPORT_OUTPUT |
+                                               flags |
                                                (avr_regbit_get(avr, p->comp[comp].com_pin) ? 0 : 1));
                        else // no pin, toggle the IRQ anyway
                                avr_raise_irq(irq,
                                                p->io.irq[TIMER_IRQ_OUT_COMP + comp].value ? 0 : 1);
                        break;
                case avr_timer_com_clear:
-                       avr_raise_irq(irq, 0);
+                       avr_raise_irq(irq, flags | 0);
                        break;
                case avr_timer_com_set:
-                       avr_raise_irq(irq, 1);
+                       avr_raise_irq(irq, flags | 1);
                        break;
        }