The idea or concept of an operating system originates from the early 1960s. This was the era of “big iron” or mainframe computers.
Initially, computers were used much like programmable calculators. Computers ran a single computational task for one user at a time. Each user with a computational task would first code an algorithm for the task and then bring the program to the computer department, typically as a stack of punched cards or a roll of paper tape.
The “high priests” serving the machine would then enter the user’s program into the machine and start the calculation. The program ran until it finished with results or crashed. The results of a calculation were typically presented as printed sheets with text.
Evolving out of a need to streamline these manual tasks were operating systems.
Modern operating systems perform many essential functions. The following are some of them (in decreasing order of importance):
Scheduling is about when and how to allocate computational resources to different tasks and users. This is especially important in multitasking and real-time systems. Some computational resources are one of a kind. For example, a single CPU cannot be used by more than one task at a time.
In an attempt to optimize performance and shuffle priorities, scheduling algorithms have been extensively studied in academia and software development projects.
Memory management is another critical function in operating systems such as Windows, Mac, and Linux. Modern operating systems utilize virtual memory addressing, where each application appears to have its own unified address space consisting of various types of memory, like RAM and mass storage (i.e. hard disk or SSD).
If virtual addresses are used, they must be translated to real addresses in order to access memory. The OS takes care of this by means of a specific piece of hardware, the memory management unit (MMU), which is nowadays integrated into the CPU. The MMU also protects the address space of each application from being overwritten by other applications and crashing the application.
Microcontrollers, in general, don’t have an MMU and hence cannot run Linux and similar OSs. However, newer microcontrollers in the ARM Cortex-M family include a memory protection unit (MPU). This is akin to a simplified MMU and provides some of the same benefits, like protecting the memory space of a task against corruption by another task.
An OS greatly simplifies the implementation of applications by presenting an application programming interface (API), which is an abstract model of the computer system and hardware. Without an API, each application would need to include its own code for common tasks like as writing to a file and communicating with peripherals. This would be a highly inefficient and needless duplication of efforts. With an API, the application only needs to issue a system call, and the OS then handles all the unpleasant and complicated details.
Many embedded microcontroller applications don’t actually need an OS at all. An example would be a simple thermostat. First, the microcontroller would read the actual temperature from a sensor. Then, it would switch a heater on if the actual temperature is less than a target temperature. Otherwise, the heater is switched off.
For applications like this, where the tasks are few and simple, an operating system isn’t needed. Indeed, any OS imposes an additional load on its system’s resources, leaving less available for the application itself.
On the other hand, in an embedded system with many tasks of different priorities and time constraints, a real-time OS can be beneficial or even necessary.
Wikipedia defines a real-time operating system (RTOS) as “an operating system in which the time to process an input stimulus is less than the time lapsed until the next input stimulus of the same type.” This is an often-quoted definition.
Furthermore, RTOSs are usually characterized as “hard” or “soft”. This has to do with the consequences of missing a deadline in responding to a stimulus or an event. In a hard RTOS, the consequences could be catastrophic, for example in aircraft flight control systems or self-driving cars. In soft RTOSs, a missed deadline might well have a negative impact on something but cause no disaster.
When considering an RTOS, it’s worthwhile to pay attention to a few details and important characteristics.
Commonly seen with RTOSs, “open source” seldom means “completely free”, even if the products and related intellectual properties are available without payment. In most cases, there are some albeit minor restrictions in using the product.
This is all spelled out in the license terms. They’re often not very significant for one-off projects, but they may be worth reading for larger-scale or commercial deployments.
Board support packages with ready-to-use examples are very good for starting a project rapidly and smoothly without too much trouble.
An integrated development environment (IDE) is a toolset for developing embedded applications. This includes at least a code editor, compiler, and debugger. Sometimes other tools are also included, like a code library.
In the Internet of things (IoT), most devices are interconnected by wireless networks. More recent RTOSs include protocol stacks for several types of wireless networks: WiFi, Bluetooth, and Bluetooth Mesh, LoRa, etc.
RTOSs are available in a bewildering variety – more than any other kind of OS. A Wikipedia listing presents nearly 200 RTOSs divided into different categories according to types of licenses (open source or proprietary), application areas, development status, and so on.
Open source is obviously the preferred license type for maker projects and casual experimentation, as it comes with the advantage of being free. On the other hand, there is usually no direct support from the OS developer. Users are thus limited to community support (if it exists), good documentation, and easy-to-install examples. Some open-source RTOS providers offer commercial-level support against a monthly payment or other similar schemes.
Several RTOSs started out as proprietary products but were later released into the public domain. The RTEMS operating system is one such example, with an interesting history starting in the 1980s. Originally an acronym for “Real-Time Executive for Missile Systems”, RTEMS was then relabeled “Real-Time Executive for Military Systems” and finally “Real-Time Executive for Multiprocessor Systems”.
Looking at more recent open-source RTOS offerings, the most interesting ones are clearly targeting IoT applications and include enhanced support for easily connecting a device to a cloud platform such as Amazon Web Services (AWS) or the IBM Watson IoT Platform.
To illustrate many of the aspects discussed here, let’s take a look at three well-known RTOS examples:
The open-source Mynewt OS is in active development under stewardship by the Apache Software Foundation. Apache advertises itself as the “world’s largest open-source foundation,” with more than 39,000 volunteers contributing code to hundreds of projects.
Mynewt is especially strong when it comes to wireless protocols. It offers a Bluetooth Low Energy (BLE) 5.0 stack and Bluetooth Mesh support. LoRa and LoRaWAN protocols are supported as well.
FreeRTOS was developed by Real Time Engineers, an organization located in Bristol, UK. In 2017, stewardship for further development was transferred to Amazon, which also provides a version of FreeRTOS with libraries for IoT support, specifically for AWS.
FreeRTOS is also available in two other special variants. Commercial licensing is available in the form of OpenRTOS, and for safety-critical systems, a version called SafeRTOS is available, developed by Wittenstein High Integrity Systems (WHIS), a FreeRTOS partner that specializes in safety.
The Mbed OS is one part of a comprehensive ecosystem for the rapid development of IoT devices based on the ARM Cortex-M microcontroller family. Mbed includes a toolchain and IDE for online use (the Mbed Online Compiler), which is based on ARM default tools, such as the version 6.14 compiler. Alternatively, GNU tools can be used instead of ARM tools.
In addition to the online IDE, there is also a desktop version, Mbed Studio, available for Windows, Linux, and Mac. The development tools can also be used via a command-line interface (CLI).
The documentation includes many examples and tutorials.
Lead image source: Percepio
License: The text of "Real-Time Operating System (RTOS): A Simple Guide" by All3DP is licensed under a Creative Commons Attribution 4.0 International License.