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
8.8KB

  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 Built-in Functions (Using the GNU Compiler Collection (GCC))</title>
  21. <meta name="description" content="AVR Built-in Functions (Using the GNU Compiler Collection (GCC))">
  22. <meta name="keywords" content="AVR Built-in Functions (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="Target-Builtins.html#Target-Builtins" rel="up" title="Target Builtins">
  30. <link href="Blackfin-Built_002din-Functions.html#Blackfin-Built_002din-Functions" rel="next" title="Blackfin Built-in Functions">
  31. <link href="ARM-ARMv8_002dM-Security-Extensions.html#ARM-ARMv8_002dM-Security-Extensions" rel="prev" title="ARM ARMv8-M Security Extensions">
  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-Built_002din-Functions"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Blackfin-Built_002din-Functions.html#Blackfin-Built_002din-Functions" accesskey="n" rel="next">Blackfin Built-in Functions</a>, Previous: <a href="ARM-ARMv8_002dM-Security-Extensions.html#ARM-ARMv8_002dM-Security-Extensions" accesskey="p" rel="prev">ARM ARMv8-M Security Extensions</a>, Up: <a href="Target-Builtins.html#Target-Builtins" accesskey="u" rel="up">Target Builtins</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-Built_002din-Functions-1"></a>
  68. <h4 class="subsection">6.60.10 AVR Built-in Functions</h4>
  69. <p>For each built-in function for AVR, there is an equally named,
  70. uppercase built-in macro defined. That way users can easily query if
  71. or if not a specific built-in is implemented or not. For example, if
  72. <code>__builtin_avr_nop</code> is available the macro
  73. <code>__BUILTIN_AVR_NOP</code> is defined to <code>1</code> and undefined otherwise.
  74. </p>
  75. <dl compact="compact">
  76. <dt><code>void __builtin_avr_nop (void)</code></dt>
  77. <dt><code>void __builtin_avr_sei (void)</code></dt>
  78. <dt><code>void __builtin_avr_cli (void)</code></dt>
  79. <dt><code>void __builtin_avr_sleep (void)</code></dt>
  80. <dt><code>void __builtin_avr_wdr (void)</code></dt>
  81. <dt><code>unsigned char __builtin_avr_swap (unsigned char)</code></dt>
  82. <dt><code>unsigned int __builtin_avr_fmul (unsigned char, unsigned char)</code></dt>
  83. <dt><code>int __builtin_avr_fmuls (char, char)</code></dt>
  84. <dt><code>int __builtin_avr_fmulsu (char, unsigned char)</code></dt>
  85. <dd><p>These built-in functions map to the respective machine
  86. instruction, i.e. <code>nop</code>, <code>sei</code>, <code>cli</code>, <code>sleep</code>,
  87. <code>wdr</code>, <code>swap</code>, <code>fmul</code>, <code>fmuls</code>
  88. resp. <code>fmulsu</code>. The three <code>fmul*</code> built-ins are implemented
  89. as library call if no hardware multiplier is available.
  90. </p>
  91. </dd>
  92. <dt><code>void __builtin_avr_delay_cycles (unsigned long ticks)</code></dt>
  93. <dd><p>Delay execution for <var>ticks</var> cycles. Note that this
  94. built-in does not take into account the effect of interrupts that
  95. might increase delay time. <var>ticks</var> must be a compile-time
  96. integer constant; delays with a variable number of cycles are not supported.
  97. </p>
  98. </dd>
  99. <dt><code>char __builtin_avr_flash_segment (const __memx void*)</code></dt>
  100. <dd><p>This built-in takes a byte address to the 24-bit
  101. <a href="Named-Address-Spaces.html#AVR-Named-Address-Spaces">address space</a> <code>__memx</code> and returns
  102. the number of the flash segment (the 64 KiB chunk) where the address
  103. points to. Counting starts at <code>0</code>.
  104. If the address does not point to flash memory, return <code>-1</code>.
  105. </p>
  106. </dd>
  107. <dt><code>uint8_t __builtin_avr_insert_bits (uint32_t map, uint8_t bits, uint8_t val)</code></dt>
  108. <dd><p>Insert bits from <var>bits</var> into <var>val</var> and return the resulting
  109. value. The nibbles of <var>map</var> determine how the insertion is
  110. performed: Let <var>X</var> be the <var>n</var>-th nibble of <var>map</var>
  111. </p><ol>
  112. <li> If <var>X</var> is <code>0xf</code>,
  113. then the <var>n</var>-th bit of <var>val</var> is returned unaltered.
  114. </li><li> If X is in the range 0&hellip;7,
  115. then the <var>n</var>-th result bit is set to the <var>X</var>-th bit of <var>bits</var>
  116. </li><li> If X is in the range 8&hellip;<code>0xe</code>,
  117. then the <var>n</var>-th result bit is undefined.
  118. </li></ol>
  119. <p>One typical use case for this built-in is adjusting input and
  120. output values to non-contiguous port layouts. Some examples:
  121. </p>
  122. <div class="smallexample">
  123. <pre class="smallexample">// same as val, bits is unused
  124. __builtin_avr_insert_bits (0xffffffff, bits, val)
  125. </pre></div>
  126. <div class="smallexample">
  127. <pre class="smallexample">// same as bits, val is unused
  128. __builtin_avr_insert_bits (0x76543210, bits, val)
  129. </pre></div>
  130. <div class="smallexample">
  131. <pre class="smallexample">// same as rotating bits by 4
  132. __builtin_avr_insert_bits (0x32107654, bits, 0)
  133. </pre></div>
  134. <div class="smallexample">
  135. <pre class="smallexample">// high nibble of result is the high nibble of val
  136. // low nibble of result is the low nibble of bits
  137. __builtin_avr_insert_bits (0xffff3210, bits, val)
  138. </pre></div>
  139. <div class="smallexample">
  140. <pre class="smallexample">// reverse the bit order of bits
  141. __builtin_avr_insert_bits (0x01234567, bits, 0)
  142. </pre></div>
  143. </dd>
  144. <dt><code>void __builtin_avr_nops (unsigned count)</code></dt>
  145. <dd><p>Insert <var>count</var> <code>NOP</code> instructions.
  146. The number of instructions must be a compile-time integer constant.
  147. </p>
  148. </dd>
  149. </dl>
  150. <p>There are many more AVR-specific built-in functions that are used to
  151. implement the ISO/IEC TR 18037 &ldquo;Embedded C&rdquo; fixed-point functions of
  152. section 7.18a.6. You don&rsquo;t need to use these built-ins directly.
  153. Instead, use the declarations as supplied by the <code>stdfix.h</code> header
  154. with GNU-C99:
  155. </p>
  156. <div class="smallexample">
  157. <pre class="smallexample">#include &lt;stdfix.h&gt;
  158. // Re-interpret the bit representation of unsigned 16-bit
  159. // integer <var>uval</var> as Q-format 0.16 value.
  160. unsigned fract get_bits (uint_ur_t uval)
  161. {
  162. return urbits (uval);
  163. }
  164. </pre></div>
  165. <hr>
  166. <div class="header">
  167. <p>
  168. Next: <a href="Blackfin-Built_002din-Functions.html#Blackfin-Built_002din-Functions" accesskey="n" rel="next">Blackfin Built-in Functions</a>, Previous: <a href="ARM-ARMv8_002dM-Security-Extensions.html#ARM-ARMv8_002dM-Security-Extensions" accesskey="p" rel="prev">ARM ARMv8-M Security Extensions</a>, Up: <a href="Target-Builtins.html#Target-Builtins" accesskey="u" rel="up">Target Builtins</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>
  169. </div>
  170. </body>
  171. </html>