blob: ba767da8333935c90c6ff5b65ce9bf596e2514c4 [file] [log] [blame]
<!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"/>
<title>RTX Specific Functions</title>
<title>CMSIS-RTOS: RTX Specific Functions</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="cmsis.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script type="text/javascript" src="printComponentTabs.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
$(document).ready(initResizable);
$(window).load(resizeHeight);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
$(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 46px;">
<td id="projectlogo"><img alt="Logo" src="CMSIS_Logo_Final.png"/></td>
<td style="padding-left: 0.5em;">
<div id="projectname">CMSIS-RTOS
&#160;<span id="projectnumber">Version 1.03</span>
</div>
<div id="projectbrief">Real-Time Operating System: API and RTX Reference Implementation.</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<div id="CMSISnav" class="tabs1">
<ul class="tablist">
<script type="text/javascript">
<!--
writeComponentTabs.call(this);
//-->
</script>
</ul>
</div>
<!-- Generated by Doxygen 1.8.6 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main&#160;Page</span></a></li>
<li><a href="pages.html"><span>Usage&#160;and&#160;Description</span></a></li>
<li><a href="modules.html"><span>Reference</span></a></li>
<li>
<div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</li>
</ul>
</div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('group__RTX__Global__Functions.html','');});
</script>
<div id="doc-content">
<!-- 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">&#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>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="header">
<div class="summary">
<a href="#func-members">Functions</a> </div>
<div class="headertitle">
<div class="title">RTX Specific Functions</div> </div>
</div><!--header-->
<div class="contents">
<p>This section describes the functions that are specific to CMSIS-RTOS RTX.
<a href="#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:gafb4dc4d3dff8343a393726d2860282e4"><td class="memItemLeft" align="right" valign="top">__NO_RETURN void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__RTX__Global__Functions.html#gafb4dc4d3dff8343a393726d2860282e4">os_idle_demon</a> (void)</td></tr>
<tr class="memdesc:gafb4dc4d3dff8343a393726d2860282e4"><td class="mdescLeft">&#160;</td><td class="mdescRight">OS idle demon (running when no other thread is ready to run). <a href="#gafb4dc4d3dff8343a393726d2860282e4">More...</a><br/></td></tr>
<tr class="separator:gafb4dc4d3dff8343a393726d2860282e4"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga145e7eafdd042bb522020cbb3b469d9c"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__RTX__Global__Functions.html#ga145e7eafdd042bb522020cbb3b469d9c">os_tick_init</a> (void)</td></tr>
<tr class="memdesc:ga145e7eafdd042bb522020cbb3b469d9c"><td class="mdescLeft">&#160;</td><td class="mdescRight">Initializes an alternative hardware timer as RTX kernel timer. <a href="#ga145e7eafdd042bb522020cbb3b469d9c">More...</a><br/></td></tr>
<tr class="separator:ga145e7eafdd042bb522020cbb3b469d9c"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga567543bf38239a91f09751686c23017b"><td class="memItemLeft" align="right" valign="top">uint32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__RTX__Global__Functions.html#ga567543bf38239a91f09751686c23017b">os_tick_val</a> (void)</td></tr>
<tr class="memdesc:ga567543bf38239a91f09751686c23017b"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get alternative hardware timer's current value (0 .. OS_TRV) <a href="#ga567543bf38239a91f09751686c23017b">More...</a><br/></td></tr>
<tr class="separator:ga567543bf38239a91f09751686c23017b"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gad5deddec3fea0fb31798f571afc3c692"><td class="memItemLeft" align="right" valign="top">uint32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__RTX__Global__Functions.html#gad5deddec3fea0fb31798f571afc3c692">os_tick_ovf</a> (void)</td></tr>
<tr class="memdesc:gad5deddec3fea0fb31798f571afc3c692"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get alternative hardware timer's overflow flag. <a href="#gad5deddec3fea0fb31798f571afc3c692">More...</a><br/></td></tr>
<tr class="separator:gad5deddec3fea0fb31798f571afc3c692"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga85dab8408f27236c7341a69feb6258c7"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__RTX__Global__Functions.html#ga85dab8408f27236c7341a69feb6258c7">os_tick_irqack</a> (void)</td></tr>
<tr class="memdesc:ga85dab8408f27236c7341a69feb6258c7"><td class="mdescLeft">&#160;</td><td class="mdescRight">Acknowledge alternative hardware timer interrupt. <a href="#ga85dab8408f27236c7341a69feb6258c7">More...</a><br/></td></tr>
<tr class="separator:ga85dab8408f27236c7341a69feb6258c7"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga651ae76b3acf45f80bf0e0487b51d6e6"><td class="memItemLeft" align="right" valign="top">__NO_RETURN void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__RTX__Global__Functions.html#ga651ae76b3acf45f80bf0e0487b51d6e6">os_error</a> (uint32_t error_code)</td></tr>
<tr class="memdesc:ga651ae76b3acf45f80bf0e0487b51d6e6"><td class="mdescLeft">&#160;</td><td class="mdescRight">OS error callback (called when a runtime error is detected). <a href="#ga651ae76b3acf45f80bf0e0487b51d6e6">More...</a><br/></td></tr>
<tr class="separator:ga651ae76b3acf45f80bf0e0487b51d6e6"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga3e9c57746ccbdfe90464ad50513c569e"><td class="memItemLeft" align="right" valign="top">uint32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__RTX__Global__Functions.html#ga3e9c57746ccbdfe90464ad50513c569e">os_suspend</a> (void)</td></tr>
<tr class="memdesc:ga3e9c57746ccbdfe90464ad50513c569e"><td class="mdescLeft">&#160;</td><td class="mdescRight">Suspend the RTX task scheduler. <a href="#ga3e9c57746ccbdfe90464ad50513c569e">More...</a><br/></td></tr>
<tr class="separator:ga3e9c57746ccbdfe90464ad50513c569e"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga1b85a217d43e6b971ffcf24f8aae1c33"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__RTX__Global__Functions.html#ga1b85a217d43e6b971ffcf24f8aae1c33">os_resume</a> (uint32_t sleep_time)</td></tr>
<tr class="memdesc:ga1b85a217d43e6b971ffcf24f8aae1c33"><td class="mdescLeft">&#160;</td><td class="mdescRight">Resume the RTX task scheduler. <a href="#ga1b85a217d43e6b971ffcf24f8aae1c33">More...</a><br/></td></tr>
<tr class="separator:ga1b85a217d43e6b971ffcf24f8aae1c33"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Description</h2>
<p>The RTX kernel can be customized for different application requirements:</p>
<ul>
<li>If you are depending on the <a class="el" href="lowPower.html">lowest power consumption</a> possible, you need to adapt the function <a class="el" href="group__RTX__Global__Functions.html#gafb4dc4d3dff8343a393726d2860282e4">os_idle_demon</a> to send the system to sleep mode as often as possible. In addition, use the <a class="el" href="lowPower.html#TickLess">low power RTX extensions</a> <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> to suspend the RTX scheduler and to stop the SysTick timer.</li>
<li>If you need to specify an <a class="el" href="timerTick.html#AltTimer">alternate hardware timer</a> as the system tick timer, you need to<ol type="1">
<li>implement the functions <a class="el" href="group__RTX__Global__Functions.html#ga145e7eafdd042bb522020cbb3b469d9c">os_tick_init</a>, <a class="el" href="group__RTX__Global__Functions.html#gad5deddec3fea0fb31798f571afc3c692">os_tick_ovf</a>, <a class="el" href="group__RTX__Global__Functions.html#ga567543bf38239a91f09751686c23017b">os_tick_val</a>, and optionally the function <a class="el" href="group__RTX__Global__Functions.html#ga85dab8408f27236c7341a69feb6258c7">os_tick_irqack</a>.</li>
<li>replace the alternate timer interrupt vector with the <a class="el" href="timerTick.html#OS_Tick_Handler">OS_Tick_Handler</a> in the Interrupt Vector Table in startup file.</li>
</ol>
</li>
<li>If you try to find a <b>runtime</b> <b>error</b>, use the function <a class="el" href="group__RTX__Global__Functions.html#ga651ae76b3acf45f80bf0e0487b51d6e6">os_error</a> to debug the error. </li>
</ul>
<h2 class="groupheader">Function Documentation</h2>
<a class="anchor" id="ga651ae76b3acf45f80bf0e0487b51d6e6"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void os_error </td>
<td>(</td>
<td class="paramtype">uint32_t&#160;</td>
<td class="paramname"><em>error_code</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">error_code</td><td>actual error code that has been detected.</td></tr>
</table>
</dd>
</dl>
<p>Some system error conditions can be detected during runtime. If the RTX kernel detects a runtime error, it calls the runtime error function <b>os_error</b>.</p>
<p>The argument <em>error_code</em> passes the actual error code to this function:</p>
<table class="doxtable">
<tr>
<th>Error Code </th><th>Description </th></tr>
<tr>
<td>OS_ERROR_STACK_OVF</td><td>The stack checking has detected a stack overflow for the currently running thread. </td></tr>
<tr>
<td>OS_ERROR_FIFO_OVF </td><td>The ISR FIFO Queue buffer overflow is detected. </td></tr>
<tr>
<td>OS_ERROR_MBX_OVF </td><td>A mailbox overflow is detected for the function <a class="el" href="group__CMSIS__RTOS__Message.html#gac0dcf462fc92de8ffaba6cc004514a6d">osMessagePut</a> or <a class="el" href="group__CMSIS__RTOS__Mail.html#ga485ef6f81854ebda8ffbce4832181e02">osMailPut</a>. </td></tr>
<tr>
<td>OS_ERROR_TIMER_OVF</td><td>The User Timer Callback Queue overflow is detected. </td></tr>
</table>
<p>The function <b>os_error</b> must contain an infinite loop to prevent further program execution. You can use an emulator to step over infinite loop and trace into the code introducing a runtime error. For the overflow errors this means you need to increase the size of the object causing an overflow.</p>
<dl class="section note"><dt>Note</dt><dd>Cannot be called from <a class="el" href="functionOverview.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
<p><b>Code</b> <b>Example</b> </p>
<div class="fragment"><div class="line"><span class="keywordtype">void</span> <a class="code" href="group__RTX__Global__Functions.html#ga651ae76b3acf45f80bf0e0487b51d6e6">os_error</a> (uint32_t error_code) {</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// HERE: include optional code to be executed on runtime error. </span></div>
<div class="line"> <span class="keywordflow">switch</span> (error_code) {</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">case</span> <a class="code" href="RTX__Conf__CM_8c.html#abf8311a7a239ec56c6d725f926ba766d">OS_ERROR_STACK_OVF</a>:</div>
<div class="line"> <span class="comment">// Stack overflow detected for the currently running task. </span></div>
<div class="line"> <span class="comment">// Thread can be identified by calling svcThreadGetId(). </span></div>
<div class="line"> <span class="keywordflow">break</span>;</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">case</span> <a class="code" href="RTX__Conf__CM_8c.html#a075d54df14c85a6afe32b7f5c99c9c29">OS_ERROR_FIFO_OVF</a>:</div>
<div class="line"> <span class="comment">// ISR FIFO Queue buffer overflow detected. </span></div>
<div class="line"> <span class="keywordflow">break</span>;</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">case</span> <a class="code" href="RTX__Conf__CM_8c.html#ab715d7d66c341c067ef0a97b55db8a10">OS_ERROR_MBX_OVF</a>:</div>
<div class="line"> <span class="comment">// Mailbox overflow detected. </span></div>
<div class="line"> <span class="keywordflow">break</span>;</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">case</span> <a class="code" href="RTX__Conf__CM_8c.html#a79d7e388d951f11bd0dabd13f722cea8">OS_ERROR_TIMER_OVF</a>:</div>
<div class="line"> <span class="comment">// User Timer Callback Queue overflow detected. </span></div>
<div class="line"> <span class="keywordflow">break</span>;</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">for</span> (;;);</div>
<div class="line">}</div>
</div><!-- fragment --><p>OS error callback (called when a runtime error is detected).</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">error_code</td><td>actual error code that has been detected </td></tr>
</table>
</dd>
</dl>
</div>
</div>
<a class="anchor" id="gafb4dc4d3dff8343a393726d2860282e4"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void os_idle_demon </td>
<td>(</td>
<td class="paramtype">void&#160;</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>The function <b>os_idle_demon</b> is executed by the RTX kernel, when no other threads are ready to run. By default, this task is an empty end-less loop that does nothing. It only waits until another task becomes ready to run. You may change the code of the <b>os_idle_demon</b> function to put the CPU into a power-saving or idle mode.</p>
<p>The default stack size for this task is defined in the file <b>#<a class="el" href="RTX__Conf__CM_8c.html">RTX_Conf_CM.c</a></b>. Refer to <a class="el" href="threadConfig.html">Thread Configuration</a> entry <b>Default Thread stack size [bytes]</b>.</p>
<dl class="section note"><dt>Note</dt><dd>Cannot be called from <a class="el" href="functionOverview.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
<p><b>Code</b> <b>Example</b> </p>
<div class="fragment"><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>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">for</span> (;;) {</div>
<div class="line"> __WFI(); <span class="comment">// wait for interrupt</span></div>
<div class="line"> }</div>
<div class="line">}</div>
</div><!-- fragment --><p>OS idle demon (running when no other thread is ready to run). </p>
</div>
</div>
<a class="anchor" id="ga1b85a217d43e6b971ffcf24f8aae1c33"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void os_resume </td>
<td>(</td>
<td class="paramtype">uint32_t&#160;</td>
<td class="paramname"><em>sleep_time</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">sleep_time</td><td>specifies how long the system was in sleep or power-down mode.</td></tr>
</table>
</dd>
</dl>
<p>The function <b>os_resume</b> resumes the RTX task scheduler. You must call this function after you have called <a class="el" href="group__RTX__Global__Functions.html#ga3e9c57746ccbdfe90464ad50513c569e">os_suspend</a> to re-enable the task scheduler.</p>
<p>The argument <em>sleep_time</em> specifies how long the system was in sleep or power-down mode. It is measured in number of system intervals.</p>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>You can call this function from the idle task only.</li>
<li>When the system is in power-down, the system tick timer is not running.</li>
<li>Cannot be called from <a class="el" href="functionOverview.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</li>
</ul>
</dd></dl>
<p>See <a class="el" href="group__RTX__Global__Functions.html#ga3e9c57746ccbdfe90464ad50513c569e">os_suspend</a> for a <b>Code</b> <b>Example</b>. </p>
</div>
</div>
<a class="anchor" id="ga3e9c57746ccbdfe90464ad50513c569e"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">uint32_t os_suspend </td>
<td>(</td>
<td class="paramtype">void&#160;</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<dl class="section return"><dt>Returns</dt><dd>number of ticks, for how long the system can sleep or power-down.</dd></dl>
<p>The function <b>os_suspend</b> suspends the RTX task scheduler. The function calculates the time, for how long the system is allowed to power-down, and locks the task scheduler. When the function returns, the task switches are disabled. For normal RTX operation, after calling <b>os_suspend</b>, you must call the <a class="el" href="group__RTX__Global__Functions.html#ga1b85a217d43e6b971ffcf24f8aae1c33">os_resume</a> function to re-enable the OS task scheduler.</p>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>You can call this function from the idle task only.</li>
<li>When the system is in power-down, the system tick timer is not running.</li>
<li>Cannot be called from <a class="el" href="functionOverview.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</li>
</ul>
</dd></dl>
<p><b>Code</b> <b>Example</b> </p>
<p>The low power RTX is controlled from the <a class="el" href="group__RTX__Global__Functions.html#gafb4dc4d3dff8343a393726d2860282e4">os_idle_demon</a>. The peripheral wake-up timer must be initialized before the system enters an endless loop. <b>os_suspend</b> calculates the timeout until the first suspended task becomes ready, and returns the timeout to the user:</p>
<div class="fragment"><div class="line"><span class="keywordflow">for</span> (;;) {</div>
<div class="line">sleep = <a class="code" href="group__RTX__Global__Functions.html#ga3e9c57746ccbdfe90464ad50513c569e">os_suspend</a>();</div>
</div><!-- fragment --><p>The user sets-up a peripheral timer to sleep timeout and starts the timer. The timeout is measured in system ticks.</p>
<div class="fragment"><div class="line"><span class="keywordflow">if</span> (sleep) {</div>
<div class="line"> <span class="comment">// Setup the wake-up timer ... </span></div>
</div><!-- fragment --><p>When the wake-up timer is set-up and running, the user puts the system in power-down mode. The wake-up timer must run also in power-down mode. All other peripherals and the CPU may power-down to reduce power.</p>
<div class="fragment"><div class="line"><span class="comment">// Power-down the system ... </span></div>
<div class="line">SCB-&gt;SCR |= SCB_SCR_SLEEPDEEP_Msk;</div>
<div class="line">__WFE();</div>
</div><!-- fragment --><p>The wake-up timer, when expired, generates the interrupt and wakes-up the system. Hence, it must run also in power-down mode. The system resumes operation and needs to call the function <a class="el" href="group__RTX__Global__Functions.html#ga1b85a217d43e6b971ffcf24f8aae1c33">os_resume</a>. This function restores the RTX and re-enables the scheduler.</p>
<div class="fragment"><div class="line"> <span class="comment">// After Wake-up </span></div>
<div class="line"> sleep = (tc - LPC_WWDT-&gt;TV) / 250;</div>
<div class="line">}</div>
<div class="line"><a class="code" href="group__RTX__Global__Functions.html#ga1b85a217d43e6b971ffcf24f8aae1c33">os_resume</a>(sleep);</div>
</div><!-- fragment --><p>If, for any reason, the system does not wake up immediately after the wake-up interrupt, the actual sleep time is checked and adjusted. </p>
</div>
</div>
<a class="anchor" id="ga145e7eafdd042bb522020cbb3b469d9c"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int os_tick_init </td>
<td>(</td>
<td class="paramtype">void&#160;</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<dl class="section return"><dt>Returns</dt><dd>IRQ number of the alternative hardware timer</dd></dl>
<p>The function <b>os_tick_init</b> initializes an alternate hardware timer as the system tick timer and starts it. If you setup OS_SYSTICK to 0, this function will be available for adding the alternate timer. It returns the interrupt number of the alternative hardware timer.</p>
<dl class="section note"><dt>Note</dt><dd>- When using an alternate timer, you must enter the <a class="el" href="timerTick.html#OS_Tick_Handler">OS_Tick_Handler</a> in the interrupt vector table in the startup file.</dd>
<dd>
- Cannot be called from <a class="el" href="functionOverview.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
<p><b>Code</b> <b>Example</b> </p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;LPC43xx.h&quot;</span> <span class="comment">// Device header</span></div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> <a class="code" href="group__RTX__Global__Functions.html#ga145e7eafdd042bb522020cbb3b469d9c">os_tick_init</a> (<span class="keywordtype">void</span>) {</div>
<div class="line"> <span class="comment">// Initialize hardware timer as system tick timer. </span></div>
<div class="line"> </div>
<div class="line"> LPC_CCU1-&gt;CLK_M4_RITIMER_CFG = (1UL &lt;&lt; 0);</div>
<div class="line"> </div>
<div class="line"> LPC_RITIMER-&gt;COMPVAL = <a class="code" href="RTX__Conf__CM_8c.html#a9d55a070ddb219165bd4287f08318d51">OS_TRV</a>; <span class="comment">// Set match value</span></div>
<div class="line"> LPC_RITIMER-&gt;COUNTER = 0; <span class="comment">// Set count value to 0</span></div>
<div class="line"> LPC_RITIMER-&gt;CTRL = (1UL &lt;&lt; 3) | <span class="comment">// Timer enable</span></div>
<div class="line"> (1UL &lt;&lt; 2) | <span class="comment">// Timer enable for debug</span></div>
<div class="line"> (1UL &lt;&lt; 1) | <span class="comment">// Timer enable clear on match</span></div>
<div class="line"> (1UL &lt;&lt; 0); <span class="comment">// Clear interrupt flag</span></div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">return</span> (M0_RITIMER_OR_WWDT_IRQn); <span class="comment">// Return IRQ number of timer (0..239) </span></div>
<div class="line">}</div>
</div><!-- fragment -->
</div>
</div>
<a class="anchor" id="ga85dab8408f27236c7341a69feb6258c7"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void os_tick_irqack </td>
<td>(</td>
<td class="paramtype">void&#160;</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>The function <b>os_tick_irqack</b> acknowledges the peripheral timer interrupt.</p>
<dl class="section note"><dt>Note</dt><dd>- When using an alternate timer, you must enter the <a class="el" href="timerTick.html#OS_Tick_Handler">OS_Tick_Handler</a> in the interrupt vector table in the startup file. </dd>
<dd>
- Cannot be called from <a class="el" href="functionOverview.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
<p><b>Code</b> <b>Example</b> </p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;LPC43xx.h&quot;</span> <span class="comment">// Device header</span></div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> <a class="code" href="group__RTX__Global__Functions.html#ga85dab8408f27236c7341a69feb6258c7">os_tick_irqack</a> (<span class="keywordtype">void</span>) {</div>
<div class="line"> </div>
<div class="line"> LPC_RITIMER-&gt;CTRL |= (1UL &lt;&lt; 0); <span class="comment">// Clear interrupt flag</span></div>
<div class="line">}</div>
</div><!-- fragment -->
</div>
</div>
<a class="anchor" id="gad5deddec3fea0fb31798f571afc3c692"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">uint32_t os_tick_ovf </td>
<td>(</td>
<td class="paramtype">void&#160;</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<dl class="section return"><dt>Returns</dt><dd>Overflow flag<br/>
<ul>
<li>1 : overflow</li>
<li>0 : no overflow</li>
</ul>
</dd></dl>
<p>The function <b>os_tick_ovf</b> returns the overflow flag of the alternate hardware timer specified by os_tick_init.</p>
<dl class="section note"><dt>Note</dt><dd>- When using an alternate timer, you must enter the <a class="el" href="timerTick.html#OS_Tick_Handler">OS_Tick_Handler</a> in the interrupt vector table in the startup file. </dd>
<dd>
- Cannot be called from <a class="el" href="functionOverview.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
<p><b>Code</b> <b>Example</b> </p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;LPC43xx.h&quot;</span> <span class="comment">// Device header</span></div>
<div class="line"> </div>
<div class="line">uint32_t <a class="code" href="group__RTX__Global__Functions.html#gad5deddec3fea0fb31798f571afc3c692">os_tick_ovf</a> (<span class="keywordtype">void</span>) {</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">return</span> (LPC_RITIMER-&gt;CTRL);</div>
<div class="line">}</div>
</div><!-- fragment -->
</div>
</div>
<a class="anchor" id="ga567543bf38239a91f09751686c23017b"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">uint32_t os_tick_val </td>
<td>(</td>
<td class="paramtype">void&#160;</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<dl class="section return"><dt>Returns</dt><dd>Current value of the alternative hardware timer</dd></dl>
<p>The function <b>os_tick_val</b> returns the current value of the alternate hardware timer specified by os_tick_init.</p>
<dl class="section note"><dt>Note</dt><dd>- When using an alternate timer, you must enter the <a class="el" href="timerTick.html#OS_Tick_Handler">OS_Tick_Handler</a> in the interrupt vector table in the startup file. </dd>
<dd>
- Cannot be called from <a class="el" href="functionOverview.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
<p><b>Code</b> <b>Example</b> </p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;LPC43xx.h&quot;</span> <span class="comment">// Device header</span></div>
<div class="line"> </div>
<div class="line">uint32_t <a class="code" href="group__RTX__Global__Functions.html#ga567543bf38239a91f09751686c23017b">os_tick_val</a> (<span class="keywordtype">void</span>) {</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">return</span> (LPC_RITIMER-&gt;COUNTER);</div>
<div class="line">}</div>
</div><!-- fragment -->
</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated on Wed Jul 10 2019 15:21:02 for CMSIS-RTOS Version 1.03 by Arm Ltd. All rights reserved.
<!--
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.6
-->
</li>
</ul>
</div>
</body>
</html>