| 1 | /* $Id: timers.h,v 1.1 2010/06/27 22:18:26 simimeie Exp $ |
| 2 | * Functions for timing. |
| 3 | * This mainly allows you to get a timestamp value |
| 4 | */ |
| 5 | |
| 6 | #ifndef _TIMERS_H_ |
| 7 | #define _TIMERS_H_ |
| 8 | |
| 9 | /* timestamps are usually delivered in 'ticks'. |
| 10 | * At 8.0 MHz, there are ca. 122 ticks per second, and the 16 bit tick counter |
| 11 | * overflows about every 536 seconds. |
| 12 | * If you need exacter timing, you can also get a struct timestamp. |
| 13 | * That will contain the tick value and the current counter value as |
| 14 | * an uint16, giving you a precision of up to 1 cpu cycle. */ |
| 15 | |
| 16 | #define TICKSPERSECOND (CPUFREQ / 65536UL) |
| 17 | #define TICKSPERSECONDF ((float)CPUFREQ / 65536.0) |
| 18 | |
| 19 | struct timestamp { |
| 20 | uint16_t ticks; |
| 21 | uint16_t partticks; |
| 22 | }; |
| 23 | |
| 24 | /* Init timers */ |
| 25 | void timers_init(void); |
| 26 | |
| 27 | /* get ticks. |
| 28 | * Warning: Will reenable interrupts if they were disabled. */ |
| 29 | uint16_t getticks(void); |
| 30 | /* The same, but won't touch the global interrupt enable bit. |
| 31 | * MUST BE CALLED WITH INTERRUPTS DISABLED */ |
| 32 | uint16_t getticks_noirq(void); |
| 33 | |
| 34 | /* get timestamp |
| 35 | * Warning: Will reenable interrupts if they were disabled. */ |
| 36 | struct timestamp gettimestamp(void); |
| 37 | /* The same, but won't touch the global interrupt enable bit. |
| 38 | * MUST BE CALLED WITH INTERRUPTS DISABLED */ |
| 39 | struct timestamp gettimestamp_noirq(void); |
| 40 | |
| 41 | #endif /* _TIMERS_H_ */ |