1 <!-- HTML header for doxygen 1.9.6-->
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" lang="en-US">
5 <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
6 <meta http-equiv="X-UA-Compatible" content="IE=11"/>
7 <meta name="viewport" content="width=device-width, initial-scale=1"/>
8 <title>CMSIS-RTOS2: Timer Management</title>
9 <link href="doxygen.css" rel="stylesheet" type="text/css"/>
10 <link href="tabs.css" rel="stylesheet" type="text/css"/>
11 <link href="extra_navtree.css" rel="stylesheet" type="text/css"/>
12 <link href="extra_stylesheet.css" rel="stylesheet" type="text/css"/>
13 <link href="extra_search.css" rel="stylesheet" type="text/css"/>
14 <script type="text/javascript" src="jquery.js"></script>
15 <script type="text/javascript" src="dynsections.js"></script>
16 <script type="text/javascript" src="printComponentTabs.js"></script>
17 <script type="text/javascript" src="footer.js"></script>
18 <script type="text/javascript" src="navtree.js"></script>
19 <link href="navtree.css" rel="stylesheet" type="text/css"/>
20 <script type="text/javascript" src="resize.js"></script>
21 <script type="text/javascript" src="navtreedata.js"></script>
22 <script type="text/javascript" src="navtree.js"></script>
23 <link href="search/search.css" rel="stylesheet" type="text/css"/>
24 <script type="text/javascript" src="search/searchdata.js"></script>
25 <script type="text/javascript" src="search/search.js"></script>
26 <script type="text/javascript">
27 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
28 $(document).ready(function() { init_search(); });
31 <script type="text/javascript" src="darkmode_toggle.js"></script>
32 <link href="extra_stylesheet.css" rel="stylesheet" type="text/css"/>
33 <link href="extra_navtree.css" rel="stylesheet" type="text/css"/>
34 <link href="extra_search.css" rel="stylesheet" type="text/css"/>
35 <link href="version.css" rel="stylesheet" type="text/css" />
36 <script type="text/javascript" src="../../version.js"></script>
39 <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
41 <table cellspacing="0" cellpadding="0">
43 <tr style="height: 55px;">
44 <td id="projectlogo" style="padding: 1.5em;"><img alt="Logo" src="cmsis_logo_white_small.png"/></td>
45 <td style="padding-left: 1em; padding-bottom: 1em;padding-top: 1em;">
46 <div id="projectname">CMSIS-RTOS2
47  <span id="projectnumber"><script type="text/javascript">
49 writeHeader.call(this);
50 writeVersionDropdown.call(this, "CMSIS-RTOS2");
55 <div id="projectbrief">Real-Time Operating System API</div>
57 <td> <div id="MSearchBox" class="MSearchBoxInactive">
59 <span id="MSearchSelect" onmouseover="return searchBox.OnSearchSelectShow()" onmouseout="return searchBox.OnSearchSelectHide()"> </span>
60 <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
61 onfocus="searchBox.OnSearchFieldFocus(true)"
62 onblur="searchBox.OnSearchFieldFocus(false)"
63 onkeyup="searchBox.OnSearchFieldChange(event)"/>
64 </span><span class="right">
65 <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.svg" alt=""/></a>
69 <!--END !PROJECT_NAME-->
74 <!-- end header part -->
75 <div id="CMSISnav" class="tabs1">
77 <script type="text/javascript">
78 writeComponentTabs.call(this);
82 <script type="text/javascript">
83 writeSubComponentTabs.call(this);
85 <!-- Generated by Doxygen 1.9.6 -->
86 <script type="text/javascript">
87 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
88 var searchBox = new SearchBox("searchBox", "search/",'.html');
92 <div id="side-nav" class="ui-resizable side-nav-resizable">
94 <div id="nav-tree-contents">
95 <div id="nav-sync" class="sync"></div>
98 <div id="splitbar" style="-moz-user-select:none;"
99 class="ui-resizable-handle">
102 <script type="text/javascript">
103 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
104 $(document).ready(function(){initNavTree('group__CMSIS__RTOS__TimerMgmt.html',''); initResizable(); });
107 <div id="doc-content">
108 <!-- window showing the filter options -->
109 <div id="MSearchSelectWindow"
110 onmouseover="return searchBox.OnSearchSelectShow()"
111 onmouseout="return searchBox.OnSearchSelectHide()"
112 onkeydown="return searchBox.OnSearchSelectKey(event)">
115 <!-- iframe showing the search results (closed by default) -->
116 <div id="MSearchResultsWindow">
117 <div id="MSearchResults">
120 <div id="SRResults"></div>
121 <div class="SRStatus" id="Loading">Loading...</div>
122 <div class="SRStatus" id="Searching">Searching...</div>
123 <div class="SRStatus" id="NoMatches">No Matches</div>
130 <div class="summary">
131 <a href="#nested-classes">Data Structures</a> |
132 <a href="#typedef-members">Typedefs</a> |
133 <a href="#enum-members">Enumerations</a> |
134 <a href="#enumval-members">Enumerator</a> |
135 <a href="#func-members">Functions</a> </div>
136 <div class="headertitle"><div class="title">Timer Management<div class="ingroups"><a class="el" href="group__CMSIS__RTOS.html">CMSIS-RTOS API v2</a></div></div></div>
138 <div class="contents">
140 <p>Create and control timer and timer callback functions.
141 <a href="#details">More...</a></p>
142 <table class="memberdecls">
143 <tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="nested-classes" name="nested-classes"></a>
144 Data Structures</h2></td></tr>
145 <tr class="memitem:structosTimerAttr__t"><td class="memItemLeft" align="right" valign="top">struct  </td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#structosTimerAttr__t">osTimerAttr_t</a></td></tr>
146 <tr class="memdesc:structosTimerAttr__t"><td class="mdescLeft"> </td><td class="mdescRight">Attributes structure for timer. <a href="group__CMSIS__RTOS__TimerMgmt.html#structosTimerAttr__t">More...</a><br /></td></tr>
147 <tr class="separator:structosTimerAttr__t"><td class="memSeparator" colspan="2"> </td></tr>
148 </table><table class="memberdecls">
149 <tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="typedef-members" name="typedef-members"></a>
150 Typedefs</h2></td></tr>
151 <tr class="memitem:gaad5409379689ee27bb0a0b56ea4a4b34"><td class="memItemLeft" align="right" valign="top">typedef void * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a></td></tr>
152 <tr class="separator:gaad5409379689ee27bb0a0b56ea4a4b34"><td class="memSeparator" colspan="2"> </td></tr>
153 <tr class="memitem:gaacf768c1ec64b020598afb985d7b30be"><td class="memItemLeft" align="right" valign="top">typedef void(* </td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaacf768c1ec64b020598afb985d7b30be">osTimerFunc_t</a>) (void *argument)</td></tr>
154 <tr class="memdesc:gaacf768c1ec64b020598afb985d7b30be"><td class="mdescLeft"> </td><td class="mdescRight">Timer callback function. <br /></td></tr>
155 <tr class="separator:gaacf768c1ec64b020598afb985d7b30be"><td class="memSeparator" colspan="2"> </td></tr>
156 </table><table class="memberdecls">
157 <tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="enum-members" name="enum-members"></a>
158 Enumerations</h2></td></tr>
159 <tr class="memitem:ga7dc24a4c2b90334427081c3da7a71915"><td class="memItemLeft" align="right" valign="top">enum  </td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#ga7dc24a4c2b90334427081c3da7a71915">osTimerType_t</a> { <br />
160   <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gga7dc24a4c2b90334427081c3da7a71915a2e0e1f31c742c84b497c4d7143357bdb">osTimerOnce</a> = 0
162   <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gga7dc24a4c2b90334427081c3da7a71915ab3463d921dc310938094745c230f2b35">osTimerPeriodic</a> = 1
165 <tr class="memdesc:ga7dc24a4c2b90334427081c3da7a71915"><td class="mdescLeft"> </td><td class="mdescRight">Timer type. <a href="group__CMSIS__RTOS__TimerMgmt.html#ga7dc24a4c2b90334427081c3da7a71915">More...</a><br /></td></tr>
166 <tr class="separator:ga7dc24a4c2b90334427081c3da7a71915"><td class="memSeparator" colspan="2"> </td></tr>
167 </table><table class="memberdecls">
168 <tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
169 Functions</h2></td></tr>
170 <tr class="memitem:gad4e7f785c5f700a509f55a3bf6a62bec"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gad4e7f785c5f700a509f55a3bf6a62bec">osTimerNew</a> (<a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaacf768c1ec64b020598afb985d7b30be">osTimerFunc_t</a> func, <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#ga7dc24a4c2b90334427081c3da7a71915">osTimerType_t</a> type, void *argument, const <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#structosTimerAttr__t">osTimerAttr_t</a> *attr)</td></tr>
171 <tr class="memdesc:gad4e7f785c5f700a509f55a3bf6a62bec"><td class="mdescLeft"> </td><td class="mdescRight">Create and Initialize a timer. <br /></td></tr>
172 <tr class="separator:gad4e7f785c5f700a509f55a3bf6a62bec"><td class="memSeparator" colspan="2"> </td></tr>
173 <tr class="memitem:ga4f82a98eee4d9ea79507e44340d3d319"><td class="memItemLeft" align="right" valign="top">const char * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#ga4f82a98eee4d9ea79507e44340d3d319">osTimerGetName</a> (<a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a> timer_id)</td></tr>
174 <tr class="memdesc:ga4f82a98eee4d9ea79507e44340d3d319"><td class="mdescLeft"> </td><td class="mdescRight">Get name of a timer. <br /></td></tr>
175 <tr class="separator:ga4f82a98eee4d9ea79507e44340d3d319"><td class="memSeparator" colspan="2"> </td></tr>
176 <tr class="memitem:gab6ee2859ea657641b7adfac599b8121d"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gab6ee2859ea657641b7adfac599b8121d">osTimerStart</a> (<a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a> timer_id, uint32_t ticks)</td></tr>
177 <tr class="memdesc:gab6ee2859ea657641b7adfac599b8121d"><td class="mdescLeft"> </td><td class="mdescRight">Start or restart a timer. <br /></td></tr>
178 <tr class="separator:gab6ee2859ea657641b7adfac599b8121d"><td class="memSeparator" colspan="2"> </td></tr>
179 <tr class="memitem:gabd7a89356da7717293eb0bc5d87b8ac9"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gabd7a89356da7717293eb0bc5d87b8ac9">osTimerStop</a> (<a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a> timer_id)</td></tr>
180 <tr class="memdesc:gabd7a89356da7717293eb0bc5d87b8ac9"><td class="mdescLeft"> </td><td class="mdescRight">Stop a timer. <br /></td></tr>
181 <tr class="separator:gabd7a89356da7717293eb0bc5d87b8ac9"><td class="memSeparator" colspan="2"> </td></tr>
182 <tr class="memitem:ga69d3589f54194022c30dd01e45ec6741"><td class="memItemLeft" align="right" valign="top">uint32_t </td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#ga69d3589f54194022c30dd01e45ec6741">osTimerIsRunning</a> (<a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a> timer_id)</td></tr>
183 <tr class="memdesc:ga69d3589f54194022c30dd01e45ec6741"><td class="mdescLeft"> </td><td class="mdescRight">Check if a timer is running. <br /></td></tr>
184 <tr class="separator:ga69d3589f54194022c30dd01e45ec6741"><td class="memSeparator" colspan="2"> </td></tr>
185 <tr class="memitem:gad0001dd74721ab461789324806db2453"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gad0001dd74721ab461789324806db2453">osTimerDelete</a> (<a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a> timer_id)</td></tr>
186 <tr class="memdesc:gad0001dd74721ab461789324806db2453"><td class="mdescLeft"> </td><td class="mdescRight">Delete a timer. <br /></td></tr>
187 <tr class="separator:gad0001dd74721ab461789324806db2453"><td class="memSeparator" colspan="2"> </td></tr>
189 <a name="details" id="details"></a><h2 class="groupheader">Description</h2>
190 <p>In addition to the <a class="el" href="group__CMSIS__RTOS__Wait.html">Generic Wait Functions</a> CMSIS-RTOS also supports virtual timer objects. These timer objects can trigger the execution of a function (not threads). When a timer expires, a callback function is executed to run associated code with the timer. Each timer can be configured as a one-shot or a periodic timer. A periodic timer repeats its operation until it is <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gad0001dd74721ab461789324806db2453">deleted</a> or <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gabd7a89356da7717293eb0bc5d87b8ac9">stopped</a>. All timers can be <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gab6ee2859ea657641b7adfac599b8121d">started, restarted</a>, or <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gabd7a89356da7717293eb0bc5d87b8ac9">stopped</a>.</p>
191 <dl class="section note"><dt>Note</dt><dd>RTX handles Timers in the thread <b>osRtxTimerThread</b>. Callback functions run under control of this thread and may use other CMSIS-RTOS API calls. The <b>osRtxTimerThread</b> is configured in timerConfig. </dd>
193 Timer management functions cannot be called from Interrupt Service Routines.</dd></dl>
194 <p>The figure below shows the behavior of a periodic timer. For one-shot timers, the timer stops after execution of the callback function.</p>
196 <img src="Timer.png" alt=""/>
197 <div class="caption">
198 Behavior of a Periodic Timer</div></div>
199 <h2><a class="anchor" id="autotoc_md3"></a>
200 Working with Timers</h2>
201 <p>The following steps are required to use a software timer:</p><ol type="1">
202 <li>Define the timers: <div class="fragment"><div class="line"><a class="code hl_typedef" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a> one_shot_id, periodic_id;</div>
203 <div class="ttc" id="agroup__CMSIS__RTOS__TimerMgmt_html_gaad5409379689ee27bb0a0b56ea4a4b34"><div class="ttname"><a href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a></div><div class="ttdeci">void * osTimerId_t</div><div class="ttdef"><b>Definition:</b> cmsis_os2.h:263</div></div>
204 </div><!-- fragment --></li>
205 <li>Define callback functions: <div class="fragment"><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> one_shot_Callback (<span class="keywordtype">void</span> *argument) {</div>
206 <div class="line"> int32_t arg = (int32_t)argument; <span class="comment">// cast back argument '0' </span></div>
207 <div class="line"> <span class="comment">// do something, i.e. set thread/event flags</span></div>
208 <div class="line">}</div>
209 <div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> periodic_Callback (<span class="keywordtype">void</span> *argument) {</div>
210 <div class="line"> int32_t arg = (int32_t)argument; <span class="comment">// cast back argument '5'</span></div>
211 <div class="line"> <span class="comment">// do something, i.e. set thread/event flags</span></div>
212 <div class="line">}</div>
213 </div><!-- fragment --></li>
214 <li>Instantiate and start the timers: <div class="fragment"><div class="line"><span class="comment">// creates a one-shot timer:</span></div>
215 <div class="line">one_shot_id = <a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gad4e7f785c5f700a509f55a3bf6a62bec">osTimerNew</a>(one_shot_Callback, <a class="code hl_enumvalue" href="group__CMSIS__RTOS__TimerMgmt.html#gga7dc24a4c2b90334427081c3da7a71915a2e0e1f31c742c84b497c4d7143357bdb">osTimerOnce</a>, (<span class="keywordtype">void</span> *)0, NULL); <span class="comment">// (void*)0 is passed as an argument</span></div>
216 <div class="line"> <span class="comment">// to the callback function</span></div>
217 <div class="line"><span class="comment">// creates a periodic timer:</span></div>
218 <div class="line">periodic_id = <a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gad4e7f785c5f700a509f55a3bf6a62bec">osTimerNew</a>(periodic_Callback, <a class="code hl_enumvalue" href="group__CMSIS__RTOS__TimerMgmt.html#gga7dc24a4c2b90334427081c3da7a71915ab3463d921dc310938094745c230f2b35">osTimerPeriodic</a>, (<span class="keywordtype">void</span> *)5, NULL); <span class="comment">// (void*)5 is passed as an argument</span></div>
219 <div class="line"> <span class="comment">// to the callback function</span></div>
220 <div class="line"><a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gab6ee2859ea657641b7adfac599b8121d">osTimerStart</a>(one_shot_id, 500U);</div>
221 <div class="line"><a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gab6ee2859ea657641b7adfac599b8121d">osTimerStart</a>(periodic_id, 1500U);</div>
222 <div class="line"> </div>
223 <div class="line"><span class="comment">// start the one-shot timer again after it has triggered the first time:</span></div>
224 <div class="line"><a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gab6ee2859ea657641b7adfac599b8121d">osTimerStart</a>(one_shot_id, 500U);</div>
225 <div class="line"> </div>
226 <div class="line"><span class="comment">// when timers are not needed any longer free the resources:</span></div>
227 <div class="line"><a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gad0001dd74721ab461789324806db2453">osTimerDelete</a>(one_shot_id);</div>
228 <div class="line"><a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gad0001dd74721ab461789324806db2453">osTimerDelete</a>(periodic_id);</div>
229 <div class="ttc" id="agroup__CMSIS__RTOS__TimerMgmt_html_gab6ee2859ea657641b7adfac599b8121d"><div class="ttname"><a href="group__CMSIS__RTOS__TimerMgmt.html#gab6ee2859ea657641b7adfac599b8121d">osTimerStart</a></div><div class="ttdeci">osStatus_t osTimerStart(osTimerId_t timer_id, uint32_t ticks)</div><div class="ttdoc">Start or restart a timer.</div></div>
230 <div class="ttc" id="agroup__CMSIS__RTOS__TimerMgmt_html_gad0001dd74721ab461789324806db2453"><div class="ttname"><a href="group__CMSIS__RTOS__TimerMgmt.html#gad0001dd74721ab461789324806db2453">osTimerDelete</a></div><div class="ttdeci">osStatus_t osTimerDelete(osTimerId_t timer_id)</div><div class="ttdoc">Delete a timer.</div></div>
231 <div class="ttc" id="agroup__CMSIS__RTOS__TimerMgmt_html_gad4e7f785c5f700a509f55a3bf6a62bec"><div class="ttname"><a href="group__CMSIS__RTOS__TimerMgmt.html#gad4e7f785c5f700a509f55a3bf6a62bec">osTimerNew</a></div><div class="ttdeci">osTimerId_t osTimerNew(osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr)</div><div class="ttdoc">Create and Initialize a timer.</div></div>
232 <div class="ttc" id="agroup__CMSIS__RTOS__TimerMgmt_html_gga7dc24a4c2b90334427081c3da7a71915a2e0e1f31c742c84b497c4d7143357bdb"><div class="ttname"><a href="group__CMSIS__RTOS__TimerMgmt.html#gga7dc24a4c2b90334427081c3da7a71915a2e0e1f31c742c84b497c4d7143357bdb">osTimerOnce</a></div><div class="ttdeci">@ osTimerOnce</div><div class="ttdoc">One-shot timer.</div><div class="ttdef"><b>Definition:</b> cmsis_os2.h:188</div></div>
233 <div class="ttc" id="agroup__CMSIS__RTOS__TimerMgmt_html_gga7dc24a4c2b90334427081c3da7a71915ab3463d921dc310938094745c230f2b35"><div class="ttname"><a href="group__CMSIS__RTOS__TimerMgmt.html#gga7dc24a4c2b90334427081c3da7a71915ab3463d921dc310938094745c230f2b35">osTimerPeriodic</a></div><div class="ttdeci">@ osTimerPeriodic</div><div class="ttdoc">Repeating timer.</div><div class="ttdef"><b>Definition:</b> cmsis_os2.h:189</div></div>
234 </div><!-- fragment --> </li>
236 <hr/><h2 class="groupheader">Data Structure Documentation</h2>
237 <a name="structosTimerAttr__t" id="structosTimerAttr__t"></a>
238 <h2 class="memtitle"><span class="permalink"><a href="#structosTimerAttr__t">◆ </a></span>osTimerAttr_t</h2>
240 <div class="memitem">
241 <div class="memproto">
242 <table class="memname">
244 <td class="memname">struct osTimerAttr_t</td>
247 </div><div class="memdoc">
248 <div class="textblock"><p>Specifies the following attributes for the <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gad4e7f785c5f700a509f55a3bf6a62bec">osTimerNew</a> function. </p>
249 </div><table class="fieldtable">
250 <tr><th colspan="3">Data Fields</th></tr>
251 <tr><td class="fieldtype">
252 <a id="ab74e6bf80237ddc4109968cedc58c151" name="ab74e6bf80237ddc4109968cedc58c151"></a>const char *</td>
253 <td class="fieldname">
255 <td class="fielddoc">
256 name of the timer <p>Pointer to a constant string with a human readable name (displayed during debugging) of the timer object.</p>
257 <p>Default: <span class="XML-Token">NULL</span> no name specified. </p>
259 <tr><td class="fieldtype">
260 <a id="a6e93b49cb79c12f768d72580c7731f30" name="a6e93b49cb79c12f768d72580c7731f30"></a>uint32_t</td>
261 <td class="fieldname">
263 <td class="fielddoc">
264 attribute bits <p>Reserved for future use (must be set to '0' for future compatibility). </p>
266 <tr><td class="fieldtype">
267 <a id="a1e100dc33d403841ed3c344e3397868e" name="a1e100dc33d403841ed3c344e3397868e"></a>void *</td>
268 <td class="fieldname">
270 <td class="fielddoc">
271 memory for control block <p>Pointer to a memory for the timer control block object. Refer to StaticObjectMemory for more information.</p>
272 <p>Default: <span class="XML-Token">NULL</span> to use <a class="el" href="group__CMSIS__RTOS__MemoryMgmt.html#CMSIS_RTOS_MemoryMgmt_Automatic">Automatic Dynamic Allocation</a> for the timer control block. </p>
274 <tr><td class="fieldtype">
275 <a id="aa55a4335d12dc2785dc00fdc292d1159" name="aa55a4335d12dc2785dc00fdc292d1159"></a>uint32_t</td>
276 <td class="fieldname">
278 <td class="fielddoc">
279 size of provided memory for control block <p>The size (in bytes) of memory block passed with <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#a1e100dc33d403841ed3c344e3397868e">cb_mem</a>. For RTX, the minimum value is defined with osRtxTimerCbSize (higher values are permitted).</p>
280 <p>Default: <span class="XML-Token">0</span> as the default is no memory provided with <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#a1e100dc33d403841ed3c344e3397868e">cb_mem</a>. </p>
286 <h2 class="groupheader">Typedef Documentation</h2>
287 <a id="gaad5409379689ee27bb0a0b56ea4a4b34" name="gaad5409379689ee27bb0a0b56ea4a4b34"></a>
288 <h2 class="memtitle"><span class="permalink"><a href="#gaad5409379689ee27bb0a0b56ea4a4b34">◆ </a></span>osTimerId_t</h2>
290 <div class="memitem">
291 <div class="memproto">
292 <table class="memname">
294 <td class="memname"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a></td>
297 </div><div class="memdoc">
298 <p>Timer ID identifies the timer.</p>
299 <p>Instances of this type hold a reference to a timer object. <br />
301 <li><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gad4e7f785c5f700a509f55a3bf6a62bec">osTimerNew</a> </li>
306 <a id="gaacf768c1ec64b020598afb985d7b30be" name="gaacf768c1ec64b020598afb985d7b30be"></a>
307 <h2 class="memtitle"><span class="permalink"><a href="#gaacf768c1ec64b020598afb985d7b30be">◆ </a></span>osTimerFunc_t</h2>
309 <div class="memitem">
310 <div class="memproto">
311 <table class="memname">
313 <td class="memname">void(* osTimerFunc_t)(void *argument)</td>
316 </div><div class="memdoc">
317 <p>The timer callback function is called every time the timer elapses.</p>
318 <p>The callback might be executed either in a dedicated timer thread or in interrupt context. Thus it is recommended to only use ISR callable functions from the timer callback.</p>
319 <dl class="params"><dt>Parameters</dt><dd>
320 <table class="params">
321 <tr><td class="paramdir">[in]</td><td class="paramname">argument</td><td>The argument provided to <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gad4e7f785c5f700a509f55a3bf6a62bec">osTimerNew</a>. </td></tr>
328 <h2 class="groupheader">Enumeration Type Documentation</h2>
329 <a id="ga7dc24a4c2b90334427081c3da7a71915" name="ga7dc24a4c2b90334427081c3da7a71915"></a>
330 <h2 class="memtitle"><span class="permalink"><a href="#ga7dc24a4c2b90334427081c3da7a71915">◆ </a></span>osTimerType_t</h2>
332 <div class="memitem">
333 <div class="memproto">
334 <table class="memname">
336 <td class="memname">enum <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#ga7dc24a4c2b90334427081c3da7a71915">osTimerType_t</a></td>
339 </div><div class="memdoc">
340 <p>The <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#ga7dc24a4c2b90334427081c3da7a71915">osTimerType_t</a> specifies the a repeating (periodic) or one-shot timer for the function <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gad4e7f785c5f700a509f55a3bf6a62bec">osTimerNew</a>. </p>
341 <table class="fieldtable">
342 <tr><th colspan="2">Enumerator</th></tr><tr><td class="fieldname"><a id="gga7dc24a4c2b90334427081c3da7a71915a2e0e1f31c742c84b497c4d7143357bdb" name="gga7dc24a4c2b90334427081c3da7a71915a2e0e1f31c742c84b497c4d7143357bdb"></a>osTimerOnce </td><td class="fielddoc"><p>One-shot timer. </p>
343 <p>The timer is not automatically restarted once it has elapsed. It can be restarted manually using <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gab6ee2859ea657641b7adfac599b8121d">osTimerStart</a> as needed. </p>
345 <tr><td class="fieldname"><a id="gga7dc24a4c2b90334427081c3da7a71915ab3463d921dc310938094745c230f2b35" name="gga7dc24a4c2b90334427081c3da7a71915ab3463d921dc310938094745c230f2b35"></a>osTimerPeriodic </td><td class="fielddoc"><p>Repeating timer. </p>
346 <p>The timer repeats automatically and triggers the callback continuously while running, see <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gab6ee2859ea657641b7adfac599b8121d">osTimerStart</a> and <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gabd7a89356da7717293eb0bc5d87b8ac9">osTimerStop</a>. </p>
352 <h2 class="groupheader">Function Documentation</h2>
353 <a id="gad4e7f785c5f700a509f55a3bf6a62bec" name="gad4e7f785c5f700a509f55a3bf6a62bec"></a>
354 <h2 class="memtitle"><span class="permalink"><a href="#gad4e7f785c5f700a509f55a3bf6a62bec">◆ </a></span>osTimerNew()</h2>
356 <div class="memitem">
357 <div class="memproto">
358 <table class="memname">
360 <td class="memname"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a> osTimerNew </td>
362 <td class="paramtype"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaacf768c1ec64b020598afb985d7b30be">osTimerFunc_t</a> </td>
363 <td class="paramname"><em>func</em>, </td>
366 <td class="paramkey"></td>
368 <td class="paramtype"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#ga7dc24a4c2b90334427081c3da7a71915">osTimerType_t</a> </td>
369 <td class="paramname"><em>type</em>, </td>
372 <td class="paramkey"></td>
374 <td class="paramtype">void * </td>
375 <td class="paramname"><em>argument</em>, </td>
378 <td class="paramkey"></td>
380 <td class="paramtype">const <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#structosTimerAttr__t">osTimerAttr_t</a> * </td>
381 <td class="paramname"><em>attr</em> </td>
389 </div><div class="memdoc">
390 <dl class="params"><dt>Parameters</dt><dd>
391 <table class="params">
392 <tr><td class="paramdir">[in]</td><td class="paramname">func</td><td>function pointer to callback function. </td></tr>
393 <tr><td class="paramdir">[in]</td><td class="paramname">type</td><td><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gga7dc24a4c2b90334427081c3da7a71915a2e0e1f31c742c84b497c4d7143357bdb">osTimerOnce</a> for one-shot or <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gga7dc24a4c2b90334427081c3da7a71915ab3463d921dc310938094745c230f2b35">osTimerPeriodic</a> for periodic behavior. </td></tr>
394 <tr><td class="paramdir">[in]</td><td class="paramname">argument</td><td>argument to the timer callback function. </td></tr>
395 <tr><td class="paramdir">[in]</td><td class="paramname">attr</td><td>timer attributes; NULL: default values. </td></tr>
399 <dl class="section return"><dt>Returns</dt><dd>timer ID for reference by other functions or NULL in case of error.</dd></dl>
400 <p>The function <b>osTimerNew</b> creates an one-shot or periodic timer and associates it with a callback function with <em>argument</em>. The timer is in stopped state until it is started with <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gab6ee2859ea657641b7adfac599b8121d">osTimerStart</a>. The function can be safely called before the RTOS is started (call to <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga9ae2cc00f0d89d7b6a307bba942b5221">osKernelStart</a>), but not before it is initialized (call to <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#gae818f6611d25ba3140bede410a52d659">osKernelInitialize</a>).</p>
401 <p>The function <b>osTimerNew</b> returns the pointer to the timer object identifier or <span class="XML-Token">NULL</span> in case of an error.</p>
402 <dl class="section note"><dt>Note</dt><dd>This function <b>cannot</b> be called from Interrupt Service Routines.</dd></dl>
403 <p><b>Code Example</b> </p><div class="fragment"><div class="line"><span class="preprocessor">#include "<a class="code" href="cmsis__os2_8h.html">cmsis_os2.h</a>"</span></div>
404 <div class="line"> </div>
405 <div class="line"><span class="keywordtype">void</span> Timer1_Callback (<span class="keywordtype">void</span> *arg); <span class="comment">// prototypes for timer callback function</span></div>
406 <div class="line"><span class="keywordtype">void</span> Timer2_Callback (<span class="keywordtype">void</span> *arg); <span class="comment">// prototypes for timer callback function</span></div>
407 <div class="line"> </div>
408 <div class="line">uint32_t exec1; <span class="comment">// argument for the timer call back function</span></div>
409 <div class="line">uint32_t exec2; <span class="comment">// argument for the timer call back function</span></div>
410 <div class="line"> </div>
411 <div class="line"><span class="keywordtype">void</span> TimerCreate_example (<span class="keywordtype">void</span>) {</div>
412 <div class="line"> <a class="code hl_typedef" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a> id1; <span class="comment">// timer id</span></div>
413 <div class="line"> <a class="code hl_typedef" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a> id2; <span class="comment">// timer id</span></div>
414 <div class="line"> </div>
415 <div class="line"> <span class="comment">// Create one-shoot timer</span></div>
416 <div class="line"> exec1 = 1U;</div>
417 <div class="line"> id1 = <a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gad4e7f785c5f700a509f55a3bf6a62bec">osTimerNew</a>(Timer1_Callback, <a class="code hl_enumvalue" href="group__CMSIS__RTOS__TimerMgmt.html#gga7dc24a4c2b90334427081c3da7a71915a2e0e1f31c742c84b497c4d7143357bdb">osTimerOnce</a>, &exec1, NULL);</div>
418 <div class="line"> <span class="keywordflow">if</span> (id1 != NULL) {</div>
419 <div class="line"> <span class="comment">// One-shoot timer created</span></div>
420 <div class="line"> }</div>
421 <div class="line"> </div>
422 <div class="line"> <span class="comment">// Create periodic timer</span></div>
423 <div class="line"> exec2 = 2U;</div>
424 <div class="line"> id2 = <a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gad4e7f785c5f700a509f55a3bf6a62bec">osTimerNew</a>(Timer2_Callback, <a class="code hl_enumvalue" href="group__CMSIS__RTOS__TimerMgmt.html#gga7dc24a4c2b90334427081c3da7a71915ab3463d921dc310938094745c230f2b35">osTimerPeriodic</a>, &exec2, NULL);</div>
425 <div class="line"> <span class="keywordflow">if</span> (id2 != NULL) {</div>
426 <div class="line"> <span class="comment">// Periodic timer created</span></div>
427 <div class="line"> }</div>
428 <div class="line"> :</div>
429 <div class="line">}</div>
430 <div class="ttc" id="acmsis__os2_8h_html"><div class="ttname"><a href="cmsis__os2_8h.html">cmsis_os2.h</a></div></div>
431 </div><!-- fragment -->
434 <a id="ga4f82a98eee4d9ea79507e44340d3d319" name="ga4f82a98eee4d9ea79507e44340d3d319"></a>
435 <h2 class="memtitle"><span class="permalink"><a href="#ga4f82a98eee4d9ea79507e44340d3d319">◆ </a></span>osTimerGetName()</h2>
437 <div class="memitem">
438 <div class="memproto">
439 <table class="memname">
441 <td class="memname">*const char * osTimerGetName </td>
443 <td class="paramtype"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a> </td>
444 <td class="paramname"><em>timer_id</em></td><td>)</td>
448 </div><div class="memdoc">
449 <dl class="params"><dt>Parameters</dt><dd>
450 <table class="params">
451 <tr><td class="paramdir">[in]</td><td class="paramname">timer_id</td><td>timer ID obtained by <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gad4e7f785c5f700a509f55a3bf6a62bec">osTimerNew</a>. </td></tr>
455 <dl class="section return"><dt>Returns</dt><dd>name as null-terminated string.</dd></dl>
456 <p>The function <b>osTimerGetName</b> returns the pointer to the name string of the timer identified by parameter <em>timer_id</em> or <span class="XML-Token">NULL</span> in case of an error.</p>
457 <dl class="section note"><dt>Note</dt><dd>This function may be called from Interrupt Service Routines. </dd></dl>
461 <a id="gab6ee2859ea657641b7adfac599b8121d" name="gab6ee2859ea657641b7adfac599b8121d"></a>
462 <h2 class="memtitle"><span class="permalink"><a href="#gab6ee2859ea657641b7adfac599b8121d">◆ </a></span>osTimerStart()</h2>
464 <div class="memitem">
465 <div class="memproto">
466 <table class="memname">
468 <td class="memname"><a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> osTimerStart </td>
470 <td class="paramtype"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a> </td>
471 <td class="paramname"><em>timer_id</em>, </td>
474 <td class="paramkey"></td>
476 <td class="paramtype">uint32_t </td>
477 <td class="paramname"><em>ticks</em> </td>
485 </div><div class="memdoc">
486 <dl class="params"><dt>Parameters</dt><dd>
487 <table class="params">
488 <tr><td class="paramdir">[in]</td><td class="paramname">timer_id</td><td>timer ID obtained by <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gad4e7f785c5f700a509f55a3bf6a62bec">osTimerNew</a>. </td></tr>
489 <tr><td class="paramdir">[in]</td><td class="paramname">ticks</td><td>time ticks value of the timer. </td></tr>
493 <dl class="section return"><dt>Returns</dt><dd>status code that indicates the execution status of the function.</dd></dl>
494 <p>The function <b>osTimerStart</b> starts or restarts a timer specified by the parameter <em>timer_id</em>. The parameter <em>ticks</em> specifies the value of the timer in time ticks.</p>
495 <p>Possible <a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> return values:</p><ul>
496 <li><em>osOK:</em> the specified timer has been started or restarted.</li>
497 <li><em>osErrorISR:</em> <b>osTimerStart</b> cannot be called from interrupt service routines.</li>
498 <li><em>osErrorParameter:</em> parameter <em>timer_id</em> is either <span class="XML-Token">NULL</span> or invalid or <em>ticks</em> is incorrect.</li>
499 <li><em>osErrorResource:</em> the timer is in an invalid state.</li>
500 <li><em>osErrorSafetyClass:</em> the calling thread safety class is lower than the safety class of the specified timer.</li>
502 <dl class="section note"><dt>Note</dt><dd>This function <b>cannot</b> be called from Interrupt Service Routines.</dd></dl>
503 <p><b>Code Example</b> </p><div class="fragment"><div class="line"><span class="preprocessor">#include "<a class="code" href="cmsis__os2_8h.html">cmsis_os2.h</a>"</span></div>
504 <div class="line"> </div>
505 <div class="line"><span class="keywordtype">void</span> Timer_Callback (<span class="keywordtype">void</span> *arg) { <span class="comment">// timer callback function</span></div>
506 <div class="line"> <span class="comment">// arg contains &exec</span></div>
507 <div class="line"> <span class="comment">// called every second after osTimerStart</span></div>
508 <div class="line">}</div>
509 <div class="line"> </div>
510 <div class="line">uint32_t exec; <span class="comment">// argument for the timer call back function</span></div>
511 <div class="line"> </div>
512 <div class="line"><span class="keywordtype">void</span> TimerStart_example (<span class="keywordtype">void</span>) {</div>
513 <div class="line"> <a class="code hl_typedef" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a> id; <span class="comment">// timer id</span></div>
514 <div class="line"> uint32_t timerDelay; <span class="comment">// timer value</span></div>
515 <div class="line"> <a class="code hl_enumeration" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> status; <span class="comment">// function return status</span></div>
516 <div class="line"> </div>
517 <div class="line"> <span class="comment">// Create periodic timer</span></div>
518 <div class="line"> exec = 1U;</div>
519 <div class="line"> <span class="keywordtype">id</span> = <a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gad4e7f785c5f700a509f55a3bf6a62bec">osTimerNew</a>(Timer_Callback, <a class="code hl_enumvalue" href="group__CMSIS__RTOS__TimerMgmt.html#gga7dc24a4c2b90334427081c3da7a71915ab3463d921dc310938094745c230f2b35">osTimerPeriodic</a>, &exec, NULL);</div>
520 <div class="line"> <span class="keywordflow">if</span> (<span class="keywordtype">id</span> != NULL) {</div>
521 <div class="line"> timerDelay = 1000U;</div>
522 <div class="line"> status = <a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gab6ee2859ea657641b7adfac599b8121d">osTimerStart</a>(<span class="keywordtype">id</span>, timerDelay); <span class="comment">// start timer</span></div>
523 <div class="line"> <span class="keywordflow">if</span> (status != <a class="code hl_enumvalue" href="cmsis__os2_8h.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813ea9e1c9e2550bb4de8969a935acffc968f">osOK</a>) {</div>
524 <div class="line"> <span class="comment">// Timer could not be started</span></div>
525 <div class="line"> }</div>
526 <div class="line"> }</div>
527 <div class="line"> ;</div>
528 <div class="line">}</div>
529 <div class="ttc" id="acmsis__os2_8h_html_ga6c0dbe6069e4e7f47bb4cd32ae2b813ea9e1c9e2550bb4de8969a935acffc968f"><div class="ttname"><a href="cmsis__os2_8h.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813ea9e1c9e2550bb4de8969a935acffc968f">osOK</a></div><div class="ttdeci">@ osOK</div><div class="ttdoc">Operation completed successfully.</div><div class="ttdef"><b>Definition:</b> cmsis_os2.h:247</div></div>
530 <div class="ttc" id="agroup__CMSIS__RTOS__Definitions_html_ga6c0dbe6069e4e7f47bb4cd32ae2b813e"><div class="ttname"><a href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a></div><div class="ttdeci">osStatus_t</div><div class="ttdoc">Status code values returned by CMSIS-RTOS functions.</div><div class="ttdef"><b>Definition:</b> cmsis_os2.h:246</div></div>
531 </div><!-- fragment -->
534 <a id="gabd7a89356da7717293eb0bc5d87b8ac9" name="gabd7a89356da7717293eb0bc5d87b8ac9"></a>
535 <h2 class="memtitle"><span class="permalink"><a href="#gabd7a89356da7717293eb0bc5d87b8ac9">◆ </a></span>osTimerStop()</h2>
537 <div class="memitem">
538 <div class="memproto">
539 <table class="memname">
541 <td class="memname"><a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> osTimerStop </td>
543 <td class="paramtype"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a> </td>
544 <td class="paramname"><em>timer_id</em></td><td>)</td>
548 </div><div class="memdoc">
549 <dl class="params"><dt>Parameters</dt><dd>
550 <table class="params">
551 <tr><td class="paramdir">[in]</td><td class="paramname">timer_id</td><td>timer ID obtained by <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gad4e7f785c5f700a509f55a3bf6a62bec">osTimerNew</a>. </td></tr>
555 <dl class="section return"><dt>Returns</dt><dd>status code that indicates the execution status of the function.</dd></dl>
556 <p>The function <b>osTimerStop</b> stops a timer specified by the parameter <em>timer_id</em>.</p>
557 <p>Possible <a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> return values:</p><ul>
558 <li><em>osOK:</em> the specified timer has been stopped.</li>
559 <li><em>osErrorISR:</em> <b>osTimerStop</b> cannot be called from interrupt service routines.</li>
560 <li><em>osErrorParameter:</em> parameter <em>timer_id</em> is either <span class="XML-Token">NULL</span> or invalid.</li>
561 <li><em>osErrorResource:</em> the timer is not running (you can only stop a running timer).</li>
562 <li><em>osErrorSafetyClass:</em> the calling thread safety class is lower than the safety class of the specified timer.</li>
564 <dl class="section note"><dt>Note</dt><dd>This function <b>cannot</b> be called from Interrupt Service Routines.</dd></dl>
565 <p><b>Code Example</b> </p><div class="fragment"><div class="line"><span class="preprocessor">#include "<a class="code" href="cmsis__os2_8h.html">cmsis_os2.h</a>"</span></div>
566 <div class="line"> </div>
567 <div class="line"><span class="keywordtype">void</span> Timer_Callback (<span class="keywordtype">void</span> *arg); <span class="comment">// prototype for timer callback function</span></div>
568 <div class="line"> </div>
569 <div class="line">uint32_t exec; <span class="comment">// argument for the timer call back function</span></div>
570 <div class="line"> </div>
571 <div class="line"><span class="keywordtype">void</span> TimerStop_example (<span class="keywordtype">void</span>) {</div>
572 <div class="line"> <a class="code hl_typedef" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a> id; <span class="comment">// timer id</span></div>
573 <div class="line"> <a class="code hl_enumeration" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> status; <span class="comment">// function return status</span></div>
574 <div class="line"> </div>
575 <div class="line"> <span class="comment">// Create periodic timer</span></div>
576 <div class="line"> exec = 1U;</div>
577 <div class="line"> <span class="keywordtype">id</span> = <a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gad4e7f785c5f700a509f55a3bf6a62bec">osTimerNew</a>(Timer_Callback, <a class="code hl_enumvalue" href="group__CMSIS__RTOS__TimerMgmt.html#gga7dc24a4c2b90334427081c3da7a71915ab3463d921dc310938094745c230f2b35">osTimerPeriodic</a>, &exec, NULL);</div>
578 <div class="line"> <a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gab6ee2859ea657641b7adfac599b8121d">osTimerStart</a>(<span class="keywordtype">id</span>, 1000U); <span class="comment">// start timer</span></div>
579 <div class="line"> :</div>
580 <div class="line"> status = <a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gabd7a89356da7717293eb0bc5d87b8ac9">osTimerStop</a>(<span class="keywordtype">id</span>); <span class="comment">// stop timer</span></div>
581 <div class="line"> <span class="keywordflow">if</span> (status != <a class="code hl_enumvalue" href="cmsis__os2_8h.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813ea9e1c9e2550bb4de8969a935acffc968f">osOK</a>) {</div>
582 <div class="line"> <span class="comment">// Timer could not be stopped</span></div>
583 <div class="line"> }</div>
584 <div class="line"> ;</div>
585 <div class="line"> <a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gab6ee2859ea657641b7adfac599b8121d">osTimerStart</a>(<span class="keywordtype">id</span>, 1000U); <span class="comment">// start timer again</span></div>
586 <div class="line"> ;</div>
587 <div class="line">}</div>
588 <div class="ttc" id="agroup__CMSIS__RTOS__TimerMgmt_html_gabd7a89356da7717293eb0bc5d87b8ac9"><div class="ttname"><a href="group__CMSIS__RTOS__TimerMgmt.html#gabd7a89356da7717293eb0bc5d87b8ac9">osTimerStop</a></div><div class="ttdeci">osStatus_t osTimerStop(osTimerId_t timer_id)</div><div class="ttdoc">Stop a timer.</div></div>
589 </div><!-- fragment -->
592 <a id="ga69d3589f54194022c30dd01e45ec6741" name="ga69d3589f54194022c30dd01e45ec6741"></a>
593 <h2 class="memtitle"><span class="permalink"><a href="#ga69d3589f54194022c30dd01e45ec6741">◆ </a></span>osTimerIsRunning()</h2>
595 <div class="memitem">
596 <div class="memproto">
597 <table class="memname">
599 <td class="memname">uint32_t osTimerIsRunning </td>
601 <td class="paramtype"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a> </td>
602 <td class="paramname"><em>timer_id</em></td><td>)</td>
606 </div><div class="memdoc">
607 <dl class="params"><dt>Parameters</dt><dd>
608 <table class="params">
609 <tr><td class="paramdir">[in]</td><td class="paramname">timer_id</td><td>timer ID obtained by <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gad4e7f785c5f700a509f55a3bf6a62bec">osTimerNew</a>. </td></tr>
613 <dl class="section return"><dt>Returns</dt><dd>0 not running, 1 running.</dd></dl>
614 <p>The function <b>osTimerIsRunning</b> checks whether a timer specified by parameter <em>timer_id</em> is running. It returns <span class="XML-Token">1</span> if the timer is running and <span class="XML-Token">0</span> if the timer is stopped or an error occurred.</p>
615 <dl class="section note"><dt>Note</dt><dd>This function <b>cannot</b> be called from Interrupt Service Routines. </dd></dl>
619 <a id="gad0001dd74721ab461789324806db2453" name="gad0001dd74721ab461789324806db2453"></a>
620 <h2 class="memtitle"><span class="permalink"><a href="#gad0001dd74721ab461789324806db2453">◆ </a></span>osTimerDelete()</h2>
622 <div class="memitem">
623 <div class="memproto">
624 <table class="memname">
626 <td class="memname"><a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> osTimerDelete </td>
628 <td class="paramtype"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a> </td>
629 <td class="paramname"><em>timer_id</em></td><td>)</td>
633 </div><div class="memdoc">
634 <dl class="params"><dt>Parameters</dt><dd>
635 <table class="params">
636 <tr><td class="paramdir">[in]</td><td class="paramname">timer_id</td><td>timer ID obtained by <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gad4e7f785c5f700a509f55a3bf6a62bec">osTimerNew</a>. </td></tr>
640 <dl class="section return"><dt>Returns</dt><dd>status code that indicates the execution status of the function.</dd></dl>
641 <p>The function <b>osTimerDelete</b> deletes the timer specified by parameter <em>timer_id</em>.</p>
642 <p>Possible <a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> return values:</p><ul>
643 <li><em>osOK:</em> the specified timer has been deleted.</li>
644 <li><em>osErrorISR:</em> <b>osTimerDelete</b> cannot be called from interrupt service routines.</li>
645 <li><em>osErrorParameter:</em> parameter <em>timer_id</em> is either <span class="XML-Token">NULL</span> or invalid.</li>
646 <li><em>osErrorResource:</em> the timer is in an invalid state.</li>
647 <li><em>osErrorSafetyClass:</em> the calling thread safety class is lower than the safety class of the specified timer.</li>
649 <dl class="section note"><dt>Note</dt><dd>This function <b>cannot</b> be called from Interrupt Service Routines.</dd></dl>
650 <p><b>Code Example</b> </p><div class="fragment"><div class="line"><span class="preprocessor">#include "<a class="code" href="cmsis__os2_8h.html">cmsis_os2.h</a>"</span></div>
651 <div class="line"> </div>
652 <div class="line"><span class="keywordtype">void</span> Timer_Callback (<span class="keywordtype">void</span> *arg); <span class="comment">// prototype for timer callback function</span></div>
653 <div class="line"> </div>
654 <div class="line">uint32_t exec; <span class="comment">// argument for the timer call back function</span></div>
655 <div class="line"> </div>
656 <div class="line"><span class="keywordtype">void</span> TimerDelete_example (<span class="keywordtype">void</span>) {</div>
657 <div class="line"> <a class="code hl_typedef" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a> id; <span class="comment">// timer id</span></div>
658 <div class="line"> <a class="code hl_enumeration" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> status; <span class="comment">// function return status </span></div>
659 <div class="line"> </div>
660 <div class="line"> <span class="comment">// Create periodic timer</span></div>
661 <div class="line"> exec = 1U;</div>
662 <div class="line"> <span class="keywordtype">id</span> = <a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gad4e7f785c5f700a509f55a3bf6a62bec">osTimerNew</a>(Timer_Callback, <a class="code hl_enumvalue" href="group__CMSIS__RTOS__TimerMgmt.html#gga7dc24a4c2b90334427081c3da7a71915ab3463d921dc310938094745c230f2b35">osTimerPeriodic</a>, &exec, NULL);</div>
663 <div class="line"> <a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gab6ee2859ea657641b7adfac599b8121d">osTimerStart</a>(<span class="keywordtype">id</span>, 1000U); <span class="comment">// start timer</span></div>
664 <div class="line"> ;</div>
665 <div class="line"> status = <a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gad0001dd74721ab461789324806db2453">osTimerDelete</a>(<span class="keywordtype">id</span>); <span class="comment">// stop and delete timer</span></div>
666 <div class="line"> <span class="keywordflow">if</span> (status != <a class="code hl_enumvalue" href="cmsis__os2_8h.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813ea9e1c9e2550bb4de8969a935acffc968f">osOK</a>) {</div>
667 <div class="line"> <span class="comment">// Timer could not be deleted</span></div>
668 <div class="line"> } </div>
669 <div class="line"> ;</div>
670 <div class="line">}</div>
671 </div><!-- fragment -->
674 </div><!-- contents -->
675 </div><!-- doc-content -->
676 <!-- start footer part -->
677 <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
680 <script type="text/javascript">
682 writeFooter.call(this);