computer science/electrical engineering E I Edward Ashford Lee and Introduction to Embedded Systems N M A Cyber-Physical Systems Approach T Sanjit Arunkumar Seshia second edition B R Edward Ashford Lee and Sanjit Arunkumar Seshia E O D D The most visible use of computers and software is processing information for human consumption. The vast majority D U of computers in use, however, are much less visible. They run the engine, brakes, seatbelts, airbag, and audio system E C in your car. They digitally encode your voice and construct a radio signal to send it from your cell phone to a base sta- D tion. They command robots on a factory floor, power generation in a power plant, processes in a chemical plant, and S TI INTRODUCTION TO traffic lights in a city. These less visible computers are called embedded systems, and the software they run is called O Y embedded software. The principal challenges in designing and analyzing embedded systems stem from their interac- N S tion with physical processes. This book takes a cyber-physical approach to embedded systems, introducing the engi- T T EMBEDDED SYSTEMS neering concepts underlying embedded systems as a technology and as a subject of study. The focus is on modeling, E O design, and analysis of cyber-physical systems, which integrate computation, networking, and physical processes. M The second edition offers two new chapters, several new exercises, and other improvements. The book can be S A CYBER-PHYSICAL SYSTEMS used as a textbook at the advanced undergraduate or introductory graduate level and as a professional reference for practicing engineers and computer scientists. Readers should have some familiarity with machine structures, computer programming, basic discrete mathematics and algorithms, and signals and systems. APPROACH Edward Ashford Lee is the Robert S. Pepper Distinguished Professor in the Department of Electrical Engineering and s SA Cmoemntp ouft eErl eScctireicnacle Esn agti nteheer Uinngi vaenrds iCtyo omfp Cuatelirfo Srcniiean, cBeesr kaetl ethye. SUannivjiet rAsrituyn okfu Cmaalrif oSrensiah,i aB iesr kae Pleryo.fessor in the Depart- econd YSTE CYB “Books titled Introduction to Embedded Systems traditionally focus on computer hardware and software. By taking e MER Ast aCnydb earn-dP hdyessiicganl tShyes tceommsp Autpinpgro saycshte, mLese t haantd m Saekseh ioau gr iwveo srltdu dfuennctsti othne. Ninot eogthraetre bdo poekr spproevcitdivees tshuecyh n ae ecdo mtop ruenhdeenr-- dition S AP-PHY Second Edition Modeling sive introduction to embedded systems for real-time applications.” PS —Bruce H. Krogh, Professor of Electrical and Computer Engineering, Carnegie Mellon University ROIC AA Design “Introduction to Embedded Systems by Lee and Seshia is an introductory yet rigorous textbook for the future Internet CL of Things engineer. It provides a unified systems view of computing and the physical world that will be the foundation H of the 21st-century Internet of Things revolution.” —George J. Pappas, Joseph Moore Professor, University of Pennsylvania Analysis “Designers of embedded systems are only too often overwhelmed by the many skills and disciplines that have to be SE mastered: from writing device drivers, to worst case execution time analysis, to formal verification and modeling of ad continuous time systems. This book by Lee and Seshia is an excellent guide to bringing order into these complex- nw ities of design by discerning the fundamental from the detail, the essential property from the accidental aspect. It jita r presents all the indispensable knowledge areas for an embedded systems designer and leaves out what can be Ad delegated to other specialized disciplines.” ru A ns —Axel Jantsch, Professor of Systems on Chips, Institute of Computer Technology, TU Wien, Vienna; author of Mod- kh eling Embedded Systems and SoC’s ufo m r “The outstanding property of this textbook is the combination of mathematical rigor and comprehensiveness. It is ad r L presented with numerous examples and with such quality that understanding the material is easy. Introduction to Se Embedded Systems is a must-read for those wanting to master the complexity of what is today the key enabling ee s a technology in most every complex system surrounding us: embedded and cyber-physical systems.” hn —Werner Damm, Director, Interdisciplinary Research Center on Cooperative Critical Systems, Carl von Ossietzky iad University of Oldenburg 978-0-262-53381-2 The MIT Press Massachusetts Institute of Technology 90000 Cambridge, Massachusetts 02142 http://mitpress.mit.edu 9 780262 533812 Copyright(cid:13)c 2017 EdwardAshfordLee&SanjitArunkumarSeshia ThisworkislicensedunderaCreativeCommons Attribution-NonCommercial-NoDerivatives4.0InternationalLicense. SecondEdition,Version2.2 ISBN:978-0-262-53381-2 Pleasecitethisbookas: E.A.LeeandS.A.Seshia, IntroductiontoEmbeddedSystems-ACyber-PhysicalSystemsApproach, SecondEdition,MITPress,2017. Thisbookisdedicatedtoourfamilies. Contents Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . x 1 Introduction 1 1.1 Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.2 MotivatingExample . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 1.3 TheDesignProcess . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 1.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 I ModelingDynamicBehaviors 17 2 ContinuousDynamics 18 2.1 NewtonianMechanics. . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 2.2 ActorModels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 2.3 PropertiesofSystems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 2.4 FeedbackControl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 2.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 CONTENTS 3 DiscreteDynamics 42 3.1 DiscreteSystems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 3.2 TheNotionofState . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 3.3 Finite-StateMachines . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 3.4 ExtendedStateMachines . . . . . . . . . . . . . . . . . . . . . . . . . . 60 3.5 Nondeterminism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 3.6 BehaviorsandTraces . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 3.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 4 HybridSystems 78 4.1 ModalModels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 4.2 ClassesofHybridSystems . . . . . . . . . . . . . . . . . . . . . . . . . 82 4.3 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 5 CompositionofStateMachines 109 5.1 ConcurrentComposition . . . . . . . . . . . . . . . . . . . . . . . . . . 111 5.2 HierarchicalStateMachines . . . . . . . . . . . . . . . . . . . . . . . . 126 5.3 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 6 ConcurrentModelsofComputation 135 6.1 StructureofModels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 6.2 Synchronous-ReactiveModels . . . . . . . . . . . . . . . . . . . . . . . 141 6.3 DataflowModelsofComputation. . . . . . . . . . . . . . . . . . . . . . 147 6.4 TimedModelsofComputation . . . . . . . . . . . . . . . . . . . . . . . 162 6.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 Lee&Seshia,IntroductiontoEmbeddedSystems v CONTENTS II DesignofEmbeddedSystems 178 7 SensorsandActuators 179 7.1 ModelsofSensorsandActuators . . . . . . . . . . . . . . . . . . . . . . 181 7.2 CommonSensors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 7.3 Actuators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200 7.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 8 EmbeddedProcessors 210 8.1 TypesofProcessors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211 8.2 Parallelism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220 8.3 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238 9 MemoryArchitectures 239 9.1 MemoryTechnologies . . . . . . . . . . . . . . . . . . . . . . . . . . . 240 9.2 MemoryHierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242 9.3 MemoryModels. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251 9.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 10 InputandOutput 260 10.1 I/OHardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261 10.2 SequentialSoftwareinaConcurrentWorld . . . . . . . . . . . . . . . . 272 10.3 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284 11 Multitasking 291 11.1 ImperativePrograms . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294 11.2 Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298 vi Lee&Seshia,IntroductiontoEmbeddedSystems CONTENTS 11.3 ProcessesandMessagePassing . . . . . . . . . . . . . . . . . . . . . . . 311 11.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318 12 Scheduling 322 12.1 BasicsofScheduling . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323 12.2 RateMonotonicScheduling . . . . . . . . . . . . . . . . . . . . . . . . 329 12.3 EarliestDeadlineFirst . . . . . . . . . . . . . . . . . . . . . . . . . . . 334 12.4 SchedulingandMutualExclusion . . . . . . . . . . . . . . . . . . . . . 339 12.5 MultiprocessorScheduling . . . . . . . . . . . . . . . . . . . . . . . . . 344 12.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351 III AnalysisandVerification 357 13 InvariantsandTemporalLogic 358 13.1 Invariants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359 13.2 LinearTemporalLogic . . . . . . . . . . . . . . . . . . . . . . . . . . . 362 13.3 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372 14 EquivalenceandRefinement 376 14.1 ModelsasSpecifications . . . . . . . . . . . . . . . . . . . . . . . . . . 377 14.2 TypeEquivalenceandRefinement . . . . . . . . . . . . . . . . . . . . . 378 14.3 LanguageEquivalenceandContainment . . . . . . . . . . . . . . . . . . 381 14.4 Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387 14.5 Bisimulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395 14.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399 Lee&Seshia,IntroductiontoEmbeddedSystems vii CONTENTS 15 ReachabilityAnalysisandModelChecking 404 15.1 OpenandClosedSystems . . . . . . . . . . . . . . . . . . . . . . . . . 405 15.2 ReachabilityAnalysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406 15.3 AbstractioninModelChecking . . . . . . . . . . . . . . . . . . . . . . . 413 15.4 ModelCheckingLivenessProperties . . . . . . . . . . . . . . . . . . . . 417 15.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425 16 QuantitativeAnalysis 427 16.1 ProblemsofInterest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428 16.2 ProgramsasGraphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430 16.3 FactorsDeterminingExecutionTime . . . . . . . . . . . . . . . . . . . . 435 16.4 BasicsofExecutionTimeAnalysis . . . . . . . . . . . . . . . . . . . . . 442 16.5 OtherQuantitativeAnalysisProblems . . . . . . . . . . . . . . . . . . . 451 16.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455 17 SecurityandPrivacy 459 17.1 CryptographicPrimitives . . . . . . . . . . . . . . . . . . . . . . . . . . 461 17.2 ProtocolandNetworkSecurity . . . . . . . . . . . . . . . . . . . . . . . 469 17.3 SoftwareSecurity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474 17.4 InformationFlow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477 17.5 AdvancedTopics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485 17.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491 viii Lee&Seshia,IntroductiontoEmbeddedSystems CONTENTS IV Appendices 492 A SetsandFunctions 493 A.1 Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493 A.2 RelationsandFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . 494 A.3 Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 498 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501 B ComplexityandComputability 502 B.1 EffectivenessandComplexityofAlgorithms . . . . . . . . . . . . . . . . 503 B.2 Problems,Algorithms,andPrograms . . . . . . . . . . . . . . . . . . . . 506 B.3 TuringMachinesandUndecidability . . . . . . . . . . . . . . . . . . . . 508 B.4 Intractability: PandNP . . . . . . . . . . . . . . . . . . . . . . . . . . . 514 B.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 518 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519 Bibliography 521 NotationIndex 541 NotationIndex 541 Index 543 Lee&Seshia,IntroductiontoEmbeddedSystems ix Preface What This Book Is About The most visible use of computers and software is processing information for human consumption. We use them to write books (like this one), search for information on the web, communicate via email, and keep track of financial data. The vast majority of computersinuse,however,aremuchlessvisible. Theyruntheengine,brakes,seatbelts, airbag, and audio system in your car. They digitally encode your voice and construct a radiosignaltosenditfromyourcellphonetoabasestation. Theycontrolyourmicrowave oven,refrigerator,anddishwasher. Theyrunprintersrangingfromdesktopinkjetprinters tolargeindustrialhigh-volumeprinters. Theycommandrobotsonafactoryfloor,power generationinapowerplant,processesinachemicalplant,andtrafficlightsinacity. They searchformicrobesinbiologicalsamples,constructimagesoftheinsideofahumanbody, and measure vital signs. They process radio signals from space looking for supernovae and for extraterrestrial intelligence. They bring toys to life, enabling them to react to humantouchandtosounds. Theycontrolaircraftandtrains. Theselessvisiblecomputers arecalledembeddedsystems,andthesoftwaretheyruniscalledembeddedsoftware. Despitethiswidespreadprevalenceofembeddedsystems,computersciencehas,through- outitsrelativelyshorthistory,focusedprimarilyoninformationprocessing. Onlyrecently haveembeddedsystemsreceivedmuchattentionfromresearchers. Andonlyrecentlyhas
Description: