zerocopyrx.html 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  5. <meta http-equiv="X-UA-Compatible" content="IE=9"/>
  6. <meta name="generator" content="Doxygen 1.8.13"/>
  7. <meta name="viewport" content="width=device-width, initial-scale=1"/>
  8. <title>lwIP: Zero-copy RX</title>
  9. <link href="tabs.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. <link href="navtree.css" rel="stylesheet" type="text/css"/>
  13. <script type="text/javascript" src="resize.js"></script>
  14. <script type="text/javascript" src="navtreedata.js"></script>
  15. <script type="text/javascript" src="navtree.js"></script>
  16. <script type="text/javascript">
  17. $(document).ready(initResizable);
  18. </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. <link href="doxygen.css" rel="stylesheet" type="text/css" />
  23. </head>
  24. <body>
  25. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  26. <div id="titlearea">
  27. <table cellspacing="0" cellpadding="0">
  28. <tbody>
  29. <tr style="height: 56px;">
  30. <td id="projectalign" style="padding-left: 0.5em;">
  31. <div id="projectname">lwIP
  32. &#160;<span id="projectnumber">2.1.2</span>
  33. </div>
  34. <div id="projectbrief">Lightweight IP stack</div>
  35. </td>
  36. </tr>
  37. </tbody>
  38. </table>
  39. </div>
  40. <!-- end header part -->
  41. <!-- Generated by Doxygen 1.8.13 -->
  42. <script type="text/javascript">
  43. var searchBox = new SearchBox("searchBox", "search",false,'Search');
  44. </script>
  45. <script type="text/javascript" src="menudata.js"></script>
  46. <script type="text/javascript" src="menu.js"></script>
  47. <script type="text/javascript">
  48. $(function() {
  49. initMenu('',true,false,'search.php','Search');
  50. $(document).ready(function() { init_search(); });
  51. });
  52. </script>
  53. <div id="main-nav"></div>
  54. </div><!-- top -->
  55. <div id="side-nav" class="ui-resizable side-nav-resizable">
  56. <div id="nav-tree">
  57. <div id="nav-tree-contents">
  58. <div id="nav-sync" class="sync"></div>
  59. </div>
  60. </div>
  61. <div id="splitbar" style="-moz-user-select:none;"
  62. class="ui-resizable-handle">
  63. </div>
  64. </div>
  65. <script type="text/javascript">
  66. $(document).ready(function(){initNavTree('zerocopyrx.html','');});
  67. </script>
  68. <div id="doc-content">
  69. <!-- window showing the filter options -->
  70. <div id="MSearchSelectWindow"
  71. onmouseover="return searchBox.OnSearchSelectShow()"
  72. onmouseout="return searchBox.OnSearchSelectHide()"
  73. onkeydown="return searchBox.OnSearchSelectKey(event)">
  74. </div>
  75. <!-- iframe showing the search results (closed by default) -->
  76. <div id="MSearchResultsWindow">
  77. <iframe src="javascript:void(0)" frameborder="0"
  78. name="MSearchResults" id="MSearchResults">
  79. </iframe>
  80. </div>
  81. <div class="header">
  82. <div class="headertitle">
  83. <div class="title">Zero-copy RX </div> </div>
  84. </div><!--header-->
  85. <div class="contents">
  86. <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 -->
  87. </div><!-- doc-content -->
  88. <!-- start footer part -->
  89. <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  90. <ul>
  91. <li class="footer">Generated by
  92. <a href="http://www.doxygen.org/index.html">
  93. <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.13 </li>
  94. </ul>
  95. </div>
  96. </body>
  97. </html>