Nios® V Processor Software Developer Handbook

ID 743810
Date 10/31/2022
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

10.7. Using the MicroC/TCP-IP Protocol Stack

Intel provides an example on how to use µC/TCP-IP protocol stack in Intel FPGA Development Kit. The primary application file is uc_tcp_ip_init.c which consist of the implementation source code for your reference. You can modify the code to meet your actual product requirements.

uc_tcp_ip_init.c performs below operations:

  1. Calls network_init() function to:
    1. Initialize µC/TCP-IP tasks
    2. Add and start the TSE mSGDMA driver into system
    3. Configure IP address through static IP or using a DHCP server
  2. Uses network_stop() function to stop a particular interface such as TSE instance. This function is at the end of uc_tcp_ip_init.c

network_init() network stack initialization implementation code

CPU_BOOLEAN network_init(struct network_conf *conf, NET_IF_NBR *p_if_nbr) {
    NET_ERR    err_net;

    // µC/TCP-IP generic stack init.
    err_net = Net_Init(
            &NetRxTaskCfg,
            &NetTxDeallocTaskCfg,
            &NetTmrTaskCfg);
    if (err_net != NET_ERR_NONE) {
        logf("Failed to Net_Init(): (%d).\n", err_net);
        return DEF_FALSE;
    }

    // Update TSE sys info struct and MAC address from configuration.
    NetDev_Cfg_Ether_TSE.BaseAddr = (CPU_ADDR) conf->tse_sys_info;

    Mem_Copy(NetDev_Cfg_Ether_TSE.HW_AddrStr, conf->mac_addr,
        sizeof(CPU_CHAR) * NET_IF_802x_ADDR_SIZE_STR);

    // Add TSE.
    *p_if_nbr = NetIF_Add(
            (void *)&NetIF_API_Ether, // const for all eth interfaces
            (void *)&NetDev_API_TSE_mSGDMA_Intel_HAL,
            NULL, // (void *)&Net_DrvBSP_Nios_II,
            (void *)&NetDev_Cfg_Ether_TSE,
            NULL, // (void *)&NetPhy_API_Generic,
            NULL, // (void *)&NetPhy_Cfg_Ether_TSE,
                    &err_net);
    if (err_net != NET_IF_ERR_NONE) {
        logf("Failed to NetIF_Add(): (%d).\n", err_net);
        return DEF_FALSE;
    }

    // Start TSE.
    NetIF_Start(*p_if_nbr, &err_net);
    if (err_net != NET_IF_ERR_NONE){
        logf("Failed to NetIF_Start(): (%d).\n", err_net);
        return DEF_FALSE;
    }

    CPU_BOOLEAN ret;
    if (conf->use_dhcp) {
        ret = conf_dhcp(*p_if_nbr);
    } else {
        ret = conf_static(*p_if_nbr, conf);
    }

    return ret;
}