Hi
Want to know if there is a way to instruct the compiler to preserve more than the normal registers (R0-R3, R12, LR, PSR, and PC) during an interrupt.
Regards Viktor Bucher
Surely, the compiler has to preserve whatever registers it uses - and, if it doesn't use a register, there is no point in preserving it?!
Not exactly. I wrote an assembly function that is called from inside the interrupt. This function uses more registers than those that are preserved by the interrupt itself
A compiler always (at least if the processor allows it) defines a number of scratch registers that may be used without second thought.
But any function playing with other registers must take 100% responsibility for such use, and restore the expected state before returning or calling another function that hasn't been explicitly written to accept these exceptional register uses.
Those registers must only be preserved during an interrupt call and not when called from the main program.
Then write two versions of the function, one for calling from the ISR and one for calling from the main program. That avoids pesky reentrancy issues, too.
If you are using a Cortex M3, the PC, xPSR, r0-r3, r12 and LR are saved automatically BY THE PROCESSOR when the interrupt is generated.
If you use any other registers than these as scratch registers, you will need to save those your self. That is the same for non-interrupt functions (i.e. if you use any registers other than these you will need to save them) This means that on a Cortex-M3 processor you DO NOT need to distinguish between interrupt functions and non interrupt functions. The processor handles saving scratch registers used in the ARM calling convention you never need to know you are being called from an interrupt or a normal call.
Hi all
I agree with you people. I already know all the solution posted here. I just wanted to know if there is a command/pragma whatever may exist to inform the interrupt function it should preserve some other registers. Just that
Thank
I am speaking about Cortex-M3 here, if your processor is different please ignore.
No there is not because there is NEVER a need for this. When I say NEVER it is not that there are some cases that it may be useful, it is NEVER. You NEVER need and NEVER want this.
The Cortex-M3 was built with the ARM calling convention fully in mind. Any function that follows the ARM calling convention can be called from an interrupt or a normal function call. There is nothing more to do. The Cortex-M3 handles any differences between interrupt / normal call BEFORE the calls are made. There is no need to do anything different in an interrupt routine or a normal function call. If you are finding a need for this than you should reevaluate why you think you have this need, because you do not.
Robert,
I concur.
--Cpt. Vince Foster 2nd Cannon Place Fort Marcy Park, VA (P.S. my shortest post ever)
Actual content: 2 words;
Total word-count: 18.
/*------------------------------------------------------------------. ; Dear Andy, I comment my code with the same ratio of content ; ; to code ratio. This keeps the clearity to any other code-monkey ; ; who reads my work easy to understand. ; '------------------------------------------------------------------*/ word_count = (u8)49; return( word_count );
--Cpt. Vince Foster 2nd Cannon Place Fort Marcy Park, VA
/*------------------------------------------------------------------. ; Dear Andy, I comment my code with the same ratio of comment ; ; to code ratio. This keeps the clarity to any other code-monkey ; ; who reads my work easy to understand. ; '------------------------------------------------------------------*/ word_count = (u8)49; return( word_count );
And I see that you code with redundancy too ;)
Are you referring to my error in 'content' vs 'comment' error, or are you referring to the fact that I don't simply return a value, and that I also type-cast numbers?:
{ ... word_count = (u8)49; return( word_count ); // versus the typical [poor-form] return statement: return( 49 ); }
--Cpt. Vince Foster 2nd Cannon Place Fort Marcy Park, VA ?
I was referring to the posts from 16-Apr-2009 12:12 and 16-Apr-2009 12:18 that showed a significant redundancy, but a bit of transfer or encoding errors between the copies. But I would prefer an odd number of copies to be able to majority-vote on the correct copy :)
"Majority Vote" logic... ahhh, odd indeed. That is why I like Actel FPGAs so much. Rad-Hard.
And I have a headache too. (15mg of Hydrocodone isn't doing it for me)
I would think Potassium Iodide would be better than Hydrocodone if you where striving for rad-hardening. Doubtful if it helps with a headache.
Hello Cpt. Vince,
Here are possible side effects of using Hydrocodone :-) I hope you are better now
Severe allergic reactions (rash; hives; itching; difficulty breathing; tightness in the chest; swelling of the mouth, face, lips, or tongue); bloody, black, or tarry stools; blurred vision; change in the amount of urine produced; chest pain; confusion; dark urine; depression; fainting; fast or irregular heartbeat; fever, chills, or persistent sore throat; mental or mood changes; numbness of an arm or leg; one-sided weakness; red, swollen, blistered, or peeling skin; ringing in the ears; seizures; severe headache or dizziness; severe or persistent stomach pain or nausea; severe vomiting; shortness of breath; slow or shallow breathing; stiff neck; sudden or unexplained weight gain; swelling of hands, legs, or feet; unusual bruising or bleeding; unusual joint or muscle pain; unusual tiredness or weakness; vision or speech changes; vomit that looks like coffee grounds; yellowing of the skin or eyes.
Thanks, and yes, I am better now. I hate those things (headaches).
As for the 'effects' go, since I already have each one of those effects prior to taking any medication, I didn't notice anything different... my headache went away.
And as for the "vomit that looks like coffee grounds", we've been using that in our coffee maker: way cheaper than Kopi Luwak.
View all questions in Keil forum