Software Operating Systems
The Operating System is the core Software Architecture component that determines how the overall system task execution happens. Over time, a number of Operating System types have been developed. For this post, we will focus on Embedded Software Operating System types. The primary ones are:
- Round-robin Scheduler
- Round-robin Scheduler with Interrupts
- Function Queue Scheduler
- Real Time Operating System – RTOS
The Loop or Round-Robin Scheduler is a single execution thread that runs repeatedly. Systems that run in loops can be either simple or large, but the key feature is that there are no context switches or background tasks that can alter the flow of execution. As a result, these are best suited to simpler tasks that do not require fast response to external stimuli, or which can focus on that stimuli only. Some DSP systems work this way because the execution time will be exactly known.
An example of a recent project we did that that used a single loop was a protocol converter that read a weigand data stream and passed it off to a main processor using a handshaked bit pipe. This was done because the main processor had a latency conflict and could not guarantee to handle the weigand minimum data pulse width and 2 other time critical communications tasks at the same time. So one System Architecture decision was to separate this into 2 microcontrollers to manage the required response time. A small 8 bit processor (8 pins too) was used to buffer the incoming weigand stream. Each time a new byte was collected it would reflect the first bit to an output and raise a synchronisation pin. The main processor would raise a read pin after collecting the bit and the slave processor would release its synchronisation pin then the main processor would release the read pin. This allowed very fast data transfer to the main processor at a time of the main processors choosing with a simple and deterministic process in the slave processor.
Systems like this are referred to as Asymmetrical Multiprocessing systems.
A Round-robin Scheduler loop processing system looks like this:
Round-robin Scheduler with Interrupts
The Round-robin Scheduler with Interrupts is the most common form of small operating system. It is enormously flexible and provides fast response to external hardware signals with guaranteed internal time management. It is very common to use interrupts for:
- Time ticks to maintain a precise sense of elapsed time
- Communications, especially UARTs
- Specialised output controls such as PWM, motor control and waveform generation
- ADC collection and digital filtering
- Input monitoring and debouncing
For small systems up to 10K lines of code this format of operating system is our usual starting point because there is almost nothing it won’t handle if designed correctly.
The primary advantage is guaranteed response for high priority events via Interrupt.
The primary disadvantages are that in a worst case scenario every task could fully execute in the same pass and that care must be taken to manage data that is used by both the main loop and interrupt service routines.
Quite large systems can be handled using this style of Operating System and it is also easy to run in a fully simulate environment without hardware. In 2011 we received the Electronics News Future Award for Industrial Electronics for a capacitor bank power factor correction controller which uses a Round-Robin Scheduler with Interrupts Operating System.
Function Queue Scheduler
A Function Queue Scheduler is where a list of function pointers is pushed to an execution queue. The Function Queue also contains priority information so that very high priority tasks can be pushed to the front of the queue. The tasks are executed by calling the function pointers. This type of Operating System is best suited to heavily event driven systems. Each time an event occurs the event handler, usually an interrupt, pushes a new task to the Function Queue.
The primary advantage is that only the code required to handle the current events needs to execute whereas in a Round-robin Scheduler all the modules execute at least a minimal set of decisions to determine if there is anything to be done on this pass.
The primary disadvantage is that a very low priority task might never execute if enough high priority tasks are pushed to the queue ahead of it. This is referred to as ‘starving’.
We have used a variant on the Function Queue Scheduler for handling user configured accessories and user selected program tasks. These were managed by building a token queue rather than a function queue and operated like an interpreted language.
This style of Operating System is probably the least well understood and so the least used. The diagram below shows the basic operation ignoring the use of priority to alter the insertion point in the Function Queue.
Real Time Operating System
The Real Time Operating System or RTOS is the “all singing all dancing” Operating System that allows different threads of execution to operating asynchronously and independently. A great benefit of this is that separate modules or even programs can run on the same computer without the writers having to know anything about the other modules. It is the most flexible of the architectures and also the most difficult to predict precise results for any given system. Problems like priority inversion and task interdependency can lead to system lockups so careful design is still required.
Many commercial modules such as TCP/IP communications stacks assume you are running an RTOS.
The RTOS generally requires the most system resources for the operating system itself and most RTOS systems are sold under commercial licenses. Some include run time royalties. Free RTOS is an example of an open source RTOS that is becoming popular because it is free of royalties or annual support subscriptions.
The RTOS is considered the ultimate operating system and for large, complex or distributed team projects and has many advantages. It is also the most complex with the most disadvantages.
Most modern general purpose computers and smart hand held devices use an RTOS including Windows, OS X, iOS, Android, Linux, Solaris, UNIX and many other variants. A useful list can be found at Operating System List.
Selecting an Operating System type
So in building a system, it is important to work out the level of complexity and the future expansion expected. We approach this by assuming that it is always best to use the simplest approach that gets the job done. This also eases support and maintenance which are software lifecycle costs often not considered up front but which are affected by you choice of Operating System.
So the process we use is:
- Analyse the requirements to identify latency and response requirements
- Look at the processor clock frequency and instruction execution rate
- What is the simplest approach that can work
- Does a more complex approach have enough advantages to justify using it
- Select the Operating System type to use
Although this sounds simple enough, and analysis is not always straight forward and there can be surprises down the track that require the decision to be evaluated again.
Successful Endeavours specialise in Electronics Design and Embedded Software Development. Ray Keefe has developed market leading electronics products in Australia for nearly 30 years. This post is Copyright © 2011 Successful Endeavours Pty Ltd