summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo C2018-09-08 20:29:11 +0200
committerLeo C2018-09-08 20:29:11 +0200
commit89826c563e38a30d5bfc589905eb1202fa14b751 (patch)
treedd078beac30e6433c2c7697dca0fb7387d7e14fd
parent226d32211880a061265faf6b8eadaf6ca1ec7a38 (diff)
downloadz180-stamp-89826c563e38a30d5bfc589905eb1202fa14b751.zip
move sys timer setup from main to timer.c
-rw-r--r--avr/main.c9
-rw-r--r--avr/timer.c9
-rw-r--r--include/timer.h6
3 files changed, 16 insertions, 8 deletions
diff --git a/avr/main.c b/avr/main.c
index 1fba3cb..0a49a1f 100644
--- a/avr/main.c
+++ b/avr/main.c
@@ -110,7 +110,7 @@ void setup_avr(void)
_BV(PRUSART3) | _BV(PRUSART2) | _BV(PRUSART1);
- /* disable analog comparator */
+ /* Disable analog comparator */
ACSR = _BV(ACD);
/* Ports */
@@ -118,11 +118,8 @@ void setup_avr(void)
CLKPR = _BV(CLKPCE);
CLKPR = 0;
- /* Timer */
- PRR1 &= ~_BV(PRTIM4);
- OCR4A = F_CPU / 1000 - 1; /* Timer4: 1000Hz interval */
- TCCR4B = (0b00<<WGM42)|(0b001<<CS40); /* Normal Mode, Prescaler 1 */
- TIMSK4 = _BV(OCIE4A); /* Enable Output Compare A interrupt */
+ /* System timer */
+ setup_timer();
/* INT5, INT6: falling edge */
EICRB = (EICRB & ~((0b11 << ISC50) | (0b11 << ISC60))) |
diff --git a/avr/timer.c b/avr/timer.c
index 1b15985..03c86c8 100644
--- a/avr/timer.c
+++ b/avr/timer.c
@@ -47,6 +47,15 @@ ISR(TIMER4_COMPA_vect)
tick_10ms = i;
}
+/*--------------------------------------------------------------------------*/
+
+void setup_timer(void)
+{
+ PRR1 &= ~_BV(PRTIM4);
+ OCR4A = F_CPU / 1000 - 1; /* Timer4: 1000Hz interval */
+ TCCR4B = (0b00<<WGM42)|(0b001<<CS40); /* Normal Mode, Prescaler 1 */
+ TIMSK4 = _BV(OCIE4A); /* Enable Output Compare A interrupt */
+}
/*--------------------------------------------------------------------------*/
diff --git a/include/timer.h b/include/timer.h
index 83bc329..d604008 100644
--- a/include/timer.h
+++ b/include/timer.h
@@ -1,7 +1,7 @@
/*
- * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ * (C) Copyright 2014,2018 Leo C. <erbl259-lmu@yahoo.de>
*
- * SPDX-License-Identifier: GPL-2.0+
+ * SPDX-License-Identifier: GPL-2.0
*/
#ifndef TIMER_H
@@ -9,6 +9,8 @@
#include "common.h"
+void setup_timer(void);
+
uint32_t get_timer(uint32_t);
#endif /* TIMER_H */