Skip to content
Snippets Groups Projects
Verified Commit cc5f0e29 authored by rahix's avatar rahix
Browse files

chore(lifecycle): Port to new mutex API


Using a bare FreeRTOS mutex is deprecated.  Replace it with the new
`struct mutex`.  This should increase stability of the module.

Signed-off-by: default avatarRahix <rahix@rahix.de>
parent 9a5a46cd
Branches
Tags
No related merge requests found
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "modules/log.h" #include "modules/log.h"
#include "modules/modules.h" #include "modules/modules.h"
#include "modules/config.h" #include "modules/config.h"
#include "modules/mutex.h"
#include "api/dispatcher.h" #include "api/dispatcher.h"
#include "api/interrupt-sender.h" #include "api/interrupt-sender.h"
#include "l0der/l0der.h" #include "l0der/l0der.h"
...@@ -10,7 +11,6 @@ ...@@ -10,7 +11,6 @@
#include "FreeRTOS.h" #include "FreeRTOS.h"
#include "task.h" #include "task.h"
#include "semphr.h"
#include <string.h> #include <string.h>
#include <stdbool.h> #include <stdbool.h>
...@@ -26,8 +26,7 @@ ...@@ -26,8 +26,7 @@
#define PYINTERPRETER "" #define PYINTERPRETER ""
static TaskHandle_t lifecycle_task = NULL; static TaskHandle_t lifecycle_task = NULL;
static StaticSemaphore_t core1_mutex_data; static struct mutex core1_mutex = { 0 };
static SemaphoreHandle_t core1_mutex = NULL;
enum payload_type { enum payload_type {
PL_INVALID = 0, PL_INVALID = 0,
...@@ -254,11 +253,7 @@ static void load_menu(bool reset) ...@@ -254,11 +253,7 @@ static void load_menu(bool reset)
{ {
LOG_DEBUG("lifecycle", "Into the menu"); LOG_DEBUG("lifecycle", "Into the menu");
if (xSemaphoreTake(core1_mutex, BLOCK_WAIT) != pdTRUE) { mutex_lock(&core1_mutex);
LOG_ERR("lifecycle",
"Can't load because mutex is blocked (menu).");
return;
}
int ret = load_async("menu.py", reset); int ret = load_async("menu.py", reset);
if (ret < 0) { if (ret < 0) {
...@@ -278,7 +273,7 @@ static void load_menu(bool reset) ...@@ -278,7 +273,7 @@ static void load_menu(bool reset)
} }
} }
xSemaphoreGive(core1_mutex); mutex_unlock(&core1_mutex);
} }
/* Helpers }}} */ /* Helpers }}} */
...@@ -298,14 +293,9 @@ void epic_system_reset(void) ...@@ -298,14 +293,9 @@ void epic_system_reset(void)
*/ */
int epic_exec(char *name) int epic_exec(char *name)
{ {
if (xSemaphoreTake(core1_mutex, BLOCK_WAIT) != pdTRUE) { mutex_lock(&core1_mutex);
LOG_ERR("lifecycle",
"Can't load because mutex is blocked (epi exec).");
return -EBUSY;
}
int ret = load_sync(name, true); int ret = load_sync(name, true);
xSemaphoreGive(core1_mutex); mutex_unlock(&core1_mutex);
return ret; return ret;
} }
...@@ -318,13 +308,9 @@ int epic_exec(char *name) ...@@ -318,13 +308,9 @@ int epic_exec(char *name)
*/ */
int __epic_exec(char *name) int __epic_exec(char *name)
{ {
if (xSemaphoreTake(core1_mutex, BLOCK_WAIT) != pdTRUE) { mutex_lock(&core1_mutex);
LOG_ERR("lifecycle",
"Can't load because mutex is blocked (1 exec).");
return -EBUSY;
}
int ret = load_async(name, false); int ret = load_async(name, false);
xSemaphoreGive(core1_mutex); mutex_unlock(&core1_mutex);
return ret; return ret;
} }
...@@ -361,17 +347,14 @@ void return_to_menu(void) ...@@ -361,17 +347,14 @@ void return_to_menu(void)
void vLifecycleTask(void *pvParameters) void vLifecycleTask(void *pvParameters)
{ {
lifecycle_task = xTaskGetCurrentTaskHandle(); lifecycle_task = xTaskGetCurrentTaskHandle();
core1_mutex = xSemaphoreCreateMutexStatic(&core1_mutex_data); mutex_create(&core1_mutex);
mutex_lock(&core1_mutex);
if (xSemaphoreTake(core1_mutex, 0) != pdTRUE) {
panic("lifecycle: Failed to acquire mutex after creation.");
}
LOG_DEBUG("lifecycle", "Booting core 1 ..."); LOG_DEBUG("lifecycle", "Booting core 1 ...");
core1_boot(); core1_boot();
vTaskDelay(pdMS_TO_TICKS(10)); vTaskDelay(pdMS_TO_TICKS(10));
xSemaphoreGive(core1_mutex); mutex_unlock(&core1_mutex);
/* If `main.py` exists, start it. Otherwise, start `menu.py`. */ /* If `main.py` exists, start it. Otherwise, start `menu.py`. */
if (epic_exec("main.py") < 0) { if (epic_exec("main.py") < 0) {
...@@ -386,11 +369,7 @@ void vLifecycleTask(void *pvParameters) ...@@ -386,11 +369,7 @@ void vLifecycleTask(void *pvParameters)
while (1) { while (1) {
ulTaskNotifyTake(pdTRUE, portMAX_DELAY); ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
if (xSemaphoreTake(core1_mutex, BLOCK_WAIT) != pdTRUE) { mutex_lock(&core1_mutex);
LOG_ERR("lifecycle",
"Can't load because mutex is blocked (task).");
continue;
}
if (write_menu) { if (write_menu) {
write_menu = false; write_menu = false;
...@@ -406,6 +385,6 @@ void vLifecycleTask(void *pvParameters) ...@@ -406,6 +385,6 @@ void vLifecycleTask(void *pvParameters)
do_load((struct load_info *)&async_load); do_load((struct load_info *)&async_load);
xSemaphoreGive(core1_mutex); mutex_unlock(&core1_mutex);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment