From 4a8f9407b8148d017af567ce41f0d42aecbe9b05 Mon Sep 17 00:00:00 2001
From: Kevin O'Connor <kevin@koconnor.net>
Date: Sat, 28 Apr 2018 20:04:32 -0400
Subject: [PATCH] avr: Do not use Idle mode

The AVR chips (bizarrely) start an ADC conversion when entering Idle
mode.  This behavior can cause the ADC to be busy when a sample is
required.  Worse, if a series of events cause the cpu to enter and
leave Idle mode with a timing similar to the ADC checking rate then it
can cause the ADC to show as busy for extended periods.  This could
cause high MCU load and possibly lead to a "Rescheduled timer in the
past" shutdown.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
---
 src/avr/irq.h  | 2 +-
 src/avr/main.c | 8 --------
 2 files changed, 1 insertion(+), 9 deletions(-)

diff --git a/src/avr/irq.h b/src/avr/irq.h
index 349c4c434..63a1018bb 100644
--- a/src/avr/irq.h
+++ b/src/avr/irq.h
@@ -29,7 +29,7 @@ static inline void irq_restore(irqstatus_t flag) {
 }
 
 static inline void irq_wait(void) {
-    asm("sei\n    sleep\n    cli" : : : "memory");
+    asm("sei\n    nop\n    cli" : : : "memory");
 }
 
 static inline void irq_poll(void) {
diff --git a/src/avr/main.c b/src/avr/main.c
index 9737c2be4..2655d307f 100644
--- a/src/avr/main.c
+++ b/src/avr/main.c
@@ -52,14 +52,6 @@ prescaler_init(void)
 }
 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)