Updated versions of ChibiOS/RT, NilRTOS, and FreeRTOS

Hi All,

I'm currently building an little app with four threads using NilRTOS and using ethernet.
Lots of blocking with one thread whilst using the network, so I had a look at the ethernet library and straight away, the W5100:Class::init has a 300 millisecond delay in it. After a bit of fiddling I took fat16lib's cue and altered it to use nilThdSleepMilliseconds() instead of delay() - all good. Except for the now non-portable ethernet library - it doesn't work if you don't include the NilRTOS headers at the top of the library..... including them at the top of your sketch doesn't work, even if the Ethernet library is included further down.

So after some more fiddling about, here's a few steps for the not-everyday-programmers :stuck_out_tongue: to do it in a more transparent fashion:
Put your #include <NilRTOS.h> that you have at the top of your sketch into a new header file (made by pressing the 'new' button with your existing sketch open. I had one already as I defined a few types for passing data back and forth.)
Include this new file in your sketch at the top eg. #include "MyTypes.h" - note the " instead of the <>

Open up your library .cpp file (under \Libraries\ in your arduino program directory) with notepad or your favorite C editor and poke about in it. Maybe save a backup copy somewhere :slight_smile:

Everywhere you see a delay() in your library put something like:

// make it a little bit more friendly to NilRTOS.
#if defined(__NIL__)
  nilThdSleepMilliseconds(300);
#elseif
  delay(300);
#endif

When this is compiled, if NIL is defined (as it is in NilRTOS.h), the NilRTOS library is there and you can use it's functions, otherwise the library will just use the normal delay and all your 'normal'' sketches will run as-is.

This makes threading much nicer with the Ethernet library.... I might go through the LCD one as well as there are delays liberally sprinkled through it.

Hope this helps, and if anyone knows the 'right' way to do this, let me know :stuck_out_tongue: