blinking two LEDs is a ridiculous example.
Fairly enough. As I proposed earlier, pick your favorite tasks and implement them on your favorite RTOS and we will then compare.
Do you often take the things to extreme? Do you use single tool for everything? I don't use any Microchip product however, I would use PIC10F series to do very very simple task in very confined space.. Nearly just a single thing, or may be a second but simple second.. That's it.. What gain will we have using PIC10F series and RTOS? We are talking about multiple tasks that run parallel: communication, user interface, time critical complex responses etc.
For instance, what e100 asks is perfectly RTOS candidate.. Main task deals with user interface, other task scans buttons and transmits it as key down, key up messages to message queue of UI task. Other task deals with communication. Transmits the request as messages to main task.. Even on Atmega88 it can work.. I've been not using Atmega, as ARM M0 chips are cheaper than that.. I would put 4x4mm ARM though..
For tiny, if you re-read my post, you would see something like 64B out of 512B as a measure of second task's payload in RAM.. I don't remember I claimed RTOS for every chip. And I am not claiming RTOS wont add some ROM space.. But most of the time, even with RTOS, plenty of RAM and ROM is left in many chips.. I usually use remaining ROM for different fonts, graphics, sound, audio etc.. What I referred as "cost of switch statement" is not the total overhead of ROM, but CPU time lost in the unnecessary state machine loops. Think about this, if you didn't plan to avoid redundant state machine's state check, I mean you call state machine's function that has main switch-case block, CPU will have to run into a lot of compare, jump, compare jump instructions.. This is lost time also lost energy if your application is running by batteries. If you use RTOS, your task would not bother CPU until it is awaken by what it is waiting for..
How many lines of code would you write to implement reading an I2C sensor, displaying it, setting an alarm level, and responding uart communication.. How much time would you spend on state machine? Than customer wants new stuff, new commands send from UART etc.. They always want something more when they see their project is running. This is my measurement. First how much time, second how easy to add new features, and third how many lines looks same.. If I am writing similar thing again and again, I am doing something wrong..
BTW, what most developers miss is the cost of the time. You can buy chips, there is no online store that you can buy time.. Measurement of how much ROM and RAM overhead is one thing, but if the chip you
have to/may use have enough of them, than it is not a good measure..
An example of measurement.. I have Callback class, which costs 8 bytes of RAM on 32 bit, 4 bytes on 8 and 16 bit.. You can register Event (object that task can wait for), function, and even a nonvirtual method of any object.. (This is not allowed by C++ however I found very simple workaround)
With callback class you can do following:
void handleTimerTick(void* sender, void* param)
{
// do something, caution this is called by IRQ
}
int main()
{
core.init();
Timer t;
t.setPeriod(100);
t.onTick = handleTimerTick;
t.start();
while (1)
{
// do something
wait(250);
}
}
Timer calls handleTimerTick in each 100ms.. Same Callback and same Timer class:
int main()
{
core.init();
Event e;
Timer t;
t.onTick = e;
t.setPeriod(100);
t.start();
while (1)
{
// do something
// do other thing
e.wait();
}
}
Here Timer t sets Event e in every 100ms.. Your loop is repeated in each 100ms, even the code before e.wait() takes different time in each loop.. For example, suppose on one loop it took 60ms to run to e.wait, it will wait 40ms to rerun, and 30ms in other run it will take 70ms to rerun.. I can give lots of different usage of Callback, connecting objects to objects -for instance which makes code reuse really easy..
Isn't that wise?
Same Timer class, same Callback class, just used for different kind of stuff. Isn't it worth of 4 bytes of RAM (8 and 16 bits), or 32 bytes of RAM (32 bits) if you have 512B of RAM? Isn't "larger than 1KB" common nowadays? Could you use ROM, and RAM usage instead of time you spent, code cleanness, ease of adding new feature as a measure here? Except that you have to use very very tiny ROM, very very tiny RAM that are forced by the projects constraints.. Till now, I never came across that constraint. May be many LED's driven by many 6 pin MCU and serial communication of multiple LED driver MCU's.. Or something similar, ok, don't bother using RTOS there..