diff --git a/src/main/scheduler/scheduler.c b/src/main/scheduler/scheduler.c index fc18976160..c1540c8cf7 100644 --- a/src/main/scheduler/scheduler.c +++ b/src/main/scheduler/scheduler.c @@ -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 diff --git a/src/main/scheduler/scheduler.h b/src/main/scheduler/scheduler.h index b3678649b3..ee679f6ec5 100644 --- a/src/main/scheduler/scheduler.h +++ b/src/main/scheduler/scheduler.h @@ -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 diff --git a/src/test/Makefile b/src/test/Makefile index a2c105ed99..75c0e79be7 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -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 \ diff --git a/src/test/unit/link_quality_unittest.cc b/src/test/unit/link_quality_unittest.cc index 38399218cd..b564005fc0 100644 --- a/src/test/unit/link_quality_unittest.cc +++ b/src/test/unit/link_quality_unittest.cc @@ -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) {} diff --git a/src/test/unit/osd_unittest.cc b/src/test/unit/osd_unittest.cc index 7439c30efd..8d1664b8af 100644 --- a/src/test/unit/osd_unittest.cc +++ b/src/test/unit/osd_unittest.cc @@ -1377,5 +1377,6 @@ extern "C" { void schedulerIgnoreTaskStateTime(void) { } void schedulerIgnoreTaskExecRate(void) { } void schedulerIgnoreTaskExecTime(void) { } + bool schedulerGetIgnoreTaskExecTime() { return false; } void schedulerSetNextStateTime(timeDelta_t) {} } diff --git a/src/test/unit/scheduler_unittest.cc b/src/test/unit/scheduler_unittest.cc index bc20c0ce48..cbd955e575 100644 --- a/src/test/unit/scheduler_unittest.cc +++ b/src/test/unit/scheduler_unittest.cc @@ -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, } };