Skip to content
schlammbad edited this page Feb 21, 2024 · 13 revisions

(actively under construction)

Please see the FAQ for common questions and answers.

Please consider donating to the cause.
Donate

For quick questions jump on Gitter and ask away.
Gitter

Overview

This library provides an Arduino project with a non-preemptive multitasking support that is compatible across hardware platforms. Non-preemptive multitasking will never interrupt your code to switch to another task. This means that to switch tasks it relies on you to write code in small pieces and return quickly.

This model has several benefits for small microcontrollers when compared to a preemptive task system.

  • There is little need to protect variables from being accessed from other tasks since only one is run at one time. This makes code less complex and less fragile.
  • No wasted CPU cycles saving state and switching tasks too often as the time to "switch" tasks is controlled by you when your code is done doing some atomic piece.
  • No wasted memory having a separate stack for each task, each with their own pre-allocated memory for max stack use. In this system it uses the already existing stack.

For a good starting point at understanding the direction of this library, please read Adafruit Multitasking Arduino. While this library was not based on that work, they do share common goals.

NOTE: Avoid the use of delay() in all high level code as the tasks timing should be used to replace it.

Supported Platforms

  • AVR 8 bit Arduino
  • ESP8266
  • Most RM based Arduinos (sleep and watchdog features are not supported yet).

There are several examples that will help you get started. They range from simple to complex and are always a good reference.

There are other projects that use this library to solve problems and create useful solutions. You may find someone has already provided a feature you are looking for.

An important part of multi-tasking is understanding time. This can be how often you need to do a task or how much time has passed since the last time your task was called.

Sleep Support

Microcontrollers often support the ability to go into a low power mode while still being able to quickly wake up and react to changes. This is useful for projects that are powered from a battery. This library abstracts and includes that support inherently and will do the work for you. Due to the unique features of sleep for each board type, the sleep support exposed is also unique for each. Select one of the below to see specifics:

Microcontrollers often support the ability to auto-reset when the code goes into an unexpected lockup. These lockups can be caused from unexpected infinite loops or bugs. But having your device sit in this locked up state isn't good, so the watchdog will monitor this and trigger a reset for you; thus restarting your device and code from a known good state.
This library will do the work to setup and "feed" the watchdog. All you need to do is avoid using delay() and architect it into small pieces that return often.

The TaskManager is the core of this library. It will start and stop tasks, and call them to run in their time interval.

There are several ways to write tasks depending on the complexity of the task needed.