tara0809 发表于 2014-11-12 17:19:06

UART2TCP 不明白

本帖最后由 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;
                        }

ruanxianwu 发表于 2014-11-12 18:03:17

我也看不到呀呀呀

tara0809 发表于 2014-11-12 20:53:48

ruanxianwu 发表于 2014-11-12 18:03
我也看不到呀呀呀

看不到什么

security 发表于 2014-11-12 23:41:42

w是读指针到fifo尾部的数据长度,此时数据发生了循环溢出,写指针从fifo首部开始了。tcpflush的作用,上面的注释有提到了,可以仔细看看,即立即发送,否则,发送会缓冲延迟
页: [1]
查看完整版本: UART2TCP 不明白