aboutsummaryrefslogtreecommitdiffstats
path: root/ucs2-lib/doc/html/_p__u_m__s_t_a_r_t_e_d__l_l_d.html
blob: 97949938d596f36cd4de4b5c4c2d84acf25552b4 (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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<!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: Low-Level Driver</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__l_l_d.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">Low-Level Driver </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><h1>Introduction</h1>
<p>The low-level driver (LLD) is responsible to forward Tx messages from the UNICENS library to the INIC and Rx messages from the INIC to the UNICENS library. The UNICENS library currently provides one interface to exchange control messages with the INIC. Therefore, the control messages will be wrapped in a so called Port Message. The low-level driver is responsible to transmit and receive the Port Messages over the interface that is adjusted in the INIC Configuration String.</p>
<p><a class="anchor" id="A_GS_LLD_CONFIG"></a> </p>
<h1>Initialization</h1>
<p>The following example shows how to assign low-level driver functions which are invoked by the UNICENS library.</p>
<div class="fragment"><div class="line"><span class="keywordtype">bool</span> Initialize(<span class="keywordtype">void</span>)</div>
<div class="line">{</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"></div>
<div class="line">    <span class="comment">/* platform specific initialization of the low-level driver */</span></div>
<div class="line">    Lld_SysInitialize(<span class="comment">/*system specific parameters*/</span>);</div>
<div class="line"></div>
<div class="line">    <span class="comment">/* assign init data */</span></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);</div>
<div class="line">    init_data.<a class="code" href="struct_ucs___init_data__t_ac0b0a4478bafe6e81ed3c3e2c72f4fc9.html#ac0b0a4478bafe6e81ed3c3e2c72f4fc9" title="Comprises assignment to low-level driver communication interfaces.">lld</a>.<a class="code" href="struct_ucs___lld___callbacks__t_a96bad24b6b49ffacfd9136230447cb22.html#a96bad24b6b49ffacfd9136230447cb22" title="Callback function to initialize the low-level driver and start the transmission and reception of mess...">start_fptr</a> = &amp;Lld_Start;</div>
<div class="line">    init_data.<a class="code" href="struct_ucs___init_data__t_ac0b0a4478bafe6e81ed3c3e2c72f4fc9.html#ac0b0a4478bafe6e81ed3c3e2c72f4fc9" title="Comprises assignment to low-level driver communication interfaces.">lld</a>.<a class="code" href="struct_ucs___lld___callbacks__t_ab0f955ca90942fda14ac12500422a437.html#ab0f955ca90942fda14ac12500422a437" title="Callback function to stop/abort the transmission and reception of messages.">stop_fptr</a> = &amp;Lld_Stop;</div>
<div class="line">    init_data.<a class="code" href="struct_ucs___init_data__t_ac0b0a4478bafe6e81ed3c3e2c72f4fc9.html#ac0b0a4478bafe6e81ed3c3e2c72f4fc9" title="Comprises assignment to low-level driver communication interfaces.">lld</a>.<a class="code" href="struct_ucs___lld___callbacks__t_ad8f7d021075e06672a999eb02da1d2e4.html#ad8f7d021075e06672a999eb02da1d2e4" title="Callback function to transmit one or multiple messages to the INIC.">tx_transmit_fptr</a> = &amp;Lld_TxTransmit;</div>
<div class="line">    init_data.<a class="code" href="struct_ucs___init_data__t_ac0b0a4478bafe6e81ed3c3e2c72f4fc9.html#ac0b0a4478bafe6e81ed3c3e2c72f4fc9" title="Comprises assignment to low-level driver communication interfaces.">lld</a>.<a class="code" href="struct_ucs___lld___callbacks__t_a90fa6db664734c2446327b71c51f5b52.html#a90fa6db664734c2446327b71c51f5b52" title="Callback function which is invoked as soon as Rx message objects are available again.">rx_available_fptr</a> = &amp;Lld_RxMsgAvailable;</div>
<div class="line">    <span class="comment">/* ... further assignment and initialization ... */</span></div>
<div class="line"></div>
<div class="line">    <span class="comment">/* create one instance of UCS */</span></div>
<div class="line">    inst_ptr = <a class="code" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v_ga85a99b5d236b29e2d598bef51edad638.html#ga85a99b5d236b29e2d598bef51edad638" title="Retrieves a UNICENS API instance.">Ucs_CreateInstance</a>();</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">if</span> (inst_ptr != NULL)</div>
<div class="line">    {</div>
<div class="line">        <span class="keywordflow">if</span> (<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>(inst_ptr, &amp;init_data, &amp;App_OnInitResult) == <a class="code" href="group___g___u_c_s___i_n_i_t___a_n_d___s_r_v___t_y_p_e_s_ga886138f5d13e84ffaa3df5769830e1cd.html#gga886138f5d13e84ffaa3df5769830e1cda3fb51656e17ee4802f23706f35e349bc" title="Operation successfully completed.">UCS_RET_SUCCESS</a>)</div>
<div class="line">        {</div>
<div class="line">            <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line">        }</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line">}</div>
</div><!-- fragment --><table  class="mns_ic_table">
<tr>
<td id="mns_ic_started">&#160;</td><td>See also <em>Getting Started</em>, section <a class="el" href="_p__u_m__s_t_a_r_t_e_d__i_n_i_t.html">Initialization</a>. </td></tr>
</table>
<h1>Local Data</h1>
<p>The exemplary implementation of callback functions refers the following local data. In order to call UNICENS API functions the low-level driver has to store a set of callback functions and an internal handle which is required to invoke a callback function.</p>
<div class="fragment"><div class="line"><span class="preprocessor">#define MAX_DATA_LEN    72            </span><span class="comment">/* messages can be up to 72 bytes */</span><span class="preprocessor"></span></div>
<div class="line"><span class="preprocessor"></span><a class="code" href="struct_ucs___lld___api__t.html" title="Initialization required for one communication channel (control or packet)">Ucs_Lld_Api_t</a> *_cb_ptr;               <span class="comment">/* reference to UCS callback functions */</span></div>
<div class="line"><span class="keywordtype">void</span> *_h_ptr;                         <span class="comment">/* reference to nun-public handler, which */</span></div>
<div class="line">                                      <span class="comment">/* is necessary to invoke callback functions */</span></div>
<div class="line"><span class="keywordtype">bool</span> _rx_event;                       <span class="comment">/* labels if the driver may read an available Rx message */</span></div>
<div class="line"></div>
<div class="line">uint8_t _tx_buffer[MAX_DATA_LEN];</div>
<div class="line">uint8_t _rx_buffer[MAX_DATA_LEN];</div>
</div><!-- fragment --><h1>Start and Stop</h1>
<p>The UNICENS library invokes the mandatory callback functions <code>start_fptr()</code> and <code>stop_fptr()</code> to signal when internal data is valid and the LLD may access UNICENS callback functions and message objects for transmission and reception.</p>
<p>The function <code>Lld_SysInitialize()</code> is not called by the UNICENS library. This example function is system specific and might be necessary to set local data to definite values and to initialize the device driver before UNICENS library will start to transmit and receive.</p>
<p>The low-level driver is allowed to initialize and run the communication with the INIC before the UNICENS Library calls <code>Lld_Start()</code>. While the UNICENS callback functions are invalid, it is recommended to discard incoming Rx messages.</p>
<p>Before leaving the function <code>Lld_Stop()</code> the LLD must ensure not accessing UCS memory and callback functions any longer.</p>
<div class="fragment"><div class="line"><span class="keywordtype">void</span> Lld_SysInitialize(<span class="keywordtype">void</span>)</div>
<div class="line">{</div>
<div class="line">    <span class="comment">/* Initialization: system specific setup of the device driver, trace, queues, interrupts, etc.</span></div>
<div class="line"><span class="comment">       Initialize local data, discard incoming messages from the INIC until Lld_Start() is called.</span></div>
<div class="line"><span class="comment">     */</span></div>
<div class="line">    _rx_event = <span class="keyword">false</span>;</div>
<div class="line">    _api_ptr = NULL;</div>
<div class="line">    _h_ptr = NULL;</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span> Lld_Start(<a class="code" href="struct_ucs___lld___api__t.html" title="Initialization required for one communication channel (control or packet)">Ucs_Lld_Api_t</a>* api_ptr, <span class="keywordtype">void</span> *h_ptr, <span class="keywordtype">void</span> *lld_user_ptr)</div>
<div class="line">{</div>
<div class="line">    <span class="comment">/* UNICENS is ready to transmit and receive.</span></div>
<div class="line"><span class="comment">       Now, remember the callbacks and the handle which is</span></div>
<div class="line"><span class="comment">       required to invoke a callback function.</span></div>
<div class="line"><span class="comment">     */</span></div>
<div class="line">    _api_ptr = api_ptr;</div>
<div class="line">    _h_ptr = inst_ptr;</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span> Lld_Stop(<span class="keywordtype">void</span> *lld_user_ptr)</div>
<div class="line">{</div>
<div class="line">    <span class="comment">/* IMPORTANT: Do no longer invoke any UNICENS callback function and</span></div>
<div class="line"><span class="comment">       immediately stop accessing UNICENS message objects.</span></div>
<div class="line"><span class="comment">       I.e., ensure stopping asynchronous transmission and reception using UNICENS memory</span></div>
<div class="line"><span class="comment">       before leaving this function (e.g., stop/wait DMA copy operations to/from UNICENS memory). </span></div>
<div class="line"><span class="comment">       Incoming messages from the INIC should be discarded until Lld_Start() is called again.</span></div>
<div class="line"><span class="comment">     */</span></div>
<div class="line">    _api_ptr = NULL;</div>
<div class="line">    _h_ptr = NULL;</div>
<div class="line">}</div>
</div><!-- fragment --><h1>Message Transmission</h1>
<p>The low-level driver must implement a transmit function which requires a reference to <a class="el" href="struct_ucs___lld___tx_msg__t.html" title="Tx message object providing the raw port message byte stream.">Ucs_Lld_TxMsg_t</a>. The code section below shows the declaration of the <a class="el" href="struct_ucs___lld___tx_msg__t.html" title="Tx message object providing the raw port message byte stream.">Ucs_Lld_TxMsg_t</a> and the referred <a class="el" href="struct_ucs___mem___buffer__t.html">Ucs_Mem_Buffer_t</a> type. The <a class="el" href="struct_ucs___mem___buffer__t.html">Ucs_Mem_Buffer_t</a> structure contains values to describe the pointer and the size of the buffer. Furthermore it is possible that one buffer refers a second buffer if next_buffer_ptr is set. This means that it is possible to concatenate multiple buffers. Furthermore, one message structure refers a buffer structure. The <code>custom_next_msg_ptr</code> is not set by UNICENS library. It can be used by the Low Level Driver to concatenate messages, e.g. for asynchronous transmission.</p>
<div class="fragment"><div class="line"><span class="keyword">typedef</span> <span class="keyword">struct </span>Ucs_Mem_Buffer_</div>
<div class="line">{</div>
<div class="line">    <span class="keyword">struct </span>Ucs_Mem_Buffer_  *next_buffer_ptr;</div>
<div class="line">    uint8_t                 *data_ptr; </div>
<div class="line">    uint16_t                 data_size; </div>
<div class="line">    uint16_t                 total_size;</div>
<div class="line"> </div>
<div class="line">} <a class="code" href="struct_ucs___mem___buffer__t.html" title="Memory chunk representing a message or part of a message.">Ucs_Mem_Buffer_t</a>;</div>
<div class="line"></div>
<div class="line"><span class="keyword">typedef</span> <span class="keyword">struct </span>Ucs_Lld_TxMsg_</div>
<div class="line">{</div>
<div class="line">    <span class="keyword">struct </span>Ucs_Lld_TxMsg_   *custom_next_msg_ptr; </div>
<div class="line">    <a class="code" href="struct_ucs___mem___buffer__t.html" title="Memory chunk representing a message or part of a message.">Ucs_Mem_Buffer_t</a>        *memory_ptr;</div>
<div class="line"></div>
<div class="line">} <a class="code" href="struct_ucs___lld___tx_msg__t.html" title="Tx message object providing the raw port message byte stream.">Ucs_Lld_TxMsg_t</a>;</div>
</div><!-- fragment --><p>The transmit function shall copy the data from the memory buffers to the target buffer. Therefore, the low-level driver has to iterate over all buffers. After the low-level driver does no longer refer the message object, it has to call <code>tx_release_fptr</code>. It is important to call <code>tx_release_fptr</code> in the same order as the messages are passed to the transmit function.</p>
<div class="fragment"><div class="line"><span class="keywordtype">void</span> Lld_TxTransmit(<a class="code" href="struct_ucs___lld___tx_msg__t.html" title="Tx message object providing the raw port message byte stream.">Ucs_Lld_TxMsg_t</a> *msg_ptr, <span class="keywordtype">void</span> *lld_user_ptr)</div>
<div class="line">{</div>
<div class="line">    <a class="code" href="struct_ucs___mem___buffer__t.html" title="Memory chunk representing a message or part of a message.">Ucs_Mem_Buffer_t</a> * buf_ptr;</div>
<div class="line">    uint16_t i = 0U;                                      <span class="comment">/* index of target buffer*/</span> </div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">if</span> ((msg_ptr != NULL) &amp;&amp; _api_ptr)</div>
<div class="line">    { </div>
<div class="line">        <span class="keywordflow">for</span> (buf_ptr = msg_ptr-&gt;<a class="code" href="struct_ucs___lld___tx_msg__t_a0fae6a3f19d8a9bbdad3c3b1ead3e868.html#a0fae6a3f19d8a9bbdad3c3b1ead3e868" title="Points to the data buffer.">memory_ptr</a>; buf_ptr != NULL; buf_ptr = buf_ptr-&gt;<a class="code" href="struct_ucs___mem___buffer__t_a5245ce4ea7d022a357642b645e7ac645.html#a5245ce4ea7d022a357642b645e7ac645" title="Points to an additional memory buffer that belongs to the same message.">next_buffer_ptr</a>)</div>
<div class="line">        {</div>
<div class="line">            memcpy(&amp;_tx_buffer[i], buf_ptr-&gt;<a class="code" href="struct_ucs___mem___buffer__t_a6166cef59cbe432be35512925debeae6.html#a6166cef59cbe432be35512925debeae6" title="Points to the data buffer.">data_ptr</a>, buf_ptr-&gt;<a class="code" href="struct_ucs___mem___buffer__t_aae6bdbdf6ea1ad3da5af37f0a91d3ea0.html#aae6bdbdf6ea1ad3da5af37f0a91d3ea0" title="Size of the data buffer.">data_size</a>);</div>
<div class="line">            i += buf_ptr-&gt;<a class="code" href="struct_ucs___mem___buffer__t_aae6bdbdf6ea1ad3da5af37f0a91d3ea0.html#aae6bdbdf6ea1ad3da5af37f0a91d3ea0" title="Size of the data buffer.">data_size</a>;</div>
<div class="line">        }</div>
<div class="line">                                                          <span class="comment">/* call synchronous transmit function of driver */</span></div>
<div class="line">        MY_TX(&amp;_tx_buffer[0], msg_ptr-&gt;<a class="code" href="struct_ucs___lld___tx_msg__t_a0fae6a3f19d8a9bbdad3c3b1ead3e868.html#a0fae6a3f19d8a9bbdad3c3b1ead3e868" title="Points to the data buffer.">memory_ptr</a>-&gt;<a class="code" href="struct_ucs___mem___buffer__t_af0c4b4b26e805f939299b203943976b2.html#af0c4b4b26e805f939299b203943976b2" title="Reserved for future use. Size of this and all concatenated data buffers.">total_size</a>);</div>
<div class="line">                                                          <span class="comment">/* release the message object */</span></div>
<div class="line">        _api_ptr-&gt;tx_release_fptr(_h_ptr, msg_ptr);</div>
<div class="line">    }</div>
<div class="line">}</div>
</div><!-- fragment --><dl class="section note"><dt>Note</dt><dd>The transmit function has no return value. This means that the low-level driver itself has to handle asynchronous re-transmission if the interface is busy. Therefore, the Low Level Driver is able to enqueue multiple message objects by using <code>custom_next_msg_ptr</code>. If the LLD detects an unrecoverable transmission error the LLD shall abort the transmission and call <code>tx_release_fptr()</code>.</dd></dl>
<table  class="mns_ic_table">
<tr>
<td id="mns_ic_api">&#160;</td><td>See also <em>API Reference</em>, sections <a class="el" href="group___g___u_c_s___l_l_d.html">Low-Level Driver</a> and <a class="el" href="struct_ucs___lld___api__t.html" title="Initialization required for one communication channel (control or packet)">Ucs_Lld_Api_t</a>. </td></tr>
</table>
<h1>Message Reception</h1>
<p>The low-level driver has to forward messages to the UNICENS library by calling <code>rx_allocate_fptr()</code> and <code>rx_receive_fptr()</code>. The structure of the provided Rx message object is shown in the code section below.</p>
<div class="fragment"><div class="line"><span class="keyword">typedef</span> <span class="keyword">struct</span></div>
<div class="line">{</div>
<div class="line">    uint8_t*        data_ptr;</div>
<div class="line">    uint16_t        data_size;</div>
<div class="line"></div>
<div class="line">} <a class="code" href="struct_ucs___lld___rx_msg__t.html" title="Rx message object pointing to the raw port message byte stream.">Ucs_Lld_RxMsg_t</a>;</div>
</div><!-- fragment --><p>If <code>rx_allocate_fptr()</code> returns a valid reference to a <a class="el" href="struct_ucs___lld___rx_msg__t.html" title="Rx message object pointing to the raw port message byte stream.">Ucs_Lld_RxMsg_t</a> structure, the low-level driver has to copy the received message to the <code>data_ptr</code> attribute. The value of <code>data_size</code> is already set to the same value as initially stated to <code>rx_allocate_fptr()</code>. After the copy operation, the low-level driver shall call <code>rx_receive_fptr()</code> which hands the Rx message over to the UNICENS library.</p>
<div class="fragment"><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> My_RxHandler(<span class="keywordtype">void</span>)</div>
<div class="line">{</div>
<div class="line">    <span class="keywordflow">if</span> (_rx_event != <span class="keyword">false</span>)</div>
<div class="line">    {</div>
<div class="line">        <span class="keywordtype">bool</span> success = <span class="keyword">false</span>;</div>
<div class="line">        uint16_t size = 0;</div>
<div class="line">                                        <span class="comment">/* receive to LLD provided buffer */</span></div>
<div class="line">        success = MY_RX(&amp;_rx_buffer[0], &amp;size);</div>
<div class="line"></div>
<div class="line">                                        <span class="comment">/* check if UNICENS is running and message is ok */</span></div>
<div class="line">        <span class="keywordflow">if</span> ((_api_ptr != NULL) &amp;&amp; (success != <span class="keyword">false</span>) &amp;&amp; (size &lt; MAX_DATA_LEN))</div>
<div class="line">        {</div>
<div class="line">            <a class="code" href="struct_ucs___lld___rx_msg__t.html" title="Rx message object pointing to the raw port message byte stream.">Ucs_Lld_RxMsg_t</a> *msg_ptr;</div>
<div class="line">                                        <span class="comment">/* allocate message object from UCS */</span></div>
<div class="line">            msg_ptr = _api_ptr-&gt;rx_allocate_fptr(_h_ptr, size);</div>
<div class="line"></div>
<div class="line">            <span class="keywordflow">if</span> (msg_ptr != NULL)</div>
<div class="line">            {</div>
<div class="line">                uint16_t i;</div>
<div class="line"></div>
<div class="line">                <span class="keywordflow">for</span> (i=0; i&lt;size; i++)</div>
<div class="line">                {                       <span class="comment">/* copy data to UCS message object */</span></div>
<div class="line">                    msg_ptr-&gt;<a class="code" href="struct_ucs___lld___rx_msg__t_a6166cef59cbe432be35512925debeae6.html#a6166cef59cbe432be35512925debeae6" title="Points to a UNICENS allocated memory chunk.">data_ptr</a>[i] = _rx_buffer[i]; </div>
<div class="line">                }</div>
<div class="line">                                        <span class="comment">/* pass message object to UCS */</span></div>
<div class="line">                _api_ptr-&gt;rx_receive_fptr(_h_ptr, msg_ptr);</div>
<div class="line">            }</div>
<div class="line">            <span class="keywordflow">else</span></div>
<div class="line">            {</div>
<div class="line">                <span class="comment">/* wait until Lld_RxMsgAvailable() is invoked */</span></div>
<div class="line">            }</div>
<div class="line">        }</div>
<div class="line">        <span class="keywordflow">else</span></div>
<div class="line">        {</div>
<div class="line">            <span class="comment">/* discard Rx message - since UCS is not running */</span> </div>
<div class="line">        }</div>
<div class="line">    }</div>
<div class="line">}</div>
</div><!-- fragment --><table  class="mns_ic_table">
<tr>
<td id="mns_ic_api">&#160;</td><td>See also <em>API Reference</em>, sections <a class="el" href="group___g___u_c_s___l_l_d.html">Low-Level Driver</a> and <a class="el" href="struct_ucs___lld___api__t.html" title="Initialization required for one communication channel (control or packet)">Ucs_Lld_Api_t</a>. </td></tr>
</table>
</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>