Skip to content

Commit

Permalink
main: Increase pre-reboot robustness
Browse files Browse the repository at this point in the history
Abort immediately if pre-reboot task cannot be created for any reason.
  • Loading branch information
MattiasTF committed Jul 26, 2024
1 parent 7884ede commit fd15453
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion software/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ static void pre_reboot_task(void *arg)
esp_system_abort(pre_reboot_message);
}

static void task_creation_failed(int error_code)
{
char msg[48];
msg[0] = 0;
snprintf(msg, ARRAY_SIZE(msg), "Failed to create pre-reboot task: %i", error_code);
esp_system_abort(msg);
}

#endif

static void pre_reboot_helper(void)
Expand All @@ -175,14 +183,23 @@ static void pre_reboot(void)
#if MODULE_WATCHDOG_AVAILABLE()
watchdog.add("pre_reboot", pre_reboot_message, PRE_REBOOT_MAX_DURATION, 0, true);
#else
xTaskCreatePinnedToCore(
auto err = xTaskCreatePinnedToCore(
pre_reboot_task,
"pre_reboot_task",
640,
nullptr,
ESP_TASK_PRIO_MAX,
nullptr,
1);

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
#pragma GCC diagnostic ignored "-Wuseless-cast"
// pdPASS expands to an old-style cast that is also useless
if (err != pdPASS) {
task_creation_failed(err);
}
#pragma GCC diagnostic pop
#endif

pre_reboot_helper();
Expand Down

0 comments on commit fd15453

Please sign in to comment.