From e7b61a928f0662a93fcbd38cd3a1e26a77c55e31 Mon Sep 17 00:00:00 2001 From: Steve Evans Date: Fri, 14 Jan 2022 03:22:52 +0000 Subject: [PATCH] Still update duration of next anticipated state even is current execution time is ignored --- src/main/fc/tasks.c | 28 +++++++++++++--------------- src/main/osd/osd.c | 24 ++++++++++++++---------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/main/fc/tasks.c b/src/main/fc/tasks.c index 463954b4e0..19021c65ce 100644 --- a/src/main/fc/tasks.c +++ b/src/main/fc/tasks.c @@ -225,23 +225,21 @@ static void taskUpdateRxMain(timeUs_t currentTimeUs) break; } - if (schedulerGetIgnoreTaskExecTime()) { - return; - } + if (!schedulerGetIgnoreTaskExecTime()) { + executeTimeUs = micros() - currentTimeUs + RX_TASK_MARGIN; - executeTimeUs = micros() - currentTimeUs + RX_TASK_MARGIN; + // If the scheduler has reduced the anticipatedExecutionTime due to task aging, pick that up + anticipatedExecutionTime = schedulerGetNextStateTime(); + if (anticipatedExecutionTime != (rxStateDurationFracUs[oldRxState] >> RX_TASK_DECAY_SHIFT)) { + rxStateDurationFracUs[oldRxState] = anticipatedExecutionTime << RX_TASK_DECAY_SHIFT; + } - // If the scheduler has reduced the anticipatedExecutionTime due to task aging, pick that up - anticipatedExecutionTime = schedulerGetNextStateTime(); - if (anticipatedExecutionTime != (rxStateDurationFracUs[oldRxState] >> RX_TASK_DECAY_SHIFT)) { - rxStateDurationFracUs[oldRxState] = anticipatedExecutionTime << RX_TASK_DECAY_SHIFT; - } - - if (executeTimeUs > (rxStateDurationFracUs[oldRxState] >> RX_TASK_DECAY_SHIFT)) { - rxStateDurationFracUs[oldRxState] = executeTimeUs << RX_TASK_DECAY_SHIFT; - } else { - // Slowly decay the max time - rxStateDurationFracUs[oldRxState]--; + if (executeTimeUs > (rxStateDurationFracUs[oldRxState] >> RX_TASK_DECAY_SHIFT)) { + rxStateDurationFracUs[oldRxState] = executeTimeUs << RX_TASK_DECAY_SHIFT; + } else { + // Slowly decay the max time + rxStateDurationFracUs[oldRxState]--; + } } if (debugMode == DEBUG_RX_STATE_TIME) { diff --git a/src/main/osd/osd.c b/src/main/osd/osd.c index 7a86267d57..342e62fbda 100644 --- a/src/main/osd/osd.c +++ b/src/main/osd/osd.c @@ -1006,6 +1006,8 @@ void osdDrawStats2(timeUs_t currentTimeUs) osdStatsEnabled = false; stats.armed_time = 0; } + + schedulerIgnoreTaskExecTime(); } #ifdef USE_ESC_SENSOR if (featureIsEnabled(FEATURE_ESC_SENSOR)) { @@ -1305,20 +1307,22 @@ void osdUpdate(timeUs_t currentTimeUs) break; } - executeTimeUs = micros() - currentTimeUs; + if (!schedulerGetIgnoreTaskExecTime()) { + executeTimeUs = micros() - currentTimeUs; - // On the first pass no element groups will have been formed, so all elements will have been - // rendered which is unrepresentative, so ignore - if (!firstPass) { - if (osdCurState == OSD_STATE_UPDATE_ELEMENTS) { - if (executeTimeUs > osdElementGroupDurationUs[osdCurElementGroup]) { - osdElementGroupDurationUs[osdCurElementGroup] = executeTimeUs; + // On the first pass no element groups will have been formed, so all elements will have been + // rendered which is unrepresentative, so ignore + if (!firstPass) { + if (osdCurState == OSD_STATE_UPDATE_ELEMENTS) { + if (executeTimeUs > osdElementGroupDurationUs[osdCurElementGroup]) { + osdElementGroupDurationUs[osdCurElementGroup] = executeTimeUs; + } } - } - if (executeTimeUs > osdStateDurationUs[osdCurState]) { - osdStateDurationUs[osdCurState] = executeTimeUs; + if (executeTimeUs > osdStateDurationUs[osdCurState]) { + osdStateDurationUs[osdCurState] = executeTimeUs; + } } }