|
||||||||||||||
Functions Provided by the TCP/IP Stack For Use By The Port LayerThe port layer can use the following function:
Receiving DataThe Ethernet MAC driver will place received Ethernet frames into a buffer. The port layer has to:
Network Interface Port Layer Examples1. Example of a Basic Network Interface Port LayerSimple network interfaces can be created by copying Ethernet frames between buffers allocated by the Ethernet MAC driver libraries and buffers allocated by the port layer. [A more efficient zero copy alternative is provided after the simple example.]Example implementation of xNetworkInterfaceInitialise() for a basic port layer
Example implementation of xNetworkInterfaceOutput() for a basic port layer
Example of passing received data to the TCP/IP in a basic port layerWhen a packet is received from the Ethernet (or other network) driver the port layer must use a NetworkBufferDescriptor_t structure to describe the packet, then call xSendEventStructToIPTask() to send the NetworkBufferDescriptor_t structure to the embedded TCP/IP stack.NOTE 1: If BufferAllocation_2.c is used then network buffer descriptors and Ethernet buffers cannot be allocated from inside an interrupt service routine (ISR). In this case the Ethernet MAC receive interrupt can defer the receive processing to a task. This is demonstrated below. NOTE 2: There are numerous advanced techniques that can be employed to minimise the amount of data sent from the port layer into the embedded TCP/IP stack. For example, eConsiderFrameForProcessing() can be called to determine if the received Ethernet frame needs to be sent to the embedded TCP/IP stack at all, and Ethernet frames that are received in quick succession can be sent to the embedded TCP/IP stack in one go. See the Hardware and Driver Specific Settings section of the FreeRTOS+TCP configuration page for more information.
2. Example of a More Efficient Network Interface Port LayerIt is intended that this section is read after the section that describes how to create a simple network interface port layer.Simple network interfaces copy Ethernet frames between buffers used and managed by the TCP/IP stack and buffers used and managed by the Ethernet (or other network) MAC drivers. Copying data between buffers makes the driver's implementation simple, but is inefficient. Zero copy network interfaces do not copy data between buffers, but instead pass references to buffers between the TCP/IP stack and the Ethernet MAC drivers. Zero copy interfaces are more complex, and can rarely be created without editing the Ethernet MAC drivers themselves. If transmission is performed using zero copy then it is necessary to set ipconfigZERO_COPY_TX_DRIVER to 1. Most Ethernet hardware will use DMA (Direct Memory Access) to move frames between the Ethernet hardware and pre-allocated RAM buffers. Normally the pre-allocated memory buffers are referenced using a set of DMA descriptors. DMA descriptors are normally chained - each descriptor points to the next in the chain, with the last in the chain pointing back to the first.
Chained DMA descriptors
Example implementation of xNetworkInterfaceInitialise() for a zero copy port layerxNetworkInterfaceInitialise() must use pucGetNetworkBuffer() to obtain the pointers to which the receive DMA descriptors point. It is not necessary to allocate any buffers for the transmit DMA descriptors - the buffers will be passed in (by reference) as data becomes available to send.
The DMA Rx descriptors are initialised to point to buffers
that were allocated by pucGetNetworkBuffer().
Example implementation of xNetworkInterfaceOutput() for a zero copy layerxNetworkInterfaceOutput() does not copy the frame being transmitted to a buffer that is being managed by the MAC driver (it can't because the DMA's Tx descriptors are not pointing to any buffers) but instead updates the next DMA Tx descriptor so the descriptor points to the buffer that already contains the data.NOTE: The Ethernet buffer must be released after the data it contains has been transmitted. If BufferAllocation_2.c is used the Ethernet buffer cannot be released from the Ethernet Transmit End interrupt, so must be released by the xNetworkInterfaceOutput() function the next time the same DMA descriptor is used. Often only one or two descriptors are used for transmitting data anyway, so this does not waste too much RAM.
Receiving Data Using Zero-CopyIf reception is performed using zero copy then it is necessary to set ipconfigZERO_COPY_RX_DRIVER to 1.The receive DMA will place received frames into the buffer pointed to by the the receive DMA descriptor. The buffer was allocated using a call to pucGetNetworkBuffer(), which allows it to be referenced from a network buffer descriptor, and therefore passed by reference directly into the TCP/IP stack. A new empty network buffer is then allocated, and the receive DMA descriptor is updated to point to the empty buffer ready to receive the next packet. All the notes regarding the implementation of the simple receive handler (including advanced features to improve efficiency) apply to the zero copy receive handler and are not repeated here.
|
[ Back to the top ]
[ About FreeRTOS ]
[ Privacy ]
[ FreeRTOS Labs Sitemap ]
[ Main FreeRTOS Sitemap ]
[
]
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|