Interrupt Handling - Saving Registers

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Interrupt Handling - Saving Registers

6,444 Views
admin
Specialist II
Hello,

I have a question regarding the Resets and Interrupts Tutorial part.

When an interrupt is to be entered, the CPU first stores the registers in the following order:

CCR, A, X, PC_H, PC_L

Quote:
"CCR, being the first register to be restored, the I bit is also restored, enabling interrupts".

Is it possible that a queued interrupt or a newly coming interrupt is serviced BEFORE the other registers are restored (because of the I bit), corrupting by that the stack content ?


Best Regards,
Roger Tannous.
Labels (1)
0 Kudos
7 Replies

514 Views
peg
Senior Contributor IV

Hi Roger,

The order you have shown is the unstacking order, the stacking order is opposite!

Stacking operations are normally last in, first out.

Quote from GP manual:

"An interrupt does not stop the operation of the instruction being executed, but begins when the current instruction completes its operation"

So there you go, concern unfounded!

BR Peg

 

0 Kudos

514 Views
Nabla69
Contributor V
That's a very good point, I like...
 
Freescale MCU are made that even if you always have an interrupt pending, you will progress in the main loop because the next instruction after the RTI starts its execution.
It is not the case with other MCU in which you could stay stuck executing only ISRs forgetting about the main loop because it doesn't have time...
 
Alvin.
0 Kudos

514 Views
peg
Senior Contributor IV

Hi,

I don't think you are correct here, says me, mouthing of before I check for sure.

Peg

 

0 Kudos

514 Views
Nabla69
Contributor V
Hi Peg,
 
I have to concede. Reference Manual of HCS08 does say:

"When an interrupt occurs, The CCR value is saved on the stack before the I bit is automatically set (I would be 0 in the stacked CCR value). When the return-from-interrupt (RTI) instruction is executed to return to the main program, the act of restoring the CCR value from the stack normally clears the I bit.

When the I bit is set, the change takes effect too late in the instruction to prevent an interrupt at the instruction boundary immediately following an SEI or TAP instruction. In the case of setting I with a TAP or SEI instruction, I is actually set at the instruction boundary at the end of the TAP or SEI instruction. In the case of clearing I with a TAP or CLI instruction, I is actually cleared at the instruction boundary at the end of the TAP or SEI instruction. Because of this, the next instruction, after a CLI or TAP that cleared I, will always execute even if an interrupt was already waiting when the CLI or TAP that cleared I was executed. In the case of the RTI instruction, the CCR is restored during the first cycle of the instruction so the 1-cycle delay, associated with clearing I, expires several cycles before the RTI instruction finishes. WAIT and STOP also clear I in the middle of the instruction, so the delay expires before actually entering wait or stop mode.
"

My bad...:smileysad: I'm sure there a way to get blocked though.

Even a bigger cheque for you then !?
Alvin. {RTFM}

0 Kudos

514 Views
Sten
Contributor IV

The restoring of the registers is done in a single instruction (RTI), and because the interrupt status is examined by the CPU at the completion of (not in the middle of)  each instruction, all the registered will be restored before entering the next ISR.

Sten

0 Kudos

514 Views
mke_et
Contributor IV

Just don't forget to pshh and pulh if you change/use it.  That register isn't automatically saved, and if you happen to use it...

 

0 Kudos

514 Views
rhinoceroshead
Contributor I
I don't think Freescale would be that cruel to you.  Although, I think I read somewhere that some of the more complex instructions on the HC12 were interruptable, and that you should disable interrupts before running them if your ISR will modify contents of certain memory locations.  I'm not 100% sure about this, but I think those instructions were fuzzy logic ones.  I really doubt the HC08 has any interruptable instructions.
0 Kudos