diff options
author | Daniel Friesel <derf@finalrewind.org> | 2018-10-12 10:44:11 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2018-10-12 10:44:11 +0200 |
commit | fd1aabd0417bef53e7ff54df52eba80be5494d56 (patch) | |
tree | e0cb6183e82f1fbf78fb66c673eee8cb497bc658 /include/arch/arduino-nano/driver | |
parent | 4853a5593cc6147e1851e537b46a5128792939a5 (diff) |
half-baked timer implementation for MSP430 and Arduino
Diffstat (limited to 'include/arch/arduino-nano/driver')
-rw-r--r-- | include/arch/arduino-nano/driver/timer.h | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/include/arch/arduino-nano/driver/timer.h b/include/arch/arduino-nano/driver/timer.h index 267cb1d..98ef20e 100644 --- a/include/arch/arduino-nano/driver/timer.h +++ b/include/arch/arduino-nano/driver/timer.h @@ -1,23 +1,30 @@ #include <avr/io.h> #include <avr/interrupt.h> -#define ON_TIMER_INTERRUPT ISR(TIMER0_COMPA_vect) +#define ON_TIMER_INTERRUPT_head ISR(TIMER0_COMPA_vect) { +#define ON_TIMER_INTERRUPT_tail } class Timer { private: Timer(const Timer ©); - + unsigned char prescaler; public: Timer() {} - inline void setup(unsigned char const frequency) { + inline void setup_khz(unsigned char const frequency) { + OCR0A = frequency ? 255 / frequency : 1; + TCCR0A = _BV(WGM01); + prescaler = _BV(CS01) | _BV(CS00); + } + inline void setup_hz(unsigned char const frequency) { OCR0A = frequency ? 255 / frequency : 1; TCCR0A = _BV(WGM01); + prescaler = _BV(CS02) | _BV(CS00); } inline void start(unsigned char const interrupt) { TCNT0 = 0; - TCCR0B = _BV(CS01) | _BV(CS00); + TCCR0B = prescaler; if (interrupt) { TIMSK0 = _BV(OCIE0A); } |