From: Michel Pollet Date: Wed, 10 Jun 2015 20:06:15 +0000 (+0100) Subject: interrupts: Redone the logic of delivery X-Git-Tag: v1.3~33 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=3a4fab8b693e4afca6e3b83ff7afc9e15bc56358;p=sx%2Fsimavr.git interrupts: Redone the logic of delivery Simplified a few expressions Signed-off-by: Michel Pollet --- diff --git a/simavr/sim/sim_interrupts.c b/simavr/sim/sim_interrupts.c index a5e96ff..b153907 100644 --- a/simavr/sim/sim_interrupts.c +++ b/simavr/sim/sim_interrupts.c @@ -225,25 +225,21 @@ void avr_service_interrupts( avr_t * avr) { - if (!avr->sreg[S_I]) + if (!avr->sreg[S_I] || !avr->interrupt_state) return; - if (avr->interrupt_state) { - if (avr->interrupt_state < 0) { - avr->interrupt_state++; - if (avr->interrupt_state == 0) - avr->interrupt_state = avr_has_pending_interrupts(avr); - return; - } - } else + if (avr->interrupt_state < 0) { + avr->interrupt_state++; + if (avr->interrupt_state == 0) + avr->interrupt_state = avr_has_pending_interrupts(avr); return; + } avr_int_table_p table = &avr->interrupts; // how many are pending... - int cnt = table->pending_w > table->pending_r ? - table->pending_w - table->pending_r : - (table->pending_w + INT_FIFO_SIZE) - table->pending_r; + int cnt = INT_FIFO_MOD( + (table->pending_w + INT_FIFO_SIZE) - table->pending_r); // locate the highest priority one int min = 0xff; int mini = 0;