Real Time Operating System – Basics

Before I started two years back on my first project, I admit that I did not know much about the working of a (real-time) operating system. All the stuff like – counting semaphores, task scheduling, context switches, event control blocks, interrupts and ISR routines, task and time management, and what else and whatnot all seemed a wee bit too much to grasp.

Real Time Operating System - Basics 1

For me, the only thing I could think about when someone said Operating System before was a Windows OS or a Linux OS…and boy was ignorance bliss! As I started to write code for the first embedded system, I realized how naive I have been to think that I could always stick to Windows or a Linux machine and write small software programs and stay afloat.

As it dawned on me that this would not be the case in my new company, I began searching to learn what an RTOS (aka, Real-Time Operating System) could do and how it worked. It took me a while and a lot of effort to finally understand why we actually needed one and what all one could do with one. But I do not regret the time spent learning all that I could find on the topic. Even now, I am still not an expert but at least not as naive and ignorant as before.

So I thought maybe, I should note it all down somewhere, maybe for future reference or just for anyone who wanted a quick feel or glimpse at what a real-time OS was needed for or could do.

Chapter 1. RTOS – Fundamentals

To start, An RTOS is a multitasking operating system intended for real-time applications, which mostly include those which run on embedded systems. The list of embedded systems that we find in our everyday life keeps growing exponentially every year. Nowadays, you find embedded systems everywhere, be it household appliances- like microwaves, dishwashers, office appliances – like fax machines or copiers, computer peripherals – like modems, printers, scanners, or hi-tech stuff like robots, spacecraft, automobiles, research equipment, weapons systems, and whatnot.

The RTOS that I got to work with was called PCOS-II from Micrium. The Basic con

READ MORE :

Acceptors that one has to know about before starting with an RTOS are – Resources A resource simple means any entity, for example, an I/O device like a keyboard, display, printer, or a program defined array, variable, or structure. Tasks A task or a thread, as some may call it, is just a simple piece of program that thinks that it has all the resources and CPU all to itself. A task can typically have any of these states – Running, Dormant, Ready, Waiting. A task is said to be running when it has ccontrolsCPU and can execute its code. A task is said to be ready to execute its code, but its priority is lesser than the currently running task. A task is said to be waiting when it is waiting for the occurrence of an event like an Input/Output operation to complete, or an interrupt to occur, or any resource to become available. A task is dormant when it still resides in the memory and has not been made available to the kernel.

Multi-Tasking Multitasking is the process by which several tasks or threads can run on the same CPU. In fact, better said when a single CPU switches its attention between various tasks in a sequential way enabling someone to think that all the tasks are being run at the same time. Context Switches or Task Switches This is the process by which a kernel shifts its attention to a different task from the one it is currently executing. To enable context switches, the kernel must safely save all the running tasks CPU registers onto the stack and then load all the saved registers of the next task that is waiting to be run. Kernel The Kernel is the central component of the Operating system, and it manages all the tasks. Its main job is to enable the context switches or task switches. Its responsibilities also include managing the various system resources.

  • Schedulers
  • First in First Out
  • Round Robin
  • Shortest Remaining Time
  • Priority Based

The Scheduler is the part of the Kernel responsible for determining which of the current tasks have to be run next. There actually exist two types of priority-based kernels – the preemptive ones and the non-preemptive ones.

Non-preemptive scheduling is also called co-operative multitasking; the tasks actually cooperate to share the CPU and give the illusion that all of them are executing simultaneously. In real, each task works for some time and then gives the CPU control over the other tasks.

The preemptive one always runs the highest priority task, which is ready to run. When a higher priority task becomes ready to run, the current task is pre-emptied ( or suspended), and the CPU control is given away to the new higher priority task. Once the higher priority task has finished execution, the CPU control is transferred back to the earlier task, which was suspended.

Share

Alcohol scholar. Bacon fan. Internetaholic. Beer geek. Thinker. Coffee advocate. Reader. Have a strong interest in consulting about teddy bears in Nigeria. Spent 2001-2004 promoting glue in Pensacola, FL. My current pet project is testing the market for salsa in Las Vegas, NV. In 2008 I was getting to know birdhouses worldwide. Spent 2002-2008 buying and selling easy-bake-ovens in Bethesda, MD. Spent 2002-2009 marketing country music in the financial sector.