Fundamental Concepts
What is a General Purpose Operating System?
An operating system is a computer program that supports a computer’s basic functions, and provides services to other programs (or applications) that run on the computer. The applications provide the functionality that the user of the computer wants or needs.
What is an RTOS?
A Real-Time Operating System (RTOS) is a type of computer operating system designed to be small and deterministic. RTOSes are commonly used in embedded systems such as medical devices and automotive ECUs that need to react to external events within strict time constraints.
Most operating systems appear to allow multiple programs to execute at the same time. This is called multi-tasking. In reality, each processor core can only be running a single thread of execution at any given point in time. A part of the operating system called the scheduler is responsible for deciding which program to run when, and provides the illusion of simultaneous execution by rapidly switching between each program.
The type of an operating system is defined by how the scheduler decides which program to run when. For example, the scheduler used in a multiuser operating system (such as Unix) will ensure each user gets a fair amount of the processing time. As another example, the scheduler in a desktop operating system (such as Windows) will try and ensure the computer remains responsive to its user.
The scheduler in a Real Time Operating System is designed to provide a predictable (normally described as deterministic) execution pattern. This is particularly of interest to embedded systems as embedded systems often have real time requirements. A real time requirement is one that specifies that the embedded system must respond to a certain event within a strictly defined time (the deadline). A guarantee to meet real-time requirements can only be made if the behavior of the operating system’s scheduler can be predicted (and is therefore deterministic).
Traditional small real time schedulers, such as the scheduler used in FreeRTOS, achieve determinism by allowing the user to assign a priority to each thread of execution. The scheduler then uses the priority to know which thread of execution to run next. In FreeRTOS, a thread of execution is called a task.
What is FreeRTOS?
FreeRTOS is a class of RTOS that is designed to be small enough to run on a microcontroller – although its use is not limited to microcontroller applications.
A microcontroller is a small and resource constrained processor that incorporates, on a single chip, the processor itself, read only memory (ROM or Flash) to hold the program to be executed, and the random access memory (RAM) needed by the programs it executes. Typically the program is executed directly from the read only memory.
Microcontrollers are used in deeply embedded applications (those applications where you never actually see the processors themselves, or the software they are running) that normally have a very specific and dedicated job to do. The size constraints, and dedicated end application nature, rarely warrant the use of a full RTOS implementation – or indeed make the use of a full RTOS implementation possible. FreeRTOS therefore provides the core real time scheduling functionality, inter-task communication, timing and synchronisation primitives only. This means it is more accurately described as a real time kernel, or real time executive. Additional functionality, such as a command console interface, or networking stacks, can then be included with add-on components.
Deep dive of some concepts
Kernel
A kernel is the core, privileged component of an operating system (OS) that acts as the primary bridge between a computer’s hardware and software applications. It manages essential system resources, including CPU scheduling, memory allocation, and peripheral devices (I/O). It remains resident in memory, ensuring hardware and software interact efficiently and securely.
FreeRTOS is more accurately described as a real-time kernel or real-time executive because it is a minimalist, lightweight component focused solely on core scheduling, task management, inter-task communication, and synchronization. Unlike full operating systems, it lacks extensive libraries, GUI, or diverse device drivers, designed specifically for constrained embedded systems needing deterministic, timely responses.
Multitasking
The kernel is the core component within an operating system. General purpose operating systems, such as Linux, employ kernels that allow multiple users to access the computer’s processor seemingly simultaneously. These multiple users can each execute multiple programs apparently concurrently.
A conventional single core processor can only execute a single task at a time – but by rapidly switching between tasks a multitasking operating system can make it appear as if each task is executing concurrently.
Each executing program is implemented by one or more threads under control of the operating system. If an operating system can execute multiple threads in this manner it is said to be multitasking. Small RTOSes, like FreeRTOS, normally call threads tasks because they don’t support virtual memory, so there is no distinction between processes and threads.
The use of a multitasking operating system can simplify the design of what would otherwise be a complex software application:
- The multitasking and inter-task communications features of the operating system allow the complex application to be partitioned into a set of smaller and more manageable tasks.
- Complex timing and sequencing details become the responsibility of the RTOS kernel, removing that burden from the application code.
Scheduling
The scheduler is the part of the kernel responsible for deciding which task should be executing at any particular time.
The scheduling policy is the algorithm used by the scheduler to decide which task to execute at any point in time. The policy of a (non real-time) multi-user system will most likely allow each task a “fair” proportion of processor time. The policy used in real-time embedded systems is described later.
A task will only be swapped out if the scheduling algorithm decides to execute a different task. This can happen without the currently executing task being aware of it, such as when the scheduling algorithm responds to an external event or timer expiration. It can also happen if the executing task explicitly calls an API function that results in it yielding, sleeping (also called delaying), or blocking.
If a task yields, the scheduling algorithm could select the same task to execute again. If a task sleeps, it becomes unavailable for selection until the specified delay period elapses. Similarly, if a task blocks, it becomes unavailable for selection until either a specific event occurs (e.g., data arrives on a UART) or a timeout period expires.
The operating system kernel is responsible for managing these task states and transitions, ensuring that the appropriate task is selected for execution at any given time according to the scheduling algorithm and the current state of each task.
Real Time Scheduling
Real-time operating systems (RTOSes) achieve multitasking using these same principles – but their objectives are very different to those of general purpose (non real-time) systems. The different objective is reflected in the scheduling policy. Real-time embedded systems are designed to provide a timely response to real world events. Events occurring in the real world can have deadlines before which the real-time embedded system must respond and the RTOS scheduling policy must ensure these deadlines are met.
To achieve this objective using a small RTOS, such as FreeRTOS, the software engineer must assign a priority to each task. The scheduling policy of the RTOS is then to simply ensure that the highest priority task that is able to execute is the task given processing time. This may optionally include sharing processing time “fairly” between tasks of equal priority if there is more than one task at the same highest priority that are able to run (are not delaying and are not blocked).
This basic form of real-time scheduling isn’t magic – it can’t slow down or speed up time – the application writer must ensure their timing constraints are feasible to meet with their selected task prioritization.
——————————————————————————————————-
Above material mainly comes from:

Leave a Reply