]> begriffs open source - cmsis/blob - main/RTOS2/group__CMSIS__RTOS__TimerMgmt.html
Update documentation for branch main
[cmsis] / main / RTOS2 / group__CMSIS__RTOS__TimerMgmt.html
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">
4 <head>
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&amp;dn=expat.txt MIT */
24   $(document).ready(function() { init_search(); });
25 /* @license-end */
26 </script>
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>
34 </head>
35 <body>
36 <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
37 <div id="titlearea">
38 <table cellspacing="0" cellpadding="0">
39  <tbody>
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    &#160;<span id="projectnumber"><script type="text/javascript">
45      <!--
46      writeHeader.call(this);
47      writeVersionDropdown.call(this, "CMSIS-RTOS2");
48      //-->
49     </script>
50    </span>
51    </div>
52    <div id="projectbrief">Real-Time Operating System API</div>
53   </td>
54    <td>        <div id="MSearchBox" class="MSearchBoxInactive">
55         <span class="left">
56           <span id="MSearchSelect"                onmouseover="return searchBox.OnSearchSelectShow()"                onmouseout="return searchBox.OnSearchSelectHide()">&#160;</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>
63           </span>
64         </div>
65 </td>
66   <!--END !PROJECT_NAME-->
67  </tr>
68  </tbody>
69 </table>
70 </div>
71 <!-- end header part -->
72 <div id="CMSISnav" class="tabs1">
73   <ul class="tablist">
74     <script type="text/javascript">
75       writeComponentTabs.call(this);
76     </script>
77   </ul>
78 </div>
79 <script type="text/javascript">
80   writeSubComponentTabs.call(this);
81 </script>
82 <!-- Generated by Doxygen 1.9.6 -->
83 <script type="text/javascript">
84 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
85 var searchBox = new SearchBox("searchBox", "search/",'.html');
86 /* @license-end */
87 </script>
88 </div><!-- top -->
89 <div id="side-nav" class="ui-resizable side-nav-resizable">
90   <div id="nav-tree">
91     <div id="nav-tree-contents">
92       <div id="nav-sync" class="sync"></div>
93     </div>
94   </div>
95   <div id="splitbar" style="-moz-user-select:none;" 
96        class="ui-resizable-handle">
97   </div>
98 </div>
99 <script type="text/javascript">
100 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
101 $(document).ready(function(){initNavTree('group__CMSIS__RTOS__TimerMgmt.html',''); initResizable(); });
102 /* @license-end */
103 </script>
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)">
110 </div>
111
112 <!-- iframe showing the search results (closed by default) -->
113 <div id="MSearchResultsWindow">
114 <div id="MSearchResults">
115 <div class="SRPage">
116 <div id="SRIndex">
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>
121 </div>
122 </div>
123 </div>
124 </div>
125
126 <div class="header">
127   <div class="summary">
128 <a href="#nested-classes">Data Structures</a> &#124;
129 <a href="#typedef-members">Typedefs</a> &#124;
130 <a href="#enum-members">Enumerations</a> &#124;
131 <a href="#func-members">Functions</a>  </div>
132   <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>
133 </div><!--header-->
134 <div class="contents">
135
136 <p>Create and control timer and timer callback functions.  
137 <a href="#details">More...</a></p>
138 <table class="memberdecls">
139 <tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="nested-classes" name="nested-classes"></a>
140 Data Structures</h2></td></tr>
141 <tr class="memitem:structosTimerAttr__t"><td class="memItemLeft" align="right" valign="top">struct &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#structosTimerAttr__t">osTimerAttr_t</a></td></tr>
142 <tr class="memdesc:structosTimerAttr__t"><td class="mdescLeft">&#160;</td><td class="mdescRight">Attributes structure for timer.  <a href="group__CMSIS__RTOS__TimerMgmt.html#structosTimerAttr__t">More...</a><br /></td></tr>
143 <tr class="separator:structosTimerAttr__t"><td class="memSeparator" colspan="2">&#160;</td></tr>
144 </table><table class="memberdecls">
145 <tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="typedef-members" name="typedef-members"></a>
146 Typedefs</h2></td></tr>
147 <tr class="memitem:gaad5409379689ee27bb0a0b56ea4a4b34"><td class="memItemLeft" align="right" valign="top">typedef void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a></td></tr>
148 <tr class="separator:gaad5409379689ee27bb0a0b56ea4a4b34"><td class="memSeparator" colspan="2">&#160;</td></tr>
149 <tr class="memitem:gaacf768c1ec64b020598afb985d7b30be"><td class="memItemLeft" align="right" valign="top">typedef void(*&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaacf768c1ec64b020598afb985d7b30be">osTimerFunc_t</a>) (void *argument)</td></tr>
150 <tr class="memdesc:gaacf768c1ec64b020598afb985d7b30be"><td class="mdescLeft">&#160;</td><td class="mdescRight">Timer callback function.  <br /></td></tr>
151 <tr class="separator:gaacf768c1ec64b020598afb985d7b30be"><td class="memSeparator" colspan="2">&#160;</td></tr>
152 </table><table class="memberdecls">
153 <tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="enum-members" name="enum-members"></a>
154 Enumerations</h2></td></tr>
155 <tr class="memitem:ga7dc24a4c2b90334427081c3da7a71915"><td class="memItemLeft" align="right" valign="top">enum &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#ga7dc24a4c2b90334427081c3da7a71915">osTimerType_t</a> { <br />
156 &#160;&#160;<a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gga7dc24a4c2b90334427081c3da7a71915a2e0e1f31c742c84b497c4d7143357bdb">osTimerOnce</a> = 0
157 , <br />
158 &#160;&#160;<a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gga7dc24a4c2b90334427081c3da7a71915ab3463d921dc310938094745c230f2b35">osTimerPeriodic</a> = 1
159 <br />
160  }</td></tr>
161 <tr class="memdesc:ga7dc24a4c2b90334427081c3da7a71915"><td class="mdescLeft">&#160;</td><td class="mdescRight">Timer type.  <a href="group__CMSIS__RTOS__TimerMgmt.html#ga7dc24a4c2b90334427081c3da7a71915">More...</a><br /></td></tr>
162 <tr class="separator:ga7dc24a4c2b90334427081c3da7a71915"><td class="memSeparator" colspan="2">&#160;</td></tr>
163 </table><table class="memberdecls">
164 <tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
165 Functions</h2></td></tr>
166 <tr class="memitem:gad4e7f785c5f700a509f55a3bf6a62bec"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a>&#160;</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>
167 <tr class="memdesc:gad4e7f785c5f700a509f55a3bf6a62bec"><td class="mdescLeft">&#160;</td><td class="mdescRight">Create and Initialize a timer.  <br /></td></tr>
168 <tr class="separator:gad4e7f785c5f700a509f55a3bf6a62bec"><td class="memSeparator" colspan="2">&#160;</td></tr>
169 <tr class="memitem:ga7938dde88ada1a01b60f41cf120069c0"><td class="memItemLeft" align="right" valign="top">const char *&#160;</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>
170 <tr class="memdesc:ga7938dde88ada1a01b60f41cf120069c0"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get name of a timer.  <br /></td></tr>
171 <tr class="separator:ga7938dde88ada1a01b60f41cf120069c0"><td class="memSeparator" colspan="2">&#160;</td></tr>
172 <tr class="memitem:gab6ee2859ea657641b7adfac599b8121d"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a>&#160;</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>
173 <tr class="memdesc:gab6ee2859ea657641b7adfac599b8121d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Start or restart a timer.  <br /></td></tr>
174 <tr class="separator:gab6ee2859ea657641b7adfac599b8121d"><td class="memSeparator" colspan="2">&#160;</td></tr>
175 <tr class="memitem:gabd7a89356da7717293eb0bc5d87b8ac9"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a>&#160;</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>
176 <tr class="memdesc:gabd7a89356da7717293eb0bc5d87b8ac9"><td class="mdescLeft">&#160;</td><td class="mdescRight">Stop a timer.  <br /></td></tr>
177 <tr class="separator:gabd7a89356da7717293eb0bc5d87b8ac9"><td class="memSeparator" colspan="2">&#160;</td></tr>
178 <tr class="memitem:ga69d3589f54194022c30dd01e45ec6741"><td class="memItemLeft" align="right" valign="top">uint32_t&#160;</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>
179 <tr class="memdesc:ga69d3589f54194022c30dd01e45ec6741"><td class="mdescLeft">&#160;</td><td class="mdescRight">Check if a timer is running.  <br /></td></tr>
180 <tr class="separator:ga69d3589f54194022c30dd01e45ec6741"><td class="memSeparator" colspan="2">&#160;</td></tr>
181 <tr class="memitem:gad0001dd74721ab461789324806db2453"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a>&#160;</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>
182 <tr class="memdesc:gad0001dd74721ab461789324806db2453"><td class="mdescLeft">&#160;</td><td class="mdescRight">Delete a timer.  <br /></td></tr>
183 <tr class="separator:gad0001dd74721ab461789324806db2453"><td class="memSeparator" colspan="2">&#160;</td></tr>
184 </table>
185 <a name="details" id="details"></a><h2 class="groupheader">Description</h2>
186 <p>Create and control timer and timer callback functions. </p>
187 <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>
188 <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>
189 <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>
190 <div class="image">
191 <img src="Timer.png" alt=""/>
192 <div class="caption">
193 Behavior of a Periodic Timer</div></div>
194 <h2><a class="anchor" id="autotoc_md4"></a>
195 Working with Timers</h2>
196 <p>The following steps are required to use a software timer:</p><ol type="1">
197 <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>
198 </div><!-- fragment --></li>
199 <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>
200 <div class="line">  int32_t arg = (int32_t)argument; <span class="comment">// cast back argument &#39;0&#39; </span></div>
201 <div class="line">  <span class="comment">// do something, i.e. set thread/event flags</span></div>
202 <div class="line">}</div>
203 <div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> periodic_Callback (<span class="keywordtype">void</span> *argument) {</div>
204 <div class="line">  int32_t arg = (int32_t)argument; <span class="comment">// cast back argument &#39;5&#39;</span></div>
205 <div class="line">  <span class="comment">// do something, i.e. set thread/event flags</span></div>
206 <div class="line">}</div>
207 </div><!-- fragment --></li>
208 <li>Instantiate and start the timers: <div class="fragment"><div class="line"><span class="comment">// creates a one-shot timer:</span></div>
209 <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>
210 <div class="line">                                                                               <span class="comment">// to the callback function</span></div>
211 <div class="line"><span class="comment">// creates a periodic timer:</span></div>
212 <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>
213 <div class="line">                                                                               <span class="comment">// to the callback function</span></div>
214 <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>
215 <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>
216 <div class="line"> </div>
217 <div class="line"><span class="comment">// start the one-shot timer again after it has triggered the first time:</span></div>
218 <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>
219 <div class="line"> </div>
220 <div class="line"><span class="comment">// when timers are not needed any longer free the resources:</span></div>
221 <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>
222 <div class="line"><a class="code hl_function" href="group__CMSIS__RTOS__TimerMgmt.html#gad0001dd74721ab461789324806db2453" title="Delete a timer.">osTimerDelete</a>(periodic_id);</div>
223 </div><!-- fragment --> </li>
224 </ol>
225 <hr/><h2 class="groupheader">Data Structure Documentation</h2>
226 <a name="structosTimerAttr__t" id="structosTimerAttr__t"></a>
227 <h2 class="memtitle"><span class="permalink"><a href="#structosTimerAttr__t">&#9670;&#160;</a></span>osTimerAttr_t</h2>
228
229 <div class="memitem">
230 <div class="memproto">
231       <table class="memname">
232         <tr>
233           <td class="memname">struct osTimerAttr_t</td>
234         </tr>
235       </table>
236 </div><div class="memdoc">
237 <div class="textblock"><p>Attributes structure for timer. </p>
238 <p>Specifies the following attributes for the <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gad4e7f785c5f700a509f55a3bf6a62bec">osTimerNew</a> function. </p>
239 </div><table class="fieldtable">
240 <tr><th colspan="3">Data Fields</th></tr>
241 <tr><td class="fieldtype">
242 <a id="ab74e6bf80237ddc4109968cedc58c151" name="ab74e6bf80237ddc4109968cedc58c151"></a>const char *</td>
243 <td class="fieldname">
244 name</td>
245 <td class="fielddoc">
246 name of the timer <p>Pointer to a constant string with a human readable name (displayed during debugging) of the timer object.</p>
247 <p>Default: <span class="XML-Token">NULL</span> no name specified. </p>
248 </td></tr>
249 <tr><td class="fieldtype">
250 <a id="a6e93b49cb79c12f768d72580c7731f30" name="a6e93b49cb79c12f768d72580c7731f30"></a>uint32_t</td>
251 <td class="fieldname">
252 attr_bits</td>
253 <td class="fielddoc">
254 attribute bits <p>Reserved for future use (must be set to '0' for future compatibility). </p>
255 </td></tr>
256 <tr><td class="fieldtype">
257 <a id="a1e100dc33d403841ed3c344e3397868e" name="a1e100dc33d403841ed3c344e3397868e"></a>void *</td>
258 <td class="fieldname">
259 cb_mem</td>
260 <td class="fielddoc">
261 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>
262 <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>
263 </td></tr>
264 <tr><td class="fieldtype">
265 <a id="aa55a4335d12dc2785dc00fdc292d1159" name="aa55a4335d12dc2785dc00fdc292d1159"></a>uint32_t</td>
266 <td class="fieldname">
267 cb_size</td>
268 <td class="fielddoc">
269 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>. Required value depends on the underlying kernel implementation.</p>
270 <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>
271 </td></tr>
272 </table>
273
274 </div>
275 </div>
276 <h2 class="groupheader">Typedef Documentation</h2>
277 <a id="gaad5409379689ee27bb0a0b56ea4a4b34" name="gaad5409379689ee27bb0a0b56ea4a4b34"></a>
278 <h2 class="memtitle"><span class="permalink"><a href="#gaad5409379689ee27bb0a0b56ea4a4b34">&#9670;&#160;</a></span>osTimerId_t</h2>
279
280 <div class="memitem">
281 <div class="memproto">
282       <table class="memname">
283         <tr>
284           <td class="memname"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a></td>
285         </tr>
286       </table>
287 </div><div class="memdoc">
288 <p>Timer ID identifies the timer.</p>
289 <p>Instances of this type hold a reference to a timer object. <br  />
290 Returned by:</p><ul>
291 <li><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gad4e7f785c5f700a509f55a3bf6a62bec">osTimerNew</a> </li>
292 </ul>
293
294 </div>
295 </div>
296 <a id="gaacf768c1ec64b020598afb985d7b30be" name="gaacf768c1ec64b020598afb985d7b30be"></a>
297 <h2 class="memtitle"><span class="permalink"><a href="#gaacf768c1ec64b020598afb985d7b30be">&#9670;&#160;</a></span>osTimerFunc_t</h2>
298
299 <div class="memitem">
300 <div class="memproto">
301       <table class="memname">
302         <tr>
303           <td class="memname">void(* osTimerFunc_t)(void *argument)</td>
304         </tr>
305       </table>
306 </div><div class="memdoc">
307
308 <p>Timer callback function. </p>
309 <p>The timer callback function is called every time the timer elapses.</p>
310 <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>
311 <dl class="params"><dt>Parameters</dt><dd>
312   <table class="params">
313     <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>
314   </table>
315   </dd>
316 </dl>
317
318 </div>
319 </div>
320 <h2 class="groupheader">Enumeration Type Documentation</h2>
321 <a id="ga7dc24a4c2b90334427081c3da7a71915" name="ga7dc24a4c2b90334427081c3da7a71915"></a>
322 <h2 class="memtitle"><span class="permalink"><a href="#ga7dc24a4c2b90334427081c3da7a71915">&#9670;&#160;</a></span>osTimerType_t</h2>
323
324 <div class="memitem">
325 <div class="memproto">
326       <table class="memname">
327         <tr>
328           <td class="memname">enum <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#ga7dc24a4c2b90334427081c3da7a71915">osTimerType_t</a></td>
329         </tr>
330       </table>
331 </div><div class="memdoc">
332
333 <p>Timer type. </p>
334 <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>
335 <table class="fieldtable">
336 <tr><th colspan="2">Enumerator</th></tr><tr><td class="fieldname"><a id="gga7dc24a4c2b90334427081c3da7a71915a2e0e1f31c742c84b497c4d7143357bdb" name="gga7dc24a4c2b90334427081c3da7a71915a2e0e1f31c742c84b497c4d7143357bdb"></a>osTimerOnce&#160;</td><td class="fielddoc"><p>One-shot timer. </p>
337 <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>
338 </td></tr>
339 <tr><td class="fieldname"><a id="gga7dc24a4c2b90334427081c3da7a71915ab3463d921dc310938094745c230f2b35" name="gga7dc24a4c2b90334427081c3da7a71915ab3463d921dc310938094745c230f2b35"></a>osTimerPeriodic&#160;</td><td class="fielddoc"><p>Repeating timer. </p>
340 <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>
341 </td></tr>
342 </table>
343
344 </div>
345 </div>
346 <h2 class="groupheader">Function Documentation</h2>
347 <a id="gad4e7f785c5f700a509f55a3bf6a62bec" name="gad4e7f785c5f700a509f55a3bf6a62bec"></a>
348 <h2 class="memtitle"><span class="permalink"><a href="#gad4e7f785c5f700a509f55a3bf6a62bec">&#9670;&#160;</a></span>osTimerNew()</h2>
349
350 <div class="memitem">
351 <div class="memproto">
352       <table class="memname">
353         <tr>
354           <td class="memname"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a> osTimerNew </td>
355           <td>(</td>
356           <td class="paramtype"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaacf768c1ec64b020598afb985d7b30be">osTimerFunc_t</a>&#160;</td>
357           <td class="paramname"><em>func</em>, </td>
358         </tr>
359         <tr>
360           <td class="paramkey"></td>
361           <td></td>
362           <td class="paramtype"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#ga7dc24a4c2b90334427081c3da7a71915">osTimerType_t</a>&#160;</td>
363           <td class="paramname"><em>type</em>, </td>
364         </tr>
365         <tr>
366           <td class="paramkey"></td>
367           <td></td>
368           <td class="paramtype">void *&#160;</td>
369           <td class="paramname"><em>argument</em>, </td>
370         </tr>
371         <tr>
372           <td class="paramkey"></td>
373           <td></td>
374           <td class="paramtype">const <a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#structosTimerAttr__t">osTimerAttr_t</a> *&#160;</td>
375           <td class="paramname"><em>attr</em>&#160;</td>
376         </tr>
377         <tr>
378           <td></td>
379           <td>)</td>
380           <td></td><td></td>
381         </tr>
382       </table>
383 </div><div class="memdoc">
384
385 <p>Create and Initialize a timer. </p>
386 <dl class="params"><dt>Parameters</dt><dd>
387   <table class="params">
388     <tr><td class="paramdir">[in]</td><td class="paramname">func</td><td>function pointer to callback function. </td></tr>
389     <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>
390     <tr><td class="paramdir">[in]</td><td class="paramname">argument</td><td>argument to the timer callback function. </td></tr>
391     <tr><td class="paramdir">[in]</td><td class="paramname">attr</td><td>timer attributes; NULL: default values. </td></tr>
392   </table>
393   </dd>
394 </dl>
395 <dl class="section return"><dt>Returns</dt><dd>timer ID for reference by other functions or NULL in case of error.</dd></dl>
396 <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>
397 <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>
398 <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>
399 <p><b>Code Example</b> </p><div class="fragment"><div class="line"><span class="preprocessor">#include &quot;cmsis_os2.h&quot;</span></div>
400 <div class="line"> </div>
401 <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>
402 <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>
403 <div class="line"> </div>
404 <div class="line">uint32_t exec1;                                 <span class="comment">// argument for the timer call back function</span></div>
405 <div class="line">uint32_t exec2;                                 <span class="comment">// argument for the timer call back function</span></div>
406 <div class="line"> </div>
407 <div class="line"><span class="keywordtype">void</span> TimerCreate_example (<span class="keywordtype">void</span>)  {</div>
408 <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>
409 <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>
410 <div class="line"> </div>
411 <div class="line">  <span class="comment">// Create one-shoot timer</span></div>
412 <div class="line">  exec1 = 1U;</div>
413 <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>, &amp;exec1, NULL);</div>
414 <div class="line">  <span class="keywordflow">if</span> (id1 != NULL) {</div>
415 <div class="line">    <span class="comment">// One-shoot timer created</span></div>
416 <div class="line">  }</div>
417 <div class="line"> </div>
418 <div class="line">  <span class="comment">// Create periodic timer</span></div>
419 <div class="line">  exec2 = 2U;</div>
420 <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>, &amp;exec2, NULL);</div>
421 <div class="line">  <span class="keywordflow">if</span> (id2 != NULL) {</div>
422 <div class="line">    <span class="comment">// Periodic timer created</span></div>
423 <div class="line">  }</div>
424 <div class="line">  :</div>
425 <div class="line">}</div>
426 </div><!-- fragment --> 
427 </div>
428 </div>
429 <a id="ga7938dde88ada1a01b60f41cf120069c0" name="ga7938dde88ada1a01b60f41cf120069c0"></a>
430 <h2 class="memtitle"><span class="permalink"><a href="#ga7938dde88ada1a01b60f41cf120069c0">&#9670;&#160;</a></span>osTimerGetName()</h2>
431
432 <div class="memitem">
433 <div class="memproto">
434       <table class="memname">
435         <tr>
436           <td class="memname">const char * osTimerGetName </td>
437           <td>(</td>
438           <td class="paramtype"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a>&#160;</td>
439           <td class="paramname"><em>timer_id</em></td><td>)</td>
440           <td></td>
441         </tr>
442       </table>
443 </div><div class="memdoc">
444
445 <p>Get name of a timer. </p>
446 <dl class="params"><dt>Parameters</dt><dd>
447   <table class="params">
448     <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>
449   </table>
450   </dd>
451 </dl>
452 <dl class="section return"><dt>Returns</dt><dd>name as null-terminated string.</dd></dl>
453 <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>
454 <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>
455
456 </div>
457 </div>
458 <a id="gab6ee2859ea657641b7adfac599b8121d" name="gab6ee2859ea657641b7adfac599b8121d"></a>
459 <h2 class="memtitle"><span class="permalink"><a href="#gab6ee2859ea657641b7adfac599b8121d">&#9670;&#160;</a></span>osTimerStart()</h2>
460
461 <div class="memitem">
462 <div class="memproto">
463       <table class="memname">
464         <tr>
465           <td class="memname"><a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> osTimerStart </td>
466           <td>(</td>
467           <td class="paramtype"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a>&#160;</td>
468           <td class="paramname"><em>timer_id</em>, </td>
469         </tr>
470         <tr>
471           <td class="paramkey"></td>
472           <td></td>
473           <td class="paramtype">uint32_t&#160;</td>
474           <td class="paramname"><em>ticks</em>&#160;</td>
475         </tr>
476         <tr>
477           <td></td>
478           <td>)</td>
479           <td></td><td></td>
480         </tr>
481       </table>
482 </div><div class="memdoc">
483
484 <p>Start or restart a timer. </p>
485 <dl class="params"><dt>Parameters</dt><dd>
486   <table class="params">
487     <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>
488     <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>
489   </table>
490   </dd>
491 </dl>
492 <dl class="section return"><dt>Returns</dt><dd>status code that indicates the execution status of the function.</dd></dl>
493 <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>
494 <p>Possible <a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> return values:</p><ul>
495 <li><em>osOK:</em> the specified timer has been started or restarted.</li>
496 <li><em>osErrorISR:</em> <b>osTimerStart</b> cannot be called from interrupt service routines.</li>
497 <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>
498 <li><em>osErrorResource:</em> the timer is in an invalid state.</li>
499 <li><em>osErrorSafetyClass:</em> the calling thread safety class is lower than the safety class of the specified timer.</li>
500 </ul>
501 <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>
502 <p><b>Code Example</b> </p><div class="fragment"><div class="line"><span class="preprocessor">#include &quot;cmsis_os2.h&quot;</span></div>
503 <div class="line"> </div>
504 <div class="line"><span class="keywordtype">void</span> Timer_Callback (<span class="keywordtype">void</span> *arg) {               <span class="comment">// timer callback function</span></div>
505 <div class="line">                                                <span class="comment">// arg contains &amp;exec</span></div>
506 <div class="line">                                                <span class="comment">// called every second after osTimerStart</span></div>
507 <div class="line">}</div>
508 <div class="line"> </div>
509 <div class="line">uint32_t exec;                                  <span class="comment">// argument for the timer call back function</span></div>
510 <div class="line"> </div>
511 <div class="line"><span class="keywordtype">void</span> TimerStart_example (<span class="keywordtype">void</span>) {</div>
512 <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>
513 <div class="line">  uint32_t    timerDelay;                       <span class="comment">// timer value</span></div>
514 <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>
515 <div class="line"> </div>
516 <div class="line">  <span class="comment">// Create periodic timer</span></div>
517 <div class="line">  exec = 1U;</div>
518 <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>, &amp;exec, NULL);</div>
519 <div class="line">  <span class="keywordflow">if</span> (<span class="keywordtype">id</span> != NULL)  {</div>
520 <div class="line">    timerDelay = 1000U;</div>
521 <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>
522 <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>
523 <div class="line">      <span class="comment">// Timer could not be started</span></div>
524 <div class="line">    }</div>
525 <div class="line">  }</div>
526 <div class="line">  ;</div>
527 <div class="line">}</div>
528 </div><!-- fragment --> 
529 </div>
530 </div>
531 <a id="gabd7a89356da7717293eb0bc5d87b8ac9" name="gabd7a89356da7717293eb0bc5d87b8ac9"></a>
532 <h2 class="memtitle"><span class="permalink"><a href="#gabd7a89356da7717293eb0bc5d87b8ac9">&#9670;&#160;</a></span>osTimerStop()</h2>
533
534 <div class="memitem">
535 <div class="memproto">
536       <table class="memname">
537         <tr>
538           <td class="memname"><a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> osTimerStop </td>
539           <td>(</td>
540           <td class="paramtype"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a>&#160;</td>
541           <td class="paramname"><em>timer_id</em></td><td>)</td>
542           <td></td>
543         </tr>
544       </table>
545 </div><div class="memdoc">
546
547 <p>Stop a timer. </p>
548 <dl class="params"><dt>Parameters</dt><dd>
549   <table class="params">
550     <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>
551   </table>
552   </dd>
553 </dl>
554 <dl class="section return"><dt>Returns</dt><dd>status code that indicates the execution status of the function.</dd></dl>
555 <p>The function <b>osTimerStop</b> stops a timer specified by the parameter <em>timer_id</em>.</p>
556 <p>Possible <a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> return values:</p><ul>
557 <li><em>osOK:</em> the specified timer has been stopped.</li>
558 <li><em>osErrorISR:</em> <b>osTimerStop</b> cannot be called from interrupt service routines.</li>
559 <li><em>osErrorParameter:</em> parameter <em>timer_id</em> is either <span class="XML-Token">NULL</span> or invalid.</li>
560 <li><em>osErrorResource:</em> the timer is not running (you can only stop a running timer).</li>
561 <li><em>osErrorSafetyClass:</em> the calling thread safety class is lower than the safety class of the specified timer.</li>
562 </ul>
563 <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>
564 <p><b>Code Example</b> </p><div class="fragment"><div class="line"><span class="preprocessor">#include &quot;cmsis_os2.h&quot;</span></div>
565 <div class="line"> </div>
566 <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>
567 <div class="line"> </div>
568 <div class="line">uint32_t exec;                                  <span class="comment">// argument for the timer call back function</span></div>
569 <div class="line"> </div>
570 <div class="line"><span class="keywordtype">void</span> TimerStop_example (<span class="keywordtype">void</span>) {</div>
571 <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>
572 <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>
573 <div class="line"> </div>
574 <div class="line">  <span class="comment">// Create periodic timer</span></div>
575 <div class="line">  exec = 1U;</div>
576 <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>, &amp;exec, NULL);</div>
577 <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>
578 <div class="line">  :</div>
579 <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>
580 <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>
581 <div class="line">    <span class="comment">// Timer could not be stopped</span></div>
582 <div class="line">  }</div>
583 <div class="line">  ;</div>
584 <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>
585 <div class="line">  ;</div>
586 <div class="line">}</div>
587 </div><!-- fragment --> 
588 </div>
589 </div>
590 <a id="ga69d3589f54194022c30dd01e45ec6741" name="ga69d3589f54194022c30dd01e45ec6741"></a>
591 <h2 class="memtitle"><span class="permalink"><a href="#ga69d3589f54194022c30dd01e45ec6741">&#9670;&#160;</a></span>osTimerIsRunning()</h2>
592
593 <div class="memitem">
594 <div class="memproto">
595       <table class="memname">
596         <tr>
597           <td class="memname">uint32_t osTimerIsRunning </td>
598           <td>(</td>
599           <td class="paramtype"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a>&#160;</td>
600           <td class="paramname"><em>timer_id</em></td><td>)</td>
601           <td></td>
602         </tr>
603       </table>
604 </div><div class="memdoc">
605
606 <p>Check if a timer is running. </p>
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>
610   </table>
611   </dd>
612 </dl>
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 <a class="el" href="usingOS2.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>. </dd></dl>
616
617 </div>
618 </div>
619 <a id="gad0001dd74721ab461789324806db2453" name="gad0001dd74721ab461789324806db2453"></a>
620 <h2 class="memtitle"><span class="permalink"><a href="#gad0001dd74721ab461789324806db2453">&#9670;&#160;</a></span>osTimerDelete()</h2>
621
622 <div class="memitem">
623 <div class="memproto">
624       <table class="memname">
625         <tr>
626           <td class="memname"><a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> osTimerDelete </td>
627           <td>(</td>
628           <td class="paramtype"><a class="el" href="group__CMSIS__RTOS__TimerMgmt.html#gaad5409379689ee27bb0a0b56ea4a4b34">osTimerId_t</a>&#160;</td>
629           <td class="paramname"><em>timer_id</em></td><td>)</td>
630           <td></td>
631         </tr>
632       </table>
633 </div><div class="memdoc">
634
635 <p>Delete a timer. </p>
636 <dl class="params"><dt>Parameters</dt><dd>
637   <table class="params">
638     <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>
639   </table>
640   </dd>
641 </dl>
642 <dl class="section return"><dt>Returns</dt><dd>status code that indicates the execution status of the function.</dd></dl>
643 <p>The function <b>osTimerDelete</b> deletes the timer specified by parameter <em>timer_id</em>.</p>
644 <p>Possible <a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> return values:</p><ul>
645 <li><em>osOK:</em> the specified timer has been deleted.</li>
646 <li><em>osErrorISR:</em> <b>osTimerDelete</b> cannot be called from interrupt service routines.</li>
647 <li><em>osErrorParameter:</em> parameter <em>timer_id</em> is either <span class="XML-Token">NULL</span> or invalid.</li>
648 <li><em>osErrorResource:</em> the timer is in an invalid state.</li>
649 <li><em>osErrorSafetyClass:</em> the calling thread safety class is lower than the safety class of the specified timer.</li>
650 </ul>
651 <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>
652 <p><b>Code Example</b> </p><div class="fragment"><div class="line"><span class="preprocessor">#include &quot;cmsis_os2.h&quot;</span></div>
653 <div class="line"> </div>
654 <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>
655 <div class="line"> </div>
656 <div class="line">uint32_t exec;                                  <span class="comment">// argument for the timer call back function</span></div>
657 <div class="line"> </div>
658 <div class="line"><span class="keywordtype">void</span> TimerDelete_example (<span class="keywordtype">void</span>) {</div>
659 <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>
660 <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>
661 <div class="line"> </div>
662 <div class="line">  <span class="comment">// Create periodic timer</span></div>
663 <div class="line">  exec = 1U;</div>
664 <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>, &amp;exec, NULL);</div>
665 <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>
666 <div class="line">  ;</div>
667 <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>
668 <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>
669 <div class="line">    <span class="comment">// Timer could not be deleted</span></div>
670 <div class="line">  } </div>
671 <div class="line">  ;</div>
672 <div class="line">}</div>
673 </div><!-- fragment --> 
674 </div>
675 </div>
676 </div><!-- contents -->
677 </div><!-- doc-content -->
678 <!-- start footer part -->
679 <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
680   <ul>
681     <li class="footer">
682       <script type="text/javascript">
683         <!--
684         writeFooter.call(this);
685         //-->
686       </script> 
687     </li>
688   </ul>
689 </div>
690 </body>
691 </html>