This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM2634: how to ping the 2 ip address in am2634

Part Number: AM2634
Other Parts Discussed in Thread: SYSCONFIG

Tool/software:

hi teams,

my requirement need to ping 2 ip with the am2634 mcu

the below config which i had setted up

i configured the 2 NetIf in sysconfig.

appmain.c

#include <stdio.h>
#include <stdarg.h>
#include <string.h>
/* lwIP core includes */
#include "lwip/opt.h"
#include "lwip/sys.h"
#include "lwip/init.h"
#include "lwip/dhcp.h"
#include "lwip/timeouts.h"
#include <apps/tcpecho_raw/tcpecho_raw.h>

#include <kernel/dpl/ClockP.h>
#include <kernel/dpl/EventP.h>
#include <networking/enet/utils/include/enet_apputils.h>
#include <networking/enet/utils/include/enet_board.h>
#include "ti_board_config.h"
#include "ti_board_open_close.h"
#include "ti_drivers_open_close.h"
#include "ti_enet_config.h"
#include "ti_enet_open_close.h"
#include "app_cpswconfighandler.h"
#include "ti_enet_lwipif.h"


/* ========================================================================== */
/*                           Macros & Typedefs                                */
/* ========================================================================== */

static const uint8_t BROADCAST_MAC_ADDRESS[ENET_MAC_ADDR_LEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };

/* ========================================================================== */
/*                         Structure Declarations                             */
/* ========================================================================== */

/* ========================================================================== */
/*                          Function Declarations                             */
/* ========================================================================== */
static void App_printCpuLoad();//y

static void App_tcpipInitCompleteCb(void *pArg);//y

static void App_setupNetif();//y

static void App_allocateIPAddress();//y

static void App_setupNetworkStack();//y

static void App_shutdownNetworkStack();//y

static void App_netifStatusChangeCb(struct netif *state_netif);//y

static void App_netifLinkChangeCb(struct netif *state_netif);//y

static inline int32_t App_isNetworkUp(struct netif* netif_);//y



static void App_handleEvent(const uint32_t eventMask);

static uint32_t App_receiveEvents(EventP_Object* pEvent);


//******************  My Function      *************************************

//void httpd_init(void);

//void udpServer_init(void);

void udpClient_connect(void);

//void tcp_client_init(void);

//void tcp_server_init();
/* ========================================================================== */
/*                            Global Variables                                */
/* ========================================================================== */

/* dhcp struct for the ethernet netif */
//static struct dhcp g_netifDhcp[ENET_SYSCFG_NETIF_COUNT];
struct netif *g_pNetif[ENET_SYSCFG_NETIF_COUNT];//y

EventP_Object hEvent;

/* Handle to the Application interface for the LwIPIf Layer
*/
LwipifEnetApp_Handle hlwipIfApp = NULL;
/* ========================================================================== */
/*                          Function Definitions                              */
/* ========================================================================== */
#define IP_ADDR_POOL_COUNT  (2U)

const ip_addr_t gStaticIP[IP_ADDR_POOL_COUNT]   =  { IPADDR4_INIT_BYTES(192, 168, 1, 200) /* For NetifIdx = 0 */,  IPADDR4_INIT_BYTES(  192, 168, 1, 201) /* For NetifIdx = 1 */};

const ip_addr_t gStaticIPGateway[IP_ADDR_POOL_COUNT] =  { IPADDR4_INIT_BYTES(192, 168, 2, 1) /* For NetifIdx = 0 */, IPADDR4_INIT_BYTES(192, 168, 2, 1) /* For NetifIdx = 1 */};

const ip_addr_t gStaticIPNetmask[IP_ADDR_POOL_COUNT] =  { IPADDR4_INIT_BYTES(255,255,255,0)  /* For NetifIdx = 0 */, IPADDR4_INIT_BYTES(255,255,252,0) /* For NetifIdx = 1 */};


int appMain(void *args)
{
    Enet_Type enetType;
    uint32_t instId;

    int32_t status;
    status = EventP_construct(&hEvent);

    Drivers_open();
    Board_driversOpen();

    printf("==========================\r\n");
    printf("  CPSW LWIP HTTP WEB SERVER \r\n");
    printf("==========================\r\n");

    EnetApp_getEnetInstInfo(CONFIG_ENET_CPSW0, &enetType, &instId);

    EnetAppUtils_enableClocks(enetType, instId);

    EnetApp_driverInit();

    status = EnetApp_driverOpen(enetType, instId);

    EnetApp_initPhyStateHandlerTask(&hEvent);

    if (ENET_SOK != status)
    {
        EnetAppUtils_print("Failed to open ENET: %d\r\n", status);
        EnetAppUtils_assert(false);
        return -1;
    }


    EnetApp_addMCastEntry(enetType,
                              instId,
                              EnetSoc_getCoreId(),
                              BROADCAST_MAC_ADDRESS,
                              CPSW_ALE_ALL_PORTS_MASK);
        //call createPhyHandler here

        App_setupNetworkStack();

        if (ENET_SOK != status)
        {
            EnetAppUtils_print("Failed to construct Event: %d\r\n", status);
            EnetAppUtils_assert(false);
            return -1;
        }

        while (false == App_isNetworkUp(netif_default))
        {
            printf("Waiting for network UP ...\r\n");
            sys_check_timeouts();

            const uint32_t recvdEventsMask = App_receiveEvents(&hEvent);

            if (recvdEventsMask != AppEventId_NONE)
            {
                App_handleEvent(recvdEventsMask);
            }
        }

        printf("Network is UP ...\r\n");
        ClockP_sleep(1);

//        AppTcp_startClient();

//        AppTcp_startServer();

    //    tcpecho_raw_init();
    //    httpd_init();
        udpServer_init();
//        tcp_client_init();
//        tcp_client_init_multiple(5);


//    udpClient_connect();

//        tcp_server_init();


        while (1)
        {
            sys_check_timeouts();
//            udpClient_connect();
//            tcp_server_init();
//            tcp_client_init();

            const uint32_t recvdEventsMask = App_receiveEvents(&hEvent);

            if (recvdEventsMask != AppEventId_NONE)
            {
                App_handleEvent(recvdEventsMask);
                ClockP_sleep(1);
            }
        }

        App_shutdownNetworkStack();
        EnetApp_driverDeInit();
        EventP_destruct(&hEvent);
        return 0;
    }


    static void App_handleEvent(const uint32_t eventMask)
    {

        // lwip raw API examples learn about

        if (AppEventId_NETIFMNGR_RXPKT & eventMask)
        {
            LWIPIF_LWIP_rxPktHandler(g_pNetif[ENET_SYSCFG_DEFAULT_NETIF_IDX]);
        }

        if (AppEventId_NETIFMNGR_POLL & eventMask)
        {
            LWIPIF_LWIP_periodic_polling(g_pNetif[ENET_SYSCFG_NETIF_COUNT - 1]);
        }

        if ( AppEventId_NETIFMNGR_TXPKT & eventMask)
        {
            LWIPIF_LWIP_txPktHandler(g_pNetif[ENET_SYSCFG_DEFAULT_NETIF_IDX]);
        }

        if (AppEventId_CPSW_PERIODIC_POLL & eventMask)
        {
            EnetApp_phyStateHandler();
        }
    }

    static uint32_t App_receiveEvents(EventP_Object* pEvent)
    {
        int32_t status = SystemP_SUCCESS;
        uint32_t recvdEventsMask = AppEventId_NONE;

        status = EventP_waitBits(pEvent,
                            AppEventId_ANY_EVENT, // bitsToWaitFor
                            1,
                            0,
                            SystemP_NO_WAIT,
    &recvdEventsMask);

         if ((status != SystemP_SUCCESS) && (status != SystemP_TIMEOUT))
         {
             EnetAppUtils_print("Failed to receive Event handle\r\n");
             EnetAppUtils_assert(false);
         }

         return recvdEventsMask;
    }

    static void App_setupNetworkStack()
    {
        lwip_init();

        srand(ClockP_getTicks()/1000);

        App_setupNetif();

        App_allocateIPAddress();

        return;
    }

    static void App_shutdownNetworkStack()
    {
        return;
    }

    static void App_setupNetif()
    {
        ip4_addr_t ipaddr, netmask, gw;

        ip4_addr_set_zero(&gw);
        ip4_addr_set_zero(&ipaddr);
        ip4_addr_set_zero(&netmask);

        printf("Starting lwIP, local interface IP is dhcp-enabled\r\n");
        hlwipIfApp = LwipifEnetApp_getHandle();
        for (uint32_t i = 0U; i < ENET_SYSCFG_NETIF_COUNT; i++)
        {
            /* Open the netif and get it populated*/
            g_pNetif[i] = LwipifEnetApp_netifOpen(hlwipIfApp, NETIF_INST_ID0 + i, &ipaddr, &netmask, &gw);
            netif_set_status_callback(g_pNetif[i], App_netifStatusChangeCb);
            netif_set_link_callback(g_pNetif[i], App_netifLinkChangeCb);
            netif_set_up(g_pNetif[NETIF_INST_ID0 + i]);
        }
        LwipifEnetApp_startSchedule(hlwipIfApp, g_pNetif[ENET_SYSCFG_DEFAULT_NETIF_IDX], &hEvent);
    }


    static void App_allocateIPAddress()
    {
//        sys_lock_tcpip_core();

        for (uint32_t  netifIdx = 0U; netifIdx < ENET_SYSCFG_NETIF_COUNT; netifIdx++)
        {
            netif_set_addr(g_pNetif[NETIF_INST_ID0 + netifIdx],
                                    &gStaticIP[NETIF_INST_ID0 + netifIdx],
                                    &gStaticIPNetmask[NETIF_INST_ID0 + netifIdx],
                                    &gStaticIPGateway[NETIF_INST_ID0 + netifIdx]);
        }
//        sys_unlock_tcpip_core();
        return;
    }



    static void App_netifStatusChangeCb(struct netif *pNetif)
    {
        if (netif_is_up(pNetif))
        {
            printf("Enet IF UP Event. Local interface IP:%s\r\n",
                        ip4addr_ntoa(netif_ip4_addr(pNetif)));
        }
        else
        {
            printf("Enet IF DOWN Event\r\n");
        }
        return;
    }

    static void App_netifLinkChangeCb(struct netif *pNetif)
    {
        if (netif_is_link_up(pNetif))
        {
            printf("Network Link UP Event\r\n");
        }
        else
        {
            printf("Network Link DOWN Event\r\n");
        }
        return;
    }

    static int32_t App_isNetworkUp(struct netif* netif_)
    {
        return (netif_is_up(netif_) && netif_is_link_up(netif_) && !ip4_addr_isany_val(*netif_ip4_addr(netif_)));
    }

    static void App_printCpuLoad()
    {
        static uint32_t startTime_ms = 0;
        const  uint32_t currTime_ms  = ClockP_getTimeUsec()/1000;
        const  uint32_t printInterval_ms = 5000;

        if (startTime_ms == 0)
        {
            startTime_ms = currTime_ms;
        }
        else if ( (currTime_ms - startTime_ms) > printInterval_ms )
        {
            const uint32_t cpuLoad = TaskP_loadGetTotalCpuLoad();

            printf(" %6d.%3ds : CPU load = %3d.%02d %%\r\n",
                        currTime_ms/1000, currTime_ms%1000,
                        cpuLoad/100, cpuLoad%100 );

            startTime_ms = currTime_ms;
            TaskP_loadResetAll();
        }
        return;
    }

so i am trying to ping the ip address but it was not happens

like this i am facing the issue and below i will attach my log below

kindly say what i need to do i need to ping the 2 ips in am2634 mcu.