From d2986026b9ba3d971c3982f7839338f0662cb97f Mon Sep 17 00:00:00 2001
From: Rahix <rahix@rahix.de>
Date: Sat, 24 Aug 2019 18:59:26 +0200
Subject: [PATCH] fix(dispatcher): Initialize mutex before RTOS startup

Signed-off-by: Rahix <rahix@rahix.de>
---
 epicardium/modules/dispatcher.c | 7 +++++--
 epicardium/modules/hardware.c   | 5 +++++
 epicardium/modules/modules.h    | 1 +
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/epicardium/modules/dispatcher.c b/epicardium/modules/dispatcher.c
index 1f504eca..03f8534c 100644
--- a/epicardium/modules/dispatcher.c
+++ b/epicardium/modules/dispatcher.c
@@ -13,14 +13,17 @@ TaskHandle_t dispatcher_task_id;
 static StaticSemaphore_t api_mutex_data;
 SemaphoreHandle_t api_mutex = NULL;
 
+void dispatcher_mutex_init(void)
+{
+	api_mutex = xSemaphoreCreateMutexStatic(&api_mutex_data);
+}
+
 /*
  * API dispatcher task.  This task will sleep until an API call is issued and
  * then wake up to dispatch it.
  */
 void vApiDispatcher(void *pvParameters)
 {
-	api_mutex = xSemaphoreCreateMutexStatic(&api_mutex_data);
-
 	LOG_DEBUG("dispatcher", "Ready.");
 	while (1) {
 		if (api_dispatcher_poll()) {
diff --git a/epicardium/modules/hardware.c b/epicardium/modules/hardware.c
index c944c6b9..91a87471 100644
--- a/epicardium/modules/hardware.c
+++ b/epicardium/modules/hardware.c
@@ -177,6 +177,11 @@ int hardware_early_init(void)
 	 */
 	hwlock_init();
 
+	/*
+	 * API Dispatcher Mutex
+	 */
+	dispatcher_mutex_init();
+
 	return 0;
 }
 
diff --git a/epicardium/modules/modules.h b/epicardium/modules/modules.h
index 9eea0cb6..87124144 100644
--- a/epicardium/modules/modules.h
+++ b/epicardium/modules/modules.h
@@ -9,6 +9,7 @@
 
 /* ---------- Dispatcher --------------------------------------------------- */
 void vApiDispatcher(void *pvParameters);
+void dispatcher_mutex_init(void);
 extern SemaphoreHandle_t api_mutex;
 extern TaskHandle_t dispatcher_task_id;
 
-- 
GitLab