Top Banner

of 21

csd Interrupts

Jun 03, 2018

Download

Documents

Karthikeya Sri
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 8/12/2019 csd Interrupts

    1/21

    Chapter 3: Section 3.2.4

    ARM & Cortex-M4 User Manuals

    Interrupt-Driven Input/Output

  • 8/12/2019 csd Interrupts

    2/21

    Interrupt I/O

    Busy/wait is very inefficient.

    CPU cant do other work while testing device.

    Hard to do simultaneous I/O.

    Interrupts allow a device to change the flow of control inthe CPU.

    Causes subroutine call to handle device.

  • 8/12/2019 csd Interrupts

    3/21

    Interrupt interface

    CPU

    status

    reg

    data

    regmechanism

    PC

    intr request

    intr ack

    data/address

    IR

  • 8/12/2019 csd Interrupts

    4/21

    Interrupt behavior

    Based on subroutine call mechanism.

    Interrupt forces next instruction to be a subroutine call

    to a predetermined location.

    Return address is saved to resume executingforeground program.

    Context switched to interrupt service routine

  • 8/12/2019 csd Interrupts

    5/21

    Interrupt physical interface

    CPU and device are connected by CPU bus.

    CPU and device handshake:

    device asserts interrupt request;

    CPU asserts interrupt acknowledge when it can handle the

    interrupt.

    (See ARM interrupt support)

    http://c/Users/nelsovp/Documents/Course%20Materials/ELEC5260_6260/Slides/ARM%20Interrupts.ppthttp://c/Users/nelsovp/Documents/Course%20Materials/ELEC5260_6260/Slides/ARM%20LPC2292%20Interrupts.pptxhttp://c/Users/nelsovp/Documents/Course%20Materials/ELEC5260_6260/Slides/ARM%20Interrupts.ppthttp://c/Users/nelsovp/Documents/Course%20Materials/ELEC5260_6260/Slides/ARM%20Interrupts.ppthttp://c/Users/nelsovp/Documents/Course%20Materials/ELEC5260_6260/Slides/ARM%20LPC2292%20Interrupts.pptxhttp://c/Users/nelsovp/Documents/Course%20Materials/ELEC5260_6260/Slides/ARM%20Interrupts.ppt
  • 8/12/2019 csd Interrupts

    6/21

    Example: interrupt-driven main

    program

    mai n( ) {whi l e ( TRUE) {

    i f ( got char ) { / / set by i nt r r out i ne

    OUT_DATA = achar ; / / wr i t e charOUT_STATUS = 1; / / set stat usgot char = FALSE; / / r eset f l ag}

    }other processing.

    }

  • 8/12/2019 csd Interrupts

    7/21

    Example: character I/O handlers

    #def i ne I N_DATA ( *( ( vol at i l e unsi gned byte *) 0xE0028018) )

    #def i ne I N_STATUS ( *( ( vol at i l e unsi gned byte *) 0xE002801C) )

    voi d i nput _handl er ( ) {

    achar = I N_DATA; / / gl obal var i abl egot char = TRUE; / / si gnal mai n pr og

    I N_STATUS = 0; / / r eset st at us

    }

    voi d out put _handl er ( ) {} / / i nt er r upt si gnal s char done

  • 8/12/2019 csd Interrupts

    8/21

    Example: interrupt I/O with buffers

    Queue for characters:

    head tailhead tail

    a

    leave one empty slot

    to allow full buffer to

    be detected

  • 8/12/2019 csd Interrupts

    9/21

    Buffer-based input handler

    voi d i nput _handl er ( ) {char achar ;

    i f ( f ul l _buf f er ( ) ) er r or = 1;

    el se {

    achar = I N_DATA; / / r ead char

    add_char ( achar ) ; } / / add t o queue

    I N_STATUS = 0; / / r eset st at us

    i f ( nchar s >= 1) { / / buf f er empt y?

    OUT_DATA = r emove_char ( ) ;

    OUT_STATUS = 1; }} / / above needed t o i ni t i at e out put

  • 8/12/2019 csd Interrupts

    10/21

    Interrupts vs. Subroutines CPU checks interrupt lines between instructions

    Interrupt handler starting address:

    fixed in some microcontrollers

    usually provided as a pointer

    CPU saves its state, to be restored by the interrupt handler Push items on a stack

    And/Or: Save items in special registers

    Handler should save any other registers that it may use

  • 8/12/2019 csd Interrupts

    11/21

    Priorities and vectors

    Two mechanisms allow us to make interrupts more specific: Prioritiesdetermine what interrupt gets CPU first.

    Vectorsdetermine what code is called for each type of

    interrupt.

    Mechanisms are orthogonal: most CPUs provide both.

  • 8/12/2019 csd Interrupts

    12/21

    Prioritized interrupts

    CPU

    device 1 device 2 device n

    L1 L2 .. Ln

    interruptacknowledge

    interruptrequests

  • 8/12/2019 csd Interrupts

    13/21

    Interrupt prioritization

    Masking: interrupt with priority lower than current priorityis not recognized until pending interrupt is complete.

    Non-maskable interrupt(NMI): highest-priority, nevermasked.

    Often used for power-down. Handler may choose to enable other interrupts (allows

    handler to be preempted)

    CPU may also have bit(s) in its status register to enable ormask interrupt requests.

  • 8/12/2019 csd Interrupts

    14/21

    I/O sequence diagram

    :foreground :input :output :queue

    empty

    a

    empty

    b

    bc

    c

  • 8/12/2019 csd Interrupts

    15/21

    Example: Prioritized I/O

    :interrupts :foreground :A :B :C

    B

    A,B

    C

    A

    high priority low priority

  • 8/12/2019 csd Interrupts

    16/21

    Interrupt vectors

    Allow different devices to be handled by different code.

    Interrupt vector table:

    Directly supported by CPU architecture and/or

    Supported by a separate interrupt-support device/function

    handler 0

    handler 1

    handler 2

    handler 3

    Interrupt

    Vector Table

    Head

  • 8/12/2019 csd Interrupts

    17/21

    Interrupt vector acquisition

    :CPU :device

    receive

    requestreceive

    ack

    receive

    vector Synchronous msg

    Asynchronous msg

  • 8/12/2019 csd Interrupts

    18/21

    Generic interrupt mechanism

    intr?N

    Y

    Assume priority selection is

    handled before this point.

    N

    ignore

    Y

    ack

    vector?Y

    N

    timeout?

    Y

    bus error

    call table[vector]

    intr priority >currentpriority?

    continueexecution

    Device sends vector

    CPU calls handler &

    Software processes the request

    CPU acknowledgesthe request

    CPU detects interrupt request

    N

  • 8/12/2019 csd Interrupts

    19/21

    Sources of interrupt overhead

    Handler execution time. Interrupt mechanism overhead.

    Register save/restore.

    Pipeline-related penalties.

    Cache-related penalties. Interrupt latency= time from activation of interrupt signal

    until event serviced.

    ARM worst-case latency to respond to interrupt is 27 cycles:

    2 cycles to synchronize external request. Up to 20 cycles to complete current instruction.

    3 cycles for data abort.

    2 cycles to enter interrupt handling state.

  • 8/12/2019 csd Interrupts

    20/21

    Exception

    Exception: internally detected error.

    Example: divide by 0

    ARM: undefined opcode, data abort, memory error

    Exceptions are synchronous with instructions but unpredictable.

    Build exception mechanism on top of interrupt mechanism.

    Exceptions are usually prioritized and vectorized.

  • 8/12/2019 csd Interrupts

    21/21

    Trap

    Trap(software interrupt): an exception generated by aninstruction.

    Ex: Enter supervisor mode.

    ARM uses SWI instruction for traps.

    Cortex uses SVC instruction (supervisor call)