Download presentation
Presentation is loading. Please wait.
1
Interrupt Programming
Presented by: Jered Aasheim Tom Cornelius February 1, 2000
2
What Is An Interrupt? An interrupt is an asynchronous signal that some event has occurred. The event depends entirely on the application/environment. Examples: 1) Interrupt can occur whenever a timer expires. 2) Interrupt when a byte has been received on the serial port 3) Interrupt can occur because of an external event (i.e. a sensor has just collected some data, an A/D conversion is complete, etc.) Maskable interrupts can be enabled/disabled by the developer; this gives you the choice of servicing a particular type of interrupt.
3
Interrupts on the TD40
4
Using Interrupts On any system, there are three steps required to use interrupts: 1) Create the interrupt service routine (ISR). The ISR is the portion of code that executes once the interrupt occurs. 2) Setup the interrupt vector table (IVT). The IVT is the portion of memory that holds the addresses of the ISRs for each of the respective interrupts. The system uses this table to know where to jump to in order to execute the ISR. 3) Configure the interrupt source. Nearly all interrupts have SFRs that help control their behavior.
5
Create the Interrupt Service Routine
On the TD40, you must use the interrupt keyword to designate a subroutine as an ISR: void interrupt far Timer0_ISR (void) { … // Code to handle interrupt // Issue a specific EOI for the interrupt outport(0xFF22, 0x0008); } The EOI is a special signal used to inform the CPU that the interrupt has been handled and to clear the interrupt condition.
6
Setup the Interrupt Vector Table
The interrupt vector table is a portion of memory used by the system to determine where the ISRs are for each of the respective interrupts. Each interrupt has a fixed “slot” in the IVT. This slot needs to be loaded with the address of the ISR to handle this interrupt. Example: From the documentation, we see that the “slot” (i.e. the vector address) for Timer0 is 0x0020: *(void far* far*)(0x0020) = Timer0_ISR; This C code will load the the Timer0 “slot” in the IVT with the address of the Timer0 ISR. When an interrupt occurs, the CPU will look into the IVT and then jump to the Timer0_ISR routine.
7
Configure the Interrupt Source
Nearly all interrupts have SFR(s) that control their behavior. For example, the timer SFRs on the TD40 are: NOTE: The TCUCON SFR also needs to be configured for timers.
8
Hints/Tips Keep the code that handles interrupts (i.e. the ISRs) as small possible. Avoid long loops and code that relies on user input. Be aware that higher priority interrupts may occur when you are servicing an interrupt. Most systems allow you to assign priorities to individual interrupts. You can also globally disable interrupts when executing an ISR. Be sure to signal the CPU when an interrupt is done being processed; this is usually done using the EOI (End of Interrupt) instruction. Hard real-time systems require a strict upper bound on the amount of time it takes to service an interrupt (examples: medical devices, fuel injector, etc.) Conversely, soft real-time systems have less strict timing considerations and can “afford” to be late in handling an interrupt (examples: portable music player, cellular telephone, etc.).
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.