Jelajahi Sumber

v3.1.1 - more precise CPU load measuring. Ability to define idle sleep threshold for ESP chips

Anatoli Arkhipenko 6 tahun lalu
induk
melakukan
3a9afe73cf

+ 1 - 1
README

@@ -1,5 +1,5 @@
 Task Scheduler – cooperative multitasking for Arduino, ESPx, STM32 and other microcontrollers
-Version 3.1.0 2020-01-07
+Version 3.1.1 2020-01-09
 
 If you find TaskScheduler useful for your Arduino project, please drop me an email: arkhipenko@hotmail.com
 ----------------------------------------------------------------------------------------------------------

+ 1 - 1
README.md

@@ -1,6 +1,6 @@
 # Task Scheduler
 ### Cooperative multitasking for Arduino, ESPx, STM32 and other microcontrollers
-#### Version 3.1.0: 2020-01-07
+#### Version 3.1.1: 2020-01-09
 
 ### OVERVIEW:
 A lightweight implementation of cooperative multitasking (task scheduling) supporting:

+ 6 - 3
examples/Scheduler_example24_CPU_LOAD/Scheduler_example24_CPU_LOAD.ino

@@ -8,6 +8,9 @@
    Compare the results.
 */
 
+#define _TASK_ESP8266_DLY_THRESHOLD 50L
+#define _TASK_ESP32_DLY_THRESHOLD 40L
+
 #define _TASK_SLEEP_ON_IDLE_RUN
 #define _TASK_TIMECRITICAL
 #include <TaskScheduler.h>
@@ -41,16 +44,16 @@ void tOff() {
   Serial.print("Loop counts c1="); Serial.println(c1);
   Serial.print("Task counts c2="); Serial.println(c2);
   Serial.print("Total CPU time="); Serial.print(cpuTot); Serial.println(" micros");
-  Serial.print("Scheduling overhead CPU time="); Serial.print(cpuCyc); Serial.println(" micros");
+  Serial.print("Scheduling Overhead CPU time="); Serial.print(cpuCyc); Serial.println(" micros");
   Serial.print("Idle Sleep CPU time="); Serial.print(cpuIdl); Serial.println(" micros");
-  Serial.print("CPU Callback time="); Serial.print(cpuTot - cpuIdl - cpuCyc); Serial.println(" micros");
+  Serial.print("Productive work CPU time="); Serial.print(cpuTot - cpuIdl - cpuCyc); Serial.println(" micros");
   Serial.println();
 
   float idle = (float)cpuIdl / (float)cpuTot * 100;
   Serial.print("CPU Idle Sleep "); Serial.print(idle); Serial.println(" % of time.");
 
   float prod = (float)(cpuIdl + cpuCyc) / (float)cpuTot * 100;
-  Serial.print("CPU Callback processing "); Serial.print(100.00 - prod); Serial.println(" % of time.");
+  Serial.print("Productive work (not idle, not scheduling)"); Serial.print(100.00 - prod); Serial.println(" % of time.");
 
 }
 

+ 1 - 1
library.json

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

+ 1 - 1
library.properties

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

+ 23 - 17
src/TaskScheduler.h

@@ -153,6 +153,9 @@
 //
 // v3.1.0:
 //    2020-01-07 - feature: added 4 cpu load monitoring methods for _TASK_TIMECRITICAL compilation option
+//
+// v3.1.1.:
+//    2020-01-09 - update: more precise CPU load measuring. Ability to define idle sleep threshold for ESP chips
 
 
 #include <Arduino.h>
@@ -892,15 +895,15 @@ bool Scheduler::execute() {
 	unsigned long tStart, tFinish;
 
 #ifdef _TASK_TIMECRITICAL
-	unsigned long tPassStart;
-	unsigned long tTaskStart, tTaskFinish;
-	unsigned long tIdleStart;
+	register unsigned long tPassStart;
+	register unsigned long tTaskStart, tTaskFinish;
+	unsigned long tIdleStart = 0;
 #endif  // _TASK_TIMECRITICAL
 
 	Task *nextTask;  // support for deleting the task in the onDisable method
     iCurrent = iFirst;
 
-	tStart = micros();  // Scheduling pass start time in microseconds. 
+	tStart = micros();  // Scheduling full pass start time in microseconds. 
 
 #ifdef _TASK_PRIORITY
     // If lower priority scheduler does not have a single task in the chain
@@ -912,8 +915,8 @@ bool Scheduler::execute() {
     while (iCurrent) {
 
 #ifdef _TASK_TIMECRITICAL
-		tTaskStart = tTaskFinish = tIdleStart = 0;
 		tPassStart = micros();
+		tTaskStart = tTaskFinish = 0; 
 #endif  // _TASK_TIMECRITICAL
 
 #ifdef _TASK_PRIORITY
@@ -998,39 +1001,42 @@ bool Scheduler::execute() {
 
             }
         } while (0);    //guaranteed single run - allows use of "break" to exit
+
+        iCurrent = nextTask;
+		
 		
 #ifdef _TASK_TIMECRITICAL
 		iCPUCycle += ( (micros() - tPassStart) - (tTaskFinish - tTaskStart) );
 #endif  // _TASK_TIMECRITICAL
-
-        iCurrent = nextTask;
-		
 		
 #if defined (ARDUINO_ARCH_ESP8266) || defined (ARDUINO_ARCH_ESP32)
         yield();
 #endif  // ARDUINO_ARCH_ESPxx
-		
     }
 
     tFinish = micros(); // Scheduling pass end time in microseconds.
-	
-#ifdef _TASK_SLEEP_ON_IDLE_RUN
 
-#ifdef _TASK_TIMECRITICAL
-	tIdleStart = micros();
-#endif  // _TASK_TIMECRITICAL
+
+#ifdef _TASK_SLEEP_ON_IDLE_RUN
 
     if (idleRun && iAllowSleep) {
 		if ( iSleepScheduler == this ) { // only one scheduler should make the MC go to sleep. 
 			if ( iSleepMethod != NULL ) {
+				
+#ifdef _TASK_TIMECRITICAL
+				tIdleStart = micros();
+#endif  // _TASK_TIMECRITICAL
+
 				(*iSleepMethod)( tFinish-tStart );
+				
+#ifdef _TASK_TIMECRITICAL
+				iCPUIdle += (micros() - tIdleStart);
+#endif  // _TASK_TIMECRITICAL
 			}
 		}
     }
 	
-#ifdef _TASK_TIMECRITICAL
-	iCPUIdle += (micros() - tIdleStart);
-#endif  // _TASK_TIMECRITICAL
+
 
 #endif  // _TASK_SLEEP_ON_IDLE_RUN
 

+ 4 - 0
src/TaskSchedulerSleepMethods.h

@@ -31,7 +31,9 @@ void SleepMethod( unsigned long aDuration ) {
 
 #elif defined( ARDUINO_ARCH_ESP8266 )
 
+#ifndef _TASK_ESP8266_DLY_THRESHOLD
 #define _TASK_ESP8266_DLY_THRESHOLD 200L
+#endif
 extern "C" {
 #include "user_interface.h"
 }
@@ -45,7 +47,9 @@ void SleepMethod( unsigned long aDuration ) {
 
 #elif defined( ARDUINO_ARCH_ESP32 )
 
+#ifndef _TASK_ESP32_DLY_THRESHOLD
 #define _TASK_ESP32_DLY_THRESHOLD 200L
+#endif
 #warning _TASK_SLEEP_ON_IDLE_RUN for ESP32 cannot use light sleep mode but a standard delay for 1 ms
 extern unsigned long tStart, tFinish;