Exceptions and Interrupts - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Exceptions and Interrupts

Description:

Works like a Call, except Flag register is saved, too. CPU saves current state ... Flag Register (re-enables global interrupts) Return to user program (restore PC) ... – PowerPoint PPT presentation

Number of Views:115
Avg rating:3.0/5.0
Slides: 13
Provided by: kevinb7
Category:

less

Transcript and Presenter's Notes

Title: Exceptions and Interrupts


1
Exceptions and Interrupts
2
Exceptional Circumstances
  • At home - how do you know when someone wants to
    talk to you on the telephone?
  • A. Periodically pick up the phone and see if
    someones there
  • This is known as polling
  • B. Wait for the phone to ring and then answer it
  • This is exception- or interrupt-driven

3
When Interrupting is Nice
  • Coordinating I/O operations
  • Notifies the CPU that an input is ready or an
    output can be changed
  • Timing
  • Periodic (clock-driven) interrupts remind the CPU
    of the passage of time
  • Multi-tasking
  • Updating counters
  • Timing during interactive programs
  • Errors
  • Interrupts can notify of error situations

4
Exception Types
  • Hardware (called Interrupts or Resets)
  • Reset
  • User-defined interrupt
  • Timer operations
  • CPU operations monitor failure
  • Software (not on PSoC)
  • Illegal instruction
  • Divide by zero
  • Overflow

5
Im Not listening...
  • Interrupts can sometimes be ignored (or masked)
  • Good for when the CPU is doing something more
    important
  • When the interrupt mask is set, interrupts are
    hidden (masked) and ignored
  • Interrupts may be prioritized
  • The fire alarm is more important than the oven
    timer which is more important than the telephone
  • Non-maskable interrupts cannot be ignored
  • NMIs take precedence and interrupt any task

6
Servicing Interrupts and Exceptions
  • When an exception occurs
  • CPU decides whether to do anything
  • CPU saves current state
  • PC, Flag Register
  • Global interrupts disabled
  • Jump to interrupt service routine (ISR)
  • Execute routine
  • RETI - return from interrupt

Works like a Call, except Flag register is saved,
too.
  • Restore state
  • Flag Register (re-enables global interrupts)
  • Return to user program (restore PC)

7
Interrupt Vector Table
  • When an interrupt occurs, control of the program
    moves to the interrupt service routine (ISR)
  • Similar to a subroutine
  • But how do we know where the ISR is?
  • The address of the ISR is provided by the
    interrupt vector table
  • IVT has one entry for each type of interrupt
  • Each entry is indexed by interrupt type
  • PSoC vector table has four bytes for each entry
  • Usually holds a single LJMP instruction that
    passes control to the ISR

8
Interrupt Vector Table
0004h LJMP to code for handling low voltage
indicator
0010h LJMP to code for handling analog col 2
interrupt
001Ch LJMP to code for handling GPIO interrupt
9
Full PSoC Interrupt Vector Table
Name Identifies source of interrupt
Device Availability
Priority If interrupts happen at the same time,
highest priority interrupt wins
Address Address of interrupt vectorNote Only 4
bytes, usually just an LJMP
10
Programming With Interrupts
  • Write the interrupt service routine
  • What action is to be performed when a particular
    interrupt happens?
  • End with RETI
  • Link the interrupt vector to the ISR
  • At interrupt vector location, write LJMP myISR
  • Usually taken care of by PSoC Designer
  • Write the main routine
  • Enable the interrupt to be serviced
  • Int_MSKx registers control various interrupts
  • Write a 1 into the appropriate bit to enable
    the interrupt
  • See next slide for details
  • Globally enable interrupts
  • Set GIE bit in flag register use
    M8C_EnableGInt
  • Wait. That is, do nothing

11
Interrupt Mask Registers
  • The registers INT_MSKx turn individual interrupts
    on or off
  • Write a 1 to the appropriate bit to turn
    interrupts on
  • The 29466 chip were using has 4 analog columns
    and 4 digital rows (highlighted)
  • See useful equates in M8C.inc under System and
    Global Resource Registers

12
Example - GPIO ISR
Whenever GPIO pin goes high, update and display a
count
1. Select interrupt on pin in Design view(Dont
forget pull-down mode!)
2. Write the GPIO ISR
// ISR for the GPIO interruptPSoC_GPIO_ISR
inc count // increment count mov A,0 //
position LCD at 0,14 mov X,14 call
LCD_1_Position mov A, count call
LCD_1_PrHexByte // print out count reti // all
done - return
Interrupts cant have parameters Must use globals
3. Link ISR to GPIO vector at 001C (Usually done
already in boot.asm)
org 001Ch ljmp PSoC_GPIO_ISR
export count export _main area
bss count blk 1 // define counter area
text _main M8C_EnableGint call
LCD_1_Start call LCD_1_Init or REGINT_MSK0,
00100000 //1 in GPIO position loop jmp loop
4. Write the initialization and main routine
Do-nothing program!
Write a Comment
User Comments (0)
About PowerShow.com