1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-15 12:25:20 +03:00

Add expediting of OSD task

This commit is contained in:
Steve Evans 2022-01-14 03:42:10 +00:00
parent e7b61a928f
commit db904b4a75
6 changed files with 27 additions and 0 deletions

View file

@ -93,6 +93,9 @@ static int32_t desiredPeriodCycles;
static uint32_t lastTargetCycles;
static uint8_t skippedRxAttempts = 0;
#ifdef USE_OSD
static uint8_t skippedOSDAttempts = 0;
#endif
#if defined(USE_LATE_TASK_STATISTICS)
static int16_t lateTaskCount = 0;
@ -638,6 +641,11 @@ FAST_CODE void scheduler(void)
if ((currentTask - tasks) == TASK_RX) {
skippedRxAttempts = 0;
}
#ifdef USE_OSD
else if ((currentTask - tasks) == TASK_OSD) {
skippedOSDAttempts = 0;
}
#endif
if ((cyclesOverdue > 0) || (-cyclesOverdue < taskGuardMinCycles)) {
if (taskGuardCycles < taskGuardMaxCycles) {
@ -650,6 +658,9 @@ FAST_CODE void scheduler(void)
taskCount++;
#endif // USE_LATE_TASK_STATISTICS
} else if ((selectedTask->taskAgePeriods > TASK_AGE_EXPEDITE_COUNT) ||
#ifdef USE_OSD
(((selectedTask - tasks) == TASK_OSD) && (++skippedOSDAttempts > TASK_AGE_EXPEDITE_OSD)) ||
#endif
(((selectedTask - tasks) == TASK_RX) && (++skippedRxAttempts > TASK_AGE_EXPEDITE_RX))) {
// If a task has been unable to run, then reduce it's recorded estimated run time to ensure
// it's ultimate scheduling

View file

@ -48,6 +48,7 @@
#define TASK_EXEC_TIME_SHIFT 7
#define TASK_AGE_EXPEDITE_RX 25 // Make RX tasks more schedulable if it's failed to be scheduled this many times
#define TASK_AGE_EXPEDITE_OSD 25 // Make OSD tasks more schedulable if it's failed to be scheduled this many times
#define TASK_AGE_EXPEDITE_COUNT 1 // Make aged tasks more schedulable
#define TASK_AGE_EXPEDITE_SCALE 0.9 // By scaling their expected execution time

View file

@ -278,6 +278,8 @@ scheduler_unittest_SRC := \
$(USER_DIR)/common/crc.c \
$(USER_DIR)/common/streambuf.c
scheduler_unittest_DEFINES := \
USE_OSD=
sensor_gyro_unittest_SRC := \
$(USER_DIR)/sensors/gyro.c \

View file

@ -512,6 +512,7 @@ extern "C" {
bool taskUpdateRxMainInProgress() { return true; }
void schedulerIgnoreTaskStateTime(void) { }
void schedulerIgnoreTaskExecRate(void) { }
bool schedulerGetIgnoreTaskExecTime() { return false; }
void schedulerIgnoreTaskExecTime(void) { }
void schedulerSetNextStateTime(timeDelta_t) {}

View file

@ -1377,5 +1377,6 @@ extern "C" {
void schedulerIgnoreTaskStateTime(void) { }
void schedulerIgnoreTaskExecRate(void) { }
void schedulerIgnoreTaskExecTime(void) { }
bool schedulerGetIgnoreTaskExecTime() { return false; }
void schedulerSetNextStateTime(timeDelta_t) {}
}

View file

@ -37,6 +37,8 @@ const int TEST_UPDATE_RX_CHECK_TIME = 34;
const int TEST_UPDATE_RX_MAIN_TIME = 1;
const int TEST_IMU_UPDATE_TIME = 5;
const int TEST_DISPATCH_TIME = 1;
const int TEST_UPDATE_OSD_CHECK_TIME = 5;
const int TEST_UPDATE_OSD_TIME = 30;
#define TASK_COUNT_UNITTEST (TASK_BATTERY_VOLTAGE + 1)
#define TASK_PERIOD_HZ(hz) (1000000 / (hz))
@ -76,6 +78,8 @@ extern "C" {
void taskUpdateRxMain(timeUs_t) { simulatedTime += TEST_UPDATE_RX_MAIN_TIME; }
void imuUpdateAttitude(timeUs_t) { simulatedTime += TEST_IMU_UPDATE_TIME; }
void dispatchProcess(timeUs_t) { simulatedTime += TEST_DISPATCH_TIME; }
bool osdUpdateCheck(timeUs_t, timeDelta_t) { simulatedTime += TEST_UPDATE_OSD_CHECK_TIME; return false; }
void osdUpdate(timeUs_t) { simulatedTime += TEST_UPDATE_OSD_TIME; }
void resetGyroTaskTestFlags(void) {
taskGyroRan = false;
@ -156,6 +160,13 @@ extern "C" {
.taskFunc = taskUpdateBatteryVoltage,
.desiredPeriodUs = TASK_PERIOD_HZ(50),
.staticPriority = TASK_PRIORITY_MEDIUM,
},
[TASK_OSD] = {
.taskName = "OSD",
.checkFunc = osdUpdateCheck,
.taskFunc = osdUpdate,
.desiredPeriodUs = TASK_PERIOD_HZ(12),
.staticPriority = TASK_PRIORITY_LOW,
}
};