Featured post

Arduino FreeRTOS Mutex Examples

In this section, we will explain using an example to demonstrate mutexes in Arduino using freeRTOSThere are two freeRTOS Mutex examples in this tutorial, the first example demands some hardware (LCD) While the second does not need any hardware, you can try out both if you have the resources.

In the last tutorial, we considered in detail: semaphores and mutexes and we also established the difference between binary semaphores and mutexes.
Just for a review:Recall that a mutex is a locking mechanism that implements the take and gives functionality in itself, unlike a binary semaphore. See this tutorial if you have not before continuing.
Example 1: Protecting the LCD Resource Using Mutex in freeRTOS
Program Description

In this program, we Demonstrated the use a 16x2 LCD display to implement a mutex.

The LiquidCrystal library works with all LCD displays that are compatible with the Hitachi HD44780 driver. you can usually tell them by their 16-pin interface.


* LCD RS pin to digital…

Understanding Real Time Operating Systems [R.T.O.S]

It is very important for computer science students and electronic and computer engineers to understand real time operating systems. In this post, a solid background of RTOS will be established and you will be able to understand the basics and features of a real time OS.

Real time operating systems sounds strange at a glance, you can immediately suggest that it is an operating system that responds in real time. In an RTOS, tasks are given a deadline to complete, missing a deadline can cause undesired to catastrophic damages.

How then is it different from a General Purpose Operating system?

Where are they applied?

What features makes a given Operating system an RTOS?

Is there a way I can implement RTOS in my project if yes, how?

In this article, I will endeavor to answer all the questions listed above. If you would like to go through the history of RTOS, Wikipedia presents a good summary here.

What is an RTOS?

Let’s define an Operating system first.

An operating system is a system program that manages the computer hardware and acts as an intermediary between the user of a computer and computer hardware. It provides process abstraction for multitasking/concurrency and an environment in which a user can execute programs in a convenient and efficient manner and also allocates resources and services, such as memory, processors, devices and information to tasks.

In summary, an Operating System is a system program that provides an interface between hardware and application programs.

An RTOS is a combination of two words: “Real Time” and “Operating System

  • Real-Time indicates an expectant response or reaction to an event on the instant of its evolution.

  • Operating System is a system program that provides an interface between hardware and application programs.

  • RTOS is, therefore, an operating system that supports real-time applications and performs its operation and gets the result within the deadline required.

Note: A task is a thread of execution or simply a function. The combination of tasks forms an application.

Application / Use cases of RTOS

RTOS is applied in virtually all embedded systems. it is mainly used in time-constrained applications were the phenomenon "hanging" should not exist, imagine a flight control system not responding to commands because the system is "hanging" or frozen? You can imagine the catastrophic effects that will follow.

The following are examples of use cases for the Real-time Operating system.

  1. Microwave cookers

  2. Embedded systems,

  3. Industrial robots

  4. Flight Control systems

  5. Missile Launchers

Classification of RTOS.

Do not get confused by the wide applications of RTOS in the world today, there are actually two (hard rtos and soft RTOS) and blurry three divisions of RTOS

  • Hard RTOS: the degree of tolerance for missed deadlines is extremely small or zero. A missed deadline has catastrophic results for the system

  • Firm RTOS: missing a deadline might result in an unacceptable quality reduction

  • Soft RTOS: deadlines may be missed and can be recovered from. Reduction in system quality is acceptable

What are the features of an RTOS

When you see the following features been exhibited by an operating system, then you are actually dealing an RTOS.

  • Preemptibility of the Kernel: Supports multiple tasks in real-time applications and able to preempt any task in the system and allocate the resource to the task that needs it most even at peak load. The implementation of this arises from the fact that the Kernel is given the highest priority in the Interrupt Vector Table.

  • Task Priority: In RTOS, tasks have priority, the RTOS Identifies a task that needs a resource the most and allocates control to obtain the resource

  • Reliable & Sufficient Inter-Task Communication Mechanism: For multiple tasks to communicate in a timely manner and to ensure data integrity among each other.

  • Priority Inheritance: Allow applications with stringent priority requirements to be implemented.

  • Predefined Short Latencies: The time it takes from switching from a task into another task is very short.

  • Control of Memory Management: Provides ways for the task to lock its code and data into real memory

Differences between a General Purpose Operating system (GPOS) and a Real Time Operating System (RTOS)

The difference between an RTOS and a GPOS lies on some features and functions.

  1. Real Time: An RTOS is constrained and designed to perform tasks in real time while a GPOS has no such ability.

  2. Deterministic: An RTOS is deterministic, you can predict its performance but you cannot do so for a GPOS. For instance, you cannot accurately predict how long it will take to copy a file of 3Gb from a hard disk to a flash drive in a GPOS.

  3. Deadlines: GPOS do not have deadlines attached to processes and tasks, however, this is not so for RTOS, there are strict deadlines that must not be missed depending on the type of RTOS Hard, firm and soft )

  4. Preemptive Scheduling: The application programmer can decide which task could preempt another, in GPOS this is not done.

  5. Latency: An RTOS has predefined short latency while a GPOS has undefined latency.

  6. Jitter: Timing error or jitter is not accepted in rtos, while in GPOS, it may not mean much

  7. Priority Inversion is supported in RTOS but not integrated into GPOS.

Real Time Kernel: Heart of RTOS

The concept of an RTOS is centered on the real-time Kernel, the real-time Kernel is a software that forms the heart of the  RTOS, the program has the highest priority and cannot be masked, due to its functions in an rtos, it runs continuously.

The basic functions of an RTOS Kernel include the following:

  1. Task Management: This has to do with deciding which tasks should be run, the sequence and order of execution. The real-time kernel manages tasks by task scheduling which may be pre-emptive or cooperative, task prioritizing, task execution, etc.

  2. Inter-task communication and Synchronization: It ensures tasks are able to communicate with each other seamlessly, send and receive data from each other. The real-time kernel ensures that information is not corrupted in the process through synchronization, also through handling or managing resource usage and allocation.

  3. Memory Allocation Functions: the kernel provides a platform for the programmer to dynamically allocate slots of RAM in his application, thus memory usage can be dynamically controlled to meet the task requirements.

  4. Device I/O Functions: The real-time kernel controls and organizes the access to hardware resources, device drivers and other I/O systems. Usually, it provides a platform for add-ons to extend its functions to advanced I/O which includes file systems, networking, graphics, database management, POSIX Support, Debugging Facilities, etc

States of a task

We have mentioned tasks more frequently in this post, now let us look at the states which a task can be in at any point in time. Recall a task is a thread of execution, functions that make up the application.

Generally, a task can be in two broad states: Running or not running state.


In the running state, the task is actively using CPU resources It will run until its execution time elapses or it returns a data that is needed by another task or it is preempted by a higher priority task.


Tasks in this state are currently not running i.e. not actively being executed by the OS, The not-running state can be further divided into:

  • Blocked State: A task is sent to the blocked state if it needs an input which is currently not available, or awaiting a parameter or an event to occur like keyboard input.

  • Ready State: A task in the ready state has been created and ready to run, this implies that it has all it needs to be in the running state.

  • Idle State: In this state, the task has already been created with its defined memory allocation. In RTOS, tasks should have deadlines, memory allocations, priority (optional) etc. A task remains Idle until been called upon or until it is queued for execution.


Popular posts from this blog

Arduino FreeRTOS Tutorial 05: Binary Semaphores and Mutexes

Arduino FreeRTOS Beginner Tutorial: Task Creation, Scheduling, Deleting

Digital Systems and Stability Analysis using Jury's Stability Test