You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

196 lines
9.3KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <title>AVR Function Attributes (Using the GNU Compiler Collection (GCC))</title>
  21. <meta name="description" content="AVR Function Attributes (Using the GNU Compiler Collection (GCC))">
  22. <meta name="keywords" content="AVR Function Attributes (Using the GNU Compiler Collection (GCC))">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="Function-Attributes.html#Function-Attributes" rel="up" title="Function Attributes">
  30. <link href="Blackfin-Function-Attributes.html#Blackfin-Function-Attributes" rel="next" title="Blackfin Function Attributes">
  31. <link href="ARM-Function-Attributes.html#ARM-Function-Attributes" rel="prev" title="ARM Function Attributes">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.indentedblock {margin-right: 0em}
  36. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  37. blockquote.smallquotation {font-size: smaller}
  38. div.display {margin-left: 3.2em}
  39. div.example {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style: oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nolinebreak {white-space: nowrap}
  54. span.roman {font-family: initial; font-weight: normal}
  55. span.sansserif {font-family: sans-serif; font-weight: normal}
  56. ul.no-bullet {list-style: none}
  57. -->
  58. </style>
  59. </head>
  60. <body lang="en">
  61. <a name="AVR-Function-Attributes"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Blackfin-Function-Attributes.html#Blackfin-Function-Attributes" accesskey="n" rel="next">Blackfin Function Attributes</a>, Previous: <a href="ARM-Function-Attributes.html#ARM-Function-Attributes" accesskey="p" rel="prev">ARM Function Attributes</a>, Up: <a href="Function-Attributes.html#Function-Attributes" accesskey="u" rel="up">Function Attributes</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  65. </div>
  66. <hr>
  67. <a name="AVR-Function-Attributes-1"></a>
  68. <h4 class="subsection">6.33.6 AVR Function Attributes</h4>
  69. <p>These function attributes are supported by the AVR back end:
  70. </p>
  71. <dl compact="compact">
  72. <dt><code>interrupt</code></dt>
  73. <dd><a name="index-interrupt-function-attribute_002c-AVR"></a>
  74. <p>Use this attribute to indicate
  75. that the specified function is an interrupt handler. The compiler generates
  76. function entry and exit sequences suitable for use in an interrupt handler
  77. when this attribute is present.
  78. </p>
  79. <p>On the AVR, the hardware globally disables interrupts when an
  80. interrupt is executed. The first instruction of an interrupt handler
  81. declared with this attribute is a <code>SEI</code> instruction to
  82. re-enable interrupts. See also the <code>signal</code> function attribute
  83. that does not insert a <code>SEI</code> instruction. If both <code>signal</code> and
  84. <code>interrupt</code> are specified for the same function, <code>signal</code>
  85. is silently ignored.
  86. </p>
  87. </dd>
  88. <dt><code>naked</code></dt>
  89. <dd><a name="index-naked-function-attribute_002c-AVR"></a>
  90. <p>This attribute allows the compiler to construct the
  91. requisite function declaration, while allowing the body of the
  92. function to be assembly code. The specified function will not have
  93. prologue/epilogue sequences generated by the compiler. Only basic
  94. <code>asm</code> statements can safely be included in naked functions
  95. (see <a href="Basic-Asm.html#Basic-Asm">Basic Asm</a>). While using extended <code>asm</code> or a mixture of
  96. basic <code>asm</code> and C code may appear to work, they cannot be
  97. depended upon to work reliably and are not supported.
  98. </p>
  99. </dd>
  100. <dt><code>no_gccisr</code></dt>
  101. <dd><a name="index-no_005fgccisr-function-attribute_002c-AVR"></a>
  102. <p>Do not use <code>__gcc_isr</code> pseudo instructions in a function with
  103. the <code>interrupt</code> or <code>signal</code> attribute aka. interrupt
  104. service routine (ISR).
  105. Use this attribute if the preamble of the ISR prologue should always read
  106. </p><div class="example">
  107. <pre class="example">push __zero_reg__
  108. push __tmp_reg__
  109. in __tmp_reg__, __SREG__
  110. push __tmp_reg__
  111. clr __zero_reg__
  112. </pre></div>
  113. <p>and accordingly for the postamble of the epilogue &mdash; no matter whether
  114. the mentioned registers are actually used in the ISR or not.
  115. Situations where you might want to use this attribute include:
  116. </p><ul>
  117. <li> Code that (effectively) clobbers bits of <code>SREG</code> other than the
  118. <code>I</code>-flag by writing to the memory location of <code>SREG</code>.
  119. </li><li> Code that uses inline assembler to jump to a different function which
  120. expects (parts of) the prologue code as outlined above to be present.
  121. </li></ul>
  122. <p>To disable <code>__gcc_isr</code> generation for the whole compilation unit,
  123. there is option <samp>-mno-gas-isr-prologues</samp>, see <a href="AVR-Options.html#AVR-Options">AVR Options</a>.
  124. </p>
  125. </dd>
  126. <dt><code>OS_main</code></dt>
  127. <dt><code>OS_task</code></dt>
  128. <dd><a name="index-OS_005fmain-function-attribute_002c-AVR"></a>
  129. <a name="index-OS_005ftask-function-attribute_002c-AVR"></a>
  130. <p>On AVR, functions with the <code>OS_main</code> or <code>OS_task</code> attribute
  131. do not save/restore any call-saved register in their prologue/epilogue.
  132. </p>
  133. <p>The <code>OS_main</code> attribute can be used when there <em>is
  134. guarantee</em> that interrupts are disabled at the time when the function
  135. is entered. This saves resources when the stack pointer has to be
  136. changed to set up a frame for local variables.
  137. </p>
  138. <p>The <code>OS_task</code> attribute can be used when there is <em>no
  139. guarantee</em> that interrupts are disabled at that time when the function
  140. is entered like for, e.g. task functions in a multi-threading operating
  141. system. In that case, changing the stack pointer register is
  142. guarded by save/clear/restore of the global interrupt enable flag.
  143. </p>
  144. <p>The differences to the <code>naked</code> function attribute are:
  145. </p><ul>
  146. <li> <code>naked</code> functions do not have a return instruction whereas
  147. <code>OS_main</code> and <code>OS_task</code> functions have a <code>RET</code> or
  148. <code>RETI</code> return instruction.
  149. </li><li> <code>naked</code> functions do not set up a frame for local variables
  150. or a frame pointer whereas <code>OS_main</code> and <code>OS_task</code> do this
  151. as needed.
  152. </li></ul>
  153. </dd>
  154. <dt><code>signal</code></dt>
  155. <dd><a name="index-signal-function-attribute_002c-AVR"></a>
  156. <p>Use this attribute on the AVR to indicate that the specified
  157. function is an interrupt handler. The compiler generates function
  158. entry and exit sequences suitable for use in an interrupt handler when this
  159. attribute is present.
  160. </p>
  161. <p>See also the <code>interrupt</code> function attribute.
  162. </p>
  163. <p>The AVR hardware globally disables interrupts when an interrupt is executed.
  164. Interrupt handler functions defined with the <code>signal</code> attribute
  165. do not re-enable interrupts. It is save to enable interrupts in a
  166. <code>signal</code> handler. This &ldquo;save&rdquo; only applies to the code
  167. generated by the compiler and not to the IRQ layout of the
  168. application which is responsibility of the application.
  169. </p>
  170. <p>If both <code>signal</code> and <code>interrupt</code> are specified for the same
  171. function, <code>signal</code> is silently ignored.
  172. </p></dd>
  173. </dl>
  174. <hr>
  175. <div class="header">
  176. <p>
  177. Next: <a href="Blackfin-Function-Attributes.html#Blackfin-Function-Attributes" accesskey="n" rel="next">Blackfin Function Attributes</a>, Previous: <a href="ARM-Function-Attributes.html#ARM-Function-Attributes" accesskey="p" rel="prev">ARM Function Attributes</a>, Up: <a href="Function-Attributes.html#Function-Attributes" accesskey="u" rel="up">Function Attributes</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  178. </div>
  179. </body>
  180. </html>