X-Git-Url: http://git.rrze.uni-erlangen.de/gitweb/?p=moodlight.git;a=blobdiff_plain;f=timers.h;fp=timers.h;h=75cf012560dc483d649d4ae9553ea7daedd7ff26;hp=0000000000000000000000000000000000000000;hb=10ee5c5d2f67244662b528199b9f0d406fd2fefa;hpb=17aea8ef6cd47a0469e248a4e7325bcde394ea51 diff --git a/timers.h b/timers.h new file mode 100644 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_ */