diff options
author | tmk <nobody@nowhere> | 2012-09-02 23:47:18 +0900 |
---|---|---|
committer | tmk <nobody@nowhere> | 2012-09-02 23:47:18 +0900 |
commit | c77c5043a121f195b3a552feb8283424a0652ce2 (patch) | |
tree | 5b20b8c5cb7702408ffc10af0c259d71e6ce4ce9 /common/timer.c | |
parent | b17f52ebe188b612d0cb063bd2386434a952aaf4 (diff) | |
download | firmware-c77c5043a121f195b3a552feb8283424a0652ce2.tar.gz firmware-c77c5043a121f195b3a552feb8283424a0652ce2.tar.bz2 firmware-c77c5043a121f195b3a552feb8283424a0652ce2.zip |
usb_hid: Fix timer size uint16_t to uint32_t;
Diffstat (limited to 'common/timer.c')
-rw-r--r-- | common/timer.c | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/common/timer.c b/common/timer.c index 48a38c9b6..8b8d37e8b 100644 --- a/common/timer.c +++ b/common/timer.c @@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. // counter resolution 1ms -volatile uint16_t timer_count = 0; +volatile uint32_t timer_count = 0; void timer_init(void) { @@ -59,7 +59,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 +85,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?) |