summaryrefslogtreecommitdiffstats
path: root/timer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'timer.cpp')
-rw-r--r--timer.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/timer.cpp b/timer.cpp
new file mode 100644
index 0000000..b4a1b12
--- /dev/null
+++ b/timer.cpp
@@ -0,0 +1,18 @@
+#include "timer.h"
+#include "global.h"
+
+#include <avr/interrupt.h>
+
+
+static volatile unsigned long ticks = 0;
+
+
+SIGNAL(SIG_OVERFLOW0) {
+ ticks++;
+}
+
+void sleep(unsigned long ms) {
+ unsigned long t = ticks + ms * (F_CPU/TIMER_PRESCALER/256000);
+
+ while(ticks < t);
+}