From 69c6db98f12f1fe103a1177ec37444bc3024645f Mon Sep 17 00:00:00 2001
From: Daniel Friesel <derf@finalrewind.org>
Date: Fri, 12 Oct 2018 10:45:24 +0200
Subject: [PATCH] arduino nano: ignore non-timer interrupts for loop

---
 src/arch/arduino-nano/arch.cc | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/arch/arduino-nano/arch.cc b/src/arch/arduino-nano/arch.cc
index 7f18c38..3009637 100644
--- a/src/arch/arduino-nano/arch.cc
+++ b/src/arch/arduino-nano/arch.cc
@@ -32,10 +32,14 @@ void wakeup();
 #if defined(WITH_LOOP) || defined(TIMER_S)
 
 #include "driver/uptime.h"
-void loop();
 
 #endif
 
+#if defined(WITH_LOOP)
+extern void loop();
+volatile char run_loop = 0;
+#endif
+
 void Arch::idle_loop(void)
 {
 	while (1) {
@@ -44,13 +48,13 @@ void Arch::idle_loop(void)
 		SMCR = 0;
 		asm("wdr");
 #ifdef WITH_LOOP
-		loop();
+		if (run_loop) {
+			loop();
+			run_loop = 0;
+		}
 #endif
 #ifdef WITH_WAKEUP
 		wakeup();
-#endif
-#ifdef TIMER_S
-		uptime.tick_s();
 #endif
 	}
 }
@@ -79,6 +83,12 @@ Arch arch;
 
 ISR(TIMER1_COMPA_vect)
 {
+#ifdef WITH_LOOP
+	run_loop = 1;
+#endif
+#ifdef TIMER_S
+	uptime.tick_s();
+#endif
 }
 
 #endif
-- 
GitLab