So it looks like there is 8Kb of internal RX buffer on the W5100 chip... so how does one deal with reading the data faster than its coming in? If I don't read it fast enough or too fast what happens? How do you flush the buffer on chip via client.flush()? I suspect it's FIFO.
I'm running into a situation where I am getting 8k of data posted to me and it looks like the data is being "clipped" ... guess the buffer is getting filled.
Looking at the W5100.c file there is mention of how the memory channels are allocated... anyone know how it's setup to work? Full 8kb or less?
/**
@brief This function is being used for copy the data form Receive buffer of the chip to application buffer.
It calculate the actual physical address where one has to read
the data from Receive buffer. Here also take care of the condition while it exceed
the Rx memory uper-bound of socket.
*/
void read_data(SOCKET s, vuint8 * src, vuint8 * dst, uint16 len)
{
uint16 size;
uint16 src_mask;
uint8 * src_ptr;
src_mask = (uint16)src & getIINCHIP_RxMASK(s);
src_ptr = (uint8 *)(getIINCHIP_RxBASE(s) + src_mask);
if( (src_mask + len) > getIINCHIP_RxMAX(s) )
{
size = getIINCHIP_RxMAX(s) - src_mask;
wiz_read_buf((uint16)src_ptr, (uint8*)dst,size);
dst += size;
size = len - size;
src_ptr = (uint8 *)(getIINCHIP_RxBASE(s));
wiz_read_buf((uint16)src_ptr, (uint8*) dst,size);
}
else
{
wiz_read_buf((uint16)src_ptr, (uint8*) dst,len);
}
}
So does it just override the previous if not read fast enough? How do you know how big the buffer is? I'd like to know if it's really 8Kb.
Yeah, I got the details... I'm more interested in how the RX memory buffer is setup. Looks like 8Kb is reserved on the chip. However, what happens if more than that gets posted and is not read fast enough?
What SHOULD happen is that packets that cannot be buffered will get discarded and end up being retransmitted by the remote host. (actually, it ought to use a TCP window smaller than the available buffer memory, which should prevent the remote host from ever sending a packet that won't fit.)
(If you don't use TCP, you will need to duplicate some of this functionality with whatever protocol you DO use.)
Why is it set to 2Kb rather than the full 8Kb which is available on the W5100 chip!? What is the reasoning? This means once the buffer is filled, all new data gets discarded. Bad.
Ok, so I understand it a bit more... 2048k for RX buffer is because you can have up to 4 sockets. I'd like to reduce that to 2 active sockets and 4k each. Any tips on how I can change that?
Set socket memory information
This stage sets the socket tx/rx memory information. The base address and mask address of
each socket are fixed and saved in this stage.
so it describes how to set them up on the w5100 chip. for the arduino sketch you may have to change something else. I am not sure if there is a software buffer in the sketch or not.
So keeping max_sockets at 4 but changing the RMSR in the sysinit to 0xAA (4kb) now allows more than 2048 limits in the client.available() ... weird thing is I didn't change the max_sockets. Not sure if that will cause any edge case issues... however, it seems to be working now, allowing up to 4kb!
Any ideas why it's working just by changing the RMSR setting and nothing else?
Also note... it seems like the buffer via 'client.available()' doesn't adjust on the chip as you read bytes from it. So if 3kb of data came in... it locks 3kb until you flush and stop. Not exactly what I expected. Guess most people don't get post data bigger than 2kb. ;D
OK. So maybe it's time to approach the problem from the other end. Why is it necessary to send 8KB messages to the Arduino that can't handle 8KB messages on a good day?
Because I don't have control over some devices that "post" data and I don't want a computer in between. It looks like the typical message is 2900 bytes just over the limit... It wouldn't be a problem if I didn't need a few bytes from range 2048-2900. Looks like changing it to 4kb is working... however, I'm not sure why I can't change the max sockets to 2 since 4kb+4kb = 8kb... it's giving me compile errors in when I change max_sockets to 2.
Also, reading from the buffer, actually doesn't seem to "clear" the char from the buffer... not sure if that is by design or just not coded to support it. Can someone confirm this as well... not sure if it's something I'm doing wrong.