mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-23 08:15:30 +03:00
Fix issues impacting RX_STATE_MODES state duration and add DEBUG_RX_STATE_TIME
This commit is contained in:
parent
8d52a36150
commit
c05ad2ec9b
7 changed files with 31 additions and 2 deletions
|
@ -99,4 +99,5 @@ const char * const debugModeNames[DEBUG_COUNT] = {
|
||||||
"TIMING_ACCURACY",
|
"TIMING_ACCURACY",
|
||||||
"RX_EXPRESSLRS_SPI",
|
"RX_EXPRESSLRS_SPI",
|
||||||
"RX_EXPRESSLRS_PHASELOCK",
|
"RX_EXPRESSLRS_PHASELOCK",
|
||||||
|
"RX_STATE_TIME"
|
||||||
};
|
};
|
||||||
|
|
|
@ -97,6 +97,7 @@ typedef enum {
|
||||||
DEBUG_TIMING_ACCURACY,
|
DEBUG_TIMING_ACCURACY,
|
||||||
DEBUG_RX_EXPRESSLRS_SPI,
|
DEBUG_RX_EXPRESSLRS_SPI,
|
||||||
DEBUG_RX_EXPRESSLRS_PHASELOCK,
|
DEBUG_RX_EXPRESSLRS_PHASELOCK,
|
||||||
|
DEBUG_RX_STATE_TIME,
|
||||||
DEBUG_COUNT
|
DEBUG_COUNT
|
||||||
} debugType_e;
|
} debugType_e;
|
||||||
|
|
||||||
|
|
|
@ -659,6 +659,9 @@ static uint8_t applySelectAdjustment(adjustmentFunction_e adjustmentFunction, ui
|
||||||
|
|
||||||
static void calcActiveAdjustmentRanges(void)
|
static void calcActiveAdjustmentRanges(void)
|
||||||
{
|
{
|
||||||
|
// This initialisation upsets the scheduler task duration estimation
|
||||||
|
schedulerIgnoreTaskExecTime();
|
||||||
|
|
||||||
adjustmentRange_t defaultAdjustmentRange;
|
adjustmentRange_t defaultAdjustmentRange;
|
||||||
memset(&defaultAdjustmentRange, 0, sizeof(defaultAdjustmentRange));
|
memset(&defaultAdjustmentRange, 0, sizeof(defaultAdjustmentRange));
|
||||||
|
|
||||||
|
|
|
@ -182,9 +182,10 @@ bool taskUpdateRxMainInProgress()
|
||||||
|
|
||||||
static void taskUpdateRxMain(timeUs_t currentTimeUs)
|
static void taskUpdateRxMain(timeUs_t currentTimeUs)
|
||||||
{
|
{
|
||||||
static timeUs_t rxStateDurationFracUs[RX_STATE_COUNT];
|
static timeDelta_t rxStateDurationFracUs[RX_STATE_COUNT];
|
||||||
timeUs_t executeTimeUs;
|
timeDelta_t executeTimeUs;
|
||||||
rxState_e oldRxState = rxState;
|
rxState_e oldRxState = rxState;
|
||||||
|
timeDelta_t anticipatedExecutionTime;
|
||||||
|
|
||||||
// Where we are using a state machine call schedulerIgnoreTaskExecRate() for all states bar one
|
// Where we are using a state machine call schedulerIgnoreTaskExecRate() for all states bar one
|
||||||
if (rxState != RX_STATE_UPDATE) {
|
if (rxState != RX_STATE_UPDATE) {
|
||||||
|
@ -230,6 +231,12 @@ static void taskUpdateRxMain(timeUs_t currentTimeUs)
|
||||||
|
|
||||||
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 (executeTimeUs > (rxStateDurationFracUs[oldRxState] >> RX_TASK_DECAY_SHIFT)) {
|
if (executeTimeUs > (rxStateDurationFracUs[oldRxState] >> RX_TASK_DECAY_SHIFT)) {
|
||||||
rxStateDurationFracUs[oldRxState] = executeTimeUs << RX_TASK_DECAY_SHIFT;
|
rxStateDurationFracUs[oldRxState] = executeTimeUs << RX_TASK_DECAY_SHIFT;
|
||||||
} else {
|
} else {
|
||||||
|
@ -237,6 +244,10 @@ static void taskUpdateRxMain(timeUs_t currentTimeUs)
|
||||||
rxStateDurationFracUs[oldRxState]--;
|
rxStateDurationFracUs[oldRxState]--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (debugMode == DEBUG_RX_STATE_TIME) {
|
||||||
|
debug[oldRxState] = rxStateDurationFracUs[oldRxState] >> RX_TASK_DECAY_SHIFT;
|
||||||
|
}
|
||||||
|
|
||||||
schedulerSetNextStateTime(rxStateDurationFracUs[rxState] >> RX_TASK_DECAY_SHIFT);
|
schedulerSetNextStateTime(rxStateDurationFracUs[rxState] >> RX_TASK_DECAY_SHIFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -299,6 +299,13 @@ void changeOsdProfileIndex(uint8_t profileIndex)
|
||||||
|
|
||||||
void osdAnalyzeActiveElements(void)
|
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();
|
osdAddActiveElements();
|
||||||
osdDrawActiveElementsBackground(osdDisplayPort);
|
osdDrawActiveElementsBackground(osdDisplayPort);
|
||||||
}
|
}
|
||||||
|
|
|
@ -356,6 +356,11 @@ FAST_CODE void schedulerSetNextStateTime(timeDelta_t nextStateTime)
|
||||||
taskNextStateTime = 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)
|
FAST_CODE timeUs_t schedulerExecuteTask(task_t *selectedTask, timeUs_t currentTimeUs)
|
||||||
{
|
{
|
||||||
timeUs_t taskExecutionTimeUs = 0;
|
timeUs_t taskExecutionTimeUs = 0;
|
||||||
|
|
|
@ -230,6 +230,7 @@ void schedulerResetTaskStatistics(taskId_e taskId);
|
||||||
void schedulerResetTaskMaxExecutionTime(taskId_e taskId);
|
void schedulerResetTaskMaxExecutionTime(taskId_e taskId);
|
||||||
void schedulerResetCheckFunctionMaxExecutionTime(void);
|
void schedulerResetCheckFunctionMaxExecutionTime(void);
|
||||||
void schedulerSetNextStateTime(timeDelta_t nextStateTime);
|
void schedulerSetNextStateTime(timeDelta_t nextStateTime);
|
||||||
|
timeDelta_t schedulerGetNextStateTime();
|
||||||
void schedulerInit(void);
|
void schedulerInit(void);
|
||||||
void scheduler(void);
|
void scheduler(void);
|
||||||
timeUs_t schedulerExecuteTask(task_t *selectedTask, timeUs_t currentTimeUs);
|
timeUs_t schedulerExecuteTask(task_t *selectedTask, timeUs_t currentTimeUs);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue