Skip to content

Commit 89c5d60

Browse files
committed
Merge branch 'testing'
2 parents 2470286 + 4ef9a80 commit 89c5d60

File tree

9 files changed

+366
-128
lines changed

9 files changed

+366
-128
lines changed

README.md

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

5-
[![arduino-library-badge](https://www.ardu-badge.com/badge/TaskScheduler.svg?)](https://www.ardu-badge.com/TaskScheduler)
5+
[![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

77
### OVERVIEW:
88
A lightweight implementation of cooperative multitasking (task scheduling) supporting:
@@ -19,6 +19,7 @@ A lightweight implementation of cooperative multitasking (task scheduling) suppo
1919
11. Overall task timeout
2020
12. Static and dynamic callback method binding
2121
13. CPU load / idle statistics for time critical applications
22+
14. Scheduling options with priotity for original schedule (with and without catchup) and interval
2223

2324
Scheduling overhead: between `15` and `18` microseconds per scheduling pass (Arduino UNO rev 3 @ `16MHz` clock, single scheduler w/o prioritization)
2425

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
/*
2+
Example of scheduling options:
3+
4+
t1 - is a default option with priority given to schedule, i.e., scheduler tries
5+
maintain original schedule and performs task "catch up" to ensure the number
6+
of iterations that were supposed to happen do happen.
7+
8+
t2 - is an option with priority given to schedule, but without "catch up"
9+
the scheduler will try to maintain original schedule, but next task invocation
10+
is always scheduled to happen in the future
11+
12+
t3 - is a option with priority given to interval. Task are scheduled always in the
13+
future from the point of their current invocation start using task's interval.
14+
15+
16+
*/
17+
// ==== DEFINES ===================================================================================
18+
19+
// ==== Debug and Test options ==================
20+
#define _DEBUG_
21+
//#define _TEST_
22+
23+
//===== Debugging macros ========================
24+
#ifdef _DEBUG_
25+
#define SerialD Serial
26+
#define _PM(a) SerialD.print(millis()); SerialD.print(": "); SerialD.println(a)
27+
#define _PP(a) SerialD.print(a)
28+
#define _PL(a) SerialD.println(a)
29+
#define _PX(a) SerialD.println(a, HEX)
30+
#else
31+
#define _PM(a)
32+
#define _PP(a)
33+
#define _PL(a)
34+
#define _PX(a)
35+
#endif
36+
37+
38+
39+
40+
// ==== INCLUDES ==================================================================================
41+
42+
// ==== Uncomment desired compile options =================================
43+
// #define _TASK_TIMECRITICAL // Enable monitoring scheduling overruns
44+
// #define _TASK_SLEEP_ON_IDLE_RUN // Enable 1 ms SLEEP_IDLE powerdowns between tasks if no callback methods were invoked during the pass
45+
// #define _TASK_STATUS_REQUEST // Compile with support for StatusRequest functionality - triggering tasks on status change events in addition to time only
46+
// #define _TASK_WDT_IDS // Compile with support for wdt control points and task ids
47+
// #define _TASK_LTS_POINTER // Compile with support for local task storage pointer
48+
// #define _TASK_PRIORITY // Support for layered scheduling priority
49+
// #define _TASK_MICRO_RES // Support for microsecond resolution
50+
// #define _TASK_STD_FUNCTION // Support for std::function (ESP8266 and ESP32 ONLY)
51+
// #define _TASK_DEBUG // Make all methods and variables public for debug purposes
52+
// #define _TASK_INLINE // Make all methods "inline" - needed to support some multi-tab, multi-file implementations
53+
// #define _TASK_TIMEOUT // Support for overall task timeout
54+
// #define _TASK_OO_CALLBACKS // Support for dynamic callback method binding
55+
// #define _TASK_DEFINE_MILLIS // Force forward declaration of millis() and micros() "C" style
56+
// #define _TASK_EXPOSE_CHAIN // Methods to access tasks in the task chain
57+
#define _TASK_SCHEDULING_OPTIONS // Support for multiple scheduling options
58+
#include <TaskScheduler.h>
59+
60+
61+
62+
// ==== GLOBALS ===================================================================================
63+
// ==== Scheduler ==============================
64+
Scheduler ts;
65+
66+
void t1CB();
67+
void t2CB();
68+
void t3CB();
69+
70+
// ==== Scheduling defines (cheat sheet) =====================
71+
/*
72+
TASK_MILLISECOND
73+
TASK_SECOND
74+
TASK_MINUTE
75+
TASK_HOUR
76+
TASK_IMMEDIATE
77+
TASK_FOREVER
78+
TASK_ONCE
79+
TASK_NOTIMEOUT
80+
81+
TASK_SCHEDULE - schedule is a priority, with "catch up" (default)
82+
TASK_SCHEDULE_NC - schedule is a priority, without "catch up"
83+
TASK_INTERVAL - interval is a priority, without "catch up"
84+
*/
85+
86+
// ==== Task definitions ========================
87+
Task t1_schedule (100 * TASK_MILLISECOND, 10, &t1CB, &ts);
88+
Task t2_schedule_nc (100 * TASK_MILLISECOND, 10, &t2CB, &ts);
89+
Task t3_interval (100 * TASK_MILLISECOND, 10, &t3CB, &ts);
90+
91+
92+
93+
// ==== CODE ======================================================================================
94+
95+
/**************************************************************************/
96+
/*!
97+
@brief Standard Arduino SETUP method - initialize sketch
98+
@param none
99+
@returns none
100+
*/
101+
/**************************************************************************/
102+
void setup() {
103+
// put your setup code here, to run once:
104+
#if defined(_DEBUG_) || defined(_TEST_)
105+
Serial.begin(115200);
106+
delay(1000);
107+
_PL("Scheduling Options: setup()");
108+
#endif
109+
110+
t2_schedule_nc.setSchedulingOption(TASK_SCHEDULE_NC);
111+
t3_interval.setSchedulingOption(TASK_INTERVAL);
112+
113+
114+
_PM("t1 start time");
115+
t1_schedule.enable();
116+
delay(10);
117+
118+
_PM("t2 start time");
119+
t2_schedule_nc.enable();
120+
delay(10);
121+
122+
_PM("t3 start time");
123+
t3_interval.enable();
124+
125+
delay(333);
126+
_PM("333 ms delay ended");
127+
}
128+
129+
130+
/**************************************************************************/
131+
/*!
132+
@brief Standard Arduino LOOP method - using with TaskScheduler there
133+
should be nothing here but ts.execute()
134+
@param none
135+
@returns none
136+
*/
137+
/**************************************************************************/
138+
void loop() {
139+
ts.execute();
140+
}
141+
142+
143+
/**************************************************************************/
144+
/*!
145+
@brief Callback method of task1 - explain
146+
@param none
147+
@returns none
148+
*/
149+
/**************************************************************************/
150+
void t1CB() {
151+
_PM("t1CB()");
152+
// task code
153+
delay(10);
154+
}
155+
156+
157+
/**************************************************************************/
158+
/*!
159+
@brief Callback method of task2 - explain
160+
@param none
161+
@returns none
162+
*/
163+
/**************************************************************************/
164+
void t2CB() {
165+
_PM("t2CB()");
166+
// task code
167+
delay(10);
168+
}
169+
170+
/**************************************************************************/
171+
/*!
172+
@brief Callback method of task3 - explain
173+
@param none
174+
@returns none
175+
*/
176+
/**************************************************************************/
177+
void t3CB() {
178+
_PM("t3CB()");
179+
// task code
180+
delay(10);
181+
}

examples/Scheduler_template/Scheduler_template.ino

Lines changed: 94 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,71 @@
1-
// #define _TASK_TIMECRITICAL // Enable monitoring scheduling overruns
2-
// #define _TASK_SLEEP_ON_IDLE_RUN // Enable 1 ms SLEEP_IDLE powerdowns between tasks if no callback methods were invoked during the pass
3-
// #define _TASK_STATUS_REQUEST // Compile with support for StatusRequest functionality - triggering tasks on status change events in addition to time only
4-
// #define _TASK_WDT_IDS // Compile with support for wdt control points and task ids
5-
// #define _TASK_LTS_POINTER // Compile with support for local task storage pointer
6-
// #define _TASK_PRIORITY // Support for layered scheduling priority
7-
// #define _TASK_MICRO_RES // Support for microsecond resolution
8-
// #define _TASK_STD_FUNCTION // Support for std::function (ESP8266 and ESP32 ONLY)
9-
// #define _TASK_DEBUG // Make all methods and variables public for debug purposes
10-
// #define _TASK_INLINE // Make all methods "inline" - needed to support some multi-tab, multi-file implementations
11-
// #define _TASK_TIMEOUT // Support for overall task timeout
12-
// #define _TASK_OO_CALLBACKS // Support for dynamic callback method binding
13-
// #define _TASK_DEFINE_MILLIS // Force forward declaration of millis() and micros() "C" style
14-
// #define _TASK_EXPOSE_CHAIN // Methods to access tasks in the task chain
15-
16-
#include <TaskScheduler.h>
1+
/*
2+
Your code description here
3+
(c) you, 20XX
4+
All rights reserved.
5+
6+
Functionality:
7+
8+
Version log:
9+
10+
20XX-MM-DD:
11+
v1.0.0 - Initial release
12+
13+
*/
14+
// ==== DEFINES ===================================================================================
1715

18-
// Debug and Test options
16+
// ==== Debug and Test options ==================
1917
#define _DEBUG_
2018
//#define _TEST_
2119

20+
//===== Debugging macros ========================
2221
#ifdef _DEBUG_
23-
#define _PP(a) Serial.print(a);
24-
#define _PL(a) Serial.println(a);
22+
#define SerialD Serial
23+
#define _PM(a) SerialD.print(millis()); SerialD.print(": "); SerialD.println(a)
24+
#define _PP(a) SerialD.print(a)
25+
#define _PL(a) SerialD.println(a)
26+
#define _PX(a) SerialD.println(a, HEX)
2527
#else
28+
#define _PM(a)
2629
#define _PP(a)
2730
#define _PL(a)
31+
#define _PX(a)
2832
#endif
2933

3034

31-
// Scheduler
35+
36+
37+
// ==== INCLUDES ==================================================================================
38+
39+
// ==== Uncomment desired compile options =================================
40+
// #define _TASK_SLEEP_ON_IDLE_RUN // Enable 1 ms SLEEP_IDLE powerdowns between tasks if no callback methods were invoked during the pass
41+
// #define _TASK_TIMECRITICAL // Enable monitoring scheduling overruns
42+
// #define _TASK_STATUS_REQUEST // Compile with support for StatusRequest functionality - triggering tasks on status change events in addition to time only
43+
// #define _TASK_WDT_IDS // Compile with support for wdt control points and task ids
44+
// #define _TASK_LTS_POINTER // Compile with support for local task storage pointer
45+
// #define _TASK_PRIORITY // Support for layered scheduling priority
46+
// #define _TASK_MICRO_RES // Support for microsecond resolution
47+
// #define _TASK_STD_FUNCTION // Support for std::function (ESP8266 and ESP32 ONLY)
48+
// #define _TASK_DEBUG // Make all methods and variables public for debug purposes
49+
// #define _TASK_INLINE // Make all methods "inline" - needed to support some multi-tab, multi-file implementations
50+
// #define _TASK_TIMEOUT // Support for overall task timeout
51+
// #define _TASK_OO_CALLBACKS // Support for dynamic callback method binding
52+
// #define _TASK_DEFINE_MILLIS // Force forward declaration of millis() and micros() "C" style
53+
// #define _TASK_EXPOSE_CHAIN // Methods to access tasks in the task chain
54+
// #define _TASK_SCHEDULING_OPTIONS // Support for multiple scheduling options
55+
56+
#include <TaskScheduler.h>
57+
58+
59+
60+
// ==== GLOBALS ===================================================================================
61+
// ==== Scheduler ==============================
3262
Scheduler ts;
3363

3464
void task1Callback();
3565
void task2Callback();
3666

67+
// ==== Scheduling defines (cheat sheet) =====================
3768
/*
38-
Scheduling defines:
3969
TASK_MILLISECOND
4070
TASK_SECOND
4171
TASK_MINUTE
@@ -44,12 +74,27 @@ void task2Callback();
4474
TASK_FOREVER
4575
TASK_ONCE
4676
TASK_NOTIMEOUT
77+
78+
TASK_SCHEDULE - schedule is a priority, with "catch up" (default)
79+
TASK_SCHEDULE_NC - schedule is a priority, without "catch up"
80+
TASK_INTERVAL - interval is a priority, without "catch up"
4781
*/
4882

83+
// ==== Task definitions ========================
4984
Task t1 (100 * TASK_MILLISECOND, TASK_FOREVER, &task1Callback, &ts, true);
5085
Task t2 (TASK_IMMEDIATE, 100, &task2Callback, &ts, true);
5186

5287

88+
89+
// ==== CODE ======================================================================================
90+
91+
/**************************************************************************/
92+
/*!
93+
@brief Standard Arduino SETUP method - initialize sketch
94+
@param none
95+
@returns none
96+
*/
97+
/**************************************************************************/
5398
void setup() {
5499
// put your setup code here, to run once:
55100
#if defined(_DEBUG_) || defined(_TEST_)
@@ -59,21 +104,43 @@ void setup() {
59104
#endif
60105
}
61106

107+
108+
/**************************************************************************/
109+
/*!
110+
@brief Standard Arduino LOOP method - using with TaskScheduler there
111+
should be nothing here but ts.execute()
112+
@param none
113+
@returns none
114+
*/
115+
/**************************************************************************/
62116
void loop() {
63117
ts.execute();
64118
}
65119

66120

121+
/**************************************************************************/
122+
/*!
123+
@brief Callback method of task1 - explain
124+
@param none
125+
@returns none
126+
*/
127+
/**************************************************************************/
67128
void task1Callback() {
68-
_PP(millis());
69-
_PL(": task1Callback()");
70-
129+
_PM("task1Callback()");
130+
// task code
71131
}
72132

73-
void task2Callback() {
74-
_PP(millis());
75-
_PL(": task2Callb()");
76133

134+
/**************************************************************************/
135+
/*!
136+
@brief Callback method of task2 - explain
137+
@param none
138+
@returns none
139+
*/
140+
/**************************************************************************/
141+
void task2Callback() {
142+
_PM("task2Callback()");
143+
// task code
77144
}
78145

79146

0 commit comments

Comments
 (0)