diff options
| author | tmk <nobody@nowhere> | 2014-06-16 11:12:45 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2014-07-30 14:07:43 +0900 |
| commit | 867f115bee190515aa195dc3e58f1c381ea9695b (patch) | |
| tree | a738787299cbac2fbaf26e586393f4d4170e8775 /common | |
| parent | f15b2691c92e1d9b3c0e59363c803ec540303f37 (diff) | |
| download | qmk_firmware-867f115bee190515aa195dc3e58f1c381ea9695b.tar.gz qmk_firmware-867f115bee190515aa195dc3e58f1c381ea9695b.zip | |
Port timer to mbed
Diffstat (limited to 'common')
| -rw-r--r-- | common/avr/timer.c (renamed from common/timer.c) | 1 | ||||
| -rw-r--r-- | common/mbed/timer.c | 40 | ||||
| -rw-r--r-- | common/timer.h | 19 |
3 files changed, 41 insertions, 19 deletions
diff --git a/common/timer.c b/common/avr/timer.c index e0dec6cef..292b41c3a 100644 --- a/common/timer.c +++ b/common/avr/timer.c | |||
| @@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 18 | #include <avr/io.h> | 18 | #include <avr/io.h> |
| 19 | #include <avr/interrupt.h> | 19 | #include <avr/interrupt.h> |
| 20 | #include <stdint.h> | 20 | #include <stdint.h> |
| 21 | #include "timer_avr.h" | ||
| 21 | #include "timer.h" | 22 | #include "timer.h" |
| 22 | 23 | ||
| 23 | 24 | ||
diff --git a/common/mbed/timer.c b/common/mbed/timer.c new file mode 100644 index 000000000..a64a77239 --- /dev/null +++ b/common/mbed/timer.c | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | #include "cmsis.h" | ||
| 2 | #include "timer.h" | ||
| 3 | |||
| 4 | /* Mill second tick count */ | ||
| 5 | volatile uint32_t timer_count = 0; | ||
| 6 | |||
| 7 | /* Timer interrupt handler */ | ||
| 8 | void SysTick_Handler(void) { | ||
| 9 | timer_count++; | ||
| 10 | } | ||
| 11 | |||
| 12 | void timer_init(void) | ||
| 13 | { | ||
| 14 | SysTick_Config(SystemCoreClock / 1000); /* 1ms tick */ | ||
| 15 | } | ||
| 16 | |||
| 17 | void timer_clear(void) | ||
| 18 | { | ||
| 19 | timer_count = 0; | ||
| 20 | } | ||
| 21 | |||
| 22 | uint16_t timer_read(void) | ||
| 23 | { | ||
| 24 | return (uint16_t)(timer_count & 0xFFFF); | ||
| 25 | } | ||
| 26 | |||
| 27 | uint32_t timer_read32(void) | ||
| 28 | { | ||
| 29 | return timer_count; | ||
| 30 | } | ||
| 31 | |||
| 32 | uint16_t timer_elapsed(uint16_t last) | ||
| 33 | { | ||
| 34 | return TIMER_DIFF_16(timer_read(), last); | ||
| 35 | } | ||
| 36 | |||
| 37 | uint32_t timer_elapsed32(uint32_t last) | ||
| 38 | { | ||
| 39 | return TIMER_DIFF_32(timer_read32(), last); | ||
| 40 | } | ||
diff --git a/common/timer.h b/common/timer.h index 6437473ff..f0c5ffc98 100644 --- a/common/timer.h +++ b/common/timer.h | |||
| @@ -20,25 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 20 | 20 | ||
| 21 | #include <stdint.h> | 21 | #include <stdint.h> |
| 22 | 22 | ||
| 23 | #ifndef TIMER_PRESCALER | ||
| 24 | # if F_CPU > 16000000 | ||
| 25 | # define TIMER_PRESCALER 256 | ||
| 26 | # elif F_CPU > 2000000 | ||
| 27 | # define TIMER_PRESCALER 64 | ||
| 28 | # elif F_CPU > 250000 | ||
| 29 | # define TIMER_PRESCALER 8 | ||
| 30 | # else | ||
| 31 | # define TIMER_PRESCALER 1 | ||
| 32 | # endif | ||
| 33 | #endif | ||
| 34 | #define TIMER_RAW_FREQ (F_CPU/TIMER_PRESCALER) | ||
| 35 | #define TIMER_RAW TCNT0 | ||
| 36 | #define TIMER_RAW_TOP (TIMER_RAW_FREQ/1000) | ||
| 37 | |||
| 38 | #if (TIMER_RAW_TOP > 255) | ||
| 39 | # error "Timer0 can't count 1ms at this clock freq. Use larger prescaler." | ||
| 40 | #endif | ||
| 41 | |||
| 42 | #define TIMER_DIFF(a, b, max) ((a) >= (b) ? (a) - (b) : (max) - (b) + (a)) | 23 | #define TIMER_DIFF(a, b, max) ((a) >= (b) ? (a) - (b) : (max) - (b) + (a)) |
| 43 | #define TIMER_DIFF_8(a, b) TIMER_DIFF(a, b, UINT8_MAX) | 24 | #define TIMER_DIFF_8(a, b) TIMER_DIFF(a, b, UINT8_MAX) |
| 44 | #define TIMER_DIFF_16(a, b) TIMER_DIFF(a, b, UINT16_MAX) | 25 | #define TIMER_DIFF_16(a, b) TIMER_DIFF(a, b, UINT16_MAX) |
