Real-Time Operating System (RTOS)
A real-time operating system (RTOS) is an operating system with two key features: predictability and determinism. In an RTOS, repeated tasks are performed within a tight time boundary, while in a general-purpose OS, this is not necessarily so.
- It permits critical threads to run within strict timing parameters.
- Important when dealing with safety-critical applications, as even a few milliseconds of lost time can result in a system failing catastrophically.
https://uwarg-docs.atlassian.net/wiki/spaces/ZP/pages/2030862337/RTOS+-+WIP
https://www.youtube.com/watch?app=desktop&v=kP-pP6FEu8I
At UWaterloo, there’s MTE241 https://ece.uwaterloo.ca/~dwharder/icsrts/Lecture_materials/
- Their own textbook: https://ece.uwaterloo.ca/~dwharder/icsrts/Lecture_materials/A_practical_introduction_to_real-time_systems_for_undergraduate_engineering_print_spring_2018.pdf
Characteristics of Real-Time Operating Systems Real-time operating systems can be characterized as having unique requirements in five general areas [MORG92]:
- Determinism
- Responsiveness
- User control
- Reliability
- Fail-soft operation
the main difference
At the core of it, the main difference with an RTOS lies in the Scheduler, which decides what task to run at a given time:
- A regular OS (Linux, Windows) uses Round Robin to time slice, there’s no concept of deadlines
- On the other hand, with an RTOS, you can specify the timing requirements of a task, i.e. a deadline, and how often something should run. The scheduler makes sure to meet those, and preempts when necessary
In a regular OS, certain parts of the kernel cannot be Preempted
RTOS != guaranteed improved performance
Let’s say you write a super bloated program that takes 100ms to run, but you tell RTOS that this program runs every 50ms.
The RTOS will attempt to schedule it accordingly. However, this creates a conflict because the task can’t finish its execution within the allocated time. This leads to missed deadlines, and system failures.
With a regular OS, you might notice this, but because there is no deadlines, this degradation is not so obvious. The system still thinks it’s correct.
How are tasks specified in RTOS?
- Through deadlines and priorities.
These are fed into the scheduler.See Real-Time Scheduling. Priorities help the system decide which task to execute first in scenarios where multiple tasks are ready to execute simultaneously.
Reflection
FreeRTOS
RTOS = Real-time operating system
Different OS: Windows, MacOS, iOS, Android are all operating systems
STM32 is a microcontroller just like the atmega328p.
However, STM32 is much more powerful, and the esp32 is even more powerful.
For my entire life, I’ve been pretty much just coding with an Arduino, which was enough for most things. I coded it directly on the Arduino IDE, and it just used a giant “Super Loop”, and ran all of the code in it.
However, as things get more complex and where you need concurrent programming (i.e. several things are happening at the same time, this is no longer viable. Instead, we can use RTOS.
Super Loop
- These basic tasks include reading sensors
- Incredibly easy to implement and little overhead
- For vast projects, this type of program flow is great
- saves on CPU cycles and memory
- ISR (Interrupt service routine) can interrupt things
Cons:
- We might be experiencing lag if for example task 1 takes too long
RTOS
- Multi-core, have several tasks run in parallel
- RTOS Can divide up tasks knowing that they can run concurrently
ROS realtime: Resources