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

Slides:



Advertisements
Similar presentations
Computer Architecture
Advertisements

Chapter 3 Basic Input/Output
ECE 353 Introduction to Microprocessor Systems
Lab III Real-Time Embedded Operating System for a SoC System.
Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1.
1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
A look at interrupts What are interrupts and why are they needed.
8051 Core Specification.
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 3: Input/output and co-processors dr.ir. A.C. Verschueren.
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.
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.
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.
Communication Lab - Interrupts 1/13 Sequential Programming  Our C++ programs are sequential ( סדרתיים), they start at the first instruction and end at.
A look at interrupts What are interrupts and why are they needed.
1 Interrupts INPUT/OUTPUT ORGANIZATION: Interrupts CS 147 JOKO SUTOMO.
MS_uC / dnd / V VIC - Vectored Interrupts Programming Microcontroller VIC – Vectored interrupt controller Autumn term K Byte Burst Flash.
INPUT/OUTPUT ORGANIZATION INTERRUPTS CS147 Summer 2001 Professor: Sin-Min Lee Presented by: Jing Chen.
INTERRUPTS PROGRAMMING
What are Exception and Interrupts? MIPS terminology Exception: any unexpected change in the internal control flow – Invoking an operating system service.
General System Architecture and I/O.  I/O devices and the CPU can execute concurrently.  Each device controller is in charge of a particular device.
Exception and Interrupt Handling
Embedded Systems 7763B Mt Druitt College of TAFE
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.
CORTEX-M0 Structure Discussion 2 – Core Peripherals
MICROPROCESSOR INPUT/OUTPUT
2: Computer-System Structures
1-1 Embedded Network Interface (ENI) API Concepts Shared RAM vs. FIFO modes ENI API’s.
Introduction to Embedded Systems Rabie A. Ramadan 6.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 5 part 4 Exceptions.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Microprocessors 1 MCS-51 Interrupts.
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction Purpose  This training course provides an overview of the CPU architecture.
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
AT91 Interrupt Handling. 2 Stops the execution of main software Redirects the program flow, based on an event, to execute a different software subroutine.
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.
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.
Silberschatz, Galvin and Gagne  Applied Operating System Concepts Chapter 2: Computer-System Structures Computer System Architecture and Operation.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
AT91 C-startup. 2 For reasons of modularity and portability most application code for an embedded application is written in C The application entry point.
Embedded Systems Design 1 Lecture Set 8 MCS-51 Interrupts.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
بسم الله الرحمن الرحيم MEMORY AND I/O.
Time Management.  Time management is concerned with OS facilities and services which measure real time.  These services include:  Keeping track of.
9/20/6Lecture 3 - Instruction Set - Al1 Exception Handling.
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.
Interrupts and Interrupt Handling David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
Introduction to Exceptions 1 Introduction to Exceptions ARM Advanced RISC Machines.
DATE S. S.. Sandstone The sandstone carries out the following tasks: 1. Set up target platform environment, 2. Load a bootable image into memory, 3. Relinquish.
Chapter 6 Limited Direct Execution Chien-Chung Shen CIS/UD
Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir. A.C. Verschueren Eindhoven University of Technology Section of Digital.
Interrupts and signals
68HC11 Interrupts & Resets.
Microprocessor Systems Design I
Timer and Interrupts.
Interrupts In 8085 and 8086.
Module 2: Computer-System Structures
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.
An Embedded Software Primer
Lecture 3 - Instruction Set - Al
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
Module 2: Computer-System Structures
COMP3221: Microprocessors and Embedded Systems
Module 2: Computer-System Structures
Presentation transcript:

Exceptions

Exception Types Exception Handling Vectoring Interrupts Interrupt Handlers Interrupt Priorities Interrupt applications 6-2

Exception Types Exceptions caused by executing an instruction  Software interrupts  Undefined instruction  Prefetch abort (accessing an invalid address) Exceptions caused as a side effect of an instruction  Data abort Exceptions unrelated to instruction execution  Reset  IRQ - Usually generated by external peripherals  FIQ - Usually generated by external peripherals 6-3

Exception Handling When an exception occurs  The exception is latched.  The normal program execution is stopped.  The current PC and CPU mode is preserved.  The PC is forced to the corresponding vector location  Program execution continues from this point  For the IRQ and FIQ exceptions when the exception has been processed the environment restored and the PC reloaded so that the original program can resume. The event that caused the exception must be cleared. 6-4

ARM 7 Exception handling When an exception occurs, the CPU will change modes and the PC will be forced to an exception vector. The vector table starts from address zero with the reset vector, and then has an exception vector every four bytes. 6-5 Each operating mode has an associated interrupt vector. When the processor changes mode the PC will jump to the associated vector. NB: there is a missing vector at 0x

Exception Priorities 6-6 If two or more exceptions are asserted they will be served in the following order

6-7 ; Taken from the assembler startup file. ; Exception Vectors ; Mapped to Address 0. ; Absolute addressing mode must be used. ; Dummy Handlers are implemented as infinite loops which can be modified. Vectors LDR PC, Reset_Addr LDR PC, Undef_Addr LDR PC, SWI_Addr LDR PC, PAbt_Addr LDR PC, DAbt_Addr NOP ; Reserved Vector ; LDR PC, IRQ_Addr LDR PC, [PC, #-0x0120] ; Vector from VicVectAddr LDR PC, FIQ_Addr Exception Vectors

6-8 Reset_Addr DCD Reset_Handler Undef_Addr DCD Undef_Handler SWI_Addr DCD SWI_Handler PAbt_Addr DCD PAbt_Handler DAbt_Addr DCD DAbt_Handler DCD 0 ; Reserved Address IRQ_Addr DCD IRQ_Handler FIQ_Addr DCD FIQ_Handler Undef_Handler B Undef_Handler;Tight loops SWI_Handler B SWI_Handler PAbt_Handler B PAbt_Handler DAbt_Handler B DAbt_Handler IRQ_Handler B IRQ_Handler FIQ_Handler B FIQ_Handler Cont.

6-9 ; Reset Handler EXPORT Reset_Handler Reset_Handler ; Clock Setup --- IF (:LNOT:(:DEF:NO_CLOCK_SETUP)):LAND:(CLOCK_SETUP != 0) LDR R0, =SCB_BASE MOV R1, #0xAA MOV R2, #0x55 ; Configure and Enable PLL LDR R3, =SCS_Val ; Enable main oscillator STR R3, [R0, #SCS_OFS] IF (SCS_Val:AND:OSCEN) != 0 OSC_Loop LDR R3, [R0, #SCS_OFS] ; Wait for main oscillator ANDS R3, R3, #OSCSTAT BEQ OSC_Loop ENDIF ETC.

Interrupts 6-10 Two interrupt request inputs to the CPU FIQ - fast interrupt request FIQ higher priority than IRQ Two interrupt request inputs. n implies not i.e. active low.

ARM 7 Interrupts Two interrupt sources FIQ and IRQ FIQ has priority over IRQ  An IRQ handler can be interrupted by an FIQ but not the other way round. Normally only have one interrupt source using the FIQ input. To support multiple interrupt sources on IRQ 1. logically OR together and then in the interrupt handler poll each device (this is slow!), or 2. Use a Vectored Interrupt Controller (VIC) The LPC23XX devices use a VIC 6-11

The VIC The VIC provides support for up to 32 interrupt sources 16 priority levels (fixed hardware priority within a level) the 32 inputs can be designated as either FIQ or as vectored IRQ interrupts. A priority can be assigned to each of the separately vectored IRQs 6-12 VIC FIQIRQ 32 interrupt sources ………... FIQ has higher priority than IRQ

FIQ request The VIC ORs all the requests to produce the FIQ signal to the ARM processor. Remember the FIQ has one vector location only. Normal to only assign one input to the FIQ - otherwise would need the FIQ handler to poll the VIC to find the interrupting signal source. The shortest latency is achieved when only one request is classified as FIQ Leaving the FIQ handler  The interrupt request must be cleared before returning from the interrupt handler. 6-13

Vectored IRQ The VIC ORs all the vectored IRQ requests together to produce the IRQ signal to the ARM7 processor. The VIC has a table of interrupt address handlers for each IRQ interrupt source. When the IRQ is asserted to the ARM7 the address corresponding to the interrupt source is copied from the table into a special VICAddress register which is then accessed by the IRQ handler to go to the correct interrupt handler. Leaving a vectored IRQ  The interrupt request must be cleared before returning from the interrupt handler AND  a dummy write to the VIC to signal the end of the current IRQ 6-14

IRQ Vector instruction The instruction placed on the IRQ vector must load the contents of the Vector address register into the PC LDR PC,[PC,#-0xFF0] 6-15

Interrupts diagrammatically 6-16 Read by IRQ handler and put into Program Counter (PC) Interrupt signals from the 32 sources Each interrupt is individually enabled Select which interrupts are FIQ and which are vectored IRQ

Vectored IRQs 6-17 IRQ status[0:31 ]

IRQ Vectored IRQ process 6-18 Priority encoder Vector Address Vec 0 Vec 1 Vec 2 Vec 3 Vec 4 …. Vec 31 Timer 0 Each of the 32 interrupt sources from the various peripherals is allocated a slot in the table. Eg. Timer 0 is allocated the number 4, external interrupt 0 is allocated to Interrupt Sourcs Vector Address X Lvl 9 Lvl 15

6-19 Keil 'C' Language Extensions The C Compiler allows designation of a 'C' function as an Interrupt Handler by adding __irq after the function header in both the function declaration and the function definition. void IntHandler(void) __irq; The Interrupt handler cannot accept any input arguments i.e the argument list must be (void) Also the return type MUST be void. An interrupt handler function MUST NEVER be called directly from the main program code!! The Interrupt Handler is only invoked by the hardware interrupt vectoring mechanism.

To summarise the procedure Configure the peripheral i.e. enable interrupts within the peripheral Enable the peripheral bit within the VIC Select to use either the FIQ or IRQ interrupt Set the priority of the interrupt 0-15 (0 highest) Set the Vector address for the interrupt handler  FIQ - fixed at address 0x C  IRQ - set vector address in relevant slot of VIC Write the interrupt handler, which should terminate by clearing the request before returning. 6-20

Interrupt usage Used for non periodic and/or asynchronous events. Avoids polling which is potentially wasteful of CPU processing time. Allows the main program to be seen as a background task and the interrupts as higher priority tasks or events that must take precedence. Good for responding to events and data input. Avoids loss of input data which could happen with polling 6-21

6-22 The Interrupt Handler Interrupt handler routine  local variables are created on each invocation  use static keyword to preserve local variable value between invocations e.g. static int value = 0; Data communication between main program and ISR is via shared global variables.  this introduces mutual exclusion problems  Cannot access a common resource concurrently from two execution threads (concurrent access) Other problems - Re-entrancy of functions  The ISR calls a function that was being executed when this interrupt occurred.

6-23 Interrupt Processing Solutions to the mutual exclusion problem  disable the interrupt during the main program access of the shared variables.  use a single atomically accessed variable - not possible in many cases!  use semaphores and mutexes - requires an Operating System that supports these features Solution to the function re-entrancy problem  Don't call any functions from the ISR  Make sure function is re-entrant - not always possible

Data Buffering and Interrupts Decouples main program from interrupt handler Moves data processing from the interrupt handler in to the main program Use of "Circular Buffers" to provide optimum buffer usage Main program Read data from buffer and processes it. Move Rdptr and decrement count Interrupt Handler Input data from peripheral and store in buffer. Move Wrptr pointer and increment count Data Buffer (size = N) X0X0 X1X1 X2X2 Count = 3 Rdptr Wrptr

6-25 Interrupt Techniques Interrupt Handler input X if (count < N) { //store in buffer Buffer[Wrptr] = X Wrptr++ if (Wrptr == N) { Wptr = 0 } count++ } Part of main program if (count > 0) { //process all data while (count > 0) { val = Buffer[Rdptr] Rdptr++ if (Rdptr == N) { Rdptr = 0 } count-- //process val } α What if count == N? β What about mutual exclusion? What are initial values? α β

Solution to the mutual exclusion problem The disabling of interrupts would not be required if it could be guaranteed that the decrement of the count was an atomic(indivisible) operation and could not be interrupted midway through the operation 6-26 Rdptr++ if (Rdptr == N) { Rdptr = 0 } disable interrupt count-- enable interrupt //process val }