leOS, standing for little embedded Operating System, is a scheduler/taskmanager (a prototype of an OS) for Arduino boards and Atmel microcontrollers that can manage background tasks. leOS can start new tasks, pause and resume them and delete them too. All is done using a scheduler that can start tasks without the partecipation of the user so that the tasks will appear trasparents at the main loop. To be honest, it should more correct to say that leOS is actually something that is halfway a simple prototype of an real-time operating system (RTOS) and a scheduler. In fact it doesnt have the methods to give a task a tick of time to run itself and a preemptive sistem to stop them, freeze their state and resume them in a later moment; but it’s something that is more complex and efficient of several other schedulers that just use millis() to schedule when launch a task because i.e. leOS isn’t affected by the use of delay() in the main loop.
It uses an interrupt driven scheduler (based on an 8-bit timer of the micro, usually Timer 2) that checks is time has come to start an active task. The user can choose the interval time from 1 to 3600000 ms (1 hour at the moment, the max value can be changed). The library offers 4 methods to manage tasks:
addTask(function, interval)
pauseTask(function)
restartTask(function)
removeTask(function)
addTasK add the "function" in the scheduler with interval "interval". pauseTask and restartTask halts and resume the execution of a task, removeTask removes a task from the scheduler.
The library should run on several micros albeit it has been tested only on Arduino/Atmega328 at the moment.
More info and the code are available here:
http://www.leonardomiliani.com/?p=516&lang=en
leOS is at a very early stage, comments, suggestions and critics are welcome
EDIT:
a stable version is attached at this post
EDIT2:
if someone has found this lib usefull,I publish for him the new version 0.1.1, that let the user chooses between 32-bit & 64-bit counters (the first ones consume much less Flash memory), it's compatible with Atmega32U4 (Arduino Leonardo), can manage one-time tasks, can modify a running task.
EDIT3:
leOS is now updated to version 0.1.3.
I've introduced the ability to add a paused task at the scheduler, so that it won't start running immediately after adding. This is useful i.e. if your task drives something like a LED or a transistor and you want to choose the right moment to start the action. So the new sintax of the method addTask is now as follow:
addTask(function, interval[, status]);
with status that can be:
PAUSED: to add a task in paused mode, so that it won't start until the user won't use the restartTask() method;
SCHEDULED (default option): a task that start running immediately
ONETIME: a task that will have to be run only once
Thank you for your feedback.
N.B.:
starting from v. 0.1.3 the library will be available only from my web site, due to the fact that in this manner I can keep track of the whole number of downloads