lowPower.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  5. <meta http-equiv="X-UA-Compatible" content="IE=9"/>
  6. <title>Configuration for Low-Power Modes</title>
  7. <title>CMSIS-RTOS: Configuration for Low-Power Modes</title>
  8. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  9. <link href="cmsis.css" rel="stylesheet" type="text/css" />
  10. <script type="text/javascript" src="jquery.js"></script>
  11. <script type="text/javascript" src="dynsections.js"></script>
  12. <script type="text/javascript" src="printComponentTabs.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="navtree.js"></script>
  16. <script type="text/javascript">
  17. $(document).ready(initResizable);
  18. $(window).load(resizeHeight);
  19. </script>
  20. <link href="search/search.css" rel="stylesheet" type="text/css"/>
  21. <script type="text/javascript" src="search/search.js"></script>
  22. <script type="text/javascript">
  23. $(document).ready(function() { searchBox.OnSelectItem(0); });
  24. </script>
  25. </head>
  26. <body>
  27. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  28. <div id="titlearea">
  29. <table cellspacing="0" cellpadding="0">
  30. <tbody>
  31. <tr style="height: 46px;">
  32. <td id="projectlogo"><img alt="Logo" src="CMSIS_Logo_Final.png"/></td>
  33. <td style="padding-left: 0.5em;">
  34. <div id="projectname">CMSIS-RTOS
  35. &#160;<span id="projectnumber">Version 1.03</span>
  36. </div>
  37. <div id="projectbrief">Real-Time Operating System: API and RTX Reference Implementation.</div>
  38. </td>
  39. </tr>
  40. </tbody>
  41. </table>
  42. </div>
  43. <!-- end header part -->
  44. <div id="CMSISnav" class="tabs1">
  45. <ul class="tablist">
  46. <script type="text/javascript">
  47. <!--
  48. writeComponentTabs.call(this);
  49. //-->
  50. </script>
  51. </ul>
  52. </div>
  53. <!-- Generated by Doxygen 1.8.6 -->
  54. <script type="text/javascript">
  55. var searchBox = new SearchBox("searchBox", "search",false,'Search');
  56. </script>
  57. <div id="navrow1" class="tabs">
  58. <ul class="tablist">
  59. <li><a href="index.html"><span>Main&#160;Page</span></a></li>
  60. <li class="current"><a href="pages.html"><span>Usage&#160;and&#160;Description</span></a></li>
  61. <li><a href="modules.html"><span>Reference</span></a></li>
  62. <li>
  63. <div id="MSearchBox" class="MSearchBoxInactive">
  64. <span class="left">
  65. <img id="MSearchSelect" src="search/mag_sel.png"
  66. onmouseover="return searchBox.OnSearchSelectShow()"
  67. onmouseout="return searchBox.OnSearchSelectHide()"
  68. alt=""/>
  69. <input type="text" id="MSearchField" value="Search" accesskey="S"
  70. onfocus="searchBox.OnSearchFieldFocus(true)"
  71. onblur="searchBox.OnSearchFieldFocus(false)"
  72. onkeyup="searchBox.OnSearchFieldChange(event)"/>
  73. </span><span class="right">
  74. <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
  75. </span>
  76. </div>
  77. </li>
  78. </ul>
  79. </div>
  80. </div><!-- top -->
  81. <div id="side-nav" class="ui-resizable side-nav-resizable">
  82. <div id="nav-tree">
  83. <div id="nav-tree-contents">
  84. <div id="nav-sync" class="sync"></div>
  85. </div>
  86. </div>
  87. <div id="splitbar" style="-moz-user-select:none;"
  88. class="ui-resizable-handle">
  89. </div>
  90. </div>
  91. <script type="text/javascript">
  92. $(document).ready(function(){initNavTree('lowPower.html','');});
  93. </script>
  94. <div id="doc-content">
  95. <!-- window showing the filter options -->
  96. <div id="MSearchSelectWindow"
  97. onmouseover="return searchBox.OnSearchSelectShow()"
  98. onmouseout="return searchBox.OnSearchSelectHide()"
  99. onkeydown="return searchBox.OnSearchSelectKey(event)">
  100. <a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Macros</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&#160;</span>Pages</a></div>
  101. <!-- iframe showing the search results (closed by default) -->
  102. <div id="MSearchResultsWindow">
  103. <iframe src="javascript:void(0)" frameborder="0"
  104. name="MSearchResults" id="MSearchResults">
  105. </iframe>
  106. </div>
  107. <div class="header">
  108. <div class="headertitle">
  109. <div class="title">Configuration for Low-Power Modes </div> </div>
  110. </div><!--header-->
  111. <div class="contents">
  112. <div class="textblock"><p>The system thread <b>os_idle_demon</b> can be use to switch the system into a low-power mode. The easiest form to enter a low-power mode is the execution of the <code>__WFE</code> function that puts the processor into a sleep mode where it waits for an event.</p>
  113. <p><b>Configuration Example:</b></p>
  114. <div class="fragment"><div class="line"><span class="preprocessor">#include &quot;device.h&quot;</span> <span class="comment">/* Device definitions */</span></div>
  115. <div class="line"> </div>
  116. <div class="line"><span class="keywordtype">void</span> <a class="code" href="group__RTX__Global__Functions.html#gafb4dc4d3dff8343a393726d2860282e4">os_idle_demon</a> (<span class="keywordtype">void</span>) {</div>
  117. <div class="line"> <span class="comment">/* The idle demon is a system thread, running when no other thread is */</span></div>
  118. <div class="line"> <span class="comment">/* ready to run. */</span></div>
  119. <div class="line"> </div>
  120. <div class="line"> <span class="keywordflow">for</span> (;;) {</div>
  121. <div class="line"> __WFE(); <span class="comment">/* Enter sleep mode */</span></div>
  122. <div class="line"> }</div>
  123. <div class="line">}</div>
  124. </div><!-- fragment --><dl class="section note"><dt>Note</dt><dd><code>__WFE()</code> is not available at every Cortex-M implementation. Check device manuals for availability.</dd></dl>
  125. <h1><a class="anchor" id="TickLess"></a>
  126. Tick-less operation</h1>
  127. <p>CMSIS-RTOS RTX provides extension for tick-less operation which is useful for applications that use extensively low-power modes where the SysTick timer is also disabled. To provide a time-tick in such power-saving modes a wake-up timer is used to derive timer intervals. The RTX functions <a class="el" href="group__RTX__Global__Functions.html#ga3e9c57746ccbdfe90464ad50513c569e">os_suspend</a> and <a class="el" href="group__RTX__Global__Functions.html#ga1b85a217d43e6b971ffcf24f8aae1c33">os_resume</a> control the tick-less operation.</p>
  128. <p>Using this functions allows the RTX thread scheduler to stop the periodic kernel tick interrupt. When all active threads are suspended, the system enters power-down and calculates how long it can stay in this power-down mode. In the power-down mode the processor and potentially peripherals can be switched off. Only a wake-up timer must remain powered, because this timer is responsible to wake-up the system after the power-down period expires.</p>
  129. <p>The tick-less operation is controlled from the <a class="el" href="group__RTX__Global__Functions.html#gafb4dc4d3dff8343a393726d2860282e4">os_idle_demon</a> thread. The wake-up timeout value is set before the system enters the power-down mode. The function <a class="el" href="group__RTX__Global__Functions.html#ga3e9c57746ccbdfe90464ad50513c569e">os_suspend</a> calculates the wake-up timeout measured in RTX Timer Ticks; this value is used to setup the wake-up timer that runs during the power-down mode of the system.</p>
  130. <p>Once the system resumes operation (either by a wake-up time out or other interrupts) the RTX thread scheduler is started with the function <a class="el" href="group__RTX__Global__Functions.html#ga1b85a217d43e6b971ffcf24f8aae1c33">os_resume</a>. The parameter <em>sleep_time</em> specifies the time (in RTX Timer Ticks) that the system was in power-down mode.</p>
  131. <p><b>Code</b> <b>Example</b> </p>
  132. <div class="fragment"><div class="line"><span class="preprocessor">#include &quot;LPC11Uxx.h&quot;</span> <span class="comment">/* LPC11Uxx definitions */</span></div>
  133. <div class="line"> </div>
  134. <div class="line"><span class="keywordtype">void</span> <a class="code" href="group__RTX__Global__Functions.html#gafb4dc4d3dff8343a393726d2860282e4">os_idle_demon</a> (<span class="keywordtype">void</span>) {</div>
  135. <div class="line"> <span class="comment">/* The idle demon is a system thread, running when no other thread is */</span></div>
  136. <div class="line"> <span class="comment">/* ready to run. */</span></div>
  137. <div class="line"> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> sleep;</div>
  138. <div class="line"> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> tc;</div>
  139. <div class="line"> </div>
  140. <div class="line"> LPC_SYSCON-&gt;SYSAHBCLKCTRL |= (1UL &lt;&lt; 15) | <span class="comment">/* Enable clock for WWDT */</span></div>
  141. <div class="line"> (1UL &lt;&lt; 19); <span class="comment">/* Enable clock for Pin IRQ */</span></div>
  142. <div class="line"> </div>
  143. <div class="line"> LPC_SYSCON-&gt;PINTSEL[0] = 1; <span class="comment">/* P0.1 selected as INT0 IRQ */</span></div>
  144. <div class="line"> LPC_SYSCON-&gt;STARTERP0 |= (1UL &lt;&lt; 0); <span class="comment">/* Enable INT0 wake-up */</span></div>
  145. <div class="line"> LPC_SYSCON-&gt;STARTERP1 |= (1UL &lt;&lt; 12); <span class="comment">/* Enable WWDT wake-up */</span></div>
  146. <div class="line"> </div>
  147. <div class="line"> LPC_SYSCON-&gt;WDTOSCCTRL = (3 &lt;&lt; 0) | <span class="comment">/* WDOSC DIVSEL=3 */</span></div>
  148. <div class="line"> (2 &lt;&lt; 5); <span class="comment">/* WDOSC FREQ=0.8MHz */</span></div>
  149. <div class="line"> LPC_SYSCON-&gt;PDRUNCFG &amp;= ~(1UL &lt;&lt; 6); <span class="comment">/* Power-up WDT Oscillator */</span></div>
  150. <div class="line"> LPC_SYSCON-&gt;PDSLEEPCFG &amp;= ~(1UL &lt;&lt; 6); <span class="comment">/* Power WDT Oscillator in PD */</span></div>
  151. <div class="line"> </div>
  152. <div class="line"> LPC_WWDT-&gt;CLKSEL = (1UL &lt;&lt; 0) | <span class="comment">/* Select WDOSC as Clock */</span></div>
  153. <div class="line"> (1UL &lt;&lt; 31); <span class="comment">/* Lock selection */</span></div>
  154. <div class="line"> LPC_WWDT-&gt;WARNINT = 1000; <span class="comment">/* WDT Warning IRQ value */</span></div>
  155. <div class="line"> LPC_WWDT-&gt;MOD = (1UL &lt;&lt; 0); <span class="comment">/* Enable WDT */</span></div>
  156. <div class="line"> </div>
  157. <div class="line"> NVIC_EnableIRQ(FLEX_INT0_IRQn); <span class="comment">/* Enable INT0 IRQ (wake-up) */</span></div>
  158. <div class="line"> NVIC_EnableIRQ(WDT_IRQn); <span class="comment">/* Enable WWDT IRQ (wake-up) */</span></div>
  159. <div class="line"> </div>
  160. <div class="line"> <span class="keywordflow">for</span> (;;) {</div>
  161. <div class="line"> <span class="comment">/* HERE: include optional user code to be executed when no task runs.*/</span></div>
  162. <div class="line"> sleep = <a class="code" href="group__RTX__Global__Functions.html#ga3e9c57746ccbdfe90464ad50513c569e">os_suspend</a>(); <span class="comment">/* Suspend RTX thread scheduler */</span></div>
  163. <div class="line"> </div>
  164. <div class="line"> <span class="keywordflow">if</span> (sleep) { <span class="comment">/* How long can we sleep? */</span></div>
  165. <div class="line"> <span class="comment">/* &quot;sleep&quot; is in RTX Timer Ticks which is 10ms in this configuration */</span></div>
  166. <div class="line"> </div>
  167. <div class="line"> <span class="comment">/* Setup WDT wake-up: WDT ticks @25kHz (FREQ/2/(DIVSEL+1)/4) */</span></div>
  168. <div class="line"> tc = (sleep * 250) + 1000;</div>
  169. <div class="line"> LPC_WWDT-&gt;TC = tc;</div>
  170. <div class="line"> LPC_WWDT-&gt;FEED = 0xAA;</div>
  171. <div class="line"> LPC_WWDT-&gt;FEED = 0x55;</div>
  172. <div class="line"> </div>
  173. <div class="line"> <span class="comment">/* Enter Power-down mode */</span></div>
  174. <div class="line"> LPC_SYSCON-&gt;PDAWAKECFG = LPC_SYSCON-&gt;PDRUNCFG; <span class="comment">/* Power after wake-up */</span></div>
  175. <div class="line"> LPC_PMU-&gt;PCON = 0x02; <span class="comment">/* Select Power-down mode */</span></div>
  176. <div class="line"> SCB-&gt;SCR = (1UL &lt;&lt; 2); <span class="comment">/* Set SLEEPDEEP */</span></div>
  177. <div class="line"> __WFE(); <span class="comment">/* Enter Power-down mode */</span></div>
  178. <div class="line"> </div>
  179. <div class="line"> <span class="comment">/* After Wake-up */</span></div>
  180. <div class="line"> sleep = (tc - LPC_WWDT-&gt;TV) / 250;</div>
  181. <div class="line"> }</div>
  182. <div class="line"> </div>
  183. <div class="line"> <a class="code" href="group__RTX__Global__Functions.html#ga1b85a217d43e6b971ffcf24f8aae1c33">os_resume</a>(sleep); <span class="comment">/* Resume RTX thread scheduler */</span></div>
  184. <div class="line"> }</div>
  185. <div class="line">}</div>
  186. </div><!-- fragment --><dl class="section note"><dt>Note</dt><dd><code>__WFE()</code> is not available at every Cortex-M implementation. Check device manuals for availability. </dd></dl>
  187. </div></div><!-- contents -->
  188. </div><!-- doc-content -->
  189. <!-- start footer part -->
  190. <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  191. <ul>
  192. <li class="navelem"><a class="el" href="index.html">index</a></li><li class="navelem"><a class="el" href="rtxImplementation.html">RTX Implementation</a></li><li class="navelem"><a class="el" href="configure.html">Configure RTX</a></li>
  193. <li class="footer">Generated on Thu Apr 9 2020 15:49:56 for CMSIS-RTOS Version 1.03 by Arm Ltd. All rights reserved.
  194. <!--
  195. <a href="http://www.doxygen.org/index.html">
  196. <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.6
  197. -->
  198. </li>
  199. </ul>
  200. </div>
  201. </body>
  202. </html>