Hey guys,

While trying to make lwIP work, with a simple ping I have problems with it.
Trying to debug it I noticed that I cannot allocate memory using
memp_alloc. The problem that I have is that memp_tab[]  is an array with
NULL elements.
I tried to play with the lwipopts.h parameters making sure that I have
enough buffs, I checked if I free properly to prevent leakage but I also
have the problem in the very begining.

I attached the files that might help you help me:D

Best regards,
Angel C

On Wed, Jun 27, 2012 at 5:47 PM, Simon Goldschmidt <[email protected]> wrote:

> Angel CODREAN <[email protected]> wrote:
> > While debugging I got up until memp.c at line 404 memp = memp_tab[type];
> > which returns NULL and I don't manage to understand why.
>
> That simply means you are running out of memory in one of the pools.
> Either you memory is (configured) too small or you are leaking (i.e. not
> freeing) memory somewhere.
>
> Simon
> --
> Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
> belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de
>
> _______________________________________________
> lwip-users mailing list
> [email protected]
> https://lists.nongnu.org/mailman/listinfo/lwip-users
>
/** This file is created by Energy Micro, based on the reptile/lwip/src/include/lwip/opt.h
*   with the following aspects that need to be taken into account
*   * unnecesarry options have been removed 
*   * details about each option can be found in the original file
*   * default values are to be found in the original file
*/

#ifndef _LWIP_OPTS_H_
#define _LWIP_OPTS_H_

#define NO_SYS                          1
#define SYS_LIGHTWEIGHT_PROT            (!NO_SYS)
#define MEM_ALIGNMENT                   4
#define MEM_SIZE                        128 * 1024

/** Internal memory pool sizes */
#define MEMP_NUM_PBUF                   16
#define MEMP_NUM_NETBUF                 16
#define MEMP_NUM_RAW_PCB                16
#define MEMP_NUM_UDP_PCB                4
#define MEMP_NUM_TCP_PCB                5
#define MEMP_NUM_TCP_PCB_LISTEN         8
#define MEMP_NUM_TCP_SEG                16
#define MEMP_NUM_REASSDATA              5
#define MEMP_NUM_FRAG_PBUF              15
#define MEMP_NUM_ARP_QUEUE              30
#define MEMP_NUM_IGMP_GROUP             8
#define MEMP_NUM_SYS_TIMEOUT            8
#define MEMP_NUM_TCPIP_MSG_API          8
#define MEMP_NUM_TCPIP_MSG_INPKT        8
#define MEMP_NUM_SNMP_NODE              50
#define MEMP_NUM_SNMP_ROOTNODE          30
#define MEMP_NUM_SNMP_VARBIND           2
#define MEMP_NUM_SNMP_VALUE             3
#define MEMP_NUM_NETDB                  1
#define MEMP_NUM_LOCALHOSTLIST          1
#define MEMP_NUM_PPPOE_INTERFACES       1
#define PBUF_POOL_SIZE                  160

/** ARP options */
#define ETH_PAD_SIZE                    2
#define LWIP_ARP                        1
#if LWIP_ARP == 1
#define ARP_TABLE_SIZE                  30
#define ARP_QUEUEING                    1       
#define ETHARP_TRUST_IP_MAC             0
#define ETHARP_SUPPORT_VLAN             0
#define LWIP_ETH_ARP_INTERVAL           2000 /**< ARP timer interval in miliseconds */
#endif

/** IP options */
#define IP_FORWARD                      0
#define IP_OPTIONS_ALLOWED              1
#define IP_REASSEMBLY                   0
#define IP_FRAG                         0
#define IP_DEFAULT_TTL                  255

/** ICMP options */
#define LWIP_ICMP                       1
#define LWIP_BROADCAST_PING             1
#define LWIP_MULTICAST_PING             1

/** RAW options */
#define LWIP_RAW                        1

/** DHCP options */
#define LWIP_DHCP                       0

/** AUTOIP options */
#define LWIP_AUTOIP                     1
#define LWIP_DHCP_AUTOIP_COOP           0

/** SNMP options */
#define LWIP_SNMP                       0

/** IGMP options */
#define LWIP_IGMP                       1

/** DNS options */
#define LWIP_DNS                        0

/** UDP options */
#define LWIP_UDP                        1
#define LWIP_UDPLITE                    0
#define LWIP_NETBUF_RECVINFO            0

/** TCP options */
#define LWIP_TCP                        1
#define LWIP_TCP_TIMESTAMPS             0
#define TCP_WND                         8192
#define TCP_MAXRTX                      10
#define TCP_SYNMAXRTX                   3
#define TCP_QUEUE_OOSEQ                 1
#define TCP_MSS                         1460
#define TCP_SND_BUF                     (8 * TCP_MSS)
#define TCP_SND_QUEUELEN                (2 * TCP_SND_BUF/TCP_MSS)
#define TCP_SNDLOWAT                    (TCP_SND_BUF/2)
#define TCP_LISTEN_BACKLOG              1
#define LWIP_ETH_TCP_INTERVAL 2000 /**< TCP timer interval in miliseconds */

/** Pbuf options */
#define PBUF_POOL_BUFSIZE               1520		// + sizeof(pbuf) = 1536 = 12 cache lines of 128 bytes
#define PBUF_LINK_HLEN                  (14 + ETH_PAD_SIZE)

/** Network Interfaces options */
#define LWIP_NETIF_HOSTNAME             1
#define LWIP_NETIF_API                  (!NO_SYS)
#define LWIP_NETIF_HWADDRHINT           1
#define LWIP_NETIF_LOOPBACK             1
#define LWIP_NETIF_LINK_CALLBACK        1

/** LOOPIF options */
#define LWIP_HAVE_LOOPIF                0

/** Thread options */
#define TCPIP_MBOX_SIZE                 32
#define DEFAULT_UDP_RECVMBOX_SIZE       32
#define DEFAULT_TCP_RECVMBOX_SIZE       32
#define DEFAULT_ACCEPTMBOX_SIZE         4

/** thread priorities are in VDK terms - 1 is highest, 30 is lowest */
#define TCPIP_THREAD_PRIO               5
#define DEFAULT_THREAD_PRIO             10
#define LOW_THREAD_PRIO                 29

/** Sequential layer options */
#define LWIP_NETCONN                    (!NO_SYS)

/** Socket options */
#define LWIP_SOCKET                     (!NO_SYS)
#define LWIP_COMPAT_SOCKETS             1
#define LWIP_TCP_KEEPALIVE              1
#define LWIP_SO_RCVTIMEO                1
#define LWIP_SO_RCVBUF                  0
#define SO_REUSE                        1
#define SO_REUSE_RXTOALL                1

/** Statistics options */
#define LWIP_STATS                      1
#define LWIP_STATS_LARGE                1
#if LWIP_STATS
#define LINK_STATS                      1
#define IP_STATS                        1
#define IPFRAG_STATS                    1
#define ICMP_STATS                      1
#define IGMP_STATS                      1
#define UDP_STATS                       1
#define TCP_STATS                       1
#define MEM_STATS                       1
#define MEMP_STAT                       1
#define SYS_STATS                       1
#define LWIP_STATS_DISPLAY              1
#endif /* STATS */
#define LWIP_PROVIDE_ERRNO              1

/** Debugging options */
#define LWIP_DBG_MIN_LEVEL              LWIP_DBG_LEVEL_ALL
#define LWIP_DEBUG 1
#define LWIP_DBG_TYPES_ON               LWIP_DBG_STATE
#define ETHARP_DEBUG                    LWIP_DBG_ON
#define NETIF_DEBUG                     LWIP_DBG_ON
#define PBUF_DEBUG                      LWIP_DBG_ON
#define API_LIB_DEBUG                   LWIP_DBG_ON
#define API_MSG_DEBUG                   LWIP_DBG_ON
#define SOCKETS_DEBUG                   LWIP_DBG_ON
#define ICMP_DEBUG                      LWIP_DBG_ON
#define IGMP_DEBUG                      LWIP_DBG_ON
#define INET_DEBUG                      LWIP_DBG_ON
#define IP_DEBUG                        LWIP_DBG_ON
#define IP_REASS_DEBUG                  LWIP_DBG_ON
#define RAW_DEBUG                       LWIP_DBG_ON
#define MEM_DEBUG                       LWIP_DBG_ON
#define MEMP_DEBUG                      LWIP_DBG_ON
#define SYS_DEBUG                       LWIP_DBG_ON
#define TIMERS_DEBUG                    LWIP_DBG_ON
#define TCP_DEBUG                       LWIP_DBG_ON
#define TCP_INPUT_DEBUG                 LWIP_DBG_ON
#define TCP_FR_DEBUG                    LWIP_DBG_ON
#define TCP_RTO_DEBUG                   LWIP_DBG_ON
#define TCP_CWND_DEBUG                  LWIP_DBG_ON
#define TCP_WND_DEBUG                   LWIP_DBG_ON
#define TCP_OUTPUT_DEBUG                LWIP_DBG_ON
#define TCP_RST_DEBUG                   LWIP_DBG_ON
#define TCP_QLEN_DEBUG                  LWIP_DBG_ON
#define UDP_DEBUG                       LWIP_DBG_ON
#define TCPIP_DEBUG                     LWIP_DBG_ON
#define PPP_DEBUG                       LWIP_DBG_ON
#define SLIP_DEBUG                      LWIP_DBG_ON
#define DHCP_DEBUG                      LWIP_DBG_ON
#define AUTOIP_DEBUG                    LWIP_DBG_ON
#define SNMP_MSG_DEBUG                  LWIP_DBG_ON
#define SNMP_MIB_DEBUG                  LWIP_DBG_ON
#define DNS_DEBUG                       LWIP_DBG_ON


#endif // _LWIP_OPTS_H_
#include "lwip_driver.h"
#include "efm32.h"
#include "em_cmu.h"
#include "ksz8851snl_driver.h"
#include "lwip/def.h"
#include "lwip/mem.h"
#include "lwip/pbuf.h"
#include "lwip/sys.h"
#include <lwip/stats.h>
#include <lwip/snmp.h>
#include "netif/etharp.h"
#include "netif/ppp_oe.h"

/** Initialization function that should be passed to netif_add */
err_t  LWIP_driver_init(struct netif *netif)
{
  localNetif = netif;
  netif->name[0] = IFNAME0;
  netif->name[1] = IFNAME1;
  
  netif->output = etharp_output;
  netif->linkoutput = LWIP_driver_output;
  
  /** set the HW address length */
  netif->hwaddr_len = ETH_MAC_ADDR_LEN;
  
  /** set the HW address */
  KSZ8851SNL_getMACAddress(netif->hwaddr);

  /** set the maximum transfer unit */
  netif->mtu = 1500;

  /** Set the flags according to device capabilities */
  netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_LINK_UP | NETIF_FLAG_ETHARP ;

  /** initialize the timers */
  timestamp_ETH_ARP = *timestamp_current;
  timestamp_ETH_TCP = *timestamp_current;

  /** initialize the hardware */
  KSZ8851SNL_init();

  return ERR_OK;
}

u32_t sys_now(void)
{
  return *timestamp_current; 
}

/** Called when a raw packet is ready to be transmitted. */
err_t LWIP_driver_output(struct netif *netif, struct pbuf *p)
{
  struct pbuf *q;
//#if ETH_PAD_SIZE
//  pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
//#endif
  for(q = p; q != NULL; q = q->next) {
    KSZ8851SNL_send(p->tot_len, p->payload);
  }
//#if ETH_PAD_SIZE
//  pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
//#endif  
  
  LINK_STATS_INC(link.xmit);
  
  return ERR_OK;
}

///** Called when a packet is received */
//err_t LWIP_driver_input(struct pbuf *pbuf, struct netif *netif)
//{  	
//  uint16_t length;
//  //TODO improve this
//  uint8_t payload[1500];
//  KSZ8851SNL_receive(payload, &length);
//  struct pbuf *p = pbuf_alloc(PBUF_RAW, length, PBUF_POOL);
//  p->len=length;
//  p->tot_len+=length;
//  for (int i=0;i<length;i++)
//  {
//   (p->payload)[i] = (uint8_t)payload[i];
//  }
//    
//  ethernet_input(p, netif);
//  return ERR_OK;
//}

static void LWIP_driver_input(struct netif *netif)
{
  struct eth_hdr *ethhdr;
  struct pbuf *p;

 /* move received packet into a new pbuf */
  p = low_level_input(netif);
    
  /** no packet could be read, silently ignore this */
  if (p == NULL) return;
  /* points to packet payload, which starts with an Ethernet header */
  ethhdr = p->payload;

 switch (htons(ethhdr->type)) {
    /* IP or ARP packet? */
    case ETHTYPE_IP:
    case ETHTYPE_ARP:
//#if PPPOE_SUPPORT
//  /* PPPoE packet? */
//  case ETHTYPE_PPPOEDISC:
//  case ETHTYPE_PPPOE:
//#endif /* PPPOE_SUPPORT */
    /* full packet send to tcpip_thread to process */
      if (netif->input(p, netif)!=ERR_OK)
      { 
         LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
         pbuf_free(p);
         p = NULL;
      }
      break;

  default:
    pbuf_free(p);
    p = NULL;
    break;
  }
}

static struct pbuf *low_level_input(struct netif *netif)
{
  struct pbuf *p;
  u16_t len=100;
//#if ETH_PAD_SIZE
//  len += ETH_PAD_SIZE; /* allow room for Ethernet padding */
//#endif
  

  /* We allocate a pbuf chain of pbufs from the pool. */
  p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
  if (p != NULL) 
  {
    KSZ8851SNL_receive(p->payload, &(p->len));

   LINK_STATS_INC(link.recv);
  } else 
  {
    //TODO drop packet();
    LINK_STATS_INC(link.memerr);
    LINK_STATS_INC(link.drop);
  }

  return p;  
}

/** Timestamp capabilities */
void LWIP_driver_timestamp_engine(void)
{
  if (abs(timestamp_ETH_ARP - *timestamp_current) >= LWIP_ETH_ARP_INTERVAL) {
      etharp_tmr();
      timestamp_ETH_ARP = *timestamp_current;
  }
  if (abs(timestamp_ETH_TCP - *timestamp_current) >= LWIP_ETH_TCP_INTERVAL) {
      tcp_tmr();
      timestamp_ETH_TCP = *timestamp_current;
  }
}

/** LWIP main loop */
void LWIP_loop(struct netif *netif, uint32_t *global_timestamp)
{
  timestamp_current=global_timestamp;
  while(1)
  {
    LWIP_driver_timestamp_engine();
    LWIP_driver_input(localNetif);//blocking call for the moment
  }
}
_______________________________________________
lwip-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/lwip-users

Reply via email to