From 43c2ccf5d836ae43b43e8ac147d09c6a025cb0f4 Mon Sep 17 00:00:00 2001 From: nifi Date: Mon, 6 Apr 2009 13:08:42 +0000 Subject: [PATCH] fixed clock_seconds to use full 32 bit --- cpu/avr/dev/clock.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/cpu/avr/dev/clock.c b/cpu/avr/dev/clock.c index 15ecdab91..1d984ab90 100644 --- a/cpu/avr/dev/clock.c +++ b/cpu/avr/dev/clock.c @@ -6,13 +6,18 @@ #include #include -static volatile clock_time_t count; +static volatile clock_time_t count, scount; +static volatile unsigned long seconds; /*---------------------------------------------------------------------------*/ //SIGNAL(SIG_OUTPUT_COMPARE0) ISR(AVR_OUTPUT_COMPARE_INT) { - ++count; + count++; + if(++scount == CLOCK_SECOND) { + scount = 0; + seconds++; + } if(etimer_pending()) { etimer_request_poll(); } @@ -59,7 +64,7 @@ clock_init(void) * 16 bit data type, time intervals of up to 524 seconds can be * measured. */ - count = 0; + scount = count = 0; sei (); } @@ -68,7 +73,11 @@ clock_init(void) clock_time_t clock_time(void) { - return count; + clock_time_t tmp; + do { + tmp = count; + } while(tmp != count); + return tmp; } /*---------------------------------------------------------------------------*/ /** @@ -107,5 +116,9 @@ clock_set_seconds(unsigned long sec) unsigned long clock_seconds(void) { - return count / CLOCK_SECOND; + unsigned long tmp; + do { + tmp = seconds; + } while(tmp != seconds); + return tmp; }