Coder Social home page Coder Social logo

robaol / arduino-scheduler Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mikaelpatel/arduino-scheduler

0.0 1.0 0.0 140 KB

Portable Cooperative Multi-tasking Scheduler for Arduino

Home Page: https://mikaelpatel.github.io/Arduino-Scheduler/

C++ 100.00%

arduino-scheduler's Introduction

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

arduino-scheduler's People

Contributors

mikaelpatel avatar rstoica avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.