X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/blobdiff_plain/d332e3337306d5f8b5c810048bbd145391c33f29..89826c563e38a30d5bfc589905eb1202fa14b751:/avr/timer.c diff --git a/avr/timer.c b/avr/timer.c index e222e68..03c86c8 100644 --- a/avr/timer.c +++ b/avr/timer.c @@ -1,22 +1,23 @@ /* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0 */ -#include "common.h" +#include "timer.h" #include #include #include "time.h" -#include "timer.h" /* timer interrupt/overflow counter */ /* counts up every ms. */ static volatile uint32_t timestamp; -/*---------------------------------------------------------*/ -/* 1000Hz timer interrupt generated by OC3A */ -/*---------------------------------------------------------*/ - -ISR(TIMER3_COMPA_vect) +/* + * 1000Hz timer interrupt generated by OC4A + */ +ISR(TIMER4_COMPA_vect) { static int_fast8_t tick_10ms; static int_fast8_t tick_1s; @@ -24,6 +25,8 @@ ISR(TIMER3_COMPA_vect) extern void disk_timerproc(void); + OCR4A += F_CPU / 1000; /* 1000Hz interval */ + timestamp++; i = tick_10ms + 1; @@ -44,24 +47,15 @@ ISR(TIMER3_COMPA_vect) tick_10ms = i; } - /*--------------------------------------------------------------------------*/ -#if 0 -void timer_setup(void) +void setup_timer(void) { - - /* Clock */ - CLKPR = _BV(CLKPCE); - CLKPR = 0; - - /* Timer */ - - OCR1A = F_CPU / 1000 - 1; // Timer1: 1000Hz interval (OC1A) - TCCR1B = 0b00001001; - TIMSK1 = _BV(OCIE1A); // Enable TC1.oca interrupt + PRR1 &= ~_BV(PRTIM4); + OCR4A = F_CPU / 1000 - 1; /* Timer4: 1000Hz interval */ + TCCR4B = (0b00<