Software Initialization

net_init()

int32_t net_init (char *ip,
char *subnet,
char *gateway,
uint32_t (*dhcp_func)(char *, uint16_t),
char *dns,
uint32_t (*dns_func)(void));
The net_init() function is the main TCP stack initialization function. It MUST be called once prior to any other net_lib function calls (except dsk_init() or EmacInit() resp.). Parameters depend on the TCP/IP configuration of your network. Two basic configurations can be distinguished:

  • manually administered network: IP addresses, host names, subnet mask etc. are manually assigned to each network station
  • DHCP administered network: A DHCP server automatically assigns IP addresses and provides additional information (subnet mask, DNS server, gateway).
If your network is manually administered, ask you network administrator for the following settings: IP address, subnet mask, IP address of your default gateway, and DNS server IP address if any. Subnet mask and gateway are required for connections to hosts outside your local subnet.

A DNS server is used to resolve symbolic host names to IP addresses. A typical example is the Internet: www.ti.com is much easier to remember than the IP address 192.91.75.198. A DNS server resolves this name to the actual IP address each time you connect to www.ti.com. If no DNS server is available, but symbolic host names should be used, each host has to maintain a hosts file from which IP addresses for a given host name are read. Since a DSP system typically doesn't imply a file system, you must use defines or variables to assign an IP address to a symbolic name.

If your network is DHCP-based you don't have to care about these configuration settings. If net_init() is called, your system will send a DHCP request via the network. DHCP requests are broadcast messages, which are answered only by a dedicated DHCP server. This server then responds with an IP address, DNS server address, subnet mask and gateway which are automatically configured by net_init(). You must only specify the DSP system's host name. This must be the "fully qualified host name" including the domain name, e.g. "dsp.company.net". A DHCP-based network always uses symbolic host names because the IP address assigned to a host may change if host is shut-down and not restarted before the DHCP lease time is expired.

Example configuration static IP address, DHCP disabled, DNS disabled:

/***************************************************************************
init sockets
***************************************************************************/
if ( !net_init ("192.168.168.200", "255.255.255.0", NULL, NULL, NULL, NULL))
{
prg_exit ("net_init() failed"); /* out of memory, try to increase heap */
}


Example configuration static IP address, DHCP disabled, DNS enabled, DNS server IP 192.168.168.1:

/***************************************************************************
init sockets
***************************************************************************/
if ( !net_init ("192.168.168.200", "255.255.255.0", NULL, NULL, "192.168.168.1", DNS_ENABLE))
{
prg_exit ("net_init() failed"); /* out of memory, try to increase heap */
}


Example configuration dynamic IP address, DHCP enabled, DNS enabled:

/***************************************************************************
init sockets
***************************************************************************/
if ( !net_init ("dsp.company.net", NULL, NULL, DHCP_ENABLE, NULL, DNS_ENABLE))
{
prg_exit ("net_init() failed"); /* out of memory, try to increase heap */
}


Example configuration using variables from netconfig.c:

Refer to Device Specific Initialization file netconfig.c

/***************************************************************************
init sockets using variables from netconfig.c
***************************************************************************/
{
prg_exit ("net_init() failed"); /* out of memory, try to increase heap */
}