1. Trang chủ
  2. » Kỹ Thuật - Công Nghệ

Embedded systems design by steve heath

451 1,5K 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 451
Dung lượng 2,39 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

The term embedded systems design covers a very widerange of microprocessor designs and does not simply start andend with a simple microcontroller.. It is essential to know how to develop

Trang 2

Embedded Systems Design

Trang 3

By the same author

VMEbus: a practical companion

Newnes UNIX™ Pocket Book

Microprocessor architectures: RISC, CISC and DSP

Effective PC networking

PowerPC: a practical companion

The PowerPC Programming Pocket Book

The PC and MAC handbook

The Newnes Windows NT Pocket Book

Multimedia Communications

Essential Linux

Migrating to Windows NT

All books published by Butterworth-Heinemann

About the author:

Through his work with Motorola Semiconductors, the author has beeninvolved in the design and development of microprocessor-based systems since 1982.These designs have included VMEbus systems, microcontrollers, IBM PCs, AppleMacintoshes, and both CISC- and RISC-based multiprocessor systems, while usingoperating systems as varied as MS-DOS, UNIX, Macintosh OS and real-time kernels

An avid user of computer systems, he has had over 60 articles and papers published

in the electronics press, as well as several books

Trang 4

Embedded Systems Design

Second edition

Steve Heath

OXFORD AMSTERDAM BOSTON LONDON NEW YORK

PARIS SAN DIEGO SAN FRANCISCO SINGAPORE SYDNEY TOKYO

Trang 5

An imprint of Elsevier Science

Linacre House, Jordan Hill, Oxford OX2 8DP

200 Wheeler Road, Burlington MA 01803

First published 1997

Reprinted 2000, 2001

Second edition 2003

Copyright © 2003, Steve Heath All rights reserved

The right of Steve Heath to be identified as the author of this work

has been asserted in accordance with the Copyright, Designs and

Patents Act 1988

No part of this publication may be reproduced in any material form (including photocopying or storing in any medium by electronic means and whether or not transiently or incidentally to some other use of this publication) without the written permission of the copyright holder except in accordance with the provisions of the Copyright, Designs and Patents Act 1988 or under the terms

of a licence issued by the Copyright Licensing Agency Ltd, 90 Tottenham Court Road, London, England W1T 4LP Applications for the copyright holder’s written permission to reproduce any part of this publication should be addressed to the publisher

TRADEMARKS/REGISTERED TRADEMARKS

Computer hardware and software brand names mentioned in this book are protected by their respective trademarks and are acknowledged

British Library Cataloguing in Publication Data

A catalogue record for this book is available from the British Library

Library of Congress Cataloguing in Publication Data

A catalogue record for this book is available from the Library of Congress

ISBN 0 7506 5546 1

Typeset by Steve Heath

Trang 6

1 What is an embedded system? 1

Trang 9

Case 1: write through 108

Trang 10

Multi-master support 149

5 Interfacing to the analogue world 175

Trang 11

6 Interrupts and exceptions 189

7 Real-time operating systems 212

Trang 13

8 Writing software for embedded systems 288

Trang 14

9 Emulation and debugging techniques 321

Trang 15

10 Buffering and other data structures 339

11 Memory and performance trade-offs 357

Scenario 1 — Single cycle processor with

Trang 16

Task A highest priority 375

14 Real-time without a RTOS 398

Deriving real time performance from a non-real time system 400

Trang 18

The term embedded systems design covers a very widerange of microprocessor designs and does not simply start andend with a simple microcontroller It can be a PC running softwareother than Windows and word processing software It can be asophisticated multiprocessor design using the fastest processors

on the market today

The common thread to embedded systems design is anunderstanding of the interaction that the various componentswithin the system have with each other It is important to under-stand how the hardware works and the restraints that using acertain peripheral may have on the rest of the system It is essential

to know how to develop the software for such systems and theeffect that different hardware designs can have on the softwareand vice versa It is this system design knowledge that has beencaptured in this book as a series of tutorials on the various aspects

of embedded systems design

Chapter 1 defines what is meant by the term and in essencedefines the scope of the rest of the book The second chapterprovides a set of tutorials on processor architectures explainingthe different philosophies that were used in their design andcreation It covers many of the common processor architecturesranging from 8 bit microcontrollers through CISC and RISCprocessors and finally ending with digital signal processors andincludes information on the ARM processor family

The third chapter discusses different memory types andtheir uses This has been expanded in this edition to cover caches

in more detail and the challenges associated with them for ded design The next chapter goes through basic peripherals such

embed-as parallel and serial ports along with timers and DMA lers This theme is continued in the following chapter whichcovers analogue to digital conversion and basic power control.Interrupts are covered in great detail in the sixth chapterbecause they are so essential to any embedded design The differ-ent types that are available and their associated software routinesare described with several examples of how to use them and,perhaps more importantly, how not to use them

control-The theme of software is continued in the next two chapterswhich cover real-time operating systems and software develop-ment Again, these have a tremendous effect on embedded de-signs but whose design implications are often not well understood

or explained Chapter 9 discusses debugging and emulation niques

Trang 19

tech-The remaining five chapters are dedicated to design ples covering buffer and data structures, memory and processorperformance trade-offs and techniques, software design examplesincluding using a real-time operating system to create state ma-chines and finally a couple of design examples In this edition, anexample real-time system design is described that uses a non-real-time system to create an embedded system The C source code isprovided so that it can be run and experimented with on a PCrunning MS-DOS.

exam-Steve Heath

Trang 20

By the nature of this book, many hardware and softwareproducts are identified by their tradenames In these cases, thesedesignations are claimed as legally protected trademarks by thecompanies that make these products It is not the author’s nor thepublisher’s intention to use these names generically, and thereader is cautioned to investigate a trademark before using it as ageneric term, rather than a reference to a specific product to which

it is attached

Many of the techniques within this book can destroy dataand such techniques must be used with extreme caution Again,neither author nor publisher assume any responsibility or liabilityfor their use or any results

While the information contained in this book has beencarefully checked for accuracy, the author assumes no responsibil-ity or liability for its use, or any infringement of patents or otherrights of third parties which would result

As technical characteristics are subject to rapid change, thedata contained are presented for guidance and education only Forexact detail, consult the relevant standard or manufacturers’ dataand specification

Trang 22

1 What is an embedded

system?

Whenever the word microprocessor is mentioned, it jures up a picture of a desktop or laptop PC running an applicationsuch as a word processor or a spreadsheet While this is a popularapplication for microprocessors, it is not the only one and the fact

con-is most people use them indirectly in common objects and ances without realising it Without the microprocessor, theseproducts would not be as sophisticated or cheap as they are today.The embedding of microprocessors into equipment andconsumer appliances started before the appearance of the PC andconsumes the majority of microprocessors that are made today Inthis way, embedded microprocessors are more deeply ingrainedinto everyday life than any other electronic circuit that is made Alarge car may have over 50 microprocessors controlling functionssuch as the engine through engine management systems, brakeswith electronic anti-lock brakes, transmission with traction con-trol and electronically controlled gearboxes, safety with airbagsystems, electric windows, air-conditioning and so on With awell-equipped car, nearly every aspect has some form of elec-tronic control associated with it and thus a need for a microproc-essor within an embedded system

appli-A washing machine may have a microcontroller that tains the different washing programs, provides the power controlfor the various motors and pumps and even controls the displaythat tells you how the wash cycles are proceeding

con-Mobile phones contain more processing power than a top processor of a few years ago Many toys contain microproces-sors and there are even kitchen appliances such as bread machinesthat use microprocessor-based control systems The word control

desk-is very apt for embedded systems because in virtually everyembedded system application, the goal is to control an aspect of aphysical system such as temperature, motion, and so on using avariety of inputs With the recent advent of the digital age replac-ing many of the analogue technologies in the consumer world, thedominance of the embedded system is ever greater Each digitalconsumer device such as a digital camera, DVD or MP3 player alldepend on an embedded system to realise the system As a result,the skills behind embedded systems design are as diverse as thesystems that have been built although they share a commonheritage

Trang 23

What is an embedded system?

There are many definitions for this but the best way todefine it is to describe it in terms of what it is not and with examples

of how it is used

An embedded system is a microprocessor-based systemthat is built to control a function or range of functions and is notdesigned to be programmed by the end user in the same way that

a PC is Yes, a user can make choices concerning functionality butcannot change the functionality of the system by adding/replac-ing software With a PC, this is exactly what a user can do: oneminute the PC is a word processor and the next it’s a gamesmachine simply by changing the software An embedded system

is designed to perform one particular task albeit with choices anddifferent options The last point is important because it differenti-ates itself from the world of the PC where the end user doesreprogram it whenever a different software package is bought andrun However, PCs have provided an easily accessible source ofhardware and software for embedded systems and it should be nosurprise that they form the basis of many embedded systems Toreflect this, a very detailed design example is included at the end

of this book that uses a PC in this way to build a sophisticated datalogging system for a race car

If this need to control the physical world is so great, what is

so special about embedded systems that has led to the widespreaduse of microprocessors? There are several major reasons and thesehave increased over the years as the technology has progressedand developed

Replacement for discrete logic-based circuits

The microprocessor came about almost by accident as aprogrammable replacement for calculator chips in the 1970s Up tothis point, most control systems using digital logic were imple-mented using individual logic integrated circuits to create thedesign and as more functionality became available, the number ofchips was reduced

This was the original reason for a replacement for digitalsystems constructed from logic circuits The microprocessor wasoriginally developed to replace a mass of logic that was used tocreate the first electronic calculators in the early 1970s For exam-ple, the early calculators were made from discrete logic chips andmany hundreds were needed just to create a simple four functioncalculator As the integrated circuit developed, the individuallogic functions were integrated to create higher level functions.Instead of creating an adder from individual logic gates, a com-plete adder could be bought in one package It was not long beforecomplete calculators were integrated onto a single chip Thisenabled them to be built at a very low cost compared to the originalmachines but any changes or improvements required that a new

Trang 24

chip be developed The answer was to build a chip that had someform of programmable capability within it Why not build a chipthat took data in, processed it and sent it out again? In this way,instead of creating new functions by analysing the gate level logicand modifying it — a very time-consuming process — newproducts could be created by changing the program code thatprocessed the information Thus the microprocessor was born.

Provide functional upgrades

In the same way that the need to develop new calculatorchips faster and with less cost prompted the development of thefirst microprocessors, the need to add or remove functionalityfrom embedded system designs is even more important Withmuch of the system’s functionality encapsulated in the softwarethat runs in the system, it is possible to change and upgradesystems by changing the software while keeping the hardware thesame This reduces the cost of production even lower becausemany different systems can share the same hardware base

In some cases, this process is not possible or worthwhile butallows the manufacturer to develop new products far quicker andfaster Examples of this include timers and control panels fordomestic appliances such as VCRs and televisions

In other cases, the system can be upgraded to improvefunctionality This is frequently done with machine tools, tel-ephone switchboards and so on The key here is that the ability toadd functionality now no longer depends on changing the hard-ware but can be done by simply changing the software If thesystem is connected to a communications link such as a telephone

or PC network, then the upgrade can be done remotely withouthaving to physically send out an engineer or technician

Provide easy maintenance upgrades

The same mechanism that allows new functionality to beadded through reprogramming is also beneficial in allowing bugs

to be solved through changing software Again it can reduce theneed for expensive repairs and modifications to the hardware

Improves mechanical performance

For any electromechanical system, the ability to offer a finerdegree of control is important It can prevent excessive mechanicalwear, better control and diagnostics and, in some cases, actuallycompensate for mechanical wear and tear A good example of this

is the engine management system Here, an embedded essor controls the fuel mixture and ignition for the engine and willalter the parameters and timing depending on inputs from theengine such as temperature, the accelerator position and so on Inthis way, the engine is controlled far more efficiently and can beconfigured for different environments like power, torque, fuelefficiency and so on As the engine components wear, it can even

Trang 25

microproc-adjust the parameters to compensate accordingly or if they aredramatically out of spec, flag up the error to the driver or indicatethat servicing is needed.

This level of control is demonstrated by the market in

‘chipped’ engine management units where third party companiesmodify the software within the control unit to provide morepower or torque The differences can range from 10% to nearly50% for some turbo charged engines! All this from simply chang-ing a few bytes Needless to say, this practice may invalidate anyguarantee from the manufacturer and may unduly stress and limitthe engine’s mechanical life In some cases, it may even infringethe original manufacturer’s intellectual property rights

Protection of intellectual property

To retain a competitive edge, it is important to keep thedesign knowledge within the company and prevent others fromunderstanding exactly what makes a product function This knowl-edge, often referred to as IPR (intellectual property rights), be-comes all important as markets become more competitive With adesign that is completely hardware based and built from off-the-shelf components, it can be difficult to protect the IPR that wasused in its design All that is needed to do is to take the product,identify the chips and how they are connected by tracing the tracks

on the circuit board Some companies actually grind the partnumbers off the integrated circuits to make it harder to reverseengineer in this way

With an embedded system, the hardware can be identifiedbut the software that really supplies the system’s functionality can

be hidden and more difficult to analyse With self-containedmicrocontrollers, all that is visible is a plastic package with a fewconnections to the outside world The software is already burntinto the on-chip memory and is effectively impossible to access As

a result, the IPR is much more secure and protected

Replacement for analogue circuits

The movement away from the analogue domain towardsdigital processing has gathered pace recently with the advent ofhigh performance and low cost processing

To understand the advantages behind digital signal ing, consider a simple analogue filter The analogue implementa-tion is extremely simple compared to its digital equivalent Theanalogue filter works by varying the gain of the operational

process-amplifier which is determined by the relationship between ri and rf.

In a system with no frequency component, the capacitor ci plays no part as its impedance is far greater than that of rf As the

frequency component increases, the capacitor impedance

de-creases until it is about equal with rf where the effect will be to

reduce the gain of the system As a result, the amplifier acts as a

Trang 26

low pass filter where high frequencies will be filtered out Theequation shows the relationship where jω is the frequency compo-nent These filters are easy to design and are cheap to build Bymaking the CR (capacitor-resistor) network more complex, differ-ent filters can be designed.

y(t) x(t)=

rf

ri 1 + jω r c

1

f f

y(t) Output

to actuator

x(t) Input from sensor

t

y(t) x(t)

ri

rf

cf

The required filtering

The analogue circuit

The mathematical function

Analogue signal processing

x(t)

FIR filter

Finite impulse response

∑c(n) x (n-k) n

k = 0

D/A

Low pass antialiasing filter

Sampler and analogue

to digital converter

Digital signal processing operation

Digital

to analogue converter

Reconstruction low pass filter

Analogue out Analogue

in

Digital signal processing (DSP)

The digital equivalent is more complex requiring severalelectronic stages to convert the data, process it and reconstitute thedata The equation appears to be more involved, comprising of asummation of a range of calculations using sample data multi-plied by a constant term These constants take the place of the CR

Trang 27

components in the analogue system and will define the filter’stransfer function With digital designs, it is the tables of coeffi-cients that are dynamically modified to create the different filtercharacteristics.

Given the complexity of digital processing, why then use it?The advantages are many Digital processing does not suffer fromcomponent ageing, drift or any adjustments which can plague ananalogue design They have high noise immunity and powersupply rejection and due to the embedded processor can easilyprovide self-test features The ability to dynamically modify thecoefficients and therefore the filter characteristics allows complexfilters and other functions to be easily implemented However, theprocessing power needed to complete the ‘multiply–accumulate’processing of the data does pose some interesting processingrequirements

N instruction routine

x(n) x(n+1) Ts=1/F

A/D conversion

Data sampling

at frequency Fs

D/A conversion

Time to execute one instruction Ts Fs

1kHz

10 kHz

100 kHz 1MHz

1 ms

100 µs

10 µs

1 µs 1kHz

10 kHz

100 kHz 1MHz

The diagram shows the problem An analogue signal is

sampled at a frequency fs and is converted by the A/D converter.

This frequency will be first determined by the speed of this

conversion At every period, ts, there will be a new sample to process using N instructions The table shows the relationship

between sampling speed, the number of instructions and the

Trang 28

instruction execution time It shows that the faster the samplingfrequency, the more processing power is needed To achieve the 1MHz frequency, a 10 MIPS processor is needed whose instructionset is powerful enough to complete the processing in under 10instructions This analysis does not take into account A/D conver-sion delays For DSP algorithms, the sampling speed is usuallytwice the frequency of the highest frequency signal being proc-essed: in this case the 1 MHz sample rate would be adequate forsignals up to 500 kHz.

One major difference between analogue and digital filters isthe accuracy and resolution that they offer Analogue signals mayhave definite limits in their range, but have infinite values be-tween that range Digital signal processors are forced to representthese infinite variations within a finite number of steps deter-mined by the number of bits in the word With an 8 bit word, theincreases are in steps of 1/256 of the range With a 16 bit word, suchsteps are in 1/65536 and so on Depicted graphically as shown, a

16 bit word would enable a low pass filter with a roll-off of about

90 dB A 24 bit word would allow about 120 dB roll-off to beachieved

dB 0dB

Frequency

16 bit

24 bit

Word size and cutoff frequencies

DSP can be performed by ordinary microprocessors, though their more general-purpose nature often limits perform-ance and the frequency response However, with responses ofonly a few hundred Hertz, even simple microcontrollers canperform such tasks As silicon technology improved, special build-ing blocks appeared allowing digital signal processors to bedeveloped, but their implementation was often geared to a hard-ware approach rather than designing a specific processor architec-ture for the job It is now common for processors to claim DSP

Trang 29

al-support through enhanced multiply–accumulate operations orthrough special accelerators It is clear though, that as generalpurpose processing increases in capability, what was once the soleprovince of a DSP can now be achieved by a general purposeprocessor.

Inside the embedded system

Processor

The main criteria for the processor is: can it provide theprocessing power needed to perform the tasks within the system?This seems obvious but it frequently occurs that the tasks are eitherunderestimated in terms of their size and/or complexity or thatcreeping elegance expands the specification to beyond the proces-sor’s capability

In many cases, these types of problems are compounded bythe performance measurement used to judge the processor Bench-marks may not be representative of the type of work that thesystem is doing They may execute completely out of cache memoryand thus give an artificially high performance level which the finalsystem cannot meet because its software does not fit in the cache.The software overheads for high level languages, operating sys-tems and interrupts may be higher than expected These are allissues that can turn a paper design into failed reality

While processor performance is essential and forms the firstgating criterion, there are others such as cost — this should besystem cost and not just the cost of the processor in isolation,power consumption, software tools and component availabilityand so on These topics are discussed in more detail in Chapter 2

Memory

Memory is an important part of any embedded systemdesign and is heavily influenced by the software design, and inturn may dictate how the software is designed, written anddeveloped These topics will be addressed in more detail later on

in this book As a way of introduction, memory essentially forms two functions within an embedded system:

per-• It provides storage for the software that it will run

At a minimum, this will take the form of some non-volatilememory that retains its contents when power is removed.This can be on-chip read only memory (ROM) or externalEPROM The software that it contains might be the com-plete program or an initialisation routine that obtains thefull software from another source within or outside of thesystem This initialisation routine is often referred to as abootstrap program or routine PC boards that have embed-ded processors will often start up using software stored in

an onboard EPROM and then wait for the full software to bedownloaded from the PC across the PC expansion bus

Trang 30

• It provides storage for data such as program variables andintermediate results, status information and any other datathat might be created throughout the operation

Software needs some memory to store variables and tomanage software structures such as stacks The amount ofmemory that is needed for variables is frequently less thanthat needed for the actual program With RAM being moreexpensive than ROM and non-volatile, many embeddedsystems and in particular, microcontrollers, have smallamounts of RAM compared to the ROM that is available forthe program As a result, the software that is written forsuch systems often has to be written to minimise RAMusage so that it will fit within the memory resources placedupon the design This will often mean the use of compilersthat produce ROMable code that does not rely on beingresident in RAM to execute This is discussed in more detail

in Chapter 3

Peripherals

An embedded system has to communicate with the outsideworld and this is done by peripherals Input peripherals areusually associated with sensors that measure the external environ-ment and thus effectively control the output operations that theembedded system performs In this way, an embedded system can

be modelled on a three-stage pipeline where data and informationinput into the first stage of the pipeline, the second stage processes

it before the third stage outputs data

If this model is then applied to a motor controller, the inputswould be the motor’s actual speed and power consumption, andthe speed required by the operator The outputs would be a pulsewidth modulated waveform that controls the power to the motorand hence the speed and an output to a control panel showing thecurrent speed The middle stage would be the software thatprocessed the inputs and adjusts the outputs to achieve the re-quired engine speed The main types of peripherals that are usedinclude:

• Binary outputsThese are simple external pins whose logic state can becontrolled by the processor to either be a logic zero (off) or

a logic one (on) They can be used individually or groupedtogether to create parallel ports where a group of bits can beinput or output simultaneously

• Serial outputsThese are interfaces that send or receive data using one ortwo pins in a serial mode They are less complex to connectbut are more complicated to program A parallel port looksvery similar to a memory location and is easier to visualiseand thus use A serial port has to have data loaded into a

Trang 31

register and then a start command issued The data mayalso be augmented with additional information as required

by the protocol

• Analogue valuesWhile processors operate in the digital domain, the naturalworld does not and tends to orientate to analogue values

As a result, interfaces between the system and the externalenvironment need to be converted from analogue to digitaland vice versa

• DisplaysDisplays are becoming important and can vary from simpleLEDs and seven segment displays to small alpha-numericLCD panels

• Time derived outputsTimers and counters are probably the most commonly usedfunctions within an embedded system

Software

The software components within an embedded systemoften encompasses the technology that adds value to the systemand defines what it does and how well it does it The software canconsist of several different components:

• Initialisation and configuration

• Operating system or run-time environment

• The applications software itself

While this standardisation could mean that the importance

of selecting an algorithm is far less than it might be thought, thereality is far different The focus on getting the right implementa-tion is important since, for example, it may allow the same func-tion to be executed on cheaper hardware As most embeddedsystems are designed to be commercially successful, this selectionprocess is very important Defining and implementing the correctalgorithm is a critical operation and is described through severalexamples in this book

Trang 32

This section will go through some example embeddedsystems and briefly outline the type of functionality that eachoffers

Microcontroller

Microcontrollers can be considered as self-contained tems with a processor, memory and peripherals so that in manycases all that is needed to use them within an embedded system is

sys-to add software The processors are usually based on 8 bit based architectures such as the MC6800 family There are 4 bitversions available such as the National COP series which furtherreduce the processing power and reduce cost even further Theseare limited in their functionality but their low cost has meant thatthey are used in many obscure applications Microcontrollers areusually available in several forms:

stack-• Devices for prototyping or low volume production runsThese devices use non-volatile memory to allow the soft-ware to be downloaded and returned in the device UVerasable EPROM used to be the favourite but EEPROM isalso gaining favour Some microcontrollers used a specialpackage with a piggyback socket on top of the package toallow an external EPROM to be plugged in for prototyping.This memory technology replaces the ROM on the chipallowing software to be downloaded and debugged Thedevice can be reprogrammed as needed until the softwarereaches its final release version

The use of non-volatile memory also makes these devicessuitable for low volume production runs or where thesoftware may need customisation and thus preventingmoving to a ROMed version

These devices are sometimes referred to as umbrella vices with a single device capable of providing prototypingsupport for a range of other controllers in the family

de-• Devices for low to medium volume production runs

In the mid-1980s, a derivative of the prototype deviceappeared on the market called the one time programmable

or OTP These devices use EPROM instead of the ROM butinstead of using the ceramic package with a window toallow the device to be erased, it was packaged in a cheaperplastic pack and thus was only capable of programming asingle time — hence the name These devices are cheaperthan the prototype versions but still have the programmingdisadvantage However, their lower cost has made them asuitable alternative to producing a ROM device For low tomedium production quantities, they are cost effective andoffer the ability to customise software as necessary

Trang 33

4144 bytes EPROM

176 bytesRAM

240 bytes Boot ROM

HC05 processor coreClock

Watchdog Baud rate

Example microcontroller (Motorola MC68HC705C4A)

• Devices for high volume production runsFor high volumes, microcontrollers can be built alreadyprogrammed with software in the ROM To do this acustomer supplies the software to the manufacturer whothen creates the masks necessary to create the ROM in thedevice This process is normally done on partly processedsilicon wafers to reduce the turnaround time The advan-tage for the customer is that the costs are much lower thanusing prototyping or OTP parts and there is no program-ming time or overhead involved The downside is that there

is usually a minimum order based on the number of chipsthat a wafer batch can produce and an upfront mask charge.The other major point is that once in ROM, the softwarecannot be changed and therefore customisation or bugfixing would have to wait until the next order or involvescrapping all the devices that have been made It is possible

to offer some customisation by including different softwaremodules and selecting the required ones on the basis of avalue read into the device from an external port but thisdoes consume memory which can increase the costs Somecontrollers can provide some RAM that can be used to patchthe ROM without the need for a new mask set

Trang 34

MC68HC 705

MC68HC 705

EPROM prototyping

OTP External

EPROM (no chip)

ExternalEPROM (with chip)

Prototype microcontrollers

Expanded microcontroller

The choice of memory sizes and partitioning is usually amajor consideration Some applications require more memory orperipherals than are available on a standard part Mostmicrocontroller families have parts that support external expan-sion and have an external memory and/or I/O bus which canallow the designer to put almost any configuration together This

is often done by using a parallel port as the interface instead ofgeneral-purpose I/O Many of the higher performancemicrocontrollers are adopting this approach

Trang 35

In the example shown on the previous page, themicrocontroller has an expanded mode that allows the parallelports A and B to be used as byte wide interfaces to external RAMand ROM In this type of configuration, some microcontrollersdisable access to the internal memory while others still allow it.

Microprocessor based

Microprocessor-based embedded systems originally tookexisting general-purpose processors such as the MC6800 and 8080devices and constructed systems around them using externalperipherals and memory The use of processors in the PC marketcontinued to provide a series of faster and faster processors such

as the MC68020, MC68030 and MC68040 devices from Motorolaand the 80286, 80386, 80486 and Pentium devices from Intel TheseCISC architectures have been complemented with RISC proces-sors such as the PowerPC, MIPS and others These systems offermore performance than is usually available from a traditionalmicrocontroller

However, this is beginning to change There has been thedevelopment of integrated microprocessors where the processor

is combined with peripherals such as parallel and serial ports,DMA controllers and interface logic to create devices that are moresuitable for embedded systems by reducing the hardware designtask and costs As a result, there has been almost a paralleldevelopment of these integrated processors along with the desk-top processors Typically, the integrated processor will use aprocessor generation that is one behind the current generation.The reason is dependent on silicon technology and cost By usingthe previous generation which is smaller, it frees up silicon area onthe die to add the peripherals and so on

Board based

So far, the types of embedded systems that we have ered have assumed that the hardware needs to be designed, builtand debugged An alternative is to use hardware that has alreadybeen built and tested such as board-based systems as provided byPCs and through international board standards such as VMEbus.The main advantage is the reduced work load and the availability

consid-of ported sconsid-oftware that can simply be utilised with very littleeffort The disadvantages are higher cost and in some casesrestrictions in the functionality that is available

Trang 36

process-There are essentially four basic architecture types which areusually defined as 8 bit accumulator, 16/32 bit complex instruc-tion set computers (CISC), reduced instruction set computer (RISC)architectures and digital signal processors (DSP) Their develop-ment or to be more accurate, their availability to embedded systemdesigners is chronological and tends to follow the same type ofpattern as shown in the graph.

Processor life history

However, it should be remembered that in parallel with thislife cycle, processor architectures are being moved intomicrocontroller and integrated processor devices so that the end

of life really refers to the discontinuance of the architecture as aseparate CPU plus external memory and peripherals product TheMC6800 processor is no longer used in discrete designs but thereare over 200 MC6801/6805 and 68HC11 derivatives that essen-tially use the same basic architecture and instruction set

Trang 37

8 bit accumulator processors

This category of processor first appeared in the mid-1970s

as the first microprocessors Devices such as the 8080 from Inteland the MC6800 from Motorola started the microprocessor revo-lution They provided about 1 MIP of performance and were attheir introduction the fastest processors available

Register models

The programmer has a very simple register model for thistype of processor The model for the Motorola MC6800 8 bitprocessor is shown as an example but it is very representative ofthe many processors that appeared (and subsequently vanished)

It has two 8 bit accumulators used for storing data and performingarithmetic operations The program counter is 16 bits in size andtwo further 16 bit registers are provided for stack manipulationsand address indexing

The MC6800 programmer's model

On first inspection, the model seems quite primitive and notcapable of providing the basis of a computer system There do notseem to be enough registers to hold data, let alone manipulate it!Comparing this with the register laden RISC architectures thatfeature today, this is a valid conclusion What is often forgotten isthat many of the instructions, such as logical operations, canoperate on direct memory using the index register to act as pointer.This removes the need to bring data into the processor at theexpense of extra memory cycles and the need for additional orwider registers The main area within memory that is used for datastorage is known as the stack It is normally accessed using aspecial register that indexes into the area called the stack pointer

Trang 38

This is used to provide local data storage for programs and to storeinformation for the processor such as return addresses for subrou-tine jumps and interrupts.

The stack pointer provides additional storage for the grammer: it is used to store data like return addresses for subrou-tine calls and provides additional variable storage using a PUSH/POP mechanism Data is PUSHed onto the stack to store it, andPOPed off to retrieve it Providing the programmer can trackwhere the data resides in these stack frames, it offers a goodreplacement for the missing registers

pro-8 bit data restrictions

An 8 bit data value can provide an unsigned resolution ofonly 256 bits, which makes it unsuitable for applications where ahigher resolution is needed In these cases, such as financial,arithmetic, high precision servo control systems, the obvioussolution is to increase the data size to 16 bits This would give aresolution of 65536 — an obvious improvement This may beacceptable for a control system but is still not good enough for adata processing program, where a 32 bit data value may have to bedefined to provide sufficient integer range While there is nodifficulty with storing 8, 16, 32 or even 64 bits in external memory,even though this requires multiple bus accesses, it does preventthe direct manipulation of data through the instruction set.However, due to the register model, data larger than 8 bitscannot use the standard arithmetic instructions applicable to 8 bitdata stored in the accumulator This means that even a simple 16bit addition or multiplication has to be carried out as a series ofinstructions using the 8 bit model This reduces the overall effi-ciency of the architecture

The code example is a routine for performing a simple 16 bitmultiplication It takes two unsigned 16 bit numbers and produces

a 16 bit product If the product is larger than 16 bits, only the leastsignificant 16 bits are retained The first eight or so instructionssimply create a temporary storage area on the stack for themultiplicand, multiplier, return address and loop counter Com-pared to internal register storage, storing data in stack frames isnot as efficient due the increased external memory access.Accessing external data consumes machine cycles whichcould be used to process data Without suitable registers and the

16 bit wide accumulator, all this information must be storedexternally on the stack The algorithm used simply performs asuccession of arithmetic shifts on each half of the multiplicandstored in the A and B accumulators Once this is complete, the 16bit result is split between the two accumulators and the temporarystorage cleared off the stack The operation takes at least 29instructions to perform with the actual execution time totallydependant on the values being multiplied together For compari-son, most 16/32 bit processors such as the MC68000 and 80x86families can perform the same operation with a single instruction!

Trang 39

MULT16 LDX #5 CLEAR WORKING REGISTERS

DEX

Addressing memory

When the first 8 bit microprocessors appeared during themiddle to late 1970s, memory was expensive and only available invery small sizes: 256 bytes up to 1 kilobyte Applications weresmall, partly due to their implementation in assembler rather than

a high level language, and therefore the addressing range of 64kilobytes offered by the 16 bit address seemed extraordinarilylarge It was unlikely to be exceeded As the use of these earlymicroprocessors became more widespread, applications started

to grow in size and the use of operating systems like CP/M andhigh level languages increased memory requirements until theaddress range started to limit applications Various techniqueslike bank switching and program overlays were developed tohelp

Trang 40

System integrity

Another disadvantage with this type of architecture is itsunpredictability in handling error conditions A bug in a softwareapplication could corrupt the whole system, causing a system toeither crash, hang up or, even worse, perform some unforeseenoperations The reasons are quite simple: there is no partitioningbetween data and programs within the architecture An applica-tion can update a data structure using a corrupt index pointerwhich overwrites a part of its program

start

finish

Addresspointer

Newdata start

finish

System memory

Addresspointer

System MemoryNewdata

Valid pointeraddress

Invalid pointeraddress

System corruption via an invalid

pointer

Data are simply bytes of information which can be preted as instruction codes The processor calls a subroutinewithin this area, starts to execute the data as code and suddenly thewhole system starts performing erratically! On some machines,certain undocumented code sequences could put the processor in

inter-a test mode inter-and stinter-art cycling through the inter-address rinter-anges etc Theseattributes restricted their use to non-critical applications

Example 8 bit architectures

Z80

The Z80 microprocessor is an 8 bit CPU with a 16 bit addressbus capable of direct access to 64k of memory space It wasdesigned by Zilog and rapidly gained a lot of interest The Z80 wasbased on the Intel 8080 but has an extended instruction set andmany hardware improvements It can run 8080 code if needed byits support of the 8080 instruction set The instruction set isessential based around an 8 bit op code giving a maximum of 256instructions The 158 instructions that are specified — the others

Ngày đăng: 08/03/2016, 11:32

TỪ KHÓA LIÊN QUAN