Final RTOS
Final RTOS
RTOS is one of OS in embedded system that manages and schedule pheriperial devices on the
working condition. This operating system is selected because of different mechanisms. One of
this is low power to prevent multiple programs to be run. The second one is features such as
scalability, manageability, reliability and so on. RTOS applicable in many areas of the world like
radar and aircraft also uses network operating system. Embedded operating system has its own
kernel that control and schedule the activities of the device what, when, how to do.
i|Page
Contents
Abstract ............................................................................................................................................ i
Introduction ..................................................................................................................................... 1
1.1 Types of RTOS................................................................................................................. 2
1.1.1 Hard Real Time ......................................................................................................... 2
1.1.2 Soft Real Time .......................................................................................................... 2
1.1.3 Firm real time ............................................................................................................ 2
1.2 RTOS Architecture ........................................................................................................... 2
1.2.1. Kernel ........................................................................................................................ 3
1.3 RTOS Scheduling Algorithms ......................................................................................... 4
1.3.1. Scheduling types ....................................................................................................... 5
1.4 Requirements of RTOS .................................................................................................... 8
1.5 Necessity of real time operating system for embedded.................................................... 8
1.6 Parameters of real time operating systems ....................................................................... 9
1.6.1 Inter Task Communication ....................................................................................... 9
1.6.2 Context Switching................................................................................................... 11
1.6.3 Interrupt................................................................................................................... 12
1.7 Features of RTOS ........................................................................................................... 12
1.7.1 Reliability................................................................................................................ 12
1.7.2 Predictability ........................................................................................................... 13
1.7.3 Performance ............................................................................................................ 13
1.7.4 Manageability ......................................................................................................... 13
1.7.5 Scalability ............................................................................................................... 13
1.8 Real Time Operating System Services ........................................................................... 13
1.8.1. Memory management services ............................................................................... 13
1.8.2. Timer services ......................................................................................................... 14
1.8.3. Interrupt handling services ...................................................................................... 14
1.8.4. Device I/O management services............................................................................ 14
1.9 Difference between general purpose and real time operating systems .......................... 14
1.10 Advantage of RTOS ....................................................................................................... 15
1.11 Application of RTOS ..................................................................................................... 17
ii | P a g e
1.13. Conclusion .................................................................................................................. 18
Reference ...................................................................................................................................... 19
iii | P a g e
Introduction
OS is a software program that founds intermediate between the user and computer hardware. The
main aim of this system manages all activities of the computer hardware and software
applications. The hardware (HW) must provide suitable ways to ensure the true activities of the
computer system and to control user programs from interrupt of good conditions of the system
[1].
In 1960s James Martin raises coding of real time system issued in parallel with construction of
commercial systems, while in 1965 text code computer systems of real time with the issue
different tasks done by RTOS. Beside of this air defense, telephone switching and others are
availing the bigger real time systems.
Now a days so many challenges avail on embedded system software and hardware. The number
of materials in the present time Internet of Things surrounds washing machine, autonomous
vehicle, sound recorder and image capture, smart home controller et al develops very fast along
with the expand of those devices on the HW and the SW [2]. Currently, SW developers focus
different tools to solve large variety from small to very difficult systems including selective
ASIC parts.
A real-time operating system is one that guarantees maximum response times for functionality
such as responding to interrupts and scheduling. General-purpose OS have average response
times, but they do not have great response times, consequently making them unattractive for hard
real-time systems to do some tasks.
Real Time Operating System (RTOS) is one type of OS that implement to manage the activities
of pheriperial devices and has low power to prevent multiple programs run together [1].the main
concern of this OS to enhance (coordinate) specified activities finished before deadline. Another
objective is that every task completed within specific time intervals. RTOS is an environment
that other applications do their task properly without any interference condition to occur.
In a RTOS, tasks generally have direct access to a common memory space, and the fastest way to
share data with regard to sharing memory. On general operating system, there is any great
response while it takes average response to do tasks. On the other hand, RTOS is that focuses on
great response to do any activities such as scheduling and interrupts.
1|Page
1.1 Types of RTOS
RTOS can be classified in to two parts with the regarded of time constraint on deadline and
result that after deadline it occurs.
In Hard RTOS, the deadline is handled very strictly which means that a given task must start
executing on specified scheduled time and must be completed within the assigned time duration.
Example: Medical critical care system, Aircraft systems, etc.
Soft Real time RTOS, accepts some delays by the Operating system. In this type of RTOS, there
is a deadline assigned for a specific job, but a delay for a small amount of time is acceptable. So,
this type of RTOS handles deadlines softly. Example: Online Transaction system and Livestock
price quotation System.
This real time type causes unacceptable quality reduction when there is missing of deadlines.
RTOS is used on complex design of embedded systems. This OS contains different components
inside. Each component has its own application. Good architecture of RTOS comprise kernel,
networking protocol, stacks and others. However, for simple device it is enough to include kernel
[3].
2|Page
1.2.1. Kernel
The Kernel is small unit of RTOS and part of the operating systems that is responsible for task
management, and inters task communication and synchronization. Specifically, the Real Time
Scheduler is the part of the RTOS kernel that is responsible for deciding which task should be
executing. Depend on the structure of RTOS there is additional tasks as an example managing
protection of programs and multitasking.
Task management allows programmers to design their software as a number of separate chunks
of codes with each handling a distinct goal and deadline. This service encompasses mechanism
like scheduler and dispatcher that creates and maintains task objects.
Task Object
If multiple tasks to be occur at the same time in real time operating system, therefore it must be
responsible to decompose, schedule and sequential program unit known as task. In real-time
context, task is the basic unit of execution and is governed by three time-critical properties;
release time, deadline and execution time.
Release time refers to the point in time from which the task can be executed.
Deadline is the point in time by which the task must complete.
Execution time denotes the time the task takes to execute.
3|Page
i. Idle: it is the starting os the state where the task is happen and assigning of memory.
However, it is not ready and is not schedulable by kernel.
ii. Ready: the state is active and scheduled by the kernel but there is another issue, which is,
consider before running. If there is priority given for the task, it is scheduled to run in
addition to use resources.
iii. Running: in this state, execution of the codes and accessing the system resources will
take place. It will run until it needs some input or wait for an event or until it is
preempted by another higher priority task than this one.
iv. Blocked (waiting) state Execution of task codes suspends after saving the needed
parameters into its context. It needs some IPC (input) or it needs to wait for an event or
wait for higher priority task to block for enabling running after blocking.
1.2.1.2 Multitasking
The term multitasking means that several sequential tasks are processed in parallel. However,
on single processor systems, several tasks cannot run at the same time. Therefore, task switches
must be available.
Most of the time every activity done independent of one another regarding with the
information sharing, while to deliver the result of expected, cooperative work is best solution.
For example, it may be required that a certain task can only continue to run after another task
has completed a certain operation. In such a case, the tasks involved must be synchronized,
i.e., the parallelism of tasks is restricted again. Synchronization can be accomplished using
inter-task communication.
One of the most important advantages of real time operating system is that scheduling.
Scheduling is the way to assign time and sequence for the program, which is processed on
preplanning algorithms. It is avail on another applications in addition to RTOS. This process is
designed and applied by the scheduler.
Variety of algorithms may support RTOS, but the main thing is selection of algorithms applied
first before the activity of execution of application of users stated. The specified algorithm must
always enable to meet the given task.
4|Page
1.3.1. Scheduling types
Many scheduling algorithms can be used for scheduling task execution on a CPU. The algorithm
of scheduling divides preemptive and non-preemptive types.
Task 1 10 50
Task 2 40 50
Task 3 60 40
Let see the above table tasks with their arrival time and execution time. From the given task,
task3 has higher priority than others, second task2 at the last task1 will be complete on execution
time. See detail distribution below.
5|Page
In Fig. 3 we can see that Task 1 is the first to start executing, as it is the first one to arrive (at t =
10 μs ). Task 2 arrives at t = 40μs and since it has a higher priority, the scheduler interrupts the
execution of Task 1 and puts Task 2 into running state. Task 3 which has the highest priority
arrives at t = 60 μs. At this moment Task 2 is interrupted and Task 3 is put into running state. As
it is the highest priority task it runs until it completes at t = 100 μs. Then Task 2 resumes its
operation as the current highest priority task. Task 1 is the last to complete is operation.
i. Priority scheduling
Priority scheduling is one of the most known scheduling algorithms in RTOS. This preemptive
shechuling type applies when concurrency of programs come into execution stage then the
urgent one comes first but the remaining will go back to ready state. The basic principle is that
the task with the highest priority will be given the opportunity to use the CPU.
The other idea in preemptive version of the algorithm, a running task can be stopped if a higher
priority task enters the scheduling queue. Of course, not all tasks can have unique priority levels
and there will always be tasks that have the same priority. Different approaches can be used for
handling the scheduling of those tasks (e.g FCFS scheduling or round robin scheduling).
Round-robin is a preemptive type of scheduling algorithm. There are no priorities assigned to the
tasks. Each task is put into a running state for a fixed predefined time. This time is commonly
referred to as time-slice (aka quantum). In case a task has not completed by the end of its
dedicated time-slice, it is interrupted, so the next task from the scheduling queue can be run in
the following time slice. A pre-emptied task has an opportunity to complete its operation once
it’s again its turn to use a time-slice.
An advantage of this type of scheduling is its simplicity and relatively easy implementation.
In this scheduling algorithm type, the scheduler has no power to enforce the interrupted
programs change into ready state. The solely power is controlling the starting and waiting state
of the execution of the process. If there is voluntary returning between running and urgent
programs simply the scheduler control starting and waiting time.
6|Page
Figure 4:Non-preemptive scheduling
The non-preemptive scheduling can simplify the synchronization of the tasks, but that is at the
cost of increased response times to events. This reduces its practical use in complex real-time
systems.
In first come first served algorithm type there is no permission for urgent issued to execute by
interrupting of the normal execution of program. In general, the selected task that is entered
firstly in the queue and go to in ready state, then it can go to on execution state before the
successor runs ad utilizes the CPU.it is easy to control but greater response time
Shortest job first (SJF) or shortest job next, is a scheduling policy that selects the waiting process
with the smallest execution time to execute next. SJN is a non-preemptive algorithm.
Steps of this algorithm
1. Sort all the process according to the arrival time.
2. Then select that process which has minimum arrival time and minimum Burst time.
3. After completion of process make a pool of process which after till the completion of
previous process and select that process among the pool which is having minimum Burst
time.
Advantage
it has a small amount of average waiting time among all scheduling algorithms.
7|Page
During the running phase of using this algorithm, starvation may happen but it is
solved with the concept of aging.
It is practically infeasible as Operating System may not know burst time and therefore
May not sort them. While it is not possible to predict execution time, several methods
can be used to estimate the execution time for a job, such as a weighted average of
previous execution times. SJF can be used in specialized environments where
accurate estimates of running time are available.
There are many requirements of RTOS. Some of them are the following one.
i. One of the RTOS is that multithreaded and has priority scheduling. Generally it must
be preemptive. e.g. handle multiple threads and be able to preempt tasks if necessary.
ii. A system of priority inheritance must exist. Priority inheritance is a mechanism to
ensure that lower priority tasks cannot disrupts the execution of higher priority tasks.
iii. The OS must support various types of thread/task synchronization mechanisms.
iv. For predictable response:
Every function has its own set time to do the task without any dependency.
Non preempt portions of kernel functions necessary for inter-process
synchronization and communication are highly optimized, short and deterministic
Non-preempt portions of the interrupt handler routines are kept small and
deterministic
Interrupt handlers are scheduled and executed at appropriate priority
The OS mask the maximum time during which interrupts and by device
drivers must be known.
The maximum time that device drivers use to process an interrupt, and specific
IRQ information relating to those device drivers must be known.
The interrupt latency (the time from interrupt to task run) must be predictable and
compatible with application requirements
Embedded systems are continuously increasing their hardware and software complexity moving
to single chip solutions. The RTOS in Embedded System mainly does the following tasks.
8|Page
i. To adjust and integrate processes it requires program control for simplification
ii. Requires guides for interrelating hardware with application programs
iii. Availability of RTOS models is becoming strategic inside hardware/software co-design
environments
So many parameters can be apply regarding to solve or do a given tasks using RTOs in
embedded system devices.
Simple OS has multiple options to translate between a given processors. However, so many
limitations are raised such as message queue, semaphore remote procedure calls, socket et al not
present. While in real time, operating system directly accesses any information from memory
without any third party and distribute in quick way using sharing memory mechanism.
Synchronize and message issued needs to exchange information between a given tasks. When we
come to flags in the communication gives purpose for synchronization of internal actions of
message queue while mailbox give service by sending of texts in between the system. The basic
data utilizer is known as semaphore [4][5].
1.1.1.1 Semaphores
i. Wait
The wait operation decrements the value of its argument S, if it is positive. If S is negative or
zero, then no operation is performed.
Wait(S)
{While (S<=0);
S--;}
9|Page
ii. Signal
signal(S)
{S++;}
Types of Semaphores
There are two main types of semaphores i.e. counting semaphores and binary semaphores.
Details about these are given as follows:
i. Counting Semaphores
It has no boundary to stop value, and give service for coordination of resource access where
unlimited count is number of resource, which is avail. These semaphore type increments when
there is addition of resource while decrement (minimize its number) loss of resource.
1.1.1.2 Mailbox
Mailbox is deployed location that has high power to carry one variable of form ADDR which is
controlled and may be used by many tasks properly. Some of the tasks given by this is write read
et al. If one program is writing to the system but if it is full, any task does not apply on it until it
finishes. Trying to send to a full mailbox or read from an empty one may result in an error or
task suspension, depending on options selected in the API call and the Nucleus SE configuration.
1.1.1.3 Queue
Queues are the primary form of inter task communications. They can be used to send messages
between tasks, and between interrupts and tasks. In most cases, they are used as thread, safe
FIFO (First In First Out) buffers with new data being sent to the back of the queue, although data
can also be sent to the front.
10 | P a g e
Figure 5:process of queue
Writing to and reading from a queue. In this example the queue was created to hold 5 items. If
the data try to enter into the queue RTOS blocks, and the inter task communication waits to hold
that data if the queue holds 5 item’s.
The way that holds information of one process if there if interruption is occur either by
permission or force action, then this information is set into context switch. In simple terms, it is
like loading and unloading the process from running state to ready state.
i. When a high-priority process comes to ready state (i.e. with higher priority than the
running process)
ii. An Interrupt occurs
iii. User and kernel mode switch (It is not necessary though)
iv. Preemptive CPU scheduling used
11 | P a g e
6. Restore the context of the process that was previously running when it is loaded again on the
processor. This is done by loading the previous values of the process control block and
registers.
1.6.3 Interrupt
A signal, which emanated by either HW or SW for the event happens is called interrupt. Interrupt
is happened with so many things like urgent issue is occur, multiple tasks come together, or by
any means if there is priority happen. Whatever it is, interrupt happens the controller breaks the
current execution and restart based on interrupt handler or ISR. ISR tells the processor or
controller what to do when the interrupt occurs. The interrupts can be either hardware interrupts
or software interrupts.
A hardware interrupt is an electronic alerting signal sent to the processor from an external
device, like a disk controller or an external peripheral. For example, when we press a key on the
keyboard or move the mouse, they trigger hardware interrupts, which cause the processor to
read the keystroke or mouse position.
Real time operating system has identifiable needs that express itself by process, procedure to
execute on the environments. Failure to customize means that your production objectives will not
be met or the level of accuracy will be compromised. These five key features are :
1.7.1 Reliability
Any RTOS must be reliable. This means that it operates for a reasonably long time without
human interference. Reliability also means the configuration to enable the system to choose the
12 | P a g e
right or most profitable action for current operations. For example, a system for the telecom or
banking industries needs to consider the cost of terminating or engaging certain actions,
compared to a phone or calculator whose cost is limited to an individual, game, app function, etc.
1.7.2 Predictability
Features of RTOS are predictable of tasks within timeframe in addition to predicted result. This
result is known by procedures and operations. The determination is by targets set during
production or procedural planning.
1.7.3 Performance
To design some device so many pre conditions planed as efficiency cost strength performance
and others. Real-time operating systems are designed to make work easier. Every system must
solve a problem or reduce the workload. As such, the developer should provide a system that is
easily assimilated with existing software and hardware as well as aligned to the goals of the
organization.
1.7.4 Manageability
This means a system whose veracity or bulkiness is manageable. The software and hardware
required to operate the RTOS must be of reasonable size. Technicians should also be easy to find
and orient. The idea is to reduce the cost of implementation.
1.7.5 Scalability
The needs of any production or event environment change with time. This means that a system
may require an upgrade or downgrade. Such provisions must be made during design and
installation of any RTOS.
The kernel manages and allocates the resources for a particular task in RTOS. As tasks cannot
acquire CPU resources all the time, the kernel provides some services like,
If there is any process appended, the memory manager allocates the memory addresses to it by
mapping process address space. Two types of memory management in RTOSs. They are Stack
and Heap
13 | P a g e
i. The allocation of memory for different context such as registers contents, program
counter, etc is done by task control block. This block of memory is known
as Kernel Stack and its management is called Stack management
ii. After the completion of a program initialization, the physical memory of the MCU or
MPU will usually be occupied with program code, program data and system stack.
The remaining physical memory is called Heap. This heap memory is typically used
by the kernel for dynamic memory allocation of data space for tasks. The memory is
divided into fixed size memory blocks, which can be requested by tasks. When a task
finishes using a memory block it must return it to the pool. This process of managing
the heap memory is known as Heap management
In embedded Systems for proper scheduling of system and user tasks there is a need for a
periodical interrupt to keep track of time delays and timeout, these timer services are used for
this proper management. Another timer service provided is in meeting task deadline by
cooperating with task schedulers to determine whether tasks have met or missed their real-time
deadlines.
One of the central tasks of real-time software is the processing of interrupts. As soon as several
tasks run in a program, it is virtually impossible to achieve good response times by polling.
Continuous polling would prevent tasks with lower priorities from running and thus waste
precious CPU time. To avoid this RTOS uses Interrupt, a hardware mechanism to let know the
CPU that an asynchronous event has occurred. The interrupt handler may be thought of as a task
running with a priority higher than all other tasks. While an interrupt handler is active, no other
interrupts with lower priorities can be processed.
In an embedded system there are differ device drive ISRs for each device. Each driver function
of a device calls a separate ISR. The device I/O manager is the software that manages all these in
the RTOS.
1.9 Difference between general purpose and real time operating systems
14 | P a g e
GPOS RPOS
Cannot perform real time tasks Perform real time task
No time controller for dead line Has real time kernel for dead line time
Follow non preemptive Follow preemptive
Has synchronization problem Achieved synchronization in real time kernel
Inter task communication does not apply Apply inter task communication
Latency is avail overcome latency problem
Jitter ,i.e timing error happens There is no timing error
Real time operating system has many guaranties in embedded system to overcome the following
characteristics [4]
To develop any system in baseline with small microcontrollers, increase SW products is the main
concern according to the status to market relating as well as short period of changing way and
ability. The difficulty of programming real time operating system is good tool for managing
programs and to release tasks among designers. So, due to release time operating system any
program that runs once at a time, each one is partition within specified time
Embedded system developed before out of using real time operating system often important for
synchronization base regarded to functions. Since this system bugs and other SW safety issues
specially if there is an interrupt is avail. To overcome the problem occurs real time operating
system is used for synchronization activity properly controlled and the specified task will do
without any disturbance
Most RTOS developers provide control the system resources, like that of memory management,
time management, file management, interfering of program management (interrupt)
15 | P a g e
communication as well as synchronization ways. The features of real time operating system
concern the general part. The designer the SW to deal cleaner program.
With time management functions, software designers can achieve task delay, timer handling or
time-triggered processing without resorting to understanding the underlying hardware
mechanisms. As compared with a small system that does not use any RTOS, achieving time
related features can be tricky, as the software designer needs to understand the underlying
peripherals (such as timers), how to use it, and how to link it with the top-level application code.
16 | P a g e
1.11 Application of RTOS
17 | P a g e
1.13. Conclusion
Generally, RTOS serves on real time application system with differentiate of ideal from critical
analysis.it is more attractive and small in size compare from GPOS and fast in speed.
RTOS has many functions such as scheduling of programs, multiprocessing symmetry, memory
management, fast dispatch latency et al. without any operating system any device could not
active rather passive action is seen.
RTOS system occupies very less memory and consumes fewer resources and its performance is
the most important factor required to be considered during selection of RTOS. It is applied to the
embedded application and important for Airlines reservation system, Air traffic control system,
defense application systems like RADAR, networked Multimedia Systems etc. On the contrary,
it has also drawbacks like concentration on a few task which is known as the biggest con of
RTOS.
18 | P a g e
Reference
[1] M. T. Elsir, P. Sebastian, and Y. V. Voon, “A RTOS for Educational Purposes Abstract :,”
pp. 1–4.
[2] R. M. Gomes and M. Baunach, “A Model-Based Concept for RTOS Portability,” 2018
IEEE/ACS 15th Int. Conf. Comput. Syst. Appl., pp. 1–6, 2018.
[3] O. April and N. E. C. Electronics, “Old Company Name in Catalogs and Other
Documents,” 2010.
[4] S. Tan, “Real-time operating system ( RTOS ) for small ( 16-bit ) microcontroller,” pp.
1007–1011, 2009.
[5] R. Mavrevski, M. Traykov, and I. Trenchev, “Multitasking in embedded system designs,”
Int. J. online Biomed. Eng., vol. 15, no. 9, pp. 44–57, 2019, doi:
10.3991/ijoe.v15i09.10631.
19 | P a g e