Commit dd79f415a894fa70078e87a72cfe63b39ca2dee7
authorTam Do <tdo.pro@gmail.com>
Sat, 21 Jul 2018 18:40:09 +0000 (13:40 -0500)
committerTam Do <tdo.pro@gmail.com>
Sat, 21 Jul 2018 18:40:09 +0000 (13:40 -0500)
simavr/sim/sim_interrupts.c

index 68c3bffe26063346ffb534321dbae89cedf7c56f..3b97673cfe7c90af9cb6c54d9d5a3ae26dd80cf7 100644 (file)
@@ -115,23 +115,25 @@ avr_raise_interrupt(
        if (!vector || !vector->vector)
                return 0;
 
-       if (vector->pending) {
-               if (vector->trace)
-                       printf("IRQ%d:I=%d already raised (enabled %d) (cycle %lld pc 0x%x)\n",
-                               vector->vector, !!avr->sreg[S_I], avr_regbit_get(avr, vector->enable),
-                               (long long int)avr->cycle, avr->pc);
-        // no return - polling ISR within interrupt allowed
-       }
-
        if (vector->trace)
                printf("IRQ%d raising (enabled %d)\n",
                        vector->vector, avr_regbit_get(avr, vector->enable));
+
        // always mark the 'raised' flag to one, even if the interrupt is disabled
        // this allow "polling" for the "raised" flag, like for non-interrupt
        // driven UART and so so. These flags are often "write one to clear"
        if (vector->raised.reg)
                avr_regbit_set(avr, vector->raised);
 
+       if (vector->pending) {
+               if (vector->trace)
+                       printf("IRQ%d:I=%d already raised (enabled %d) (cycle %lld pc 0x%x)\n",
+                               vector->vector, !!avr->sreg[S_I], avr_regbit_get(avr, vector->enable),
+                               (long long int)avr->cycle, avr->pc);
+
+        return 0;
+       }
+
        avr_raise_irq(vector->irq + AVR_INT_IRQ_PENDING, 1);
        avr_raise_irq(avr->interrupts.irq + AVR_INT_IRQ_PENDING, 1);