Device Software

What is an RTOS?

There are basically 2 ways any embedded system device can run software - bare-metal or with an Operating System ( OS ) / Real-Time Operating System ( RTOS ).

Bare-metal means writing the code directly for the hardware without using any middleware or abstraction layer or operating systems. This is completely fine for some basic applications which do a couple of tasks. For example, in the application - Water level controller, only 2 tasks are monitoring the water level sensor and switching on the pump motor if the tank is empty. This can be simply executed in an infinite loop something like below and you are good to go.

unsigned char waterLevel = 0x00;
while( 1)
        waterlevel = readSensor( );
        if ( waterStatus = 5 )
                setMotor( );

But, in little complicated applications, if you keep adding features, you can see yourself creating abstractions for various stuff like buffer overflows, sleeping to save battery, run multiple tasks based on priority, etc. If a lot of similar things are implemented, then it's just like reinventing an RTOS!

So, what exactly is an RTOS?

RTOS or a Real-Time Operating system is an operating system usually running on an embedded device that can run time-constrained applications. An RTOS provides all the functionalities you would expect from an operating system such as memory management, thread synchronization, timers, cross-boundary communication, etc.,

How is it different from an OS?

An Operating system or General Purpose Operating System ( GPOS ) is an operating system that usually provides a soft real-time response. So, there is no guarantee that the task will be complete. But an RTOS usually provides a hard real-time response, providing a fast and highly deterministic response to external events. Examples of GPOS: Linux, Windows OS, macOS, Android, etc Examples of RTOS: FreeRTOS, LynxOS, QNX, etc

Different types of RTOS

RTOS can be classified into 3 types

Soft RTOS: missing a deadline associated with a task is acceptable. Example: a sound system of the computer. it is okay if you miss some bits, but it won't have a catastrophic effect on anything.

Firm RTOS: Should not miss deadlines associated with the tasks. But missing a deadline may not cause a catastrophic effect, but may cause undesired effects. This might cause a reduction in product quality. Example: Robotic assembly lines. if it misses a deadline, it would be bad, but there might not be catastrophic effects in most cases.

Hard RTOS: These types of RTOS strictly adhere to deadlines associated with the tasks. Missing a deadline can cause catastrophic effects. Example: Car airbag system. If the task of deploying an airbag is delayed, then it can cause the loss of lives.

Main features of RTOS

  • Occupies very little memory and CPU overhead ( 1-4% )
  • Predictable response times
  • Kernel schedules which tasks to be run next based on priority
  • Supports multitasking and task preemption. Preemption means to switch from a currently executing task to a high-priority task ready and waiting to be executed.
  • Short interrupt dispatch latency
  • Short context switching latency
  • Memory management

RTOS and Internet of Things

The "Thing" may or may not run an operating system of any type. As stated above, it can also be a bare metal if it serves some basic purposes and has fewer tasks to perform. But, RTOS makes the system much more reliable. Some of the RTOS like Amazon FreeRTOS provide connectivity, security, and over-the-air update functionalities right out of the box. If the application you are building is more complex or might get more complex with time, then it is a good idea to use an RTOS.

More on the Amazon FreeRTOS in the next articles.

More Posts

Git commit best practices

This post explains how to write good commit messages and how not to write bad commit messages. Also, you will learn some more best practices...

Generic IoT device architecture
Device Hardware

In this article, you will learn about the generic Internet of Things device architecture. Certain specific components are necessary to consi...

MQTT : Quality of Service ( QoS )

Quality of Service (QoS) in MQTT messaging is an agreement between sender and receiver on the guarantee of delivering a message.