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 | qmk_firmware-c77c5043a121f195b3a552feb8283424a0652ce2.tar.gz qmk_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/>. | |||
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | // counter resolution 1ms | 24 | // counter resolution 1ms |
| 25 | volatile uint16_t timer_count = 0; | 25 | volatile uint32_t timer_count = 0; |
| 26 | 26 | ||
| 27 | void timer_init(void) | 27 | void timer_init(void) |
| 28 | { | 28 | { |
| @@ -59,7 +59,20 @@ void timer_clear(void) | |||
| 59 | inline | 59 | inline |
| 60 | uint16_t timer_read(void) | 60 | uint16_t timer_read(void) |
| 61 | { | 61 | { |
| 62 | uint16_t t; | 62 | uint32_t t; |
| 63 | |||
| 64 | uint8_t sreg = SREG; | ||
| 65 | cli(); | ||
| 66 | t = timer_count; | ||
| 67 | SREG = sreg; | ||
| 68 | |||
| 69 | return (t & 0xFFFF); | ||
| 70 | } | ||
| 71 | |||
| 72 | inline | ||
| 73 | uint32_t timer_read32(void) | ||
| 74 | { | ||
| 75 | uint32_t t; | ||
| 63 | 76 | ||
| 64 | uint8_t sreg = SREG; | 77 | uint8_t sreg = SREG; |
| 65 | cli(); | 78 | cli(); |
| @@ -72,14 +85,27 @@ uint16_t timer_read(void) | |||
| 72 | inline | 85 | inline |
| 73 | uint16_t timer_elapsed(uint16_t last) | 86 | uint16_t timer_elapsed(uint16_t last) |
| 74 | { | 87 | { |
| 75 | uint16_t t; | 88 | uint32_t t; |
| 89 | |||
| 90 | uint8_t sreg = SREG; | ||
| 91 | cli(); | ||
| 92 | t = timer_count; | ||
| 93 | SREG = sreg; | ||
| 94 | |||
| 95 | return TIMER_DIFF_16((t & 0xFFFF), last); | ||
| 96 | } | ||
| 97 | |||
| 98 | inline | ||
| 99 | uint32_t timer_elapsed32(uint32_t last) | ||
| 100 | { | ||
| 101 | uint32_t t; | ||
| 76 | 102 | ||
| 77 | uint8_t sreg = SREG; | 103 | uint8_t sreg = SREG; |
| 78 | cli(); | 104 | cli(); |
| 79 | t = timer_count; | 105 | t = timer_count; |
| 80 | SREG = sreg; | 106 | SREG = sreg; |
| 81 | 107 | ||
| 82 | return TIMER_DIFF_MS(t, last); | 108 | return TIMER_DIFF_32(t, last); |
| 83 | } | 109 | } |
| 84 | 110 | ||
| 85 | // excecuted once per 1ms.(excess for just timer count?) | 111 | // excecuted once per 1ms.(excess for just timer count?) |
