• Stars
    star
    161
  • Rank 228,100 (Top 5 %)
  • Language
    C++
  • Created over 8 years ago
  • Updated over 2 years ago

Reviews

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

Repository Details

Portable Cooperative Multi-tasking Scheduler for Arduino

Arduino-Scheduler

This library implements an extended sub-set of the Arduino Scheduler class. Multiple loop() functions, tasks, may be started and run in a cooperative multi-tasking style. The tasks are run until they call yield() or delay(). The Arduino yield() function is replaced by an implementation in the library that allows context switching.

Tasks should be viewed as static and continuous. This implementation does not allocate tasks on the heap. They are allocated on the normal stack and linked into a cyclic run queue. One-shot tasks are not supported. Instead the task start function is extended with a setup function reference. Tasks are started with:

Scheduler.start(taskSetup, taskLoop [,taskStackSize]).

The tasks will start execution when the main task yields. The taskSetup is called first and once by the task followed by repeated calls to taskLoop. This works just as the Arduino setup() and loop() functions. There is also an optional parameter, taskStackSize. The default value depends on the architecture (128 bytes for AVR and 1024 bytes for SAM/SAMD/Teensy 3.X).

Scheduler.startLoop(taskLoop [,taskStackSize]).

A short hand version of start() is available when the taskSetup is NULL.

The Scheduler is a single-ton and the library creates the single instance.

This library also includes support for task synchronization and communication; Semaphores, Queues and Channels. There is also built-in support for checking the amount of stack head room, i.e. untouched stack space.

int bytes = Scheduler.stack();

The Scheduler member function stack() will scan the running task stack and determine the minimum amount of remaining stack during the execution so far. The example sketch SchedulerBlinkMax shows how this can be used.

Install

Download and unzip the Arduino-Scheduler library into your sketchbook libraries directory. Rename from Arduino-Scheduler-master to Arduino-Scheduler.

The Scheduler library and examples should be found in the Arduino IDE File>Examples menu.

Performance

There are several benchmark sketches in the examples directory. Below are some of the results.

Context Switch

Board us cycles
Arduino Mega 2560 (16 MHz) 12.64 203
Arduino Uno, Nano, Pro-Mini, etc (16 MHz) 11.00 176
Sparkfun SAMD21 (48 MHz) 2.60 125
Arduino Due (84 MHz) 1.36 115
Teensy 3.1 (72 MHz) 1.10 80
Teensy 3.6 (180 MHz) 0.43 78

More Repositories

1

Cosa

An Object-Oriented Platform for Arduino/AVR
C++
339
star
2

Arduino-OWI

One Wire Interface (OWI) library for Arduino
C++
61
star
3

Arduino-GPIO

General Purpose Input/Output (GPIO) library for Arduino
C++
47
star
4

Arduino-FVM

Byte Token Threaded Forth Virtual Machine (FVM) for Arduino
C++
37
star
5

Arduino-Debug

On-target sketch debugger for Arduino
C++
20
star
6

Arduino-Shell

RPN Postscript/Forth Command Shell for Arduino
C++
19
star
7

Arduino-TWI

Two-Wire Interface (TWI) library for Arduino
C++
17
star
8

Arduino-Storage

External Memory Manager (Storage) library for Arduino
C++
9
star
9

Sketchbook

Arduino snippets that demonstrate how to program or solve a specific problem
C++
8
star
10

Arduino-SPI

Serial Peripheral Interface (SPI) library for Arduino.
C++
8
star
11

Arduino-Timemark

Timemark handler for Arduino
C++
5
star
12

Arduino-LCD

LCD library for Arduino
C++
4
star
13

Cosa-Dolce

Object-Oriented Programming with Cosa/Education and Teaching Support.
Arduino
4
star
14

vfm

Virtual Forth Machine Project
C
4
star
15

Arduino-RTC

Real-Time Clock (RTC) library for Arduino
C++
4
star
16

Cosa-MQTT

MQTT for Cosa Arduino OOP Framework
C++
3
star
17

Cosa-SNMP

SNMP Agent for Cosa Arduino OOP Framework
C++
3
star
18

parse

Yet another top down parser generator
C
3
star
19

Cosa-Domotica

Home Automation with the Cosa Arduino OOP Framework
Arduino
3
star
20

Cosa-ProtocolBuffer

Google Protocol Buffers for Cosa Arduino OOP Framework
C++
2
star
21

Cosa-NEXA

NEXA Wireless Lighting Control support library for Cosa Arduino OOP Framework
C++
2
star
22

Cosa-Shell

Command interpreter (shell) support library for Cosa Arduino OOP Framework
C++
1
star
23

Cosa-AVR

AVR ISP support for Cosa Arduino OOP Framework
C++
1
star