From fd1be4ffeb3c5d6b5786d6761c2cca81688c3988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Phillip=20K=C3=BChne?= Date: Sun, 16 Feb 2025 19:17:36 +0100 Subject: [PATCH] Improve Power State Update Task timing --- src/power/PowerManager.cpp | 5 ++++- src/power/PowerParameters.h | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/power/PowerManager.cpp b/src/power/PowerManager.cpp index 760cfb6..420598d 100644 --- a/src/power/PowerManager.cpp +++ b/src/power/PowerManager.cpp @@ -14,8 +14,11 @@ SemaphoreHandle_t PowerManager::powerMutex = NULL; void vTaskUpdatePowerState(void *pvParameters) { for (;;) { ESP_LOGV(TAG, "Updating Power State..."); + TickType_t executionStart = xTaskGetTickCount(); PowerManager::updatePowerStateHandler(); - vTaskDelay(pdMS_TO_TICKS(10)); + vTaskDelayUntil( + &executionStart, + pdMS_TO_TICKS(PowerParameters::POWER_STATE_UPDATE_INTERVAL_MS)); } } diff --git a/src/power/PowerParameters.h b/src/power/PowerParameters.h index bf16281..24ea9f0 100644 --- a/src/power/PowerParameters.h +++ b/src/power/PowerParameters.h @@ -12,6 +12,7 @@ #ifndef PowerParameters_h #define PowerParameters_h +#include namespace PowerParameters { struct Battery { @@ -114,6 +115,9 @@ enum PowerConsumers { MOTOR_RIGHT, IMU }; + +static constexpr uint32_t POWER_STATE_UPDATE_INTERVAL_MS = 10; + }; // namespace PowerParameters #endif // Consumptions_h \ No newline at end of file