[X]关闭

tcp长时间传输数据出错

文档创建者:江苏-天文
浏览次数:6098
最后更新:2019-07-17
出现的问题是:在whie循环中多次执行send_data()之后,sdk Terminal窗口中报错:
#define ERR_MEM        -1    /* Out of memory error.     */
#define ERR_CONN       -13   /* Not connected.            */
程序在ch27上修改,在主函数的while循环中执行以下语句:

        while (1)
        {
                /* call tcp timer every 250ms */
                if(TcpTmrFlag)
                {
                        if(request_pcb->state == CLOSED || (request_pcb->state == SYN_SENT && request_pcb->nrtx == TCP_SYNMAXRTX))
                        {
                                request_pcb = tcp_new();
                                if (!request_pcb) {
                                        xil_printf("txperf: Error creating PCB. Out of Memory\r\n");
                                        return -1;
                                }

                                //ip_set_option(request_pcb, SOF_REUSEADDR);

                                err = tcp_connect(request_pcb, &ipaddress, port, tcp_connected_callback);
                                if (err != ERR_OK) {
                                        xil_printf("txperf: tcp_connect returned error: %d\r\n", err);
                                        return err;
                                }
                        }
                        tcp_tmr();
                        TcpTmrFlag = 0;
                }
                /*receive input packet from emac*/
                xemacif_input(netif);
                /* if connected to the server, start receive data from PL through axidma, then transmit the data to the PC software by TCP*/
                if(tcp_client_connected)
                {
                        send_data();
                        sleep(1);
                }

        }


以下是send_data()函数:send_data()函数主要就是tcp_write()和tcp_output()函数。

void send_data()
{
        #if __arm__
                int copy = 3;
        #else
                int copy = 0;
        #endif
                err_t err;
        struct tcp_pcb *tpcb = connected_pcb;
        err = tcp_write(tpcb, yuan, 15, copy);
        if (err != ERR_OK) {
                xil_printf("txperf: Error on tcp_write: %d\r\n", err);
                connected_pcb = NULL;
                return;
        }

        err = tcp_output(tpcb);
        if (err != ERR_OK) {
                xil_printf("txperf: Error on tcp_output: %d\r\n",err);
                return;
        }

}



发表评论已发布 1

uisrc

发表于 2019-7-17 14:01:21 | 显示全部楼层

操作系统不是实时系统,TCP本身也无法确保延迟的问题,所以这个有点难解决的
越努力越幸运!加油!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则