Stevens Institute of Technology CPE 800C Real-Time and Embedded System Lecture 1: Introduction Dr. Yan Meng http://www.ece.stevens-tech.edu/~ymeng/ Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Course Introduction Instructor: Yan Meng Office: Burchard 215 Phone: 201-216-5496 Email: ymeng1@stevens.edu Office hour: Thursday 4:00pm-6:00pm Homework Must be typed or printed hardcopy (i.e., not handwritten) Email is OK with MS/Office or program attachments Include the problem statement with solution. Keep a copy of your hardcopy or electronic homework (if probably will not be returned) If you submit homework as an email attachment, make sure your name appears in the file Homework will be due at the beginning of the class 1 after it is asigned Problem solutions will be posted on-line LATE HOMEWORK WILL NOT BE ACCEPTED AFTER THE SOLUTION IS POSTED Grading Homework 20% project 20% midterm 30% final 30% Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Course Introduction (Contd) Course Description Cover various fundamental issues as well as practical development in the area of real-time embedded systems Required Textbook J ane W. S. Liu, Real-Time Systems, Prentice-Hall, Inc. 2000, ISBN: 0-13-099651-3. Referenced books Qing Li, Real-Time Concepts for Embedded Systems, CMP Books, 2003, ISBN 1-57820-124-1. Frank Vahid, Tony Givargis, Embedded System Design: A Unified Hardware/Software Introduction, J ohn Wiley & Sons, 2002, ISBN 0-471-38678-2. Wayne Wolf, Computers as Components: Principles of Embedded Computing System Design, Morgan Kaufman, 2001. Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Course Topics Introduction of Real-Time Embedded Systems Real-Time Operating Systems Embedded Software Programming Scheduling and Synchronization Hardware/Software Co-Design Real-Time Communication Distributed Embedded Systems Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Todays Lecture What are real-time embedded system? Design technology of RT embedded system Choose the right processor Software development of RT embedded system Real-time vs. general software Overview of real-time operating system Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Embedded System Embedded systems are computing systems with tightly coupled hardware and software integration, that are designed to perform a dedicated function. The word embedded reflects the fact that these systems are usually an integral part of a larger system, known as the embedding system. Multiple embedded systems can coexist in an embedding system Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Embedded Systems Examples Sonys Aibo Sonicare toothbrush Palm Vx Handheld Garmin SreetPilot GPS Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Real-Time Systems Definition Real-time systems are defined as those systems in which the overall correctness of the system depends on both the functional correctness and the timing correctness. The timing correctness is at least as important as the functional correctness Characteristics: Provide well-timed computation Deadlines, jitters, periodicity Temporal dependency Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Hard vs. Soft Real-time Systems Hard real-time system Must meet deadlines with a near-zero degree of flexibility The deadline must be met, or catastrophes occur ( cost is extremely high and can involve human lives) The computation results obtained after the deadline have either zero-level of usefulness or have a high rate of depreciation Soft real-time system Must meet its deadlines but with a degree of flexibility The deadlines can contain varying levels of tolerance, average timing deadlines, and even statistical distribution of response times with different degrees of acceptability A missed deadline does not result in system failure, but costs can rise in proportion to delay, depending on the application Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Real-Time Embedded System Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Real-time Embedded Systems Examples Electric toothbrush, pacemaker Cellular phones Autonomous mobile robots GPS receivers, Internet And more Plant sensor actuator Control-raw computation A/D A/D D/A Reference input Controller Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Why RT Embedded System are Different? Dedicated to specific tasks Be supported by a wide array of processors, and processor architectures Cost sensitive Real-time constraints Real-time operating system Power constraints Must operate under severe environment conditions Far fewer resources than desktop systems Store all the object code in ROM Require specialized tools and methods to be efficiently designed Have dedicated debugging circuitry Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Requirements for RT Embedded Systems NRE cost (nonrecurring engineering cost) one-time monetary cost of designing the system Unit cost monetary cost of manufacturing each copy of the system Size physical space required by the system (bytes in SW, gates/transistors in HW) Performance execution time Power consumption - power consumed by the system Flexibility ability to change the functionality without incurring heavy NRE cost Time-to-prototype time needed to build a working version of the system Time-to-market time required to develop a system to the point that it can be released and sold to customers. Maintainability ability to modify the system after its initial release Correctness functional and timely Safety probability that the system will not cause harm Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Real-Time Embedded System Design technology Hardware (processor, memory, I/O, bus, etc) Software (OS, libraries, Applications, GUI, etc) Design process (system/behavioral/RT /logic specification, implementation, Testing, etc.) Tool chain (analysis, compiler, debugging, integration, etc.) Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology RT Embedded System Design Cycle Seven phases Product specification Partitioning of the design into its software and hardware components Iteration and refinement of the partitioning Independent hardware and software design tasks Integration of the hardware and software components Product testing and release On-going maintenance and upgrading Notes: The real world RT embedded system design process is not as simple as above. A considerable amount of iteration and optimization occurs within phases and between phases. Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Hardware Design - Embedded Processors Processors in PC General-purpose or universal processors Provide a full scale of features and a wide spectrum of functionalities Designed for a variety of applications Large power consumption, heat production and size Embedded Processors Special purpose processors Designed for a specific class of application Focus on size, power consumption, price, and performance Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Choosing the Right Embedded Processor Cost of Goods Time to Market Real-time Constraints Performance Size Power Consumption Legacy Code Support ? Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Choosing the Right Embedded Processor (Contd) Is it available in a suitable implementation? Cost-sensitive projects might require an off-the-shelf, highly integrated part High-performance applications might require gate-to-gate delays that are only practical when the entire design is fabricated on a single chip Is it capable of sufficient performance? The bottlenecks that limit performance often have less to do with computational power than with the fitbetween the architecture and the devices more demanding tasks Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Choosing the Right Embedded Processor (Contd) Is it supported by an appropriate operating system? In order to take an advantage of commercial RTOS, such as VxWorks or pSOS from Wind River System, the processors need have the support from those RTOS Is it supported by appropriate and adequate tools? Good tools are critical to project success At a minimum, youll need a good cross-compiler and good debugging support In many situations, youll need far more, such as in-circuit emulators (ICE), simulators, and so on Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Processors in RT Embedded System Microprocessor-based system A CPU without any additional peripheral or support devices Microcontroller-based system A CPU with a minimum complement of external parts, such as memory, I/O, and clock, etc. System-on-Chip system Multiple CPUs and multiple peripheral devices on a single silicon chip Individual elements are not designed from scratch but are licensed (in the form of synthesizable VHDL or Verilog specifications) from various IC design houses The elements are connected with custom inter-connect logic Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Hardware/Software Partitioning Designing the hardware for an embedded system is more than just selecting the right processor and gluing it to a few peripherals. The partitioning decision is a complex optimization problem, which is difficult due to the conflicting requirements of the system The implement of an algorithm design can be as a combination of hardware components and software components Purely in software the CPU without the FPU Purely in hardware the dedicated modem chip In some combination the video card Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Hardware/Software Integration Must have special tools and methods to manage the complexity An exercise in debugging and discovery The Holy Grail of embedded system design is to combine the first hardware prototype, the application software, the drive code, and the operating system software together with a pinch of optimism and to have the design work perfectly out of the chute unlikely scenario in real world The real-time nature of embedded systems leads to highly complex, nondeterministic behavior that can only be analyzed as it occurs Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Product Testing and Releasing Product testing takes on special significance when the performance of the embedded system has life or death consequences attached (such as a nuclear power generating stations emergency system) Testing is more than making sure the software doesnt crash at a critical moment Because embedded systems usually have extremely tight design margins to meet cost goals, testing must determine whether the system is performing close to its optimal capabilities Memory leaks problem for embedded system running continuously for a long time is potentially disastrous Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Maintenance and Upgrading The majority of embedded system designers (around 60%) maintain and upgrade existing products, rather than design new products Those engineers who maintain and upgrade the existing systems are usually not the original designers Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology SW Development for Embedded Systems To write the control software for a smart washer initialize read keypad or control knob read sensors take an action System current state state transition diagram external triggers via polling or ISR Would you like to write an auto landing software for Boeing 787? initialization external trigger? Take actions Change system state ISR: to set/clear events Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology SW Development for Embedded Systems Never-ending in a single control loop Single execution threat and one address space Event triggering and state transitions Small memory footprint What are missing in the example solution: no concurrency (real-world events occur in parallel) no explicit timing control (lets add a timer) difficult to develop and maintain large embedded systems verifiable, reusable, and maintainable Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Real-Time vs. General Software Multi-tasking for concurrent events Machine dependence and portability Software abstraction, modular design Information hiding, OO, separate compilation, reusable A sorting procedure function, input, output specification Control timing Resource constraints and sharing CPU time, stack, memory, and bandwidth Scheduling Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Real-time vs. General Software (Contd) Portability and configuration management Windows and its applications Registry and hardware abstraction Maintenance and upgrade Component reuse and integration Use DLLs in embedded systems? DLL(dynamic link library) is a small application thats called by a large application to provide a service or set of instruction. The DLL is designed to save space by placing commonly used routines in a DLL file, rather than placing copies of all of the routines in each individual program. Profiling: resource usage in a specific platform for each component Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Timing Constraints and Characteristics An example: 2 actions and 1 event A1 must be done at least every 10ms, and takes 1ms A2 must be completed with 5ms when E occurs and takes 2ms E must be detected by polling and is detectable for at least 0.5 ms E would not occur twice within 50 ms polling of E takes 0.01ms a passive clock with a tick size 0.1ms 0.5ms Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Timing Constraints and Characteristics Predicting and controlling timing and events Timing relationship: (can you guarantee it?) predictable actions in response to external stimuli deadline (absolute or relative), and jitter (the period frequency displacement of the signal from its ideal location) Instruments play in a band miss a note or timing Difficult to control timing all players of an interactive game in Internet see the actions at the same time Sequence, order, and race condition ( when the state of a resource depends on timing factors that are not predictable) Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Timing Constraints and Multi-threading Given input x 1 at time t 1 , produce output y 1 at time t 2 Non-deterministic operation, Time-dependent behavior, and race condition difficult to model, analyze, test, and re-produce. Example: NASA Pathfinder spacecraft Total system resets in Mars Pathfinder An overrun of data collection task a priority inversion in mutex semaphore failure of communication task a system reset. Took 18 hours to reproduce the failure in a lab replica the problem became obvious and a fix was installed Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Challenges in Embedded Sys. Development To ensure safety (security) for critical applications Software development process and Certification We dont know how safe a software is Use of standard processes and compliance with pre-determined objectives to help avoid the common pitfalls of software development Traceability Requirements Test/verification Implementation Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Embedded System Development Need a real-time (embedded) operating system ? Need a development and test environment ? Use the host to edit, compile, and build application programs, and configure the target At the target embedded system, use tools to load, execute, debug, and monitor (performance and timing) Ethernet Simulated signal source (Workstation, embedded system development tools) (workstation, interface cards), & test harness Development workstation Embedded systems Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Real-Time Operating System Functions: task management, scheduling, dispatcher communication (pipe, queue) synchronization (semaphore, event) memory management time management device driver interrupt service Interrupt dispatch Interrupt service Time service & events Services (create thread, sleep, notify, send,) Scheduling & dispatcher External interrupt System calls (trap) Timer interrupt kernel Task execution Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Tornado Development Environment Target Host Target server Target agent application vxWork Editor, Compiler WindSh CrossWind Browser WindConfig Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Booting a Target in a Cross-Development Environment When power-up, execute boot ROM code at the target load vxWorks (RTOS) or applications into the target memory (via network) start executing vxWorks boot parameters (network address, directory . ) Typically, there is a generic boot ROM (firmware, monitor, etc) Need to write the vxWorks boot ROM into flash memory vxWorks is a configurable RTOS configure vxWorks with hardware-dependent drivers for the target board (BSP --- board-supporting package) Once vxWorks is executing start a target server at the host to manage target resources use the command shell and other tools Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Target Server The target server (tgtsvr) manages the interactions with the target communication channel symbol table for the target Tools use WTX (Wind River Tool Exchange) protocol to communicate with the target server target server Debug agent vxWorks network-independent communication WindSh (shell) WindView (timing monitor) CrssWind (debugger) Registry Daemon License management Custom-built tool WTX protocol Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Tornado Target Environment Spring 2005 Dept. of Electrical and Computer Engineering Stevens Institute of Technology Tornado Host Environment (Server)