Fundamental concept in computation Interrupt execution of a program to handle an event

Similar documents
Processor and compiler dependent

COMP2121: Microprocessors and Interfacing

Microprocessors & Interfacing

Interrupts (I) Lecturer: Sri Notes by Annie Guo. Week8 1

Grundlagen Microcontroller Interrupts. Günther Gridling Bettina Weiss

INTERRUPT, TIMER/COUNTER. KONKUK UNIV. VLSI Design Lab. LSI Design Lab

Microprocessors & Interfacing

Interrupts (II) Lecturer: Sri Parameswaran Notes by: Annie Guo

AGH University of Science and Technology Cracow Department of Electronics

AVR134: Real Time Clock (RTC) Using the Asynchronous Timer. Features. Introduction. AVR 8-bit Microcontrollers APPLICATION NOTE

Embedded Systems and Software

Timers and Interrupts. Mark Neil - Microprocessor Course

AGH University of Science and Technology Cracow Department of Electronics

80C51 Block Diagram. CSE Overview 1

AVR Timers TIMER0. Based on:

EEL 4744C: Microprocessor Applications. Lecture 7. Part 1. Interrupt. Dr. Tao Li 1

Reading Assignment. Interrupt. Interrupt. Interrupt. EEL 4744C: Microprocessor Applications. Lecture 7. Part 1

PC Interrupt Structure and 8259 DMA Controllers

Module 3. Embedded Systems I/O. Version 2 EE IIT, Kharagpur 1

INTERRUPTS in microprocessor systems

Introduction to Embedded Systems

Interrupt/Timer/DMA 1

EE458 - Embedded Systems Exceptions and Interrupts

8-bit Microcontroller. Application Note. AVR134: Real-Time Clock (RTC) using the Asynchronous Timer. Features. Theory of Operation.

Newbie s Guide to AVR Interrupts

e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: Interrupt Handling Module No: CS/ES/13 Quadrant 1 e-text

ATmega Interrupts. Reading. The AVR Microcontroller and Embedded Systems using Assembly and C) by Muhammad Ali Mazidi, Sarmad Naimi, and Sepehr Naimi

CHAPTER 11 INTERRUPTS PROGRAMMING

Physics 120B: Lecture 11. Timers and Scheduled Interrupts

TIMSK=0b ; /* enables the T/C0 overflow interrupt in the T/C interrupt mask register for */

Atmel AVR Timers and Interrupts

AVR Helper Library 1.3. Dean Ferreyra

Interrupts and timers

UBC104 Embedded Systems. Review: Introduction to Microcontrollers

Physics 124: Lecture 12. Timer Basics. Timers and Scheduled Interrupts

Chapters 2, 3: bits and pieces. Chapters 2 & 3. Chapters 2, 3: bits and pieces. Chapters 2, 3: bits and pieces. Using C. A last word about hardware

Microprocessors B (17.384) Spring Lecture Outline

12. Interrupts and Programmable Multilevel Interrupt Controller

8-bit Microcontroller with 8K Bytes Programmable Flash AT90C8534. Preliminary

e-pg Pathshala Subject: Computer Science Paper: Embedded System Module: Interrupt Programming in Embedded C Module No: CS/ES/20 Quadrant 1 e-text

Timer Module Timer A. ReadMeFirst

Microprocessors and Microcontrollers (EE-231)

8-bit Microcontroller. Application Note. AVR134: Real-Time Clock (RTC) using the Asynchronous Timer. Features. Theory of Operation.

Topic 11: Interrupts ISMAIL ARIFFIN FKE UTM SKUDAI JOHOR

Microcontrollers. Program organization Interrupt driven I/O. EECE 218 Microcontrollers 1

ECE 372 Microcontroller Design Parallel IO Ports - Interrupts. ECE 372 Microcontroller Design Parallel IO Ports - Interrupts

Interrupts. Embedded Systems Interfacing. 08 September 2011

ECE 354 Computer Systems Lab II. Interrupts, Strings, and Busses

EE 308: Microcontrollers

Distributed Real- Time Control Systems. Lecture 7 Real- Time Control

Chapter 6 PROGRAMMING THE TIMERS

Introduction to the MC9S12 Hardware Subsystems

Chapter 2. Overview of Architecture and Microcontroller-Resources

12.1. Unit 12. Exceptions & Interrupts

Distributed Real-Time Control Systems. Chapter 10 Real-Time Digital Control

OS Structure. Hardware protection & privilege levels Control transfer to and from the operating system

Topic 11: Timer ISMAIL ARIFFIN FKE UTM SKUDAI JOHOR

General Purpose Programmable Peripheral Devices. Assistant Professor, EC Dept., Sankalchand Patel College of Engg.,Visnagar

real-time kernel documentation

These three counters can be programmed for either binary or BCD count.

Wireless Sensor Networks (WSN)

8085 Interrupts. Lecturer, CSE, AUST

3. (a) Explain the steps involved in the Interfacing of an I/O device (b) Explain various methods of interfacing of I/O devices.

AN HONORS UNIVERSITY IN MARYLAND UMBC. AvrX. Yousef Ebrahimi Professor Ryan Robucci

2. (2 pts) If an external clock is used, which pin of the 8051 should it be connected to?

EKT222 Miroprocessor Systems Lab 5

Interrupt Basics Karl-Ragmar Riemschneider

8086 Interrupts and Interrupt Responses:

Embedded Controller Programming II. I/O Device Programming in C Part 1: Input and Interrupts

Marten van Dijk, Syed Kamran Haider

EE4390 Microprocessors

Interrupts and Low Power Features

Yielding, General Switching. November Winter Term 2008/2009 Gerd Liefländer Universität Karlsruhe (TH), System Architecture Group

8-bit Microcontroller with 2K Bytes of In-System Programmable Flash. ATtiny22 ATtiny22L. Preliminary. Features. Description

CPEG300 Embedded System Design. Lecture 6 Interrupt System

Lab 9: On-Board Time Generation and Interrupts

By the end of Class. Outline. Homework 5. C8051F020 Block Diagram (pg 18) Pseudo-code for Lab 1-2 due as part of prelab

Marten van Dijk Department of Electrical & Computer Engineering University of Connecticut

Mark Redekopp, All rights reserved. EE 357 Unit 10b. Interrupts Timers

Interrupts, timers and counters

Interrupts Arduino, AVR, and deep dark programming secrets. What is an Interrupt?

Chapter 7 Central Processor Unit (S08CPUV2)

Department of Electronics and Instrumentation Engineering Question Bank

Interrupt is a process where an external device can get the attention of the microprocessor. Interrupts can be classified into two types:

Lecture 5: MSP430 Interrupt

8-bit Microcontroller with 1K Byte of In-System Programmable Flash AT90S1200

Menu. Polling Example

ECE 354 Introduction to Lab 2. February 23 rd, 2003

8-bit Microcontroller with 2K Bytes of In-System Programmable Flash AT90S2323 AT90LS2323 AT90S2343 AT90S/LS2323. Features.

School of Electrical, Computer and Telecommunications Engineering University of Wollongong Australia

Interrupts. EE4380 Fall 2001 Class 9. Pari vallal Kannan. Center for Integrated Circuits and Systems University of Texas at Dallas

Interrupts & Interrupt Service Routines (ISRs)

8-bit Microcontroller with 1K Byte Flash. ATtiny15L

Timers and interrupts

Interrupts. by Rahul Patel, Assistant Professor, EC Dept., Sankalchand Patel College of Engg.,Visnagar

EE Embedded Systems Design. Lessons Exceptions - Resets and Interrupts

AVR Microcontrollers Architecture

AVR XMEGA Product Line Introduction AVR XMEGA TM. Product Introduction.

An Operating System in Action

Department of EIE / Pondicherry Engineering College. Timer/Counters. Department of EIE / Pondicherry Engineering College 1

Transcription:

Interrupts Fundamental concept in computation Interrupt execution of a program to handle an event Don t have to rely on program relinquishing control Can code program without worrying about others Issues What can interrupt and when? Where is the code that knows what to do? How long does it take to handle interruption? Can an interruption be, in turn, interrupted? How does the interrupt handling code communicate its results? How is data shared between interrupt handlers and programs? CSE 466 - Winter 2008 Interrupts 1 What is an Interrupt? Reaction to something in I/O (human, comm link) Usually asynchronous to processor activities interrupt handler or interrupt service routine (ISR) invoked to take care of condition causing interrupt Change value of internal variable (count) Read a data value (sensor, receive) Write a data value (actuator, send) Main Program Instruction 1 Instruction 2 Instruction 3 Instruction 4.. ISR Save state Instruction 1 Instruction 2 Instruction 3.. Restore state Return from Interrupt CSE 466 - Winter 2008 Interrupts 2 1

Interrupts Code sample that does not interrupt char SPI_SlaveReceive(void) { /* Wait for reception complete */ while(!(spsr & (1<<SPIF))) ; /* Return data register */ return SPDR; } Instead of busy waiting until a byte is received the processor can generate an interrupt when it sets SPIF SIGNAL(SIG_SPI) { RX_Byte = SPDR } CSE 466 - Winter 2008 Interrupts 3 Saving and Restoring Context Processor and compiler dependent Where to find ISR code? Different interrupts have separate ISRs Who does dispatching? Direct Different address for each interrupt type Supported directly by processor architecture Indirect One top-level ISR Switch statement on interrupt type A mix of these two extremes? CSE 466 - Winter 2008 Interrupts 4 2

Saving and Restoring Context How much context to save? Registers, flags, program counter, etc. Save all or part? Agreement needed between ISR and program Where should it be saved? Stack, special memory locations, shadow registers, etc. How much room will be needed on the stack? Nested interrupts may make stack reach its limit what then? Restore context when ISR completes CSE 466 - Winter 2008 Interrupts 5 Ignoring Interrupts Can interrupts be ignored? It depends on the cause of the interrupt No, for nuclear power plant temperature warning Yes, for keypad on cell phone (human timescale is long) When servicing another interrupt Ignore others until done Can t take too long keep ISRs as short as possible Just do a quick count, or read, or write not a long computation Interrupt disabling Will ignored interrupt stick? Rising edge sets a flip-flop Or will it be gone when you get to it? Level changes again and its as if it never happened Don t forget to re-enable CSE 466 - Winter 2008 Interrupts 6 3

Prioritizing Interrupts When multiple interrupts happen simultaneously Which is serviced first? Fixed or flexible priority? Priority interrupts Higher priority can interrupt Lower priority can t Maskable interrupts don t bother me with that right now Not all interrupts are maskable, some are non-maskable CSE 466 - Winter 2008 Interrupts 7 Interrupts in the ATmega16 External interrupts From I/O pins of microcontroller Internal interrupts Timers Output compare Input capture Overflow Communication units Receiving something Done sending ADC Completed conversion CSE 466 - Winter 2008 Interrupts 8 4

Interrupt Jump Vector Table Fixed location in memory to find first instruction for each type of interrupt Only room for one instruction JMP to location of complete ISR CSE 466 - Winter 2008 Interrupts 9 Chain of Events on Interrupt Finish executing current instruction Disable all interrupts Push program counter on to stack Jump to interrupt vector table Jump to start of complete ISR Save any context that ISR may otherwise change Registers and flags must be saved within ISR and restored before it returns this is very important! SEI Re-enable interrupts if nested interrupts are ok Complete ISR s code CLI Re-enable interrupts upon return Jump back to next instruction before interruption Automatic RETI Compiler CSE 466 - Winter 2008 Interrupts 10 5

Shared Data Problem When you use interrupts you create the opportunity for multiple sections of code to update a variable. This might cause a problems in your logic if an interrupt updates a variable between two lines of code that are directly dependent on each other (e.g. if statement) One solution is to create critical sections where you disable the interrupts for a short period of time while you complete your logic on the shared variable cli();..critical section code goes here.. sei(); CSE 466 - Winter 2008 Interrupts 11 External Interrupts Special pins: INT0, INT1, INT2 Can interrupt on edge or level Can interrupt even if set to be output pins Implements software interrupts by setting output CSE 466 - Winter 2008 Interrupts 12 6

Closer Look at a Timer/Counter Timer0/Counter0 Clear timer on compare match (auto reload) Prescaler (divide clock by up to 1024) Overflow and compare match interrupts Registers Configuration Count value Output compare value CSE 466 - Winter 2008 Interrupts 13 Timer/Counter Registers Timer/Counter Control Register TCCR0 CSE 466 - Winter 2008 Interrupts 14 7

Timer/Counter Registers (cont d) Timer/Counter Control Register TCCR0 CSE 466 - Winter 2008 Interrupts 15 Timer/Counter Registers (cont d) Timer/Counter Control Register TCCR0 CSE 466 - Winter 2008 Interrupts 16 8

Timer/Counter Registers (cont d) CSE 466 - Winter 2008 Interrupts 17 Setting Register Values Defined names for each register and bit Set timer to clear on match Set prescaler to 1024 TCCR0 = (1<<WGM01) (1<<CS02) (1<<CS00); Set count value to compare against OCR0 = 150; Set timer to interrupt when it reaches count TIMSK = (1<<OCIE0); CSE 466 - Winter 2008 Interrupts 18 9

Writing an Interrupt Handler in C Set and clear interrupt enable sei(); cli(); Interrupt handler SIGNAL(SIG_OUTPUT_COMPARE0) { i++; } Setting I/O registers TCCR0 = (1<<WGM01) (1<<CS02) (1<<CS00); Enabling specific interrupts TIMSK = (1<<OCIE0); CSE 466 - Winter 2008 Interrupts 19 Writing an Interrupt Handler in C (cont d) Ensure main program sets up all registers Enable interrupts as needed Enable global interrupts (SEI) Write handler routine for each enabled interrupt What if an interrupt occurs and a handler isn t defined? Make sure routine does not disrupt others Data sharing problem Save any state that might be changed (done by compiler) Re-enable interrupts upon return Done by compiler with RETI CSE 466 - Winter 2008 Interrupts 20 10

Power modes Processor can go to sleep and save power Different modes put different sets of modules to sleep Which one to use depends on which modules are needed to wake up processor Timers, external interrupts, ADC, serial communication lines, etc. set_sleep_mode (mode); sleep_mode (); CSE 466 - Winter 2008 Interrupts 21 Power modes (cont d) CSE 466 - Winter 2008 Interrupts 22 11

Power modes (cont d) Wake up sources and active clocks CSE 466 - Winter 2008 Interrupts 23 12