A real-time operating system, or RTOS, is a deterministic and fast operating system that is used in IoT and embedded applications. An RTOS is very small and highly suitable for use in microcontrollers. The main purpose of an RTOS is to facilitate multithreading to enable the separation of software functionality into multiple programs known as tasks. It rapidly switches executing tasks to create the illusion of parallel execution. To enable deterministic real-time behaviour, an RTOS offers developers total control over multithreading.
Althoughan RTOS offers numerous benefits, it comes with its unique set of challenges.
As noted above, an RTOS is a special software component that controls program execution to offer a new level of abstraction in the form of tasks. Therefore, the control flow of a program is never apparent from its source code when using an RTOS. This is because the RTOS determines the task to be executed at any given time. Though this can be an advantage because it facilitates higher production through higher abstraction, you are left with less control over a product’s finer details.
Therefore, an RTOS is not a solution in itself. Developers must determine how RTOS-commanded tasks will interact and share data using the available RTOS services. Additionally, they must determine crucial RTOS parameters like task urgency that are not immediately obvious. Even when the codeis written as per the best RTOS design practices, some third-party or in-house components operating in the same RTOS environment may fail to adhere to the set out principles.
The main challenge of using RTOS-based designs is that its tasks do not operate as isolated entities. There is always some form of dependency between the tasks, like shared processor time. When the fixed priority pre-emptive feature is in use, high priority tasks can take over execution at any point. This delays the execution of low priority tasks that must wait until all the high priority tasks are executed successfully. Some types of shred resources like hardware peripherals and global data may cause dependencies between tasks since synchronization blocks tasks from executing effectively when desired. This can cause unpredictable system delays if not designed accordingly.
A classic RTOS challenge known as priority inversion occurs when high priority tasks try to access a shared resource like a communication interface that is being used by a low priority task. The high priority task is blocked until the low priority task returns the shared communication interface or resource. Priority inversion occurs when a medium priority task attempts to pre-empt the low priority task at this point. The high priority task is blocked due to the unrelated task that pops up with a low scheduling priority.
Task dependencies like shared resources and scheduling are affected by input timing and execution timing. The timing properties vary based on system situation and state and are not particularly visible in the source code. This makes it almost impossible to determine the real-time behavior of an RTOS-based system from its source code.
In spite of these challenges, real-time operating systems deliver a wide range of benefits in microcontrollers and beyond. Learn more about our real-time operating system vision here.