Net_Ethernet_28j60_UserTCP not called

mikroC, mikroBasic and mikroPascal PRO for Microchip’s 32-bit PIC MCUs
Post Reply
Author
Message
peini
Posts: 46
Joined: 28 Dec 2011 09:56

Net_Ethernet_28j60_UserTCP not called

#1 Post by peini » 01 Jul 2019 10:07

Hello

I've created a TCP Server app using the "Network Ethernet Library" from Libstock.
Connecting to it with a simple C# application works find and i'am receiving some data.
My UserTCP method looks like this:

Code: Select all

void Net_Ethernet_28j60_UserTCP ( SOCKET_28j60_Dsc *socket )
{
  // We only listen on port 1234
  if( socket->destPort != 1234 )
      return;

  Debug.WriteLine( "User TCP" );

  if ( m_tcpSocket == NULL )
  {
      Debug.WriteLine( "Socket opened" );
      m_tcpSocket = socket;
      Net_Ethernet_28j60_putStringTCP( "Hello", m_tcpSocket );
  }
  else
  {
      if ( m_bTcpSend )
      {
          Debug.WriteLine( "Send hello" );
          Net_Ethernet_28j60_putStringTCP( "Hello", m_tcpSocket );
          m_bTcpSend = 0;
      }
  }
}
The socket will be opened and "Hello" will be returned. This part is working fine.
But now i want the Server to actively send some data to the host without a request from the host.
I've read that i have to call "Net_Ethernet_28j60_startSendTCP" but the problem is that "Net_Ethernet_28j60_UserTCP" is never called anymore.
The TCP connection is still open.

Somewhere else in the code:

Code: Select all

m_bTcpSend = 1;
Net_Ethernet_28j60_startSendTCP( m_tcpSocket );
What is wrong here?
Am i understanding the concept right?

peini
Posts: 46
Joined: 28 Dec 2011 09:56

Re: Net_Ethernet_28j60_UserTCP not called

#2 Post by peini » 02 Jul 2019 14:48

Ok, solved it by myself.
The problem was the use of FreeRTOS where Net_Ethernet_28j60_startSendTCP( m_tcpSocket ); has been called from another thread than doPackets() without using a mutex.
Now its working correctly.
Here is the new code if someone needs it:

Code: Select all

if ( xSemaphoreTake( m_ethLock, 10 ) == pdTRUE )
{
    m_bTcpSend = 1;
    Net_Ethernet_28j60_startSendTCP( m_tcpSocket );
    xSemaphoreGive( m_ethLock );
}
and

Code: Select all

if ( xSemaphoreTake( m_ethLock, 10 ) == pdTRUE )
{
      // Process incoming ethernet packets
      Net_Ethernet_28j60_doPacket();
      xSemaphoreGive( m_ethLock );
}

User avatar
petar.suknjaja
mikroElektronika team
Posts: 683
Joined: 05 Mar 2018 09:44
Location: Belgrade

Re: Net_Ethernet_28j60_UserTCP not called

#3 Post by petar.suknjaja » 03 Jul 2019 08:04

Hi,
Thank you for letting us know,
Kind regards,
Petar

Post Reply

Return to “PIC32 PRO Compilers”