#include <cpu_core.h>
#include <lib_mem.h>
#include <Source/net.h>
#include <Source/net_ascii.h>
#include <IF/net_if.h>
#include <IF/net_if_ether.h>
#ifdef NET_IPv4_MODULE_EN
#include <IP/IPv4/net_ipv4.h>
#endif
#ifdef NET_IPv6_MODULE_EN
#include <IP/IPv6/net_ipv6.h>
#endif
#include <Cfg/Template/net_dev_cfg.h> /* See Note #1. */
#include <Dev/Ether/Template/net_dev_ether_template_dma.h> /* See Note #2. */
#include <Dev/Ether/PHY/Generic/net_phy.h> /* See Note #3. */
#include <BSP/Template/net_bsp_ether.h> /* See Note #4. */
CPU_BOOLEAN AppInit_TCPIP (void)
{
NET_IF_NBR if_nbr;
NET_ERR err_net;
#ifdef NET_IPv4_MODULE_EN
NET_IPv4_ADDR addr_ipv4;
NET_IPv4_ADDR msk_ipv4;
NET_IPv4_ADDR gateway_ipv4;
#endif
#ifdef NET_IPv6_MODULE_EN
CPU_BOOLEAN cfg_result;
#if (NET_IPv6_CFG_ADDR_AUTO_CFG_EN == DEF_DISABLED)
NET_FLAGS ipv6_flags;
NET_IPv6_ADDR ipv6_addr;
#endif
#endif
/* ------- PREREQUISITES MODULE INIT -------- */
CPU_Init(); /* See Note #5. */
Mem_Init();
/* ------ INIT NETWORK TASKS & OBJECTS ------ */
err_net = Net_Init(&NetRxTaskCfg, /* See Note #6. */
&NetTxDeallocTaskCfg,
&NetTmrTaskCfg);
if (err_net != NET_ERR_NONE) {
return (DEF_FAIL);
}
/* --------- ADD ETHERNET INTERFACE --------- */
/* See Note #7. */
if_nbr = NetIF_Add(&NetIF_API_Ether, /* See Note #7b. */
&NetDev_API_TemplateEtherDMA, /* Device driver API, See Note #7c. */
&NetDev_BSP_BoardDev_Nbr, /* BSP API, See Note #7d. */
&NetDev_Cfg_Ether_1, /* Device configuration, See Note #7e. */
&NetPhy_API_Generic, /* PHY driver API, See Note #7f. */
&NetPhy_Cfg_Ether_1, /* PHY configuration, See Note #7g. */
&err_net);
if (err_net != NET_IF_ERR_NONE) {
return (DEF_FAIL);
}
/* -------- START ETHERNET INTERFACE -------- */
NetIF_Start(if_nbr, &err_net); /* See Note #8. */
if (err_net != NET_IF_ERR_NONE) {
return (DEF_FAIL);
}
#ifdef NET_IPv4_MODULE_EN
/* ------- CONFIGURE IPV4 STATIC ADDR ------- */
/* See Note #9 */
NetASCII_Str_to_IP("10.10.10.64", /* Convert IPv4 string addr to 32 bits addr. */
&addr_ipv4,
NET_IPv4_ADDR_SIZE,
&err_net);
NetASCII_Str_to_IP("255.255.255.0", /* Convert IPv4 mask string to 32 bits addr. */
&msk_ipv4,
NET_IPv4_ADDR_SIZE,
&err_net);
NetASCII_Str_to_IP("10.10.10.1", /* Convert Gateway string to 32 bits addr. */
&gateway_ipv4,
NET_IPv4_ADDR_SIZE,
&err_net);
NetIPv4_CfgAddrAdd(if_nbr, /* Add a statically-configured IPv4 host ... */
addr_ipv4, /* ... addr, subnet mask, & default ... */
msk_ipv4, /* ... gateway to the interface. See Note #10.*/
gateway_ipv4,
&err_net);
if (err_net != NET_IPv4_ERR_NONE) {
return (DEF_FAIL);
}
#endif
#ifdef NET_IPv6_MODULE_EN
#if (NET_IPv6_CFG_ADDR_AUTO_CFG_EN == DEF_ENABLED)
/* ---- START IPV6 STATELESS AUTO-CONFI ----- */
/* See Note #12. */
NetIPv6_AddrAutoCfgHookSet(if_nbr, /* Set hook to received Auto-Cfg result. */
&App_AutoCfgResult, /* TODO update pointer to hook defined in App.*/
&err_net);
/* See Note #13. */
cfg_result = NetIPv6_AddrAutoCfgEn(if_nbr, /* Enable and Start Auto-Config process. */
DEF_YES,
&err_net);
if (cfg_result == DEF_FAIL) {
return (DEF_FAIL);
} |