From 374ca0bbeb65a90e7ddd9c18f6394dc404600bb7 Mon Sep 17 00:00:00 2001
From: schneider <schneider@blinkenlichts.net>
Date: Wed, 15 Sep 2021 01:52:30 +0200
Subject: [PATCH] feat(sleep): Allow the interrupt module to break epic_sleep

---
 epicardium/drivers/sleep.c        | 4 +++-
 epicardium/user_core/interrupts.c | 9 +++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/epicardium/drivers/sleep.c b/epicardium/drivers/sleep.c
index 8370d47be..524a4a5ab 100644
--- a/epicardium/drivers/sleep.c
+++ b/epicardium/drivers/sleep.c
@@ -210,5 +210,7 @@ void sleep_deepsleep(void)
 
 void epic_sleep(uint32_t ms)
 {
-	vTaskDelay(pdMS_TO_TICKS(ms));
+	/* Allow the interrupt module to break us out of a call to
+	 * epic_sleep() */
+	ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(ms));
 }
diff --git a/epicardium/user_core/interrupts.c b/epicardium/user_core/interrupts.c
index 76675eb28..0ccfd87fb 100644
--- a/epicardium/user_core/interrupts.c
+++ b/epicardium/user_core/interrupts.c
@@ -2,6 +2,7 @@
 #include "os/core.h"
 #include "epicardium.h"
 #include "api/interrupt-sender.h"
+#include "user_core/user_core.h"
 #include <assert.h>
 
 struct interrupt_priv {
@@ -45,6 +46,10 @@ void interrupt_trigger_sync(api_int_id_t id)
 		;
 
 	api_interrupt_trigger(id);
+
+	/* Break the dispatcher task out of a potential call
+	 * to epic_sleep() */
+	xTaskNotifyGive(dispatcher_task_id);
 out:
 	mutex_unlock(&interrupt_mutex);
 }
@@ -171,6 +176,10 @@ void vInterruptsTask(void *pvParameters)
 			interrupt_data.has_pending = false;
 		} else if (interrupt_data.int_enabled[current_irq]) {
 			api_interrupt_trigger(current_irq);
+
+			/* Break the dispatcher task out of a potential call
+			 * to epic_sleep() */
+			xTaskNotifyGive(dispatcher_task_id);
 		}
 
 		mutex_unlock(&interrupt_mutex);
-- 
GitLab