From e12527b8950f8f5ed4f7bb638bcf78abf3fc818c Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sun, 6 Aug 2017 19:26:48 -0400 Subject: avr: Move prescaler and sleep initialization from timer.c to main.c Signed-off-by: Kevin O'Connor --- src/avr/main.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/avr/main.c') 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) -- cgit v1.2.3-70-g09d2