From 3a4fab8b693e4afca6e3b83ff7afc9e15bc56358 Mon Sep 17 00:00:00 2001 From: Michel Pollet Date: Wed, 10 Jun 2015 21:06:15 +0100 Subject: [PATCH] interrupts: Redone the logic of delivery Simplified a few expressions Signed-off-by: Michel Pollet --- simavr/sim/sim_interrupts.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) 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; -- 2.39.5