Communication Lab - Interrupts 1/13 Sequential Programming  Our C++ programs are sequential ( סדרתיים), they start at the first instruction and end at.

Slides:



Advertisements
Similar presentations
Exceptions. Exception Types Exception Handling Vectoring Interrupts Interrupt Handlers Interrupt Priorities Interrupt applications 6-2.
Advertisements

A look at interrupts What are interrupts and why are they needed.
I/O Unit.
FIU Chapter 7: Input/Output Jerome Crooks Panyawat Chiamprasert
68HC11 Polling and Interrupts
Interfacing. This Week In DIG II  Basic communications terminology  Communications protocols  Microprocessor interfacing: I/O addressing  Port and.
Interrupts What is an interrupt? What does an interrupt do to the “flow of control” Interrupts used to overlap computation & I/O – Examples would be console.
Outline  Examine some of the H/W supplied with a typical PC and consider the software required to control it.  Introduce Commkit, a software tool that.
COMP3221: Microprocessors and Embedded Systems Lecture 15: Interrupts I Lecturer: Hui Wu Session 1, 2005.
© 2006 Pearson Education, Upper Saddle River, NJ All Rights Reserved.Brey: The Intel Microprocessors, 7e Chapter 13 Direct Memory Access (DMA)
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.
LOGO Chapter 1 Interrupt handling. hardware interrupt Under x86, hardware interrupts are called IRQ's. When the CPU receives an interrupt, it stops whatever.
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.
Introduction An interrupt is an event which informs the CPU that its service (action) is needed. Sources of interrupts: internal fault (e.g.. divide by.
A look at interrupts What are interrupts and why are they needed.
Computer System Structures memory memory controller disk controller disk controller printer controller printer controller tape-drive controller tape-drive.
Dr. Kimberly E. Newman Hybrid Embedded wk3 Fall 2009.
INPUT/OUTPUT ORGANIZATION INTERRUPTS CS147 Summer 2001 Professor: Sin-Min Lee Presented by: Jing Chen.
The 8051 Microcontroller and Embedded Systems
INTERRUPTS PROGRAMMING
1 Computer System Overview Chapter 1 Review of basic hardware concepts.
What are Exception and Interrupts? MIPS terminology Exception: any unexpected change in the internal control flow – Invoking an operating system service.
Interrupts. 2 Definition: An electrical signal sent to the CPU (at any time) to alert it to the occurrence of some event that needs its attention Purpose:
Introduction to Embedded Systems
COMP201 Computer Systems Exceptions and Interrupts.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
UNIT 8 Keypad Interface Contact Closure Counter Exceptions (Interrupts and Reset)
1 Computer System Overview Chapter 1. 2 n An Operating System makes the computing power available to users by controlling the hardware n Let us review.
MICROPROCESSOR INPUT/OUTPUT
CoE3DJ4 Digital Systems Design Chapter 6: Interrupts.
The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of.
1 COMPUTER ARCHITECTURE (for Erasmus students) Assoc.Prof. Stasys Maciulevičius Computer Dept.
Interrupt.
1. Registers Used in Timer/Counter  TH0, TL0, TH1, TL1  TMOD (Timer mode register)  TCON (Timer control register) 2.
Microprocessors 1 MCS-51 Interrupts.
1 © Unitec New Zealand Interrupt Lecture 6 Date: - 20 Sept, 2011 Embedded Hardware ETEC 6416.
1 Interrupts, Resets Today: First Hour: Interrupts –Section 5.2 of Huang’s Textbook –In-class Activity #1 Second Hour: More Interrupts Section 5.2 of Huang’s.
AT91 Interrupt Handling. 2 Stops the execution of main software Redirects the program flow, based on an event, to execute a different software subroutine.
6-1 Infineon 167 Interrupts The C167CS provides 56 separate interrupt sources that may be assigned to 16 priority levels. The C167CS uses a vectored interrupt.
7. IRQ and PIC ENGI 3655 Lab Sessions. Richard Khoury2 Textbook Readings  Interrupts ◦ Section
Embedded Systems Design 1 Lecture Set 8 MCS-51 Interrupts.
EE/CS-352: Embedded Microcontroller Systems Part V The 8051 Assembly Language Interrupts.
بسم الله الرحمن الرحيم MEMORY AND I/O.
9/20/6Lecture 3 - Instruction Set - Al1 Exception Handling.
Lecture 3 CSE 341 – Microprocessors Lecture 3 Md. Omar Faruqe UB 1228
kashanu.ac.ir Microprocessors Interrupts Lec note 8.
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.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Intel 8259A PIC EEE 365 [FALL 2014] LECTURE 21 ATANU K SAHA BRAC UNIVERSITY.
Transmitter Interrupts Review of Receiver Interrupts How to Handle Transmitter Interrupts? Critical Regions Text: Tanenbaum
CS501 Advanced Computer Architecture
68HC11 Interrupts & Resets.
Microprocessor Systems Design I
Lesson Objectives Aims Key Words Interrupt, Buffer, Priority, Stack
Introduction An interrupt is an event which informs the CPU that its service (action) is needed. Sources of interrupts: Internal fault (e.g.. divide by.
Interrupts In 8085 and 8086.
Day 08 Processes.
Day 09 Processes.
BVM Engineering College Electrical Engineering Department : Microprocessor and Microcontroller Interfacing Interrupts of 8051 Prepared by:
8259 Chip The Intel 8259 is a family of Programmable Interrupt Controllers (PIC) designed and developed for use with the Intel 8085 and Intel 8086 microprocessors.
Interrupt Driven I/O References Text: Tanenbaum ch.1.4.3, ch Receiver Interrupt Program Example:
Computer System Overview
Processor Fundamentals
8259 Programmable Interrupt Controller
Transmitter Interrupts
COMPUTER PERIPHERALS AND INTERFACES
Programmable Interrupt Controller (PIC)
COMP3221: Microprocessors and Embedded Systems
Presentation transcript:

Communication Lab - Interrupts 1/13 Sequential Programming  Our C++ programs are sequential ( סדרתיים), they start at the first instruction and end at the last.  Wrong!!! Loops, branches, and function calls jump from instruction to instruction in a non-linear way.  However, the jumps are planned by the programmer. A function call or branch jumps to a known location.

Communication Lab - Interrupts 2/13 Function Call a = b + c; d = f1(a); e = a + 17; int f1(int x){ x = x*7; x = x + 1; return(x); }  The jump to the function occurs at a known position in the program.  But what if we are waiting for an external event, such as receiving a signal on the serial port?

Communication Lab - Interrupts 3/13 Interrupting Execution  The OS (Operating System) interrupts program execution all the time, switching to another users code (or to the system’s code).  However the user doesn’t notice this, it looks like the his/her program is being run exclusively (באופן בלעדי). a = b + c; d = b << 3; OS interrupt e = a + 17; strcpy(str1,””); if(c == ‘1’) str1[0] = ‘_’; str1[1] = c; OS interrupt

How is Code Interrupted on a PC?  IRQ (Interrupt ReQuest) lines are connected to various devices (parallel and serial ports, timer, disk controller, sound card …).  When the device sets its IRQ a signal is sent to the PIC (Programmable Interrupt Controller).

Communication Lab - Interrupts 5/13 Notifying the Processor  When an IRQ is set the PIC receives a signal.  It then checks the Interrupt Mask Register (IMR). The IMR contains a bit for each IRQ. If the corresponding bit is set the IRQ is masked, the interrupt won’t be received.  The request is then transferred into the Interrupt Request Register (IRR). It is held there until it is serviced.  The IRR is transferred into the priority handler, which decides which interrupt to handle first (if there are several requests pending).  The highest priority interrupt is then moved into the In Service Register (ISR).  A signal is sent to the processor.  The processor finishes executing the current instruction, looks at the ISR and sees which IRQ has been signaled.  The processor jumps to a function which “handles” the interrupt, this is called an interrupt handler or Interrupt Service Routine (ISR).

Communication Lab - Interrupts 6/13 The Interrupt Vector  The first 256 words (1024 bytes) of memory holds the Interrupt Vector. Each can hold the address of an ISR.  Each IRQ has a fixed address in the interrupt vector.  The IRQs and ISR entries for the serial ports are: COM1/COM3: IRQ 4ISR 0xC COM2/COM4: IRQ3ISR 0xB

Communication Lab - Interrupts 7/13 Writing an ISR  First we have to write the ISR: #define COM1 0x3F8 void interrupt COM1INT() /* ISR for COM1 */ { int c; c = inportb(COM1 + 5); if (c & 1) { /* if the DR is set, read */ buffer[counter] = inportb(COM1); counter++; /* buffer and counter are */ } /* global variables */ outportb(0x20,0x20); /* signal End of */ } /* Interrupt (EOI) */

Communication Lab - Interrupts 8/13 Setting an ISR  In order to have the ISR activated we have to set the interrupt vector: #define COM1VECT 0x0C void interrupt (*oldcom1isr)(); oldcom1isr = getvect(INTVECT); /* Save old Interrupt Vector.*/ setvect(COM1VECT, COM1INT); /* Set Interrupt Vector Entry */  Now when IRQ 4 (COM1) is set the processor will jump to our ISR. Not yet.  The IRQ is still masked.

Communication Lab - Interrupts 9/13 Unmasking the IRQ  The PIC’s IMR is accessed through Port 0x21: outportb(0x21,(inportb(0x21) & 0xEF)); /* Set PIC to unmask IRQ 4 */  OxEF resets (zeros) the 5th bit of the IMR, leaving all other bits untouched.  Now will we jump to our ISR if IRQ 4 is set? Yes, but IRQ 4 won’t be set!  We have to enable Interrupts through the UART.

Communication Lab - Interrupts 10/13 The Interrupt Enable Register (IER)  The IER is register 1 of the UART. It’s bits are: Bit 0: Interrupt when the DR is set. Bit 1: Interrupt when the THR is empty. Bit 2: Interrupt when the LSR (Line Status Register) is modified. Bit 3: Interrupt when the MSR (Modem Status Register) is modified. Bit 4-7: Reserved  So in order to jump to the ISR when the DR is set we must set bit 0 of the IER: outportb(COM1 + 1, 0x01); /* Set the IER to enable interrupts when data is pending. */

Communication Lab - Interrupts 11/13 The Interrupt Identification Register (IIR)  If more than 1 bit is set in the IER, we won’t know why the interrupt occurred  The IIR has this information. Its bits are: Bit 0: 0 - an interrupt is waiting to be handled. 1 - no interrupt. Bits 2,1: 00 - MSR change 01 - THR empty 10 - DR set 11 - LSR change Bits 3-7: Reserved.

Communication Lab - Interrupts 12/13 Why Use Interrupts?  Good question? The other alternative is to perform polling, in a loop read the MSR and LSR and check for changes.  Using interrupts the program can do other things or just wait until data is received.  But isn’t jumping to an ISR for every byte received wasteful? Indeed it is.  The solution is simple. Once in an ISR read until there aren’t any more bytes to read.

Communication Lab - Interrupts 13/13 Buffered ISR void interrupt COM1INT() /* ISR for COM1 */ { int c; do { c = inportb(COM + 5); if (c & 1) { buffer[counter] = inportb(COM1); counter++; if (counter == MAXBUF) { counter = 0; } } }while (c & 1); outportb(0x20,0x20); }