From baf0850690605960bd90ac7f149892905066039b Mon Sep 17 00:00:00 2001 From: FredericG Date: Sun, 6 Mar 2011 11:50:54 +0000 Subject: [PATCH] OP-336 CPU usage calculation incorrect when armed - no measure the time between calculations git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2987 ebee16cc-31ac-478f-84a7-5cbb03baadba --- flight/Modules/System/systemmod.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/flight/Modules/System/systemmod.c b/flight/Modules/System/systemmod.c index 803123bb9..96efd4fb9 100644 --- a/flight/Modules/System/systemmod.c +++ b/flight/Modules/System/systemmod.c @@ -255,6 +255,7 @@ static void updateWDGstats() */ static void updateStats() { + static portTickType lastTickCount = 0; SystemStatsData stats; // Get stats and update @@ -271,8 +272,14 @@ static void updateStats() if (idleCounterClear) { idleCounter = 0; } - stats.CPULoad = - 100 - (uint8_t) round(100.0 * ((float)idleCounter / (float)(SYSTEM_UPDATE_PERIOD_MS / 1000)) / (float)IDLE_COUNTS_PER_SEC_AT_NO_LOAD); + + portTickType now = xTaskGetTickCount(); + if (now > lastTickCount) { + uint32_t dT = (xTaskGetTickCount() - lastTickCount) * portTICK_RATE_MS; // in ms + stats.CPULoad = + 100 - (uint8_t) round(100.0 * ((float)idleCounter / ((float)dT / 1000.0)) / (float)IDLE_COUNTS_PER_SEC_AT_NO_LOAD); + } //else: TickCount has wrapped, do not calc now + lastTickCount = now; idleCounterClear = 1; #if defined(PIOS_INCLUDE_ADC) && defined(PIOS_ADC_USE_TEMP_SENSOR)