![Page 1: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/1.jpg)
Interrupts: Not just one of Life’s little annoyances.
Topic Video 055
1Tuesday, 7 July 2009
![Page 2: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/2.jpg)
What is an interrupt?
2Tuesday, 7 July 2009
![Page 3: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/3.jpg)
What is an interrupt?
2Tuesday, 7 July 2009
![Page 4: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/4.jpg)
What is an interrupt?Pete... Take
the rubbish out Please...
2Tuesday, 7 July 2009
![Page 5: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/5.jpg)
What is an interrupt?Pete... Take
the rubbish out Please...I’ll do it
later...
2Tuesday, 7 July 2009
![Page 6: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/6.jpg)
What is an interrupt?Pete... Take
the rubbish out Please...I’ll do it
later...
You will do it now or no computer for a
week...
2Tuesday, 7 July 2009
![Page 7: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/7.jpg)
Why?
• All tasks are not created equal.
• Not all tasks are predictable.
3Tuesday, 7 July 2009
![Page 8: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/8.jpg)
What is a Hardware Interrupt...
X
Y
CCR
PC
StackCPUS12
D
SP
Running
X
Y
CCR
PC
D
SP
4Tuesday, 7 July 2009
![Page 9: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/9.jpg)
What is a Hardware Interrupt...
X
Y
CCR
PC
StackCPUS12
D
SP
Running
X
Y
CCR
PC
D
SP
4Tuesday, 7 July 2009
![Page 10: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/10.jpg)
What is a Hardware Interrupt...
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
Y
CCR
PC
D
SP
4Tuesday, 7 July 2009
![Page 11: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/11.jpg)
What is a Hardware Interrupt...
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
Y
CCR
PC
D
SP
4Tuesday, 7 July 2009
![Page 12: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/12.jpg)
What is a Hardware Interrupt...
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
YCCR
PC
D
SP
4Tuesday, 7 July 2009
![Page 13: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/13.jpg)
What is a Hardware Interrupt...
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
YCCR
PC
D
SP
4Tuesday, 7 July 2009
![Page 14: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/14.jpg)
What is a Hardware Interrupt...
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
YCCR
PC
D
SP
4Tuesday, 7 July 2009
![Page 15: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/15.jpg)
What is a Hardware Interrupt...
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
Y
CCR
PC
D
SP
4Tuesday, 7 July 2009
![Page 16: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/16.jpg)
What is a Hardware Interrupt...
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
Y
CCR
PC
D
SP
Interrupts Disabled
4Tuesday, 7 July 2009
![Page 17: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/17.jpg)
What is a Hardware Interrupt...
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
Y
CCR
PC
D
SP
Interrupts Disabled
5Tuesday, 7 July 2009
![Page 18: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/18.jpg)
What is a Hardware Interrupt...
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
Y
CCR
PC
D
SP
Interrupts Disabled
5Tuesday, 7 July 2009
![Page 19: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/19.jpg)
What is a Hardware Interrupt...
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
Y
CCR
PC
D
SP
PC
Interrupts Disabled
5Tuesday, 7 July 2009
![Page 20: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/20.jpg)
What is a Hardware Interrupt...
X
Y
CCR
PC
StackCPUS12
D
SP
Running
X
Y
CCR
PC
D
SP
PC
CCR
X
Y
Interrupts Disabled
D
SP
5Tuesday, 7 July 2009
![Page 21: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/21.jpg)
What is a Hardware Interrupt...
X
Y
CCR
PC
StackCPUS12
D
SP
Running
X
Y
CCR
PC
D
SP
PC
CCR
X
Y
Interrupts Disabled
D
5Tuesday, 7 July 2009
![Page 22: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/22.jpg)
What is a Hardware Interrupt...
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
Y
CCR
PC
D
SP
PC
CCR
X
Y
Interrupts Disabled
D
5Tuesday, 7 July 2009
![Page 23: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/23.jpg)
What is a Hardware Interrupt...
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
Y
CCR
PC
D
SP
Interrupts Disabled
6Tuesday, 7 July 2009
![Page 24: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/24.jpg)
What is a Hardware Interrupt...
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
Y
CCR
PC
D
SP
Interrupts Disabled
6Tuesday, 7 July 2009
![Page 25: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/25.jpg)
What is a Hardware Interrupt...
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
YCCR
PC
D
SP
6Tuesday, 7 July 2009
![Page 26: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/26.jpg)
What is a Hardware Interrupt...
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
YCCR
PC
D
SP
6Tuesday, 7 July 2009
![Page 27: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/27.jpg)
What is a Hardware Interrupt...
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
YCCR
PC
D
SP
6Tuesday, 7 July 2009
![Page 28: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/28.jpg)
What is a Hardware Interrupt...
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
Y
CCR
PC
D
SP
6Tuesday, 7 July 2009
![Page 29: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/29.jpg)
What is a Hardware Interrupt...
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
Y
CCR
PC
D
SP
6Tuesday, 7 July 2009
![Page 30: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/30.jpg)
What is a Hardware Interrupt...
X
Y
CCR
PC
StackCPUS12
D
SP
Running
X
Y
CCR
PC
D
SP
6Tuesday, 7 July 2009
![Page 31: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/31.jpg)
SCPU12 Interrupts
• The MC9S12XDP512 contains vectored interrupts with hardware priority resolution that can be customized with software.
• The MC9S12XDP512 contains two external dedicated interrupt lines IRQ and XIRQ located on port E.
• The IRQ • The XIRQ
• The MC9S12XDP512 contains numerous internal interrupt sources that are associated with the various internal subsystems.
7Tuesday, 7 July 2009
![Page 32: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/32.jpg)
Questions that need to be answered...
• Do we need an interrupt?
• Who will trigger the interrupt and under what conditions?
• Internal or External source?
• What must be done when it occurs?
• Run some code?
8Tuesday, 7 July 2009
![Page 33: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/33.jpg)
Interrupt Vector Table• What is an Interrupt Vector Table?
• A table of pointers in memory that point to subroutines that need to be executed once the interrupt it triggered.
• Each interrupt source has its own special location in this table.
Vector Address Interrupt Source CCR Mask Local Enable
$FFFE System reset None None
$FFFC Clock Monitor Reset None PLLCTL
$FFFA COP Watchdog Reset None COP Rate select
Vector Base + $F8 Unimplemented OpCode None None
Vector Base + $F6 SWI None None
Vector Base + $F4 XIRQ X-bit None
Vector Base + $F2 IRQ I-bit IRQCR
9Tuesday, 7 July 2009
![Page 34: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/34.jpg)
Setting the Vector Base
• Apart from the vectors for the three reset sources (Reset, Clock Reset and Watchdog Reset) the vector table can be located anywhere inside system memory.
• The vector base address must be set using the IVBR register.
VB7 VB6 VB5 VB4 VB3 VB2 VB1 VB0
IVBR ($0121)
Holds the MSB of the vector base address.
10Tuesday, 7 July 2009
![Page 35: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/35.jpg)
What else?
• The vector table makes the connection between a interrupt source and the corresponding code that must be executed.
• Code that is executed as a result of an interrupt is referred to as an interrupt service routine (ISR).
• By putting the address of the ISR into a particular position of the vector table, will ensure that the ISR will be executed if that interrupt source is triggered.
• So as long as the interrupt source is enabled, the ISR will run.
11Tuesday, 7 July 2009
![Page 36: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/36.jpg)
Controlling Interrupts
• The X bit in the CCR is used to control the XIRQ interrupt source.
• The I bit in the CCR is used to control the remaining interrupt sources.
• The interrupts will only work if they have been properly enabled.
12Tuesday, 7 July 2009
![Page 37: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/37.jpg)
Controlling InterruptsThe Interrupt Process
• Using the two bits in the CCR namely the X and I bits, it is possible to control the entire interrupt subsystem.
• Each maskable interrupt can be individually disabled or enabled by setting the appropriate bit in the device’s control registers.
• During an interrupt, the X bit remains unchanged, this means a non maskable interrupt can occur within an interrupt service routine.
• The use of nested interrupts should be avoided, however it is possible to have nested interrupts if the I bit is cleared during an interrupt service routine (recommended only for experts).
• Interrupts are disabled on reset.
13Tuesday, 7 July 2009
![Page 38: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/38.jpg)
Things you need to do...Initialising Interrupt Vectors
• Before using interrupts, the interrupt vectors must be initialised to point to the appropriate interrupt service routines.
• If a subsystem uses the interrupt facility then the interrupt vector must be set and a interrupt service routine provided.
• The Hardware Reset interrupt vector must be set to point to the beginning of the code.
• When the processor is originally powered up or reset, the routine pointed to by the hardware interrupt service will be executed.
14Tuesday, 7 July 2009
![Page 39: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/39.jpg)
Reset Vector ExampleEntry:
LDS #RAMEnd+1 ; initialize the stack pointer
CLI ; enable interrupts
mainLoop:
BRA *
;**************************************************************
;* Interrupt Vectors *
;**************************************************************
ORG $FFFE
DC.W Entry ; Reset Vector
15Tuesday, 7 July 2009
![Page 40: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/40.jpg)
Interrupt Sources
• Inside the MC9S12XDP512 there are approximately 128 possible subsystem interrupt sources that can be enabled or disabled by bits locally contained within the control registers of the particular I/O subsystem.
• Each of these sources has its own interrupt vector associated with it and therefore has space allocated inside the vector table.
• When an interrupt request is generated the value located in the interrupt vector for the particular source is fetched and loaded into the program counter.
16Tuesday, 7 July 2009
![Page 41: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/41.jpg)
Interrupt SourcesExternal Interrupt Sources (IRQ)
• An interrupt request on the IRQ pin is generated by external logic.• The IRQ pin is an active low signal and you may set it to a level active
or a negative edge response.• The Interrupt Control Register located at $001E contains bits to
select which response is needed and to enable or disable the IRQ pin.
00000DLYIRQENIRQE
Interrupt Control Register (IRQCR): ($001E)
IRQE: IRQ Select Edge Sensitivity (0=level triggered, 1=falling edge triggered).IRQEN: Enable IRQ pin (1=enabled, 0=GPIO)
17Tuesday, 7 July 2009
![Page 42: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/42.jpg)
Other Interrupt SourcesExceptions
• In a system, there are always events that are so important that they should never be ignored.
• These events are usually referred to as exceptions.
RESETThis the hardware reset, this usually take place when the system is reset or firstly powered up. This interrupt has the highest priority of all the interrupts.
18Tuesday, 7 July 2009
![Page 43: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/43.jpg)
CLOCK MONITOR FAILURE
If the CPU clock signals slow down or fails and the Clock monitor is enabled. The clock monitor will detect a problem and issue a CME reset signal. However it is impossible for the CPU to execute the interrupt until the clock signal reappears.
Other Interrupt SourcesExceptions
19Tuesday, 7 July 2009
![Page 44: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/44.jpg)
COMPUTER OPERATING NORMALLYAlso referred to as the watchdog timer. If your program crashes or hangs then this exception is triggered.
Other Interrupt SourcesExceptions
20Tuesday, 7 July 2009
![Page 45: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/45.jpg)
UNIMPLEMENTED OPCODE TRAPIf for some reason the program gets lost and begins executing data, it is highly likely that it will try to execute an unimplemented op-code. If this does occur the CPU will trigger the an interrupt and the unimplemented opcode trap vector will be fetched and executed.
Other Interrupt SourcesExceptions
21Tuesday, 7 July 2009
![Page 46: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/46.jpg)
SOFTWARE INTERRUPTThe software interrupt is effectively a branch to the subroutine whose address is located in the software interrupt vector. It is a software triggered interrupt.
Other Interrupt Sources
22Tuesday, 7 July 2009
![Page 47: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/47.jpg)
NON-MASKABLE INTERRUPT REQUESTXIRQ is an external non-maskable interrupt input. It is controlled using only the X bit in the CCR. Once the X bit has been cleared it is impossible to set this bit again once the program has commenced.
Other Interrupt Sources
23Tuesday, 7 July 2009
![Page 48: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/48.jpg)
InterruptsInterrupt Flags / Internal Interrupt Sources
• There exists many internal interrupt sources form the various built-in subsystems.
• In order to use the interrupt capability of these subsystems, global interrupts must be enabled and the enable bit set in the appropriate control register for the I/O device.
• Some subsystems set a flag bit in a status register when an interrupt occurs and if this flag isn’t reset then an interrupt will trigger again once ISR is complete.
24Tuesday, 7 July 2009
![Page 49: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/49.jpg)
Interrupt Subsystem
25Tuesday, 7 July 2009
![Page 50: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/50.jpg)
Waiting for an Interrupt...
What to do while waiting for an interrupt:
Spin LoopsThe simplest way to make the CPU wait is to implement a spin loop. A spin loop consists of a branch instruction back to itself. For example:
LOOP: BRA LOOP
When an interrupt occurs the loop will be interrupted and will continue the loop when the ISR completes.
26Tuesday, 7 July 2009
![Page 51: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/51.jpg)
WAI: Wait for interruptThe WAI performs two functions:
• Firstly, it pushes the CPU contents onto the stack in preparation for the upcoming interrupt, this reduces the delay involved in executing the ISR.
• Secondly, it places the CPU into a wait state, reducing the overall power consumption. When the interrupt is triggered the ISR is executed and upon returning from the interrupt, the interrupted program will continue from the next instruction following the WAI instruction.
Waiting for an Interrupt...
27Tuesday, 7 July 2009
![Page 52: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/52.jpg)
Stop: Stop clocks instructionThe final method involves using the STOP instruction, this will stop the clocks, and dramatically reduce the power consumption of the CPU. Only the interrupts IRQ, XIRQ and RESET can remove the CPU from this state. You should also ensure that the watchdog timer is disabled otherwise this instruction will trigger a watchdog interrupt.
Waiting for an Interrupt...
28Tuesday, 7 July 2009
![Page 53: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/53.jpg)
What’s so special about an ISR?
• An interrupt service routine (ISR) is simply a subroutine terminated by an RTI instead of RTS.
• The interrupt service routine is only executed once the interrupt vector has been initialised properly, interrupts have been enabled and unmasked, an interrupt has occurred, the CPU registers have been pushed onto the stack, and the vector has been fetched.
29Tuesday, 7 July 2009
![Page 54: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/54.jpg)
What’s so special about an ISR?
• Great care must be taken when using the stack inside an ISR.• All PSH commands must have corresponding PUL commands of
equal size.• All JSR must have corresponding RTS at the end of the
subroutine.• Failure to restore the stack to its original state will result in the
register set being reloaded incorrectly at the end of the ISR.• Hints to writing successful Interrupt Services Routines are:
• Re-enable Interrupts in the ISR only if you need them, if there are higher level interrupts that need servicing then you can re-enable the interrupts by clearing the I bit.
• Do not use nested interrupts, unless you really have to.• Reset any interrupt generating flags in the I/O devices prior to exiting the
ISR. If you do not reset the flag the device will immediately generate another interrupt upon exiting the ISR.
30Tuesday, 7 July 2009
![Page 55: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/55.jpg)
• Do not worry about using registers in the ISR.• Do not assume any register contents.• Keep ISRs simple to begin with. • Keep ISR short.
What’s so special about an ISR?
31Tuesday, 7 July 2009
![Page 56: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/56.jpg)
Another exampleVirgin System
TCO: EQU $FFEE ; Address of vector for Timer channel 0 ORG ROMSTART
Entry: LDS #RAMEnd+1 ; initialize the stack pointer
MOVB #$FF,IVBR
CLI ; enable interrupts
MainLoop: BRA *TCOISR: NOP RTI ORG TCO ;Location of TC0 interrupt vector DC.W TCOISR ; The label of the address is the TCO ISR.
32Tuesday, 7 July 2009
![Page 57: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/57.jpg)
Another exampleuBug12 System
TCO: EQU $FFEE ; Address of vector for Timer channel 0 ORG ROMSTART
Entry: LDS #RAMEnd+1 ; initialize the stack pointer
MOVB #$F7,IVBR
CLI ; enable interrupts
MainLoop: BRA *TCOISR: NOP RTI ORG TCO ;Location of TC0 interrupt vector DC.W TCOISR ; The label of the address is the TCO ISR.
33Tuesday, 7 July 2009
![Page 58: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/58.jpg)
ReCap: The interrupt process...
X
Y
CCR
PC
StackCPUS12
D
SP
Running
X
Y
CCR
PC
D
SP
34Tuesday, 7 July 2009
![Page 59: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/59.jpg)
ReCap: The interrupt process...
X
Y
CCR
PC
StackCPUS12
D
SP
Running
X
Y
CCR
PC
D
SP
34Tuesday, 7 July 2009
![Page 60: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/60.jpg)
ReCap: The interrupt process...
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
Y
CCR
PC
D
SP
34Tuesday, 7 July 2009
![Page 61: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/61.jpg)
ReCap: The interrupt process...
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
Y
CCR
PC
D
SP
34Tuesday, 7 July 2009
![Page 62: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/62.jpg)
ReCap: The interrupt process...
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
YCCR
PC
D
SP
34Tuesday, 7 July 2009
![Page 63: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/63.jpg)
ReCap: The interrupt process...
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
YCCR
PC
D
SP
34Tuesday, 7 July 2009
![Page 64: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/64.jpg)
ReCap: The interrupt process...
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
YCCR
PC
D
SP
34Tuesday, 7 July 2009
![Page 65: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/65.jpg)
ReCap: The interrupt process...
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
Y
CCR
PC
D
SP
34Tuesday, 7 July 2009
![Page 66: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/66.jpg)
ReCap: The interrupt process...
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
Y
CCR
PC
D
SP
Interrupts Disabled
34Tuesday, 7 July 2009
![Page 67: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/67.jpg)
...IRQ...
Reset
X
Y
CCR
PC
Interrupt Vector TableCPUS12
D
SPSP
Interrupts DisabledIRQ
ReCap: The interrupt process...
35Tuesday, 7 July 2009
![Page 68: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/68.jpg)
...IRQ...
Reset
X
Y
CCR
PC
Interrupt Vector TableCPUS12
D
SPSP
Interrupts Disabled
PC
ReCap: The interrupt process...
35Tuesday, 7 July 2009
![Page 69: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/69.jpg)
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
Y
CCR
PC
D
SP
PC
Interrupts Disabled
ReCap: The interrupt process...
36Tuesday, 7 July 2009
![Page 70: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/70.jpg)
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
Y
CCR
PC
D
SP
PC
Interrupts Disabled
ReCap: The interrupt process...
36Tuesday, 7 July 2009
![Page 71: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/71.jpg)
X
Y
CCR
PC
StackCPUS12
D
SP
Running
X
Y
CCR
PC
D
SP
PC
CCR
X
Y
Interrupts Disabled
D
SP
ReCap: The interrupt process...
36Tuesday, 7 July 2009
![Page 72: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/72.jpg)
X
Y
CCR
PC
StackCPUS12
D
SP
Running
X
Y
CCR
PC
D
SP
PC
CCR
X
Y
Interrupts Disabled
D
ReCap: The interrupt process...
36Tuesday, 7 July 2009
![Page 73: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/73.jpg)
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
Y
CCR
PC
D
SP
PC
CCR
X
Y
Interrupts Disabled
D
ReCap: The interrupt process...
36Tuesday, 7 July 2009
![Page 74: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/74.jpg)
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
Y
CCR
PC
D
SP
Interrupts Disabled
ReCap: The interrupt process...
37Tuesday, 7 July 2009
![Page 75: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/75.jpg)
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
Y
CCR
PC
D
SP
Interrupts Disabled
ReCap: The interrupt process...
37Tuesday, 7 July 2009
![Page 76: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/76.jpg)
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
YCCR
PC
D
SP
ReCap: The interrupt process...
37Tuesday, 7 July 2009
![Page 77: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/77.jpg)
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
YCCR
PC
D
SP
ReCap: The interrupt process...
37Tuesday, 7 July 2009
![Page 78: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/78.jpg)
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
YCCR
PC
D
SP
ReCap: The interrupt process...
37Tuesday, 7 July 2009
![Page 79: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/79.jpg)
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
Y
CCR
PC
D
SP
ReCap: The interrupt process...
37Tuesday, 7 July 2009
![Page 80: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/80.jpg)
X
Y
CCR
PC
StackCPUS12
D
SP
Halted
X
Y
CCR
PC
D
SP
ReCap: The interrupt process...
37Tuesday, 7 July 2009
![Page 81: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/81.jpg)
X
Y
CCR
PC
StackCPUS12
D
SP
Running
X
Y
CCR
PC
D
SP
ReCap: The interrupt process...
37Tuesday, 7 July 2009
![Page 82: Topic05 Dealing with Interrupts on the Freescale MC9S12X](https://reader035.vdocuments.mx/reader035/viewer/2022062512/552e02cf4a79593c578b47c6/html5/thumbnails/82.jpg)
Need Further Assistance?
• Ask your Demonstrator,
• Post a question on the Forum,
• Email the Convener, or
• Make an appointment.
38Tuesday, 7 July 2009