ソースを参照

Merge branch 'testing'

Anatoli Arkhipenko 4 年 前
コミット
bf48b5afc1
6 ファイル変更42 行追加11 行削除
  1. 6 4
      README.md
  2. 2 0
      keywords.txt
  3. 1 1
      library.json
  4. 1 1
      library.properties
  5. 21 4
      src/TaskScheduler.h
  6. 11 1
      src/TaskSchedulerDeclarations.h

+ 6 - 4
README.md

@@ -1,6 +1,6 @@
 # Task Scheduler
 ### Cooperative multitasking for Arduino, ESPx, STM32 and other microcontrollers
-#### Version 3.3.0: 2021-05-12 [Latest updates](https://github.com/arkhipenko/TaskScheduler/wiki/Latest-Updates)
+#### Version 3.4.0: 2021-07-14 [Latest updates](https://github.com/arkhipenko/TaskScheduler/wiki/Latest-Updates)
 
 [![arduino-library-badge](https://www.ardu-badge.com/badge/TaskScheduler.svg?)](https://www.ardu-badge.com/TaskScheduler)[![xscode](https://img.shields.io/badge/Available%20on-xs%3Acode-blue?style=?style=plastic&logo=appveyor&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAZQTFRF////////VXz1bAAAAAJ0Uk5T/wDltzBKAAAAlUlEQVR42uzXSwqAMAwE0Mn9L+3Ggtgkk35QwcnSJo9S+yGwM9DCooCbgn4YrJ4CIPUcQF7/XSBbx2TEz4sAZ2q1RAECBAiYBlCtvwN+KiYAlG7UDGj59MViT9hOwEqAhYCtAsUZvL6I6W8c2wcbd+LIWSCHSTeSAAECngN4xxIDSK9f4B9t377Wd7H5Nt7/Xz8eAgwAvesLRjYYPuUAAAAASUVORK5CYII=)](https://xscode.com/arkhipenko/TaskScheduler)
 
@@ -32,7 +32,8 @@ _“Everybody who learns concurrency and thinks they understand it, ends up find
 11. Overall task timeout
 12. Static and dynamic callback method binding
 13. CPU load / idle statistics for time critical applications
-14. Scheduling options with priotity for original schedule (with and without catchup) and interval
+14. Scheduling options with priority for original schedule (with and without catchup) and interval
+15. Ability to pause/resume and enable/disable scheduling
 
 Scheduling overhead: between `15` and `18` microseconds per scheduling pass (Arduino UNO rev 3 @ `16MHz` clock, single scheduler w/o prioritization)
 
@@ -44,7 +45,8 @@ Scheduling overhead: between `15` and `18` microseconds per scheduling pass (Ard
 * ESP8266 (Node MCU v2.0)
 * ESP32
 * Teensy (tested on Teensy 3.5)
-* STM32F1 (tested on Mini USB STM32F103RCBT6 ARM Cortex-M3 leaflabs Leaf maple mini module F)
+* nRF52 (tested on nRF52832)
+* STM32 (tested on Mini USB STM32F103RCBT6 ARM Cortex-M3 leaflabs Leaf maple mini module F)
 * MSP430 and MSP432 boards
 * Raspberry Pi (requires external `Arduino.h` and `millis()` implementation)
 
@@ -100,7 +102,7 @@ Scheduling overhead: between `15` and `18` microseconds per scheduling pass (Ard
   
     >by chaffneue:
     >>My first arduino project. It's a multi-master midi controller with a shared clock and
- auto count in behaviour.
+	 auto count in behaviour.
 	
 	 youtube: https://www.youtube.com/watch?v=QRof550TtXo
 

+ 2 - 0
keywords.txt

@@ -64,10 +64,12 @@ isLastIteration	KEYWORD2
 isOverrun	KEYWORD2
 OnDisable	KEYWORD2
 OnEnable	KEYWORD2
+pause	KEYWORD2
 pending	KEYWORD2
 resetTimeout	KEYWORD2
 restart	KEYWORD2
 restartDelayed	KEYWORD2
+resume	KEYWORD2
 set	KEYWORD2
 setCallback	KEYWORD2
 setControlPoint	KEYWORD2

+ 1 - 1
library.json

@@ -16,7 +16,7 @@
       "maintainer": true
     }
   ],
-  "version": "3.3.0",
+  "version": "3.4.0",
   "frameworks": "arduino",
   "platforms": "*"
 }

+ 1 - 1
library.properties

@@ -1,5 +1,5 @@
 name=TaskScheduler
-version=3.3.0
+version=3.4.0
 author=Anatoli Arkhipenko <arkhipenko@hotmail.com>
 maintainer=Anatoli Arkhipenko <arkhipenko@hotmail.com>
 sentence=Cooperative multitasking for Arduino, ESPx, STM32 and other microcontrollers.

+ 21 - 4
src/TaskScheduler.h

@@ -195,6 +195,10 @@
 //
 // v3.3.0:
 //    2021-05-11 - feature: Timeout() methods for StatusRequest objects 
+//
+// v3.4.0:
+//    2021-07-14 - feature: ability to Enable/Disable and Pause/Resume scheduling 
+//               - feature: optional use of external millis/micros methods 
 
 
 
@@ -228,17 +232,18 @@ extern "C" {
 // #define _TASK_INLINE             // Make all methods "inline" - needed to support some multi-tab, multi-file implementations
 // #define _TASK_TIMEOUT            // Support for overall task timeout
 // #define _TASK_OO_CALLBACKS       // Support for callbacks via inheritance
-// #define _TASK_DEFINE_MILLIS      // Force forward declaration of millis() and micros() "C" style
 // #define _TASK_EXPOSE_CHAIN       // Methods to access tasks in the task chain
 // #define _TASK_SCHEDULING_OPTIONS // Support for multiple scheduling options
+// #define _TASK_DEFINE_MILLIS      // Force forward declaration of millis() and micros() "C" style
+// #define _TASK_EXTERNAL_TIME      // Custom millis() and micros() methods
 
  #ifdef _TASK_MICRO_RES
 
  #undef _TASK_SLEEP_ON_IDLE_RUN     // SLEEP_ON_IDLE has only millisecond resolution
- #define _TASK_TIME_FUNCTION() micros()
+ #define _TASK_TIME_FUNCTION() _task_micros()
 
  #else
- #define _TASK_TIME_FUNCTION() millis()
+ #define _TASK_TIME_FUNCTION() _task_millis()
 
  #endif  // _TASK_MICRO_RES
 
@@ -270,6 +275,10 @@ extern "C" {
 
 // ------------------ TaskScheduler implementation --------------------
 
+#ifndef _TASK_EXTERNAL_TIME
+static uint32_t _task_millis() {return millis();}
+static uint32_t _task_micros() {return micros();}
+#endif  //  _TASK_EXTERNAL_TIME
 
 /** Constructor, uses default values for the parameters
  * so could be called with no parameters.
@@ -782,6 +791,9 @@ void Scheduler::init() {
     iLast = NULL;
     iCurrent = NULL;
 
+    iPaused = false;
+    iEnabled = true;  
+
 #ifdef _TASK_PRIORITY
     iHighPriority = NULL;
 #endif  // _TASK_PRIORITY
@@ -1006,6 +1018,7 @@ void  Scheduler::setSleepMethod( SleepCallback aCallback ) {
  */
 
 bool Scheduler::execute() {
+  
     bool     idleRun = true;
     unsigned long m, i;  // millis, interval;
 
@@ -1034,7 +1047,11 @@ bool Scheduler::execute() {
         iCurrentScheduler = this;
 #endif  // _TASK_PRIORITY
 
-    while (iCurrent) {
+    //  each scheduled is enabled/disabled individually, so check iEnabed only
+    //  after the higher priority scheduler has been invoked.
+    if ( !iEnabled ) return true; //  consider this to be an idle run
+
+    while (!iPaused && iCurrent) {
 
 #ifdef _TASK_TIMECRITICAL
         tPassStart = micros();

+ 11 - 1
src/TaskSchedulerDeclarations.h

@@ -23,9 +23,10 @@
 // #define _TASK_INLINE             // Make all methods "inline" - needed to support some multi-tab, multi-file implementations
 // #define _TASK_TIMEOUT            // Support for overall task timeout
 // #define _TASK_OO_CALLBACKS       // Support for callbacks via inheritance
-// #define _TASK_DEFINE_MILLIS      // Force forward declaration of millis() and micros() "C" style
 // #define _TASK_EXPOSE_CHAIN       // Methods to access tasks in the task chain
 // #define _TASK_SCHEDULING_OPTIONS // Support for multiple scheduling options
+// #define _TASK_DEFINE_MILLIS      // Force forward declaration of millis() and micros() "C" style
+// #define _TASK_EXTERNAL_TIME      // Custom millis() and micros() methods
 
 class Scheduler;
 
@@ -57,6 +58,10 @@ class Scheduler;
 #define INLINE
 #endif
 
+#ifdef _TASK_EXTERNAL_TIME
+#define _task_millis()  external_millis()
+#define _task_micros()  external_micros()
+#endif  //  _TASK_EXTERNAL_TIME
 
 #ifndef _TASK_MICRO_RES
 
@@ -314,6 +319,10 @@ class Scheduler {
     INLINE void init();
     INLINE void addTask(Task& aTask);
     INLINE void deleteTask(Task& aTask);
+    INLINE void pause() { iPaused = true; };
+    INLINE void resume() { iPaused = false; };
+    INLINE void enable() { iEnabled = true; };
+    INLINE void disable() { iEnabled = false; };
 #ifdef _TASK_PRIORITY
     INLINE void disableAll(bool aRecursive = true);
     INLINE void enableAll(bool aRecursive = true);
@@ -358,6 +367,7 @@ class Scheduler {
   _TASK_SCOPE:
     Task       *iFirst, *iLast, *iCurrent;        // pointers to first, last and current tasks in the chain
 
+    bool       iPaused, iEnabled;
 #ifdef _TASK_SLEEP_ON_IDLE_RUN
     bool        iAllowSleep;                      // indication if putting MC to IDLE_SLEEP mode is allowed by the program at this time.
 #endif  // _TASK_SLEEP_ON_IDLE_RUN