47
7/23/2019 Embedded_Systems - Introduction http://slidepdf.com/reader/full/embeddedsystems-introduction 1/47 4 EMBEDDED SYSTEMS 1. WHAT IS AN EMBEDDED SYSTEM? 2. HISTORY OF EMBEDDED SYSTEMS. 3. WHAT IS AN EMBEDDED COMPUTER? 4. WHAT ARE EMBEDDED SYSTEM USES FOR? HARD REAL-TIME SYSTEMS. SOFT REAL-TIME SYSTEMS. HYBRID REAL-TIME SYSTEMS. 5. WHAT ARE SOME DOWNFALLS OF EMBEDDED COMPUTER? 6. WHY STUDY EMBEDDED SYSTEMS? 7. EMBEDDED SYSTEMS TERMINOLOGY. MICROPROCESOR BASIC.  Microprocessor Introduction  Embedded System Basics  Microprocessor Architectures  PROGRAMMING EMBEDDED SYSTEMS.  C Programming  Assembly Language  Mixed C and Assembly Programming  REAL TIME OPERATING SYSTEMS.  Real-Time Operating Systems (RTOS)  Threading and Synchronization  RTOS Implementation

Embedded_Systems - Introduction

Embed Size (px)

Citation preview

Page 1: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 1/47

4

EMBEDDED SYSTEMS

1. WHAT IS AN EMBEDDED SYSTEM?2. HISTORY OF EMBEDDED SYSTEMS.3. WHAT IS AN EMBEDDED COMPUTER?4. WHAT ARE EMBEDDED SYSTEM USES FOR?

HARD REAL-TIME SYSTEMS.

SOFT REAL-TIME SYSTEMS.

HYBRID REAL-TIME SYSTEMS.

5. WHAT ARE SOME DOWNFALLS OF EMBEDDEDCOMPUTER?

6. WHY STUDY EMBEDDED SYSTEMS?7. EMBEDDED SYSTEMS TERMINOLOGY.

MICROPROCESOR BASIC.

  Microprocessor Introduction

  Embedded System Basics

  Microprocessor Architectures

 PROGRAMMING EMBEDDED SYSTEMS.

  C Programming

  Assembly Language

  Mixed C and Assembly Programming

 REAL TIME OPERATING SYSTEMS.

  Real-Time Operating Systems (RTOS)

  Threading and Synchronization

  RTOS Implementation

Page 2: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 2/47

5

8. COMPUTER DESIGN REQUIREMENTS.

  Real time/Reactive operation.

  Small size, law weight.

  Safe and reliable.

9. System-level requirement

  End- product utility.

  System safety & reliability.

  Controlling physical system.

  Power management

10.THE LIFE CYCLE OF EMBEDDED SYSTEMS.

COMPONENT ACQURESITY.

UPGRADES.

LONG TERM COMPONENT AVAILIBITY.

SYSTEM CERTIFICATIO.

LOGISTICS AND REPAIR.

11.THE MICROCONTROLLER AS ENBEDDED SYSTEMS.

GRADE OF MICROCONTROLLER.

GRADE OF MICROPROCESORS.

PROGRAMMABLE CONTROLLERS.

12.Memory Addressing and Types.

RAM.

ROM. PROM EPROM

13.C Programming with Embedded Systems.14.Embedded Systems IO Programming15.Embedded Systems Boot Loaders & Boot Sectors.

Page 3: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 3/47

6

16.THE EMBEDDED ENVIRONMENT.

  Reliability.  Efficiency.  Cost.

17.Basic Responsibilities of Operating Systems.18.Threading & Synchronization in OS.

  REAL-TIME OPERATING SYSTEMS.

  EMBEDDED OPERATING SYSTEMS.

HIGH-END EMBEDDED OS. DEEPLY EMBEDDED OS.

19.Threading & Synchronization in OS

Preemptive multithreading. Mutexes. Critical Sections. Priority Scheduling. Deadlocks. Watchdog Timer.

20.Embedded Systems Interrupts

Hardware & Software

Interrupt Service Routines.

Interrupt Vector Table.

21.RTOS Implementation.

Memory Management. What is Task?

What is Scheduler?

22.Conclusions.23.Bibliography and References.

Page 4: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 4/47

7

PREFACE

In the world of software development, the industry can be divided intothree large sectors: Embedded systems/Network-connected devices,Infrastructure, and E-business systems.

Would it surprise you to know that both of the first two sectors(infrastructures and embedded systems/network-connected devices) relyheavily on embedded system technology? It's true. But how importantare they, really? Well, if you've ever called someone on your cell phone,you have an embedded system to thank. If you've ever driven a car or

landed safely in an airplane, thank embedded systems.

The same goes for using your Personal Digital Assistant (PDA), benefiting from complex medical equipment, or consuming electricityfrom your local power company. Embedded systems are everywhere.

Impressive? So are the numbers. Every year, more than a billion dollarsare spent on the technology and know-how necessary to make all ofthese systems a reality.

Benefits of Embedded Systems:-

Aerospace: -   Navigation systems, automatic landing systems,Flight Attitude controls, engine controls, spaceExploration. (E.g.; the Mars Pathfinder).

Automotive: -   Fuel injection control, passenger environmentalControls, Anti lock braking systems, air bag controls,

  GPS mapping.

Page 5: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 5/47

8

Communications: - Satellites, network routers, switches, hubs.

Computer Peripherals: - Printers, scanners, keyboards, displays,Modems, Hard disk drives, CD-ROM drives.

Instrumentation: -   Data collection, oscilloscopes, signalGenerators, Signal analyzers, Power supplies.

Office Automation: - FAX machines, copiers, telephones,Cash registers.

Home: -  Dishwashers, microwave ovens, VCRs, televisions,

Stereos, Fire/security alarm systems, lawn sprinklerControls, Thermostats, cameras, clock radios, answering  Machines.

Personal: -   Personal Digital Assistants (PDAs), pagers,Cell phones, wrist watches, video games,Portable MP3 players, GPS.

Medical: -  Imaging systems (e.g., XRAY, MRI, and ultrasound),

Patient monitors, and heart pacers.

Industrial: -  Elevator controls, surveillance systems, robots.

Page 6: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 6/47

9

W H A T I S E M B E D E D S Y S T E M S : -

Tough question, really. There is no one answer. We asked at least a half

dozen industry experts and got as many answers. In fact, it was so hardto pin down a definition that I almost started thinking "embeddedsystem" was just another term for "software." Nevertheless, there's onefact about embedded systems that all the experts do seem to agree on:

An Embedded System is any software system that must be designed ona platform different from the platform on which the system is intendedto be deployed.

What is meant by platform? On the development side, platform typicallyrefers to an operating system capable of hosting software development,such as Windows, Solaris, HP, etc. On the target side, the word platformrefers to the devices on which the embedded system will be deployed.

OK then, why the design constraint? Why aren't embedded targetscapable of hosting software development? Because these targets areoptimized for performance and/or simplicity, they lack the equipment

necessary for development (such as keyboards, monitors, networking,etc.). In general, development for the embedded environment is referredto as "cross-platform development."

A General-purpose definition of embedded systems is that they aredevices used to control, monitor or assist the operation of equipment,machinery or plant. “Embedded” reflects the fact that they are an

integral part of the system. In many cases, their “embeddedness” may besuch that their presence is far from obvious to the casual observer.

Page 7: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 7/47

10

An EMBEDED SYSTEM is a special-purpose computer systemdesigned to perform one or a few dedicated functions, often withreal-time computing constraints. It is usually embedded  as part

of a complete device including hardware and mechanical parts.In contrast, a general-purpose computer, such as a personalcomputer, can do many different tasks depending on programming. Embedded systems have become very importanttoday as they control many of the common devices we use.

Since the embedded system is dedicated to specific tasks, designengineers can optimize it, reducing the size and cost of the

 product, or increasing the reliability and performance. Someembedded systems are mass-produced, benefiting fromeconomies of scale.

Physically, embedded systems range from portable devices suchas digital watches and MP3 players, to large stationaryinstallations like traffic lights, factory controllers, or the systemscontrolling nuclear power plants. Complexity varies from low,

with a single microcontroller chip, to very high with multipleunits, peripherals and networks mounted inside a large chassis orenclosure.

In general, "embedded system" is not an exactly defined term, asmany systems have some element of programmability. Forexample, Handheld computers share some elements withembedded systems — such as the operating systems andmicroprocessors which power them — but are not trulyembedded systems, because they allow different applications to be loaded and peripherals to be connected.

Page 8: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 8/47

11

History of EMBEDED SYSTEMS:-

In the earliest years of computers in the 1930-40s, computers were

sometimes dedicated to a single task, but were far too large andexpensive for most kinds of tasks performed by embedded computers oftoday. Over time however, the concept of programmable controllersevolved from traditional electromechanical sequencers, via solid statedevices, to the use of computer technology.

One of the first recognizably modern embedded systems was the ApolloGuidance Computer, developed by Charles Stark Draper at the MITInstrumentation Laboratory. At the project's inception, the Apolloguidance computer was considered the riskiest item in the Apollo projectas it employed the then newly developed monolithic integrated circuitsto reduce the size and weight. An early mass-produced embeddedsystem was the Autonetics D-17 guidance computer for the Minutemanmissile, released in 1961. It was built from transistor logic and had ahard disk for main memory. When the Minuteman II went into production in 1966, the D-17 was replaced with a new computer thatwas the first high-volume use of integrated circuits. This program alone

reduced prices on quad nand gate ICs from $1000/each to $3/each, permitting their use in commercial products.

Since these early applications in the 1960s, embedded systems havecome down in price and there has been a dramatic rise in processing power and functionality. The first microprocessor for example, the Intel4004 was designed for calculators and other small systems but stillrequired many external memory and support chips. In 1978 National

Engineering Manufacturers Association released a "standard" for programmable microcontrollers, including almost any computer-basedcontrollers, such as single board computers, numerical, and event-basedcontrollers.

Page 9: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 9/47

12

As the cost of microprocessors and microcontrollers fell it becamefeasible to replace expensive knob-based analog components such as potentiometers and variable capacitors with up/down buttons or knobsread out by a microprocessor even in some consumer products. By the

mid-1980s, most of the common previously external system componentshad been integrated into the same chip as the processor and this modernform of the microcontroller allowed an even more widespread use,which by the end of the decade were the norm rather than the exceptionfor almost all electronics devices.

Embedded system, a special-purpose system in which the computer iscompletely encapsulated by the device it controls.

What is an Embedded Computer? 

The first question that needs to be asked is "What exactly is anembedded computer?" To be fair, however, it is much easier to answerthe question of what an embedded computer is not, than to try and

describe all the many things that an embedded computer can be. Anembedded computer is frequently a computer that is implemented for a particular purpose. In contrast, an average PC computer usually serves anumber of purposes: checking email, surfing the internet, listening tomusic, word processing, etc... However, embedded systems usually onlyhave a single task, or a very small number of related tasks that they are programmed to perform.

Every home has several examples of embedded computers. Any

appliance that has a digital clock, for instance, has a small embeddedmicrocontroller that performs no other task than to display the clock.Modern cars have embedded computers onboard that control such thingsas ignition timing and anti-lock brakes using input from a number ofdifferent sensors.

Page 10: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 10/47

13

Embedded computers rarely have a generic interface, however. Even ifembedded systems have a keypad and an LCD display, they are rarelycapable of using many different types of input or output. An example ofan embedded system with I/O capability is a security alarm with an LCD

status display, and a keypad for entering a password.

In general, an Embedded System:

 Is a system built to perform its duty, completely or partially

independent of human intervention?

 Is specially designed to perform a few tasks in the most efficient

way.

 Interacts with physical elements in our environment, viz.controlling and driving a motor, sensing temperature, etc.

An embedded system can be defined as a control system or computersystem designed to perform a specific task. Common examples ofembedded systems include MP3 players, navigation systems on aircraftand intruder alarm systems. An embedded system can also be defined as

a single purpose computer.Most embedded systems are time critical applications meaning that theembedded system is working in an environment where timing is veryimportant: the results of an operation are only relevant if they take placein a specific time frame. An autopilot in an aircraft is a time criticalembedded system. If the autopilot detects that the plane for some reasonis going into a stall then it should take steps to correct this withinmilliseconds or there would be catastrophic results.

Page 11: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 11/47

14

What are Embedded Systems used for? 

The uses of embedded systems are virtually limitless, because every day

new products are introduced to the market that utilizes embeddedcomputers in novel ways. In recent years, hardware such asmicroprocessors, microcontrollers, and FPGA chips have become muchcheaper. So when implementing a new form of control, it's wiser to just buy the generic chip and write your own custom software for it.Producing a custom-made chip to handle a particular task or set of taskscosts far more time and money. Many embedded computers even comewith extensive libraries, so that "writing your own software" becomes a

very trivial task indeed.

From an implementation viewpoint, there is a major difference betweena computer and an embedded system. Embedded systems are oftenrequired to provide Real-Time response. A Real-Time system is definedas a system whose correctness depends on the timeliness of its response.Examples of such systems are flight control systems of an aircraft,sensor systems in nuclear reactors and power plants. For these systems,delay in response is a fatal error. A more relaxed version of  Real-Time

 Systems, is the one where timely response with small delays isacceptable. Example of such a system would be the Scheduling DisplaySystem on the railway platforms. In technical terminology,  Real-Time

 Systems can be classified as:

 Hard Real-Time Systems - systems with severe constraints on thetimeliness of the response.

 Soft Real-Time Systems - systems which tolerate small variations

in response times.  Hybrid Real-Time Systems - systems which exhibit both hard and

soft constraints on its performance.

Page 12: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 12/47

15

What are Some Downfalls of Embedded Computers? 

Embedded computers may be economical, but they are often prone tosome very specific problems. A PC computer may ship with a glitch in

the software, and once discovered, a software patch can often be shippedout to fix the problem. An embedded system, however, is frequently programmed once, and the software cannot be patched. Even if it is possible to patch faulty software on an embedded system, the process isfrequently far too complicated for the user.

Another problem with embedded computers is that they are ofteninstalled in systems for which unreliability is not an option. For instance,the computer controlling the brakes in your car cannot be allowed to failunder any condition. The targeting computer in a missile is not allowedto fail and accidentally target friendly units. As such, many of the programming techniques used when throwing together productionsoftware cannot be used in embedded systems. Reliability must beguaranteed before the chip leaves the factory. This means that everyembedded system needs to be tested and analyzed extensively.

An embedded system will have very few resources when compared to

full blown computing systems like a desktop computer, the memorycapacity and processing power in an embedded system is limited. It ismore challenging to develop an embedded system when compared todeveloping an application for a desktop system as we are developing a program for a very constricted environment. Some embedded systemsrun a scaled down version of operating system called an RTOS (realtime operating system).

Why Study Embedded Systems? Embedded systems are playing important roles in our lives every day,even though they might not necessarily be visible. Some of theembedded systems we use every day control the menu system ontelevision, the timer in a microwave oven, a cell phone, an MP3 playeror any other device with some amount of intelligence built-in. In fact,

Page 13: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 13/47

16

recent poll data shows that embedded computer systems currentlyoutnumber humans in the WORLD. Embedded systems are a rapidlygrowing industry where growth opportunities are numerous.

Embedded Systems Terminology: -

 Microprocessor Basics

Microprocessor Introduction Embedded System Basics Microprocessor Architectures Programmable Controllers Floating Point Unit and fixed-point numbers Parity Memory Memory Units

 Programming Embedded Systems

C Programming Assembly Language

Mixed C and Assembly Programming I/O Programming Boot loaders and Boot sectors

 Real Time Operating Systems

Real-Time Operating Systems (RTOS) Threading and Synchronization Interrupts RTOS Implementation Locks and Critical Sections

Page 14: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 14/47

17

Computer Design Requirements

Embedded computers typically have tight constraints on both functionality andimplementation. In particular, they must guarantee real time operation reactive to

external events, conform to size and weight limits, budget power and coolingconsumption, satisfy safety and reliability requirements, and meet tight costtargets.

Real time/reactive operation

Real time system operation means that the correctness of a computation depends,in part, on the time at which it is delivered. In many cases the system design musttake into account worst case performance. Predicting the worst case may bedifficult on complicated architectures, leading to overly pessimistic estimates

erring on the side of caution. The Signal Processing and Mission Critical examplesystems have a significant requirement for real time operation in order to meetexternal I/O and control stability requirements.

Reactive computation means that the software executes in response to externalevents. These events may be periodic, in which case scheduling of events toguarantee performance may be possible. On the other hand, many events may be a

 periodic, in which case the maximum event arrival rate must be estimated in orderto accommodate worst case situations. Most embedded systems have a significantreactive component.

 Small size, low weight 

Many embedded computers are physically located within some larger artifact.Therefore, their form factor may be dictated by aesthetics, form factors existing in

 pre-electronic versions, or having to fit into interstices among mechanicalcomponents. In transportation and portable systems, weight may be critical for fueleconomy or human endurance. Among the examples, the Mission Critical systemhas much more stringent size and weight requirements than the others because of

its use in a flight vehicle, although all examples have restrictions of this type.

Page 15: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 15/47

18

 Safe and reliable

Some systems have obvious risks associated with failure. In mission-criticalapplications such as aircraft flight control, severe personal injury or equipmentdamage could result from a failure of the embedded computer. Traditionally, suchsystems have employed multiply-redundant computers or distributed consensus

 protocols in order to ensure continued operation after an equipment failure

However, many embedded systems that could cause personal or property damagecannot tolerate the added cost of redundancy in hardware or processing capacityneeded for traditional fault tolerance techniques. This vulnerability is oftenresolved at the system level as discussed later .

Harsh environment 

Many embedded systems do not operate in a controlled environment. Excessiveheat is often a problem, especially in applications involving combustion (e.g.,

many transportation applications). Additional problems can be caused forembedded computing by a need for protection from vibration, shock, lightning,

 power supply fluctuations, water, corrosion, fire, and general physical abuse. Forexample, in the Mission Critical example application the computer must functionfor a guaranteed, but brief, period of time even under non-survivable fireconditions.

Cost sensitivity 

Even though embedded computers have stringent requirements, cost is almostalways an issue (even increasingly for military systems). Although designers ofsystems large and small may talk about the importance of cost with equal urgency,their sensitivity to cost changes can vary dramatically. A reason for this may bethat the effect of computer costs on profitability is more a function of the

 proportion of cost changes compared to the total system cost, rather than comparedto the digital electronics cost alone. For example, in the Signal Processing systemcost sensitivity can be estimated at approximately $1000 (i.e., a designer can makedecisions at the $1000 level without undue management scrutiny). However, within the Small system decisions increasing costs by even a few cents attractmanagement attention due to the huge multiplier of production quantity combinedwith the higher percentage of total system cost it represents.

Page 16: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 16/47

19

System-level requirements

In order to be competitive in the marketplace, embedded systems require that thedesigners take into account the entire system when making design decisions.

End-product utility 

The utility of the end product is the goal when designing an embedded system, notthe capability of the embedded computer itself. Embedded products are typicallysold on the basis of capabilities, features, and system cost rather than which CPU isused in them or cost/performance of that CPU.

One way of looking at an embedded system is that the mechanisms and theirassociated I/O are largely defined by the application. Then, software is used to

coordinate the mechanisms and define their functionality, often at the level ofcontrol system equations or finite state machines. Finally, computer hardware ismade available as infrastructure to execute the software and interface it to theexternal world. While this may not be an exciting way for a hardware engineer tolook at things, it does emphasize that the total functionality delivered by the systemis what is paramount.

 System safety & reliability 

An earlier section discussed the safety and reliability of the computing hardware

itself. But, it is the safety and reliability of the total embedded system that reallymatters. The Distributed system example is mission critical, but does not employcomputer redundancy. Instead, mechanical safety backups are activated when thecomputer system loses control in order to safely shut down system operation.

A bigger and more difficult issue at the system level is software safety andreliability. While software doesn't normally "break" in the sense of hardware, itmay be so complex that a set of unexpected circumstances can cause softwarefailures leading to unsafe situations. This is a difficult problem that will take manyyears to address, and may not be properly appreciated by non-computer engineers

and managers involved in system design decisions.

Page 17: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 17/47

20

Controlling physical systems

The usual reason for embedding a computer is to interact with the environment,often by monitoring and controlling external machinery. In order to do this, analoginputs and outputs must be transformed to and from digital signal levels.Additionally, significant current loads may need to be switched in order to operatemotors, light fixtures, and other actuators. All these requirements can lead to alarge computer circuit board dominated by non-digital components.

In some systems "smart" sensors and actuators (that contain their own analoginterfaces, power switches, and small CPUS) may be used to off-load interfacehardware from the central embedded computer. This brings the additionaladvantage of reducing the amount of system wiring and number of connectorcontacts by employing an embedded network rather than a bundle of analog wires.

However, this change brings with it an additional computer design problem of partitioning the computations among distributed computers in the face of aninexpensive network with modest bandwidth capabilities.

Power management 

A less pervasive system-level issue, but one that is still common, is a need for power management to either minimize heat production or conserve battery power.While the push to laptop computing has produced "low-power" variants of popularCPUs, significantly lower power is needed in order to run from inexpensive

 batteries for 30 days in some applications, and up to 5 years in others.

Page 18: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 18/47

21

Life-cycle support 

  [An embedded system lifecycle.]

First a need or opportunity to deploy new technology is identified. Then a productconcept is developed. This is followed by concurrent product and manufacturing

 process design, production, and deployment. But in many embedded systems, thedesigner must see past deployment and take into account support, maintenance,upgrades, and system retirement issues in order to actually create a profitabledesign. Some of the issues affecting this life-cycle profitability are discussed

 below.

Component acquisition

Because an embedded system may be more application-driven than a typicaltechnology-driven desktop computer design, there may be more leeway incomponent selection. Thus, component acquisition costs can be taken into account

Page 19: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 19/47

22

when optimizing system life-cycle cost. For example, the cost of a componentgenerally decreases with quantity, so design decisions for multiple designs should

 be coordinated to share common components to the benefit of all.

 System certification

Embedded computers can affect the safety as well as the performance the system.Therefore, rigorous qualification procedures are necessary in some systems afterany design change in order to assess and reduce the risk of malfunction orunanticipated system failure. This additional cost can negate any savings thatmight have otherwise been realized by a design improvement in the embeddedcomputer or its software. This point in particular hinders use of new technology byresynthesizing hardware components -- the redesigned components cannot be usedwithout incurring the cost of system recertification.

One strategy to minimize the cost of system recertification is to delay all designchanges until major system upgrades occur. As distributed embedded systemscome into more widespread use, another likely strategy is to partition the system insuch a way as to minimize the number of subsystems that need to be recertifiedwhen changes occur. This is a partitioning problem affected by potential designchanges, technology insertion strategies, and regulatory requirements.

Logistics and repair 

Whenever an embedded computer design is created or changed, it affects thedownstream maintenance of the product. A failure of the computer can cause theentire system to be unusable until the computer is repaired. In many casesembedded systems must be repairable in a few minutes to a few hours, whichimply that spare components and maintenance personnel must be located close tothe system. A fast repair time may also imply that extensive diagnosis and datacollection capabilities must be built into the system, which may be at odds withkeeping production costs low.

Because of the long system lifetimes of many embedded systems, proliferation of

design variations can cause significant logistics expenses. For example, if acomponent design is changed it can force changes in spare component inventory,maintenance test equipment, maintenance procedures, and maintenance training.Furthermore, each design change should be tested for compatibility with varioussystem configurations, and accommodated by the configuration managementdatabase.

Page 20: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 20/47

23

Upgrades

Because of the long life of many embedded systems, upgrades to electroniccomponents and software may be used to update functionality and extend the lifeof the embedded system with respect to competing with replacement equipment.While it may often be the case that an electronics upgrade involves completelyreplacing circuit boards, it is important to realize that the rest of the system willremain unchanged. Therefore, any special behaviors, interfaces, and undocumentedfeatures must be taken into account when performing the upgrade. Also, upgradesmay be subject to recertification requirements.

Of special concern is software in an upgraded system. Legacy software may not beexecutable on upgraded replacement hardware, and may not be readily cross-compiled to the new target CPU. Even worse, timing behavior is likely to be

different on newer hardware, but may be both undocumented and critical to systemoperation.

Long-term component availability 

When embedded systems are more than a few years old, some electroniccomponents may no longer be available for production of new equipment orreplacements. This problem can be especially troublesome with obsolete

 processors and small-sized dynamic memory chips.

When a product does reach a point at which spare components are no longereconomically available, the entire embedded computer must sometimes beredesigned or upgraded. This redesign might need to take place even if the systemis no longer in production, depending on the availability of a replacement system.This problem is a significant concern on the Distributed example system.

Types of Chips

There are a number of different types of chips that we will discuss here.

Microprocessors

These chips contain a processing core, and occasionally a fewintegrated peripherals. In a different sense, Microprocessors aresimply CPUs found in desktops.

Page 21: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 21/47

24

Microcontrollers

These chips are all-in-one computer chips. They contain a processing core, memory, and integrated peripherals. In a broader

sense, a microcontroller is a CPU that is used in an embeddedsystem.

Digital Signal Processor (DSP)

DSPs are the "best of the best" when it comes to microcontrollers.DSPs frequently run very quickly, and have immense processing power (for an embedded chip).

MICROCONTROLLER AS EMBEDED

A microcontroller is a single chip, self-contained computer whichincorporates all the basic components of a personal computer on a muchsmaller scale. Microcontrollers are often referred to as single chipdevices or single chip computers. The main consequence of themicrocontroller’s small size is that its resources are far more limited than

those of a desktop personal computer.

[THE MICROCONTROLLER ]

In functional terms, a microcontroller is a programmable single chipwhich controls a process or system. Microcontrollers are typically usedas embedded controllers where they control part of a larger system such

Page 22: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 22/47

25

as an appliance, automobile, scientific instrument or a computer peripheral.

Microcontrollers are designed to be low cost solutions; therefore using

them can drastically reduce part and design costs for a project.

Physically, a microcontroller is an integrated circuit with pins along eachside. The pins presented by a microcontroller are used for power,ground, oscillator, I/O ports, interrupt request signals, reset and control.In contrast, the pins exposed by a microprocessor are most oftenmemory bus signals (rather than I/O ports).

Grades of Microcontrollers

Microcontrollers can be divided up into different categories, dependingon several parameters such as bus-width (8 bit, 16 bit, etc...), amount ofmemory, speed, and the number of I/O pins:

Low-end

Low-end chips are frequently used in simple situations, wherespeed and power are not a factor. Low-end chips are the cheapestof the bunch, and can usually cost less than a dollar , depending onthe quantity in which they are purchased. Low-end chips rarelyhave many I/O pins (4 or 8, total), and rarely have any specialcapabilities. Almost all low-end chips are 8 bits or smaller.

Mid-level chips

Mid-level chips are the "basic" microcontroller units. They don'tsuffer from the drawbacks of the low-end chips, but at the sametime they are more expensive and larger. Mid-level chips are 8 bitsor 16 bits wide, and frequently have a number of available I/O pinsto play with. Mid-level chips may come with ADC, voltage

Page 23: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 23/47

26

regulators, OpAmps, etc... Mid-level chips can cost anywhere between $1 and $10 for reasonable chips.

High-end chips

High end chips are used in situations where power and speed are amust, but a conventional microprocessor board (think a computermotherboard) is too large or expensive. High-end chips will have anumber of fancy features, more available memory, and a largeraddressable memory range. High end chips can come in 8 bit, 16 bit, 32 bit or even 64 bit, and can cost anywhere between $10 to$100 each.

Grades of Microprocessors

Memory Bus

In a computer, a processor is connected to the RAM by a data bus. Thedata bus is a series of wires running in parallel to each other that cansend data to the memory, and read data back from the memory. Inaddition, the processor must send the address of the memory to be

accessed to the RAM module, so that the correct information can bemanipulated.

Multiplexed Address/Data Bus

In old microprocessors, and in some low-end versions today, thememory bus is a single bus that will carry both the address of the data to be accessed, and then will carry the value of the data. Putting bothsignals on the same bus, at different times is a technique known as "time

division multiplexes”, or just multiplexing for short. The effect of amultiplexed memory bus is that reading or writing to memory actuallytakes twice as long: half the time to send the address to the RAMmodule, and half the time to access the data at that address. This meansthat on a multiplexed bus, moving data to and from the memory is a veryexpensive (in terms of time) process, and therefore memory read/write

Page 24: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 24/47

27

operations should be minimized. It also makes it important to ensurealgorithms which work on large datasets are cache efficient.

Demultiplexed Bus

The opposite of a multiplexed bus is a Demultiplexed bus. ADemultiplexed bus has the address on one set of wires, and the data onanother set. This scheme is twice as fast as a multiplexed system, andtherefore memory read/write operations can occur much faster.

Bus Speed

In modern high speed microprocessors, the internal CPU clock may

move much faster than the clock that synchronizes the rest of themicroprocessor system. This means that operations that need to accessresources outside the processor (the RAM for instance) are restricted tothe speed of the bus, and cannot go as fast as possible. In thesesituations, microprocessors have 2 options: They can wait for thememory access to complete (slow), or they can perform other taskswhile they are waiting for the memory access to complete (faster). Oldmicroprocessors and low-end microprocessors will always take the first

option (so again, limit the number of memory access operations), whilenewer, and high-end microprocessors will often take the second option.

I/O Bus

Any computer, be it a large PC or a small embedded computer, is uselessif it has no means to interact with the outside world. I/O communicationsfor an embedded computer frequently happen over a bus called the I/O

Bus. Like the memory bus, the I/O bus frequently multiplexes the input

and output signals over the same bus. Also, the I/O bus is moving at aslower speed than the processor is, so large numbers of I/O operationscan cause a severe performance bottleneck.

It is not uncommon for different IO methods to have separate buses.Unfortunately, it is also not uncommon for the electrical engineers

Page 25: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 25/47

28

designing the hardware to cheat and use a bus for more than 1 purpose.Doing so can save the need for extra transistors in the layout, and savecost. For example, a project may use the USB bus to talk to some LEDsthat are physically close by. These different devices may have very

different speeds of communication. When programming IO bus control,make sure to take this into account.

In some systems, memory mapped IO is used. In this scheme, thehardware reads its IO from predefined memory addresses instead of overa special bus. This means you'll have simpler software, but it also meansmain memory will get more access requests.

Programming the IO Bus

When programming IO bus controls, there are 5 major variations on howto handle it- the main thread poll, the multithread poll, the interruptmethod, the interrupt thread method, and using a DMA controller.

Programmable Controllers

The original 8086 processor shipped with a number of peripheral chipsthat each performed different tasks. Among these chips were programmable Interrupt controllers, programmable timers, and programmable I/O chips that could handle many of the tasks of theoriginal computer, to take some of the computational strain off the 8086.In new versions of Intel chips (486, Pentium, etc) many of the peripheralchips have been integrated into the processor, in an attempt to speed upthe entire computer. However, much of the functionality remains, evenin today's high-end computer systems.

Timers

External timer chips are incredibly useful for performing a number ofdifferent operations. For instance, many multi-threaded operatingsystems operate by setting a timer, and then switching to a different

Page 26: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 26/47

29

thread every time the timer goes off. Programmable timer chips canoften be programmed to provide a variety of different timing functions,to take the burden off the microprocessor. You can see some of the 8086compatible timer chips like 8253/54 also they are the same have three

independent timers internally but 8254 can work with higher frequenciesand is used to generate interrupt like Memory refresh interrupt ,Time ofday TOD interrupt and the last one is used to generate the speakerfrequencies.

Interrupt Controllers

The original 8086 processor had only a single pin used for signaling aninterrupt, so a programmable interrupt controller would handle most ofthe messy details of calling the interrupt. Also, a programmable interruptcontroller could be used to monitor an input port for instance, andtriggering an interrupt routine when input is received.

Direct Memory Access

Since memory read/write operations take longer than other operationsfor the microprocessor, it is very wasteful to ask the microprocessor to

move large blocks of memory. Luckily, the original 8086 came with a programmable direct memory access controller (DMA) for use inautomatically copying and moving large segments of memory. DMAscould also be used for implementing memory-mapped I/O, by being programmed to automatically move memory data to and from an output port.

DMA memory copies can also greatly enhance system performance byallowing the CPU to execute code in parallel with a DMA controller

automatically performing the memory copy.

Peripheral Interface Controllers

Peripheral interface controllers take a number of different forms. Eachdifferent type of port has a different controller that the microprocessor

Page 27: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 27/47

30

will interface with to send the output on that port. For instance there arecontrollers for parallel ports and more modern USB ports. Thesecontrollers are used for controlling settings on output such as timing, andsetting different modes on the output/input port.

Floating Point Unit 

Floating point numbers are....

Like all information, floating point numbers are represented by bits.

Early computers used a variety of floating-point number formats. Each

one required slightly different subroutines to add, subtract, and do otheroperations on them.

Because some computer applications use floating point numbers a lot,Intel standardized on one particular format, and designed floating-pointhardware that calculated much more quickly than the softwaresubroutines. The 80186 shipped with a floating-point co-processordubbed the 80187. The 80187 was a floating point math unit thathandled the floating point arithmetic functions. In newer processors, thefloating point unit (FPU) has been integrated directly into themicroprocessor.

Many small embedded systems, however, do not have an FPU (internalor external). Therefore, they manipulate floating-point numbers, whennecessary, the old way. They use software subroutines, often called a"floating point emulation library".

However, floating-point numbers are not necessary in many embeddedsystems. Many embedded system programmers try to eliminate floating point numbers from their programs, instead using fixed-point arithmetic.Such programs uses less space (fixed-point subroutine libraries are farsmaller than floating-point libraries, especially when just one or tworoutines are put into the system). On microprocessors without a floating-

Page 28: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 28/47

31

 point unit, the fixed-point version of a program usually runs faster thanfloating-point version. However, these embedded system programmersmust figure out exactly how much accuracy a particular applicationneeds, and make sure their fixed-point routines maintain at least that

much accuracy.

Parity 

In many instances, especially in transmission, it is important to includesome amount of error-checking information, so that incorrectinformation can be determined and discarded. One of the simplestmethods of error-checking is called parity. Parity can be broken up intoEven Parity and Odd Parity schemes. A parity check consists of a single bit that is set, depending on a certain condition.

Even Parity 

In an even parity scheme, the parity bit is set if an odd number of bits inthe data are set to 1 (to make the total number of 1 bits even). Forinstance, 01001100 would generate an even parity bit, while 11001100would not generate one.

Odd Parity 

The opposite of even parity, odd parity generates a parity bit if there areeven numbers of high-bits in the data (to create an odd number of 1's).

Limitations of Parity 

Simple 1-bit parity is only able to detect a single bit error, or an error inan odd number of bits. If an even number of bits (2, 4, 6, 8) aretransmitted in error, the parity check will not catch the mistake

However, chances of getting 2 errors in 1 transmission are much smallerthan getting only 1 error in 1 transmission. So parity checks serve as acheap and easy way to check for errors.

Page 29: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 29/47

32

More advanced error detection

ECC codes are often used for the same reasons as parity bits. Thesecodes use more bits; however they allow multi bit error detection, and

also correction of single bit errors.

CRC checks are usually used at the end of data blocks. These arecarefully designed to give a very high probability of detecting corruptionof the data block, no matter how many bit errors are in the block.

Memory 

On an Embedded System, memory is at a premium. Some chips,

 particularly embedded VLSI chips, and low-end microprocessors mayonly have a small amount of RAM "on board" (built directly into thechip), and therefore their memory is not expandable. Other embeddedsystems have a certain amount of memory, and have no means toexpand. In addition to RAM, some embedded systems have some non-volatile memory, in the form of miniature magnetic disks, FLASHmemory expansions, or even various 3rd-party memory card expansions.Keep in mind however, that a memory upgrade on an embedded system

may cost more then the entire system itself. An embedded systems programmer, therefore, needs to be very much aware of the memoryavailable, and the memory needed to complete a task.

Memory Addressing and Types

Each microcontroller has a specific addressing range. An addressingrange is the number of addresses a microcontroller can access. Theaddressing scheme used to access to these spaces varies from processorto processor, but the underlying hardware is similar.

Page 30: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 30/47

33

RAM Random access memory1 or RAM consists of memory addresses the CPU can bothread from and write to. RAM is used for data memory and allows the CPU tocreate and modify data as it executes the application program. RAM is volatile; it

holds its contents only as long as it has a constant power supply. If power to thechip is turned off, the contents of RAM are lost. This does not mean that RAMcontents are lost during a chip reset. Vital state information or other data can berecorded in data memory and recovered after an interrupt or reset.

ROM ROM, read only memory, is typically used for program instructions. The ROM in amicrocontroller usually holds the final application program. Mask able ROM ismemory space that must be burned in by the manufacturer of the chip as it isconstructed. To do this, you must provide the chip builder with the ROM contents

you wish the chip to have. The manufacturer will then mask out appropriate ROM blocks and hardwire the information you have provided.

Since recording chip ROM contents is part of the manufacturing process, it is acostly one-time expense. If you intend to use a small number of parts, you may be

 better off using chips with PROM. If you intend to use a large number of parts foryour application, then the one-time expense of placing your program in ROM ismore feasible.

PROM Programmable ROM, or PROM, started as an expensive means to prototype andtest application code before burning ROM. In recent years PROM has gained

 popularity to the point where many developers consider it a superior alternative to burning ROM. As microcontroller applications become more specialized andcomplex, needs for maintenance and support rise. Many developers use PROMdevices to provide software updates to customers without the cost of sending outnew hardware.

There are many programmable ROM technologies available which all provide asimilar service. A special technique is used to erase the contents of programmableROM then a special method is used to program new instructions into the ROM.Often, the developer uses separate hardware to perform each of these steps.

Page 31: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 31/47

34

EPROM EPROM (erasable programmable ROM) is not volatile and is read only. Chips withEPROM have a quartz window on the chip. Direct exposure to ultra-violetradiation will erase the EPROM contents. EPROM devices typically ship with a

shutter to cover the quartz window and prevent ambient UV from affecting thememory. Often the shutter is a sticker placed on the window.

Developers use an EPROM eraser to erase memory contents efficiently. The eraser bombards the memory with high-intensity UV light. To reprogram the chip, anEPROM programmer is used, a device which writes instructions into EPROM.The default, blank state for an EPROM device has each block of memory set.When you erase an EPROM you are really setting all memory blocks to 1.

Reprogramming the device resets or clears the appropriate EPROM bits to 0.

Because of the way EPROM storage is erased, you can not selectively delete portions of EPROM – when you erase the memory you must clear the entirestorage space.

EEPROM EEPROM (electrically erasable programmable ROM) devices have a significantadvantage over EPROM devices as they allow selective erasing of memorysections. EEPROM devices use high voltage to erase and re-program each memory

 block. Some devices require an external power source to provide the voltage

necessary for erasing and writing and some have an onboard pump which the chipcan use to build up a charge of the required voltage.Developers can reprogram EEPROM devices while the chip is operating.However, EEPROM that can be rewritten is usually restricted to data memorystorage. EEPROM storage used as program memory typically requires the use ofan external power source and a programmer just like EPROM storage. The mostcommon use for EEPROM is recording and maintaining configuration data vital tothe application.

Flash Memory Flash memory is an economical compromise between EEPROM and EPROMtechnology. As with EEPROM high voltage is applied to erase and rewrite flashmemory. However, unlike EEPROM, you can not selectively erase portions of flash memory – you must erase the entire block as with EPROM devices. Many

Page 32: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 32/47

35

manufacturers are turning to flash memory. It has the advantages of not requiringspecial hardware and being inexpensive enough to use in quantity.

Manufacturers often provide customers with microcontroller products whoseROM is loaded with a boot or configuration kernel where the application code iswritten into flash memory. When the manufacturer wants to provide the customerwith added functionality or a maintenance update, the hardware can bereprogrammed on site without installing new physical parts. The hardware is

 placed into configuration mode which hands control to the kernel written in ROM.This kernel then handles the software steps needed to erase and re-write thecontents of the flash memory.

C Programming with EMBEDED SYSTEMS 

Most C programmers are spoiled because they program in environments where notonly there is a standard library implementation, but there are frequently a numberof other libraries available for use. The cold fact is, that in embedded systems,there rarely are many of the libraries that programmers have grown used to, butoccasionally an embedded system might not have a complete standard library, ifthere is a standard library at all. Few embedded systems have capability fordynamic linking, so if standard library functions are to be available at all, theyoften need to be directly linked into the executable. Often times, because of spaceconcerns, it is not possible to link in an entire library file, and programmers areoften forced to "brew their own" standard c library implementations if they want touse them at all. While some libraries are bulky and not well suited for use onmicrocontrollers, many development systems still include the standard librarieswhich are the most common for C programmers.

C remains a very popular language for microcontroller developers due to the codeefficiency and reduced overhead and development time. C offers low-level controland is considered more readable than assembly. Many free C compilers areavailable for a wide variety of development platforms. The compilers are part of an

IDEs with ICD support, breakpoints, single-stepping and an assembly window.The performance of C compilers has improved considerably in recent years, andthey are claimed to be more or less as good as assembly, depending on who youask. Most tools now offer options for customizing the compiler optimization.Additionally, using C increases portability, since C code can be compiled fordifferent types of processors.

Page 33: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 33/47

36

Embedded Systems/IO Programming

An embedded system is useless if it cannot communicate with theoutside world. To this effect, embedded systems need to employ I/O

mechanisms to both receive outside data, and transmit commands backto the outside world. Few Computer Science courses will even mentionI/O programming, although it is a central feature of embedded systems programming.

Embedded Systems/Boot loaders and Boot sectors

To simplify many tasks, programmers for many systems will oftenemploy a generic piece of software called a boot loader that will setsome system settings (such as enabling protected mode), and then will be used to load the kernel, and then transfer control to the kernel forsystem operation. In embedded systems particularly, boot loaders areuseful when doing work on the kernel: the kernel can be altered andtested, and the boot loader will automatically load each new version intomemory.

To further simplify the process, the programmer can employ a toolcalled a boot menu, which is essentially a boot loader that allows theuser to select which kernel to load, from a list of possibilities. This isuseful when multiple kernels are being compared, or when differentversions of the same kernel are being debugged.

Boot loaders are used on many microcontrollers. A boot loader is oftenthe fastest way to update a program in a microcontroller with smallchanges. That makes the edit-compile-download-test cycle a little bit

faster. The microcontroller can also have minimal hard-coded silicondedicated to a simpler programming interface, which an expensive programmer needs socket. A vendor can then put a tiny program in Flashwhich reads the real program through the interface-du-jour, is it RS-232,I²C, or wireless USB.

Page 34: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 34/47

37

The Embedded Environment 

Microcontrollers used in development projects have very limitedresources. You are working close to your target machine and you must

 be familiar with your target hardware construction and operation.A good quality C development environment incorporates tools whichallow you to concentrate primarily on your applications and not on thehardware which runs them. However, you cannot ignore low-leveldetails of your target hardware. The better you understand your run-timeenvironment, the better you can take advantage of its limited capabilitiesand resources.

The Embedded DifferenceThere are many aspects of embedded systems development which must be considered. These are:

Reliability 

Embedded systems must be reliable. Personal computer programs suchas word processors and games do not need to achieve the same standardof reliability that a microcontroller application must. Errors in programssuch as word processors may result in errors in a document or loss ofdata. An error in a microcontroller application such as a televisionremote control or compact disc player will result in a product that doesnot work and consequently does not sell. An error in a microcontrollerapplication such as an antilock braking system or autopilot could befatal.

Efficiency

Issues of efficiency must be considered in real time applications. A realtime application is one in which must be able to act at a speedcorresponding with the occurrence of an actual process.

Page 35: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 35/47

38

Cost 

Many embedded systems must compete in a consumer market and costis an important issue in project development.

Real-time and embedded operating systems are in most respects similar to general purpose operating systems: they provide the interface between application programs and the system hardware, and they rely on basically the same set of programming primitives and concepts. But general purpose operating systemsmake different trade-offs in applying these primitives, because they have differentgoals.

BASIC RESPOSIBLITIES OF OPERATING SYSTEMS 

This Section discusses the basic responsibilities of the operating system that arerelevant for this text: (I) task management and scheduling, (ii) (deferred) interruptservicing, (iii) inter-process communication and synchronization, and (IV) memorymanagement. General-purpose operating systems also have other responsibilities,which are beyond the horizon of a real-time operating system: file systems and filemanagement, (graphical) user interaction, communication protocol stacks, disk IO,to name a few.

REAL-TIME OPERATING SYSTEMS 

A Real-Time Operating System (RTOS) is a computing environment that reactsto input within a specific time period. A real-time deadline can be so small thatsystem reaction appears instantaneous. The term real-time computing has also beenused, however, to describe "slow real-time" output that has a longer, but fixed,time limit.

Learning the difference between real-time and standard operating systems is aseasy as imagining yourself in a computer game. Each of the actions you take in thegame is like a program running in that environment. A game that has a real-timeoperating system for its environment can feel like an extension of your body

 because you can count on a specific "lag time:" the time between your request foraction and the computer's noticeable execution of your request.

A standard operating system, however, may feel disjointed because the lag time isunreliable. To achieve time reliability, real-time programs and their operating

Page 36: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 36/47

39

system environment must prioritize deadline actualization before anything else. Inthe gaming example, this might result in dropped frames or lower visual qualitywhen reaction time and visual effects conflict.

Embedded OPERATING SYSTEMS 

The concepts introduced in the previous sections apply of course also to embeddedOperating systems (“EOS”). Embedded operating systems, however, have somefeatures that distinguish them from real-time and general purpose operatingsystems. But the definition of an “embedded operating system” is probably evenmore ambiguous than that of an RTOS, and they come in a zillion different forms.But you’ll recognize one when you see one, although the boundary betweengeneral purpose operating systems and embedded operating systems is not sharp,and is even becoming more blurred all the time.

Embedded systems are being installed in tremendous quantities (an order ofmagnitude more than desktop PCs!): they control lots of functions in modern cars;they show up in household appliances and toys; they control vital medicalinstrumentation; they make remote controls and GPS (Global Position Systems)work; they make your portable phones work; etc.

The simplest classification between different kinds of embeddedoperating systems is as follows:

• High-end embedded systems.

These systems are often down-sized derivatives of an existing general purpose OS, but with much of the “balast” removed. Linux has given rise to a largeset of such derivatives, because of its highly modular structure and the availabilityof source code. Examples are: routers, switches, personal digital assistants, set top

 boxes.

• Deeply embedded OS.

These OSs must be really very small, and need only a handful of basic functions.Therefore, they are mostly designed from the ground up for a particularapplication. Two typical functions deeply embedded systems (used to) lack arehigh-performance graphical user interfacing or network communication. Examplesare: automotive controls, digital cameras, portable phones. But also these systemsget more graphics and networking capabilities. . .

Page 37: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 37/47

40

The most important features that make an OS into an embedded OS are:

• Small footprint.

Designers are continuously trying to put more computing power in smaller

housings, using cheaper CPUs, with on-board digital and/or analog IO; and theywant to integrate these CPUs in all kinds of small objects. A small embedded OSalso often uses only a couple of kilobytes of RAM and ROM memory.

• The embedded system should run for years without manual intervention. Thismeans that the hardware and the software should never fail. Hence, the systemshould preferably have no mechanical parts, such as floppy drives or hard disks.

 Not only because mechanical parts are more sensitive to failures, but they also takeup more space, need more energy, take longer to communicate with, and have

more complex drivers (e.g., due to motion control of the mechanical parts).

• Many embedded systems have to control devices that can be dangerous if theydon’t work exactly as designed. Therefore, the status of these devices has to bechecked regularly. The embedded computer system itself, however, is one of thesecritical devices, and has to be checked too! Hence, one often sees hardwarewatchdogs included in embedded systems. These watchdogs are usually retriggerable mono stable timers attached to the processor’s reset input. The operatingsystem checks within specified intervals whether everything is working as desired,for example by examining the contents of status registers. It then resets the

watchdog. So, if the OS doesn’t succeed in resetting the timer, that means that thesystem is not functioning properly and the timer goes off, forcing the processor toreset.If something went wrong but the OS is still working (e.g., a memory protectionerror in one of the tasks) the OS can activate a  software watchdog , which isnothing else but an interrupt that schedules a service routine to handle the error.One important job of the software watchdog could be to generate a core dump, to

 be used for analysis of what situations led to the crash.

• A long autonomy also implies using as little power as possible: embeddedsystems often have to live a long time on batteries (e.g., mobile phones), or are partof a larger system with very limited power resources (e.g., satellites).• If the system does fail despite its designed robustness (e.g., caused by a memory

 protection fault, Section 1.1.4), there is usually no user around to take theappropriate actions. Hence, the system itself should reboot autonomously, in a“safe” state, and “instantly” if it is supposed to control other critical devices.

Page 38: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 38/47

41

Compare this to the booting of your desktop computer, which needs a minute ormore before it can be used, and always comes up in the same default state. . .

• It should be as cheap as possible. Embedded systems are often produced inquantities of several thousands or even millions. Decreasing the unit price even alittle bit boils down to enormous savings.

• Some embedded systems are not physically reachable anymore after they have been started (e.g., launched satellites) in order to add software updates. However,more and more of them can still be accessed remotely. Therefore, they shouldsupport dynamic linking : object code that did not exist at the time of start isuploaded to the system, and linked in the running OS without stopping it.

Some applications require all features of embedded and real-time operating

systems. The best known examples are mobile phones and (speech-operated)handheld computers (“PDA”s): they must be small, consume little power, and yet

 be able to execute advanced signal processing algorithms, while taking up as littlespace as possible.

The above-mentioned arguments led embedded OS developers to design systemswith the absolute minimum of software and hardware. Roughly speaking,developers of general purpose and real-time operating systems approach theirclients with a “ Hey, look how much we can do!” marketing strategy; while EOSdevelopers say “ Hey, look how little we need to do what you want!” Hence,

embedded systems often come without a memory management unit (MMU), multi-tasking, a networking “stack”, or file systems. The extreme is one singlemonolithic program on the bare processor, thus completely eliminating the needfor any operating system at all.

Taking out more and more features of a general purpose operating system makesits footprint smaller and its predictability higher. On the other hand, adding morefeatures to an EOS makes it look like a general purpose OS. Most current RTOSand EOS operating systems are expanding their ranges of application, and cover

more of the full “feature spectrum.”

Page 39: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 39/47

42

Threading and Synchronization in OS:-

One of the most useful developments in the history of computing is multitaskingand multithreading. This technique isn't always available to an embedded system

engineer, but some embedded systems and RTOS have multithreading (MT)capability. The chapters in this section will talk about some of the uses of MT, andwill discuss some of the common pitfalls associated with MT programming. This

 page is only going to serve as a brief reference to multi-threaded programming.

Preemptive Multithreading

When the first multi-tasking systems were established, they did not have a centralcontroller. Multi-tasking was established by having programs voluntarily give up

control to the system, and the system would then give control to another process.This system worked reasonably well, except that any program that wasmisbehaving would slow down the entire system. For instance, if a program gotstuck in an infinite loop, it would never give up control, and the system wouldfreeze.

The solution to this problem is preemptive multithreading. In a preemptiveenvironment, control could be moved from one process to another process at anygiven time. The process that was "preempted" would not even know that anythinghad happened, except maybe there would be a larger then average delay between 2

instructions. Preemptive multithreading allows for programs that do not voluntarilygive up control, and it also allows a computer to continue functioning when asingle process hangs.

Mutexes

The term Mutex is short for "Mutual Exclusion", and is a type of mechanism usedin a preemptive environment that can prevent unauthorized access to resources thatare currently in use. Mutexes follow several rules:

1. Mutexes are system wide objects that are maintained by the kernel.2. Mutexes can only be owned by one process at a time3. Mutexes can be acquired by asking the kernel to allocate that Mutex to the

current task 4. If a Mutex is already allocated, the request function will block until the

Mutex is available.

Page 40: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 40/47

43

Critical Sections

A critical section is a sequence of computer instructions that may malfunction ifinterrupted. An atomic operation is a sequence of computer instructions that cannot

 be interrupted and function correctly. In practice, these two subtly differentdefinitions are often combined. Operating systems provide synchronization objectsto meet these requirements, and some actually call these objects as "criticalsections," "atomic operations" or "monitors."

Priority Scheduling

Many RTOS have a mechanism to distinguish the relative priorities of differenttasks. High-priority tasks are executed more frequently than the low priority tasks.Each implementation of priority scheduling will be a little different, however.

Deadlock 

A deadlock  occurs when a series of synchronization objects are held in a preemptive MT system in such a way that no process can move forward. Let ustake a look at an example:

Let's say that we have 2 threads: T1 and T2. We also have 2 Mutexes, M1 and M2.

1. T1 asks for and acquires Mutex M1.

2. T2 acquires M23. T1 asks for M2, and the system transfers control to T2 until T2 releases M2.4. T2 asks for M1, and the system is in deadlock (neither thread can continue

until the other releases its Mutex).

This is a very difficult problem to diagnose, and an even more difficult problem tofix. This chapter will provide some general guide-lines for preventing deadlocks.

Watchdog Timer 

In an embedded environment, far away from the lab, and far away from the programmers, engineers, and technicians, all sorts of things can go wrong, and theembedded system needs to be able to fix itself. Remember, once you close the box,and shrink-wrap your product, it's hard to get back in there and fix your mistakes.

Page 41: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 41/47

44

In a typical computer systems, cosmic rays flip a bit of RAM about once a month.If that happens to the wrong bit, the program can "hang", stuck in a short infiniteloop.

Turning the power off then on again gets it unstuck. But how do you jiggle the power switch when you are on Earth and your embedded system is near Neptune?Or you are in Paris, and your embedded system is in Antarctica?

One of the most important tools of an embedded systems engineer is the Watch-

Dog Timer (WDT). A WDT is a timer with a very long fuse (several seconds,usually).

The WDT counts down toward zero (*), like the big red numbers counting downon the bombs in the movies. Left to itself, eventually the counter will reach zero.

When the counter reaches zero, the WDT resets the microcontroller (as if the power were turned off, then turned back on).

When the system is running normally, you don't want it to randomly reset itself, soyou need to make sure that your program always "feeds the watch-dog" long

 before time runs out. Good practice is to reset the WDT less than halfway-throughits countdown. For instance, if the WDT has a timer of 20 seconds, then you willwant to feed the WDT at least once every 10 seconds.

Unlike when our hero deals with bombs in the movies, feeding the watch-dog

doesn't stop the countdown. When the code uses a "reset" or "clear" command tofeed the watchdog, it merely sets the WDT back to some large number -- and thenthe watchdog timer immediately starts counting down from there.

If the programmer fails to feed the watchdog in time -- or if the program hangs forany reason -- then sooner or later WDT will time out, and the program will reset,hopefully getting your system unstuck.

(*) Some watchdogs count up. With this kind of watchdog, "feeding the watchdog"resets it to zero. If it ever reaches some high limit, it resets the system.

Page 42: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 42/47

45

Embedded Systems/Interrupts

Interrupts

Sometimes things will happen in a system when the processor is simply not ready.In fact, sometimes things change that require immediate attention. Can youimagine, sitting at your PC, that you were to hit buttons on the keyboard, andnothing happens on your computer? Maybe the processor was busy, and it justdidn’t check to see if you were hitting any buttons at that time. The solution to this

 problem is something called an "Interrupt." Interrupts are events that cause themicroprocessor to stop what it is doing, and handle a high-priority task first. Afterthe interrupt is handled, the microprocessor goes back to whatever it was doing

 before. In this way, we can be assured that high-priority inputs are never ignored.

Hardware and Software

There are two types of interrupts: Hardware and Software. Software interrupts arecalled from software, using a specified command. Hardware interrupts aretriggered by peripheral devices outside the microcontroller. For instance, yourembedded system may contain a timer that sends a pulse to the controller everysecond. Your microcontroller would wait until this pulse is received, and when the

 pulse comes, an interrupt would be triggered that would handle the signal.

Interrupt Service Routines

Interrupt Service Routines (ISR) are the portions of the program code that handlethe interrupt requests. When an Interrupt is triggered (either a hardware or softwareinterrupt), the processor breaks away from the current task, moves the instruction

 pointer to the ISR, and then continues operation. When the ISR has completed, the processor returns execution to the previous location.

Many embedded systems are called interrupt driven systems, because most of the processing occurs in ISRs, and the embedded system spends most of it's time in alow-power mode.

Sometimes ISR may be split into two parts: top-half (fast interrupt handler, First-Level Interrupt Handler (FLIH)) and bottom-half (slow interrupt handler, Second-Level Interrupt Handlers (SLIH)). Top-half is a faster part of ISR which shouldquickly store minimal information about interrupt and schedule slower bottom-halfat a later time.

Page 43: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 43/47

46

Interrupt vector table

The "interrupt vector table" is a list of every interrupt service routine. It is locatedat a fixed location in program memory. (Some processors expect the interruptvector table to be a series of "call" instructions, each one followed by the addressof the ISR. Other processors expect the interrupt vector table to hold just the ISRaddresses alone.)

You must make sure that every entry in the interrupt vector table is filled with theaddress of some actual ISR, even if it means making most of them point to the "donothing and return from interrupt" ISR.

RTOS Implementation

Memory Management 

An important point to remember is that some embedded systems are locked awayand expected to run for years on end without being rebooted. If we useconventional memory-management schemes to control memory allocation, we canend up with fragmented memory which can take valuable time to defragment andrallies is a major problem for tasks that are time-sensitive. This page then will talkabout how to implement a memory management scheme in an RTOS, and will talkthrough to a basic implementation of malloc ( ) and free ( ).

There are a variety of ways to deal with memory:

Some systems never do a malloc () or free () -- all memory is allocated atcompile time.

Some systems use malloc () and free () with manual garbage collection. Some early automatic garbage collection schemes did a "stop the world" for

several seconds during garbage collection and/or memory defragmentation.Such a system could miss real-time deadlines, which would be bad.

Some later automatic garbage collection schemes do "incremental" garbagecollection and memory defragmentation.

What is a Task 

Embedded systems have a microprocessor connected to some piece of hardware(LEDs, buttons, limit switches, motors, serial port(s), battery chargers, etc.).

Page 44: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 44/47

47

Each piece of hardware is generally associated with a little bit of software, called a"task". For example, "Check the keyboard and figure out which (if any) key has

 been pressed since the last check". Or "Check the current position of the spindle,and update the PID".

Often a task has real-time limits, such as

the motors must be shut off within 1/10 second after hitting the limit switchto avoid permanent damage

the PID loop must be updated at least every 1/100 second to avoidoscillation

the MP3 player must decode a new sample at 44.1 KHz -- no faster, or itsounds chipmunk-like -- no slower, or it sounds like it's underwater.

Some embedded systems have only one task.

Other embedded systems have a single microcontroller connected to manydifferent pieces of hardware -- they need to "multi-task".

What is the Scheduler 

The "task scheduler" (or often "scheduler") is the part of the software thatschedules which task to run next. The scheduler is the part of the software thatchooses which task to run next.

The scheduler is arguably the most difficult component of an RTOS to implement.Schedulers maintain a table of the current state of each task on the system, as wellas the current priority of each task. The scheduler needs to manage the timer too.

In general, there are 3 states that a task can be in:

1. Active. There can be only 1 active thread on a given processor at a time.2. Ready. This task is ready to execute, but is not currently executing.3. Blocked. This task is currently waiting on a lock or a critical section to

 become free.

Page 45: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 45/47

48

Some systems even allow for other states:

1. Sleeping. The task has voluntarily given up control for a certain period oftime.

2. Low-Priority. This task only runs when all other tasks are blocked orsleeping.

There are 2 ways the scheduler is called:

the current task voluntarily yield()s to the scheduler, calling the schedulerdirectly, or 

the current task has run "long enough", the timer hardware interrupts it, andthe timer interrupt routine calls the scheduler.

The scheduler must save the current status of the current task (save the contents ofall registers to a specified location), it must look through the list of tasks to find thehighest priority task in the Ready state, and then must switch control back to thattask (by restoring it's register values from memory).

The scheduler should first check to ensure that it is enabled. If the scheduler isdisabled, it shouldn't preempt the current thread. This can be accomplished bychecking a current global flag value. Some functions will want to disable thescheduler, so this flag should be accessible by some accessory method. Analternate method to maintaining a global flag is simply to say that any function that

wants to disable the scheduler can simply disable the timer. This way the schedulernever gets called, and never has to check any flags.

The scheduler is generally disabled inside a critical section, where we do not wantto OS to preempt the current thread. Otherwise, the scheduler should remain active.

WE ARE NOT CLAIM THAT OUR WORK IS UNIQUE, BUT WE CLAIMTHAT OUR EFFORTS ARE ALWAYS UNIQUE.

Page 46: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 46/47

49

C A N C L U S I O N : -

Many embedded systems have requirements that differ significantly bothin details and in scope from desktop computers. In particular, the

demands of the specific application and the interface with externalequipment may dominate the system design. Also, long life-cycles andin some cases extreme cost sensitivity require more attention tooptimization based on these goals rather than maximizing thecomputational throughput.

The business and cultural climates in many embedded system designsituations are such that traditional simulation-based computer designtechniques may not be viable in their current form. Such methodologiesmay not be cost-effective given constraints on categories ofexpenditures, may not be seen as worthwhile by non-computer-trained professionals, or may simply be solving the wrong problems.

Recent interest in hardware/software code sign is a step in the rightdirection, as it permits tradeoffs between hardware and software that arecritical for more cost-effective embedded systems. However, to besuccessful future tools may well need to increase scope even further to

include life-cycle issues and business issue. EMBEDDED SYSTEM IS NEVER ENDING INDUSTRY.

Page 47: Embedded_Systems - Introduction

7/23/2019 Embedded_Systems - Introduction

http://slidepdf.com/reader/full/embeddedsystems-introduction 47/47

B I B L I O G R A P H Y & R  E F E R E N C E S : -

We did learn and implement in parallel, so here is the list of sourcesfrom which we have taken the guidance.

B O O K S : -

FIRST STEP WITH EMBEDDED SYSTEMS E-BOOK.

  By: - Byte Craft Limited.

REAL-TIME AND EMBEDDED GUIDE.

  By: - Herman Bruyninckx

W E B S I T E S : -

www.en.wikipedia.org

www.en.wikibooks.org www.embeddedsystems.com www.microsoft\embedded.com