From f777601970b5b0adc0c1242b528728e10d7b86d0 Mon Sep 17 00:00:00 2001 From: bsekisser Date: Mon, 5 Oct 2015 15:30:14 -0400 Subject: [PATCH] avr_timer: add avr_timer_clear_and_cancel_all_cycle_timers modified: sim/avr_timer.c added: avr_timer_clear_and_cancel_all_cycle_timers fixes a few oversights in original commit(s) --- simavr/sim/avr_timer.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/simavr/sim/avr_timer.c b/simavr/sim/avr_timer.c index 7950d60..386c1f9 100644 --- a/simavr/sim/avr_timer.c +++ b/simavr/sim/avr_timer.c @@ -233,6 +233,18 @@ avr_timer_cancel_all_cycle_timers( avr_cycle_timer_cancel(avr, avr_timer_compc, timer); } +static void +avr_timer_clear_and_cancel_all_cycle_timers( + struct avr_t * avr, + avr_timer_t *timer) +{ + for (int compi = 0; compi < AVR_TIMER_COMP_COUNT; compi++) + timer->comp[compi].comp_cycles = 0; + timer->tov_cycles = 0; + + avr_timer_cancel_all_cycle_timers(avr, timer); +} + static void avr_timer_tcnt_write( struct avr_t * avr, @@ -324,12 +336,7 @@ avr_timer_reconfigure( avr_t * avr = p->io.avr; // cancel everything - p->comp[AVR_TIMER_COMPA].comp_cycles = 0; - p->comp[AVR_TIMER_COMPB].comp_cycles = 0; - p->comp[AVR_TIMER_COMPC].comp_cycles = 0; - p->tov_cycles = 0; - - avr_timer_cancel_all_cycle_timers(avr, p); + avr_timer_clear_and_cancel_all_cycle_timers(avr, p); switch (p->wgm_op_mode_kind) { case avr_timer_wgm_normal: @@ -441,15 +448,7 @@ avr_timer_write( /* cs */ if (new_cs == 0) { // cancel everything - p->comp[AVR_TIMER_COMPA].comp_cycles = 0; - p->comp[AVR_TIMER_COMPB].comp_cycles = 0; - p->comp[AVR_TIMER_COMPC].comp_cycles = 0; - p->tov_cycles = 0; - - avr_cycle_timer_cancel(avr, avr_timer_tov, p); - avr_cycle_timer_cancel(avr, avr_timer_compa, p); - avr_cycle_timer_cancel(avr, avr_timer_compb, p); - avr_cycle_timer_cancel(avr, avr_timer_compc, p); + avr_timer_clear_and_cancel_all_cycle_timers(avr, p); AVR_LOG(avr, LOG_TRACE, "TIMER: %s-%c clock turned off\n", __func__, p->name); -- 2.39.5