WIZnet Developer Forum

Multiple socket handling and Send/Receive issue

Hi all,

I am new to wiznet w5100, I am little confused about multiple socket handling and Rx/Tx buffer size.

so here is my queries:

  1. Currently I am using socket 0 using Interrupt,I want to give support up to 4 sockets. I want to know is it possible when all socket (Socket 0,1,2,3) interrupt comes simultaneously. if yes so how to handle that situation ?? :question:

  2. I set the Size of RMSR/TMSR 2K to each socket. During send/receive is there any buffer shift mechanism on SOCKET???
    for e.g. I want to receive more than 2k bytes, suppose I read only 500 bytes so my question is:

  • is 500 bytes removed from the RMSR register?
  • is sender stop the data sending because RMSR is full or it simply drop/ discard the remaining bytes ?

I would greatly appreciate it if you help me… :smiley: :smiley: :smiley: :smiley: :smiley:
Thank You!!

  1. There are 2 common register and 1 register for socket
    IR It reads to see which socket has generated the interrupt ( bits S0_INT/S3_INT datasheet page 21 )
    IMR to mask the intervention of the interrupt for the 4 socket ( bits IM_IR0/IM_IR3 datasheet page 22 )
    Sn_IR to know what condition generated the interrupt on a given socket ( datasheet page 27 )

… in your case you enable all bits IM_IR0/IM_IR3, when an interrupt is generated then read IR and for each socket in Sn_INT high read Sn_IR

  1. when you receive the bytes you must move the pointer confirming their reading, buffer have an overrun method explained in pages 35 and 36.
    A register return recv data size (Sn_RX_RSR) and another the starting position in rx buffer (Sn_RX_RD) . When a portion of buffer is readed then increase Sn_RX_RD and when you have finished set RECV bit in Sn_CR and this portion is free for incoming stream.

I used this spooling method opportunity to directly read a page content and find certain SOAP token without using a duplicate buffer in memory.

I found the use of interrupt a bottleneck, I direct reading Sn_RX_RSR register and start to compose the response meanwhile that data arrives since even the transmission buffer uses this system … fill it and then confirm the transmission when they are ready.
With this system you can read and write flows of any size.

Thanks for replying Coccoliso

  1. Suppose i set all the bits IM_IR0/IM_IR3 so do I get the value of IR register as(0x04) [i.e. socket0 to socket 4 will get set in IR register], if all socket interrupt comes simultaneously.

  2. what are the reasons you have found to not use interrupt ??? and what are the benefits of reading directly Sn_RX_RSR register ???

  1. it’s ok
  2. the term “bottleneck” isinaccurate forgive me. It depends on the idle time you have available. If the purpose is to provide answers (web server) then you’re always waiting for the same condition and between test a pin or read a register there is no changes except the hw latency… and since we really do not have other things to do in the meantime :wink: unless you can find something else to do :laughing: .
    In a case you must first read the register and understand what is the socket and then read if it is in reading and then read the amount of data… the other case directly read socket stat and then the amount of data.

There is a bug when using the sockets. Specifically when you try using multiple sockets the outcome that you are trying to get would not come out as you planned, there will be incorrect data exchange. The code use for calculating the pointers into the device does not match that of the sockets. There is a delay so the timing of the data transmitted are not in synchronized at the sockets.

Are you talking about transmission or reception?
You can give a concrete example of what happens?
What is making the W5100 and how are you testing?
Are you using SPI?
You’re using TCP?

Hello there,

I’m using w5100 from Wiznet in a project where it interfaces a MC56f355 from Freescale. It worked very well until now when I tried to use another socket along with my primary one.

What happens is that apparently my Recv() function is not correctly reading message from sockets others than socket 0.

As I’m reading the packages (short ones) as soon as they arrive, the masked address should always be 0. But, the offaddr variable come with a different value for every massage, which do not occur when using socket 0.

See some of my code bellow:

unsigned int Recv_Eth(unsigned char sock,unsigned char *buf1,unsigned int buflen)
{
    unsigned int ptr,offaddr,realaddr;   	

    if (buflen <= 0 || sock >3) return 1;   

    // If the request size > MAX_BUF,just truncate it
    if (buflen > MAX_BUF)
      buflen=MAX_BUF - 2;
    // Read the Rx Read Pointer
    ptr = SPIRead_Eth(S0_RX_RD+(sock*0x0100));
    offaddr = (((ptr & 0x00FF) << 8 ) + SPIRead_Eth(S0_RX_RD+(sock*0x0100) + 1));
    
    while(buflen) {
      buflen--;
      realaddr=RXBUFADDR + (offaddr & (RX_BUF_MASK+(sock*2048)));
      *buf1 = SPIRead_Eth(realaddr);
      offaddr++;
      buf1++;
    }
    *buf1='\0';        // String terminated character

    // Increase the S0_RX_RD value, so it point to the next receive
	SPIWrite_Eth(S0_RX_RD+(sock*0x0100),(offaddr & 0xFF00) >> 8 );
	SPIWrite_Eth(S0_RX_RD+(sock*0x0100) + 1,(offaddr & 0x00FF));	

    // Now Send the RECV command
    SPIWrite_Eth(S0_CR+(sock*0x0100),CR_RECV);
    DELAY_Eeprom(5);    // Wait for Receive Process

    return 1;
}

Could you help me cast a light on it?

Thank you very much.

Gustavo Costa
gualcosta@gmail.com

Copyright © 2017 WIZnet Co., Ltd. All Rights Reserved.