Pārlūkot izejas kodu

v3.6.1 - SR bug fixes and proper Abort handling

Anatoli Arkhipenko 3 gadi atpakaļ
vecāks
revīzija
7ea57849f4

+ 1 - 1
README.md

@@ -1,6 +1,6 @@
 # Task Scheduler
 ### Cooperative multitasking for Arduino, ESPx, STM32 and other microcontrollers
-#### Version 3.6.0: 2021-12-17 [Latest updates](https://github.com/arkhipenko/TaskScheduler/wiki/Latest-Updates)
+#### Version 3.6.1: 2022-06-28 [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)
 

+ 2 - 0
keywords.txt

@@ -134,6 +134,8 @@ TASK_SCHEDULE_NC	LITERAL1
 TASK_INTERVAL	LITERAL1
 TASK_SR_OK	LITERAL1
 TASK_SR_ERROR	LITERAL1
+TASK_SR_CANCEL	LITERAL1
+TASK_SR_ABORT	LITERAL1
 TASK_SR_TIMEOUT	LITERAL1
 
 #######################################

+ 1 - 1
library.json

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

+ 1 - 1
library.properties

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

+ 15 - 2
src/TaskScheduler.h

@@ -1,6 +1,6 @@
 /*
 Cooperative multitasking library for Arduino
-Copyright (c) 2015-2019 Anatoli Arkhipenko
+Copyright (c) 2015-2022 Anatoli Arkhipenko
 
 Changelog:
 v1.0.0:
@@ -209,6 +209,9 @@ v3.5.0:
 v3.6.0:
    2021-11-01 - feature: _TASK_THREAD_SAFE compile option for multi-core systems or running under RTOS 
 
+v3.6.1:
+   2022-06-28 - bug: Internal Status Request of the canceled and aborted tasks complete with respective error code
+              - feature: TASK_SR_ABORT code causes Tasks waiting on this Status Request to be aborted as well
 
 */
 
@@ -668,7 +671,7 @@ bool Task::enable() {
         iPreviousMillis = _TASK_TIME_FUNCTION() - (iDelay = iInterval);
 
 #ifdef _TASK_TIMEOUT
-            resetTimeout();
+        resetTimeout();
 #endif // _TASK_TIMEOUT
 
         if ( iStatus.enabled ) {
@@ -880,6 +883,9 @@ void Task::abort() {
     iStatus.enabled = false;
     iStatus.inonenable = false;
     iStatus.canceled = true;
+#ifdef _TASK_STATUS_REQUEST
+    iMyStatusRequest.signalComplete(TASK_SR_ABORT);
+#endif
 }
 
 
@@ -888,6 +894,9 @@ void Task::abort() {
  */
 void Task::cancel() {
     iStatus.canceled = true;
+#ifdef _TASK_STATUS_REQUEST
+    iMyStatusRequest.signalComplete(TASK_SR_ABORT);
+#endif
     disable();
 }
 
@@ -1308,6 +1317,10 @@ bool Scheduler::execute() {
                     }
 #endif // _TASK_TIMEOUT
                     if ( (iCurrent->iStatusRequest)->pending() ) break;
+                    if ( (iCurrent->iStatusRequest)->iStatus == TASK_SR_ABORT ) {
+                      iCurrent->abort();
+                      break;
+                    }
                     if (iCurrent->iStatus.waiting == _TASK_SR_NODELAY) {
                         iCurrent->iPreviousMillis = m - (iCurrent->iDelay = i);
                     }

+ 5 - 3
src/TaskSchedulerDeclarations.h

@@ -1,5 +1,5 @@
 // Cooperative multitasking library for Arduino
-// Copyright (c) 2015-2019 Anatoli Arkhipenko
+// Copyright (c) 2015-2022 Anatoli Arkhipenko
 
 #include <stddef.h>
 #include <stdint.h>
@@ -85,7 +85,9 @@ class Scheduler;
 
 #define TASK_SR_OK          0
 #define TASK_SR_ERROR       (-1)
-#define TASK_SR_TIMEOUT     (-99)
+#define TASK_SR_CANCEL      (-32766)
+#define TASK_SR_ABORT       (-32767)
+#define TASK_SR_TIMEOUT     (-32768)
  
 #define _TASK_SR_NODELAY    1
 #define _TASK_SR_DELAY      2
@@ -113,7 +115,7 @@ class StatusRequest {
 
   _TASK_SCOPE:
     unsigned int  iCount;          // number of statuses to wait for. waiting for more that 65000 events seems unreasonable: unsigned int should be sufficient
-    int           iStatus;         // status of the last completed request. negative = error;  zero = OK; positive = OK with a specific status
+    int           iStatus;         // status of the last completed request. negative = error;  zero = OK; positive = OK with a specific status (see TASK_SR_ constants)
 
 #ifdef _TASK_TIMEOUT
     unsigned long            iTimeout;               // Task overall timeout

+ 73 - 1
src/TaskSchedulerSleepMethods.h

@@ -1,5 +1,5 @@
 // Cooperative multitasking library for Arduino
-// Copyright (c) 2015-2019 Anatoli Arkhipenko
+// Copyright (c) 2015-2022 Anatoli Arkhipenko
 
 #ifndef _TASKSCHEDULERSLEEPMETHODS_H_
 #define _TASKSCHEDULERSLEEPMETHODS_H_
@@ -21,6 +21,78 @@ void SleepMethod( unsigned long aDuration ) {
 }
 // ARDUINO_ARCH_AVR
 
+
+#elif defined( CORE_TEENSY )
+void SleepMethod( unsigned long aDuration ) {
+  asm("wfi");
+}
+//CORE_TEENSY
+
+
+#elif defined( ARDUINO_ARCH_ESP8266 )
+
+#ifndef _TASK_ESP8266_DLY_THRESHOLD
+#define _TASK_ESP8266_DLY_THRESHOLD 200L
+#endif
+extern "C" {
+#include "user_interface.h"
+}
+
+void SleepMethod( unsigned long aDuration ) {
+// to do: find suitable sleep function for esp8266
+      if ( aDuration < _TASK_ESP8266_DLY_THRESHOLD) delay(1);   // ESP8266 implementation of delay() uses timers and yield
+}
+// ARDUINO_ARCH_ESP8266
+
+
+#elif defined( ARDUINO_ARCH_ESP32 )
+
+#include <esp_sleep.h>
+
+#ifndef _TASK_ESP32_DLY_THRESHOLD
+#define _TASK_ESP32_DLY_THRESHOLD 200L
+#endif
+extern unsigned long tStart, tFinish;
+const unsigned long tRem = 1000-_TASK_ESP32_DLY_THRESHOLD;
+
+void SleepMethod( unsigned long aDuration ) {
+    if ( aDuration < tRem ) {
+        esp_sleep_enable_timer_wakeup((uint64_t) (1000 - aDuration));
+        esp_light_sleep_start();
+    }
+}
+// ARDUINO_ARCH_ESP32
+
+
+#elif defined( ARDUINO_ARCH_STM32F1 )
+
+#include <libmaple/pwr.h>
+#include <libmaple/scb.h>
+
+void SleepMethod( unsigned long aDuration ) {
+	  // Now go into stop mode, wake up on interrupt.
+	  // Systick interrupt will run every 1 milliseconds.
+	  asm("    wfi");
+}
+// ARDUINO_ARCH_STM32
+
+
+#elif defined( ENERGIA_ARCH_MSP432 )
+
+void SleepMethod( unsigned long aDuration ) {
+    delay(1);
+}
+// ENERGIA_ARCH_MSP432
+
+
+#elif defined( ENERGIA_ARCH_MSP430 )
+
+void SleepMethod( unsigned long aDuration ) {
+    sleep(1);
+}
+// ENERGIA_ARCH_MSP430
+
+
 #else
 void SleepMethod( unsigned long aDuration ) {
 }