AVR-Function-Attributes.html 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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-2017 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 5.2, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <title>Using the GNU Compiler Collection (GCC): AVR Function Attributes</title>
  20. <meta name="description" content="Using the GNU Compiler Collection (GCC): AVR Function Attributes">
  21. <meta name="keywords" content="Using the GNU Compiler Collection (GCC): AVR Function Attributes">
  22. <meta name="resource-type" content="document">
  23. <meta name="distribution" content="global">
  24. <meta name="Generator" content="makeinfo">
  25. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  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.smallquotation {font-size: smaller}
  36. div.display {margin-left: 3.2em}
  37. div.example {margin-left: 3.2em}
  38. div.indentedblock {margin-left: 3.2em}
  39. div.lisp {margin-left: 3.2em}
  40. div.smalldisplay {margin-left: 3.2em}
  41. div.smallexample {margin-left: 3.2em}
  42. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  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.nocodebreak {white-space:nowrap}
  54. span.nolinebreak {white-space:nowrap}
  55. span.roman {font-family:serif; font-weight:normal}
  56. span.sansserif {font-family:sans-serif; font-weight:normal}
  57. ul.no-bullet {list-style: none}
  58. -->
  59. </style>
  60. </head>
  61. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  62. <a name="AVR-Function-Attributes"></a>
  63. <div class="header">
  64. <p>
  65. 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>
  66. </div>
  67. <hr>
  68. <a name="AVR-Function-Attributes-1"></a>
  69. <h4 class="subsection">6.31.5 AVR Function Attributes</h4>
  70. <p>These function attributes are supported by the AVR back end:
  71. </p>
  72. <dl compact="compact">
  73. <dt><code>interrupt</code></dt>
  74. <dd><a name="index-interrupt-function-attribute_002c-AVR"></a>
  75. <p>Use this attribute to indicate
  76. that the specified function is an interrupt handler. The compiler generates
  77. function entry and exit sequences suitable for use in an interrupt handler
  78. when this attribute is present.
  79. </p>
  80. <p>On the AVR, the hardware globally disables interrupts when an
  81. interrupt is executed. The first instruction of an interrupt handler
  82. declared with this attribute is a <code>SEI</code> instruction to
  83. re-enable interrupts. See also the <code>signal</code> function attribute
  84. that does not insert a <code>SEI</code> instruction. If both <code>signal</code> and
  85. <code>interrupt</code> are specified for the same function, <code>signal</code>
  86. is silently ignored.
  87. </p>
  88. </dd>
  89. <dt><code>naked</code></dt>
  90. <dd><a name="index-naked-function-attribute_002c-AVR"></a>
  91. <p>This attribute allows the compiler to construct the
  92. requisite function declaration, while allowing the body of the
  93. function to be assembly code. The specified function will not have
  94. prologue/epilogue sequences generated by the compiler. Only basic
  95. <code>asm</code> statements can safely be included in naked functions
  96. (see <a href="Basic-Asm.html#Basic-Asm">Basic Asm</a>). While using extended <code>asm</code> or a mixture of
  97. basic <code>asm</code> and C code may appear to work, they cannot be
  98. depended upon to work reliably and are not supported.
  99. </p>
  100. </dd>
  101. <dt><code>OS_main</code></dt>
  102. <dt><code>OS_task</code></dt>
  103. <dd><a name="index-OS_005fmain-function-attribute_002c-AVR"></a>
  104. <a name="index-OS_005ftask-function-attribute_002c-AVR"></a>
  105. <p>On AVR, functions with the <code>OS_main</code> or <code>OS_task</code> attribute
  106. do not save/restore any call-saved register in their prologue/epilogue.
  107. </p>
  108. <p>The <code>OS_main</code> attribute can be used when there <em>is
  109. guarantee</em> that interrupts are disabled at the time when the function
  110. is entered. This saves resources when the stack pointer has to be
  111. changed to set up a frame for local variables.
  112. </p>
  113. <p>The <code>OS_task</code> attribute can be used when there is <em>no
  114. guarantee</em> that interrupts are disabled at that time when the function
  115. is entered like for, e.g. task functions in a multi-threading operating
  116. system. In that case, changing the stack pointer register is
  117. guarded by save/clear/restore of the global interrupt enable flag.
  118. </p>
  119. <p>The differences to the <code>naked</code> function attribute are:
  120. </p><ul>
  121. <li> <code>naked</code> functions do not have a return instruction whereas
  122. <code>OS_main</code> and <code>OS_task</code> functions have a <code>RET</code> or
  123. <code>RETI</code> return instruction.
  124. </li><li> <code>naked</code> functions do not set up a frame for local variables
  125. or a frame pointer whereas <code>OS_main</code> and <code>OS_task</code> do this
  126. as needed.
  127. </li></ul>
  128. </dd>
  129. <dt><code>signal</code></dt>
  130. <dd><a name="index-signal-function-attribute_002c-AVR"></a>
  131. <p>Use this attribute on the AVR to indicate that the specified
  132. function is an interrupt handler. The compiler generates function
  133. entry and exit sequences suitable for use in an interrupt handler when this
  134. attribute is present.
  135. </p>
  136. <p>See also the <code>interrupt</code> function attribute.
  137. </p>
  138. <p>The AVR hardware globally disables interrupts when an interrupt is executed.
  139. Interrupt handler functions defined with the <code>signal</code> attribute
  140. do not re-enable interrupts. It is save to enable interrupts in a
  141. <code>signal</code> handler. This &ldquo;save&rdquo; only applies to the code
  142. generated by the compiler and not to the IRQ layout of the
  143. application which is responsibility of the application.
  144. </p>
  145. <p>If both <code>signal</code> and <code>interrupt</code> are specified for the same
  146. function, <code>signal</code> is silently ignored.
  147. </p></dd>
  148. </dl>
  149. <hr>
  150. <div class="header">
  151. <p>
  152. 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>
  153. </div>
  154. </body>
  155. </html>