]>
git.zerfleddert.de Git - fnordlicht-mini/blob - firmware/fnordlicht-controller/timer.c
8bd52638fe95aad2060bb5a00261c644e8654302
4 * (c) by Alexander Neumann <alexander@lochraster.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 * For more information on the GPL, please go to:
20 * http://www.gnu.org/copyleft/gpl.html
24 #include <avr/interrupt.h>
25 #include "../common/io.h"
28 static volatile uint8_t internal_counter
;
32 #if defined(__AVR_ATmega8__)
33 /* initialize timer2, CTC at 10ms, prescaler 1024 */
34 OCR2
= F_CPU
/1024/100;
35 TCCR2
= _BV(WGM21
) | _BV(CS22
) | _BV(CS21
) | _BV(CS20
);
37 #elif defined(__AVR_ATmega48__) || defined(__AVR_ATmega88__) || defined(__AVR_ATmega168__)
38 /* initialize timer2, CTC at 10ms, prescaler 1024 */
39 OCR2A
= F_CPU
/1024/100;
41 TCCR2B
= _BV(CS22
) | _BV(CS21
) | _BV(CS20
);
44 #error "unknown controller, unable to initialize timer2"
48 void timer_set(timer_t
*t
, uint8_t timeout
)
50 t
->current
= internal_counter
;
54 bool timer_expired(timer_t
*t
)
59 /* attention: this is not correct, if internal_counter is incremented by more than one
60 * between two calls of timer_expired()! */
61 if (t
->current
!= internal_counter
) {
63 t
->current
= internal_counter
;
69 /* timer interrupt function */
70 #if defined(__AVR_ATmega8__)
71 ISR(TIMER2_COMP_vect
, ISR_NOBLOCK
) {
74 #elif defined(__AVR_ATmega48__) || defined(__AVR_ATmega88__) || defined(__AVR_ATmega168__)
75 ISR(TIMER2_COMPA_vect
, ISR_NOBLOCK
) {