Download as pdf or txt
Download as pdf or txt
You are on page 1of 63

Unit – 2

Design of Embedded System


Design
• The validated system specifications
document has to be converted into design
• We need to carry out a paper design for
both hardware and software.
Design Tradeoffs
• Design Stage we need to select processor
and OS, etc.,
Design Goals are
Co-Design
Partitioning the system into hardware and software
is known as co-design.

▪ Speed of Execution:
▪ Flexibility of making changes:
▪ Size of the System:
▪ Power consumption:
▪ Memory:
▪ Cost:
Hardware Design
It Involves
Selection of Processor
Processor selection is the most critical in hardware design
Processor will be Micro controller, Microprocessor or
Digital Signal Processor (DSP).

▪ Performance requirements of the processor: Speed,


MIPS, Clock frequency, Registers and internal memory,
etc.,
▪ Cost of the processor:

▪ Development tools:

▪ Special requirements:

▪ RTOS support:

▪ Technical support from the vendor:

▪ Availability of people with the expertise on a specific


processor:
Software Design
• For small embedded systems, there will be no
need for an OS and hence we can write our own
software routines for task management, I/O
management and memory management and
integrate your application software with these
routines.

• For complex embedded system, an embedded


real time OS will make the development faster
Software design involves
• Working out the details of the processing to be done by
the embedded system
• Decomposition of the processing into different tasks.
• Calculation of the processing time and the resources
required for each task.
• Deciding on the use of an embedded OS.
• Studying the need for support for communication
protocols stack.
• Study the need for embedding the HTTP server software
• Study the need for field up gradation of the software.
Selection of OS
• Optimized kernel for the chosen processor
• Support for languages
• Support for POSIX function calls
• Footprint
• Software component
• Source code/Object code
• Licensing fee
Implementation
Hardware implementation involves

– Developing the circuit schematics


– Obtaining the PCBs
– Procuring the components
– Assembling the components and testing the
individual modules on the populated PCB.
– Testing the complete hardware
Integration and Testing
Testing is the most difficult and time consuming process.

The objective of testing is to find many defects as possible.

The defects should be minimized before delivering the


product to the customer.

The project team needs to assign sufficient time for testing


the embedded system not only for its performance
characteristics but also for checking its reliability.

What is testing?
• Testing is the process to prove that the system
works correctly,

• Testing is the process to prove that the software


does not work correctly.

• Testing is the process to reduce the risk


associated with the residual defects.
Types of Testing

• Black box testing


• White box testing
• Performance testing
• Gorilla testing
• Field trial
• Acceptance testing
• Regression testing
• Environmental testing
Black box testing
The functionality of the product is tested. The system
is considered as a black box the implementation details are
not considered at all. By applying inputs outputs are tested.
White box Testing
Implementation details are considered while testing
the system. Each and every line of code is tested. Condition
based testing is done( if else )
Performance Testing
Check whether the system is meeting the time
constraints as per the requirements. Particularly for hard real
time systems a rigorous testing has to be done to ensure that
deadlines are not missed at all.
Gorilla Testing
It will randomly press some buttons on the keypad or
switch on/off the system power supply. By applying random
inputs system is tested.
Field Trial
If your system has to work in mission critical applications
or when safety is a major concern you need to conduct the field
trial in extremely controlled conditions. The system has to test in
actual field.
Acceptance Testing
When you are satisfying that the system is working as
per the requirements of the client. The client will test the system
by operating it.
Regression Testing
To ensure that modifications to one portion of the code
have no ill effects on other parts of the code. Using a set of test
cases regression testing has to be done every time changes are
made to the source code.
Environmental Testing
Types of Hardware Platforms

• Single Board Computers


• PC add on cards
• Custom Built hardware platforms
Single Board Computers
Is built around a 32 bit or 64 bit processor with all the
peripherals integrated into a single printed circuit board. For
industrial use the SBC is housed in a 19 inch rack mountable
cabinet.
PC Add on cards
The PC add on cards are plugged into the motherboard
of a PC. In many process control applications these PC add on
cards are used for data acquisition. These cards use different
types of buses for communication with the processor board.
ISA Bus
PCI Bus
Computer PCI Bus
• Virtual Instrumentation
• Interactive Voice Response
• Software Defined Radio
• Telephone tapping system
Custom Built Hardware Platforms
It is used when the application demands
design of a processor based system as per the
customer requirements.
ATMEL 89C51 Microcontroller
AVR ATmega 128 Microcontroller

Types of Hardware Platforms:


89C51 Microcontroller board
AVR Microcontroller board
Arduino Board
Raspberry pi Board, Intel Galileo, etc.,
89C51 Microcontroller Development Board
AVR Microcontroller Development Board
Features
ATmega 128 development Board
Introduction in RTOS
The main responsibility of an operating system is to manage hardware
resources and activities in the system: scheduling application
programs, writing files to disk, sending data across a network, and so
on.
When the OS must handle multiple events concurrently and ensure that
the system responds to those events within predictable time limits, it is
called a real-time operating system, or RTOS.
A Real Time Operating System (RTOS) is an operating system(OS)
intended to serve real-time applications that process data as it comes
in, typically without any delays.
Processing must be done within the defined time constraints or the
system will fail.
A Real Time Operating System is multitasking operating system for
applications, which require that system tasks and functions execute
with real-time constraints.
The system controls the execution of all functions such that
time deadlines are met.
• It responds to inputs immediately(Real Time)
• Here the task is completed within a specified time.
• In real life situations like controlling traffic signal or a nuclear
reactor or an aircraft.
• The operating system has to respond quickly.
• The RTOS act as a bridge between hardware and application
S/W.
• Commonly used real-time operating systems are, QNX
Neutrino, VxWorks, Micro C/OS-II, RT LynxOS, and OS-9.

Real-time operating systems are the only practical solution for


use in embedded systems, especially were multiple control
loops are required to behave predictably under controlled
priority levels.
Why use an RTOS?
Here are important reasons for using RTOS:

• It offers priority-based scheduling, which allows you to separate analytical


processing from non-critical processing.

• The Real time OS provides API functions that allow cleaner and smaller
application code.

• An RTOS is event-driven with no time wastage on processing time for the


event which is not occur

• RTOS offers modular task-based development, which allows modular task-


based testing.

• The task-based API encourages modular development as a task, will


typically have a clearly defined role. It allows designers/teams to work
independently on their parts of the project.
Components of RTOS
The Scheduler: This component of RTOS tells that in which order, the tasks can be
executed which is generally based on the priority.

Symmetric Multiprocessing (SMP): It is several multiple different tasks that can


be handled by the RTOS so that parallel processing can be done.

Function Library: It is an important element of RTOS that acts as an interface


that helps you to connect kernel and application code. This application allows you
to send the requests to the Kernel using a function library so that the application
can give the desired results.

Memory Management: this element is needed in the system to allocate memory


to every program, which is the most important element of the RTOS.

Fast dispatch latency: It is an interval between the termination of the task that
can be identified by the OS and the actual time taken by the thread, which is in the
ready queue, that has started processing.

User-defined data objects and classes: RTOS system makes use of


programming languages like C or C++, which should be organized according to
their operation.
Types of RTOS
• Three types of RTOS systems are:
• Hard Real Time :
• In Hard RTOS, the deadline is handled very strictly which means
that 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.
• Firm Real time:
• These type of RTOS also need to follow the deadlines. However,
missing a deadline may not have big impact but could cause
undesired affects, like a huge reduction in quality of a product.
• Example: Various types of Multimedia applications.
• Soft Real Time:
• 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,
deadlines are handled softly by this type of RTOS.
• Example: Online Transaction system and Livestock price quotation
System.
Features of RTOS

• Occupy very less memory

• Consume fewer resources

• Response times are highly predictable

• Unpredictable environment

• The Kernel saves the state of the interrupted task and then determines
which task it should run next.

• The Kernel restores the state of the task and passes control of the CPU
for that task.
Factors for selecting an RTOS
Here, are essential factors that you need to consider for selecting RTOS:

• Performance: Performance is the most important factor required to be


considered while selecting for a RTOS.

• Middleware: if there is no middleware support in Real time operating system,


then the issue of time-taken integration of processes occurs.

• Error-free: RTOS systems are error-free. Therefore, there is no chance of


getting an error while performing the task.

• Embedded system usage: Programs of RTOS are of small size. So we


widely use RTOS for embedded systems.

• Maximum Consumption: we can achieve maximum Consumption with the


help of RTOS.

• Task shifting: Shifting time of the tasks is very less.


• Unique features: A good RTS should be capable, and it has some extra
features like how it operates to execute a command, efficient protection of the
memory of the system, etc.
• 24/7 performance: RTOS is ideal for those applications which require to run
Difference between in GPOS and RTOS
General-Purpose Operating System (GPOS) Real-Time Operating System (RTOS)

It used for desktop PC and laptop. It is only applied to the embedded application.

Process-based Scheduling. Time-based scheduling used like round-robin


scheduling.

Interrupt latency is not considered as important as Interrupt lag is minimal, which is measured in a
in RTOS. few microseconds.

No priority inversion mechanism is present in the The priority inversion mechanism is current. So it
system. can not modify by the system.

Kernel's operation may or may not be preempted. Kernel's operation can be preempted.

Priority inversion remain unnoticed No predictability guarantees


Applications of Real Time Operating System

• Airlines reservation system.


• Air traffic control system.
• Systems that provide immediate updating.
• Used in any system that provides up to date and minute information
on stock prices.
• Defense application systems like RADAR.
• Networked Multimedia Systems
• Command Control Systems
• Internet Telephony
• Anti-lock Brake Systems
• Heart Pacemaker
Functions of RTOS
• Task Management
• Scheduling
• Resource Allocation
• Interrupt Handling

Task Management
* Real Time Applications the process is called as
Task which takes execution time and occupies
memory.
* Task management is the process of managing
task through its life cycle.
Task
• No of Tasks
• Resource Requirements
• Release Time
• Execution Time
• Deadlines
Resource Allocation
• Weighted Round Robin
• Priority Based
Interrupt
An interrupt is a signal from a device attached to
a computer or from a program with in a computer that
causes the main program that is operating system to
stop and figure out what to do next.
Examples of Real Time System
• Plant control
• Control of production processes / industrial automation
• Railway switching systems
• Automotive applications
• Flight control systems
• Environmental acquisition and monitoring
• Telecommunication systems
• Robotics
• Military systems
• Space missions
• Household appliances.
Architecture of the Kernel
• The embedded software consists of the
Operating System and the application
software.
• The services provided by the operating
system are accessed through Application
Programming Interface(API) to develop
application software.
• The API is a set of function calls using which
you can access the various kernel objects and
the service provided by the kernel.
The Various Kernel Objects are
• Task
• Task Scheduling
• Interrupt Service Routines
• Semaphores
• Mutexes
• Mailboxes
• Message queues
• Pipes
• Event Registers
• Signals
• Timers
The Kernel provides various services through
operations on the kernel objects.

These services are


• Memory Management
• Device Management
• Interrupt Handling
• Time Management
Tasks and Task Scheduler
• The Embedded software consists of a number
of tasks.
• These tasks include the OS tasks and
Application specific task.
• Each task in ES is implemented as an infinite
loop.
• The task objects consist of Name, unique ID,
priority, stack and task control block.
• In addition to the tasks required for the
application software, the kernel has its own
system tasks with priorities.
• Startup task: Which is executed when the
operating system starts.
• Exception handling task: to handle the
exceptions.
• Logging task: log the various system messages.
• Idle task : Which will have lowest priority and will
run when there is no other task to run.

One CPU has to handle multiple tasks, the tasks


have to share the CPU time in a disciplined manner
so that one task does not get lot of time while
others are waiting forever.
Therefore, each task has to assign a priority.
Task Scheduling
• Each task has to be assigned a priority
mechanism for deciding which task will get CPU
time next has to be worked out. This is known
as task scheduling.
• The object that does task scheduling is the task
scheduler.
• The task have to share the system resources
such as CPU registers, external memory and I/O
devices.
• The important requirement is that one task
should not corrupt the data of another task.
While scheduling Task no of Issues are

Many tasks may make calls to a function.

• A function that can be used by more than one task without


data corruption is called reentrant function.

• If data is corrupted when more than one task calls the


function such a function is called non reentrant function.

• Every task requires resources such as serial port, keyboard,


display or memory locations.

• The resources shared by two or more tasks are called as


shared resources.
Task States
Task can be in one of the following 3 states
• Running
• Waiting
• Ready to Run
Running State:
A task is said to be in running state If it is being
executed by the CPU.
Waiting State:
If it is waiting for another event to occur. Waiting
state cannot be executed till the external event
occurs.
Ready to Run State:
If it is waiting in a queue for the CPU time.
For Instance consider an embedded system that
obtains data from a serial port and converts the
data into Ethernet packets.

Task 1: reads the data from serial port another


task (task2) keeps converting the serial data
(Character) into packets and put them into buffer.

Another Task (Task3) read data from buffer and


sends it over an ethernet interface.

Task2 has to wait for Task1 to complete its work


and then inform task3 can do its work.
Task Stack:
Every task will have a stack that stores the local
variables, function parameters, return address
and CPU registers during an interrupt.

Context Switching:
The state of the CPU registers when a task has to
be preempted is called the context. Saving the
contents of the CPU registers and loading the new
task parameters is called context switching (High
Priority to low priority).
Scheduling Algorithms
• How does the kernel decide which task has to run? Various scheduling
algorithms have been developed to tackle this problem.
• Depending on the requirement of the ES, the scheduling algorithms are
selected.
Real-Time Scheduling Algorithms
Static vs. Dynamic
 Static Scheduling:
 This algorithm assigns priorities to tasks based on their periods: the
shorter the period, the higher the priority.

 All scheduling decisions at compile time.


 Temporal task structure is fixed.
 Priority and mutual exclusion satisfied by the schedule
(implicit synchronization).
 One solution is sufficient.
 Any solution is a sufficient for schedulable test.
 Benefits
 Simplicity
Static vs. Dynamic
• Dynamic Scheduling:
• Dynamic-priority algorithm assigns different priorities to the
individual jobs in each task.

• Hence the priority of the task with respect to that of the other tasks
changes as jobs are released and completed.
– All scheduling decisions at run time.
• Based upon set of ready tasks.
• Mutual exclusion and synchronization enforced by clear
synchronization concepts.
– Benefits
• Flexibility.
• Only actually used resources are claimed.
– Disadvantages
• Guarantees difficult to support
• Computational resources required for scheduling
 Static Scheduling:

Shortest Job first algorithm


Dynamic Scheduling:
Preemptive vs. Non preemptive
• Preemptive Scheduling:
– In preemptive multitasking, the highest priority task is always executed by
the CPU, All real time operating system implement this scheduling
algorithm.
– It is an Event driven.
• Each event causes interruption of running tasks.
• Choice of running tasks reconsidered after each interruption.
– Benefits:
• Can minimize response time to events.
– Disadvantages:
• Requires considerable computational resources for scheduling
Preemptive vs. Non preemptive
• Non preemptive Scheduling:
– Non-preemptive multitasking also called cooperative multitasking as
the task have to cooperate with one another to share the CPU time.
– Tasks remain active till completion
• Scheduling decisions made only after task completion.
– Benefits:
• Reasonable when task execution times ~= task switching times.
• Less computational resources needed for scheduling
– Disadvantages:
• Can leads to starvation (not met the deadline) especially for those
real time tasks ( or high priority tasks).
Rate Monotonic scheduling
• Priority assignment based on rates of tasks
• Higher rate task assigned higher priority
• Schedulable utilization = 0.693 (Liu and Leyland)

Where Ci is the computation time, and Ti is the release period

• If U < 0.693, schedulability is guaranteed


• Tasks may be schedulable even if U > 0.693
RM example

Execution
Process Period
Time
P1 1 8
P2 2 5
P3 2 10

The utilization will be:

The theoretical limit for processes, under which we can conclude that
the system is schedulable is:

Since the system is schedulable!


Deadline Monotonic scheduling
• Priority assignment based on relative deadlines of tasks
• Shorter the relative deadline, higher the priority
Earliest Deadline First (EDF)
• Earliest deadline first (EDF) is dynamic priority scheduling algorithm for
real time embedded systems.

• Earliest deadline first selects a task according to its deadline such that a
task with earliest deadline has higher priority than others.

• It means priority of a task is inversely proportional to its absolute deadline.

• Since absolute deadline of a task depends on the current instant of time so


every instant is a scheduling event in EDF as deadline of task changes
with time.

• A task which has a higher priority due to earliest deadline at one instant it
may have low priority at next instant due to early deadline of another task.

• EDF typically executes in preemptive mode i.e. currently executing task is


preempted whenever another task with earliest deadline becomes active.
Example of EARLIEST DEADLINE FIRST (EDF) SCHEDULING
ALGORITHM

Release Execution Deadline Time


Task
time(ri) Time(Ci) (Di) Period(Ti)
T1 0 1 4 4
T2 0 2 6 6
T3 0 3 8 8

U= 1/4 +2/6 +3/8 = 0.25 + 0.333 +0.375 = 0.95 = 95%

As processor utilization is less than 1 or 100% so task set is surely schedulable by


EDF.
• At t=0 all the tasks are released, but priorities are decided according to their absolute deadlines so
T1 has higher priority as its deadline is 4 earlier than T2 whose deadline is 6 and T3 whose
deadline is 8, that’s why it executes first.

• At t=1 again absolute deadlines are compared and T2 has shorter deadline so it executes and
after that T3 starts execution but at t=4 T1 comes in the system and deadlines are compared, at
this instant both T1 and T3 has same deadlines so ties are broken randomly so we continue to
execute T3.

• At t=6 T2 is released, now deadline of T1 is earliest than T2 so it starts execution and after that T2
begins to execute. At t=8 again T1 and T2 have same deadlines i.e. t=16, so ties are broken
randomly an T2 continues its execution and then T1 completes. Now at t=12 T1 and T2 come in
the system simultaneously so by comparing absolute deadlines, T1 and T2 has same deadlines
therefore ties broken randomly and we continue to execute T3.

• At t=13 T1 begins it execution and ends at t=14. Now T2 is the only task in the system so it
completes it execution.

• At t=16 T1 and T2 are released together, priorities are decided according to absolute deadlines so
T1 execute first as its deadline is t=20 and T3’s deadline is t=24.After T1 completion T3 starts and
reaches at t=17 where T2 comes in the system now by deadline comparison both have same
deadline t=24 so ties broken randomly ant we T continue to execute T3.

• At t=20 both T1 and T2 are in the system and both have same deadline t=24 so again ties broken
randomly and T2 executes. After that T1 completes it execution. In the same way system continue
to run without any problem by following EDF algorithm.
Advantages of EDF over rate monotonic:

• No need to define priorities offline


• It has less context switching than rate monotonic
• It utilize the processor maximum up to 100% utilization factor as
compared to rate monotonic

Disadvantages of EDF over rate monotonic:

• It is less predictable. Because response time of tasks are variable


and response time of tasks are constant in case of rate monotonic or
fixed priority algorithm.
• EDF provided less control over the execution
• It has high overheads

You might also like