RTOS Tutorial

Posted by

Anyone who start working on embedded system would have probably heard of Real Time operating system AKA. RTOS.  Most of you must be wondering what is this RTOS, what are its application, Do I really need an RTOS to build my embedded system, Through this series of articles I will try to clear some of the common doubts related to RTOS, we will also go through some of the basic concepts of operating system one needs in order to better understand the working of RTOS and at the end we will try to build an OS kernel ourselves.

What is RTOS and what makes an OS real Time

The bookish definition of operating system says that “An operating system is a program that
controls the execution of application program and acts as an interface between applications and the computer hardware.” In that case what makes this kind of operating system Real time? ,,

the Answer is time constraints, to put it in other words the OS we normally use in our computers such as windows, MACos etc. are called GPOS (general Purpose operating systems), they are designed to serve the basic purpose of completing the given task, with no bondage of time, but when it comes to real time system the added parameter while designing one is the time constraint.,.

Task with Deadline

A real time operating system not just have to complete the given task but also have to be ready with the output in a given time period. This time periods are known as Deadlines and this is what makes designing an RTOS complicated. The scheduler in an RTOS is designed to provide a predictable (normally described as Deterministic) execution pattern in time domain.

When we talk about real time system we can classify them in two categories:

1) HARD REAL TIME SYSTEM 

Hard real time systems are purely deterministic in nature , they have a very hard bound when it comes to timing , To understand this let’s take an example of military / defense application, let’s suppose you are designing an missile guidance system which will compute an critical turn the missile is supposed to take ,  let’s say in exactly 10 sec the missile is supposed to make that critical turn , hence the result/output should be generate at exactly 10 TH second , not 9 th not 11 th . A little early or a little delayed output can change the trajectory of the missile. Hence the 10 seconds is the deadline for the given task

2) SOFT REAL TIME SYSTEM

In soft real time system meeting of the deadline is not compulsory for every task i.e. if a task with higher priority is encountered it is served first. That doesn’t mean that the soft real time systems are allowed to miss the deadline all the time.

Why would I ever need an RTOS :

Alright we understood what an RTOS is and what it is designed for. So now where will you
need to use this? OK lets clear that, a RTOS is usually designed for low computationally intensive devices such as a microcontroller which usually have a single core processor, now there are applications where you will require to do multiple task at once for example you are a making a Credit card reader you commonly find at the petrol pumps and grocery stores in that you can see there are multiple task going on at a time. The device has to simultaneously check the internet connection, display the output, check the card details, run an encryption algorithm, and take inputs from the keypads and what not. This is where RTOS helps you out. A RTOS helps you in multitasking. It does so by multiplexing different task in the time domain.

Share the  costly resource

To understand this better let us take an analogy from time-sharing technique which was introduced in the 1960s when computers were still too expensive to be affordable. So the solution was to allow many users to make use of a single CPU by time sharing, a specific amount of time is allocated to each user to access the CPU. This allowed many people to use a single CPU at once. The switching between the users was done in milliseconds this way it almost felt like you have the full control over the CPU. Something similar happens in RTOS here instead on different users there are tasks or Threads. These threads are switched so quickly that it almost feels like the tasks are running simultaneously.

Where is it used now

A general purpose operating system have some extra feature for user interface which requires a lot of disk space and memory to work with, but when it comes to embedded system which are typically designed for some specific purpose this General purpose operating systems becomes an impractical choice and RTOS have a small memory footprint and can run on small memory space making them an ideal choice for our embedded application.

Let us take a look at some applications where RTOS are used:

1) Space Application

RTOS plays a critical role when it comes to space application. A very good example of its use can be seen in Mars Curiosity Rover. It used Micrium uC/OS-II kernel. Which was used to drive an analytical lab called SAM (Sample Analysis at Mars).

The SAM lab was designed to investigate the chemical and isotopic composition of the Martian atmosphere and soil. It conducts a sensitive search for organic compounds and measures the isotopic composition of carbonaceous material extracted from powdered solid surface samples. Galileo and Voyager space probes also have a Custom RTOS running on it.

source : Curosity rover

2) Medical Field

some of the devices used in the medical field which uses RTOS are: infusion pumps, Dialysis machines, Prostheses, Liver perfusion machine, Ventricular Assist Devices, Endoscopes, Hypertension monitors, Defibrillators, Self-monitoring blood glucose and dosing devices etc.

source: Medical 

3) Internet of things

The demands of an increasingly data-driven world mean that your IOT device will require robust and reliable software. For that, you’ll need a real-time operating system (RTOS). A flexible, scalable RTOS can help you increase your return on investment, cut development costs, reduce your time to market and provide modularity that can separate the core kernel from middleware, protocols, and applications.

Source: Internet of things 

4) Industrial applications

In industries there are many applications that uses RTOS to name a few here are some examples: Drilling Equipment, Oil and Gas valves, Power Generation Applications, Actuation Systems, Industrial Control Systems, Radiation Monitoring Equipment, battery Charging Devices.

This are just some of the common application I found on RTOS, there are many more such
application try to find some yourself.

Do i need to write my own RTOS?

So we now know where is RTOS used and when you need to use one. But where will I get one
Do I need to write a scheduler every time I need to implement RTOS in my project?
There are already many open source RTOS available in the Market. That are really easy to use and can be implemented in your Project:

Open Source RTOS

1) eCos

eCos is provided as an open source runtime system supported by the GNU open
source development tools. Currently eCos supports ten different target architectures (ARM,
Hitachi H8300, Intel x86, MIPS, Matsushita AM3x, Motorola 68k, PowerPC, SuperH, SPARC
and NEC V8xx) including many of the popular variants of these architectures and evaluation
boards.

2) uClinux

MMU Less version of Linux. Support ARM, Coldfire etc. processor.

3) FreeRTOS

FreeRTOS.org is a portable, open source, mini Real Time Kernel – a free to
download and royalty free RTOS that can be used in commercial application support 17
architectures.

4) RTAI

The Real Time Application Interface for Linux. It support following architecture x86,
PowerPC, ARM.

5) Coscox 

An embedded real-time multi-task OS especially for ARM Cortex M4, M3 and M0
chipset.

Proprietary RTOS/ Embedded OS

There are also some proprietary RTOS/ embedded OS present in the Market such as:

1) VxWork

Vxwork supports wide range of processor architectures like ARM, PowerPC,
ColdFire, MIPS etc.

2) MicroC/OS2

µC/OS-II, The Real-Time Kernel is a highly portable, ROM-able, very scalable,
pre-emptive real-time, multitasking kernel (RTOS) for microprocessors and microcontrollers.
It support ARM, PowerPC, X86 etc.

3) SafeRtos

Real Time OS for mission critical applications based on the FreeRTOS scheduling
algorithm, certified for IEC61508 SIL3, FDA 510K or DO-178B.

4) ThreadX

ThreadX is Express Logic’s advanced Real-Time Operating System (RTOS) designed
specifically for deeply embedded applications. It support ARM, PowerPC, X86 etc.

5) QNX:

QNX is real time RTOS, which support ARM, MIPS, PowerPC, SH and X86 Processor
family.

In the next article I will try to explain the internals of RTOS and some basic operating system
concepts and what all tools (Hardware and Software) you will need to start writing one yourself so stay tuned…

Author :  Jayvik Desai

Jayvik Desai is a final year student of electronics and communication at Institute Of Technology .  Nirma University  Ahmedabad. His major area of interest include Robotics, embedded systems, Internet Of Things and Computer Vision. He has been a part of Team Nirma Robocon during his initial year at  Nirma university. He has done some projects in embedded systems and robotics as a hobby and project submissions for college. He is also active as a researcher and has been able to convert one of his project on internet of things into a publication.

 

Thanks for reading till end. If you liked it, Please share in your network.

Embedkari Low Cost courses are available at

Shop

You may  find interesting topics at HowTo

Also subscribe  Embedkari for other interesting topics.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.