]> Git Repo - pico-vscode.git/blob - web/docs/group__sleep.html
Merge branch 'main' into main
[pico-vscode.git] / web / docs / group__sleep.html
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">
4 <head>
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"/>
25 </head>
26 <body>
27         <div class="navigation-mobile">
28                 <div class="logo--mobile">
29                         <a href="/"><img src="logo-mobile.svg" alt="Raspberry Pi"></a>
30                 </div>
31                 <div class="navigation-toggle">
32                         <span class="line-1"></span>
33                         <span class="line-2">
34                                 <p>Menu Toggle</p>
35                         </span>
36                         <span class="line-3"></span>
37                 </div>
38         </div>
39         <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
40                 <div class="logo">
41                         <a href="index.html"> <img src="logo.svg" alt="Raspberry Pi"></a>
42                         <span style="display: inline-block; margin-top: 10px;">
43                                 v2.0.0
44                         </span>
45                 </div>
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>
49                 </div>
50 <!--            <div class="search">
51                         <form>
52                                 <input type="search" name="search" id="search" placeholder="Search">
53                                 <input type="submit" value="Search">
54                         </form>
55                 </div> -->
56 <!-- Generated by Doxygen 1.9.4 -->
57 <script type="text/javascript">
58 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
59 var searchBox = new SearchBox("searchBox", "search",'Search','.html');
60 /* @license-end */
61 </script>
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&amp;dn=expat.txt MIT */
66 $(function() {
67   initMenu('',true,false,'search.php','Search');
68   $(document).ready(function() { init_search(); });
69 });
70 /* @license-end */
71 </script>
72 <div id="main-nav"></div>
73 </div><!-- top -->
74 <div id="side-nav" class="ui-resizable side-nav-resizable">
75   <div id="nav-tree">
76     <div id="nav-tree-contents">
77       <div id="nav-sync" class="sync"></div>
78     </div>
79   </div>
80   <div id="splitbar" style="-moz-user-select:none;" 
81        class="ui-resizable-handle">
82   </div>
83 </div>
84 <script type="text/javascript">
85 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
86 $(document).ready(function(){initNavTree('group__sleep.html',''); initResizable(); });
87 /* @license-end */
88 </script>
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)">
95 </div>
96
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">
101 </iframe>
102 </div>
103
104 <div class="header">
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> &raquo; <a class="el" href="group__pico__time.html">pico_time</a></div></div></div>
108 </div><!--header-->
109 <div class="contents">
110
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&#160;</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">&#160;</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">&#160;</td></tr>
119 <tr class="memitem:gaeeaebd3a10e0a193022f15c8603772ba"><td class="memItemLeft" align="right" valign="top">void&#160;</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">&#160;</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">&#160;</td></tr>
122 <tr class="memitem:gae617a6842d4f3a192064c4354b88fcff"><td class="memItemLeft" align="right" valign="top">void&#160;</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">&#160;</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">&#160;</td></tr>
125 <tr class="memitem:gaedc0ed51a5e908ddd660a5d279009abc"><td class="memItemLeft" align="right" valign="top">bool&#160;</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">&#160;</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">&#160;</td></tr>
128 </table>
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>
133 <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>
135 <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>
138 <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>
140 <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">&#9670;&nbsp;</a></span>best_effort_wfe_or_timeout()</h2>
145
146 <div class="memitem">
147 <div class="memproto">
148       <table class="memname">
149         <tr>
150           <td class="memname">bool best_effort_wfe_or_timeout </td>
151           <td>(</td>
152           <td class="paramtype"><a class="el" href="group__timestamp.html#ga8b7f3d602cc053f05bacceeacc257ed8">absolute_time_t</a>&#160;</td>
153           <td class="paramname"><em>timeout_timestamp</em></td><td>)</td>
154           <td></td>
155         </tr>
156       </table>
157 </div><div class="memdoc">
158
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>
182   </table>
183   </dd>
184 </dl>
185 <dl class="section return"><dt>Returns</dt><dd>true if the target time is reached, false otherwise </dd></dl>
186
187 </div>
188 </div>
189 <a id="gae617a6842d4f3a192064c4354b88fcff" name="gae617a6842d4f3a192064c4354b88fcff"></a>
190 <h2 class="memtitle"><span class="permalink"><a href="#gae617a6842d4f3a192064c4354b88fcff">&#9670;&nbsp;</a></span>sleep_ms()</h2>
191
192 <div class="memitem">
193 <div class="memproto">
194       <table class="memname">
195         <tr>
196           <td class="memname">void sleep_ms </td>
197           <td>(</td>
198           <td class="paramtype">uint32_t&#160;</td>
199           <td class="paramname"><em>ms</em></td><td>)</td>
200           <td></td>
201         </tr>
202       </table>
203 </div><div class="memdoc">
204
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>
210   </table>
211   </dd>
212 </dl>
213
214 </div>
215 </div>
216 <a id="ga7abed28d3918fe2b15f8007ba6569172" name="ga7abed28d3918fe2b15f8007ba6569172"></a>
217 <h2 class="memtitle"><span class="permalink"><a href="#ga7abed28d3918fe2b15f8007ba6569172">&#9670;&nbsp;</a></span>sleep_until()</h2>
218
219 <div class="memitem">
220 <div class="memproto">
221       <table class="memname">
222         <tr>
223           <td class="memname">void sleep_until </td>
224           <td>(</td>
225           <td class="paramtype"><a class="el" href="group__timestamp.html#ga8b7f3d602cc053f05bacceeacc257ed8">absolute_time_t</a>&#160;</td>
226           <td class="paramname"><em>target</em></td><td>)</td>
227           <td></td>
228         </tr>
229       </table>
230 </div><div class="memdoc">
231
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>
237   </table>
238   </dd>
239 </dl>
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>
241 <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>
243
244 </div>
245 </div>
246 <a id="gaeeaebd3a10e0a193022f15c8603772ba" name="gaeeaebd3a10e0a193022f15c8603772ba"></a>
247 <h2 class="memtitle"><span class="permalink"><a href="#gaeeaebd3a10e0a193022f15c8603772ba">&#9670;&nbsp;</a></span>sleep_us()</h2>
248
249 <div class="memitem">
250 <div class="memproto">
251       <table class="memname">
252         <tr>
253           <td class="memname">void sleep_us </td>
254           <td>(</td>
255           <td class="paramtype">uint64_t&#160;</td>
256           <td class="paramname"><em>us</em></td><td>)</td>
257           <td></td>
258         </tr>
259       </table>
260 </div><div class="memdoc">
261
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>
267   </table>
268   </dd>
269 </dl>
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>
271
272 </div>
273 </div>
274 </div><!-- contents -->
275 </div><!-- doc-content -->
276
277         <script src="main.js"></script>
278 </body>
279 </html>
This page took 0.041901 seconds and 4 git commands to generate.