diff options
| author | Anatoli Arkhipenko <arkhipenko@hotmail.com> | 2016-02-01 22:26:23 -0500 |
|---|---|---|
| committer | Anatoli Arkhipenko <arkhipenko@hotmail.com> | 2016-02-01 22:26:23 -0500 |
| commit | 73e5c9a810cf1210e3c1a849b9162a71400f48c3 (patch) | |
| tree | ce45edbf8e798b49b8fc729e503f70a2e48aa3a0 | |
| parent | 7dc7c04ac7feb1790a0199fc47873be44aeda25a (diff) | |
v2.1.0 - support for microsecond resolution
* bug fix: time constants wrapped inside compile option
* support for ESP8266 wifi power saving mode for _TASK_SLEEP_ON_IDLE_RUN compile option
* support for microsecond resolution
| -rw-r--r-- | README | 7 | ||||
| -rw-r--r-- | keywords.txt | 1 | ||||
| -rw-r--r-- | src/TaskScheduler.h | 45 |
3 files changed, 41 insertions, 12 deletions
@@ -1,5 +1,5 @@ Task Scheduler – cooperative multitasking for Arduino microcontrollers -Version 2.0.1: 2016-01-02 +Version 2.1.0: 2016-02-01 OVERVIEW: A lightweight implementation of cooperative multitasking (task scheduling) supporting: @@ -19,7 +19,10 @@ For detailed functionality overview please refer to TaskScheduler documentation ======================================================================================================= Changelog: -V2.0.1: +v2.1.0: + 2016-02-01 - support for microsecond resolution + +v2.0.1: 2016-01-02 - bug fix: issue#11 Xtensa compiler (esp8266): Declaration of constructor does not match implementation v2.0.0: diff --git a/keywords.txt b/keywords.txt index aa73279..8e81a2b 100644 --- a/keywords.txt +++ b/keywords.txt @@ -78,5 +78,6 @@ _TASK_STATUS_REQUEST LITERAL1 _TASK_WDT_IDS LITERAL1 _TASK_LTS_POINTER LITERAL1 _TASK_PRIORITY LITERAL1 +_TASK_MICRO_RES LITERAL1 ####################################### diff --git a/src/TaskScheduler.h b/src/TaskScheduler.h index 3a616d3..8eea44b 100644 --- a/src/TaskScheduler.h +++ b/src/TaskScheduler.h @@ -83,7 +83,9 @@ // v2.0.2: // 2016-01-05 - bug fix: time constants wrapped inside compile option // 2016-01-05 - support for ESP8266 wifi power saving mode for _TASK_SLEEP_ON_IDLE_RUN compile option - +// +// v2.1.0: +// 2016-02-01 - support for microsecond resolution /* ============================================ Cooperative multitasking library code is placed under the MIT license @@ -125,10 +127,22 @@ THE SOFTWARE. * #define _TASK_STATUS_REQUEST // Compile with support for StatusRequest functionality - triggering tasks on status change events in addition to time only * #define _TASK_WDT_IDS // Compile with support for wdt control points and task ids * #define _TASK_LTS_POINTER // Compile with support for local task storage pointer - * #define _TASK_PRIORITY // Support layered scheduling priority + * #define _TASK_PRIORITY // Support for layered scheduling priority + * #define _TASK_MICRO_RES // Support for microsecond resolution */ + #ifdef _TASK_MICRO_RES + + #undef _TASK_SLEEP_ON_IDLE_RUN // SLEEP_ON_IDLE has only millisecond resolution + #define _TASK_TIME_FUNCTION() micros() + + #else + + #define _TASK_TIME_FUNCTION() millis() + + #endif + #ifdef _TASK_SLEEP_ON_IDLE_RUN #ifdef ARDUINO_ARCH_AVR @@ -144,13 +158,24 @@ extern "C" { #endif - #define TASK_IMMEDIATE 0 +#define TASK_FOREVER (-1) +#define TASK_ONCE 1 + + +#ifndef _TASK_MICRO_RES + #define TASK_SECOND 1000L #define TASK_MINUTE 60000L #define TASK_HOUR 3600000L -#define TASK_FOREVER (-1) -#define TASK_ONCE 1 + +#else + +#define TASK_SECOND 1000000L +#define TASK_MINUTE 60000000L +#define TASK_HOUR 3600000000L + +#endif #ifdef _TASK_STATUS_REQUEST @@ -242,7 +267,7 @@ class Task { void reset(); volatile __task_status iStatus; - volatile unsigned long iInterval; // execution interval in milliseconds. 0 - immediate + volatile unsigned long iInterval; // execution interval in milliseconds (or microseconds). 0 - immediate volatile unsigned long iDelay; // actual delay until next execution (usually equal iInterval) volatile unsigned long iPreviousMillis; // previous invocation time (millis). Next invocation = iPreviousMillis + iInterval. Delayed tasks will "catch up" #ifdef _TASK_TIMECRITICAL @@ -456,7 +481,7 @@ void Task::enable() { else { iStatus.enabled = true; } - iPreviousMillis = millis() - (iDelay = iInterval); + iPreviousMillis = _TASK_TIME_FUNCTION() - (iDelay = iInterval); } } @@ -484,7 +509,7 @@ void Task::enableDelayed(unsigned long aDelay) { void Task::delay(unsigned long aDelay) { // if (!aDelay) aDelay = iInterval; iDelay = aDelay ? aDelay : iInterval; - iPreviousMillis = millis(); // - iInterval + aDelay; + iPreviousMillis = _TASK_TIME_FUNCTION(); // - iInterval + aDelay; } /** Schedules next iteration of Task for execution immediately (if enabled) @@ -492,7 +517,7 @@ void Task::delay(unsigned long aDelay) { * Task's original schedule is shifted, and all subsequent iterations will continue from this point in time */ void Task::forceNextIteration() { - iPreviousMillis = millis() - (iDelay = iInterval); + iPreviousMillis = _TASK_TIME_FUNCTION() - (iDelay = iInterval); } /** Sets the execution interval. @@ -710,7 +735,7 @@ bool Scheduler::execute() { iCurrent->disable(); break; } - m = millis(); + m = _TASK_TIME_FUNCTION(); i = iCurrent->iInterval; #ifdef _TASK_STATUS_REQUEST |
