Embedded System
Embedded System
DISCLAIMER
3
4
Contents
1.10 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
5
6 CONTENTS
2.11 Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
3 Communication Interface 73
3.5.1 Infrared . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
3.5.2 Bluetooth . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
3.5.3 Wi-Fi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
3.5.4 ZIGBEE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
3.5.5 GPRS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
11
12 CHAPTER 1. INTRODUCTION TO EMBEDDED SYSTEMS
1 Based on Generation
14 CHAPTER 1. INTRODUCTION TO EMBEDDED SYSTEMS
4 Based on Triggering
1 First Generation:
The early embedded systems built around 8-bit
microprocessors like 8085 and Z80 and 4-bit
microcontrollers.
Examples : stepper motor control units, Digital Telephone
Keypads etc.
2 Second Generation:
Embedded Systems built around 16-bit microprocessors and
8 or 16-bit microcontrollers, following the first generation
embedded systems.
Examples : SCADA, Data Acquisition Systems etc.
3 Third Generation:
Embedded Systems built around high performance 16/32 bit
Microprocessors/controllers, Application Specific
Instruction set processors like Digital Signal Processors
(DSPs), and Application Specific Integrated Circuits
(ASICs).The instruction set is complex and powerful.
Examples : Robotics, industrial process control, networking
etc.
4 Fourth Generation:
Embedded Systems built around System on Chips (SoC’s),
Re- configurable processors and multicore processors. It
brings high performance, tight integration and
miniaturization into the embedded device market.
Examples : Smart phone devices, MIDs etc.
1.4. CLASSIFICATION OF EMBEDDED SYSTEMS 15
1 Data Collection/Storage/Representation
2 Data Communication
4 Monitoring
5 Control
Data Collection/Storage/Representation
Data Communication
Monitoring
Control
Requirements
4 Distributed
6 Power Concerns
(a) Power management is another important factor that
needs to be considered in designing embedded systems.
(b) E.S should be designed in such a way as to minimize the
heat dissipation by the system.
1 Response
(a) It is the measure of quickness of the system.
(b) It tells how fast the system is tracking the changes in
input variables.
(c) Most of the E.S demands fast response which should be
almost real time.
(d) Ex – Flight control application.
2 Throughput
(a) It deals with the efficiency of a system.
(b) It can be defined as the rate of production or operation of
a defined process over a stated period of time.
(c) The rates can be expressed in terms of products, batches
produced or any other meaningful measurements.
(d) Ex – In case of card reader throughput means how many
transactions the reader can perform in a minute or in an
hour or in a day.
(e) Throughput is generally measured in terms of
’Benchmark’.
(f) A Benchmark is a reference point by which something
can be measured
28 CHAPTER 1. INTRODUCTION TO EMBEDDED SYSTEMS
3 Reliability
(a) It is a measure of how much we can rely upon the proper
functioning of the system.
(b) Mean Time Between Failure (MTBF) and Mean Time To
Repair (MTTR) are the terms used in determining system
reliability.
(c) MTBF gives the frequency of failures in
hours/weeks/months.
(d) MTTR specifies how long the system is allowed to be out
of order following a failure.
(e) For embedded system with critical application need, it
should be of the order of minutes.
4 Maintainability
(a) It deals with support and maintenance to the end user or
client in case of technical issues and product failure or on
the basis of a routine system checkup.
(b) Reliability and maintainability are complementary to
each other.
(c) A more reliable system means a system with less
corrective maintainability requirements and vice versa.
(d) Maintainability can be broadly classified into two
categories :
i. Scheduled or Periodic maintenance (Preventive
maintenance)
ii. Corrective maintenance to unexpected failures
5 Security
(a) Confidentiality, Integrity and availability are the three
major measures of information security.
(b) Confidentiality deals with protection of data and
application from unauthorized disclosure.
1.9. QUALITY ATTRIBUTES OF EMBEDDED SYSTEM 29
3 Portability
(a) It is the measure of system independence.
(b) An embedded product is said to be portable if the
product is capable of functioning in various
environments, target processors and embedded
operating systems.
(c) ‘Porting’ represents the migration of embedded
firmware written for one target processor to a different
target processor.
1.10 Summary
33
34 CHAPTER 2. TYPICAL EMBEDDED SYSTEM
The core of the embedded system falls into any one of the
following categories.
Microprocessor
5 Developers of microprocessors:
Microcontroller
Microprocessor Vs Microcontroller
Figure 2.2:
ADVANTAGES OF PLDs
3 PLDs do not require customers to pay for large NRE costs and
purchase expensive mask sets.
Figure 2.9:
Figure 2.10:
2.11 Memory
(a) Speed
(b) Data storage size and capacity
(c) Bus width
(d) Power consumption
(e) Cost
60 CHAPTER 2. TYPICAL EMBEDDED SYSTEM
1. NAND FLASH
2. NOR FLASH
Sensor
Actuator
9 The typical value for the current falls within the range of
20mA.
Figure 2.17:
5 The magnetic field attacts the armature core and moves the
contact point.
Figure 2.20:
5 The push button stays in the ’closed’ (For Push to Make type)
or ’Open’ (For Push to Break type) state as long as it is kept
in the pused state and it breaks/makes the circuit connection
when it is released.
6 Push button is used for generating a momentary pulse.
2.14. THE I/O SUBSYSTEM 71
Communication Interface
Figure 3.1:
73
74 CHAPTER 3. COMMUNICATION INTERFACE
Examples: Serial interfaces like I2C, SPI, UART, 1-Wire etc and
Parallel bus interface
4 1-Wires Interface
5 Parallel Interface
Figure 3.2:
1 Master device pulls the clock line (SCL) of the bus to ’HIGH’
2 Master device pulls the data line (SDA) ’LOW’, when the SCL
line is at logic ’HIGH’ (This is the ’Start’ condition for data
transfer).
Figure 3.4:
6 The data in the bus is valid during the ’HIGH’ period of the
clock signal.
7 In normal data transfer, the data line only changes state when
the clock is low.
78 CHAPTER 3. COMMUNICATION INTERFACE
Figure 3.5:
Figure 3.6:
Figure 3.7:
Figure 3.8:
(a) The data out line (MISO) of all the slave devices when not
selected floats at high impedance state
(b) The serial data transmission through SPI Bus is fully
configurable.
(c) SPI devices contain certain set of registers for holding
these configurations.
(d) The Serial Peripheral Control Register holds the various
configuration parameters like master/slave selection for
the device, baud rate selection for communication, clock
signal control etc.
(e) The status register holds the status of various conditions
for transmission and reception.SPI works on the principle
of ’Shift Register’.
(f) The master and slave devices contain a special shift
register for the data to transmit or receive.
(g) The size of the shift register is device dependent.
Normally it is a multiple of 8.
Figure 3.10:
I 2 C V/S SPI
S.N. I 2 C SPI
1 Speed limit varies from 100 More than 1 Mbps, 10
kbps, 400 kbps, 1Mbps, Mbps till 100 Mbps can be
3.4 Mbps depending on I 2 achieved.
version.
2 Half Duplex Synchronous Full duplex synchronous
protocol. protocol.
3 Support Multimaster Multi master configuration is
configuration. not possible.
4 Acknowledgment at each No acknowledgment
transfer
5 Requires two pins only SDA, Require separate MISO,
SCL MOSI, CLK and CS signal
for each slave.
6 Addition of new device on Addition of new device on
the bus is easy. the bus is not much easy as
I2C
7 More overlead (due to Less overhead
acknowledgment, start and
stop)
3.2. DEVICE/BOARD LEVEL OR ON BOARD COMMUNICATION INTERFACES83
Figure 3.11:
the bus has a unique 64-bit serial number. The least significant
byte of the serial number is an 8-bit number that tells the type of
the device. The most significant byte is a standard (for the 1-wire
bus) 8-bit CRC.
Figure 3.12:
1 RS-232C/RS-422/RS 485
2 USB
86 CHAPTER 3. COMMUNICATION INTERFACE
RS-232C
Figure 3.15:
1 Infrared
2 Bluetooth
3 Wi-Fi
4 Zigbee
5 GPRS
3.5.1 Infrared
5 Measure of heat
Figure 3.18:
3.5.2 Bluetooth
3.5.3 Wi-Fi
Figure 3.19:
3.5.4 ZIGBEE
Figure 3.20:
3.5.5 GPRS
Services Offered :
4.1 Introduction
99
100 CHAPTER 4. EMBEDDED FIRMWARE DESIGN AND DEVELOPMENT
Pros:
Cons :
Enhancements :
1 Assembly Language
M OV A, #30
0111010000011110
Advantages
2 High Performance
108 CHAPTER 4. EMBEDDED FIRMWARE DESIGN AND DEVELOPMENT
3 Low level Hardware Access Most of the code for low level
programming like accessing external device specific registers
from OS kernel ,device drivers, and low level interrupt
routines, etc are making use of direct assembly coding.
Drawbacks
2 Developer dependency
There is no common written rule for developing assembly
language based applications.
3 Non portable
(a) Target applications written in assembly instructions are
valid only for that particular family of processors and
cannot be re-used for another target
processors/controllers.
4.3. EMBEDDED FIRMWARE DEVELOPMENT LANGUAGES/OPTIONS109
Advantages
4.3.5 Drawbacks
4 Example :
#pragma asm
Mov A,#13H
#pragma ensasm
Figure 5.1:
115
116 CHAPTER 5. RTOS BASED EMBEDDED SYSTEM DESIGN
2 All kernel modules run within the same memory space under
a single kernel thread.
5.2.3 Microkernel
Benefits of Microkernel
1 Task/Process management
2 Task/Process scheduling
3 Task/Process synchronization
4 Error/Exception handling
5 Memory Management
6 Interrupt handling
7 Time management
Task/Process Management
Deals with setting up the memory space for the tasks, loading the
task’s code into the memory space, allocating system resources,
setting up a Task Control Block (TCB) for the task and
task/process termination/deletion. A Task Control Block (TCB)
is used for holding the information corresponding to a task. TCB
usually contains the following set of information.
122 CHAPTER 5. RTOS BASED EMBEDDED SYSTEM DESIGN
2 Task State: The current state of the task. (E.g. State= ‘Ready’
for a task which is ready to execute)
3 Task Type: Indicates what is the type for this task. The task
can be a hard real time or soft real time or background task.
Task/Process Scheduling
Task/Process Synchronization
Error/Exception handling
Memory Management
Interrupt Handling
Time Management
8 If the System time register is 32 bits wide and the ‘Timer tick’
interval is 1 microsecond, the System time register will reset
in
232 × 10−6
= 0.0497Days = 1.19Hours
24 × 60 × 60
If the ‘Timer tick’ interval is 1 millisecond, the System time
register will reset in
232 × 10−3
= 49.7Days = 50Days
24 × 60 × 60
5.5. HARD REAL-TIME SYSTEM 127
15 Load the context for the first task in the ready queue. Due
to the re- scheduling, the ready task might be changed to a
new one from the task, which was pre-empted by the ‘Timer
Interrupt’ task.
2 A Hard Real Time system must meet the deadlines for a task
without any slippage.
4 Soft Real Time systems most often have a ‘human in the loop
(HITL)’.
5 Automatic Teller Machine (ATM) is a typical example of Soft
Real Time System. If the ATM takes a few seconds more than
the ideal operation time, nothing fatal happens.
4 The terms ‘Task’, ‘job’ and ‘Process’ refer to the same entity in
the Operating System context and most often they are used
interchangeably.
5 When the process gets its turn, its registers and Program
counter register becomes mapped to the physical registers of
the CPU.
5.7. TASKS, PROCESSES & THREADS 131
Threads
Advantages of Threads
Thread Vs Process
2 A thread does not have its Process has its own code
own data memory and heap memory, data memory and
memory. It shares the data stack memory.
memory and heap memory
with other threads of the
same process.
3 A thread cannot live A process contains at least
independently; it lives one thread.
within the process.
4 There can be multiple Threads within a process
threads in a process. The share the code, data and heap
first thread (main thread) memory. Each thread holds
calls the main function and separate memory area for
occupies the start of the stack stack (shares the total stack
memory of the process. memory of the process).
5 Threads are very inexpensive Processes are very expensive
to create. to create. Involves many OS
overhead.
6 Context switching is Context switching is
inexpensive and fast. complex and involves lot
of OS overhead and is
comparatively slower.
7 If a thread expires, its stack is If a process dies, the
reclaimed by the process. resources allocated to it
are reclaimed by the OS and
all the associated threads of
the process also dies.
1 Job Queue: Job queue contains all the processes in the system
5.11. NON-PREEMPTIVE SCHEDULING 141
2 Ready Queue: Contains all the processes, which are ready for
execution and waiting for CPU to get their turn for execution.
The Ready queue is empty when there is no process ready for
running.
Drawbacks
Example 1 Three processes with process IDs P1, P2, P3 with estimated
completion time 10, 5, 7 milliseconds respectively enters the ready queue
together in the order P1, P2, P3. Calculate the waiting time and Turn
Around Time (TAT) for each process and the Average waiting time and
Turn Around Time (Assuming there is no I/O waiting for the processes).
Figure 5.10:
Drawbacks
Example 2 Three processes with process IDs P1, P2, P3 with estimated
completion time 10, 5, 7 milliseconds respectively enters the ready
queue together in the order P1, P2, P3 (Assume only P1 is present in
the ‘Ready’ queue when the scheduler picks up it and P2, P3 entered
‘Ready’ queue after that). Now a new process P4 with estimated
completion time 6ms enters the ‘Ready’ queue after 5ms of scheduling
P1. Calculate the waiting time and Turn Around Time (TAT) for each
process and the Average waiting time and Turn Around Time
(Assuming there is no I/O waiting for the processes).Assume all the
processes contain only CPU operation and no I/O operations are
involved.
Figure 5.11:
P1 and P4)
Waiting Time for P2 = 23 ms (P2 starts executing after completing
P1, P4 and P3)
Drawbacks
Example 3 Three processes with process IDs P1, P2, P3 with estimated
completion time 10, 5, 7 milliseconds and priorities 0, 3, 2 (0- highest
priority, 3 lowest priority) respectively enters the ready queue together.
Calculate the waiting time and Turn Around Time (TAT) for each process
and the Average waiting time and Turn Around Time (Assuming there is
no I/O waiting for the processes) in priority based scheduling algorithm.
Figure 5.12:
P1 and P3)
Waiting time for all processes
Average waiting time =
No. of processes
Waiting time for (P 1 + P 3 + P 2)
=
3
(0 + 10 + 17) 27
= =
3 3
= 9 milliseconds
Drawbacks
Example 4 Three processes with process IDs P1, P2, P3 with estimated
completion time 10, 5, 7 milliseconds respectively enters the ready queue
together. A new process P4 with estimated completion time 2ms enters
the ‘Ready’ queue after 2ms. Assume all the processes contain only CPU
operation and no I/O operations are involved.
Figure 5.13:
Example 5 Three processes with process IDs P1, P2, P3 with estimated
completion time 6, 4, 2 milliseconds respectively, enters the ready queue
together in the order P1, P2, P3. Calculate the waiting time and Turn
Around Time (TAT) for each process and the Average waiting time and
Turn Around Time (Assuming there is no I/O waiting for the processes)
in RR algorithm with Time slice= 2ms.
Figure 5.15:
154 CHAPTER 5. RTOS BASED EMBEDDED SYSTEM DESIGN
Example 6 Three processes with process IDs P1, P2, P3 with estimated
completion time 10, 5, 7 milliseconds and priorities 1, 3, 2 (0- highest
priority, 3 lowest priority) respectively enters the ready queue together.
A new process P4 with estimated completion time 6ms and priority 0
enters the ‘Ready’ queue after 5ms of start of execution of P1. Assume
all the processes contain only CPU operation and no I/O operations are
involved.
Figure 5.16:
1 Processor support
2 Memory Requirements
158 CHAPTER 5. RTOS BASED EMBEDDED SYSTEM DESIGN
(a) The RTOS requires ROM memory for holding the OS files
and it is normally stored in a non-volatile memory like
FLASH.
(b) OS also requires working memory RAM for loading the
OS service.
(c) Since embedded systems are memory constrained, it is
essential to evaluate the minimal RAM and ROM
requirements for the OS under consideration.
(d) Real-Time Capabilities:
i. It is not mandatory that the OS for all embedded
systems need to be Real- Time and all embedded
OS’s are ‘Real-Time’ in behavior.
ii. The Task/process scheduling policies plays an
important role in the Real- Time behavior of an OS.
5 Modularization Support
2 Cost
The total cost for developing or buying the OS and
maintaining it in terms of commercial product and custom
build needs to be evaluated before taking a decision on the
selection of OS.
3 Development and Debugging tools Availability
160 CHAPTER 5. RTOS BASED EMBEDDED SYSTEM DESIGN
Figure 5.17: