Go Down

Topic: New proposal for an Arduino scheduler, applicable for ALL Arduino devices (Read 306 times) previous topic - next topic

JoeSto

Hi,

Let me introduce:
Arduino-MOS, a ultra lightweight cooperative multitasking scheduler for Arduino devices

I know, there are a lot of schedulers available, but this one is different  :D
MOS stands for Macro based Operating System.
It consists of only a few macros and can therefore be used on all Arduino devices.
It allows multitasking with blocking, cooperative tasks, but does not require additional memory.

So, give it a try...
The code with examples is available on github

/Joe
If all you have is a hammer, everything looks like a nail!
------------------------------------
Arduino OS: see https://github.com/joe7575/Arduino-MOS

kowalski

Looks lot like a sub-set of Protothreads. See, for instance, http://harteware.blogspot.se/2010/11/protothread-and-arduino-first-easy.html.

This is difficult to actually use without some guidelines as the hidden goto's will require the programmer to save and restore any necessary context that might be needed.

GCC has some nice support for local labels.

Cheers!

PS: Here is a link to the Cosa implementation; https://github.com/mikaelpatel/Cosa/tree/master/libraries/ProtoThread. It uses both objects, local labels and integrated with the Cosa Job Schedulers. Please see the acknowledgements, and references.

JoeSto

@kowalski

Thanks for your hints.
You are right, I should add a comment that task local variables will lose their value just like in the standard loop function.

/Joe
If all you have is a hammer, everything looks like a nail!
------------------------------------
Arduino OS: see https://github.com/joe7575/Arduino-MOS

JoeSto

@kowalski

Quote
Looks lot like a sub-set of Protothreads. See, for instance, http://harteware.blogspot.se/2010/11/protothread-and-arduino-first-easy.html.
You are right, there are great matches between the Protothreads and my solution.
Both go back to the article "Coroutines in C" from Simon Tatham (http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html)

I already worked with ‚ÄěCoroutines in C" in 2003. I also tested the setjmp()/longjmp()
approach. My favorite solution was an assembler solution. I published an article (in German language) on my homepage in 2004 about "Coroutines in C".
I found it on the "way back machine": http://web.archive.org/web/20070704161820/http://www.jstolberg.de/JoesCms/data/Programming/CoroutinenInC.php   :D

But I had forgotten it until I have started playing with Arduino devices last Year.

PS: To be honest: I am no C++ programmer and have some difficulties to understand your code, but it looks very clean and professional...
If all you have is a hammer, everything looks like a nail!
------------------------------------
Arduino OS: see https://github.com/joe7575/Arduino-MOS

kowalski

@JoeSto

It is fun that you mention a setjmp/longjmp implemented variant. That is actually the implementation method I used for a very simple scheduler:

https://github.com/mikaelpatel/Arduino-Scheduler

This library allows a very simple method to start multiple setup() and loop() functions in the same sketch. The only requirement is that yield() or delay() are called at some point to context switch.

Please have a look. There are plenty of example sketches as some support classes for queues, events, semaphores, etc.

Cheers!



Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy