Giter VIP home page Giter VIP logo

tasks's Introduction

Tasks

Lightweight and fast preemptive scheduler for ATMega and SAM3X (DUE) Arduino Boards

This library implements a simple, preemptive task scheduler that is executed in parallel to the 1ms timer interrupt used for the Arduino millis() function. It allows to define cyclic tasks or tasks that should be executed in the future in parallel to the normal program execution inside the main loop.

The task scheduler is executed every 1ms. A possibly running task is interrupted by this and only resumed after all succeeding tasks have finished. This means that always the task started last has the highest priority. This effect needs to be kept in mind when programming a software using this library.

More documentation can be found here: https://htmlpreview.github.io/?https://github.com/kcl93/Tasks/blob/master/extras/html/index.html

Notes:

  • Deadlocks can appear when one task waits for another taks which was started before.
  • Timing critical tasks may not execute properly when they are interrupted for too long by other tasks. Thus it is recommended to keep task execution as short as possible.
  • The Arduino MEGA leaves the interrupts state shortly after starting the task scheduler which makes the scheduler reentrant and allows any other interrupt (timer, UART, etc.) to be triggered.
  • The Arduino DUE enables other interrupts by using the lowest possible priority (15) for the task scheduler interrupt.
  • For non-static member functions, i.e. class methods, use the adress to a wrapper function created via PTR_NON_STATIC_METHOD() instead of function name. For an example see Class_methods.

Warning:

The Arduino Due does not support reeantrant interrupts due to HW limitations. This means that unlike the Arduino MEGA the DUE is not able to execute fast 1ms tasks several times before finishing a slower tasks with for example a 10ms timebase. This problem will be especially visible if the sum of the execution time of all tasks is greater than the execution period of the fastest task.

Supported Boards:

  • all boards using the Atmel AVR controllers, e.g. Arduino Uno, Mega, Nano, etc. (only tested with those three)
  • all boards using the Atmel SAM3X8E controller, e.g. Arduino Due

Consumed interrupt:

  • Atmel ATMega328 & ATMega2560: Scheduler uses TIMER0_COMPA interrupt. This maintains millis() and analogWrite() functionality on T0 pins. However, frequent changes of the duty cycle using analogWrite() lead to a jitter in scheduler timing.
  • Atmel SAM3X8E: Scheduler uses TC3 interrupt.

CPU runtime:

Atmel ATMega328 & ATMega2560:

  • 5μs without pending tasks
  • 12μs + task duration when tasks are executed

Atmel SAM3X8E:

  • tbdμs without pending tasks
  • tbdμs + task duration when tasks are executed

Have fun!

tasks's People

Contributors

brcsw avatar gicking avatar kcl93 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.