A real-time operating system is a fairly tricky piece of software, even with a small RTOS – because of the way it messes with several low-level details of the running code, such as stacks and interrupts. It’s therefore no small feat when everything can be done as a standard add-on library for the Arduino IDE.
But that’s exactly what has been done by Bill Greiman with ChibiOS, in the form of a library called “ChibiOS_AVR” (there’s also an ARM version for the Due & Teensy).
So let’s continue where I left off yesterday and install this thing for use with JeeNodes, eh?
- download a copy of
ChibiOS20130208.zip
from this page on Google Code - unpack it and inside you’ll find a folder called
ChibiOS_AVR
- move it inside the
libraries
folder in your IDE sketches folder (next to JeeLib, etc) - you might also want to move
ChibiOS_ARM
andSdFat
next to it, for use later - other things in that ZIP file are a README file and the HTML documentation
- that’s it, now re-launch the Arduino IDE to make it recognise the new libraries
That’s really all there is to it. The ChibiOS_AVR folder also contains a dozen examples, each of which is worth looking into and trying out. Keep in mind that there is no LED on a standard JeeNode, and that the blue LED on the JeeNode SMD and JeeNode USB is on pin 9 and has a reverse polarity (“0” will turn it on, “1” will turn it off).
Note: I’m using this with Arduino IDE 1.5.2, but it should also work with IDE 1.0.x
Simple things are still relatively simple with a RTOS, but be prepared to face a whole slew of new concepts and techniques when you really start to dive in. Lots of ways to make tasks and interrupts work together – mutexes, semaphores, events, queues, mailboxes…
Luckily, ChibiOS comes with a lot of documentation, including some general guides and how-to’s. The AVR-specific documentation can be found here (as well as in that ZIP file you just downloaded).
Not sure this is the best place for it, but I’ve put yesterday’s example in JeeLib for now.
I’d like to go into RTOS’s and ChibiOS some more in the weeks ahead, if only to see how wireless communication and low-power sleep modes can be fitted in there.
Just one statistic for now: the context switch latency of ChibiOS on an ATmega328 @ 16 MHz appears to be around 15 µs. Or to put it differently: you can switch between multiple tasks over sixty thousand times a second. Gulp.