Commit ebe62299d3a9c513ca5b28ad0af013d8b7743ea2
authorMichel Pollet <buserror@gmail.com>
Thu, 24 Dec 2009 16:54:25 +0000 (16:54 +0000)
committerMichel Pollet <buserror@gmail.com>
Thu, 24 Dec 2009 16:54:25 +0000 (16:54 +0000)
Thanks to Jon Escombe

Signed-off-by: Michel Pollet <buserror@gmail.com>
simavr/sim/avr_timer.c

index 10bf174f6d0456ffee43b0c62a583d0a15af8e72..22e9f455e7e2d5cde848ce66f6136cbe8aafed97 100644 (file)
@@ -103,14 +103,16 @@ static uint8_t avr_timer_tcnt_read(struct avr_t * avr, avr_io_addr_t addr, void
        avr_timer_t * p = (avr_timer_t *)param;
        // made to trigger potential watchpoints
 
-       uint64_t when = avr->cycle - p->tov_base;
+       if (p->tov_cycles) {
+               uint64_t when = avr->cycle - p->tov_base;
 
-       uint16_t tcnt = (when * p->tov_top) / p->tov_cycles;
-//     printf("%s-%c when = %d tcnt = %d/%d\n", __FUNCTION__, p->name, (uint32_t)when, tcnt, p->tov_top);
+               uint16_t tcnt = (when * p->tov_top) / p->tov_cycles;
+       //      printf("%s-%c when = %d tcnt = %d/%d\n", __FUNCTION__, p->name, (uint32_t)when, tcnt, p->tov_top);
 
-       avr->data[p->r_tcnt] = tcnt;
-       if (p->r_tcnth)
-               avr->data[p->r_tcnth] = tcnt >> 8;
+               avr->data[p->r_tcnt] = tcnt;
+               if (p->r_tcnth)
+                       avr->data[p->r_tcnth] = tcnt >> 8;
+       }
        
        return avr_core_watch_read(avr, addr);
 }