Register TX_WR change while writing the TX buffer.

Hi Arduino,
My name is Li Gang.I am in charge of WIZnet Q&A forum
One of your customers is using an "official" ethernet shield (w5100) and found a problem about your library: the send_data_processing() in w5100.cpp

We did aging test (TCP server loopback) using our standard w5100 driver and W5100E01-AVR EVB .
The function of loopback.c is to receive the file sent from other network device (such as PC) and then send the received data to the original place (PC).
You can refer to the loopback.c in our reference code here:

After unpack the zip file, you can find W5100E01-AVR.aps which is a AVR studio 4 project file. You should install AVR studio 4 and open it. And then you will see loopback.c in the source tree. Of couse, if it is not convenient for you to install AVR studio, you can directly find loopback.c in app folder.

The test result is OK.
So, could you check your library and give a support to this customer?
This customer email address is: indriocul@gmail.com
Thanks.

Below is the questions:

Hi,

I'm sending data to google with an arduino and an "official" the ethernet shield usingn w5100.

My program works for some minutes, It sends the same POST message and read the same server answer for 10 to 100 times, then it starts to read random values and stops working.

I looked inside the library and I found a strange behavior in the function:

Code:
void W5100Class::send_data_processing(SOCKET s, uint8_t *data, uint16_t len)
{

uint16_t ptr = readSnTX_WR(s);
uint16_t offset = ptr & SMASK;
uint16_t dstAddr = offset + SBASE~~;~~
~~ if (offset + len > SSIZE)~~
~~ {~~
~~ // Wrap around circular buffer~~
~~ uint16_t size = SSIZE - offset;~~
~~ write(dstAddr, data, size);~~
write(SBASE~~, data + size, len - size);
}
else {
write(dstAddr, data, len);
}~~

~~ if(ptr!=readSnTX_WR(s)) Serial.println("Argghhhhh! who change TXWR?"); // < Look here! ~~

~~ ptr += len;
writeSnTX_WR(s, ptr);
}~~
The register TX_WR changed its value while Arduino was writing the sending message. It was not expected to do that!
After that, many other registers are broken.
In a deeper investigation I found that the problem arise on the write(dstAddr, data, len), before the write, the register and address are OK , after the write all starts go wrong.
The write function use SPI to write to the wiz5100.
Could you help me, please?

(this will make the code easier to read)

void W5100Class::send_data_processing(SOCKET s, uint8_t *data, uint16_t len)
{

  uint16_t ptr = readSnTX_WR(s);
  uint16_t offset = ptr & SMASK;
  uint16_t dstAddr = offset + SBASE[s];

  if (offset + len > SSIZE) 
  {
    // Wrap around circular buffer
    uint16_t size = SSIZE - offset;
    write(dstAddr, data, size);
    write(SBASE[s], data + size, len - size);
  } 
  else {
    write(dstAddr, data, len);
  }
  
   if(ptr!=readSnTX_WR(s)) Serial.println("Argghhhhh! who change TXWR?"); //     <  Look here!   
 
   ptr += len;
   writeSnTX_WR(s, ptr);
}