src/timer.c
changeset 53 dfe67409fbcd
parent 52 237d1f5c1c32
child 54 ec42f36d8614
--- a/src/timer.c	Thu Apr 03 19:44:53 2014 +0300
+++ b/src/timer.c	Thu Apr 03 20:25:12 2014 +0300
@@ -64,8 +64,10 @@
 
 /*
  * Sleep on timer1 interrupt.
+ *
+ * Returns 0 on interrupt, 1 on timeout.
  */
-void timer_sleep (int cycles)
+char timer_sleep (int cycles)
 {
     // set timer
     timer1_start(cycles);
@@ -81,12 +83,20 @@
     );
     
     // sleep
-    while (tbi(&TIMER_FLAGS, TIMER1_BUSY)) {
-        __asm__ ( "sleep" :: );
-    }
+    __asm__ ( "sleep" :: );
 
     // cleanup
     SMCR = 0;
+    
+    if (tbi(&TIMER_FLAGS, TIMER1_BUSY)) {
+        timer1_stop();
+
+        // interrupt
+        return 0;
+    } else {
+        // timeout
+        return 1;
+    }
 }