简体   繁体   中英

TCP issues with freeRTOS + LwIP with threading/tasks

As above, having issues using FreeRTOS+LwIP on a Zedboard, with the board just crashing and needing a power reset. I think it's to do with the network connections, I have two, one for incoming traffic and one for outgoing, both connect fine, however data seems a bit, odd.

Here's the function I'm using to receive data from the PC:

while (ntotal < size)
{
    n = lwip_read(connection_descriptor, (buffer+ntotal), size - ntotal);
    if (n < 0)
    {
        printf("Failed receiving frame, received %i bytes\n", ntotal);
        return -1;
    }
    ntotal = ntotal + n;
}

And here's for the outgoing:

int bytesSent = 0;
int bytesSentTotal = 0;
int lengthToSend = 0;
int lengthToSendTotal = 0;

lengthToSendTotal = Size;
lengthToSend = 1460;
printf("Processed frame about to be sent from obin%d\n", binNO);


while (bytesSentTotal + lengthToSend < lengthToSendTotal)
{
    //lengthToSend = lengthToSendTotal - bytesSentTotal;
    bytesSent = lwip_write(connection_descriptor, &(buffer[bytesSentTotal]), lengthToSend);
    if (bytesSent < 0)
    {
        printf("ERROR writing frame to socket\n");
        return -1;
    }
    else
    {
        bytesSentTotal += bytesSent;
        //printf("Data sent: %d\n", bytesSentTotal);
    }
}
lengthToSend = lengthToSendTotal - bytesSentTotal;
bytesSent = lwip_write(connection_descriptor, &(buffer[bytesSentTotal]), lengthToSend);

I tried changing it to send smaller amount of data per call as I wondered if trying to send a large amount at once was causing the issues (looking to send 900kb+ each time). However the behaviour seems to be the same regardless, it will start fine, with data being received, then it will freeze, often partway through sending data back, until finally the client code on my PC will fail at the write command due to non responding network connection (or something similar).

So I'm just wondering if there's anything obvious I'm doing wrong?

What happens when it crashes? Where does the program end up (in an assert(), in an exception handler, etc.)? Which version of FreeRTOS are you using - if it is a new-ish version then to you have configASSERT() defined, which could help highlight integration issues with FreeRTOS?

Was your project based on the following reference? http://www.freertos.org/RTOS-Xilinx-Zynq.html - if not maybe looking at that code could provide a hint as to what the problem might be.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM