anhuihbo

LM3S 以太网转串口 速度瓶颈 开发小结

0
阅读(23352)

一、当串口高速度3.125Mbps全速运行时,以太网读取FIFO发送的时间大于串口写入FIFO的时间时,出现丢包现象。

解决方案:(1)主机每10ms调用一次,Telnet每字发送时间约4.5-5uS;256*7所用时间约8.96mS。故采用固定长度帧发送。 首先判断FIFO已用的长度,若大于256*7,按256*7读取;若小于256*7,按较小的值读取发送。这样Telnet的发送时间便被控制下来。

    接下来中要的是,FIFO总存储空间-已读取的+写入的;防止FIFO溢出丢数据。按照3.125Mbps来计算,接收一个字为3.2uS,10mS内共接收3125字节。缓冲的FIFO空间要足够,才能保证数据不丢失。此种方案对SRAM占用较多。

(2)提高主机时间间隔,以5mS为例,固定发送长度256*4=1024;按照3.125Mbps来计算,接收一个字为3.2uS,5mS内共接收1563字节。这样对于SRAM的压力减轻。

Telnet发送:

           long lCount, lIndex,SendLength;

            lCount = (long)SerialReceiveAvailable(pState->ulSerialPort);
           
            if(tcp_sndbuf(pState->pConnectPCB) < lCount)
            {
                lCount = tcp_sndbuf(pState->pConnectPCB);
            }
           
            if(lCount >256*7)
            {
              SendLength = 256*7;
            }
            else
            {
              SendLength = SendLength;
            }
            //
            // While we have data remaining to process, continue in this
            // loop.
            //SendLength
            while((SendLength) &&
                  (pState->pConnectPCB->snd_queuelen < TCP_SND_QUEUELEN))
            {
                //
                // First, reset the index into the local buffer.
                //
                lIndex = 0;

                //
                // Fill the local buffer with data while there is data
                // and/or space remaining.
                //
                while(SendLength && (lIndex < sizeof(pucTemp)))
                {
                    pucTemp[lIndex] = SerialReceive(pState->ulSerialPort);
                    lIndex++;
                    SendLength--;
                }

                //
                // Write the local buffer into the TCP buffer.
                //
                tcp_write(pState->pConnectPCB, pucTemp, lIndex, 1);
            }

总结:数据更新索引时,关闭了所有中断,不合理。影响网速,丢包。关闭后,正常,网速提升。串口高速3.125MBPS全速。