Specifications

Transmit
pointer
*
Receive
pointer
*
End Address
of the buffer
Starting Address
of the buffer
Memory
addresses
Figure 13 The ring buffer
The buffer works by using two pointers a transmit pointer and a receive pointer. The
receive pointer is passed to the function that reads the TCP data and stores the data from
this pointer forward. When the read is finished, it is determined how many bytes were
put into the buffer and the pointer is moved to this next position, ready to receive more
data. If the pointer goes past the end of the memory space allocated it is reset back to
the start of the memory space, hence the name ring buffer. The transmit pointer is used
by the MP3 function, which was yet to be implemented, to determine from where in the
buffer it was to read data. This pointer wraps back to the beginning of the buffer the
same as the receive pointer.
The buffer management algorithm starts by calculating the amount of data that is in the
buffer by counting how far the receive pointer is in front of the transmit pointer. If the
buffer becomes full, meaning the receive buffer catches up to the transmit buffer, the
program waits until the buffer starts to become empty before reading more TCP data.
This situation is ideal; it indicates when the data is coming in faster than the data is
going out. At this point a test of how the Nut OS regulated the TCP stream from the
server when the buffer became full was done. The hope was that it would simply stop
the stream when its own buffer became full and wait for data to be taken out. It was
tested by using the same TCP file transfer model as above, but this time the Ethernut
took all the data from the server and put it into the buffer as shown in figure 14.
30