blob: 00604012bde7993b86ee0237e352596e054fc3c6 [file] [log] [blame]
<!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"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>lwIP: Zero-copy RX</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<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="navtreedata.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/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">lwIP
&#160;<span id="projectnumber">2.1.2</span>
</div>
<div id="projectbrief">Lightweight IP stack</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</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('zerocopyrx.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)">
</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">Zero-copy RX </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>The following code is an example for zero-copy RX ethernet driver: </p><div class="fragment"><div class="line"><span class="keyword">typedef</span> <span class="keyword">struct </span>my_custom_pbuf</div><div class="line">{</div><div class="line"> <span class="keyword">struct </span><a class="code" href="structpbuf__custom.html">pbuf_custom</a> p;</div><div class="line"> <span class="keywordtype">void</span>* dma_descriptor;</div><div class="line">} my_custom_pbuf_t;</div><div class="line"></div><div class="line"><a class="code" href="group__mempool.html#ga5b1fb3ce7942432d87cc948b1c5ed6cb">LWIP_MEMPOOL_DECLARE</a>(RX_POOL, 10, <span class="keyword">sizeof</span>(my_custom_pbuf_t), <span class="stringliteral">&quot;Zero-copy RX PBUF pool&quot;</span>);</div><div class="line"></div><div class="line"><span class="keywordtype">void</span> my_pbuf_free_custom(<span class="keywordtype">void</span>* p)</div><div class="line">{</div><div class="line"> <a class="code" href="group__sys__prot.html#ga945395fa326214fc9736487242710a90">SYS_ARCH_DECL_PROTECT</a>(old_level);</div><div class="line"></div><div class="line"> my_custom_pbuf_t* my_puf = (my_custom_pbuf_t*)p;</div><div class="line"></div><div class="line"> <span class="comment">// invalidate data cache here - lwIP and/or application may have written into buffer!</span></div><div class="line"> <span class="comment">// (invalidate is faster than flushing, and noone needs the correct data in the buffer)</span></div><div class="line"> invalidate_cpu_cache(p-&gt;payload, p-&gt;tot_len);</div><div class="line"></div><div class="line"> <a class="code" href="group__sys__prot.html#ga3d0e48feafd378e9c26c64567ecd8bab">SYS_ARCH_PROTECT</a>(old_level);</div><div class="line"> free_rx_dma_descriptor(my_pbuf-&gt;dma_descriptor);</div><div class="line"> <a class="code" href="group__mempool.html#gaa43d114dd702fbd8f1db18474ea93a04">LWIP_MEMPOOL_FREE</a>(RX_POOL, my_pbuf);</div><div class="line"> <a class="code" href="group__sys__prot.html#ga2f48e97047945642ddeb27e65bf4ffe2">SYS_ARCH_UNPROTECT</a>(old_level);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">void</span> eth_rx_irq()</div><div class="line">{</div><div class="line"> dma_descriptor* dma_desc = get_RX_DMA_descriptor_from_ethernet();</div><div class="line"> my_custom_pbuf_t* my_pbuf = (my_custom_pbuf_t*)<a class="code" href="group__mempool.html#ga5e2498f6c17746c1fe7153de5f7f275a">LWIP_MEMPOOL_ALLOC</a>(RX_POOL);</div><div class="line"></div><div class="line"> my_pbuf-&gt;p.custom_free_function = my_pbuf_free_custom;</div><div class="line"> my_pbuf-&gt;dma_descriptor = dma_desc;</div><div class="line"></div><div class="line"> invalidate_cpu_cache(dma_desc-&gt;rx_data, dma_desc-&gt;rx_length);</div><div class="line"> </div><div class="line"> <span class="keyword">struct </span><a class="code" href="structpbuf.html">pbuf</a>* p = <a class="code" href="group__pbuf.html#ga90fa2bbf6ea4a263ee8f7b77c75683c2">pbuf_alloced_custom</a>(<a class="code" href="group__pbuf.html#ggaee1baa59bb2f85ba575b5a8619ac1ebfa21116654fbab6d5a4dfeb87a1bb8f0ba">PBUF_RAW</a>,</div><div class="line"> dma_desc-&gt;rx_length,</div><div class="line"> <a class="code" href="group__pbuf.html#ggab7e0e32fcc292c0d7107721766ed92fbac9b6ba960fdea6f2e8f35c8313b77e4e">PBUF_REF</a>,</div><div class="line"> &amp;my_pbuf-&gt;p,</div><div class="line"> dma_desc-&gt;rx_data,</div><div class="line"> dma_desc-&gt;max_buffer_size);</div><div class="line"></div><div class="line"> <span class="keywordflow">if</span>(<a class="code" href="structnetif.html">netif</a>-&gt;<a class="code" href="structnetif.html#a8fe4f1b7b0d710216287da9615164a5c">input</a>(p, <a class="code" href="structnetif.html">netif</a>) != <a class="code" href="group__infrastructure__errors.html#ggae2e66c7d13afc90ffecd6151680fbadcaa26c163b80b1f6786ca81dadc14b00fb">ERR_OK</a>) {</div><div class="line"> <a class="code" href="group__pbuf.html#gab0dd696fb4b6bc65e548944584f1738b">pbuf_free</a>(p);</div><div class="line"> }</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">Generated by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.13 </li>
</ul>
</div>
</body>
</html>