System initialization

When performing manual initialization of lwIP for use with the raw API, the function lwip_init() can be called to perform the core setup. Depending on the actual <lwipopts.h> configuration lwip_init() will call the necessary routines to initialize the required lwIP sub-systems.

In this example, these functions must be called in the order of appearance:

lwip_init()

Calls the individual, as configured, low-level lwIP module initialization routines.

If LWIP_ARP is defined then etharp_tmr() must be called at the regular ARP_TMR_INTERVAL interval (default 5 seconds) after the system has been initialized by this call.

Similarly if LWIP_TCP is defined then you must ensure that tcp_fasttmr() and tcp_slowtmr() are called at the predefined regular intervals.

struct netif *netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask, struct ip_addr *gw, void *state, err_t (* init)(struct netif *netif), err_t (* input)(struct pbuf *p, struct netif *netif))

Adds your network interface to the netif_list. Allocate a struct netif and pass a pointer to this structure as the first argument. Give pointers to cleared struct ip_addr structures when using DHCP, or fill them with sane numbers otherwise. The state pointer may be NULL.

The init function pointer must point to an initialization function for your ethernet netif interface. The following code illustrates an example use:

err_t netif_if_init(struct netif *netif)
{
  u8_t i;
  
  for(i = 0; i < 6; i++)
    netif->hwaddr[i] = some_eth_addr[i];
  init_my_eth_device();
  return ERR_OK;
}
          

Normally for ethernet devices the input function must point to the lwIP function ethernet_input().

netif_set_default(struct netif *netif)

Registers netif as the default network interface.

netif_set_up(struct netif *netif)

When netif is fully configured, this function must be called to allow it to be used.

dhcp_start(struct netif *netif)

If LWIP_DHCP is configured then this function creates a new DHCP client for this interface the first time the routine is called. Note: you must call dhcp_fine_tmr() and dhcp_coarse_tmr() at the predefined regular intervals after starting the client.

You can peek in the netif->dhcp struct for the actual DHCP status.

Initialization detail

If required the manual raw API initialization could directly call the required lwIP sub-system module initialization functions (rather then calling the lwip_init() function).

The calls should be performed in the following order:

stats_init()

Clears the structure where runtime statistics are gathered.

Note: The statistics support is only included if LWIP_STATS is configured, and then some of the statistics code is only present if LWIP_DEBUG is also defined.

sys_init()

Not generally used with raw API, but can be called for ease of compatibility if using sequential API in addition, initialised manually. The lwip_init() implementation only calls this function if NO_SYS is NOT defined.

mem_init()

Initializes the dynamic memory heap defined by the CDL configuration option CYGNUM_LWIP_MEM_SIZE.

memp_init()

Initializes the memory pools defined by the CDL configuration options CYGNUM_LWIP_MEMP_NUM_*.

pbuf_init()

Initializes the pbuf (packet buffer) memory pool defined by the CDL configuration option CYGNUM_LWIP_PBUF_POOL_SIZE.

netif_init()

This function will call netif_add() as appropriate to create the LWIP_HAVE_LOOPIF configured loopback network interface.

lwip_socket_init()

If LWIP_SOCKET is configured then this function is called to initialise the BSD-alike API module. It does not do much at present, but it should be called to handle future changes.

ip_init()

This function does not do much at present, but it should be called to handle future changes.

etharp_init()

Called if LWIP_ARP is configured to initialize the ARP table and queue.

Note: you must regularly call the etharp_tmr function at the ARP_TMR_INTERVAL (default 5 seconds) interval after this initialization.

raw_init()

If LWIP_RAW is configured then this function is called. It does not do much at present, but it should be called to handle future changes.

udp_init()

If LWIP_UDP is configured then this function is called to initialize the required UDP support state.

tcp_init()

If LWIP_TCP is configured then this function is called to initialise the required TCP support state.

Note: you must call tcp_fasttmr() and tcp_slowtmr() at the predefined regular intervals after this initialization.

snmp_init()

If LWIP_SNMP is configured then this function is called to start the SNMP agent support. It allocates a UDP pcb and binds it to IP_ADDR_ANY for the SNMP_IN_PORT (default 161) configured port, listening for SNMP The routine will also generate a SNMP coldstart trap if configured appropriately.

autoip_init()

If LWIP_AUTOIP is configured then this function is called for the IPv4 AutoIP support. It does not do much at present, but it should be called to handle future changes.

igmp_init()

If LWIP_IGMP is configured then this function is called for the IPv4 IGMP support. It configures the allsystems and allroutes multicast addresses.

dns_init()

If LWIP_DNS is configured then this function is called to allocate the UDP pcb for the client and initialise the default DNS server address.

ip6_init()

If LWIP_IPV6 is configured then this function is called. It does not do much at present, but it should be called to handle future changes.

nd6_init()

If LWIP_IPV6 is configured then this function is called. It does not do much at present, but it should be called to handle future changes.

mld6_init()

If LWIP_IPV6 and LWIP_IPV6_MLD are configured then this function is called. It does not do much at present, but it should be called to handle future changes.

sys_timeouts_init()

If LWIP_TIMERS is configured then this function is called. It uses the sys_timeout() to register timeout callbacks for the configured lwIP features. Normally the raw API will not be providing the sys_timeout functionality, and will, as mentioned above, have to manually ensure the relevant timeout functions are called. e.g. ARP, TCP, etc.

2017-02-09
Documentation license for this page: eCosPro License