1 <!-- HTML header for doxygen 1.8.20-->
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
5 <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
6 <meta http-equiv="X-UA-Compatible" content="IE=9"/>
7 <meta name="generator" content="Doxygen 1.9.4"/>
8 <meta name="viewport" content="width=device-width, initial-scale=1"/>
9 <title>Raspberry Pi Pico SDK: sleep</title>
10 <!-- <link href="tabs.css" rel="stylesheet" type="text/css"/> -->
11 <script type="text/javascript" src="jquery.js"></script>
12 <script type="text/javascript" src="dynsections.js"></script>
13 <link href="navtree.css" rel="stylesheet" type="text/css"/>
14 <script type="text/javascript" src="resize.js"></script>
15 <script type="text/javascript" src="navtreedata.js"></script>
16 <script type="text/javascript" src="navtree.js"></script>
17 <link href="search/search.css" rel="stylesheet" type="text/css"/>
18 <script type="text/javascript" src="search/searchdata.js"></script>
19 <script type="text/javascript" src="search/search.js"></script>
20 <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
21 <link href="doxygen.css" rel="stylesheet" type="text/css" />
22 <link href="normalise.css" rel="stylesheet" type="text/css"/>
23 <link href="main.css" rel="stylesheet" type="text/css"/>
24 <link href="styles.css" rel="stylesheet" type="text/css"/>
27 <div class="navigation-mobile">
28 <div class="logo--mobile">
29 <a href="/"><img src="logo-mobile.svg" alt="Raspberry Pi"></a>
31 <div class="navigation-toggle">
32 <span class="line-1"></span>
36 <span class="line-3"></span>
39 <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
41 <a href="index.html"> <img src="logo.svg" alt="Raspberry Pi"></a>
42 <span style="display: inline-block; margin-top: 10px;">
46 <div class="navigation-footer">
47 <img src="logo-mobile.svg" alt="Raspberry Pi">
48 <a href="https://www.raspberrypi.com/" target="_blank">By Raspberry Pi Ltd</a>
50 <!-- <div class="search">
52 <input type="search" name="search" id="search" placeholder="Search">
53 <input type="submit" value="Search">
56 <!-- Generated by Doxygen 1.9.4 -->
57 <script type="text/javascript">
58 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
59 var searchBox = new SearchBox("searchBox", "search",'Search','.html');
62 <script type="text/javascript" src="menudata.js"></script>
63 <script type="text/javascript" src="menu.js"></script>
64 <script type="text/javascript">
65 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
67 initMenu('',true,false,'search.php','Search');
68 $(document).ready(function() { init_search(); });
72 <div id="main-nav"></div>
74 <div id="side-nav" class="ui-resizable side-nav-resizable">
76 <div id="nav-tree-contents">
77 <div id="nav-sync" class="sync"></div>
80 <div id="splitbar" style="-moz-user-select:none;"
81 class="ui-resizable-handle">
84 <script type="text/javascript">
85 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
86 $(document).ready(function(){initNavTree('group__sleep.html',''); initResizable(); });
89 <div id="doc-content">
90 <!-- window showing the filter options -->
91 <div id="MSearchSelectWindow"
92 onmouseover="return searchBox.OnSearchSelectShow()"
93 onmouseout="return searchBox.OnSearchSelectHide()"
94 onkeydown="return searchBox.OnSearchSelectKey(event)">
97 <!-- iframe showing the search results (closed by default) -->
98 <div id="MSearchResultsWindow">
99 <iframe src="javascript:void(0)" frameborder="0"
100 name="MSearchResults" id="MSearchResults">
105 <div class="summary">
106 <a href="#func-members">Functions</a> </div>
107 <div class="headertitle"><div class="title">sleep<div class="ingroups"><a class="el" href="group__high__level.html">High Level APIs</a> » <a class="el" href="group__pico__time.html">pico_time</a></div></div></div>
109 <div class="contents">
111 <p>Sleep functions for delaying execution in a lower power state.
112 <a href="#details">More...</a></p>
113 <table class="memberdecls">
114 <tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
115 Functions</h2></td></tr>
116 <tr class="memitem:ga7abed28d3918fe2b15f8007ba6569172"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sleep.html#ga7abed28d3918fe2b15f8007ba6569172">sleep_until</a> (<a class="el" href="group__timestamp.html#ga8b7f3d602cc053f05bacceeacc257ed8">absolute_time_t</a> target)</td></tr>
117 <tr class="memdesc:ga7abed28d3918fe2b15f8007ba6569172"><td class="mdescLeft"> </td><td class="mdescRight">Wait until after the given timestamp to return. <a href="group__sleep.html#ga7abed28d3918fe2b15f8007ba6569172">More...</a><br /></td></tr>
118 <tr class="separator:ga7abed28d3918fe2b15f8007ba6569172"><td class="memSeparator" colspan="2"> </td></tr>
119 <tr class="memitem:gaeeaebd3a10e0a193022f15c8603772ba"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sleep.html#gaeeaebd3a10e0a193022f15c8603772ba">sleep_us</a> (uint64_t us)</td></tr>
120 <tr class="memdesc:gaeeaebd3a10e0a193022f15c8603772ba"><td class="mdescLeft"> </td><td class="mdescRight">Wait for the given number of microseconds before returning. <a href="group__sleep.html#gaeeaebd3a10e0a193022f15c8603772ba">More...</a><br /></td></tr>
121 <tr class="separator:gaeeaebd3a10e0a193022f15c8603772ba"><td class="memSeparator" colspan="2"> </td></tr>
122 <tr class="memitem:gae617a6842d4f3a192064c4354b88fcff"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sleep.html#gae617a6842d4f3a192064c4354b88fcff">sleep_ms</a> (uint32_t ms)</td></tr>
123 <tr class="memdesc:gae617a6842d4f3a192064c4354b88fcff"><td class="mdescLeft"> </td><td class="mdescRight">Wait for the given number of milliseconds before returning. <a href="group__sleep.html#gae617a6842d4f3a192064c4354b88fcff">More...</a><br /></td></tr>
124 <tr class="separator:gae617a6842d4f3a192064c4354b88fcff"><td class="memSeparator" colspan="2"> </td></tr>
125 <tr class="memitem:gaedc0ed51a5e908ddd660a5d279009abc"><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="group__sleep.html#gaedc0ed51a5e908ddd660a5d279009abc">best_effort_wfe_or_timeout</a> (<a class="el" href="group__timestamp.html#ga8b7f3d602cc053f05bacceeacc257ed8">absolute_time_t</a> timeout_timestamp)</td></tr>
126 <tr class="memdesc:gaedc0ed51a5e908ddd660a5d279009abc"><td class="mdescLeft"> </td><td class="mdescRight">Helper method for blocking on a timeout. <a href="group__sleep.html#gaedc0ed51a5e908ddd660a5d279009abc">More...</a><br /></td></tr>
127 <tr class="separator:gaedc0ed51a5e908ddd660a5d279009abc"><td class="memSeparator" colspan="2"> </td></tr>
129 <a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
130 <p >Sleep functions for delaying execution in a lower power state. </p>
131 <p >These functions allow the calling core to sleep. This is a lower powered sleep; waking and re-checking time on every processor event (WFE)</p>
132 <dl class="section note"><dt>Note</dt><dd>These functions should not be called from an IRQ handler.</dd>
134 Lower powered sleep requires use of the <a class="el" href="group__alarm.html#ga5092ceb879289c0a597a389f34b4815e">default alarm pool</a> which may be disabled by the PICO_TIME_DEFAULT_ALARM_POOL_DISABLED #define or currently full in which case these functions become busy waits instead.</dd>
136 Whilst <em>sleep_</em> functions are preferable to <em>busy_wait</em> functions from a power perspective, the <em>busy_wait</em> equivalent function may return slightly sooner after the target is reached.</dd></dl>
137 <dl class="section see"><dt>See also</dt><dd><a class="el" href="group__hardware__timer.html#gab1c72f391015ff00a96b24477aa327ee" title="Busy wait wasting cycles until after the specified timestamp using the default timer instance.">busy_wait_until()</a> </dd>
139 <a class="el" href="group__hardware__timer.html#gac089d1c42bb7658bb43c798454f66e2f" title="Busy wait wasting cycles for the given (64 bit) number of microseconds using the default timer instan...">busy_wait_us()</a> </dd>
141 <a class="el" href="group__hardware__timer.html#ga89b0f1dcbbdf81c92ade2930e8e38ab6" title="Busy wait wasting cycles for the given (32 bit) number of microseconds using the default timer instan...">busy_wait_us_32()</a> </dd></dl>
142 <h2 class="groupheader">Function Documentation</h2>
143 <a id="gaedc0ed51a5e908ddd660a5d279009abc" name="gaedc0ed51a5e908ddd660a5d279009abc"></a>
144 <h2 class="memtitle"><span class="permalink"><a href="#gaedc0ed51a5e908ddd660a5d279009abc">◆ </a></span>best_effort_wfe_or_timeout()</h2>
146 <div class="memitem">
147 <div class="memproto">
148 <table class="memname">
150 <td class="memname">bool best_effort_wfe_or_timeout </td>
152 <td class="paramtype"><a class="el" href="group__timestamp.html#ga8b7f3d602cc053f05bacceeacc257ed8">absolute_time_t</a> </td>
153 <td class="paramname"><em>timeout_timestamp</em></td><td>)</td>
157 </div><div class="memdoc">
159 <p>Helper method for blocking on a timeout. </p>
160 <p >This method will return in response to an event (as per __wfe) or when the target time is reached, or at any point before.</p>
161 <p >This method can be used to implement a lower power polling loop waiting on some condition signalled by an event (<a class="el" href="group__hardware__sync.html#ga486eada32246494118f8273a80ae6856" title="Insert a SEV instruction in to the code path.">__sev()</a>).</p>
162 <p >This is called <em>best_effort</em> because under certain circumstances (notably the default timer pool being disabled or full) the best effort is simply to return immediately without a __wfe, thus turning the calling code into a busy wait.</p>
163 <p >Example usage: </p><div class="fragment"><div class="line"><span class="keywordtype">bool</span> my_function_with_timeout_us(uint64_t timeout_us) {</div>
164 <div class="line"> <a class="code hl_typedef" href="group__timestamp.html#ga8b7f3d602cc053f05bacceeacc257ed8">absolute_time_t</a> timeout_time = <a class="code hl_function" href="group__timestamp.html#ga70921b9073202a54eec3494b4d19ec84">make_timeout_time_us</a>(timeout_us);</div>
165 <div class="line"> <span class="keywordflow">do</span> {</div>
166 <div class="line"> <span class="comment">// each time round the loop, we check to see if the condition</span></div>
167 <div class="line"> <span class="comment">// we are waiting on has happened</span></div>
168 <div class="line"> <span class="keywordflow">if</span> (my_check_done()) {</div>
169 <div class="line"> <span class="comment">// do something</span></div>
170 <div class="line"> <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
171 <div class="line"> }</div>
172 <div class="line"> <span class="comment">// will try to sleep until timeout or the next processor event </span></div>
173 <div class="line"> } <span class="keywordflow">while</span> (!<a class="code hl_function" href="group__sleep.html#gaedc0ed51a5e908ddd660a5d279009abc">best_effort_wfe_or_timeout</a>(timeout_time));</div>
174 <div class="line"> <span class="keywordflow">return</span> <span class="keyword">false</span>; <span class="comment">// timed out</span></div>
175 <div class="line">}</div>
176 <div class="ttc" id="agroup__sleep_html_gaedc0ed51a5e908ddd660a5d279009abc"><div class="ttname"><a href="group__sleep.html#gaedc0ed51a5e908ddd660a5d279009abc">best_effort_wfe_or_timeout</a></div><div class="ttdeci">bool best_effort_wfe_or_timeout(absolute_time_t timeout_timestamp)</div><div class="ttdoc">Helper method for blocking on a timeout.</div><div class="ttdef"><b>Definition:</b> time.c:435</div></div>
177 <div class="ttc" id="agroup__timestamp_html_ga70921b9073202a54eec3494b4d19ec84"><div class="ttname"><a href="group__timestamp.html#ga70921b9073202a54eec3494b4d19ec84">make_timeout_time_us</a></div><div class="ttdeci">static absolute_time_t make_timeout_time_us(uint64_t us)</div><div class="ttdoc">Convenience method to get the timestamp a number of microseconds from the current time.</div><div class="ttdef"><b>Definition:</b> time.h:136</div></div>
178 <div class="ttc" id="agroup__timestamp_html_ga8b7f3d602cc053f05bacceeacc257ed8"><div class="ttname"><a href="group__timestamp.html#ga8b7f3d602cc053f05bacceeacc257ed8">absolute_time_t</a></div><div class="ttdeci">uint64_t absolute_time_t</div><div class="ttdoc">An opaque 64 bit timestamp in microseconds.</div><div class="ttdef"><b>Definition:</b> types.h:43</div></div>
179 </div><!-- fragment --><dl class="params"><dt>Parameters</dt><dd>
180 <table class="params">
181 <tr><td class="paramname">timeout_timestamp</td><td>the timeout time </td></tr>
185 <dl class="section return"><dt>Returns</dt><dd>true if the target time is reached, false otherwise </dd></dl>
189 <a id="gae617a6842d4f3a192064c4354b88fcff" name="gae617a6842d4f3a192064c4354b88fcff"></a>
190 <h2 class="memtitle"><span class="permalink"><a href="#gae617a6842d4f3a192064c4354b88fcff">◆ </a></span>sleep_ms()</h2>
192 <div class="memitem">
193 <div class="memproto">
194 <table class="memname">
196 <td class="memname">void sleep_ms </td>
198 <td class="paramtype">uint32_t </td>
199 <td class="paramname"><em>ms</em></td><td>)</td>
203 </div><div class="memdoc">
205 <p>Wait for the given number of milliseconds before returning. </p>
206 <dl class="section note"><dt>Note</dt><dd>This method attempts to perform a lower power sleep (using WFE) as much as possible.</dd></dl>
207 <dl class="params"><dt>Parameters</dt><dd>
208 <table class="params">
209 <tr><td class="paramname">ms</td><td>the number of milliseconds to sleep </td></tr>
216 <a id="ga7abed28d3918fe2b15f8007ba6569172" name="ga7abed28d3918fe2b15f8007ba6569172"></a>
217 <h2 class="memtitle"><span class="permalink"><a href="#ga7abed28d3918fe2b15f8007ba6569172">◆ </a></span>sleep_until()</h2>
219 <div class="memitem">
220 <div class="memproto">
221 <table class="memname">
223 <td class="memname">void sleep_until </td>
225 <td class="paramtype"><a class="el" href="group__timestamp.html#ga8b7f3d602cc053f05bacceeacc257ed8">absolute_time_t</a> </td>
226 <td class="paramname"><em>target</em></td><td>)</td>
230 </div><div class="memdoc">
232 <p>Wait until after the given timestamp to return. </p>
233 <dl class="section note"><dt>Note</dt><dd>This method attempts to perform a lower power (WFE) sleep</dd></dl>
234 <dl class="params"><dt>Parameters</dt><dd>
235 <table class="params">
236 <tr><td class="paramname">target</td><td>the time after which to return </td></tr>
240 <dl class="section see"><dt>See also</dt><dd><a class="el" href="group__sleep.html#gaeeaebd3a10e0a193022f15c8603772ba" title="Wait for the given number of microseconds before returning.">sleep_us()</a> </dd>
242 <a class="el" href="group__hardware__timer.html#gab1c72f391015ff00a96b24477aa327ee" title="Busy wait wasting cycles until after the specified timestamp using the default timer instance.">busy_wait_until()</a> </dd></dl>
246 <a id="gaeeaebd3a10e0a193022f15c8603772ba" name="gaeeaebd3a10e0a193022f15c8603772ba"></a>
247 <h2 class="memtitle"><span class="permalink"><a href="#gaeeaebd3a10e0a193022f15c8603772ba">◆ </a></span>sleep_us()</h2>
249 <div class="memitem">
250 <div class="memproto">
251 <table class="memname">
253 <td class="memname">void sleep_us </td>
255 <td class="paramtype">uint64_t </td>
256 <td class="paramname"><em>us</em></td><td>)</td>
260 </div><div class="memdoc">
262 <p>Wait for the given number of microseconds before returning. </p>
263 <dl class="section note"><dt>Note</dt><dd>This method attempts to perform a lower power (WFE) sleep</dd></dl>
264 <dl class="params"><dt>Parameters</dt><dd>
265 <table class="params">
266 <tr><td class="paramname">us</td><td>the number of microseconds to sleep </td></tr>
270 <dl class="section see"><dt>See also</dt><dd><a class="el" href="group__hardware__timer.html#gac089d1c42bb7658bb43c798454f66e2f" title="Busy wait wasting cycles for the given (64 bit) number of microseconds using the default timer instan...">busy_wait_us()</a> </dd></dl>
274 </div><!-- contents -->
275 </div><!-- doc-content -->
277 <script src="main.js"></script>