Arduino_OS.ino - A Small Arduino Cooperative "OS" Task Switcher

To Whom It May Concern,

This small OS has been tested on various other processors and I ported it to the Arduino ATMega328p to see how it would work. I am contributing it to the public domain hoping someone might find it of use as well.

I tried to ask how to properly submit this software for evaluation on a different topic called "How to submit software to the Arduino public domain?" and I did not make much progress with that approach so I am just going to punt and submit it here.

I have attached my Arduino_OS.ino file that has all of the OS and example tasking code. I wrote this little OS awhile back and I have ported variations of it to various processors (ARM-7, Coldfire, X86 etc) and projects successfully.

The code is a small cooperative OS that I wrote to make the creation of more sophisticated and modular projects easier.

The OS has implements the following features:

CreateThread - Called from main to initially setup a task.

Block - Stop a task from running.

UnBlock - Called to make another task ready to run that was previously blocked.

Delay - Cause a task to suspend execution for the designated number of ticks.

InitThread - Must be called from a task thread, prior to "FOREVER" loop, to complete the task setup initially begun in CreateThread.

Pause - Give up the processor and allow another task to run.

A general purpose timer class (GPTimer) has been included to allow a user to create various random timers as needed for projects. This class was used to implement the "Delay" function.

Finally, a small Queue class with Put and Get methods has been included for inter-task communications if needed.

I hope that someone finds it useful.

Thank You and Best Regards

David Q. R. Wagoner

Addendum: A bug was found in the attached Arduino_OS.ino in the Queue.Put method. This error was corrected and uploaded with OS documentation in a later posting (DQRW).

Arduino_OS.ino (9.34 KB)

Can you also provide a suitable Arduino program to illustrate how to use your scheduler.

Documentation aimed at somebody who knows absolutely nothing about Arduino programming would also be a good idea - if not essential.

In fairness, I should put my cards on the table - I'm not convinced the Arduino needs a scheduler when it is so easy to manage things using millis() as illustrated in several things at a time. Using millis() directly also means that it is easy to debug when things go wrong - compared with trying to figure out a scehduling library.

...R

Great idea, dqrwagoner! I myself have created such a program (Unos). Perhaps you can give me some pointers? Maybe we can work together to make a better system than just one of us could?

Robin2,

The Arduino_OS.ino contains the "OS" code and example code (standalone project). The simple example code is at the bottom of the module.
As for wondering if is useful, that will be up to each individual developer but I submitted it to your Arduino community because it is very simple to use but robust. I can honestly say that after over 35 years of developing software for micros (my first was the Intel 8008) being able to functionally modularize a design will pay off in debugging and maintainability later. BTW, do not make the mistake of underestimating your Arduino platform. In the 80s, I developed Host and RTU systems that supported multi-PID controls, multi-serial communications and floating point calculations for the oil industry. That was using an Intel 8080 at 8Mz using 16k RAM and 48k ROM. Your Arduino system is far more capable then most people realize. But these systems would not have been possible without good modular design and debugging methods. I hope that the OS will help to encourage good design of more complex applications.
Best Regards
David Q. R. Wagoner

Goodinventor,
Thank you for your offer. Unfortunately, I manage a software department and will not have much spare time in the near future. Before I get into my other projects I wanted to take a moment to post the OS code to your community. I have read about the Arduino for years and like the philosophy. I have used my OS for many personal CNC projects and thought I might be able to help support the Arduino effort by donating my code. I actually do not even own any Arduino hardware. I ported it using open source debuggers and simulars for the AVR.
Best Regards
David Q. R. Wagoner

dqrwagoner:
The Arduino_OS.ino contains the "OS" code and example code (standalone project). The simple example code is at the bottom of the module.

Thank you.
I understand your time constraints.

...R

If my code is not "intuitively obvious to the most casual observer" (someones else's code never is) then I will try to find time to put together a few instructions. My assumption was that looking over the code would be enough to get the gist of its operation but I might have been mistaken.
Best Regards
David Q. R. Wagoner

dqrwagoner:
"intuitively obvious to the most casual observer"

I guess you are not a regular Forum reader :slight_smile:

My sense is that your project may offer most benefit to the least experienced - hence the suggestion for documentation. However, you have to make decisions about your time.

...R

I have an Arduino that I have been testing with. But as for the 'community', I am not in a business since I am only 14 years old. I believe that the Arduino can run a simple OS. It has more resources than an Apple I!

All,

I took a few hours to "throw together" some instructions on how to use the OS. I have attached them in M$ Word (doc) format so that others might elaborate on them in my stead.

NOTE!!!! In documenting the OS I found a bug in the Queue.Put() method that I have corrected and attached. It should have returned a "false" instead of "0xff". The "0xff" was fluff from another language that I used in the past and failed to catch. I apologize for any inconveniences that his may have caused anyone.

Thank You and Best Regards

David Q. R. Wagoner

(And of course Best of Luck!)

Arduino_OS.ino (9.34 KB)

Arduino OS Instructions.doc (39 KB)

goodinventor:
I am not in a business since I am only 14 years old. I believe that the Arduino can run a simple OS.

I was not aware, until now, that you were so young. I had assumed you were a young adult.

Your age will allow you plenty of time to study operating systems - but I do not think you have yet reached the publication stage.

I don't think anyone doubts that an Arduino CAN run a simple OS. It is just that I, for one, don't see that it would be an advantage.
By all means use an Arduino to explore the way in which Operating Systems work and to learn the "trade"

Study @dqrwagoner's code carefully until you understand every piece of it.

...R

Thanks. I will work some more on it.

goodinventor:
I believe that the Arduino can run a simple OS. It has more resources than an Apple I!

. . . but only half as much RAM, and without the external address and data buses, or the video display.
Don't forget, on an Arduino, even if you only want a character-only display, the character generator will use more of your flash program memory, but on the Apple, it was a separate ROM, and the separate 1K display memory didn't eat into your system RAM.
Similarly, unlike TVout, the video display was generated in hardware, saving processor cycles for the user.

You're really not comparing like with like.

That's true, but the Arduino has more processing power. I think I'll just try a few things on the Arduino to test the idea, then port the whole program to a board with more capabilities, like the Raspberry Pi.

goodinventor:
That's true, but the Arduino has more processing power. I think I'll just try a few things on the Arduino to test the idea, then port the whole program to a board with more capabilities, like the Raspberry Pi.

I know that not every comment about your attempts has been constructive but many of them were and this does not give me the sense that you have learned anything from them.

The Raspberry PI already has the Linux operating system.

...R

This project is mostly for experimental purposes. Anyways, it will take a long time for the OS to actually be useful, but I am willing to go through the hard process of building it.

Robin2:
I know that not every comment about your attempts has been constructive but many of them were and this does not give me the sense that you have learned anything from them.

The Raspberry PI already has the Linux operating system.

...R

Even better, it has RISC OS

OK. And?

RISC OS was designed for the ARM, unlike Linux.

Well, both work on ARM. But I see what you mean. Linux supports a bunch of processors, whereas RISC OS is designed only for ARM processors.