From 08a0ee9dc843dafc374e6fcbe9ffb46d8d0ba8f5 Mon Sep 17 00:00:00 2001 From: Jim Foster Date: Sat, 28 Nov 2015 19:00:54 -0700 Subject: 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 #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 #2. using setMillis(-3000) sets the millis() value to 3 seconds before rollover. Task #1 gets an extra catch-up hit, but not Task #2. But, it works the same as the original code though when using setMillis(-3000). --- src/TaskScheduler.h | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/TaskScheduler.h b/src/TaskScheduler.h index 1b8ab18..3b964ee 100644 --- a/src/TaskScheduler.h +++ b/src/TaskScheduler.h @@ -620,27 +620,9 @@ void Scheduler::execute() { } #endif p = iCurrent->iPreviousMillis; - - // Determine when current task is supposed to run - // Once every 47 days there is a rollover execution which will occur due to millis and targetMillis rollovers - // That is why there is an option to compile with rollover fix - // Example - // iPreviousMillis = 65000 - // iInterval = 600 - // millis() = 65500 - // targetMillis = 65000 + 600 = (should be 65600) 65 (due to rollover) - // so 65 < 65500. should be 65600 > 65500. - task will be scheduled incorrectly - // since targetMillis (65) < iPreviousMillis (65000), rollover fix kicks in: - // iPreviousMillis(65000) > millis(65500) - iInterval(600) = 64900 - task will not be scheduled - + targetMillis = p + i; - #ifdef _TASK_ROLLOVER_FIX - if ( targetMillis < p ) { // targetMillis rolled over! - if ( p > ( m - i) ) break; - } - else - #endif - if ( targetMillis > m ) break; + if ( m - p < i ) break; #ifdef _TASK_TIMECRITICAL // Updated_previous+current interval should put us into the future, so iOverrun should be positive or zero. -- cgit v1.2.3