Skip to content
Michael Miller edited this page Mar 21, 2016 · 13 revisions

(actively under construction)

Please see the FAQ for common questions and answers.

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 (currently the sleep feature is not functioning)
  • Most Arm based Arduinos (sleep and watchdog support are inconsistent).

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

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.

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 library abstracts and includes that support inherently and will do the work for you.

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.

Clone this wiki locally