]> git.droids-corp.org - protos/xbee-avr.git/commitdiff
fix timer_interrupt
authorOlivier Matz <zer0@droids-corp.org>
Tue, 4 Mar 2014 20:51:12 +0000 (21:51 +0100)
committerOlivier Matz <zer0@droids-corp.org>
Sun, 9 Mar 2014 21:13:08 +0000 (22:13 +0100)
main.c

diff --git a/main.c b/main.c
index 0fb75d141f468f038b1a985f5f3c08743020642a..326ce64930ee66be51ad0e79e915e940ef4a43f9 100644 (file)
--- a/main.c
+++ b/main.c
@@ -97,7 +97,8 @@ static uint16_t get_time_ms(void)
 static void main_timer_interrupt(void)
 {
        static uint16_t cycles;
-       static uint8_t cpt;
+       static uint8_t cpt = 0;
+       static uint8_t stack = 0;
 
        cpt++;
 
@@ -112,22 +113,30 @@ static void main_timer_interrupt(void)
        else
                BUZZER_OFF();
 
-       /* interrupt every 2048 cycles */
-       cycles += 2048;
+       if ((cpt & 0x03) != 0)
+               return;
+
+       /* the following code is only called one interrupt among 4: every 682us
+        * (at 12 Mhz) = 8192 cycles */
+       cycles += 8192;
        if (cycles >= 12000) {
                cycles -= 12000;
                global_ms ++;
        }
 
-       /* called every 682us (at 12 Mhz), but global_ms is not incremented at
-        * each call */
+       /* called  */
+       if (stack++ == 0)
+               LED2_ON();
        sei();
-       callout_manage(&xbeeboard.intr_cm);
+       if ((cpt & 0x3) == 0)
+               callout_manage(&xbeeboard.intr_cm);
+       cli();
+       if (--stack == 0)
+               LED2_OFF();
 }
 
 int main(void)
 {
-       //struct callout t1;
        FILE *xbee_file;
        int8_t err;
        struct xbee_dev dev;