📄 netbuflib.html
字号:
<html><head><!-- /vobs/wpwr/docs/vxworks/ref/netBufLib.html - generated by refgen from netBufLib.c --> <title> netBufLib </title></head><body bgcolor="#FFFFFF"> <hr><a name="top"></a><p align=right><a href="libIndex.html"><i>VxWorks Reference Manual : Libraries</i></a></p></blockquote><h1>netBufLib</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote> <p><strong>netBufLib</strong> - network buffer library </p></blockquote><h4>ROUTINES</h4><blockquote><p><p><b><i><a href="./netBufLib.html#netBufLibInit">netBufLibInit</a></i>( )</b> - initialize <b><a href="./netBufLib.html#top">netBufLib</a></b><br><b><i><a href="./netBufLib.html#netPoolInit">netPoolInit</a></i>( )</b> - initialize a <b><a href="./netBufLib.html#top">netBufLib</a></b>-managed memory pool<br><b><i><a href="./netBufLib.html#netPoolDelete">netPoolDelete</a></i>( )</b> - delete a memory pool<br><b><i><a href="./netBufLib.html#netMblkFree">netMblkFree</a></i>( )</b> - free an <b>mBlk</b> back to its memory pool<br><b><i><a href="./netBufLib.html#netClBlkFree">netClBlkFree</a></i>( )</b> - free a <b>clBlk</b>-cluster construct back to the memory pool<br><b><i><a href="./netBufLib.html#netClFree">netClFree</a></i>( )</b> - free a cluster back to the memory pool<br><b><i><a href="./netBufLib.html#netMblkClFree">netMblkClFree</a></i>( )</b> - free an <b>mBlk</b>-<b>clBlk</b>-cluster construct<br><b><i><a href="./netBufLib.html#netMblkClChainFree">netMblkClChainFree</a></i>( )</b> - free a chain of <b>mBlk</b>-<b>clBlk</b>-cluster constructs<br><b><i><a href="./netBufLib.html#netMblkGet">netMblkGet</a></i>( )</b> - get an <b>mBlk</b><br><b><i><a href="./netBufLib.html#netClBlkGet">netClBlkGet</a></i>( )</b> - get a <b>clBlk</b><br><b><i><a href="./netBufLib.html#netClusterGet">netClusterGet</a></i>( )</b> - get a cluster from the specified cluster pool<br><b><i><a href="./netBufLib.html#netMblkClGet">netMblkClGet</a></i>( )</b> - get a <b>clBlk</b>-cluster and join it to the specified <b>mBlk</b><br><b><i><a href="./netBufLib.html#netTupleGet">netTupleGet</a></i>( )</b> - get an <b>mBlk</b>-<b>clBlk</b>-cluster<br><b><i><a href="./netBufLib.html#netClBlkJoin">netClBlkJoin</a></i>( )</b> - join a cluster to a <b>clBlk</b> structure <br><b><i><a href="./netBufLib.html#netMblkClJoin">netMblkClJoin</a></i>( )</b> - join an <b>mBlk</b> to a <b>clBlk</b>-cluster construct<br><b><i><a href="./netBufLib.html#netClPoolIdGet">netClPoolIdGet</a></i>( )</b> - return a <b>CL_POOL_ID</b> for a specified buffer size <br><b><i><a href="./netBufLib.html#netMblkToBufCopy">netMblkToBufCopy</a></i>( )</b> - copy data from an <b>mBlk</b> to a buffer<br><b><i><a href="./netBufLib.html#netMblkDup">netMblkDup</a></i>( )</b> - duplicate an <b>mBlk</b><br><b><i><a href="./netBufLib.html#netMblkChainDup">netMblkChainDup</a></i>( )</b> - duplicate an <b>mBlk</b> chain<br><p></blockquote><h4>DESCRIPTION</h4><blockquote><p><p>This library contains routines that you can use to organize and maintaina memory pool that consists of pools of <b>mBlk</b> structures, pools of <b>clBlk</b>structures, and pools of clusters. The <b>mBlk</b> and <b>clBlk</b> structuresare used to manage the clusters. The clusters are containers for the datadescribed by the <b>mBlk</b> and <b>clBlk</b> structures.<p>These structures and the various routines of this library constitute abuffering API that has been designed to meet the needs both of network protocols and network device drivers.<p>The <b>mBlk</b> structure is the primary vehicle for passing data betweena network driver and a protocol. However, the <b>mBlk</b> structure mustfirst be properly joined with a <b>clBlk</b> structure that was previouslyjoined with a cluster. Thus, the actual vehicle for passing data isnot merely an <b>mBlk</b> structure but an <b>mBlk</b>-<b>clBlk</b>-clusterconstruct.<p>To include <b><a href="./netBufLib.html#top">netBufLib</a></b> in VxWorks, define <b>INCLUDE_NETWORK</b> in <b>configAll.h</b>.This also automatically configures VxWorks to call <b><i><a href="./netBufLib.html#netBufLibInit">netBufLibInit</a></i>( )</b>.<p></blockquote><h4>INCLUDE FILES</h4><blockquote><p><b>netBufLib.h</b><p></blockquote><h4>-----------------------------------</h4><blockquote><p><p> -----------| |-----------|<br> | mBlk | | mBlk |<br> | | | |<br> | | | |<br> | | | |<br> | | | |<br> |-----------\ /-----------|<br> \ / <br> \ /<br> \ /<br> \|------------|/<br> | clBlk | <br> | | <br> |clRefCnt = 2| <br> | | <br> | | <br> |------------\ <br> \ <br> |---------------|<br> | cluster |<br> | |<br> | |<br> |---------------|<p></blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./netBufLib.html#top">netBufLib</a></b><hr><a name="netBufLibInit"></a><p align=right><a href="rtnIndex.html"><i>Libraries : Routines</i></a></p></blockquote><h1><i>netBufLibInit</i>( )</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote> <p><strong><i>netBufLibInit</i>( )</strong> - initialize netBufLib</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>STATUS netBufLibInit (void)</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This routine initializes netBufLib. If you defined <b>INCLUDE_NETWORK</b>in <b>configAll.h</b>, this configured VxWorks to include netBufLib.<p></blockquote><h4>RETURNS</h4><blockquote><p>OK or ERROR.</blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./netBufLib.html#top">netBufLib</a></b><hr><a name="netPoolInit"></a><p align=right><a href="rtnIndex.html"><i>Libraries : Routines</i></a></p></blockquote><h1><i>netPoolInit</i>( )</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote> <p><strong><i>netPoolInit</i>( )</strong> - initialize a <b><a href="./netBufLib.html#top">netBufLib</a></b>-managed memory pool</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>STATUS netPoolInit ( NET_POOL_ID pNetPool, /* pointer */ /* to */ /* a */ /* net */ /* pool */ M_CL_CONFIG * pMclBlkConfig, /* pointer */ /* to */ /* a */ /* mBlk */ /* configuration */ CL_DESC * pClDescTbl, /* pointer */ /* to */ /* cluster */ /* desc */ /* table */ int clDescTblNumEnt,/* number of cluster desc entries */ POOL_FUNC * pFuncTbl /* pointer to pool function table */ )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>Call this routine to set up a <b><a href="./netBufLib.html#top">netBufLib</a></b>-managed memorypool. Within this pool, <b><i><a href="./netBufLib.html#netPoolInit">netPoolInit</a></i>( )</b> organizes several sub-pools: onefor <b>mBlk</b> structures, one for <b>clBlk</b> structures, and as many clustersub-pools are there are cluster sizes. As input, this routine expectsthe following parameters:<dl><dt><i>pNetPool</i><dd>Expects a <b>NET_POOL_ID</b> that points to a previously allocated <b>NET_POOL</b>structure. You need not initialize any values in this structure. Thatis handled by <b><i><a href="./netBufLib.html#netPoolInit">netPoolInit</a></i>( )</b>.<p><dt><i>pMclBlkConfig</i><dd>Expects a pointer to a previously allocated and initialized <b>M_CL_CONFIG</b>structure. Within this structure, you must provide fourvalues: <b>mBlkNum</b>, a count of <b>mBlk</b> structures; <b>clBlkNum</b>, a countof <b>clBlk</b> structures; <b>memArea</b>, a pointer to an area of memorythat can contain all the <b>mBlk</b> and <b>clBlk</b> structures; and <b>memSize</b>, the size of that memory area. For example, you can set up an <b>M_CL_CONFIG</b> structure as follows:<pre> M_CL_CONFIG mClBlkConfig = /* mBlk, clBlk configuration table */ { mBlkNum clBlkNum memArea memSize ---------- ---- ------- ------- 400, 245, 0xfe000000, 21260 };</pre>You can calculate the <b>memArea</b> and <b>memSize</b> values. Such code could first define a table as shown above, but set both <b>memArea</b> and <b>memSize</b> as follows:<pre>mClBlkConfig.memSize = (mClBlkConfig.mBlkNum * (M_BLK_SZ + sizeof(long))) + (mClBlkConfig.clBlkNum * CL_BLK_SZ);</pre>You can set the memArea value to a pointer to private memory, or you canreserve the memory with a call to <b><i><a href="./memPartLib.html#malloc">malloc</a></i>( )</b>. For example:<pre> mClBlkConfig.memArea = malloc(mClBlkConfig.memSize);</pre>The <b>netBufLib.h</b> file defines <b>M_BLK_SZ</b> as:<pre> sizeof(struct mBlk)</pre>Currently, this evaluates to 32 bytes. Likewise, this file defines <b>CL_BLK_SZ</b> as:<pre> sizeof(struct clBlk)</pre>Currently, this evaluates to 32 bytes. <p>When choosing values for <b>mBlkNum</b> and <b>clBlkNum</b>, remember that you need as many <b>clBlk</b> structures as you have clusters (data buffers). You also need at least as many <b>mBlk</b> structures as you have <b>clBlk</b> structures, but you will most likely need more. That is because <b><a href="./netBufLib.html#top">netBufLib</a></b> shares buffers by letting multiple <b>mBlk</b> structures join to the same <b>clBlk</b> and thus to its underlying cluster. The <b>clBlk</b> keeps a count of the number of <b>mBlk</b> structures that reference it. <p><dt><i>pClDescTbl</i><dd>Expects a pointer to a table of previously allocated and initialized <b>CL_DESC</b>structures. Each structure in this table describes a single cluster pool.You need a dedicated cluster pool for each cluster size you want to support.Within each <b>CL_DESC</b> structure, you must provide four values: <b>clusterSize</b>,the size of a cluster in this cluster pool; <b>num</b>, the number of clusters in this cluster pool; <b>memArea</b>, a pointer to an area of memory that can contain all the clusters; and <b>memSize</b>, the size of that memory area.<p>Thus, if you need to support six different cluster sizes, this parametermust point to a table containing six <b>CL_DESC</b> structures. For example,consider the following:<pre> CL_DESC clDescTbl [] = /* cluster descriptor table */ { /* clusterSize num memArea memSize ---------- ---- ------- ------- */ {64, 100, 0x10000, 6800}, {128, 50, 0x20000, 6600}, {256, 50, 0x30000, 13000}, {512, 25, 0x40000, 12900}, {1024, 10, 0x50000, 10280}, {2048, 10, 0x60000, 20520} };</pre>As with the <b>memArea</b> and <b>memSize</b> members in the <b>M_CL_CONFIG</b> structure,you can set these members of the <b>CL_DESC</b> structures by calculation afteryou create the table. The formula would be as follows:<pre> clDescTbl[n].memSize = (clDescTbl[n].num * (clDescTbl[n].clusterSize + sizeof(long)));</pre>The <b>memArea</b> member can point to a private memory area that you know to be available for storing clusters, or you can use <b><i><a href="./memPartLib.html#malloc">malloc</a></i>( )</b>.<pre> clDescTbl[n].memArea = malloc( clDescTbl[n].memSize ); </pre>Valid cluster sizes range from 64 bytes to 65536 bytes. If there are multiple cluster pools, valid sizes are further restricted to powers oftwo (for example, 64, 128, 256, and so on). If there is only one cluster pool (as is often the case for the memory pool specific to a single device driver), there is no power of two restriction. Thus, the cluster can be of any size between 64 bytes and 65536 bytes on 4-byte alignment. A typical buffer size for Ethernet devices is 1514 bytes. However, becausea cluster size requires a 4-byte alignment, the cluster size for this Ethernet buffer would have to be increased to at least 1516 bytes.<p><dt><i>clDescTblNumEnt</i><dd>Expects a count of the elements in the <b>CL_DESC</b> table referenced by the <i>pClDescTbl</i> parameter. This is a count of the number of clusterpools. You can get this value using the NELEMENTS macro defined in <b>vxWorks.h</b>. For example:<pre> int clDescTblNumEnt = (NELEMENTS(clDescTbl));</pre><dt><i>pFuncTbl</i><dd> Expects a NULL or a pointer to a function table. This table contains pointers to the functions used to manage the buffers in this memory pool. Using a NULL for this parameter tells <b><a href="./netBufLib.html#top">netBufLib</a></b> to use its default function table. If you opt for the default function table, every <b>mBlk</b> and every cluster is prepended by a 4-byte header (which is why the size calculations above for clusters and <b>mBlk</b> structures contained an extra <b>sizeof(long)</b>). However, users need not concern themselves with this header when accessing these buffers. The returned pointers from functions such as <b><i><a href="./netBufLib.html#netClusterGet">netClusterGet</a></i>( )</b> return pointers to the start ofdata, which is just after the header. </dl><p>Assuming you have set up the configuration tables as shown above, a typical call to <b><i><a href="./netBufLib.html#netPoolInit">netPoolInit</a></i>( )</b> would be as follows:<pre> int clDescTblNumEnt = (NELEMENTS(clDescTbl)); NET_POOL netPool; NET_POOL_ID pNetPool = &netPool; if (netPoolInit (pNetPool, &mClBlkConfig, &clDescTbl [0], clDescTblNumEnt, NULL) != OK) return (ERROR);</pre></blockquote><h4>RETURNS</h4><blockquote><p>OK or ERROR.<p></blockquote><h4>ERRNO</h4><blockquote><p><p> S_netBufLib_MEMSIZE_INVALID<br> S_netBufLib_CLSIZE_INVALID<br> S_netBufLib_NO_SYSTEM_MEMORY<br> S_netBufLib_MEM_UNALIGNED<br> S_netBufLib_MEMSIZE_UNALIGNED<br> S_netBufLib_MEMAREA_INVALID<p></blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./netBufLib.html#top">netBufLib</a></b>, <b><i><a href="./netBufLib.html#netPoolDelete">netPoolDelete</a></i>( )</b><hr><a name="netPoolDelete"></a><p align=right><a href="rtnIndex.html"><i>Libraries : Routines</i></a></p></blockquote><h1><i>netPoolDelete</i>( )</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote> <p><strong><i>netPoolDelete</i>( )</strong> - delete a memory pool</p></blockquote><h4>SYNOPSIS</h4><blockquote><p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -