Skip to content

Commit 08a0ee9

Browse files
committed
Obsoleted _TASK_ROLLOVER_FIX
Based upon http://arduino.stackexchange.com/a/12588/10648, the extra code for _TASK_ROLLOVER_FIX should not be needed if the math is done slightly different. I updated the code and did some quick tests and it appears correct. Example arkhipenko#6 returns the same values for IDLE, but a few less ms when not compiled with IDLE. Using the setMillis() function in the SO posting, I did some quick tests with Example arkhipenko#2. using setMillis(-3000) sets the millis() value to 3 seconds before rollover. Task arkhipenko#1 gets an extra catch-up hit, but not Task arkhipenko#2. But, it works the same as the original code though when using setMillis(-3000).
1 parent c07b4b5 commit 08a0ee9

File tree

1 file changed

+2
-20
lines changed

1 file changed

+2
-20
lines changed

src/TaskScheduler.h

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -620,27 +620,9 @@ void Scheduler::execute() {
620620
}
621621
#endif
622622
p = iCurrent->iPreviousMillis;
623-
624-
// Determine when current task is supposed to run
625-
// Once every 47 days there is a rollover execution which will occur due to millis and targetMillis rollovers
626-
// That is why there is an option to compile with rollover fix
627-
// Example
628-
// iPreviousMillis = 65000
629-
// iInterval = 600
630-
// millis() = 65500
631-
// targetMillis = 65000 + 600 = (should be 65600) 65 (due to rollover)
632-
// so 65 < 65500. should be 65600 > 65500. - task will be scheduled incorrectly
633-
// since targetMillis (65) < iPreviousMillis (65000), rollover fix kicks in:
634-
// iPreviousMillis(65000) > millis(65500) - iInterval(600) = 64900 - task will not be scheduled
635-
623+
636624
targetMillis = p + i;
637-
#ifdef _TASK_ROLLOVER_FIX
638-
if ( targetMillis < p ) { // targetMillis rolled over!
639-
if ( p > ( m - i) ) break;
640-
}
641-
else
642-
#endif
643-
if ( targetMillis > m ) break;
625+
if ( m - p < i ) break;
644626

645627
#ifdef _TASK_TIMECRITICAL
646628
// Updated_previous+current interval should put us into the future, so iOverrun should be positive or zero.

0 commit comments

Comments
 (0)