summaryrefslogtreecommitdiffstats
path: root/ucs2-lib/doc/html/_p__u_m__s_t_a_r_t_e_d__s_r_v.html
blob: 7c1d6ee6db094e70471ad4e0b3b6905da680f1a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>UNICENS: Service</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="style_html.css" rel="stylesheet" type="text/css" />
<link href="inic.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div class="GlobalWrapper">
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr>
  <td><a href="index.html"><img alt="Logo" src="logo.png"/></a></td>
  <td>
   <div id="projectname">UNICENS&#160;<span id="projectnumber">V2.1.0-3491</span></div>
   <div id="projectbrief">User Manual and API Reference</div>
    <div id="searchbox">        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.2 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('_p__u_m__s_t_a_r_t_e_d__s_r_v.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">Service </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><h1>Initialization and Service</h1>
<p>In order to initialize the UNICENS library the application shall call <a class="el" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v_ga64b50780725a0dc8693b5b73f8345ad6.html#ga64b50780725a0dc8693b5b73f8345ad6" title="Assigns default values to a provided UNICENS init structure.">Ucs_SetDefaultConfig()</a>, modify the initialization structure and call <a class="el" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v_gaea8d7735d41853167a2befdc06febe43.html#gaea8d7735d41853167a2befdc06febe43" title="UNICENS initialization function.">Ucs_Init()</a>.<br/>
</p>
<p>After calling <a class="el" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v_gaea8d7735d41853167a2befdc06febe43.html#gaea8d7735d41853167a2befdc06febe43" title="UNICENS initialization function.">Ucs_Init()</a> the application is allowed to call the Basic API functions of the UNICENS library. The Basic API functions are required to drive the API. It is responsible to update timers and process internal events. The following functions are Basic API functions:</p>
<ul>
<li><a class="el" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v_ga649fb9128df6f634fc86aa03b374d822.html#ga649fb9128df6f634fc86aa03b374d822" title="The application must call this function cyclically to drive UNICENS.">Ucs_Service()</a></li>
<li><a class="el" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v_ga369c86a27ffee30a3af3423f6b3f3e59.html#ga369c86a27ffee30a3af3423f6b3f3e59" title="The application must call this function if the application timer expires.">Ucs_ReportTimeout()</a></li>
</ul>
<p>When the <a class="el" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v_gaea8d7735d41853167a2befdc06febe43.html#gaea8d7735d41853167a2befdc06febe43" title="UNICENS initialization function.">Ucs_Init()</a> result callback notifies <a class="el" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v___t_y_p_e_s_ga0a933f34b9acbf21dc68f426c324e78c.html#gga0a933f34b9acbf21dc68f426c324e78cac4d2785b5c79a9b38389e08d30494714">UCS_INIT_RES_SUCCESS</a>, then the application is allowed to call the Basic API and all other API functions. After the UNICENS API notifies termination the application shall not call any API function but restart from scratch if required.</p>
<p>The following events will terminate the UNICENS API:</p>
<ul>
<li><a class="el" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v_gaea8d7735d41853167a2befdc06febe43.html#gaea8d7735d41853167a2befdc06febe43" title="UNICENS initialization function.">Ucs_Init()</a> returns an error code</li>
<li><a class="el" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v_gaea8d7735d41853167a2befdc06febe43.html#gaea8d7735d41853167a2befdc06febe43" title="UNICENS initialization function.">Ucs_Init()</a> callback result is not <a class="el" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v___t_y_p_e_s_ga0a933f34b9acbf21dc68f426c324e78c.html#gga0a933f34b9acbf21dc68f426c324e78cac4d2785b5c79a9b38389e08d30494714">UCS_INIT_RES_SUCCESS</a></li>
<li>The <a class="el" href="struct_ucs___general___init_data__t.html">general.error_fptr()</a> is invoked</li>
<li><a class="el" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v_ga61381bd30fb6630b6c5d6ecc8968e983.html#ga61381bd30fb6630b6c5d6ecc8968e983" title="Terminates the execution of UNICENS.">Ucs_Stop()</a> callback is invoked</li>
</ul>
<h1>Main Loop Service</h1>
<p>The most easiest and robust way of driving the UNICENS library is to call <a class="el" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v_gaea8d7735d41853167a2befdc06febe43.html#gaea8d7735d41853167a2befdc06febe43" title="UNICENS initialization function.">Ucs_Init()</a> to initialize the API and call <a class="el" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v_ga649fb9128df6f634fc86aa03b374d822.html#ga649fb9128df6f634fc86aa03b374d822" title="The application must call this function cyclically to drive UNICENS.">Ucs_Service()</a> as long as the UNICENS library is running. If <a class="el" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v_ga649fb9128df6f634fc86aa03b374d822.html#ga649fb9128df6f634fc86aa03b374d822" title="The application must call this function cyclically to drive UNICENS.">Ucs_Service()</a> does not require to process internal events it returns and will consume few CPU load.</p>
<div class="fragment"><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">void</span>)</div>
<div class="line">{</div>
<div class="line">    <span class="keywordtype">bool</span> running = <span class="keyword">true</span>;</div>
<div class="line"></div>
<div class="line">    <a class="code" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v_ga64b50780725a0dc8693b5b73f8345ad6.html#ga64b50780725a0dc8693b5b73f8345ad6" title="Assigns default values to a provided UNICENS init structure.">Ucs_SetDefaultConfig</a>(<span class="comment">/*...*/</span>);</div>
<div class="line">    <span class="comment">/*  ...                             &lt;- modify initialization structure here */</span></div>
<div class="line">    <a class="code" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v_gaea8d7735d41853167a2befdc06febe43.html#gaea8d7735d41853167a2befdc06febe43" title="UNICENS initialization function.">Ucs_Init</a>(<span class="comment">/*...*/</span>);</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">while</span> (running)</div>
<div class="line">    {</div>
<div class="line">        <a class="code" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v_ga649fb9128df6f634fc86aa03b374d822.html#ga649fb9128df6f634fc86aa03b374d822" title="The application must call this function cyclically to drive UNICENS.">Ucs_Service</a>();</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
</div><!-- fragment --><dl class="section attention"><dt>Attention</dt><dd>The initialization function <a class="el" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v_gaea8d7735d41853167a2befdc06febe43.html#gaea8d7735d41853167a2befdc06febe43" title="UNICENS initialization function.">Ucs_Init()</a> must be called before the first execution of <a class="el" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v_ga649fb9128df6f634fc86aa03b374d822.html#ga649fb9128df6f634fc86aa03b374d822" title="The application must call this function cyclically to drive UNICENS.">Ucs_Service()</a>.</dd></dl>
<p>The UNICENS library can deal also with delays of 10 milliseconds or more between two calls of <a class="el" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v_ga649fb9128df6f634fc86aa03b374d822.html#ga649fb9128df6f634fc86aa03b374d822" title="The application must call this function cyclically to drive UNICENS.">Ucs_Service()</a>. Although, the UNICENS library can reach high performance results (for delays &lt;= 10ms). However, depending on the LLD and system design the use of delays between two <a class="el" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v_ga649fb9128df6f634fc86aa03b374d822.html#ga649fb9128df6f634fc86aa03b374d822" title="The application must call this function cyclically to drive UNICENS.">Ucs_Service()</a> calls will mean that an application may also increase the number of LLD Tx and Rx buffer for the communication with the INIC. It is recommended to run individual tests with high and low message load to find a balanced setup.<br/>
<br/>
 A good compromise to balance a system can be the following approach:</p>
<ul>
<li>Call <a class="el" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v_ga649fb9128df6f634fc86aa03b374d822.html#ga649fb9128df6f634fc86aa03b374d822" title="The application must call this function cyclically to drive UNICENS.">Ucs_Service()</a> every 10ms</li>
<li>Call <a class="el" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v_ga649fb9128df6f634fc86aa03b374d822.html#ga649fb9128df6f634fc86aa03b374d822" title="The application must call this function cyclically to drive UNICENS.">Ucs_Service()</a> after the LLD has forwarded Rx messages to UNICENS library</li>
<li>Call <a class="el" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v_ga649fb9128df6f634fc86aa03b374d822.html#ga649fb9128df6f634fc86aa03b374d822" title="The application must call this function cyclically to drive UNICENS.">Ucs_Service()</a> after calling an API function (excluding Basic API functions)</li>
</ul>
<p><a class="anchor" id="P_UM_ADVANCED_SERVICE"></a> </p>
<h1>Event Driven Service</h1>
<p>A more efficient way of driving the UNICENS library is the <em>Event Driven Service</em>. In this mode the UNICENS library signals to the application when the next Service or Timer must be processed. Hence, the application can invoke the UNICENS API only if required. This decreases the CPU usage of UNICENS library to a minimum.</p>
<p>In order to run the <em>Event Driven Service</em> mode of the UNICENS library, the application must assign the following two callback functions in the initialization structure: <a class="el" href="struct_ucs___general___init_data__t.html">general.request_service_fptr()</a> and <a class="el" href="struct_ucs___general___init_data__t.html">general.set_application_timer_fptr()</a>. It is required that the application assigns both events callback functions. Otherwise, <a class="el" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v_gaea8d7735d41853167a2befdc06febe43.html#gaea8d7735d41853167a2befdc06febe43" title="UNICENS initialization function.">Ucs_Init()</a> will return <a class="el" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v___t_y_p_e_s_ga886138f5d13e84ffaa3df5769830e1cd.html#gga886138f5d13e84ffaa3df5769830e1cdab98b74c51324859f3138fed96afd1573">UCS_RET_ERR_PARAM</a>.</p>
<p>A small example for <em>Event Driven Service</em> is printed below.</p>
<div class="fragment"><div class="line"><span class="keyword">static</span> <span class="keywordtype">bool</span> event_timeout = <span class="keyword">false</span>;</div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">bool</span> event_service = <span class="keyword">false</span>;</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">void</span>)</div>
<div class="line">{</div>
<div class="line">    <span class="keywordtype">bool</span> running = <span class="keyword">false</span>;</div>
<div class="line">    <a class="code" href="struct_ucs___init_data__t.html" title="UNICENS initialization structure used by function Ucs_Init().">Ucs_InitData_t</a> init_data;</div>
<div class="line">    <a class="code" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v_ga64b50780725a0dc8693b5b73f8345ad6.html#ga64b50780725a0dc8693b5b73f8345ad6" title="Assigns default values to a provided UNICENS init structure.">Ucs_SetDefaultConfig</a>(&amp;init_data);                                   <span class="comment">/* assign default configuration */</span></div>
<div class="line"></div>
<div class="line">    init_data.<a class="code" href="struct_ucs___init_data__t_a43e7559dfe1bc2860cb0d2749fa66071.html#a43e7559dfe1bc2860cb0d2749fa66071" title="General initialization data.">general</a>.<a class="code" href="struct_ucs___general___init_data__t_a7d2541cf63dfcea750c0d0ec2ef563c0.html#a7d2541cf63dfcea750c0d0ec2ef563c0" title="Callback function requesting the application to call Ucs_Service(). Mandatory callback function in ev...">request_service_fptr</a> = &amp;App_OnServiceRequest;     <span class="comment">/* assign SERVICE event callback functions */</span></div>
<div class="line">    init_data.<a class="code" href="struct_ucs___init_data__t_a43e7559dfe1bc2860cb0d2749fa66071.html#a43e7559dfe1bc2860cb0d2749fa66071" title="General initialization data.">general</a>.<a class="code" href="struct_ucs___general___init_data__t_a9de73ec82699e45173702e9b0ccc917a.html#a9de73ec82699e45173702e9b0ccc917a" title="Callback function requesting the application to call Ucs_ReportTimeout() after a certain time...">set_application_timer_fptr</a> = &amp;App_OnSetAppTimer;  <span class="comment">/* assign TIMER event callback function */</span></div>
<div class="line">    init_data.<a class="code" href="struct_ucs___init_data__t_a43e7559dfe1bc2860cb0d2749fa66071.html#a43e7559dfe1bc2860cb0d2749fa66071" title="General initialization data.">general</a>.<a class="code" href="struct_ucs___general___init_data__t_a4e1140be3951f0e14d4071840f4ebc8e.html#a4e1140be3951f0e14d4071840f4ebc8e" title="Mandatory callback function querying the actual system tick count.">get_tick_count_fptr</a> = App_OnGetTickCount;         <span class="comment">/* tick count requires the same timer </span></div>
<div class="line"><span class="comment">                                                                           reference/resolution as the application timer</span></div>
<div class="line"><span class="comment">                                                                         */</span></div>
<div class="line">    <span class="comment">/* .. further initialization .. */</span></div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">if</span> (Ucs_init(&amp;init_data) == UCS_RET_ERR_SUCCESS)</div>
<div class="line">    {</div>
<div class="line">        running = <span class="keyword">true</span>;</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">while</span> (running)</div>
<div class="line">    {</div>
<div class="line">        Os_WaitForEvent();                                              <span class="comment">/* stop until event occurs */</span></div>
<div class="line"></div>
<div class="line">        <span class="keywordflow">if</span> (event_timeout != <span class="keyword">false</span>)</div>
<div class="line">        {</div>
<div class="line">            event_timeout = <span class="keyword">false</span>;</div>
<div class="line">            <a class="code" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v_ga369c86a27ffee30a3af3423f6b3f3e59.html#ga369c86a27ffee30a3af3423f6b3f3e59" title="The application must call this function if the application timer expires.">Ucs_ReportTimeout</a>();</div>
<div class="line">        }</div>
<div class="line"></div>
<div class="line">        <span class="keywordflow">if</span>(event_service != <span class="keyword">false</span>)</div>
<div class="line">        {</div>
<div class="line">            event_service = <span class="keyword">false</span>;</div>
<div class="line">            <a class="code" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v_ga649fb9128df6f634fc86aa03b374d822.html#ga649fb9128df6f634fc86aa03b374d822" title="The application must call this function cyclically to drive UNICENS.">Ucs_Service</a>();</div>
<div class="line">        }</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
</div><!-- fragment --><p>The implementation of the callback function <code>App_OnServiceRequest()</code> should be rather simply. It must wakeup the process and signal that <a class="el" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v_ga649fb9128df6f634fc86aa03b374d822.html#ga649fb9128df6f634fc86aa03b374d822" title="The application must call this function cyclically to drive UNICENS.">Ucs_Service()</a> must be called.</p>
<div class="fragment"><div class="line"><span class="keywordtype">void</span> App_OnServiceRequest(<span class="keywordtype">void</span>)</div>
<div class="line">{</div>
<div class="line">    event_service = <span class="keyword">true</span>;</div>
<div class="line">    Os_SignalEvent();                                                   <span class="comment">/* wakeup process */</span></div>
<div class="line">}</div>
</div><!-- fragment --><dl class="section note"><dt>Note</dt><dd>During high message load the UNICENS library might also fire a high number of <em>service request</em> events in a short term. Consider that processing UNICENS library events might be at other processes expense. Therefore, balance your system also for high load scenario. During high message load it is acceptable to call <a class="el" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v_ga649fb9128df6f634fc86aa03b374d822.html#ga649fb9128df6f634fc86aa03b374d822" title="The application must call this function cyclically to drive UNICENS.">Ucs_Service()</a> in lower frequency than the <em>service request</em> event is fired by the UNICENS library.</dd></dl>
<p>The implementation of the callback function <code>App_OnSetAppTimer()</code> must consider some particularities.</p>
<ul>
<li>The function is called to <b>start</b> or <b>stop</b> exactly <b>one</b> reference timer. This timer is the smallest timeout value handled by the UNICENS library. During runtime it is possible that internal timers are started or stopped. Hence, it is possible that the UNICENS library stops or restarts the reference timer with a new value before a previously started timer expires.</li>
<li>When the function is called and parameter <code>timeout</code> is "0", the application has to stop the reference timer.</li>
<li>When the function is called and parameter <code>timeout</code> is "&gt;0", the application has to stop the reference timer and restart it with the new value.</li>
<li>It is important that <a class="el" href="struct_ucs___general___init_data__t.html">general.set_application_timer_fptr()</a> and <a class="el" href="struct_ucs___general___init_data__t.html">general.get_tick_count_fptr()</a> are using the <b>same time reference and precision</b>. Otherwise, a tick count with another precision might induce the UNICENS library to start again a timer with a small difference in timeout.</li>
</ul>
<div class="fragment"><div class="line">UINT timer_id = 0U;</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span> CALLBACK App_TimerCb (UINT uTimerID,</div>
<div class="line">                           UINT uMsg,</div>
<div class="line">                           DWORD_PTR dwUser,</div>
<div class="line">                           DWORD_PTR dw1,</div>
<div class="line">                           DWORD_PTR dw2)</div>
<div class="line">{</div>
<div class="line">    timer_id = 0U;                                          <span class="comment">/* mark timer as stopped */</span></div>
<div class="line">    event_timeout = <span class="keyword">true</span>;</div>
<div class="line">    Os_SignalEvent();                                       <span class="comment">/* wakeup process */</span></div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span> App_OnSetAppTimer(uint16_t timeout)</div>
<div class="line">{</div>
<div class="line">    </div>
<div class="line">    <span class="keywordflow">if</span> (timer_id != 0U)                                     <span class="comment">/* stop reference timer if it is still running */</span></div>
<div class="line">    {</div>
<div class="line">        (void)timeKillEvent(timer_id);</div>
<div class="line">        timer_id = 0U;</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">if</span> (timeout != 0U)                                      <span class="comment">/* start reference timer with the given timeout value */</span></div>
<div class="line">    {</div>
<div class="line">        timer_id = timeSetEvent((UINT)timeout,</div>
<div class="line">                                (UINT)1,</div>
<div class="line">                                &amp;App_TimerCb,</div>
<div class="line">                                (DWORD_PTR)0,</div>
<div class="line">                                (UINT)TIME_ONESHOT);</div>
<div class="line">   }</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line">uint16_t App_OnGetTickCount(<span class="keywordtype">void</span>)</div>
<div class="line">{</div>
<div class="line">    <span class="keywordflow">return</span> (uint16_t)timeGetTime();                         <span class="comment">/* retrieve current tick count */</span></div>
<div class="line">}</div>
</div><!-- fragment --> </div></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">&copy; 2017 Microchip Technology Inc. All rights reserved. <a href="http://www.microchip.com" target="_blank">www.microchip.com</a></li>
  </ul>
</div>
</body>
<!--
Generated on Mon Apr 3 2017 13:52:59 for UNICENS by
Doxygen 1.8.2
-->
<script language="javascript">
<!--
$('#MSearchResults').wrap('<div style="position: absolute; margin-left: 444px;"></div>');
-->
</script>
</html>