From fa3d5c345893e19b0c1eaf73ebd8a880b9c847b4 Mon Sep 17 00:00:00 2001
From: Rahix <rahix@rahix.de>
Date: Sat, 8 Jun 2019 18:45:41 +0200
Subject: [PATCH] feat(dual-core): Use {sev,wfe} to synchronize cores

Signed-off-by: Rahix <rahix@rahix.de>
---
 hw-tests/dual-core/core1.c | 6 ++++--
 hw-tests/dual-core/main.c  | 7 +++++++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/hw-tests/dual-core/core1.c b/hw-tests/dual-core/core1.c
index 605bf0e9a..989c611a0 100644
--- a/hw-tests/dual-core/core1.c
+++ b/hw-tests/dual-core/core1.c
@@ -6,14 +6,16 @@ static const gpio_cfg_t motor_pin = {PORT_0, PIN_8, GPIO_FUNC_OUT, GPIO_PAD_NONE
 
 int main(void)
 {
+	// Enable rxev on core1
+	MXC_GCR->evten |= 0x20;
 	for (int i = 0; 1; i++) {
-		printf("Hello from core 1! %d\n", i);
+		__asm volatile("wfe");
+		printf("core1: Hello! %d\n", i);
 
 #if 0
 		GPIO_OutSet(&motor_pin);
 		mxc_delay(30000);
 		GPIO_OutClr(&motor_pin);
 #endif
-		mxc_delay(970000);
 	}
 }
diff --git a/hw-tests/dual-core/main.c b/hw-tests/dual-core/main.c
index 8a8de068f..d8e94276f 100644
--- a/hw-tests/dual-core/main.c
+++ b/hw-tests/dual-core/main.c
@@ -56,5 +56,12 @@ int main(void)
         leds_update();
         TMR_Delay(MXC_TMR0, MSEC(10), 0);
         h++;
+
+        // Send a txev using `sev` every once in a while to wake up core1
+        // and let it do something
+        if (h % 100 == 0) {
+            printf("core0: Triggering core1 using SEV ...\n");
+            __asm volatile("sev");
+        }
     }
 }
-- 
GitLab