I NTRODUCTION TO E S MBEDDED YSTEMS Second Edition About the Author Shibu Kizhakke Vallathai has over fi fteen years of hands-on experience in the Embedded & Real Time System domain with solid background on all phases of Embedded Product Development Life Cycle. He holds a B Tech Degree (Hons) in Instrumentation & Control Engineering from the University of Calicut, Kerala. He started his professional career as Research Associate in the VLSI and Embedded Systems Group of India’s prime Electronics Research & Development Centre (ER&DCI—under the ministry of Information & Communication Technology, Government of India) Thiruvananthapuram Unit. He has conducted research activities in the embedded domain for Contactless Smart Card Technology and Radio Frequency Identifi cation (RFID). He has developed a variety of products in the Contactless Smart Card & RFID Technology platform using industry’s most popular 8-bit microcontroller—8051. Shibu has sound working knowledge in Embedded Hardware development using EDA Tools and fi rmware development in Assembly Language and Embedded C using a variety of IDEs and cross-compilers for various 8/16/32 bit microprocessors/microcontrollers and System on Chips. He is also an expert in RTOS based Embedded System design for various RTOSs including Windows CE, VxWorks, MicroC/ OS-II and RTX-51. He is well versed in various industry standard protocols and bus interfaces. Presently, he is engaged with the Devices Group of Microsoft Corporation, USA (www.microsoft.com) as senior Firmware Engineer. Prior to joining Microsoft, he was engaged with the Embedded Systems and Product Engineering practice unit of Infosys Technologies Limited (www.infosys.com), Thiruvananthapuram unit as senior Technology Architect. I NTRODUCTION TO E S MBEDDED YSTEMS Second Edition Shibu Kizhakke Vallathai Senior Firmware Engineer Microsoft Corporation McGraw Hill Education (India) Private Limited NEW DELHI McGraw Hill Education Offi ces New Delhi New York St Louis San Francisco Auckland Bogotá Caracas Kuala Lumpur Lisbon London Madrid Mexico City Milan Montreal San Juan Santiago Singapore Sydney Tokyo Toronto McGraw Hill Education (India) Private Limited Published by McGraw Hill Education (India) Private Limited, P-24, Green Park Extension, New Delhi 110 016. Introduction to Embedded Systems, 2e Copyright © 2017, 2009 by McGraw Hill Education (India) Private Limited No part of this publication may be reproduced or distributed in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise or stored in a database or retrieval system without the prior written permission of the publishers. The program listing (if any) may be entered, stored and executed in a computer system, but they may not be reproduced for publication. This edition can be exported from India only by the publishers, McGraw Hill Education (India) Private Limited. Print Edition: ISBN (13): 978-93-392-1968-0 ISBN (10): 93-392-1968-6 E-Book Edition: ISBN (13): 978-93-392-1969-7 ISBN (10): 93-392-1969-4 Managing Director: Kaushik Bellani Director—Products (Higher Education and Professional): Vibha Mahajan Specialist—Product Development: Piyush Priyadarshi Researcher—Product Development: Lubna Irfan Head—Production (Higher Education and Professional): Satinder S Baveja Senior Copy Editor: Kritika Lakhera Senior Production Specialist: Suhaib Ali Assistant General Manager—Product Management (Higher Education and Professional): Shalini Jha Manager—Product Management: Kartik Arora General Manager—Production: Rajender P Ghansela Manager—Production: Reji Kumar Information contained in this work has been obtained by McGraw Hill Education (India), from sources believed to be reliable. However, neither McGraw Hill Education (India) nor its authors guarantee the accuracy or completeness of any information published herein, and neither McGraw Hill Education (India) nor its authors shall be responsible for any errors, omissions, or damages arising out of use of this information. This work is published with the understanding that McGraw Hill Education (India) and its authors are supplying information but are not attempting to render engineering or other professional services. If such services are required, the assistance of an appropriate professional should be sought. Typeset at Text-o-Graphics, B-1/56, Aravali Apartment, Sector-34, Noida 201 301, and printed at Cover Printer: Visit us at: www.mheducation.co.in I dedicate this book to all Infoscions, my beloved mother late Smt. Santha, my wife Cini, my son Tejas, my papa, my friends, my other family members and my loved ones Contents Preface xiii Acknowledgements xvii Part-1: Embedded Systems: Understanding the Basic Concepts 1 1. Introduc on to Embedded Systems 3 1.1 What is an Embedded System? 4 1.2 Embedded Systems VS. General Computing Systems 4 1.3 History of Embedded Systems 5 1.4 Classifi cation of Embedded Systems 6 1.5 Major Application Areas of Embedded Systems 8 1.6 Purpose of Embedded Systems 8 1.7 Wearable Devices—The Innovative Bonding of Lifestyle with Embedded Technologies 11 Summary 13 Keywords 14 Objective Questions 14 Review Questions 15 2. The Typical Embedded System 16 2.1 Core of the Embedded System 18 2.2 Memory 29 2.3 Sensors and Actuators 35 2.4 Communication Interface 45 2.5 Embedded Firmware 59 2.6 Other System Components 60 2.7 PCB and Passive Components 64 Summary 64 Keywords 65 Objective Questions 67 Review Questions 70 Lab Assignments 72 viii Contents 3. Characteris cs and Quality A ributes of Embedded Systems 73 3.1 Characteristics of an Embedded System 73 3.2 Quality Attributes of Embedded Systems 75 Summary 80 Keywords 80 Objective Questions 81 Review Questions 82 4. Embedded Systems—Applica on- and Domain-Specifi c 84 4.1 Washing Machine—Application-Specifi c Embedded System 84 4.2 Automotive–Domain Specifi c Examples of Embedded System 86 Summary 90 Keywords 91 Objective Questions 91 Review Questions 92 5. Designing Embedded Systems with 8bit Microcontrollers—8051 93 5.1 Factors to be Considered in Selecting a Controller 94 5.2 Why 8051 Microcontroller 95 5.3 Designing with 8051 96 5.4 The 8052 Microcontroller 157 5.5 8051/52 Variants 157 Summary 158 Keywords 159 Objective Questions 160 Review Questions 164 Lab Assignments 166 6. Programming the 8051 Microcontroller 168 6.1 Different Addressing Modes Supported by 8051 169 6.2 The 8051 Instruction Set 175 Summary 199 Keywords 200 Objective Questions 201 Review Questions 206 Lab Assignments 207 7. Hardware So ware Co-Design and Program Modelling 209 7.1 Fundamental Issues in Hardware Software Co-Design 210 7.2 Computational Models in Embedded Design 212 7.3 Introduction to Unifi ed Modelling Language (UML) 220 7.4 Hardware Software Trade-offs 225 Summary 225 Keywords 226 Objective Questions 228 Review Questions 229 Lab Assignments 230 Contents ix Part-2: Design and Development of Embedded Product 231 8. Embedded Hardware Design and Development 234 8.1 Analog Electronic Components 235 8.2 Digital Electronic Components 236 8.3 VLSI and Integrated Circuit Design 249 8.4 Electronic Design Automation (EDA) Tools 254 8.5 How to use the OrCAD EDA Tool? 255 8.6 Schematic Design using Orcad Capture CIS 255 8.7 The PCB Layout Design 273 8.8 Printed Circuit Board (PCB) Fabrication 293 Summary 299 Keywords 300 Objective Questions 301 Review Questions 304 Lab Assignments 305 9. Embedded Firmware Design and Development 308 9.1 Embedded Firmware Design Approaches 309 9.2 Embedded Firmware Development Languages 312 9.3 Programming in Embedded C 324 Summary 376 Keywords 377 Objective Questions 378 Review Questions 383 Lab Assignments 386 10. Real-Time Opera ng System (RTOS) based Embedded System Design 387 10.1 Operating System Basics 389 10.2 Types of Operating Systems 392 10.3 Tasks, Process and Threads 396 10.4 Multiprocessing and Multitasking 408 10.5 Task Scheduling 410 10.6 Threads, Processes and Scheduling: Putting them Altogether 428 10.7 Task Communication 433 10.8 Task Synchronisation 449 10.9 Device Drivers 482 10.10 How to Choose an RTOS 484 Summary 485 Keywords 487 Objective Questions 489 Review Questions 499 Lab Assignments 504 11. An Introduc on to Embedded System Design with VxWorks and MicroC/OS-II RTOS 507 11.1 VxWorks 508 11.2 MicroC/OS-II 523 x Contents Summary 552 Keywords 553 Objective Questions 554 Review Questions 556 Lab Assignments 557 12. Integra on and Tes ng of Embedded Hardware and Firmware 560 12.1 Integration of Hardware and Firmware 561 12.2 Board Bring up 565 Summary 566 Keywords 567 Review Questions 567 13. The Embedded System Development Environment 568 13.1 The Integrated Development Environment (IDE) 570 13.2 Types of Files Generated on Cross-Compilation 598 13.3 Disassembler/Decompiler 607 13.4 Simulators, Emulators and Debugging 607 13.5 Target Hardware Debugging 615 13.6 Boundary Scan 617 Summary 619 Keywords 620 Objective Questions 621 Review Questions 622 Lab Assignments 623 14. Product Enclosure Design and Development 624 14.1 Product Enclosure Design Tools 625 14.2 Product Enclosure Development Techniques 625 14.3 Summary 627 Summary 628 Keywords 629 Objective Questions 629 Review Questions 630 15. The Embedded Product Development Life Cycle (EDLC) 631 15.1 What is EDLC? 632 15.2 Why EDLC 632 15.3 Objectives of EDLC 633 15.4 Different Phases of EDLC 635 15.5 EDLC Approaches (Modeling the EDLC) 646 Summary 651 Keywords 652 Objective Questions 653 Review Questions 654