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 <script type="text/javascript" src="jquery.js"></script>
11 <script type="text/javascript" src="dynsections.js"></script>
12 <script type="text/javascript" src="tabs.js"></script>
13 <script type="text/javascript" src="footer.js"></script>
14 <script type="text/javascript" src="navtree.js"></script>
15 <link href="navtree.css" rel="stylesheet" type="text/css"/>
16 <script type="text/javascript" src="resize.js"></script>
17 <script type="text/javascript" src="navtreedata.js"></script>
18 <script type="text/javascript" src="navtree.js"></script>
19 <link href="search/search.css" rel="stylesheet" type="text/css"/>
20 <script type="text/javascript" src="search/searchdata.js"></script>
21 <script type="text/javascript" src="search/search.js"></script>
22 <script type="text/javascript">
23 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
24 $(document).ready(function() { init_search(); });
27 <script type="text/javascript" src="darkmode_toggle.js"></script>
28 <link href="extra_stylesheet.css" rel="stylesheet" type="text/css"/>
29 <link href="extra_navtree.css" rel="stylesheet" type="text/css"/>
30 <link href="extra_search.css" rel="stylesheet" type="text/css"/>
31 <link href="extra_tabs.css" rel="stylesheet" type="text/css"/>
32 <link href="version.css" rel="stylesheet" type="text/css"/>
33 <script type="text/javascript" src="../../version.js"></script>
36 <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
38 <table cellspacing="0" cellpadding="0">
40 <tr style="height: 55px;">
41 <td id="projectlogo" style="padding: 1.5em;"><img alt="Logo" src="cmsis_logo_white_small.png"/></td>
42 <td style="padding-left: 1em; padding-bottom: 1em;padding-top: 1em;">
43 <div id="projectname">CMSIS-RTOS2
44  <span id="projectnumber"><script type="text/javascript">
46 writeHeader.call(this);
47 writeVersionDropdown.call(this, "CMSIS-RTOS2");
52 <div id="projectbrief">Real-Time Operating System API</div>
54 <td> <div id="MSearchBox" class="MSearchBoxInactive">
56 <span id="MSearchSelect" onmouseover="return searchBox.OnSearchSelectShow()" onmouseout="return searchBox.OnSearchSelectHide()"> </span>
57 <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
58 onfocus="searchBox.OnSearchFieldFocus(true)"
59 onblur="searchBox.OnSearchFieldFocus(false)"
60 onkeyup="searchBox.OnSearchFieldChange(event)"/>
61 </span><span class="right">
62 <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.svg" alt=""/></a>
66 <!--END !PROJECT_NAME-->
71 <!-- end header part -->
72 <div id="CMSISnav" class="tabs1">
74 <script type="text/javascript">
75 writeComponentTabs.call(this);
79 <script type="text/javascript">
80 writeSubComponentTabs.call(this);
82 <!-- Generated by Doxygen 1.9.6 -->
83 <script type="text/javascript">
84 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
85 var searchBox = new SearchBox("searchBox", "search/",'.html');
89 <div id="side-nav" class="ui-resizable side-nav-resizable">
91 <div id="nav-tree-contents">
92 <div id="nav-sync" class="sync"></div>
95 <div id="splitbar" style="-moz-user-select:none;"
96 class="ui-resizable-handle">
99 <script type="text/javascript">
100 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
101 $(document).ready(function(){initNavTree('group__CMSIS__RTOS__TimerMgmt.html',''); initResizable(); });
104 <div id="doc-content">
105 <!-- window showing the filter options -->
106 <div id="MSearchSelectWindow"
107 onmouseover="return searchBox.OnSearchSelectShow()"
108 onmouseout="return searchBox.OnSearchSelectHide()"
109 onkeydown="return searchBox.OnSearchSelectKey(event)">
112 <!-- iframe showing the search results (closed by default) -->
113 <div id="MSearchResultsWindow">
114 <div id="MSearchResults">
117 <div id="SRResults"></div>
118 <div class="SRStatus" id="Loading">Loading...</div>
119 <div class="SRStatus" id="Searching">Searching...</div>
120 <div class="SRStatus" id="NoMatches">No Matches</div>
127 <div class="summary">
128 <a href="#nested-classes">Data Structures</a> |
129 <a href="#typedef-members">Typedefs</a> |
130 <a href="#enum-members">Enumerations</a> |
131 <a href="#func-members">Functions</a> |
132 <a href="#var-members">Variables</a> </div>
133 <div class="headertitle"><div class="title">Timer Management<div class="ingroups"><a class="el" href="group__CMSIS__RTOS.html">CMSIS-RTOS2 API</a></div></div></div>
135 <div class="contents">
137 <p>Create and control timer and timer callback functions.
138 <a href="#details">More...</a></p>
139 <table class="memberdecls">
140 <tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="nested-classes" name="nested-classes"></a>
141 Data Structures</h2></td></tr>
142 <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>
143 <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>
144 <tr class="separator:structosTimerAttr__t"><td class="memSeparator" colspan="2"> </td></tr>
145 </table><table class="memberdecls">
146 <tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="typedef-members" name="typedef-members"></a>
147 Typedefs</h2></td></tr>
148 <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>
149 <tr class="separator:gaad5409379689ee27bb0a0b56ea4a4b34"><td class="memSeparator" colspan="2"> </td></tr>
150 <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>
151 <tr class="memdesc:gaacf768c1ec64b020598afb985d7b30be"><td class="mdescLeft"> </td><td class="mdescRight">Timer callback function. <br /></td></tr>
152 <tr class="separator:gaacf768c1ec64b020598afb985d7b30be"><td class="memSeparator" colspan="2"> </td></tr>
153 </table><table class="memberdecls">
154 <tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="enum-members" name="enum-members"></a>
155 Enumerations</h2></td></tr>
156 <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 />
157   <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gga7dc24a4c2b90334427081c3da7a71915a2e0e1f31c742c84b497c4d7143357bdb">osTimerOnce</a> = 0
159   <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gga7dc24a4c2b90334427081c3da7a71915ab3463d921dc310938094745c230f2b35">osTimerPeriodic</a> = 1
162 <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>
163 <tr class="separator:ga7dc24a4c2b90334427081c3da7a71915"><td class="memSeparator" colspan="2"> </td></tr>
164 </table><table class="memberdecls">
165 <tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
166 Functions</h2></td></tr>
167 <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>
168 <tr class="memdesc:gad4e7f785c5f700a509f55a3bf6a62bec"><td class="mdescLeft"> </td><td class="mdescRight">Create and Initialize a timer. <br /></td></tr>
169 <tr class="separator:gad4e7f785c5f700a509f55a3bf6a62bec"><td class="memSeparator" colspan="2"> </td></tr>
170 <tr class="memitem:ga7938dde88ada1a01b60f41cf120069c0"><td class="memItemLeft" align="right" valign="top">const char * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#ga7938dde88ada1a01b60f41cf120069c0">osTimerGetName</a> (<a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a> timer_id)</td></tr>
171 <tr class="memdesc:ga7938dde88ada1a01b60f41cf120069c0"><td class="mdescLeft"> </td><td class="mdescRight">Get name of a timer. <br /></td></tr>
172 <tr class="separator:ga7938dde88ada1a01b60f41cf120069c0"><td class="memSeparator" colspan="2"> </td></tr>
173 <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>
174 <tr class="memdesc:gab6ee2859ea657641b7adfac599b8121d"><td class="mdescLeft"> </td><td class="mdescRight">Start or restart a timer. <br /></td></tr>
175 <tr class="separator:gab6ee2859ea657641b7adfac599b8121d"><td class="memSeparator" colspan="2"> </td></tr>
176 <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>
177 <tr class="memdesc:gabd7a89356da7717293eb0bc5d87b8ac9"><td class="mdescLeft"> </td><td class="mdescRight">Stop a timer. <br /></td></tr>
178 <tr class="separator:gabd7a89356da7717293eb0bc5d87b8ac9"><td class="memSeparator" colspan="2"> </td></tr>
179 <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>
180 <tr class="memdesc:ga69d3589f54194022c30dd01e45ec6741"><td class="mdescLeft"> </td><td class="mdescRight">Check if a timer is running. <br /></td></tr>
181 <tr class="separator:ga69d3589f54194022c30dd01e45ec6741"><td class="memSeparator" colspan="2"> </td></tr>
182 <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>
183 <tr class="memdesc:gad0001dd74721ab461789324806db2453"><td class="mdescLeft"> </td><td class="mdescRight">Delete a timer. <br /></td></tr>
184 <tr class="separator:gad0001dd74721ab461789324806db2453"><td class="memSeparator" colspan="2"> </td></tr>
185 </table><table class="memberdecls">
186 <tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="var-members" name="var-members"></a>
187 Variables</h2></td></tr>
188 <tr class="memitem:ga6e93b49cb79c12f768d72580c7731f30"><td class="memItemLeft" align="right" valign="top">uint32_t </td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#ga6e93b49cb79c12f768d72580c7731f30">attr_bits</a></td></tr>
189 <tr class="memdesc:ga6e93b49cb79c12f768d72580c7731f30"><td class="mdescLeft"> </td><td class="mdescRight">attribute bits <br /></td></tr>
190 <tr class="separator:ga6e93b49cb79c12f768d72580c7731f30"><td class="memSeparator" colspan="2"> </td></tr>
191 <tr class="memitem:ga1e100dc33d403841ed3c344e3397868e"><td class="memItemLeft" align="right" valign="top">void * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#ga1e100dc33d403841ed3c344e3397868e">cb_mem</a></td></tr>
192 <tr class="memdesc:ga1e100dc33d403841ed3c344e3397868e"><td class="mdescLeft"> </td><td class="mdescRight">memory for control block <br /></td></tr>
193 <tr class="separator:ga1e100dc33d403841ed3c344e3397868e"><td class="memSeparator" colspan="2"> </td></tr>
194 <tr class="memitem:gaa55a4335d12dc2785dc00fdc292d1159"><td class="memItemLeft" align="right" valign="top">uint32_t </td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaa55a4335d12dc2785dc00fdc292d1159">cb_size</a></td></tr>
195 <tr class="memdesc:gaa55a4335d12dc2785dc00fdc292d1159"><td class="mdescLeft"> </td><td class="mdescRight">size of provided memory for control block <br /></td></tr>
196 <tr class="separator:gaa55a4335d12dc2785dc00fdc292d1159"><td class="memSeparator" colspan="2"> </td></tr>
197 <tr class="memitem:gab74e6bf80237ddc4109968cedc58c151"><td class="memItemLeft" align="right" valign="top">const char * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gab74e6bf80237ddc4109968cedc58c151">name</a></td></tr>
198 <tr class="memdesc:gab74e6bf80237ddc4109968cedc58c151"><td class="mdescLeft"> </td><td class="mdescRight">name of the timer <br /></td></tr>
199 <tr class="separator:gab74e6bf80237ddc4109968cedc58c151"><td class="memSeparator" colspan="2"> </td></tr>
201 <a name="details" id="details"></a><h2 class="groupheader">Description</h2>
202 <p>Create and control timer and timer callback functions. </p>
203 <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>
204 <dl class="section note"><dt>Note</dt><dd>Timer management functions cannot be called from <a class="el" href="usingOS2.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
205 <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>
207 <img src="Timer.png" alt=""/>
208 <div class="caption">
209 Behavior of a Periodic Timer</div></div>
210 <h2><a class="anchor" id="autotoc_md4"></a>
211 Working with Timers</h2>
212 <p>The following steps are required to use a software timer:</p><ol type="1">
213 <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>
214 </div><!-- fragment --></li>
215 <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>
216 <div class="line"> int32_t arg = (int32_t)argument; <span class="comment">// cast back argument '0' </span></div>
217 <div class="line"> <span class="comment">// do something, i.e. set thread/event flags</span></div>
218 <div class="line">}</div>
219 <div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> periodic_Callback (<span class="keywordtype">void</span> *argument) {</div>
220 <div class="line"> int32_t arg = (int32_t)argument; <span class="comment">// cast back argument '5'</span></div>
221 <div class="line"> <span class="comment">// do something, i.e. set thread/event flags</span></div>
222 <div class="line">}</div>
223 </div><!-- fragment --></li>
224 <li>Instantiate and start the timers: <div class="fragment"><div class="line"><span class="comment">// creates a one-shot timer:</span></div>
225 <div class="line">one_shot_id = <a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gad4e7f785c5f700a509f55a3bf6a62bec" title="Create and Initialize a timer.">osTimerNew</a>(one_shot_Callback, <a class="code hl_enumvalue" href="group__CMSIS__RTOS__TimerMgmt.html#gga7dc24a4c2b90334427081c3da7a71915a2e0e1f31c742c84b497c4d7143357bdb" title="One-shot timer.">osTimerOnce</a>, (<span class="keywordtype">void</span> *)0, NULL); <span class="comment">// (void*)0 is passed as an argument</span></div>
226 <div class="line"> <span class="comment">// to the callback function</span></div>
227 <div class="line"><span class="comment">// creates a periodic timer:</span></div>
228 <div class="line">periodic_id = <a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gad4e7f785c5f700a509f55a3bf6a62bec" title="Create and Initialize a timer.">osTimerNew</a>(periodic_Callback, <a class="code hl_enumvalue" href="group__CMSIS__RTOS__TimerMgmt.html#gga7dc24a4c2b90334427081c3da7a71915ab3463d921dc310938094745c230f2b35" title="Repeating timer.">osTimerPeriodic</a>, (<span class="keywordtype">void</span> *)5, NULL); <span class="comment">// (void*)5 is passed as an argument</span></div>
229 <div class="line"> <span class="comment">// to the callback function</span></div>
230 <div class="line"><a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gab6ee2859ea657641b7adfac599b8121d" title="Start or restart a timer.">osTimerStart</a>(one_shot_id, 500U);</div>
231 <div class="line"><a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gab6ee2859ea657641b7adfac599b8121d" title="Start or restart a timer.">osTimerStart</a>(periodic_id, 1500U);</div>
232 <div class="line"> </div>
233 <div class="line"><span class="comment">// start the one-shot timer again after it has triggered the first time:</span></div>
234 <div class="line"><a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gab6ee2859ea657641b7adfac599b8121d" title="Start or restart a timer.">osTimerStart</a>(one_shot_id, 500U);</div>
235 <div class="line"> </div>
236 <div class="line"><span class="comment">// when timers are not needed any longer free the resources:</span></div>
237 <div class="line"><a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gad0001dd74721ab461789324806db2453" title="Delete a timer.">osTimerDelete</a>(one_shot_id);</div>
238 <div class="line"><a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gad0001dd74721ab461789324806db2453" title="Delete a timer.">osTimerDelete</a>(periodic_id);</div>
239 </div><!-- fragment --> </li>
241 <hr/><h2 class="groupheader">Data Structure Documentation</h2>
242 <a name="structosTimerAttr__t" id="structosTimerAttr__t"></a>
243 <h2 class="memtitle"><span class="permalink"><a href="#structosTimerAttr__t">◆ </a></span>osTimerAttr_t</h2>
245 <div class="memitem">
246 <div class="memproto">
247 <table class="memname">
249 <td class="memname">struct osTimerAttr_t</td>
252 </div><div class="memdoc">
253 <div class="textblock"><p>Attributes structure for timer. </p>
254 <p>Specifies the following attributes for the <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gad4e7f785c5f700a509f55a3bf6a62bec">osTimerNew</a> function. </p>
255 </div><table class="fieldtable">
256 <tr><th colspan="3">Data Fields</th></tr>
257 <tr><td class="fieldtype">
258 <a id="gab74e6bf80237ddc4109968cedc58c151" name="gab74e6bf80237ddc4109968cedc58c151"></a>const char *</td>
259 <td class="fieldname">
261 <td class="fielddoc">
262 name of the timer <p>Pointer to a constant string with a human readable name (displayed during debugging) of the timer object.</p>
263 <p>Default: <span class="XML-Token">NULL</span> no name specified. </p>
265 <tr><td class="fieldtype">
266 <a id="ga6e93b49cb79c12f768d72580c7731f30" name="ga6e93b49cb79c12f768d72580c7731f30"></a>uint32_t</td>
267 <td class="fieldname">
269 <td class="fielddoc">
270 attribute bits <p>Reserved for future use (must be set to '0' for future compatibility). </p>
272 <tr><td class="fieldtype">
273 <a id="ga1e100dc33d403841ed3c344e3397868e" name="ga1e100dc33d403841ed3c344e3397868e"></a>void *</td>
274 <td class="fieldname">
276 <td class="fielddoc">
277 memory for control block <p>Pointer to a memory for the timer control block object. Refer to <a class="el" href="usingOS2.html#CMSIS_RTOS_MemoryMgmt_Manual">Manual User-defined Allocation</a> for more information.</p>
278 <p>Default: <span class="XML-Token">NULL</span> to use <a class="el" href="usingOS2.html#CMSIS_RTOS_MemoryMgmt_Automatic">Automatic Dynamic Allocation</a> for the timer control block. </p>
280 <tr><td class="fieldtype">
281 <a id="gaa55a4335d12dc2785dc00fdc292d1159" name="gaa55a4335d12dc2785dc00fdc292d1159"></a>uint32_t</td>
282 <td class="fieldname">
284 <td class="fielddoc">
285 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#ga1e100dc33d403841ed3c344e3397868e">cb_mem</a>. Required value depends on the underlying kernel implementation.</p>
286 <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#ga1e100dc33d403841ed3c344e3397868e">cb_mem</a>. </p>
292 <h2 class="groupheader">Typedef Documentation</h2>
293 <a id="gaad5409379689ee27bb0a0b56ea4a4b34" name="gaad5409379689ee27bb0a0b56ea4a4b34"></a>
294 <h2 class="memtitle"><span class="permalink"><a href="#gaad5409379689ee27bb0a0b56ea4a4b34">◆ </a></span>osTimerId_t</h2>
296 <div class="memitem">
297 <div class="memproto">
298 <table class="memname">
300 <td class="memname"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a></td>
303 </div><div class="memdoc">
304 <p>Timer ID identifies the timer.</p>
305 <p>Instances of this type hold a reference to a timer object. <br />
307 <li><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gad4e7f785c5f700a509f55a3bf6a62bec">osTimerNew</a> </li>
312 <a id="gaacf768c1ec64b020598afb985d7b30be" name="gaacf768c1ec64b020598afb985d7b30be"></a>
313 <h2 class="memtitle"><span class="permalink"><a href="#gaacf768c1ec64b020598afb985d7b30be">◆ </a></span>osTimerFunc_t</h2>
315 <div class="memitem">
316 <div class="memproto">
317 <table class="memname">
319 <td class="memname">void(* osTimerFunc_t)(void *argument)</td>
322 </div><div class="memdoc">
324 <p>Timer callback function. </p>
325 <p>The timer callback function is called every time the timer elapses.</p>
326 <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>
327 <dl class="params"><dt>Parameters</dt><dd>
328 <table class="params">
329 <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>
336 <h2 class="groupheader">Enumeration Type Documentation</h2>
337 <a id="ga7dc24a4c2b90334427081c3da7a71915" name="ga7dc24a4c2b90334427081c3da7a71915"></a>
338 <h2 class="memtitle"><span class="permalink"><a href="#ga7dc24a4c2b90334427081c3da7a71915">◆ </a></span>osTimerType_t</h2>
340 <div class="memitem">
341 <div class="memproto">
342 <table class="memname">
344 <td class="memname">enum <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#ga7dc24a4c2b90334427081c3da7a71915">osTimerType_t</a></td>
347 </div><div class="memdoc">
350 <p>The <b>osTimerType_t</b> specifies the timer type as repeating (periodic) or one-shot. Used in the function <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gad4e7f785c5f700a509f55a3bf6a62bec">osTimerNew</a>. </p>
351 <table class="fieldtable">
352 <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>
353 <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>
355 <tr><td class="fieldname"><a id="gga7dc24a4c2b90334427081c3da7a71915ab3463d921dc310938094745c230f2b35" name="gga7dc24a4c2b90334427081c3da7a71915ab3463d921dc310938094745c230f2b35"></a>osTimerPeriodic </td><td class="fielddoc"><p>Repeating timer. </p>
356 <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>
362 <h2 class="groupheader">Function Documentation</h2>
363 <a id="gad4e7f785c5f700a509f55a3bf6a62bec" name="gad4e7f785c5f700a509f55a3bf6a62bec"></a>
364 <h2 class="memtitle"><span class="permalink"><a href="#gad4e7f785c5f700a509f55a3bf6a62bec">◆ </a></span>osTimerNew()</h2>
366 <div class="memitem">
367 <div class="memproto">
368 <table class="memname">
370 <td class="memname"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a> osTimerNew </td>
372 <td class="paramtype"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaacf768c1ec64b020598afb985d7b30be">osTimerFunc_t</a> </td>
373 <td class="paramname"><em>func</em>, </td>
376 <td class="paramkey"></td>
378 <td class="paramtype"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#ga7dc24a4c2b90334427081c3da7a71915">osTimerType_t</a> </td>
379 <td class="paramname"><em>type</em>, </td>
382 <td class="paramkey"></td>
384 <td class="paramtype">void * </td>
385 <td class="paramname"><em>argument</em>, </td>
388 <td class="paramkey"></td>
390 <td class="paramtype">const <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#structosTimerAttr__t">osTimerAttr_t</a> * </td>
391 <td class="paramname"><em>attr</em> </td>
399 </div><div class="memdoc">
401 <p>Create and Initialize a timer. </p>
402 <dl class="params"><dt>Parameters</dt><dd>
403 <table class="params">
404 <tr><td class="paramdir">[in]</td><td class="paramname">func</td><td>function pointer to callback function. </td></tr>
405 <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>
406 <tr><td class="paramdir">[in]</td><td class="paramname">argument</td><td>argument to the timer callback function. </td></tr>
407 <tr><td class="paramdir">[in]</td><td class="paramname">attr</td><td>timer attributes; NULL: default values. </td></tr>
411 <dl class="section return"><dt>Returns</dt><dd>timer ID for reference by other functions or NULL in case of error.</dd></dl>
412 <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>
413 <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>
414 <dl class="section note"><dt>Note</dt><dd>This function <b>cannot</b> be called from <a class="el" href="usingOS2.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
415 <p><b>Code Example</b> </p><div class="fragment"><div class="line"><span class="preprocessor">#include "cmsis_os2.h"</span></div>
416 <div class="line"> </div>
417 <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>
418 <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>
419 <div class="line"> </div>
420 <div class="line">uint32_t exec1; <span class="comment">// argument for the timer call back function</span></div>
421 <div class="line">uint32_t exec2; <span class="comment">// argument for the timer call back function</span></div>
422 <div class="line"> </div>
423 <div class="line"><span class="keywordtype">void</span> TimerCreate_example (<span class="keywordtype">void</span>) {</div>
424 <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>
425 <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>
426 <div class="line"> </div>
427 <div class="line"> <span class="comment">// Create one-shoot timer</span></div>
428 <div class="line"> exec1 = 1U;</div>
429 <div class="line"> id1 = <a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gad4e7f785c5f700a509f55a3bf6a62bec" title="Create and Initialize a timer.">osTimerNew</a>(Timer1_Callback, <a class="code hl_enumvalue" href="group__CMSIS__RTOS__TimerMgmt.html#gga7dc24a4c2b90334427081c3da7a71915a2e0e1f31c742c84b497c4d7143357bdb" title="One-shot timer.">osTimerOnce</a>, &exec1, NULL);</div>
430 <div class="line"> <span class="keywordflow">if</span> (id1 != NULL) {</div>
431 <div class="line"> <span class="comment">// One-shoot timer created</span></div>
432 <div class="line"> }</div>
433 <div class="line"> </div>
434 <div class="line"> <span class="comment">// Create periodic timer</span></div>
435 <div class="line"> exec2 = 2U;</div>
436 <div class="line"> id2 = <a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gad4e7f785c5f700a509f55a3bf6a62bec" title="Create and Initialize a timer.">osTimerNew</a>(Timer2_Callback, <a class="code hl_enumvalue" href="group__CMSIS__RTOS__TimerMgmt.html#gga7dc24a4c2b90334427081c3da7a71915ab3463d921dc310938094745c230f2b35" title="Repeating timer.">osTimerPeriodic</a>, &exec2, NULL);</div>
437 <div class="line"> <span class="keywordflow">if</span> (id2 != NULL) {</div>
438 <div class="line"> <span class="comment">// Periodic timer created</span></div>
439 <div class="line"> }</div>
440 <div class="line"> :</div>
441 <div class="line">}</div>
442 </div><!-- fragment -->
445 <a id="ga7938dde88ada1a01b60f41cf120069c0" name="ga7938dde88ada1a01b60f41cf120069c0"></a>
446 <h2 class="memtitle"><span class="permalink"><a href="#ga7938dde88ada1a01b60f41cf120069c0">◆ </a></span>osTimerGetName()</h2>
448 <div class="memitem">
449 <div class="memproto">
450 <table class="memname">
452 <td class="memname">const char * osTimerGetName </td>
454 <td class="paramtype"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a> </td>
455 <td class="paramname"><em>timer_id</em></td><td>)</td>
459 </div><div class="memdoc">
461 <p>Get name of a timer. </p>
462 <dl class="params"><dt>Parameters</dt><dd>
463 <table class="params">
464 <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>
468 <dl class="section return"><dt>Returns</dt><dd>name as null-terminated string.</dd></dl>
469 <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>
470 <dl class="section note"><dt>Note</dt><dd>This function may be called from <a class="el" href="usingOS2.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>. </dd></dl>
474 <a id="gab6ee2859ea657641b7adfac599b8121d" name="gab6ee2859ea657641b7adfac599b8121d"></a>
475 <h2 class="memtitle"><span class="permalink"><a href="#gab6ee2859ea657641b7adfac599b8121d">◆ </a></span>osTimerStart()</h2>
477 <div class="memitem">
478 <div class="memproto">
479 <table class="memname">
481 <td class="memname"><a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> osTimerStart </td>
483 <td class="paramtype"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a> </td>
484 <td class="paramname"><em>timer_id</em>, </td>
487 <td class="paramkey"></td>
489 <td class="paramtype">uint32_t </td>
490 <td class="paramname"><em>ticks</em> </td>
498 </div><div class="memdoc">
500 <p>Start or restart a timer. </p>
501 <dl class="params"><dt>Parameters</dt><dd>
502 <table class="params">
503 <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>
504 <tr><td class="paramdir">[in]</td><td class="paramname">ticks</td><td><a class="el" href="usingOS2.html#CMSIS_RTOS_TimeOutValue">time ticks</a> value of the timer. </td></tr>
508 <dl class="section return"><dt>Returns</dt><dd>status code that indicates the execution status of the function.</dd></dl>
509 <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 <a class="el" href="usingOS2.html#CMSIS_RTOS_TimeOutValue">time ticks</a>.</p>
510 <p>Possible <a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> return values:</p><ul>
511 <li><em>osOK:</em> the specified timer has been started or restarted.</li>
512 <li><em>osErrorISR:</em> <b>osTimerStart</b> cannot be called from interrupt service routines.</li>
513 <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>
514 <li><em>osErrorResource:</em> the timer is in an invalid state.</li>
515 <li><em>osErrorSafetyClass:</em> the calling thread safety class is lower than the safety class of the specified timer.</li>
517 <dl class="section note"><dt>Note</dt><dd>This function <b>cannot</b> be called from <a class="el" href="usingOS2.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
518 <p><b>Code Example</b> </p><div class="fragment"><div class="line"><span class="preprocessor">#include "cmsis_os2.h"</span></div>
519 <div class="line"> </div>
520 <div class="line"><span class="keywordtype">void</span> Timer_Callback (<span class="keywordtype">void</span> *arg) { <span class="comment">// timer callback function</span></div>
521 <div class="line"> <span class="comment">// arg contains &exec</span></div>
522 <div class="line"> <span class="comment">// called every second after osTimerStart</span></div>
523 <div class="line">}</div>
524 <div class="line"> </div>
525 <div class="line">uint32_t exec; <span class="comment">// argument for the timer call back function</span></div>
526 <div class="line"> </div>
527 <div class="line"><span class="keywordtype">void</span> TimerStart_example (<span class="keywordtype">void</span>) {</div>
528 <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>
529 <div class="line"> uint32_t timerDelay; <span class="comment">// timer value</span></div>
530 <div class="line"> <a class="code hl_enumeration" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e" title="Status code values returned by CMSIS-RTOS functions.">osStatus_t</a> status; <span class="comment">// function return status</span></div>
531 <div class="line"> </div>
532 <div class="line"> <span class="comment">// Create periodic timer</span></div>
533 <div class="line"> exec = 1U;</div>
534 <div class="line"> <span class="keywordtype">id</span> = <a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gad4e7f785c5f700a509f55a3bf6a62bec" title="Create and Initialize a timer.">osTimerNew</a>(Timer_Callback, <a class="code hl_enumvalue" href="group__CMSIS__RTOS__TimerMgmt.html#gga7dc24a4c2b90334427081c3da7a71915ab3463d921dc310938094745c230f2b35" title="Repeating timer.">osTimerPeriodic</a>, &exec, NULL);</div>
535 <div class="line"> <span class="keywordflow">if</span> (<span class="keywordtype">id</span> != NULL) {</div>
536 <div class="line"> timerDelay = 1000U;</div>
537 <div class="line"> status = <a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gab6ee2859ea657641b7adfac599b8121d" title="Start or restart a timer.">osTimerStart</a>(<span class="keywordtype">id</span>, timerDelay); <span class="comment">// start timer</span></div>
538 <div class="line"> <span class="keywordflow">if</span> (status != <a class="code hl_enumvalue" href="group__CMSIS__RTOS__Definitions.html#gga6c0dbe6069e4e7f47bb4cd32ae2b813eab17c65ad8b5bae759882b41c5bf35cda" title="Operation completed successfully.">osOK</a>) {</div>
539 <div class="line"> <span class="comment">// Timer could not be started</span></div>
540 <div class="line"> }</div>
541 <div class="line"> }</div>
542 <div class="line"> ;</div>
543 <div class="line">}</div>
544 </div><!-- fragment -->
547 <a id="gabd7a89356da7717293eb0bc5d87b8ac9" name="gabd7a89356da7717293eb0bc5d87b8ac9"></a>
548 <h2 class="memtitle"><span class="permalink"><a href="#gabd7a89356da7717293eb0bc5d87b8ac9">◆ </a></span>osTimerStop()</h2>
550 <div class="memitem">
551 <div class="memproto">
552 <table class="memname">
554 <td class="memname"><a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> osTimerStop </td>
556 <td class="paramtype"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a> </td>
557 <td class="paramname"><em>timer_id</em></td><td>)</td>
561 </div><div class="memdoc">
563 <p>Stop a timer. </p>
564 <dl class="params"><dt>Parameters</dt><dd>
565 <table class="params">
566 <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>
570 <dl class="section return"><dt>Returns</dt><dd>status code that indicates the execution status of the function.</dd></dl>
571 <p>The function <b>osTimerStop</b> stops a timer specified by the parameter <em>timer_id</em>.</p>
572 <p>Possible <a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> return values:</p><ul>
573 <li><em>osOK:</em> the specified timer has been stopped.</li>
574 <li><em>osErrorISR:</em> <b>osTimerStop</b> cannot be called from interrupt service routines.</li>
575 <li><em>osErrorParameter:</em> parameter <em>timer_id</em> is either <span class="XML-Token">NULL</span> or invalid.</li>
576 <li><em>osErrorResource:</em> the timer is not running (you can only stop a running timer).</li>
577 <li><em>osErrorSafetyClass:</em> the calling thread safety class is lower than the safety class of the specified timer.</li>
579 <dl class="section note"><dt>Note</dt><dd>This function <b>cannot</b> be called from <a class="el" href="usingOS2.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
580 <p><b>Code Example</b> </p><div class="fragment"><div class="line"><span class="preprocessor">#include "cmsis_os2.h"</span></div>
581 <div class="line"> </div>
582 <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>
583 <div class="line"> </div>
584 <div class="line">uint32_t exec; <span class="comment">// argument for the timer call back function</span></div>
585 <div class="line"> </div>
586 <div class="line"><span class="keywordtype">void</span> TimerStop_example (<span class="keywordtype">void</span>) {</div>
587 <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>
588 <div class="line"> <a class="code hl_enumeration" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e" title="Status code values returned by CMSIS-RTOS functions.">osStatus_t</a> status; <span class="comment">// function return status</span></div>
589 <div class="line"> </div>
590 <div class="line"> <span class="comment">// Create periodic timer</span></div>
591 <div class="line"> exec = 1U;</div>
592 <div class="line"> <span class="keywordtype">id</span> = <a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gad4e7f785c5f700a509f55a3bf6a62bec" title="Create and Initialize a timer.">osTimerNew</a>(Timer_Callback, <a class="code hl_enumvalue" href="group__CMSIS__RTOS__TimerMgmt.html#gga7dc24a4c2b90334427081c3da7a71915ab3463d921dc310938094745c230f2b35" title="Repeating timer.">osTimerPeriodic</a>, &exec, NULL);</div>
593 <div class="line"> <a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gab6ee2859ea657641b7adfac599b8121d" title="Start or restart a timer.">osTimerStart</a>(<span class="keywordtype">id</span>, 1000U); <span class="comment">// start timer</span></div>
594 <div class="line"> :</div>
595 <div class="line"> status = <a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gabd7a89356da7717293eb0bc5d87b8ac9" title="Stop a timer.">osTimerStop</a>(<span class="keywordtype">id</span>); <span class="comment">// stop timer</span></div>
596 <div class="line"> <span class="keywordflow">if</span> (status != <a class="code hl_enumvalue" href="group__CMSIS__RTOS__Definitions.html#gga6c0dbe6069e4e7f47bb4cd32ae2b813eab17c65ad8b5bae759882b41c5bf35cda" title="Operation completed successfully.">osOK</a>) {</div>
597 <div class="line"> <span class="comment">// Timer could not be stopped</span></div>
598 <div class="line"> }</div>
599 <div class="line"> ;</div>
600 <div class="line"> <a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gab6ee2859ea657641b7adfac599b8121d" title="Start or restart a timer.">osTimerStart</a>(<span class="keywordtype">id</span>, 1000U); <span class="comment">// start timer again</span></div>
601 <div class="line"> ;</div>
602 <div class="line">}</div>
603 </div><!-- fragment -->
606 <a id="ga69d3589f54194022c30dd01e45ec6741" name="ga69d3589f54194022c30dd01e45ec6741"></a>
607 <h2 class="memtitle"><span class="permalink"><a href="#ga69d3589f54194022c30dd01e45ec6741">◆ </a></span>osTimerIsRunning()</h2>
609 <div class="memitem">
610 <div class="memproto">
611 <table class="memname">
613 <td class="memname">uint32_t osTimerIsRunning </td>
615 <td class="paramtype"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a> </td>
616 <td class="paramname"><em>timer_id</em></td><td>)</td>
620 </div><div class="memdoc">
622 <p>Check if a timer is running. </p>
623 <dl class="params"><dt>Parameters</dt><dd>
624 <table class="params">
625 <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>
629 <dl class="section return"><dt>Returns</dt><dd>0 not running, 1 running.</dd></dl>
630 <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>
631 <dl class="section note"><dt>Note</dt><dd>This function <b>cannot</b> be called from <a class="el" href="usingOS2.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>. </dd></dl>
635 <a id="gad0001dd74721ab461789324806db2453" name="gad0001dd74721ab461789324806db2453"></a>
636 <h2 class="memtitle"><span class="permalink"><a href="#gad0001dd74721ab461789324806db2453">◆ </a></span>osTimerDelete()</h2>
638 <div class="memitem">
639 <div class="memproto">
640 <table class="memname">
642 <td class="memname"><a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> osTimerDelete </td>
644 <td class="paramtype"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a> </td>
645 <td class="paramname"><em>timer_id</em></td><td>)</td>
649 </div><div class="memdoc">
651 <p>Delete a timer. </p>
652 <dl class="params"><dt>Parameters</dt><dd>
653 <table class="params">
654 <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>
658 <dl class="section return"><dt>Returns</dt><dd>status code that indicates the execution status of the function.</dd></dl>
659 <p>The function <b>osTimerDelete</b> deletes the timer specified by parameter <em>timer_id</em>.</p>
660 <p>Possible <a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> return values:</p><ul>
661 <li><em>osOK:</em> the specified timer has been deleted.</li>
662 <li><em>osErrorISR:</em> <b>osTimerDelete</b> cannot be called from interrupt service routines.</li>
663 <li><em>osErrorParameter:</em> parameter <em>timer_id</em> is either <span class="XML-Token">NULL</span> or invalid.</li>
664 <li><em>osErrorResource:</em> the timer is in an invalid state.</li>
665 <li><em>osErrorSafetyClass:</em> the calling thread safety class is lower than the safety class of the specified timer.</li>
667 <dl class="section note"><dt>Note</dt><dd>This function <b>cannot</b> be called from <a class="el" href="usingOS2.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
668 <p><b>Code Example</b> </p><div class="fragment"><div class="line"><span class="preprocessor">#include "cmsis_os2.h"</span></div>
669 <div class="line"> </div>
670 <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>
671 <div class="line"> </div>
672 <div class="line">uint32_t exec; <span class="comment">// argument for the timer call back function</span></div>
673 <div class="line"> </div>
674 <div class="line"><span class="keywordtype">void</span> TimerDelete_example (<span class="keywordtype">void</span>) {</div>
675 <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>
676 <div class="line"> <a class="code hl_enumeration" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e" title="Status code values returned by CMSIS-RTOS functions.">osStatus_t</a> status; <span class="comment">// function return status </span></div>
677 <div class="line"> </div>
678 <div class="line"> <span class="comment">// Create periodic timer</span></div>
679 <div class="line"> exec = 1U;</div>
680 <div class="line"> <span class="keywordtype">id</span> = <a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gad4e7f785c5f700a509f55a3bf6a62bec" title="Create and Initialize a timer.">osTimerNew</a>(Timer_Callback, <a class="code hl_enumvalue" href="group__CMSIS__RTOS__TimerMgmt.html#gga7dc24a4c2b90334427081c3da7a71915ab3463d921dc310938094745c230f2b35" title="Repeating timer.">osTimerPeriodic</a>, &exec, NULL);</div>
681 <div class="line"> <a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gab6ee2859ea657641b7adfac599b8121d" title="Start or restart a timer.">osTimerStart</a>(<span class="keywordtype">id</span>, 1000U); <span class="comment">// start timer</span></div>
682 <div class="line"> ;</div>
683 <div class="line"> status = <a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gad0001dd74721ab461789324806db2453" title="Delete a timer.">osTimerDelete</a>(<span class="keywordtype">id</span>); <span class="comment">// stop and delete timer</span></div>
684 <div class="line"> <span class="keywordflow">if</span> (status != <a class="code hl_enumvalue" href="group__CMSIS__RTOS__Definitions.html#gga6c0dbe6069e4e7f47bb4cd32ae2b813eab17c65ad8b5bae759882b41c5bf35cda" title="Operation completed successfully.">osOK</a>) {</div>
685 <div class="line"> <span class="comment">// Timer could not be deleted</span></div>
686 <div class="line"> } </div>
687 <div class="line"> ;</div>
688 <div class="line">}</div>
689 </div><!-- fragment -->
692 <h2 class="groupheader">Variable Documentation</h2>
693 <a id="ga6e93b49cb79c12f768d72580c7731f30" name="ga6e93b49cb79c12f768d72580c7731f30"></a>
694 <h2 class="memtitle"><span class="permalink"><a href="#ga6e93b49cb79c12f768d72580c7731f30">◆ </a></span>attr_bits</h2>
696 <div class="memitem">
697 <div class="memproto">
698 <table class="memname">
700 <td class="memname">attr_bits</td>
703 </div><div class="memdoc">
705 <p>attribute bits </p>
706 <p>Reserved for future use (must be set to '0' for future compatibility). </p>
710 <a id="ga1e100dc33d403841ed3c344e3397868e" name="ga1e100dc33d403841ed3c344e3397868e"></a>
711 <h2 class="memtitle"><span class="permalink"><a href="#ga1e100dc33d403841ed3c344e3397868e">◆ </a></span>cb_mem</h2>
713 <div class="memitem">
714 <div class="memproto">
715 <table class="memname">
717 <td class="memname">cb_mem</td>
720 </div><div class="memdoc">
722 <p>memory for control block </p>
723 <p>Pointer to a memory for the timer control block object. Refer to <a class="el" href="usingOS2.html#CMSIS_RTOS_MemoryMgmt_Manual">Manual User-defined Allocation</a> for more information.</p>
724 <p>Default: <span class="XML-Token">NULL</span> to use <a class="el" href="usingOS2.html#CMSIS_RTOS_MemoryMgmt_Automatic">Automatic Dynamic Allocation</a> for the timer control block. </p>
728 <a id="gaa55a4335d12dc2785dc00fdc292d1159" name="gaa55a4335d12dc2785dc00fdc292d1159"></a>
729 <h2 class="memtitle"><span class="permalink"><a href="#gaa55a4335d12dc2785dc00fdc292d1159">◆ </a></span>cb_size</h2>
731 <div class="memitem">
732 <div class="memproto">
733 <table class="memname">
735 <td class="memname">cb_size</td>
738 </div><div class="memdoc">
740 <p>size of provided memory for control block </p>
741 <p>The size (in bytes) of memory block passed with <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#ga1e100dc33d403841ed3c344e3397868e">cb_mem</a>. Required value depends on the underlying kernel implementation.</p>
742 <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#ga1e100dc33d403841ed3c344e3397868e">cb_mem</a>. </p>
746 <a id="gab74e6bf80237ddc4109968cedc58c151" name="gab74e6bf80237ddc4109968cedc58c151"></a>
747 <h2 class="memtitle"><span class="permalink"><a href="#gab74e6bf80237ddc4109968cedc58c151">◆ </a></span>name</h2>
749 <div class="memitem">
750 <div class="memproto">
751 <table class="memname">
753 <td class="memname">name</td>
756 </div><div class="memdoc">
758 <p>name of the timer </p>
759 <p>Pointer to a constant string with a human readable name (displayed during debugging) of the timer object.</p>
760 <p>Default: <span class="XML-Token">NULL</span> no name specified. </p>
764 </div><!-- contents -->
765 </div><!-- doc-content -->
766 <!-- start footer part -->
767 <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
770 <script type="text/javascript">
772 writeFooter.call(this);