How does Sn_RX_RSR behave in case of overrun?

Hello,

the Wiznet 5500 datasheet does not state how the Sn_RX_RSR register behaves in case of overrun. To explain my understanding problem, let’s look into an example:

Suppose we are working with socket 0 in TCP mode, and we have configured a receive buffer size of 2K (2048 bytes). Now we are going into the listen state; the S0_RX_RSR will be 0 immediately after doing this.

Now suppose the w5500 receives 2047 bytes at socket 0, but we do not read those bytes. After having received that data, S0_RX_RSR will be 2047.

Now suppose the w5500 receives one more byte. How does S0_RX_RSR behave then? Does it take the value 2048, or does it already wrap around and take the value 0? (Note: I am quite sure that it does take the value 2048 since this is the only thing which makes sense, but I’d like to have this confirmed by somebody who knows for sure).

Finally, the most important questions:

Suppose the w5500 again receives one more byte. How does it behave then?

  1. Does S0_RX_RSR keep its current value, i.e. does it keep the value 2048, or does it wrap around, i.e. does it take the value 0? In other words, is S0_RX_RSR a wrap-around-register, or is it a saturated register?

  2. Does the w5500 overwrite old data in case of overrun, i.e. if it has received as many bytes as fit into the buffer, and if it receives one more byte, does it overwrite the “oldest” byte in the ring buffer, or does it just ignore the newly received byte?

Thank you very much in advance for any clarification!

Yes.

It can not receive more data, and it explicitly states it to the remote network device in specific field of TCP packet. You can not consider W5x00 socket programming in disconnection with the “other side” - data flow and protocol of the network.

RSR is indication how many bytes application can get from the buffer. Its range is 0 to buffer size.

W5x00 says remote device not to send anything until W5x00 has space to receive it.

For UDP and RAW modes, new data not fitting into buffer is discarded, thus it is in your application’s interests to flush data as fast as possible.

1 Like

Again, thank you very much for your time and expertise!

Yes, silly me. I should have known better and should have asked for UDP. Nevertheless, I think your last statement from your post above answers all my questions:

This is reasonable and expected behavior. So Sn_RX_RSR is a saturated register (and not a wrap-around register):

When the RX buffer is full and new data arrives, the new arriving data is discarded, meaning that nothing in the buffer gets overwritten. This in turn means that the number of bytes we can read from the RX buffer remains constant, and this finally means that Sn_RX_RSR remains constant.

Thank you very much again!