This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problems using UDP (ERR_MEM_ALLOC)

Hi,

I have a negative effect while using UDP for sending data between my controller (NXP LPC2368)and PC. I use not the RTOS (anyway with RTOS i had the same problem)!
I using two sockets with different portnumbers - one for receiving - one for transmitting. In my UDP-callback I use no routines like udp_get_buf() or send_udp(). In the UART-ISR I send data to the PC (~2,5 MBit) using udp_get_buf() and udp_send().

The bandwith-, RAM- and CPU-usage is not to hard at all (using GPIO to measure the CPU-usage of each routine).

Everything is working very well as long as I send (2,5MBit) and receive(1kBit) not simultaniously! I this case the system runs well for some seconds and fail with "ERR_MEM_ALLOC" in "void sys_error()" (part of Net_Config).

I tried different settings for Stack- and Heap-Size and the usage of RTOS - allways the same.

The important parts of my source:

__irq void UART1_ISR(void)
{
 ...
 datasendbuf = udp_get_buf (6+(40*12));
 memcpy(datasendbuf,"^GMC",4);
 ...(memcpy)...                 }
 udp_send (udp_soc1, GMC_remip, GMC_port, datasendbuf, 6+(40*12));
 ...
 VICVectAddr = 0;                           //Acknowledge Interrupt
}


U16 udp_callback (U8 socket, U8 *remip, U16 port, U8 *buf, U16 len)
{
 U8 *sendbuf;
 char rx;
 short x;

 if(socket == udp_soc)
 {
   //Interpreter
   x=0;
   while(x<len)
   {
     rx = buf[x];       //Buffer Zeichenweise auslesen
     x++;
     if(rx=='^')                //Auf Startzeichen prüfen
     {
        rx_start = 1;
        rx_CR = 0;
         udp_in_pointer = 0;
     }
     if(rx_start)
     {
        udp_in[udp_in_pointer] = rx;    //Daten in Puffer übernehmen
        udp_in_pointer++;
        if(rx_CR)
        {
          if(rx == '\n')//Warten bis Endekennung empfangen
          {
             //Befehlshandler
                 if(!strncmp(udp_in+1,"GMC",3))
                {
                        SMP = 0;
                        GMC = read_RS232_int(udp_in+4,4);
                         memcpy(GMC_remip,remip,4);
                        GMC_port = port;
                }
                 else if(!strncmp(udp_in+1,"GCH",3))
                 {
                           //Comming soon
                }
          }
        }
        else
        {
          if(rx == '\r')rx_CR=1;
        }
        if(udp_in_pointer==255)
        {
          rx_start = 0;
        }
       }
     }
   }
  return (0);
}

void init (void)
{
  init_mcu ();
  init_variables();
  Timer_Init()  ;
  init_TcpNet ();

  read_settings();

  //UDP-Socket for transmit
  udp_soc1 = udp_get_socket (0, UDP_OPT_SEND_CS | UDP_OPT_CHK_CS, udp_callback);
  if (udp_soc1 != 0) {
    udp_open (udp_soc1, 0);
  }

  //UDP-Socket for receive
  udp_soc = udp_get_socket (0, UDP_OPT_SEND_CS | UDP_OPT_CHK_CS, udp_callback);
  if (udp_soc != 0) {
    udp_open (udp_soc, 11000);
  }
}

int main (void)
{
        init();

        while(1)
        {
                timer_poll();
                main_TcpNet();
        }
}


Thanks for your comments!

0