|
本帖最后由 tara0809 于 2014-11-12 17:26 编辑
请教UART2TCP 中红色的部分 w 是指的什么呢?
TCPFlush()是在什么情况下调用?
谢谢!
// Transmit pending data that has been placed into the UART RX FIFO (in the ISR)
//
wMaxPut = TCPIsPutReady(MySocket); // Get TCP TX FIFO space
wMaxGet = RXHeadPtrShadow - RXTailPtrShadow; // Get UART RX FIFO byte count
if(RXHeadPtrShadow < RXTailPtrShadow)
wMaxGet += sizeof(vUARTRXFIFO);
if(wMaxPut > wMaxGet) // Calculate the lesser of the two
wMaxPut = wMaxGet;
if(wMaxPut) // See if we can transfer anything
{
// Transfer the data over. Note that a two part put
// may be needed if the data spans the vUARTRXFIFO
// end to start address.
w = vUARTRXFIFO + sizeof(vUARTRXFIFO) - RXTailPtrShadow;
if(wMaxPut >= w)
{
TCPPutArray(MySocket, RXTailPtrShadow, w);
RXTailPtrShadow = vUARTRXFIFO;
wMaxPut -= w;
}
TCPPutArray(MySocket, RXTailPtrShadow, wMaxPut);
RXTailPtrShadow += wMaxPut;
// No flush. The stack will automatically flush and do
// transmit coallescing to minimize the number of TCP
// packets that get sent. If you explicitly call TCPFlush()
// here, latency will go down, but so will max throughput
// and bandwidth efficiency.
}
//
// Transfer received TCP data into the UART TX FIFO for future transmission (in the ISR)
//
wMaxGet = TCPIsGetReady(MySocket); // Get TCP RX FIFO byte count
wMaxPut = TXTailPtrShadow - TXHeadPtrShadow - 1;// Get UART TX FIFO free space
if(TXHeadPtrShadow >= TXTailPtrShadow)
wMaxPut += sizeof(vUARTTXFIFO);
if(wMaxPut > wMaxGet) // Calculate the lesser of the two
wMaxPut = wMaxGet;
if(wMaxPut) // See if we can transfer anything
{
// Transfer the data over. Note that a two part put
// may be needed if the data spans the vUARTTXFIFO
// end to start address.
w = vUARTTXFIFO + sizeof(vUARTTXFIFO) - TXHeadPtrShadow;
if(wMaxPut >= w)
{
TCPGetArray(MySocket, TXHeadPtrShadow, w);
TXHeadPtrShadow = vUARTTXFIFO;
wMaxPut -= w;
}
TCPGetArray(MySocket, TXHeadPtrShadow, wMaxPut);
TXHeadPtrShadow += wMaxPut;
} |
|