From: Michel Pollet Date: Sat, 25 Feb 2012 14:37:26 +0000 (+0000) Subject: timer: Fix a problem on unconfigured comparators X-Git-Tag: v1.0b1~48 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=e8217e0f848b0a3a0ed5c7e4b429a4924c83193a;p=sx%2Fsimavr.git timer: Fix a problem on unconfigured comparators Was trying to calculated and setup comparators that didn't exists on some cores... confusion ensued. This fixes the "64 led timer" example. Signed-off-by: Michel Pollet --- diff --git a/simavr/sim/avr_timer.c b/simavr/sim/avr_timer.c index c775aad..2e2630e 100644 --- a/simavr/sim/avr_timer.c +++ b/simavr/sim/avr_timer.c @@ -6,7 +6,7 @@ + CDC + Fast PWM - Copyright 2008, 2009 Michel Pollet + Copyright 2008-2012 Michel Pollet This file is part of simavr. @@ -75,8 +75,9 @@ static avr_cycle_count_t avr_timer_comp(avr_timer_t *p, avr_cycle_count_t when, break; } - return p->tov_cycles ? 0 : p->comp[comp].comp_cycles ? when - + p->comp[comp].comp_cycles : 0; + return p->tov_cycles ? 0 : + p->comp[comp].comp_cycles ? + when + p->comp[comp].comp_cycles : 0; } static avr_cycle_count_t avr_timer_compa(struct avr_t * avr, avr_cycle_count_t when, void * param) @@ -192,6 +193,8 @@ static void avr_timer_configure(avr_timer_t * p, uint32_t clock, uint32_t top) printf("%s-%c TOP %.2fHz = %d cycles\n", __FUNCTION__, p->name, t, (int)p->tov_cycles); for (int compi = 0; compi < AVR_TIMER_COMP_COUNT; compi++) { + if (!p->comp[compi].r_ocr) + continue; uint32_t ocr = _timer_get_ocr(p, compi); float fc = clock / (float)(ocr+1);