ArduinoOS

Hi,

I created an operating system for arduino which provides real multithreading, locks, exceptions, hardware abstaction and much more and wanted to share it.

You can find a more detailed description on github.

Feel free to use it and have fun with it :).

I appricate any feedback and suggestions for future releases.

Example:

#include <KernelInitializer.h>
#include <Led.h>

lock *serialLock = GetLockObject();

void setup()
{
	Serial.begin(9600);
	KernelInitializer::InitializeKernel(mainThread);
}

void mainThread()
{
	InitTask(secondThread);
	InitTaskWithStackSize(wastingCpuThread, STACK_SIZE_TINY);
	while (true)
	{
		try
		{
			throw(EXCEPTION_ILLEGAL_ARGUMENT_NULL);
		}
		catch
		{
			Serial.println("There was an Exception!");
			Serial.print("Error code: ");
			Serial.println(GetException());
			ReleaseLock(serialLock);
		}
		clearException();
		sleep(1000);
	}
}

void secondThread()
{
	Led led(5); // Led on pin 5
	while (true)
	{
		led.TurnOn();
		AquireLock(serialLock);
		Serial.println("Spam!");
		ReleaseLock(serialLock);
		sleep(1000);
		led.TurnOff();
	}
}

void wastingCpuThread()
{
	while (true)
	{
		// Nothing
	}
}

AWESOME!!! Thank you for your hard work!!!
Is it compatible with Arduino Due? It is one of the most capable Arduinos.

For me the primary attraction of Arduinos is the fact that they don't have or need an operating system.

...R

Robin2:
For me the primary attraction of Arduinos is the fact that they don't have or need an operating system.

...R

Nothing has an operating system till you put one on it. And an OS small enough for use on an embedded machine is merely a collection of helper libraries and code. Its analogous to saying "I don't use libraries because they are not needed".

Picking the right tool for the job may mean using some more advanced topics like threading and synchronization. Re-inventing the wheel can also become quite tedious, which is why we have things like these :slight_smile:

EdgarAugusto:
AWESOME!!! Thank you for your hard work!!!
Is it compatible with Arduino Due? It is one of the most capable Arduinos.

I don't have and Arduino Due to test it out but as far as I can see it uses an ARM-Processor. ArduinoOS is right now only compatibly with 16 Bit AVR-Assembly supporting processors, as well as 16 and 24 Bit function pointers.

DrBubble:
I don't have and Arduino Due to test it out but as far as I can see it uses an ARM-Processor. ArduinoOS is right now only compatibly with 16 Bit AVR-Assembly supporting processors, as well as 16 and 24 Bit function pointers.

I just tried to compile it (ArduinoOS.ino) for Arduino UNO and it succeeds:

I get a message like this:

Sketch uses 4,044 bytes (12%) of program storage space. Maximum is 32,256 bytes.
Global variables use 81 bytes (3%) of dynamic memory, leaving 1,967 bytes for local variables. Maximum is 2,048 bytes.

Also, it success for the Arduino Mega 2560:

Sketch uses 4,508 bytes (1%) of program storage space. Maximum is 253,952 bytes.
Global variables use 81 bytes (0%) of dynamic memory, leaving 8,111 bytes for local variables. Maximum is 8,192 bytes.

But then I try to compile for Arduino DUE and get the following error:

In file included from sketch/KernelInitializer.h:14:0,
                 from /ArduinoOS-master/ArduinoOS/ArduinoOS.ino:7:
sketch/TimerOne.h:14:20: fatal error: avr/io.h: No such file or directory
 #include <avr/io.h>
                    ^
compilation terminated.
exit status 1
Error compiling for board Arduino Due (Programming Port).

Bad luck, but hopefully in the future your ArduinoOS will be popular (as Linux, but for Arduino) and ported to more Arduino models. I was thinking of using it for a project which has to manage several tasks at once, and the threads solve the problem of separated codes running all at once, and it has to be the Due, instead of the UNO or MEGA, because the DUE has de CAN bus and DACs.

Thanks anyway!!!!

DrBubble:
I don't have and Arduino Due to test it out but as far as I can see it uses an ARM-Processor. ArduinoOS is right now only compatibly with 16 Bit AVR-Assembly supporting processors, as well as 16 and 24 Bit function pointers.

You don't need to own a specific Arduino model for compiling the code on the Arduino IDE, just select the intended Arduino model in the ''Tools'' menu, then ''Board'', and there's a list of Arduino Models. With the specific model selected, push the ''Verify'' button on the toolbar and it will compile the code for that Arduino. Showing any errors.

There is no need to have the Arduino plugged into your computer when compiling.

:wink:

It can't find this files because ARM-Processors don't support AVR assembler. True, you can try to compile for different arduinos to check if it is even compiling, but just because it compiles does not mean it will work.

You can try my RTOS, Simba! It supports Arduino Due! =)

The source code is available on Github and can be installed with the boards manager in the Arduino IDE.

CAN and DAC drivers are implemented, so you should be good to go! See Arduino Due for more documentation.

Feel free to contact me if you have any questions or issues! =)

Erik

There is a new update for ArduinoOS! It is now supporting exceptions.

So one can do things like this now.

try
{
	someFunction();
}
catch
{
	Serial.println("There was an Exception!");
	Serial.print("Error code: ");
	Serial.println(GetException());
}
clearException();

Release 1.1.1 of ArduinoOs is available.

Release notes:

  • Multiple locks of the same object in the same thread no longer results in a deadlock
  • Fixed critical kernel bug that caused small or in some scenarios extreme inaccuracies in the system time affecting for example the sleep function. SwitchContext increased the system time if the argument calledFromInterrupt was true. Due to inline assembly the memory location of this argument was shifted. Accesses to it resulted in a random value. Scenarios where SwitchContext was called often resulted in an extremely inaccurate system time. One scenario where this could happen is a lock that has to wait a longer period of time till the other thread releases the lock.