From: Michel Pollet Date: Wed, 16 Feb 2011 00:03:28 +0000 (+0000) Subject: timers: don't reconfigure for minor changes X-Git-Tag: v1.0a7~40 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=b778a45f49549badc2980ac79ca18a4ae7b5c5b5;p=sx%2Fsimavr.git timers: don't reconfigure for minor changes Prevents the timer to be reset when changing non important bits, like the edge detector etc Signed-off-by: Michel Pollet --- diff --git a/simavr/sim/avr_timer.c b/simavr/sim/avr_timer.c index 3912e59..a218a67 100644 --- a/simavr/sim/avr_timer.c +++ b/simavr/sim/avr_timer.c @@ -295,8 +295,21 @@ static void avr_timer_write_ocr(struct avr_t * avr, avr_io_addr_t addr, uint8_t static void avr_timer_write(struct avr_t * avr, avr_io_addr_t addr, uint8_t v, void * param) { avr_timer_t * p = (avr_timer_t *)param; + + uint8_t as2 = avr_regbit_get(avr, p->as2); + uint8_t cs = avr_regbit_get_array(avr, p->cs, ARRAY_SIZE(p->cs)); + uint8_t mode = avr_regbit_get_array(avr, p->wgm, ARRAY_SIZE(p->wgm)); + avr_core_watch_write(avr, addr, v); - avr_timer_reconfigure(p); + + // only reconfigure the timer if "relevant" bits have changed + // this prevent the timer reset when changing the edge detector + // or other minor bits + if (avr_regbit_get_array(avr, p->cs, ARRAY_SIZE(p->cs)) != cs || + avr_regbit_get_array(avr, p->wgm, ARRAY_SIZE(p->wgm)) != mode || + avr_regbit_get(avr, p->as2) != as2) { + avr_timer_reconfigure(p); + } } /*