• Stars
    star
    1,262
  • Rank 37,273 (Top 0.8 %)
  • Language
    C++
  • License
    BSD 3-Clause "New...
  • Created about 9 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Cooperative multitasking for Arduino, ESPx, STM32, nRF and other microcontrollers

Task Scheduler

Cooperative multitasking for Arduino, ESPx, STM32 and other microcontrollers

Version 3.7.0: 2022-10-10 Latest updates

arduino-library-badgexscode

Get expedited support or integration consultation for TaskScheduler from xs:code

xscode

OVERVIEW:

A lightweight implementation of cooperative multitasking (task scheduling). An easier alternative to preemptive programming and frameworks like FreeRTOS.

Why cooperative?

You mostly do not need to worry about pitfalls of concurrent processing (races, deadlocks, livelocks, resource sharing, etc.). The fact of cooperative processing takes care of such issues by design.

“Everybody who learns concurrency and thinks they understand it, ends up finding mysterious races they thought weren’t possible, and discovers that they didn’t actually understand it yet after all.” Herb Sutter, chair of the ISO C++ standards committee, Microsoft.

Main features:

  1. Periodic task execution, with dynamic execution period in milliseconds (default) or microseconds (if explicitly enabled) – frequency of execution
  2. Number of iterations (limited or infinite number of iterations)
  3. Execution of tasks in predefined sequence
  4. Dynamic change of task execution parameters (frequency, number of iterations, callback methods)
  5. Power saving via entering IDLE sleep mode when tasks are not scheduled to run
  6. Support for event-driven task invocation via Status Request object
  7. Support for task IDs and Control Points for error handling and watchdog timer
  8. Support for Local Task Storage pointer (allowing use of same callback code for multiple tasks)
  9. Support for layered task prioritization
  10. Support for std::functions (tested on ESPx and STM32 only)
  11. Overall task timeout
  12. Static and dynamic callback method binding
  13. CPU load / idle statistics for time critical applications
  14. Scheduling options with priority for original schedule (with and without catchup) and interval
  15. Ability to pause/resume and enable/disable scheduling
  16. Thread-safe scheduling while running under preemptive scheduler (i. e., FreeRTOS)
  17. Optional self-destruction of dynamically created tasks upon disable

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

TaskScheduler was tested on the following platforms:

  • Arduino Uno R3
  • Arduino Nano
  • Arduino Micro
  • ATtiny85
  • ESP8266
  • ESP32
  • Teensy (tested on Teensy 3.5)
  • nRF52 (tested on nRF52832)
  • nRF52 Adafruit Core (tested on nRF52840 with v3.6.2 workround)
  • 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)

Don't just take my word for it - try it for yourself on Wokwi


TaskScheduler process diagram

Changelog is located here.

For detailed functionality overview please refer to TaskScheduler documentation in the 'extras' folder or in the Wiki page.

User Feedback:

"I've used https://github.com/arkhipenko/TaskScheduler with great success. Running LED patterns, monitoring button presses, reading data from an accelerometer, auto advancing to the next pattern, reading data from Serial. All at the same time." - here

"There are libraries that do this automatically on Arduino too, allowing you to schedule [cooperative] multitasking and sleep the uC between tasks. E.g. https://github.com/arkhipenko/TaskScheduler is really good, I've used it before. You basically queue up a list of task callbacks and a schedule in your setup() and then do a call to tasks.execute() in loop(), which pops off the next task that is due in a queue or sleeps otherwise. It's simple, but much more straightforward than manually using if millis() - last > delta1... else sleep() and not as rigid as using the timer ISRs (which really serve a different purpose)." - here

"I took the controller with me on a business trip and spend the night getting the basic code framework out. It is going to run on top of Arkhipenko’s TaskScheduler. (https://github.com/arkhipenko/TaskScheduler) This should help me isolate any issues between the different control systems while managing the different task’s timing requirements." - here

"it's really cool and useful, for whenver you want your MCU to do more than 1 task" - here

"I encourage you to use it in the Arduino environment, it allows you to save a lot of time (and code lines) wherever you need to schedule, i.e. run many tasks that should to perform at different frequencies and when we want to have the greatest control over the performance of these tasks and we want good diagnostic of errors." - here

"arkhipenko/TaskScheduler is still my choice for now, especially when I get my pull request in, so we can have that idle 1 ms sleep feature for free." - here

"The difference with milis is basically that you don’t have to be using logics to manage the executions, but the module itself does it. This will allow us to make code more readable and easier to maintain. In addition, we must take into account the extra functions it provides, such as saving energy when not in use, or changing settings dynamically." - here

Check out what TaskScheduler can do:

Around the world:

My projects:

More Repositories

1

esp32-cam-mjpeg-multiclient

ESP32 MJPEG Multiclient Streaming Server
C++
230
star
2

esp32-cam-mjpeg

ESP32 mjpeg streaming server
C++
180
star
3

esp32-mjpeg-multiclient-espcam-drivers

ESP32 MJPEG Multiclient Streaming Server with latest Espressif drivers
C
167
star
4

Dictionary

A dictionary data type with a fast b-tree based search
C
58
star
5

EspBootstrap

A simple way to get your ESP8266 or ESP32 project configured and online quickly
C++
30
star
6

TM1650

TM1650 based seven segment display driver for arduino
C++
26
star
7

IoT_apis2

IoT Enabled Automated Plant Irrigation System
C++
14
star
8

ESP32Himem

C
11
star
9

EspColdBoot

Flexible ESP8266 and ESP32 initial device provisioning
C++
7
star
10

apis

APIS - Automated Plant Irrigation System
C++
6
star
11

AvgFilter

Integer implementation of an average filter
C++
4
star
12

pumpkin

pumpkin - an Arduino-based firmware for an Interactive Halloween Pumpkin
Arduino
4
star
13

dnd

Minecraft Interactive Do Not Enter Sword/Sign (ESP32-CAM)
C++
4
star
14

RunningLinreg

Implementation of dynamic mean squared error linear regression f(t)
C++
3
star
15

scarab

Arduino based hexbug scarab robot
C++
3
star
16

PartyLights

Code and file repo for Portable Party Lights instructable
C++
3
star
17

AverageFilter

Average Filter using integer arithmetic only
C++
3
star
18

DlpFilter

Adaptive Digital Low Pass filter (integer arithmetic only)
C++
3
star
19

predator

Files for Interactive Predator with Plasma Gun Head Tracking Halloween costume instructable
C++
2
star
20

DhpFilter

This is a digital implementation of High Pass filter using integer arithmetic only
C++
1
star
21

CPUClockSpeed

Sketch to determine clock speed on an Arduino, ESPx, or Teensy microcontroller
C++
1
star
22

PersistentQueue

Implementation of a queue that persists messages to flash
C++
1
star
23

clonezilla

Fully automated unattended backup using clonezilla
Perl
1
star