timing functions - offering low res 'tick' counts, and high res timestamp counts...
[moodlight.git] / timers.h
diff --git a/timers.h b/timers.h
new file mode 100644 (file)
index 0000000..75cf012
--- /dev/null
+++ b/timers.h
@@ -0,0 +1,41 @@
+/* $Id: timers.h,v 1.1 2010/06/27 22:18:26 simimeie Exp $
+ * Functions for timing.
+ * This mainly allows you to get a timestamp value
+ */
+
+#ifndef _TIMERS_H_
+#define _TIMERS_H_
+
+/* timestamps are usually delivered in 'ticks'.
+ * At 8.0 MHz, there are ca. 122 ticks per second, and the 16 bit tick counter
+ * overflows about every 536 seconds.
+ * If you need exacter timing, you can also get a struct timestamp.
+ * That will contain the tick value and the current counter value as
+ * an uint16, giving you a precision of up to 1 cpu cycle. */
+
+#define TICKSPERSECOND (CPUFREQ / 65536UL)
+#define TICKSPERSECONDF ((float)CPUFREQ / 65536.0)
+
+struct timestamp {
+  uint16_t ticks;
+  uint16_t partticks;
+};
+
+/* Init timers */
+void timers_init(void);
+
+/* get ticks.
+ * Warning: Will reenable interrupts if they were disabled. */
+uint16_t getticks(void);
+/* The same, but won't touch the global interrupt enable bit.
+ * MUST BE CALLED WITH INTERRUPTS DISABLED */
+uint16_t getticks_noirq(void);
+
+/* get timestamp
+ * Warning: Will reenable interrupts if they were disabled. */
+struct timestamp gettimestamp(void);
+/* The same, but won't touch the global interrupt enable bit.
+ * MUST BE CALLED WITH INTERRUPTS DISABLED */
+struct timestamp gettimestamp_noirq(void);
+
+#endif /* _TIMERS_H_ */
This page took 0.048835 seconds and 4 git commands to generate.