02.03.2014 Views

BSP Developer's Guide

BSP Developer's Guide

BSP Developer's Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

H<br />

Implementing a MUX-Based Network Interface Driver<br />

To establish a memory pool, call netPoolInit( ). For an END, make the<br />

netPoolInit( ) call during the driver’s initialization phase. From out of this pool,<br />

your driver should reserve the mBlk/clBlk/cluster constructs it needs to receive<br />

a packet. For more information, see the reference entry for netBufLib.<br />

Receiving Data into Clusters<br />

During the initialization phase of your END, call netClusterGet( ) to reserve some<br />

reasonable number of clusters to receive incoming packets (store references to<br />

these reserved clusters in a buffer ring or some other structure appropriate to your<br />

needs). When a packet arrives, your END should receive it directly into one of<br />

these clusters.<br />

When your END is ready to pass a received packet up to the MUX, it does so using<br />

an mBlk/clBlk/cluster construct. To create this construct:<br />

1. Call netClBlkGet( ) to reserve a clBlk structure.<br />

2. Call netClBlkJoin( ) to join the clBlk to the cluster containing the packet.<br />

3. Call netMblkGet( ) to reserve a mBlk structure.<br />

4. Call netMblkClJoin( ) to join the mBlk structure to the clBlk/cluster<br />

construct.<br />

Now that the packet is contained within an mBlk/clBlk/cluster construct, the<br />

END can use various netBufLib routines to adjust or inspect the data in the<br />

mBlk/clBlk/cluster construct. For example, to read the packet data in the<br />

construct, your END can call netMblkToBufCopy( ). In addition, your END can<br />

use the mBlk chaining feature to prepend or append data to the packet.<br />

H<br />

NOTE: The various net*Get( ) routines reserve memory from a pre-allocated pool.<br />

Internally, they do not use semaphores. Thus, they are safe to call from places<br />

where a call to malloc( ) would be impossible.<br />

Freeing mBlks, clBlks, and Clusters<br />

When you are done with an mBlk/clBlk/cluster chain and want to return it to the<br />

memory pool, call netMblkClChainFree( ). This frees all mBlks in the chain. It<br />

also decrements the reference counters in all the clBlks in the chain. If the reference<br />

counter for a clBlk drops to zero, that clBlk and its associated cluster are also freed<br />

back to the pool. To free a single mBlk/clBlk/cluster back to the memory pool, use<br />

netMblkClFree( ). For more information on these and other free routines, see the<br />

reference entry for netBufLib.<br />

279

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!