Bugfix: use 16 bit tick count to adjust clock after sleep

This commit is contained in:
David Kopf 2011-12-01 09:58:55 -05:00
parent 6177187954
commit 81af871db9

View file

@ -67,25 +67,29 @@ void clock_adjust_seconds(uint8_t howmany) {
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* This routine can be called to add ticks to the clock after a sleep. /* This routine can be called to add ticks to the clock after a sleep.
* Leap ticks or seconds can (rarely) be introduced if the ISR is not blocked.
*/ */
void clock_adjust_ticks(uint16_t howmany) { void clock_adjust_ticks(uint16_t howmany) {
// uint8_t sreg = SREG;cli();
count += howmany; count += howmany;
scount += howmany; howmany+= scount;
while(scount >= CLOCK_SECOND) { while(howmany >= CLOCK_SECOND) {
scount -= CLOCK_SECOND; howmany -= CLOCK_SECOND;
seconds++; seconds++;
sleepseconds++; sleepseconds++;
#if RADIOSTATS #if RADIOSTATS
if (RF230_receive_on) radioontime += 1; if (RF230_receive_on) radioontime += 1;
#endif #endif
} }
scount = howmany;
// SREG=sreg;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
//SIGNAL(SIG_OUTPUT_COMPARE0) //SIGNAL(SIG_OUTPUT_COMPARE0)
ISR(AVR_OUTPUT_COMPARE_INT) ISR(AVR_OUTPUT_COMPARE_INT)
{ {
count++; count++;
if(++scount == CLOCK_SECOND) { if(++scount >= CLOCK_SECOND) {
scount = 0; scount = 0;
seconds++; seconds++;
} }
@ -96,7 +100,7 @@ ISR(AVR_OUTPUT_COMPARE_INT)
#endif #endif
#if RADIOSTATS #if RADIOSTATS
if (RF230_receive_on) { if (RF230_receive_on) {
if (++rcount == CLOCK_SECOND) { if (++rcount >= CLOCK_SECOND) {
rcount=0; rcount=0;
radioontime++; radioontime++;
} }