04-30-2018 02:48 AM
I am developing a bare metal application for the ARM core on the Zynq XC7Z020, where I will ultimately wish to send a fair amount of data using UDP.
In my investigations I have a basic UDP transmitter that sends a 3 byte packet every second. In doing so, I am reusing the same buffer each time (same pcb, same char and same pbuf).
It basically works, except every so often one of the packets will take slightly longer and when it arrives it contains the contents of the following packet.
I have added debug code to investigate the structures and note that the pbuf->ref is higher (5) after the send in these instances than normal (3). It appears therefore that this is the sequence of events.
1) pbuf structure has ref=1. (that would be my reference in which I created it).
2) udp_send() is called and the stack makes two references to the structure.
3) On exiting the function the packet has not yet been sent, it has simply been queued to do so.
4) A second later the packet still hasn't gone, I change what is in memory.
5) udp_send() is called and the stack makes two more references.
6) Both the first and second packet are sent, but with payload of the second.
So, I understand what is going on and it makes sense. I also know how to work around (multiple buffers). I am looking for recommendations.
a) Is all the expected behaviour?
b) Why would it take so long for the packet to leave the stack?
c) Can I ensure that the ref count will be 1 if packet has been sent and that the packet has been sent if the ref count is 1?
d) Is (c) the recommended method of determining that the buffer is ready for reuse, or is there another method?
04-30-2018 03:13 AM
04-30-2018 06:18 AM
Read through rawapi.txt. The api description (don't skip the tcp section) and the section at the end of the file ("Zero-copy MACs") will likely answer most of your questions and explain your observations.
05-08-2018 02:13 AM
05-08-2018 06:06 AM