Reputation: 89
what is the meaning of following code
#if _GNU_
_attribute_((_naked_))
#elif _ICCAVR32_
#pragma shadow_registers = full
#endif
this part of code is placed before a interrupt handler. can anyone explain what is the meaning of this.
Upvotes: 1
Views: 119
Reputation: 10224
Normally, when you enter an ISR the compiler will save all of the registers, and restore them on exit. (For example, it might push them onto the stack before the ISR, and pop them off afterwards.)
If an ISR is marked as naked, this context-saving code will not be generated.
That saves significant overhead in the event that few or none of the registers are actually used, but it does so by shifting the onus onto the programmer to ensure that any modifications made to the context are undone (through manual saving and restoring of the register values).
__attribute__((__naked__))
is how GCC refers to this, and #pragma shadow_registers = full
achieves a similar result on the ICC compiler.
There's a fairly good explanation of this in the avr-gcc documentation.
To give you an example in the AVR context, it's quite common to run a watchdog timer on chips.
The watchdog timer may be reset by a singe instruction, WDR
, which is guaranteed not to touch SREG
.
If you reset this in, say, the TIMER0_COMPA
interrupt, then we have two options:
WDR
itself, ignoring RETI
etc)Upvotes: 4