We have several choices while writing software for an embedded system
Depending on your application, one of these will be more suited to your situation. Here we will try and go through some pros and cons of each that we have considered.
The tradeoffs are
- Development cost versus production cost- Power consumption- Stability- Real Time Requirements
An operating system, no matter what type it is, provides an Hardware Abstraction Layer (HAL).
An operating system also implements common programming abstractions - tasks, schedulers, semaphores and mutexes.
An operating system also commonly provides communications and file system stacks. An operating system may have for example support TCP/IP stack, USB stack or FAT file system stack.
Many systems have hard real time requirements. For example you are controlling a motor.
A rule of thumb that we have found useful is - Do not use an unmodified desktop operating system where the real time requirements are less than 1 ms
You can get latencies lower than 1 ms by using a modified desktop operating system. These modifications are usually done by having a real time operating system layer below the general operating system or by writing special kernel drivers.
If you want to use a desktop operating system and have hard real time requirements you may find it useful to handle the low latency real time requirements using a separate piece of hardware. The kind of hardware that you would use would depend on the kind of real time requirements that you have. If you have latency requirements more than microseconds a microcontoroller will do the trick. For latency requirements below microseconds custom hardware either in the form of Programmable Logic Devices or FPGAs is usually best.
Of course, if you have two processors the unit production cost goes up. So what we have done here is traded development cost versus production cost. Depending on your expected volume of production you may not want to do this.