1、Embedded Systems ArchitectureThis Page Intentionally Left BlankAMSTERDAM?BOSTON?HEIDELBERG?LONDONNEWYORK?OXFORD?PARIS?SAN DIEGOSAN FRANCISCO?SINGAPORE?SYDNEY?TOKYO?Embedded Systems ArchitectureA Comprehensive Guide for Engineers and Programmers ByTammy NoergaardNewnes is an imprint of Elsevier30 Cor
2、porate Drive,Suite 400,Burlington,MA 01803,USALinacre House,Jordan Hill,Oxford OX2 8DP,UKCopyright 2005,Elsevier Inc.All rights reserved.No part of this publication may be reproduced,stored in a retrieval system,ortransmitted in any form or by any means,electronic,mechanical,photocopying,recording,o
3、r otherwise,without the prior written permission of the publisher.Permissions may be sought directly from Elseviers Science&Technology RightsDepartment in Oxford,UK:phone:(+44)1865 843830,fax:(+44)1865 853333,e-mail:.uk.You may also complete your request on-line viathe Elsevier homepage(http:/),by s
4、electing“Customer Support”and then“Obtaining Permissions.”Recognizing the importance of preserving what has been written,Elsevier prints its books on acid-free paper whenever possible.Library of Congress Cataloging-in-Publication Data(Application submitted.)British Library Cataloguing-in-Publication
5、 DataA catalogue record for this book is available from the British Library.ISBN:0-7506-7792-9For information on all Newnes publicationsvisit our Web site at 04 05 06 07 08 0910 9 8 7 6 5 4 3 2 1Printed in the United States ofAmericaDedicationTo the engineer and man I respect and admire the most,my
6、father,Dr.Al M.ZiedThis Page Intentionally Left BlankviiContentsForeword.xiAcknowledgments.xiiiAbout the Author.xivSection I:Introduction to Embedded Systems.1Chapter 1:A Systems Engineering Approach to Embedded Systems Design.51.1 What Is an Embedded System?.51.2 Embedded Systems Design.71.3 An Int
7、roduction to Embedded SystemsArchitecture.91.4 Why Is theArchitecture of an Embedded System Important?.111.5 The Embedded Systems Model.121.6 Summary.13Chapter 1 Problems.15Chapter 2:Know Your Standards.172.1 An Overview of Programming Languages and Examples of Their Standards.302.2 Standards and Ne
8、tworking.462.3 Multiple Standards-Based Device Example:Digital Television(DTV).652.4 Summary.67Chapter 2 Problems.69Section II:Embedded Hardware.73Chapter 3:Embedded Hardware Building Blocks and the Embedded Board.773.1 Lesson One on Hardware:Learn to Read a Schematic!.773.2 The Embedded Board and t
9、he von Neumann Model.823.3 Powering the Hardware.873.4 Basic Hardware Materials:Conductors,Insulators,and Semiconductors.893.5 Common Passive Components on Boards and in Chips:Resistors,Capacitors,and Inductors.933.6 Semiconductors and theActive Building Blocks of Processors and Memory.1013.7 Puttin
10、g ItAll Together:The Integrated Circuit(IC).1173.8 Summary.121Chapter 3 Problems.122ContentsviiiChapter 4:Embedded Processors.1294.1 ISAArchitecture Models.1314.2 Internal Processor Design.1454.3 Processor Performance.2034.4 Reading a Processors Datasheet.2064.5 Summary.218Chapter 4 Problems.219Chap
11、ter 5:Board Memory.2235.1 Read-Only Memory(ROM).2275.2 Random-Access Memory(RAM).2325.3 Auxiliary Memory.2425.4 Memory Management of External Memory.2475.5 Board Memory and Performance.2495.6 Summary.250Chapter 5 Problems.251Chapter 6:Board I/O(Input/Output).2536.1 Managing Data:Serial vs.Parallel I
12、/O.2576.2 Interfacing the I/O Components.2776.3 I/O and Performance.2806.4 Summary.282Chapter 6 Problems.283Chapter 7:Board Buses.2877.1 BusArbitration and Timing.2897.2 Integrating the Bus with Other Board Components.2997.3 Bus Performance.3007.4 Summary.301Chapter 7 Problems.302Section III:Embedde
13、d Software Introduction.307Chapter 8:Device Drivers.3118.1 Example 1:Device Drivers for Interrupt-Handling.3158.2 Example 2:Memory Device Drivers.3328.3 Example 3:On-board Bus Device Drivers.3518.4 Board I/O Driver Examples.3588.5 Summary.379Chapter 8 Problems.380Chapter 9:Embedded Operating Systems
14、.3839.1 What Is a Process?.3889.2 Multitasking and Process Management.3909.3 Memory Management.421Contentsix9.4 I/O and File System Management.4359.5 OS Standards Example:POSIX(Portable Operating System Interface).4379.6 OS Performance Guidelines.4399.7 OSes and Board Support Packages(BSPs).4409.8 S
15、ummary.441Chapter 9 Problems.442Chapter 10:Middleware and Application Software.44510.1 What Is Middleware?.44510.2 What Is anApplication?.44710.3 Middleware Examples.44710.4Application Layer Software Examples.48410.5 Summary.498Chapter 10 Problems.499Section IV:Putting It All Together:Design and Dev
16、elopment.505Chapter 11:Defining the SystemCreating the Architecture and Documenting the Design.50911.1 Creating an Embedded SystemArchitecture.510 Stage 1:Have a Solid Technical Foundation.511 Stage 2:Know theABCs(Architecture Business Cycles)of Embedded Systems.512 Stage 3:Define theArchitectural P
17、atterns and Reference Models.523 Stage 4:Define theArchitectural Structures.530 Stage 5:Document theArchitecture.533 Stage 6:Analyze and Evaluate theArchitecture.53511.2 Summary.537Chapter 11 Problems.538Chapter 12:The Final Phases of Embedded Design:Implementation and Testing.54112.1 Implementing t
18、he Design.541 12.1.1 The Main Software Utility Tool:Writing Code in an Editor or IDE.542 12.1.2 Computer-Aided Design(CAD)and the Hardware.543 12.1.3 Translation ToolsPreprocessors,Interpreters,Compilers,and Linkers.545 12.1.4 Debugging Tools.548 12.1.5 System Boot-Up.55512.2 QualityAssurance and Te
19、sting of the Design.56312.3 Conclusion:Maintaining the Embedded System and Beyond.566Chapter 12 Problems.567Appendix A:Projects and Exercises.571Section I Projects.574Section II Projects.578ContentsxSection III Projects.586Section IV Projects.589Appendix B:Schematic Symbols.594Appendix C:Acronyms an
20、d Abbreviations.601Appendix D:Glossary.610Index.627Whats on the CD-ROM.640 xiWhen Tammy Noergaard first told me she wanted to write a soup-to-nuts book about buildingembedded systems I tried to dissuade her.This field is so vast,requiring insight into electron-ics,logic circuits,computer design,soft
21、ware engineering,C,assembly,and far more.But aswe talked she showed me how the industrys literature lacks a definitive work on the subject.Iwarned her of the immensity of the project.A year and many discussions later Fedex arrived with the review copy of this book.At over700 pages its appropriately
22、twice the size of almost any other opus on the subject.The bookyoure holding truly is“A Comprehensive Guide for Engineers and Programmers.”Sure,theminutia of programming a PICs timer might have been left out,but the scope is vast andimportant.Tammy starts with the first principles of electronics and
23、 advances through software to the ex-pensive end-phase of maintenance.She treats hardware and software as an integrated whole,which sort of defines the nature of embedded systems.Ironically,though,developers are in-creasingly specialized.More than a few software folks havent a clue about transistors
24、 whiletoo many EEs cant accurately define middleware.I fear readers may skip those chapters thatdont immediately pertain to the project at hand.Resist any such temptation,gentle reader!Become a true master,an embedded sage,bybroadening your horizons to cover all aspects of this fascinating field.We
25、engineers areprofessionals;you and I know this in our hearts.Yet true professionals are those who learnnew things,who apply newly evolving technologies to solve problems.Consider doctors:the discovery and production of penicillin in the 1940s changed the profession of medicineforever.Any doc who ign
26、ored this new technology,who continued to practice using only theskills learned in college,was suddenly rendered a butcher.Software and hardware developersare faced with the same situation.C wasnt taught when I went to school.The FPGA hadntbeen invented.GOTOs were still just fine,thank you.We learne
27、d to program microprocessorsin machine code using primitive toolchains.Todaywell,we know how much has changed.The rate of change is increasing;changes first derivative is an ever-escalating positive num-ber.Professional developers will read this book from cover to cover,and will constantly seekout o
28、ther sources of information.If youre not at least surfing through a half dozen techni-cal magazines a month and reading a handful of books like this per year,then it wont take aCretaceous asteroid to make you a dinosaur.ForewordxiiSome of this book might surprise you.Ten pages about reading datashee
29、ts?Fact is,datasheetsare dense formal compilations of contractual material.The vendor promises the part will dox as long as we use it in an agreed-on manner.Violate any of perhaps thousands of specifica-tions and the part will either not work or will be unreliable.With some parts dissipating 100watt
30、s or more,even such arcana as thermal characteristics are as important as the devicesinstruction set.Tammys generous use of examples elucidates the more obscure points.Engineeringwheth-er hardware or softwareis the art of building things and solving problems.The academicscan work with dry theory;we
31、practicing developers often learn best by seeing how somethingworks.So the chapter on device drivers does explain the intricacies of building these often-complex bits of code,but couples the explanation to a wealth of real-world examples.Finally,Tammys words about theArchitecture Business Cycle of e
32、mbedded systems resonatestrongly with me.We dont build these things just to have a good time(though we sure hopeto have one along the way),but to solve important business problems.Every decision wemake has business implications.Use too little horsepower and development costs skyrocketsometimes to th
33、e point of making the project unviable.A poor analysis of the problem thatleads you to toss in an excess of Flash might drive costs unacceptably high.Select a compo-nent(hardware or software)from a failing company and your outfit may share in the vendorsdemise.Enjoy this book,and futureproof your ca
34、reer at the same time.Jack GanssleForewordxiiiAcknowledgmentsMy greatest debt in creating this book goes to the reviewers,who I hope will be pleasantlysurprised to see how many of their suggestions have been incorporated into the book.Theyinclude Dr.Al M.Zied,both of my brothers(especially my younge
35、r brother who also pro-vided me the inspiration to write this book in the first place),Jack Ganssle,Dr.Volker Enders,Dr.Stefan Frank,Dr.Karl Mathia,and Steve Bailey.Thank you to my publisher Elsevier,specifically to my editor Carol Lewis and the rest of“my”Elsevier team for their hard work and dedic
36、ation in making this book a reality.I would also like to acknowledge my mentor when I was with Sony Electronics,KazuhisaMaruoka,who patiently trained me to design televisions and gave me such a strong founda-tion upon which to grow,as well as my manager at Sony Electronics,Satoshi Ishiguro,whotook a
37、 chance and hired me.My journey in the embedded systems field that has led me towriting this book began with the great people I worked with at Sony in Japan and in SanDiego.A very special thanks to my family for their support,which allowed me to write this book,and without whose support and encourag
38、ement I could never have completed it.To myhusband,Christian,thank you for giving me the happiest days of my life,and the opportu-nity and encouragement to realize this book.For my beautiful baby girl Mia,thank you forbeing so patient with your Mama while I did my writingalways gifting me with endle
39、sssmiles,hugs,and kisses when I really needed them.Thank you,Mom,for the times you flewout from Belgium,and thanks to my sister Mandy for flying up from Southern California,tohelp me at home so I could finish my writing,and for encouraging me every step of the way.Finally,a special thanks toVernica
40、Cervantes Gaona for taking such good care of Mia sothat I could have the time and focus to write.I am very grateful for the quality time you spentwith her.xivAbout the AuthorTammy Noergaard is uniquely qualified to write about all aspects of embedded systemsarchitecture.Since beginning her embedded
41、systems career in 1995,she has had wide experi-ence in product development,system design and integration,operations,sales,marketing,andtraining.She has design experience using many hardware platforms,operating systems,andlanguages.Noergaard worked for Sony as a lead software engineer developing and
42、testingembedded software for analog TVs,and also managed and trained new embedded engi-neers and programmers.The televisions that she helped to develop were critically acclaimedand rated#1 in Consumer Reports magazines.At Wind River she was the liaison engineerbetween developmental engineers and cus
43、tomers to provide design expertise,systems con-figuration,systems integration,and training for Wind River embedded software(OS,Java,device drivers,etc.)and all associated hardware for a variety of embedded systems in theConsumer Electronic market.Most recently she was a Field Engineering Specialist
44、and Con-sultant with Esmertec NorthAmerica,providing project management,system design,systemintegration,system configuration,support and expertise for various embedded Java systemsusing Jbed in everything from control systems to medical devices to digital TVs.Noergaardhas lectured to engineering cla
45、sses at the University of California at Berkeley and Stanford,the Embedded Internet Conference,and the Java Users Group in San Jose,among others.S E C T I O NIIntroduction toEmbedded SystemsThis Page Intentionally Left Blank3Introduction to Embedded SystemsThe field of embedded systems is wide and v
46、aried,and it is difficult to pin down exact defi-nitions or descriptions.However,Chapter 1 introduces a useful model that can be appliedto any embedded system.This model is introduced as a means for the reader to understandthe major components that make up different types of electronic devices,regar
47、dless of theircomplexityordifferences.Chapter2introducesanddefinesthecommonstandardsadheredtowhenbuildinganembeddedsystem.Because this book is an overview of embedded systemsarchitecture,coveringeverypossiblestandards-basedcomponentthatcouldbeimplementedisbeyonditsscope.Therefore,significantexamples
48、ofcurrentstandards-basedcomponentswereselected,suchasnetworkingandJava,todemonstratehowstandardsdefinemajorcomponentsin an embedded system.The intention is for the reader to be able to use the methodologybehind the model,standards,and real-world examples to understand any embedded system,and to be a
49、ble to apply any other standard to an embedded systems design.This Page Intentionally Left Blank5CHAPTER1A Systems Engineering Approachto Embedded Systems Design1.1 What Is an Embedded System?An embedded system is an applied computer system,as distinguished from other types of com-puter systems such
50、 as personal computers(PCs)or supercomputers.However,you will findthat the definition of“embedded system”is fluid and difficult to pin down,as it constantlyevolves with advances in technology and dramatic decreases in the cost of implementing vari-ous hardware and software components.In recent years