You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
199 lines
14 KiB
HTML
199 lines
14 KiB
HTML
<!-- HTML header for doxygen 1.8.7-->
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
|
|
<meta name="generator" content="Doxygen 1.6.3"/>
|
|
<!--BEGIN PROJECT_NAME--><title>avr-libc: avr-libc: <util/delay.h>: Convenience functions for busy-wait delay loops</title><!--END PROJECT_NAME-->
|
|
<!--BEGIN !PROJECT_NAME--><title>avr-libc: <util/delay.h>: Convenience functions for busy-wait delay loops</title><!--END !PROJECT_NAME-->
|
|
<link href="$relpath^tabs.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="$relpath^jquery.js"></script>
|
|
<script type="text/javascript" src="$relpath^dynsections.js"></script>
|
|
$treeview
|
|
$search
|
|
$mathjax
|
|
<link href="$relpath^$stylesheet" rel="stylesheet" type="text/css" />
|
|
$extrastylesheet
|
|
</head>
|
|
<body>
|
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
|
|
|
<!--BEGIN TITLEAREA-->
|
|
<div id="titlearea">
|
|
<table cellspacing="0" cellpadding="0">
|
|
<tbody>
|
|
<tr style="height: 56px;">
|
|
<!--BEGIN PROJECT_LOGO-->
|
|
<td id="projectlogo"><img alt="Logo" src="$relpath^$projectlogo"/></td>
|
|
<!--END PROJECT_LOGO-->
|
|
<!--BEGIN PROJECT_NAME-->
|
|
<td style="padding-left: 0.5em;">
|
|
<div id="projectname">avr-libc
|
|
<!--BEGIN PROJECT_NUMBER--> <span id="projectnumber">2.0.0</span><!--END PROJECT_NUMBER-->
|
|
</div>
|
|
<!--BEGIN PROJECT_BRIEF--><div id="projectbrief">$projectbrief</div><!--END PROJECT_BRIEF-->
|
|
</td>
|
|
<!--END PROJECT_NAME-->
|
|
<!--BEGIN !PROJECT_NAME-->
|
|
<!--BEGIN PROJECT_BRIEF-->
|
|
<td style="padding-left: 0.5em;">
|
|
<div id="projectbrief">$projectbrief</div>
|
|
</td>
|
|
<!--END PROJECT_BRIEF-->
|
|
<!--END !PROJECT_NAME-->
|
|
<!--BEGIN DISABLE_INDEX-->
|
|
<!--BEGIN SEARCHENGINE-->
|
|
<td>$searchbox</td>
|
|
<!--END SEARCHENGINE-->
|
|
<!--END DISABLE_INDEX-->
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<table>
|
|
<tr>
|
|
<td align="left"><a href="http://www.nongnu.org/avr-libc/"><h2>AVR Libc Home Page</h2></a></td>
|
|
<td align="center" colspan=4><img src="avrs.png" alt="AVRs" align="middle" border="0"></td>
|
|
<td align="right"><a href="https://savannah.nongnu.org/projects/avr-libc/"><h2>AVR Libc Development Pages</h2></a></td>
|
|
</tr>
|
|
<tr>
|
|
<td align="center" width="20%"><a href="index.html"><h2>Main Page</h2></a></td>
|
|
<td align="center" width="20%"><a href="pages.html"><h2>User Manual</h2></a></td>
|
|
<td align="center" width="20%"><a href="modules.html"><h2>Library Reference</h2></a></td>
|
|
<td align="center" width="20%"><a href="FAQ.html"><h2>FAQ</h2></a></td>
|
|
<td align="center" width="20%"><a href="group__demos.html"><h2>Example Projects</h2></a></td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
<!--END TITLEAREA-->
|
|
<!-- end header part -->
|
|
<!-- Generated by Doxygen 1.6.3 -->
|
|
<script type="text/javascript"><!--
|
|
var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|
--></script>
|
|
<div class="contents">
|
|
<h1><util/delay.h>: Convenience functions for busy-wait delay loops</h1><table border="0" cellpadding="0" cellspacing="0">
|
|
<tr><td colspan="2"><h2>Defines</h2></td></tr>
|
|
<tr><td class="memItemLeft" align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__util__delay.html#ga43bafb28b29491ec7f871319b5a3b2f8">F_CPU</a> 1000000UL</td></tr>
|
|
<tr><td colspan="2"><h2>Functions</h2></td></tr>
|
|
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__util__delay.html#gad22e7a36b80e2f917324dc43a425e9d3">_delay_ms</a> (double __ms)</td></tr>
|
|
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__util__delay.html#gab20bfffeacc678cb960944f5519c0c4f">_delay_us</a> (double __us)</td></tr>
|
|
</table>
|
|
<hr/><a name="_details"></a><h2>Detailed Description</h2>
|
|
<div class="fragment"><pre class="fragment"><span class="preprocessor"> #define F_CPU 1000000UL // 1 MHz</span>
|
|
<span class="preprocessor"></span> <span class="comment">//#define F_CPU 14.7456E6</span>
|
|
<span class="preprocessor"> #include <<a class="code" href="delay_8h.html">util/delay.h</a>></span>
|
|
</pre></div><dl class="note"><dt><b>Note:</b></dt><dd>As an alternative method, it is possible to pass the F_CPU macro down to the compiler from the Makefile. Obviously, in that case, no <code>#define</code> statement should be used.</dd></dl>
|
|
<p>The functions in this header file are wrappers around the basic busy-wait functions from <<a class="el" href="delay__basic_8h.html">util/delay_basic.h</a>>. They are meant as convenience functions where actual time values can be specified rather than a number of cycles to wait for. The idea behind is that compile-time constant expressions will be eliminated by compiler optimization so floating-point expressions can be used to calculate the number of delay cycles needed based on the CPU frequency passed by the macro F_CPU.</p>
|
|
<dl class="note"><dt><b>Note:</b></dt><dd>In order for these functions to work as intended, compiler optimizations <em>must</em> be enabled, and the delay time <em>must</em> be an expression that is a known constant at compile-time. If these requirements are not met, the resulting delay will be much longer (and basically unpredictable), and applications that otherwise do not use floating-point calculations will experience severe code bloat by the floating-point library routines linked into the application.</dd></dl>
|
|
<p>The functions available allow the specification of microsecond, and millisecond delays directly, using the application-supplied macro F_CPU as the CPU clock frequency (in Hertz). </p>
|
|
<hr/><h2>Define Documentation</h2>
|
|
<a class="anchor" id="ga43bafb28b29491ec7f871319b5a3b2f8"></a><!-- doxytag: member="delay.h::F_CPU" ref="ga43bafb28b29491ec7f871319b5a3b2f8" args="" -->
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">#define F_CPU 1000000UL</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
<div class="memdoc">
|
|
|
|
<p>CPU frequency in Hz. </p>
|
|
<p>The macro F_CPU specifies the CPU frequency to be considered by the delay macros. This macro is normally supplied by the environment (e.g. from within a project header, or the project's Makefile). The value 1 MHz here is only provided as a "vanilla" fallback if no such user-provided definition could be found.</p>
|
|
<p>In terms of the delay functions, the CPU frequency can be given as a floating-point constant (e.g. 3.6864E6 for 3.6864 MHz). However, the macros in <<a class="el" href="setbaud_8h.html">util/setbaud.h</a>> require it to be an integer value. </p>
|
|
|
|
</div>
|
|
</div>
|
|
<hr/><h2>Function Documentation</h2>
|
|
<a class="anchor" id="gad22e7a36b80e2f917324dc43a425e9d3"></a><!-- doxytag: member="delay.h::_delay_ms" ref="gad22e7a36b80e2f917324dc43a425e9d3" args="(double __ms)" -->
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void _delay_ms </td>
|
|
<td>(</td>
|
|
<td class="paramtype">double </td>
|
|
<td class="paramname"> <em>__ms</em></td>
|
|
<td> ) </td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
<div class="memdoc">
|
|
<p>Perform a delay of <code>__ms</code> milliseconds, using <a class="el" href="group__util__delay__basic.html#ga74a94fec42bac9f1ff31fd443d419a6a">_delay_loop_2()</a>.</p>
|
|
<p>The macro F_CPU is supposed to be defined to a constant defining the CPU clock frequency (in Hertz).</p>
|
|
<p>The maximal possible delay is 262.14 ms / F_CPU in MHz.</p>
|
|
<p>When the user request delay which exceed the maximum possible one, <a class="el" href="group__util__delay.html#gad22e7a36b80e2f917324dc43a425e9d3">_delay_ms()</a> provides a decreased resolution functionality. In this mode <a class="el" href="group__util__delay.html#gad22e7a36b80e2f917324dc43a425e9d3">_delay_ms()</a> will work with a resolution of 1/10 ms, providing delays up to 6.5535 seconds (independent from CPU frequency). The user will not be informed about decreased resolution.</p>
|
|
<p>If the avr-gcc toolchain has __builtin_avr_delay_cycles() support, maximal possible delay is 4294967.295 ms/ F_CPU in MHz. For values greater than the maximal possible delay, overflows results in no delay i.e., 0ms.</p>
|
|
<p>Conversion of <code>__ms</code> into clock cycles may not always result in integer. By default, the clock cycles rounded up to next integer. This ensures that the user gets at least <code>__ms</code> microseconds of delay.</p>
|
|
<p>Alternatively, by defining the macro <code>__DELAY_ROUND_DOWN__</code>, or <code>__DELAY_ROUND_CLOSEST__</code>, before including this header file, the algorithm can be made to round down, or round to closest integer, respectively.</p>
|
|
<dl class="note"><dt><b>Note:</b></dt><dd></dd></dl>
|
|
<p>The implementation of <a class="el" href="group__util__delay.html#gad22e7a36b80e2f917324dc43a425e9d3">_delay_ms()</a> based on __builtin_avr_delay_cycles() is not backward compatible with older implementations. In order to get functionality backward compatible with previous versions, the macro <code>"__DELAY_BACKWARD_COMPATIBLE__"</code> must be defined before including this header file. Also, the backward compatible algorithm will be chosen if the code is compiled in a <em>freestanding environment</em> (GCC option <code>-ffreestanding</code>), as the math functions required for rounding are not available to the compiler then. </p>
|
|
|
|
</div>
|
|
</div>
|
|
<a class="anchor" id="gab20bfffeacc678cb960944f5519c0c4f"></a><!-- doxytag: member="delay.h::_delay_us" ref="gab20bfffeacc678cb960944f5519c0c4f" args="(double __us)" -->
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void _delay_us </td>
|
|
<td>(</td>
|
|
<td class="paramtype">double </td>
|
|
<td class="paramname"> <em>__us</em></td>
|
|
<td> ) </td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
<div class="memdoc">
|
|
<p>Perform a delay of <code>__us</code> microseconds, using <a class="el" href="group__util__delay__basic.html#ga4e3957917c4c447d0f9166dac881b4e3">_delay_loop_1()</a>.</p>
|
|
<p>The macro F_CPU is supposed to be defined to a constant defining the CPU clock frequency (in Hertz).</p>
|
|
<p>The maximal possible delay is 768 us / F_CPU in MHz.</p>
|
|
<p>If the user requests a delay greater than the maximal possible one, <a class="el" href="group__util__delay.html#gab20bfffeacc678cb960944f5519c0c4f">_delay_us()</a> will automatically call <a class="el" href="group__util__delay.html#gad22e7a36b80e2f917324dc43a425e9d3">_delay_ms()</a> instead. The user will not be informed about this case.</p>
|
|
<p>If the avr-gcc toolchain has __builtin_avr_delay_cycles() support, maximal possible delay is 4294967.295 us/ F_CPU in MHz. For values greater than the maximal possible delay, overflow results in no delay i.e., 0us.</p>
|
|
<p>Conversion of <code>__us</code> into clock cycles may not always result in integer. By default, the clock cycles rounded up to next integer. This ensures that the user gets at least <code>__us</code> microseconds of delay.</p>
|
|
<p>Alternatively, by defining the macro <code>__DELAY_ROUND_DOWN__</code>, or <code>__DELAY_ROUND_CLOSEST__</code>, before including this header file, the algorithm can be made to round down, or round to closest integer, respectively.</p>
|
|
<dl class="note"><dt><b>Note:</b></dt><dd></dd></dl>
|
|
<p>The implementation of <a class="el" href="group__util__delay.html#gad22e7a36b80e2f917324dc43a425e9d3">_delay_ms()</a> based on __builtin_avr_delay_cycles() is not backward compatible with older implementations. In order to get functionality backward compatible with previous versions, the macro <code>__DELAY_BACKWARD_COMPATIBLE__</code> must be defined before including this header file. Also, the backward compatible algorithm will be chosen if the code is compiled in a <em>freestanding environment</em> (GCC option <code>-ffreestanding</code>), as the math functions required for rounding are not available to the compiler then. </p>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<!--- window showing the filter options -->
|
|
<div id="MSearchSelectWindow"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
|
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Defines</a></div>
|
|
|
|
<!-- iframe showing the search results (closed by default) -->
|
|
<div id="MSearchResultsWindow">
|
|
<iframe src="" frameborder="0"
|
|
name="MSearchResults" id="MSearchResults">
|
|
</iframe>
|
|
</div>
|
|
|
|
<!-- HTML footer for doxygen 1.8.7-->
|
|
<!-- start footer part -->
|
|
<!--BEGIN GENERATE_TREEVIEW-->
|
|
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
|
<ul>
|
|
$navpath
|
|
<li class="footer">$generatedby
|
|
<a href="http://www.doxygen.org/index.html">
|
|
<img class="footer" src="$relpath^doxygen.png" alt="doxygen"/></a> 1.6.3 </li>
|
|
</ul>
|
|
</div>
|
|
<!--END GENERATE_TREEVIEW-->
|
|
<!--BEGIN !GENERATE_TREEVIEW-->
|
|
<hr class="footer"/><address class="footer"><small>
|
|
$generatedby  <a href="http://www.doxygen.org/index.html">
|
|
<img class="footer" src="$relpath^doxygen.png" alt="doxygen"/>
|
|
</a> 1.6.3
|
|
</small></address>
|
|
<!--END !GENERATE_TREEVIEW-->
|
|
</body>
|
|
</html>
|