New Ethernet library with improved TCP/IP Stack

Discuss with MikroElektronika software developers about current library development.
Author
Message
borris
Posts: 219
Joined: 22 Aug 2011 07:13

Re: New Ethernet library with improved TCP/IP Stack

#76 Post by borris » 23 Jul 2013 19:56

Hurtz Hurty wrote:Hello Darko,

an implementation of the network time protocol (NTP)
with run time compensation would be very useful.

Have a sunny weekend ...
I have such an implementation in my webserver. Easy to add.

You can see how I have done it in my libstock project: http://www.libstock.com/projects/view/7 ... l-featured

borris
Posts: 219
Joined: 22 Aug 2011 07:13

Re: New Ethernet library with improved TCP/IP Stack

#77 Post by borris » 23 Jul 2013 20:58

On headers that include content length I am able to detect when the file download is complete but on some server where they don't include the content length, how do I detect when finished?

The state on the sockets don't seem to include the state of received FIN from server.

Any ideas on how I would detect when a server is finished sending data?

borris
Posts: 219
Joined: 22 Aug 2011 07:13

Re: New Ethernet library with improved TCP/IP Stack

#78 Post by borris » 25 Jul 2013 20:25

I must say, with these more elaborate libraries, it is INCREDIBLY frustrating that I cannot see the source. I have to guess all the time as to what it is doing and it causes me severe hair loss. I would urge that some policy change be made to allow us to see some of the mechanics. That way, I can answer the majority of my questions and not have to post the question here, then wait for a week to find out the answer.

Here is what I am doing an have no idea if this is going to effect the system negatively as a whole. I am using DMA memory to memory transfer to copy the frame data from RAM to the txBuffer on the socket. When I start the transfer I also increment the lastWritten by the number of bytes transferred. It works and is fast, but how do these variables work in the library. Are they a continuous block of memory? Am I going to break the socket by manipulating the lastWritten member? Will this effect that stability of the system?

borris
Posts: 219
Joined: 22 Aug 2011 07:13

Re: New Ethernet library with improved TCP/IP Stack

#79 Post by borris » 26 Jul 2013 11:59

Verified. DNSResolve function is failing on STM hardware but NOT on external 28j60.

I am still suffering from my dnsResolution not happening the first few attempts on the STM hardware. This problem is not present on the AVR running with the external 28j60. Running the same function calls. What type of initialization routine is happening behind the scenes that could cause this? Is anyone else having this issue?

borris
Posts: 219
Joined: 22 Aug 2011 07:13

Re: New Ethernet library with improved TCP/IP Stack

#80 Post by borris » 31 Jul 2013 06:08

Anyone out there? The issues appear to be coming in the form of something amiss with the Internal Ethernet on STM mcus. Here is a videohttp://youtu.be/9ySKFEIVCok (terrible quality, sorry) showing the exact same code running on AVR and STM side by side. Top one STM bottom AVR. AVR has 0 failures and takes just a few minutes. STM takes several minutes and has multiple failures.

After about 2 minutes the STM hardware seems stable, but before then it is not.

Another issue is that there must be some type of suspended / sleep state on the internal STM. After the MCU has sat idle for a couple of minutes it becomes unresponsive. It appears that it then awakens because if you wait until it fails and then press refresh, it is fast as a Ferrari. I need some help here guys.

I've included the code. Simple as possible.
Attachments
dnsTest.zip
(18.54 KiB) Downloaded 455 times

User avatar
darko.jola
Posts: 51
Joined: 03 Aug 2011 16:18

Re: New Ethernet library with improved TCP/IP Stack

#81 Post by darko.jola » 01 Aug 2013 07:37

Hello
I download your code and change only network parameters. I try it multiple times and always get same result: 0 fails.
Image
Image
Untitled.jpg (32.67 KiB) Viewed 21426 times
I can see from your code that you use different config parameter during init on AVR and STM. It works for me, but is could be possible that AUTO_NEGOTIATION makes problem to you.
Can you try with: Net_Ethernet_Init( myMacAddr, myIpAddr, _ETHERNET_FULLDUPLEX | _ETHERNET_SPD10, &_GPIO_MODULE_ETHERNET );
Also, we detect some hardware problem on STM-M4 with ethernet speed 100 Mbit/s, so you should use _ETHERNET_SPD10 in init function.

Best regards
Darko

borris
Posts: 219
Joined: 22 Aug 2011 07:13

Re: New Ethernet library with improved TCP/IP Stack

#82 Post by borris » 03 Aug 2013 05:59

I am going to guess that it has to be a hardware incompatibility with the STM hardware with my lab hardware. The ENC28J60 is rock solid.

I've tried every combination possible as well as my own register hacks to have the same behavior. I've been completely unsuccessful in getting the SP100 option to work.

I've noticed that there are varied delays in when the LED1 on the EasyMx Pro V7 will turn on. Before I perform hours of searching, what registry can I poll to wait for that LED?

borris
Posts: 219
Joined: 22 Aug 2011 07:13

Re: New Ethernet library with improved TCP/IP Stack

#83 Post by borris » 04 Aug 2013 20:47

I'm wondering..... Your demo for the Ethernet library includes a header of:

Code: Select all

const code unsigned char httpImage[] = "HTTP/1.1 200 OK\nConnection: keep-alive\nContent-type: image/jpg\n\n";
However, I do no see a Keep-Alive flag or anyway to detect that. How is keep-alive implemented in the library?

User avatar
darko.jola
Posts: 51
Joined: 03 Aug 2011 16:18

Re: New Ethernet library with improved TCP/IP Stack

#84 Post by darko.jola » 07 Aug 2013 08:39

Hello,
active LED1 indicating valid link, and blinks to indicating link activity. You can check status of link by poling bit 2 of Basic Status register of LAN8720 phy chip.
You can use some code like this:

Code: Select all

const char _PHY_BSR = 1;
int regValue;
...
  regValue = 0;
  while(!(regValue & 0b100)) {
    Net_Ethernet_Intern_PHY_Read(_PHY_BSR, &regValue);
  }
...
Keep-alive is not implemented in library. Purpose of Header containing keep-alive type is backward compatibility with some our previous project, but I agree that it should be removed in our next release.

Best regards
Darko

phil31
Posts: 348
Joined: 02 Apr 2009 15:02
Location: France
Contact:

Re: New Ethernet library with improved TCP/IP Stack

#85 Post by phil31 » 26 Jan 2014 23:12

borris wrote:I must say, with these more elaborate libraries, it is INCREDIBLY frustrating that I cannot see the source. I have to guess all the time as to what it is doing and it causes me severe hair loss. I would urge that some policy change be made to allow us to see some of the mechanics. That way, I can answer the majority of my questions and not have to post the question here, then wait for a week to find out the answer.
i totaly agree Borris :o) vote +1 !

JMAT
Posts: 3
Joined: 27 Dec 2014 19:41

Re: New Ethernet library with improved TCP/IP Stack

#86 Post by JMAT » 27 Dec 2014 21:21

I have worked with TCp/ip stack from mikroc for avr, but I have a issue. I have implemented the code for server but when I am checking the dataLength (receiving data from client) I have seen that these data arrives incompletes and takes a lot of time read all the data packets. This problem is very important, the client is a web service made in asp net then the socket ( in web service) throw a exception because tcp stack does not send back the all data. What happen with stack?

the flow chart is this:

TCP Client software -> TCP server atmega1284p(usart)-> (usart) another device

(usart) another device -> (usart)TCP server atmega1284p TCP -> TCP Client software


I do not know what happened, I am testing for a week, and suddenly this problem appears.

Can you help me??

void Net_Ethernet_28j60_UserTCP(SOCKET_28j60_Dsc *socket)
{
unsigned char len;
// I listen only to web request on port 80

if(socket->destPort != destPort)
{return;}

Tsocket = socket;

if(Tsocket->dataLength==0)
{
/*
if(TcpTxOverFlow)
{
Usart_Rx = OldUsart_Rx;
Usart_Rx_int = OldUsart_Rx_int;
}
*/


while (DataRxInBuffer())
{
TcpTx = ReceiveByte();
TcpTxOverFlow = Net_Ethernet_28j60_putByteTCP(TcpTx, Tsocket);


if(!TcpTxOverFlow)
{
PORTA.F0=1;
break;
/*
TcpTxOverFlow=1;
OldUsart_Rx = Usart_Rx;
OldUsart_Rx_int = Usart_Rx_int-1;
break;
*/
}

}
/*
if( Net_Ethernet_28j60_bufferEmptyTCP(Tsocket))
{
} */
TcpTx_bit = 1;
}
else if (Tsocket->dataLength > 0)
{
TcpRxStart = TcpRxCont;

for(len = TcpRxStart; len < (Tsocket->dataLength + TcpRxStart); len++)
{
TcpRx = Net_Ethernet_28j60_getByte();
TransmitByte(TcpRx);
TcpRxCont++;
}

TcpRx_bit = 1;

}

}

murphytheruler
Posts: 6
Joined: 17 Nov 2015 09:52

Re: New Ethernet library with improved TCP/IP Stack

#87 Post by murphytheruler » 26 Sep 2016 12:51

Hello all,

We are using PIC33EP256GM310.
I am only responsible for TCP/IP communication part of the software.
Ethernet IC is ENC28J60 and INT pin is directly connected to pin56 (RPI[color=52) of PIC33EP256GM310.
I like to use ENC28J60 in interrupt level.

here is the some definitions

Code: Select all

 void enableinterrupts(void)
{
  /* enable level 1-7 interrupts */
  /* no restoring of previous cpu ipl state performed here */
  intcon2bits.gie = 1;
  return;
}

Code: Select all

void disableinterrupts(void)
{
  /* disable level 1-7 interrupts */
  /* no saving of current cpu ipl setting performed here */
  intcon2bits.gie = 0;
  return;
}

Code: Select all

void initinterrupts(void)
{
  
  intcon1bits.nstdis = 1;               /* interrupt nesting disabled here */

  iec1bits.int1ie = 0;                  /* disable int1 interrupt */
  ipc5bits.int1ip = 7;                  /* highest priority */
  intcon2bits.int1ep = 1;               /* edge polarity ( 1 rising, 0 falling edge )  */
  iec1bits.int1ie = 1;                  /* enable int1 interrupt */
  ifs1bits.int1if = 0;                  /* reset int1 interrupt flag */

  return;
}
main while loop is like that

Code: Select all

  while (1) {
    asm clrwdt;
    Net_Ethernet_28j60_doPacket();  // process incoming Ethernet packets

    if ( sock->state == 3 ) {
      if (flagset == 1) {
        Net_Ethernet_28j60_startSendTCP(sock);      // put a ram string into enc28j60 buffer , and transfer immediately
        flagset  = 0 ;
        }
      Delay_ms(1000);
      }

    }


I also do pps mapping like that

Code: Select all

  pps_mapping([color=52, _INPUT, _INT1) ;
  SPI1_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, _SPI_PRESCALE_PRI_1, _SPI_PRESCALE_SEC_4, _SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_IDLE_2_ACTIVE);

and I write the desired values to the EIE and read it to verify.

Code: Select all

  Net_Ethernet_28j60_writeReg(EIE,0x80+0x40+0x08);
  EthernetInterruptEnableRegister = Net_Ethernet_28j60_readReg(EIE);
  if (EthernetInterruptEnableRegister == 0xC8 ) {
     led_ylw = 1;
     }
furthermore, yellow led is activated.

I sent HTTP request to the ENC28J60,

but nothing happens.

what should I do ??

full project file is attached.
Attachments
ENC28J60 - NET.zip
(1.99 MiB) Downloaded 287 times

User avatar
Aleksandar.Mitrovic
mikroElektronika team
Posts: 1697
Joined: 11 Mar 2015 12:48

Re: New Ethernet library with improved TCP/IP Stack

#88 Post by Aleksandar.Mitrovic » 28 Sep 2016 08:49

Hi,

Welcome to mikroE forum.

Have you tried to start example which we have in our compiler for server and first test your hardware?

Kind regards,
Aleksandar

murphytheruler
Posts: 6
Joined: 17 Nov 2015 09:52

Re: New Ethernet library with improved TCP/IP Stack

#89 Post by murphytheruler » 04 Oct 2016 19:49

hello,

interrupt works now.
i have a different problem now.
i connet to PC from PCB.
i keep sending messages to the PCB from PC, it also works .
but after couple of messages, namely 10 or 15,
PCB doesnt sent ACK

here it is userTCP

Code: Select all

void Net_Ethernet_28j60_UserTCP(SOCKET_28j60_Dsc *socket) {
  unsigned int    len;

  // I listen only to web request on port 80
  if(socket->destPort != 3460) {
    return;
    }

  // get aa bytes only of the request
  for(len = 0; len < socket->dataLength ; len++){
    received[len] = Net_Ethernet_28j60_getByte();
    }
  received[len] = 0;

  if (received[1] == 0x7C ) {     // "|"

    switch (received[0]) {
          case 0x31:
                dat = "OK|1\n";
                dat_pos = 0;
                break;
      case 0x32:
                dat = "OK|2\n";
                dat_pos = 0;
                break;
      case 0x33:
                dat = "OK|3\n";
                dat_pos = 0;
                break;
      case 0x34:
                dat = "OK|4\n";
                dat_pos = 0;
                break;
      case 0x36:
                dat = "OK|6\n";
                dat_pos = 0;
                break;
      case 0x37:
                dat = "OK|7\n";
                dat_pos = 0;
                break;
      }
    }

  if (dat_pos == 0 ) {
    while(dat_pos < strlen(dat)) {
      if(Net_Ethernet_28j60_putByteTCP(dat[dat_pos++], socket) == 0) {
        dat_pos--;
        break;
        }
      }

    while (Net_Ethernet_28j60_bufferEmptyTCP(socket) == 1) {
      led_red =  ~led_red ;
      delay_ms(100);
      }
    }

  }

it would be very kind of you, if you could publish full help document for Network_Ethernet_dsPIC, namely Net_Ethernet_28j60

full project is attached.
ENC28J60 - NET.zip
(2.05 MiB) Downloaded 315 times

User avatar
Aleksandar.Mitrovic
mikroElektronika team
Posts: 1697
Joined: 11 Mar 2015 12:48

Re: New Ethernet library with improved TCP/IP Stack

#90 Post by Aleksandar.Mitrovic » 05 Oct 2016 16:41

Hi,

What are you sending to the PIC?
Have you tried this example in debug mode?
murphytheruler wrote:it would be very kind of you, if you could publish full help document for Network_Ethernet_dsPIC, namely Net_Ethernet_28j60
With which routine you have a problem?

Kind regards,
Aleksandar

Post Reply

Return to “Library Development Discussion”