aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2017-08-06 19:26:48 -0400
committerKevin O'Connor <kevin@koconnor.net>2017-08-07 19:39:57 -0400
commite12527b8950f8f5ed4f7bb638bcf78abf3fc818c (patch)
tree02db022e796e1b2d34cab1921112f6711cffae48 /src
parent114c8c5b6d9a0286ac5e457848965e4491a5b595 (diff)
downloadkutter-e12527b8950f8f5ed4f7bb638bcf78abf3fc818c.tar.gz
kutter-e12527b8950f8f5ed4f7bb638bcf78abf3fc818c.tar.xz
kutter-e12527b8950f8f5ed4f7bb638bcf78abf3fc818c.zip
avr: Move prescaler and sleep initialization from timer.c to main.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src')
-rw-r--r--src/avr/main.c21
-rw-r--r--src/avr/timer.c11
2 files changed, 21 insertions, 11 deletions
diff --git a/src/avr/main.c b/src/avr/main.c
index e3de4c03..9737c2be 100644
--- a/src/avr/main.c
+++ b/src/avr/main.c
@@ -39,6 +39,27 @@ dynmem_end(void)
* Misc functions
****************************************************************/
+// Initialize the clock prescaler (if necessary)
+void
+prescaler_init(void)
+{
+ if (CONFIG_AVR_CLKPR != -1 && (uint8_t)CONFIG_AVR_CLKPR != CLKPR) {
+ irqstatus_t flag = irq_save();
+ CLKPR = 0x80;
+ CLKPR = CONFIG_AVR_CLKPR;
+ irq_restore(flag);
+ }
+}
+DECL_INIT(prescaler_init);
+
+// The "sleep" instruction should cause the processor to enter "idle mode"
+void
+sleep_init(void)
+{
+ SMCR = 0x01;
+}
+DECL_INIT(sleep_init);
+
// Optimized crc16_ccitt for the avr processor
uint16_t
crc16_ccitt(char *buf, uint8_t len)
diff --git a/src/avr/timer.c b/src/avr/timer.c
index d9397187..e32a0b42 100644
--- a/src/avr/timer.c
+++ b/src/avr/timer.c
@@ -91,14 +91,6 @@ DECL_SHUTDOWN(timer_reset);
void
timer_init(void)
{
- if (CONFIG_AVR_CLKPR != -1 && (uint8_t)CONFIG_AVR_CLKPR != CLKPR) {
- // Program the clock prescaler
- irqstatus_t flag = irq_save();
- CLKPR = 0x80;
- CLKPR = CONFIG_AVR_CLKPR;
- irq_restore(flag);
- }
-
// no outputs
TCCR1A = 0;
// Normal Mode
@@ -110,9 +102,6 @@ timer_init(void)
// enable interrupt
TIMSK1 = 1<<OCIE1A;
irq_restore(flag);
-
- // Enable idle on sleep instruction
- SMCR = 0x01;
}
DECL_INIT(timer_init);