In all cases RAM consumption and CPU load can be minimised by using network drivers that make full use of any hardware features available, such as checksum offloading and MAC address filtering. If the hardware does not offer these facilities then the network driver can still improve RAM consumption and CPU load by performing any filtering it can before passing packets to the TCP/IP stack.
#define ipconfigUSE_TCP_WIN 0The window size will be fixed to 1 MSS. The buffer size can be declared as 1 or 2 MSS:
#define ipconfigTCP_TX_BUFFER_LENGTH ( 2 * ipconfigTCP_MSS ) #define ipconfigTCP_RX_BUFFER_LENGTH ( 2 * ipconfigTCP_MSS )If RAM is really constrained then use smaller segments:
#define ipconfigNETWORK_MTU 576 #define ipconfigTCP_MSS 522All peers will understand this and only send small packets.
Only allocate the minimum number of network buffer descriptors you can get away with. This also has the effect of preventing high network traffic resulting in memory exhaustion as network buffers will not be allocated if no descriptors are available:
#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS [a small number]Finally, ensure only the amount of RAM that is actually required is allocated at any given time by using the BufferAllocation_2.c.
Second the advanced features of the TCP/IP stack, including the functionality mentioned in the description of the ipconfigUSE_LINKED_RX_MESSAGES parameter and the callback API are provided with the aim of maximising throughput - however these features are considered to be for advanced users only.
If you have enough RAM then the following declarations will help performance:
#define ipconfigNETWORK_MTU 1526 #define ipconfigTCP_MSS 1460 #define ipconfigTCP_TX_BUFFER_LENGTH ( 16 * ipconfigTCP_MSS ) #define ipconfigTCP_RX_BUFFER_LENGTH ( 16 * ipconfigTCP_MSS )On a LAN, the sliding windows will get a size of ( 8 * ipconfigTCP_MSS ), meaning that only one out of 8 packets will receive an ACK.
For more flexibility FreeRTOS_setsockopt() can be used to set sizes between a socket being created and the same socket getting used.
/* Declare the variable used to set the configuration parameters. */ WinProperties_t xWinProps; /* Start with everything set to 0. */ memset( &xWinProps, '\0', sizeof( xWinProps ) ); /* Configure as required. */ xWinProps.ulTxBufSize = 24 * ipconfigTCP_MSS; xWinProps.ulTxWinSize = 8; xWinProps.ulRxBufSize = 24 * ipconfigTCP_MSS; xWinProps.ulRxWinSize = 8; /* Set the socket options. */ FreeRTOS_setsockopt( sock, 0, FREERTOS_SO_WIN_PROPERTIES, ( void * ) &xWinProps, sizeof( xWinProps ) ); Using FreeRTOS_setsockopt() to set TCP/IP options
Usually nothing is to be gained by setting the windows larger than ( 8 * MSS ), unless the CPU and MAC are very fast and connected to a 1 Gbit LAN. Using larger buffers for reception does make sense in case the end-point is slow, for instance if all the received data must be written to an SD-card.
Finally, ensure fast and deterministic buffer allocation that can also be used directly from within the MAC interrupt by using BufferAllocation_1.c.