Real time operating system (commonly called as RTOS) is a software stack responsible for managing the workload and resources in embedded systems. The core of a microcontroller can execute only one task/ thread at a time, and given the capacity of modern days microcontroller, it would not be use of it’s full potential if they are used for any one specific task (such as taking inputs from a sensor or blinking an LED). Main Job of an RTOS is to rapidly switch between different tasks, which feels like multiple programs are being executed simultaneously on a single core. [1,2]
The term real-time in RTOS represents the very nature of RTOS being event-driven and pre-emptive. An event-driven programming paradigm means that the flow of the program is decided by occurrence of events (such as user actions, sensors values, messages from other programs etc.). Pre-emptive nature of RTOS means that a task can be postponed based on a temporary interrupt being generated from external sources (outside the current task) ,and resumed at a later time.
If you have tried to understand architecture of the microcontrollers and microprocessors, a term called Kernel must have crossed by you. Have you wondered, what is a kernel and what it does? Kernel is basically a set of computer program at the core of an OS or RTOS, which controls everything in system. For a basic understanding you can consider kernel as an interface between user and the hardware. There are 5 types of Kernel architectures: micro Kernel, monolithic Kernel, hybrid kernel, exokernel and nanokernel. Out of these five, micro Kernel and monolithic Kernel are most commonly used.
An operating system or RTOS can be divided in two categories: User services and kernel services. User services is combination of application layers and the space where users can interact with the machine. Kernel services are dedicated for hardware allocation to the the requests. In monolithic architecture, the entire RTOS/OS runs as a single program (both user space and kernel space in the same address space) where as in micro-kernels, kernel services and user services are different program running in different address space. Monolithic kernels are bigger in size with fixed number of user applications while in microlithic architectures, kernel size is relatively smaller and all the required features can be added. Micro Kernels are the newer trend because of its nature of feature addition. Linux foundation maintains a famous RTOS called Zephyr which is based on microkernel architecture. However, it consists of a small nanokernel as well. FreeRTOS is a commonly used RTOS which is also having MicroKernel.
RTOS is classified in 3 categories: Hard RTOS, Soft RTOS and firm RTOS. In hard RTOS, the critical tasks are guaranteed to be completed within time range (example: Air traffic control system, medical imaging system etc.). In soft RTOS, some relaxation of time is provided for the tasks (example: multimedia system). In firm RTOS, a deadline is being followed but the impact of missing deadline is smaller.
How to choose a RTOS for your project depends on several factors. There are several RTOS available to choose. Wikipedia has a comparison table for over three dozen of RTOS [3]. Some of these RTOS are open source while others are not. [4] has explained some parameters to consider before choosing an RTOS in a detailed blog. Some main considerations are: memory size, RTOS scalability, shell access (command line interface to RTOS), memory management unit support etc.
This article aims to list some common RTOS with their main features, supported microcontroller boards, number of active contributors and users, kernel size, communication protocols. It focuses on three common open source RTOS : FreeRTOS, Zephyr and RIOT.
FreeRTOS is one of the most famous RTOS available open source and is supported by Amazon which is integrated with several architectures (Arm cortex M7, M3, M4, M0+, A5, Arm7, ARM9, Tensilica Xtensa, RISC-V) and used on STM32, ESP32 and Arduino boards. The popularity of FreeRTOS helps you solve any issues and as it is supported by amazon, it comes with several API to integrate with Amazon Web Services [6, 7].
Zephyr was developed by Virtuoso system and later integrated with the Linux Foundation and currently it is the largest open source RTOS project [5]. As mentioned on it’s Github page, it has 124 repositories and 4730 forks [8: accessed on 28/04/2023]. Zephyr project has active contribution from Nordic, intel, ST, Espress-if and Wind river. The range of supported APIs in zephyr makes it an interesting choice for developers. If you scroll the list of APIs in the list provided by [9], the list includes more number of APIs compared to FreeRTOS and RIOT.
RIOT was developed by academic institutions like INRIA, FU Berlin and HAU Hamburg [10]. It has a tiny kernel with microkernel architecture and supports programming languages as C, C++ and rust. The source code is available on GitHub and it has 1886 forks with 29 repositories [11: accessed on 28/04/2023]. It supports several architectures (AVR, MSP430, ESP8266, ESP32, RISC-V, ARM7 and ARM Cortex-M) and can be integrated with several boards. It has a list of supported drivers provided by [12].
Table below is created by searching for some important features about these three RTOS and for some on them, it provides a link as well.
Choice of RTOS is dependent on architecture of your system and the applications you are aiming. This article suggests you to check for the supported architecture and features required on the links provided for any RTOS and then decide. Every one of them comes with their merits and it’s helpful to read about them.
References:
[1] https://en.wikipedia.org/wiki/Real-time_operating_system
[2] https://www.geeksforgeeks.org/real-time-operating-system-rtos/
[3] https://en.wikipedia.org/wiki/Comparison_of_real-time_operating_systems
[4] How to Choose a Real-Time Operating System (lynx.com)
[5] Zephyr Project – Zephyr Project
[6] https://lembergsolutions.com/blog/freertos-vs-zephyr-project-embedded-iot-projects
[8] Zephyr Project (github.com)
[9] https://elixir.bootlin.com/zephyr/latest/source
[10] RIOT (operating system) – Wikipedia
[11] RIOT · GitHub
[12] RIOT – The friendly Operating System for the Internet of Things (riot-os.org)