aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/common/avr/timer.c
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/common/avr/timer.c')
-rw-r--r--tmk_core/common/avr/timer.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/tmk_core/common/avr/timer.c b/tmk_core/common/avr/timer.c
index 84af44488..369015200 100644
--- a/tmk_core/common/avr/timer.c
+++ b/tmk_core/common/avr/timer.c
@@ -29,25 +29,35 @@ volatile uint32_t timer_count;
29 29
30void timer_init(void) 30void timer_init(void)
31{ 31{
32 // Timer0 CTC mode
33 TCCR0A = 0x02;
34
35#if TIMER_PRESCALER == 1 32#if TIMER_PRESCALER == 1
36 TCCR0B = 0x01; 33 uint8_t prescaler = 0x01;
37#elif TIMER_PRESCALER == 8 34#elif TIMER_PRESCALER == 8
38 TCCR0B = 0x02; 35 uint8_t prescaler = 0x02;
39#elif TIMER_PRESCALER == 64 36#elif TIMER_PRESCALER == 64
40 TCCR0B = 0x03; 37 uint8_t prescaler = 0x03;
41#elif TIMER_PRESCALER == 256 38#elif TIMER_PRESCALER == 256
42 TCCR0B = 0x04; 39 uint8_t prescaler = 0x04;
43#elif TIMER_PRESCALER == 1024 40#elif TIMER_PRESCALER == 1024
44 TCCR0B = 0x05; 41 uint8_t prescaler = 0x05;
45#else 42#else
46# error "Timer prescaler value is NOT vaild." 43# error "Timer prescaler value is NOT vaild."
47#endif 44#endif
48 45
46#ifndef __AVR_ATmega32A__
47 // Timer0 CTC mode
48 TCCR0A = 0x02;
49
50 TCCR0B = prescaler;
51
49 OCR0A = TIMER_RAW_TOP; 52 OCR0A = TIMER_RAW_TOP;
50 TIMSK0 = (1<<OCIE0A); 53 TIMSK0 = (1<<OCIE0A);
54#else
55 // Timer0 CTC mode
56 TCCR0 = (1 << WGM01) | prescaler;
57
58 OCR0 = TIMER_RAW_TOP;
59 TIMSK = (1 << OCIE0);
60#endif
51} 61}
52 62
53inline 63inline
@@ -107,7 +117,12 @@ uint32_t timer_elapsed32(uint32_t last)
107} 117}
108 118
109// excecuted once per 1ms.(excess for just timer count?) 119// excecuted once per 1ms.(excess for just timer count?)
110ISR(TIMER0_COMPA_vect) 120#ifndef __AVR_ATmega32A__
121#define TIMER_INTERRUPT_VECTOR TIMER0_COMPA_vect
122#else
123#define TIMER_INTERRUPT_VECTOR TIMER0_COMP_vect
124#endif
125ISR(TIMER_INTERRUPT_VECTOR, ISR_NOBLOCK)
111{ 126{
112 timer_count++; 127 timer_count++;
113} 128}