X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=common%2Ftimer.c;h=e0dec6cefcf9d07fef9f25b32f8efcd640e1958e;hb=48433a5e9988647a737234c11dd9db4080fd4a4e;hp=48a38c9b68211116c75b948c21bd9fe3e444a1cc;hpb=62d1ebb91c7b381ce3d88aad9ee0b03bea9fce26;p=tmk_firmware.git diff --git a/common/timer.c b/common/timer.c index 48a38c9..e0dec6c 100644 --- a/common/timer.c +++ b/common/timer.c @@ -22,7 +22,8 @@ along with this program. If not, see . // counter resolution 1ms -volatile uint16_t timer_count = 0; +// NOTE: union { uint32_t timer32; struct { uint16_t dummy; uint16_t timer16; }} +volatile uint32_t timer_count = 0; void timer_init(void) { @@ -59,7 +60,20 @@ void timer_clear(void) inline uint16_t timer_read(void) { - uint16_t t; + uint32_t t; + + uint8_t sreg = SREG; + cli(); + t = timer_count; + SREG = sreg; + + return (t & 0xFFFF); +} + +inline +uint32_t timer_read32(void) +{ + uint32_t t; uint8_t sreg = SREG; cli(); @@ -72,14 +86,27 @@ uint16_t timer_read(void) inline uint16_t timer_elapsed(uint16_t last) { - uint16_t t; + uint32_t t; + + uint8_t sreg = SREG; + cli(); + t = timer_count; + SREG = sreg; + + return TIMER_DIFF_16((t & 0xFFFF), last); +} + +inline +uint32_t timer_elapsed32(uint32_t last) +{ + uint32_t t; uint8_t sreg = SREG; cli(); t = timer_count; SREG = sreg; - return TIMER_DIFF_MS(t, last); + return TIMER_DIFF_32(t, last); } // excecuted once per 1ms.(excess for just timer count?)