xref: /nrf52832-nimble/rt-thread/components/net/uip/doc/html/a00156.html (revision 104654410c56c573564690304ae786df310c91fc)
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
3<title>uIP 1.0: Timer library</title>
4<link href="doxygen.css" rel="stylesheet" type="text/css">
5<link href="tabs.css" rel="stylesheet" type="text/css">
6</head><body>
7<!-- Generated by Doxygen 1.4.6 -->
8<div class="tabs">
9  <ul>
10    <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
11    <li><a href="modules.html"><span>Modules</span></a></li>
12    <li><a href="classes.html"><span>Data&nbsp;Structures</span></a></li>
13    <li><a href="files.html"><span>Files</span></a></li>
14    <li><a href="examples.html"><span>Examples</span></a></li>
15  </ul></div>
16<h1>Timer library</h1><hr><a name="_details"></a><h2>Detailed Description</h2>
17The timer library provides functions for setting, resetting and restarting timers, and for checking if a timer has expired.
18<p>
19An application must "manually" check if its timers have expired; this is not done automatically.<p>
20A timer is declared as a <code>struct</code> <code>timer</code> and all access to the timer is made by a pointer to the declared timer.<p>
21<dl compact><dt><b>Note:</b></dt><dd>The timer library uses the <a class="el" href="a00157.html">Clock library</a> to measure time. Intervals should be specified in the format used by the clock library. </dd></dl>
22
23<p>
24<table border="0" cellpadding="0" cellspacing="0">
25<tr><td></td></tr>
26<tr><td colspan="2"><br><h2>Files</h2></td></tr>
27<tr><td class="memItemLeft" nowrap align="right" valign="top">file &nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00130.html">timer.h</a></td></tr>
28
29<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Timer library header file. <br></td></tr>
30
31<p>
32<tr><td class="memItemLeft" nowrap align="right" valign="top">file &nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00129.html">timer.c</a></td></tr>
33
34<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Timer library implementation. <br></td></tr>
35
36<p>
37<tr><td colspan="2"><br><h2>Data Structures</h2></td></tr>
38<tr><td class="memItemLeft" nowrap align="right" valign="top">struct &nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00087.html">timer</a></td></tr>
39
40<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">A timer.  <a href="a00087.html#_details">More...</a><br></td></tr>
41<tr><td colspan="2"><br><h2>Functions</h2></td></tr>
42<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00156.html#g6614d96fdfcd95c95ec6e6f63071ff51">timer_set</a> (struct <a class="el" href="a00087.html">timer</a> *t, clock_time_t interval)</td></tr>
43
44<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Set a timer.  <a href="#g6614d96fdfcd95c95ec6e6f63071ff51"></a><br></td></tr>
45<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00156.html#gedaf3e48c2b04229b85455fb948468d6">timer_reset</a> (struct <a class="el" href="a00087.html">timer</a> *t)</td></tr>
46
47<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Reset the timer with the same interval.  <a href="#gedaf3e48c2b04229b85455fb948468d6"></a><br></td></tr>
48<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00156.html#gcb807bd57e5489b386b876af5c1f163a">timer_restart</a> (struct <a class="el" href="a00087.html">timer</a> *t)</td></tr>
49
50<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Restart the timer from the current point in time.  <a href="#gcb807bd57e5489b386b876af5c1f163a"></a><br></td></tr>
51<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00156.html#g6d71dececfce707c668e6257aad5906e">timer_expired</a> (struct <a class="el" href="a00087.html">timer</a> *t)</td></tr>
52
53<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Check if a timer has expired.  <a href="#g6d71dececfce707c668e6257aad5906e"></a><br></td></tr>
54</table>
55<hr><h2>Function Documentation</h2>
56<a class="anchor" name="g6d71dececfce707c668e6257aad5906e"></a><!-- doxytag: member="timer.h::timer_expired" ref="g6d71dececfce707c668e6257aad5906e" args="(struct timer *t)" --><p>
57<table class="mdTable" cellpadding="2" cellspacing="0">
58  <tr>
59    <td class="mdRow">
60      <table cellpadding="0" cellspacing="0" border="0">
61        <tr>
62          <td class="md" nowrap valign="top">int timer_expired           </td>
63          <td class="md" valign="top">(&nbsp;</td>
64          <td class="md" nowrap valign="top">struct <a class="el" href="a00087.html">timer</a> *&nbsp;</td>
65          <td class="mdname1" valign="top" nowrap> <em>t</em>          </td>
66          <td class="md" valign="top">&nbsp;)&nbsp;</td>
67          <td class="md" nowrap></td>
68        </tr>
69      </table>
70    </td>
71  </tr>
72</table>
73<table cellspacing="5" cellpadding="0" border="0">
74  <tr>
75    <td>
76      &nbsp;
77    </td>
78    <td>
79
80<p>
81Check if a timer has expired.
82<p>
83This function tests if a timer has expired and returns true or false depending on its status.<p>
84<dl compact><dt><b>Parameters:</b></dt><dd>
85  <table border="0" cellspacing="2" cellpadding="0">
86    <tr><td valign="top"></td><td valign="top"><em>t</em>&nbsp;</td><td>A pointer to the timer</td></tr>
87  </table>
88</dl>
89<dl compact><dt><b>Returns:</b></dt><dd>Non-zero if the timer has expired, zero otherwise. </dd></dl>
90<dl compact><dt><b>Examples: </b></dt><dd>
91<a class="el" href="a00048.html#a26">dhcpc.c</a>, <a class="el" href="a00042.html#a77">example-mainloop-with-arp.c</a>, and <a class="el" href="a00043.html#a94">example-mainloop-without-arp.c</a>.</dl>
92<p>
93Definition at line <a class="el" href="a00195.html#l00121">121</a> of file <a class="el" href="a00195.html">timer.c</a>.
94<p>
95References <a class="el" href="a00157.html#ge5b7160f2e653725ba5e2024c3cb7bff">clock_time()</a>, <a class="el" href="a00196.html#l00076">interval</a>, and <a class="el" href="a00196.html#l00075">start</a>.    </td>
96  </tr>
97</table>
98<a class="anchor" name="gedaf3e48c2b04229b85455fb948468d6"></a><!-- doxytag: member="timer.h::timer_reset" ref="gedaf3e48c2b04229b85455fb948468d6" args="(struct timer *t)" --><p>
99<table class="mdTable" cellpadding="2" cellspacing="0">
100  <tr>
101    <td class="mdRow">
102      <table cellpadding="0" cellspacing="0" border="0">
103        <tr>
104          <td class="md" nowrap valign="top">void timer_reset           </td>
105          <td class="md" valign="top">(&nbsp;</td>
106          <td class="md" nowrap valign="top">struct <a class="el" href="a00087.html">timer</a> *&nbsp;</td>
107          <td class="mdname1" valign="top" nowrap> <em>t</em>          </td>
108          <td class="md" valign="top">&nbsp;)&nbsp;</td>
109          <td class="md" nowrap></td>
110        </tr>
111      </table>
112    </td>
113  </tr>
114</table>
115<table cellspacing="5" cellpadding="0" border="0">
116  <tr>
117    <td>
118      &nbsp;
119    </td>
120    <td>
121
122<p>
123Reset the timer with the same interval.
124<p>
125This function resets the timer with the same interval that was given to the <a class="el" href="a00156.html#g6614d96fdfcd95c95ec6e6f63071ff51">timer_set()</a> function. The start point of the interval is the exact time that the timer last expired. Therefore, this function will cause the timer to be stable over time, unlike the timer_rester() function.<p>
126<dl compact><dt><b>Parameters:</b></dt><dd>
127  <table border="0" cellspacing="2" cellpadding="0">
128    <tr><td valign="top"></td><td valign="top"><em>t</em>&nbsp;</td><td>A pointer to the timer.</td></tr>
129  </table>
130</dl>
131<dl compact><dt><b>See also:</b></dt><dd><a class="el" href="a00156.html#gcb807bd57e5489b386b876af5c1f163a">timer_restart()</a> </dd></dl>
132<dl compact><dt><b>Examples: </b></dt><dd>
133<a class="el" href="a00042.html#a78">example-mainloop-with-arp.c</a>, and <a class="el" href="a00043.html#a95">example-mainloop-without-arp.c</a>.</dl>
134<p>
135Definition at line <a class="el" href="a00195.html#l00084">84</a> of file <a class="el" href="a00195.html">timer.c</a>.
136<p>
137References <a class="el" href="a00196.html#l00076">interval</a>, and <a class="el" href="a00196.html#l00075">start</a>.    </td>
138  </tr>
139</table>
140<a class="anchor" name="gcb807bd57e5489b386b876af5c1f163a"></a><!-- doxytag: member="timer.h::timer_restart" ref="gcb807bd57e5489b386b876af5c1f163a" args="(struct timer *t)" --><p>
141<table class="mdTable" cellpadding="2" cellspacing="0">
142  <tr>
143    <td class="mdRow">
144      <table cellpadding="0" cellspacing="0" border="0">
145        <tr>
146          <td class="md" nowrap valign="top">void timer_restart           </td>
147          <td class="md" valign="top">(&nbsp;</td>
148          <td class="md" nowrap valign="top">struct <a class="el" href="a00087.html">timer</a> *&nbsp;</td>
149          <td class="mdname1" valign="top" nowrap> <em>t</em>          </td>
150          <td class="md" valign="top">&nbsp;)&nbsp;</td>
151          <td class="md" nowrap></td>
152        </tr>
153      </table>
154    </td>
155  </tr>
156</table>
157<table cellspacing="5" cellpadding="0" border="0">
158  <tr>
159    <td>
160      &nbsp;
161    </td>
162    <td>
163
164<p>
165Restart the timer from the current point in time.
166<p>
167This function restarts a timer with the same interval that was given to the <a class="el" href="a00156.html#g6614d96fdfcd95c95ec6e6f63071ff51">timer_set()</a> function. The timer will start at the current time.<p>
168<dl compact><dt><b>Note:</b></dt><dd>A periodic timer will drift if this function is used to reset it. For preioric timers, use the <a class="el" href="a00156.html#gedaf3e48c2b04229b85455fb948468d6">timer_reset()</a> function instead.</dd></dl>
169<dl compact><dt><b>Parameters:</b></dt><dd>
170  <table border="0" cellspacing="2" cellpadding="0">
171    <tr><td valign="top"></td><td valign="top"><em>t</em>&nbsp;</td><td>A pointer to the timer.</td></tr>
172  </table>
173</dl>
174<dl compact><dt><b>See also:</b></dt><dd><a class="el" href="a00156.html#gedaf3e48c2b04229b85455fb948468d6">timer_reset()</a> </dd></dl>
175
176<p>
177Definition at line <a class="el" href="a00195.html#l00104">104</a> of file <a class="el" href="a00195.html">timer.c</a>.
178<p>
179References <a class="el" href="a00157.html#ge5b7160f2e653725ba5e2024c3cb7bff">clock_time()</a>, and <a class="el" href="a00196.html#l00075">start</a>.    </td>
180  </tr>
181</table>
182<a class="anchor" name="g6614d96fdfcd95c95ec6e6f63071ff51"></a><!-- doxytag: member="timer.h::timer_set" ref="g6614d96fdfcd95c95ec6e6f63071ff51" args="(struct timer *t, clock_time_t interval)" --><p>
183<table class="mdTable" cellpadding="2" cellspacing="0">
184  <tr>
185    <td class="mdRow">
186      <table cellpadding="0" cellspacing="0" border="0">
187        <tr>
188          <td class="md" nowrap valign="top">void timer_set           </td>
189          <td class="md" valign="top">(&nbsp;</td>
190          <td class="md" nowrap valign="top">struct <a class="el" href="a00087.html">timer</a> *&nbsp;</td>
191          <td class="mdname" nowrap> <em>t</em>, </td>
192        </tr>
193        <tr>
194          <td class="md" nowrap align="right"></td>
195          <td class="md"></td>
196          <td class="md" nowrap>clock_time_t&nbsp;</td>
197          <td class="mdname" nowrap> <em>interval</em></td>
198        </tr>
199        <tr>
200          <td class="md"></td>
201          <td class="md">)&nbsp;</td>
202          <td class="md" colspan="2"></td>
203        </tr>
204      </table>
205    </td>
206  </tr>
207</table>
208<table cellspacing="5" cellpadding="0" border="0">
209  <tr>
210    <td>
211      &nbsp;
212    </td>
213    <td>
214
215<p>
216Set a timer.
217<p>
218This function is used to set a timer for a time sometime in the future. The function <a class="el" href="a00156.html#g6d71dececfce707c668e6257aad5906e">timer_expired()</a> will evaluate to true after the timer has expired.<p>
219<dl compact><dt><b>Parameters:</b></dt><dd>
220  <table border="0" cellspacing="2" cellpadding="0">
221    <tr><td valign="top"></td><td valign="top"><em>t</em>&nbsp;</td><td>A pointer to the timer </td></tr>
222    <tr><td valign="top"></td><td valign="top"><em>interval</em>&nbsp;</td><td>The interval before the timer expires. </td></tr>
223  </table>
224</dl>
225<dl compact><dt><b>Examples: </b></dt><dd>
226<a class="el" href="a00048.html#a22">dhcpc.c</a>, <a class="el" href="a00042.html#a62">example-mainloop-with-arp.c</a>, and <a class="el" href="a00043.html#a86">example-mainloop-without-arp.c</a>.</dl>
227<p>
228Definition at line <a class="el" href="a00195.html#l00064">64</a> of file <a class="el" href="a00195.html">timer.c</a>.
229<p>
230References <a class="el" href="a00157.html#ge5b7160f2e653725ba5e2024c3cb7bff">clock_time()</a>, <a class="el" href="a00196.html#l00076">interval</a>, and <a class="el" href="a00196.html#l00075">start</a>.    </td>
231  </tr>
232</table>
233<hr size="1"><address style="align: right;"><small>Generated on Mon Jun 12 10:23:02 2006 for uIP 1.0 by&nbsp;
234<a href="http://www.doxygen.org/index.html">
235<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.6 </small></address>
236</body>
237</html>
238