6.31.5 AVR Function Attributes
These function attributes are supported by the AVR back end:
interrupt-
Use this attribute to indicate that the specified function is an interrupt handler. The compiler generates function entry and exit sequences suitable for use in an interrupt handler when this attribute is present.
On the AVR, the hardware globally disables interrupts when an interrupt is executed. The first instruction of an interrupt handler declared with this attribute is a
SEIinstruction to re-enable interrupts. See also thesignalfunction attribute that does not insert aSEIinstruction. If bothsignalandinterruptare specified for the same function,signalis silently ignored. naked-
This attribute allows the compiler to construct the requisite function declaration, while allowing the body of the function to be assembly code. The specified function will not have prologue/epilogue sequences generated by the compiler. Only basic
asmstatements can safely be included in naked functions (see Basic Asm). While using extendedasmor a mixture of basicasmand C code may appear to work, they cannot be depended upon to work reliably and are not supported. no_gccisr-
Do not use
__gcc_isrpseudo instructions in a function with theinterruptorsignalattribute aka. interrupt service routine (ISR). Use this attribute if the preamble of the ISR prologue should always readpush __zero_reg__ push __tmp_reg__ in __tmp_reg__, __SREG__ push __tmp_reg__ clr __zero_reg__
and accordingly for the postamble of the epilogue — no matter whether the mentioned registers are actually used in the ISR or not. Situations where you might want to use this attribute include:
- Code that (effectively) clobbers bits of
SREGother than theI-flag by writing to the memory location ofSREG. - Code that uses inline assembler to jump to a different function which expects (parts of) the prologue code as outlined above to be present.
To disable
__gcc_isrgeneration for the whole compilation unit, there is option -mno-gas-isr-prologues, see AVR Options. - Code that (effectively) clobbers bits of
OS_mainOS_task-
On AVR, functions with the
OS_mainorOS_taskattribute do not save/restore any call-saved register in their prologue/epilogue.The
OS_mainattribute can be used when there is guarantee that interrupts are disabled at the time when the function is entered. This saves resources when the stack pointer has to be changed to set up a frame for local variables.The
OS_taskattribute can be used when there is no guarantee that interrupts are disabled at that time when the function is entered like for, e.g. task functions in a multi-threading operating system. In that case, changing the stack pointer register is guarded by save/clear/restore of the global interrupt enable flag.The differences to the
nakedfunction attribute are:-
nakedfunctions do not have a return instruction whereasOS_mainandOS_taskfunctions have aRETorRETIreturn instruction. -
nakedfunctions do not set up a frame for local variables or a frame pointer whereasOS_mainandOS_taskdo this as needed.
-
signal-
Use this attribute on the AVR to indicate that the specified function is an interrupt handler. The compiler generates function entry and exit sequences suitable for use in an interrupt handler when this attribute is present.
See also the
interruptfunction attribute.The AVR hardware globally disables interrupts when an interrupt is executed. Interrupt handler functions defined with the
signalattribute do not re-enable interrupts. It is save to enable interrupts in asignalhandler. This “save” only applies to the code generated by the compiler and not to the IRQ layout of the application which is responsibility of the application.If both
signalandinterruptare specified for the same function,signalis silently ignored.
Next: Blackfin Function Attributes, Previous: ARM Function Attributes, Up: Function Attributes [Contents][Index]
© Free Software Foundation
Licensed under the GNU Free Documentation License, Version 1.3.
https://gcc.gnu.org/onlinedocs/gcc-8.3.0/gcc/AVR-Function-Attributes.html