Embedded Systems Interrupts C.-Z. Yang Sept.-Dec. 2001.

Slides:



Advertisements
Similar presentations
1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
Advertisements

A look at interrupts What are interrupts and why are they needed.
CSCI 4717/5717 Computer Architecture
The Kernel Abstraction. Challenge: Protection How do we execute code with restricted privileges? – Either because the code is buggy or if it might be.
COMP3221: Microprocessors and Embedded Systems Lecture 15: Interrupts I Lecturer: Hui Wu Session 1, 2005.
A look at interrupts What are interrupts and why are they needed in an embedded system? Equally as important – how are these ideas handled on the Blackfin.
Architectural Support for OS March 29, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
Figure 2.8 Compiler phases Compiling. Figure 2.9 Object module Linking.
Embedded Systems Introduction to Real-Time Operating Systems C.-Z. Yang Sept.-Dec
6-1 I/O Methods I/O – Transfer of data between memory of the system and the I/O device Most devices operate asynchronously from the CPU Most methods involve.
A look at interrupts What are interrupts and why are they needed.
Embedded Systems Software Architectures C.-Z. Yang Sept.-Dec
Embedded Systems An Overview to Embedded Software C.-Z. Yang Sept.-Dec
Embedded Systems Basic Design Using a Real- Time Operating System C.-Z. Yang Sept.-Dec
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
INPUT/OUTPUT ORGANIZATION INTERRUPTS CS147 Summer 2001 Professor: Sin-Min Lee Presented by: Jing Chen.
Exception and Interrupt Handling
Introduction to Embedded Systems
Chapter 10 The Stack Stack: An Abstract Data Type An important abstraction that you will encounter in many applications. We will describe two uses:
MICROPROCESSOR INPUT/OUTPUT
CHAPTER 3 TOP LEVEL VIEW OF COMPUTER FUNCTION AND INTERCONNECTION
Chapter 8 I/O. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 8-2 I/O: Connecting to Outside World So far,
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Operating Systems Lecture 7 OS Potpourri Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software.
Microprocessors 1 MCS-51 Interrupts.
1 CSE451 Architectural Supports for Operating Systems Autumn 2002 Gary Kimura Lecture #2 October 2, 2002.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
CS153A Announcements Project 2 TA will distribute IPAQ’s this Wednesday. Groups of 3 See Derek if you cannot attend discussion class.
Computer Organization Instruction Set Architecture (ISA) Instruction Set Architecture (ISA), or simply Architecture, of a computer is the.
Embedded Systems Design 1 Lecture Set 8 MCS-51 Interrupts.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
Embedded Computer - Definition When a microcomputer is part of a larger product, it is said to be an embedded computer. The embedded computer retrieves.
CS-280 Dr. Mark L. Hornick 1 Sequential Execution Normally, CPU sequentially executes instructions in a program Subroutine calls are synchronous to the.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Introduction to Exceptions 1 Introduction to Exceptions ARM Advanced RISC Machines.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Transmitter Interrupts Review of Receiver Interrupts How to Handle Transmitter Interrupts? Critical Regions Text: Tanenbaum
Computer System Structures Interrupts
Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir. A.C. Verschueren Eindhoven University of Technology Section of Digital.
Interrupts and exceptions
8085 Interrupts LAKSHMI.B.E..
Microprocessor Systems Design I
The deadline establish a priority among interrupt requests.
Computer Architecture
Interrupts In 8085 and 8086.
Day 08 Processes.
Day 09 Processes.
Real-time Software Design
Chapter 10 The Stack.
An Embedded Software Primer
Architectural Support for OS
Interrupts.
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
EE 472 – Embedded Systems Dr. Shwetak Patel.
CSE 451: Operating Systems Autumn 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 596 Allen Center 1.
CSE 451: Operating Systems Autumn 2001 Lecture 2 Architectural Support for Operating Systems Brian Bershad 310 Sieg Hall 1.
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
Embedded System Development Lecture 7 2/21/2007
Computer System Overview
An Embedded Software Primer
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
CSE 153 Design of Operating Systems Winter 19
Architectural Support for OS
COMP3221: Microprocessors and Embedded Systems
Embedded System Development Lecture 12 4/4/2007
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

Embedded Systems Interrupts C.-Z. Yang Sept.-Dec. 2001

元智大學資訊工程系 Systems - Interrupts2 Context Awareness Since embedded systems are closely relevant to the contexts, how can these external events be noticed?

元智大學資訊工程系 Systems - Interrupts3 I/O Interrupts The most common approach is to use interrupts. –Interrupts cause the microprocessor in the embedded system –to suspend doing whatever it is doing and –to execute some different code instead. Interrupts can solve the response problem, but not without some difficult programming, and without introducing some new problems of their own.

元智大學資訊工程系 Systems - Interrupts4 I/O Interrupts The flow –Step 1: Interrupts start with a signal from the hardware. –Step 2: The signal notifies the CPU to react the event.

元智大學資訊工程系 Systems - Interrupts5 Interrupt Service Routines The main job is to react the interrupts. Typically, interrupt service routines also must do some miscellaneous housekeeping chores, –Reset the interrupt-detecting hardware –Enable processing interrupts of lower priorities

元智大學資訊工程系 Systems - Interrupts6 ISR vs. Procedure Calls To execute ISRs, there is NO CALL instruction. –The microprocessor does the call automatically. An array, interrupt vector, of addresses is used to point to appropriate ISRs. –ISRs must be loaded when the computer is turned on. Interrupts can be masked. The context need to be saved.

元智大學資訊工程系 Systems - Interrupts7 Two Basic Models Synchronous –Returning the control of CPU to the user process must be after the completion of the ISR. Asynchronous – The control is returned without waiting for the I/O to complete.

元智大學資訊工程系 Systems - Interrupts8 Some Common Questions How does the microprocessor know where to find the interrupt routine when the interrupt occurs? How do microprocessors that use an interrupt vector table know where the table is? Can a microprocessor be interrupted in middle of an instruction?

元智大學資訊工程系 Systems - Interrupts9 Some Common Questions If two interrupts happen at the same time, which interrupt routine does the microprocessor do first? Can an interrupt request signal interrupt anther interrupt routine? What happens if an interrupt is signaled while the interrupts are disabled?

元智大學資訊工程系 Systems - Interrupts10 Some Common Questions What happened if I disable interrupts and then forget to re-enable them? Can I write my interrupt routines in C?

元智大學資訊工程系 Systems - Interrupts11 The Shared-Data Problem

元智大學資訊工程系 Systems - Interrupts12 A Powerful ISR Design Can the ISR do everything you want? –Yes, but this is very impractical. main() { int i; // setting up ISRs // do nothing but an empty loop while(1) i=i+0; } SampleISR() { newVal:= ReadADConverter() call StartNewConversion() … } SampleISR() { newVal:= ReadADConverter() call StartNewConversion() … }

元智大學資訊工程系 Systems - Interrupts13 A Practical Approach The ISR should do the necessary tasks –moving data from I/O devices to the memory buffer or vice versa –handling emergent signals –signaling the task subroutine code or the kernel The ISR needs to notify some other procedure to do follow-up processing. Task Code ISR Shared Variables

元智大學資訊工程系 Systems - Interrupts14 Accessing the Shared Data However, this may cause the shared data problem. ISR Task Code Interrupt

元智大學資訊工程系 Systems - Interrupts15 The Shared Data Problem The unexpected interrupt –may cause two readings to be different, –even though the two measured temperatures were always the same. What can we improve this? –Testing these temperature measurements directly!

元智大學資訊工程系 Systems - Interrupts16 Directly Testing The new code ISR Task Code Testing

元智大學資訊工程系 Systems - Interrupts17 A Bug Harder to Be Detected The compiler translation Interruptible

元智大學資訊工程系 Systems - Interrupts18 Characteristics of the Shared-Data Bug A bug that is very hard to find. –It does not happen every time the code runs. –The program may run correctly in most time. –However, a false alarm may be set off sometimes. How can you trace back if the embedded system has already exploded?

元智大學資訊工程系 Systems - Interrupts19 Solving the Shared-Data Problem

元智大學資訊工程系 Systems - Interrupts20 The Simplest Solution Just disable interrupts when the shared data are used by the task code.

元智大學資訊工程系 Systems - Interrupts21 The Assembly Code Disabling Interrupts

元智大學資訊工程系 Systems - Interrupts22 Atomic Instructions/Sections A More Convenient Way –Use some atomic instructions supported by the hardware. An instruction is atomic if it cannot be interrupted. The collection of lines can be atomic by adding an interrupt-disable instruction. A set of instruction that must be atomic for the system to work properly is often called a critical section.

元智大學資訊工程系 Systems - Interrupts23 Another Example A buggy program –imprecise answer Interrupt

元智大學資訊工程系 Systems - Interrupts24 Several Possible Solutions Disable the interrupt A buggy solution - Interrupts will not be appropriately enabled. A buggy solution - Interrupts will not be appropriately enabled.

元智大學資訊工程系 Systems - Interrupts25 A Better Code Changing the timing of return()

元智大學資訊工程系 Systems - Interrupts26 The Best Way The nested interrupts

元智大學資訊工程系 Systems - Interrupts27 Another Potential Solutions Doing things in the ISR

元智大學資訊工程系 Systems - Interrupts28 Potential Bugs If the microprocessor’s registers are large enough to hold a long integer, then the ASM code is atomic. However, if the registers are too small to hold a long integer, the the ASM will have the same problem.

元智大學資訊工程系 Systems - Interrupts29 A volatile Case Where is the variables?

元智大學資訊工程系 Systems - Interrupts30 A volatile Case The volatile keyword allows you to warn the compiler that certain variables may change because of interrupt routines. If this keyword is not supported, you can still get the similar result by turning off the compiler optimizations.

元智大學資訊工程系 Systems - Interrupts31 Interrupt Latency

元智大學資訊工程系 Systems - Interrupts32 One Obvious Question How fast does my system respond to each interrupt? –The longest period of time during which that interrupt is disabled. –The period of time it takes to execute any ISR for interrupts that are of higher priority than one in question. –How long it takes the microprocessor to stop what it is doing, do the necessary bookkeeping, and start executing instructions within ISR. –How long it takes the ISR to save the context and then do enough work that what it has accomplished counts as a “response”.

元智大學資訊工程系 Systems - Interrupts33 Next Question How do I get the times associated with the four factors? –Factor 3 from the data book –Factor 1, 2, and 4 through a benchmark program count the machine cycles

元智大學資訊工程系 Systems - Interrupts34 So, Make Your ISR Short The four factors control interrupt latency and, therefore, response. Although lower-priority interrupts are presumably lower priority because their response time requirements are less critical, this is not necessarily license to make their response dreadful.

元智大學資訊工程系 Systems - Interrupts35 Disabling Interrupts The remaining factor that contributes to interrupt latency is the practice of disabling interrupts. However, this needs to be carefully designed to meet the deadline requirements.

元智大學資訊工程系 Systems - Interrupts36 An Example Worst case latency

元智大學資訊工程系 Systems - Interrupts37 If Design Requirement is Changed Low-end processor Network enhancement

元智大學資訊工程系 Systems - Interrupts38 Alternatives to Disabling Interrupts Two variable sets

元智大學資訊工程系 Systems - Interrupts39 Two Variable Sets This simple mechanism solves the shared- data problem, because the ISR will never write into the set of temperatures that the task code is reading. However, the while-loop may be executed twice before it sets off the alarm.

元智大學資訊工程系 Systems - Interrupts40 A Queue Approach The shared-data problem is also eliminated.

元智大學資訊工程系 Systems - Interrupts41 A Queue Approach main()

元智大學資訊工程系 Systems - Interrupts42 A Queue Approach However, this code is very fragile. Either of these seemingly minor changes can cause bugs.