Skip to content

Commit 0959bec

Browse files
committed
Merge branch 'testing'
2 parents 31c3889 + 5cd3227 commit 0959bec

File tree

6 files changed

+69
-13
lines changed

6 files changed

+69
-13
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Task Scheduler
22
### Cooperative multitasking for Arduino, ESPx, STM32 and other microcontrollers
3-
#### Version 3.2.2: 2020-12-14 [Latest updates](https://github.com/arkhipenko/TaskScheduler/wiki/Latest-Updates)
3+
#### Version 3.3.0: 2021-05-12 [Latest updates](https://github.com/arkhipenko/TaskScheduler/wiki/Latest-Updates)
44

55
[![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)
66

@@ -28,7 +28,7 @@ _“Everybody who learns concurrency and thinks they understand it, ends up find
2828
7. Support for task IDs and Control Points for error handling and watchdog timer
2929
8. Support for Local Task Storage pointer (allowing use of same callback code for multiple tasks)
3030
9. Support for layered task prioritization
31-
10. Support for `std::functions` (tested on `ESPx` only)
31+
10. Support for `std::functions` (tested on `ESPx` and `STM32` only)
3232
11. Overall task timeout
3333
12. Static and dynamic callback method binding
3434
13. CPU load / idle statistics for time critical applications
@@ -46,6 +46,7 @@ Scheduling overhead: between `15` and `18` microseconds per scheduling pass (Ard
4646
* Teensy (tested on Teensy 3.5)
4747
* STM32F1 (tested on Mini USB STM32F103RCBT6 ARM Cortex-M3 leaflabs Leaf maple mini module F)
4848
* MSP430 and MSP432 boards
49+
* Raspberry Pi (requires external `Arduino.h` and `millis()` implementation)
4950

5051

5152

keywords.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ TaskOnEnable LITERAL1
126126
TASK_SCHEDULE LITERAL1
127127
TASK_SCHEDULE_NC LITERAL1
128128
TASK_INTERVAL LITERAL1
129+
TASK_SR_OK LITERAL1
130+
TASK_SR_ERROR LITERAL1
131+
TASK_SR_TIMEOUT LITERAL1
129132

130133
#######################################
131134

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"maintainer": true
1717
}
1818
],
19-
"version": "3.2.2",
19+
"version": "3.3.0",
2020
"frameworks": "arduino",
2121
"platforms": "*"
2222
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=TaskScheduler
2-
version=3.2.2
2+
version=3.3.0
33
author=Anatoli Arkhipenko <arkhipenko@hotmail.com>
44
maintainer=Anatoli Arkhipenko <arkhipenko@hotmail.com>
55
sentence=Cooperative multitasking for Arduino, ESPx, STM32 and other microcontrollers.

src/TaskScheduler.h

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,14 @@
189189
// processing in the onDisable method.
190190
// feature: Task.cancelled() method - indicates that task was disabled with a cancel() method.
191191
//
192+
// v3.2.3:
193+
// 2021-01-01 - feature: discontinued use of 'register' keyword. Depricated in C++ 11
194+
// feature: add STM32 as a platform supporting _TASK_STD_FUNCTION. (PR #105)
195+
//
196+
// v3.3.0:
197+
// 2021-05-11 - feature: Timeout() methods for StatusRequest objects
198+
199+
192200

193201
#include <Arduino.h>
194202

@@ -244,7 +252,7 @@ extern "C" {
244252
#endif // _TASK_SLEEP_ON_IDLE_RUN
245253

246254

247-
#if !defined (ARDUINO_ARCH_ESP8266) && !defined (ARDUINO_ARCH_ESP32)
255+
#if !defined (ARDUINO_ARCH_ESP8266) && !defined (ARDUINO_ARCH_ESP32) && !defined (ARDUINO_ARCH_STM32)
248256
#ifdef _TASK_STD_FUNCTION
249257
#error Support for std::function only for ESP8266 or ESP32 architecture
250258
#undef _TASK_STD_FUNCTION
@@ -327,7 +335,14 @@ StatusRequest::StatusRequest()
327335
iStatus = 0;
328336
}
329337

330-
void StatusRequest::setWaiting(unsigned int aCount) { iCount = aCount; iStatus = 0; }
338+
void StatusRequest::setWaiting(unsigned int aCount) {
339+
iCount = aCount;
340+
iStatus = 0;
341+
#ifdef _TASK_TIMEOUT
342+
iStarttime = _TASK_TIME_FUNCTION();
343+
#endif // #ifdef _TASK_TIMEOUT
344+
}
345+
331346
bool StatusRequest::pending() { return (iCount != 0); }
332347
bool StatusRequest::completed() { return (iCount == 0); }
333348
int StatusRequest::getStatus() { return iStatus; }
@@ -380,6 +395,19 @@ bool Task::waitForDelayed(StatusRequest* aStatusRequest, unsigned long aInterval
380395
}
381396
return false;
382397
}
398+
399+
#ifdef _TASK_TIMEOUT
400+
void StatusRequest::resetTimeout() {
401+
iStarttime = _TASK_TIME_FUNCTION();
402+
}
403+
404+
long StatusRequest::untilTimeout() {
405+
if ( iTimeout ) {
406+
return ( (long) (iStarttime + iTimeout) - (long) _TASK_TIME_FUNCTION() );
407+
}
408+
return -1;
409+
}
410+
#endif // _TASK_TIMEOUT
383411
#endif // _TASK_STATUS_REQUEST
384412

385413
bool Task::isEnabled() { return iStatus.enabled; }
@@ -667,6 +695,7 @@ bool Task::disable() {
667695
void Task::abort() {
668696
iStatus.enabled = false;
669697
iStatus.inonenable = false;
698+
iStatus.canceled = true;
670699
}
671700

672701

@@ -978,16 +1007,16 @@ void Scheduler::setSleepMethod( SleepCallback aCallback ) {
9781007

9791008
bool Scheduler::execute() {
9801009
bool idleRun = true;
981-
register unsigned long m, i; // millis, interval;
1010+
unsigned long m, i; // millis, interval;
9821011

9831012
#ifdef _TASK_SLEEP_ON_IDLE_RUN
9841013
unsigned long tFinish;
9851014
unsigned long tStart = micros();
9861015
#endif // _TASK_SLEEP_ON_IDLE_RUN
9871016

9881017
#ifdef _TASK_TIMECRITICAL
989-
register unsigned long tPassStart;
990-
register unsigned long tTaskStart, tTaskFinish;
1018+
unsigned long tPassStart;
1019+
unsigned long tTaskStart, tTaskFinish;
9911020

9921021
#ifdef _TASK_SLEEP_ON_IDLE_RUN
9931022
unsigned long tIdleStart = 0;
@@ -1048,6 +1077,12 @@ bool Scheduler::execute() {
10481077
// Otherwise, continue with execution as usual. Tasks waiting to StatusRequest need to be rescheduled according to
10491078
// how they were placed into waiting state (waitFor or waitForDelayed)
10501079
if ( iCurrent->iStatus.waiting ) {
1080+
#ifdef _TASK_TIMEOUT
1081+
StatusRequest *sr = iCurrent->iStatusRequest;
1082+
if ( sr->iTimeout && (m - sr->iStarttime > sr->iTimeout) ) {
1083+
sr->signalComplete(TASK_SR_TIMEOUT);
1084+
}
1085+
#endif // _TASK_TIMEOUT
10511086
if ( (iCurrent->iStatusRequest)->pending() ) break;
10521087
if (iCurrent->iStatus.waiting == _TASK_SR_NODELAY) {
10531088
iCurrent->iPreviousMillis = m - (iCurrent->iDelay = i);
@@ -1074,7 +1109,7 @@ bool Scheduler::execute() {
10741109
{
10751110
long ov = (long) ( iCurrent->iPreviousMillis + i - m );
10761111
if ( ov < 0 ) {
1077-
long ii = i == 0 ? 1 : i;
1112+
long ii = i ? i : 1;
10781113
iCurrent->iPreviousMillis += ((m - iCurrent->iPreviousMillis) / ii) * ii;
10791114
}
10801115
}

src/TaskSchedulerDeclarations.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,17 @@ class Scheduler;
7777

7878
#ifdef _TASK_STATUS_REQUEST
7979

80+
#define TASK_SR_OK 0
81+
#define TASK_SR_ERROR (-1)
82+
#define TASK_SR_TIMEOUT (-99)
83+
8084
#define _TASK_SR_NODELAY 1
8185
#define _TASK_SR_DELAY 2
8286

87+
class Scheduler;
88+
8389
class StatusRequest {
90+
friend class Scheduler;
8491
public:
8592
INLINE StatusRequest();
8693
INLINE void setWaiting(unsigned int aCount = 1);
@@ -90,10 +97,22 @@ class StatusRequest {
9097
INLINE bool completed();
9198
INLINE int getStatus();
9299
INLINE int getCount();
100+
101+
#ifdef _TASK_TIMEOUT
102+
INLINE void setTimeout(unsigned long aTimeout) { iTimeout = aTimeout; };
103+
INLINE unsigned long getTimeout() { return iTimeout; };
104+
INLINE void resetTimeout();
105+
INLINE long untilTimeout();
106+
#endif
93107

94108
_TASK_SCOPE:
95109
unsigned int iCount; // number of statuses to wait for. waiting for more that 65000 events seems unreasonable: unsigned int should be sufficient
96110
int iStatus; // status of the last completed request. negative = error; zero = OK; positive = OK with a specific status
111+
112+
#ifdef _TASK_TIMEOUT
113+
unsigned long iTimeout; // Task overall timeout
114+
unsigned long iStarttime; // millis at task start time
115+
#endif // _TASK_TIMEOUT
97116
};
98117
#endif // _TASK_STATUS_REQUEST
99118

@@ -125,13 +144,11 @@ typedef struct {
125144
#endif
126145

127146
#ifdef _TASK_TIMEOUT
128-
bool timeout : 1; // indication if task is waiting on the status request
147+
bool timeout : 1; // indication if task timed out
129148
#endif
130149

131150
} __task_status;
132151

133-
class Scheduler;
134-
135152

136153
class Task {
137154
friend class Scheduler;

0 commit comments

Comments
 (0)