1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-22 15:55:48 +03:00

Fix issues impacting RX_STATE_MODES state duration and add DEBUG_RX_STATE_TIME

This commit is contained in:
Steve Evans 2022-01-11 20:09:55 +00:00
parent 8d52a36150
commit c05ad2ec9b
7 changed files with 31 additions and 2 deletions

View file

@ -99,4 +99,5 @@ const char * const debugModeNames[DEBUG_COUNT] = {
"TIMING_ACCURACY",
"RX_EXPRESSLRS_SPI",
"RX_EXPRESSLRS_PHASELOCK",
"RX_STATE_TIME"
};

View file

@ -97,6 +97,7 @@ typedef enum {
DEBUG_TIMING_ACCURACY,
DEBUG_RX_EXPRESSLRS_SPI,
DEBUG_RX_EXPRESSLRS_PHASELOCK,
DEBUG_RX_STATE_TIME,
DEBUG_COUNT
} debugType_e;

View file

@ -659,6 +659,9 @@ static uint8_t applySelectAdjustment(adjustmentFunction_e adjustmentFunction, ui
static void calcActiveAdjustmentRanges(void)
{
// This initialisation upsets the scheduler task duration estimation
schedulerIgnoreTaskExecTime();
adjustmentRange_t defaultAdjustmentRange;
memset(&defaultAdjustmentRange, 0, sizeof(defaultAdjustmentRange));

View file

@ -182,9 +182,10 @@ bool taskUpdateRxMainInProgress()
static void taskUpdateRxMain(timeUs_t currentTimeUs)
{
static timeUs_t rxStateDurationFracUs[RX_STATE_COUNT];
timeUs_t executeTimeUs;
static timeDelta_t rxStateDurationFracUs[RX_STATE_COUNT];
timeDelta_t executeTimeUs;
rxState_e oldRxState = rxState;
timeDelta_t anticipatedExecutionTime;
// Where we are using a state machine call schedulerIgnoreTaskExecRate() for all states bar one
if (rxState != RX_STATE_UPDATE) {
@ -230,6 +231,12 @@ static void taskUpdateRxMain(timeUs_t currentTimeUs)
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 (executeTimeUs > (rxStateDurationFracUs[oldRxState] >> RX_TASK_DECAY_SHIFT)) {
rxStateDurationFracUs[oldRxState] = executeTimeUs << RX_TASK_DECAY_SHIFT;
} else {
@ -237,6 +244,10 @@ static void taskUpdateRxMain(timeUs_t currentTimeUs)
rxStateDurationFracUs[oldRxState]--;
}
if (debugMode == DEBUG_RX_STATE_TIME) {
debug[oldRxState] = rxStateDurationFracUs[oldRxState] >> RX_TASK_DECAY_SHIFT;
}
schedulerSetNextStateTime(rxStateDurationFracUs[rxState] >> RX_TASK_DECAY_SHIFT);
}

View file

@ -299,6 +299,13 @@ void changeOsdProfileIndex(uint8_t profileIndex)
void osdAnalyzeActiveElements(void)
{
/* This code results in a total RX task RX_STATE_MODES state time of ~68us on an F411 overclocked to 108MHz
* This upsets the scheduler task duration estimation and will break SPI RX communication. This can
* occur in flight, but only when the OSD profile is changed by switch so can be ignored, only causing
* one late task instance.
*/
schedulerIgnoreTaskExecTime();
osdAddActiveElements();
osdDrawActiveElementsBackground(osdDisplayPort);
}

View file

@ -356,6 +356,11 @@ FAST_CODE void schedulerSetNextStateTime(timeDelta_t nextStateTime)
taskNextStateTime = nextStateTime;
}
FAST_CODE timeDelta_t schedulerGetNextStateTime()
{
return currentTask->anticipatedExecutionTime >> TASK_EXEC_TIME_SHIFT;
}
FAST_CODE timeUs_t schedulerExecuteTask(task_t *selectedTask, timeUs_t currentTimeUs)
{
timeUs_t taskExecutionTimeUs = 0;

View file

@ -230,6 +230,7 @@ void schedulerResetTaskStatistics(taskId_e taskId);
void schedulerResetTaskMaxExecutionTime(taskId_e taskId);
void schedulerResetCheckFunctionMaxExecutionTime(void);
void schedulerSetNextStateTime(timeDelta_t nextStateTime);
timeDelta_t schedulerGetNextStateTime();
void schedulerInit(void);
void scheduler(void);
timeUs_t schedulerExecuteTask(task_t *selectedTask, timeUs_t currentTimeUs);