2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
20 //#define SCHEDULER_DEBUG
23 TASK_PRIORITY_IDLE
= 0, // Disables dynamic scheduling, task is executed only if no other task is active this cycle
24 TASK_PRIORITY_LOW
= 1,
25 TASK_PRIORITY_MEDIUM
= 3,
26 TASK_PRIORITY_HIGH
= 5,
27 TASK_PRIORITY_REALTIME
= 6,
28 TASK_PRIORITY_MAX
= 255
32 const char * taskName
;
34 uint32_t desiredPeriod
;
35 uint8_t staticPriority
;
36 uint32_t maxExecutionTime
;
37 uint32_t totalExecutionTime
;
38 uint32_t averageExecutionTime
;
71 /* Count of real tasks */
74 /* Service task IDs */
75 TASK_NONE
= TASK_COUNT
,
81 const char * taskName
;
82 bool (*checkFunc
)(uint32_t currentDeltaTime
);
83 void (*taskFunc
)(void);
85 uint32_t desiredPeriod
; // target period of execution
86 uint8_t staticPriority
; // dynamicPriority grows in steps of this size, shouldn't be zero
89 uint8_t dynamicPriority
; // measurement of how old task was last executed, used to avoid task starvation
90 uint32_t lastExecutedAt
; // last time of invocation
91 uint32_t lastSignaledAt
; // time of invocation event for event-driven tasks
92 uint16_t taskAgeCycles
;
95 uint32_t averageExecutionTime
; // Moving averate over 6 samples, used to calculate guard interval
96 uint32_t taskLatestDeltaTime
; //
97 #ifndef SKIP_TASK_STATISTICS
98 uint32_t maxExecutionTime
;
99 uint32_t totalExecutionTime
; // total time consumed by task since boot
103 extern cfTask_t cfTasks
[TASK_COUNT
];
104 extern uint16_t cpuLoad
;
105 extern uint16_t averageSystemLoadPercent
;
107 void getTaskInfo(cfTaskId_e taskId
, cfTaskInfo_t
* taskInfo
);
108 void rescheduleTask(cfTaskId_e taskId
, uint32_t newPeriodMicros
);
109 void setTaskEnabled(cfTaskId_e taskId
, bool newEnabledState
);
110 uint32_t getTaskDeltaTime(cfTaskId_e taskId
);
112 void scheduler(void);
114 #define isSystemOverloaded() (averageSystemLoadPercent >= 100)