Tool/software:
Hi team,
i am working on enet_cpsw_tcpclient_am263x-cc this project and in this project i am trying to configure 2 Ip's so here i could able to ping 192.168.2.200 but i could not able to ping 192.168.2.201
i am using the app.main which i attached below
/*
* app_main1.c
*
* Created on: 28-Aug-2024
* Author: AAKASH V
*/
/*
* Copyright (c) 2001,2002 Florian Schulze.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the authors nor the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* app_main.c - This file is part of lwIP test
*
*/
/* ========================================================================== */
/* Include Files */
/* ========================================================================== */
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include "FreeRTOS.h"
#include "task.h"
/* lwIP core includes */
#include "lwip/opt.h"
#include "lwip/sys.h"
#include "lwip/tcpip.h"
#include "lwip/dhcp.h"
#include <kernel/dpl/TaskP.h>
#include <kernel/dpl/ClockP.h>
#include <kernel/dpl/ClockP.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 "app_tcpclient.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();
static void App_tcpipInitCompleteCb(void *pArg);
static void App_setupNetif();
static void App_allocateIPAddress();
static void App_setupNetworkStack();
static void App_shutdownNetworkStack();
static void App_netifStatusChangeCb(struct netif *state_netif);
static void App_netifLinkChangeCb(struct netif *state_netif);
static inline int32_t App_isNetworkUp(struct netif* netif_);
/* ========================================================================== */
/* 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];
/* 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, 2, 200) /* For NetifIdx = 0 */, IPADDR4_INIT_BYTES( 192, 168, 2, 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;
Drivers_open();
Board_driversOpen();
DebugP_log("==========================\r\n");
DebugP_log(" CPSW LWIP TCP CLIENT \r\n");
DebugP_log("==========================\r\n");
EnetApp_getEnetInstInfo(CONFIG_ENET_CPSW0, &enetType, &instId);
EnetAppUtils_enableClocks(enetType, instId);
EnetApp_driverInit();
const int32_t status = EnetApp_driverOpen(enetType, instId);
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);
App_setupNetworkStack();
while (false == App_isNetworkUp(netif_default))
{
DebugP_log("Waiting for network UP ...\r\n");
ClockP_sleep(2);
}
DebugP_log("Network is UP ...\r\n");
ClockP_sleep(1);
AppTcp_startClient();
while (1)
{
ClockP_usleep(1000);
App_printCpuLoad();
}
App_shutdownNetworkStack();
EnetApp_driverDeInit();
return 0;
}
static void App_setupNetworkStack()
{
sys_sem_t pInitSem;
const err_t err = sys_sem_new(&pInitSem, 0);
EnetAppUtils_assert(err == ERR_OK);
tcpip_init(App_tcpipInitCompleteCb, &pInitSem);
/* wait for TCP/IP initialization to complete */
sys_sem_wait(&pInitSem);
sys_sem_free(&pInitSem);
return;
}
static void App_shutdownNetworkStack()
{
LwipifEnetApp_netifClose(hlwipIfApp, NETIF_INST_ID0);
return;
}
static void App_tcpipInitCompleteCb(void *pArg)
{
sys_sem_t *pSem = (sys_sem_t*)pArg;
EnetAppUtils_assert(pArg != NULL);
/* init randomizer again (seed per thread) */
srand((unsigned int)sys_now()/1000);
App_setupNetif();
App_allocateIPAddress();
sys_sem_signal(pSem);
}
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);
DebugP_log("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]);
}
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))
{
DebugP_log("Enet IF UP Event. Local interface IP:%s\r\n",
ip4addr_ntoa(netif_ip4_addr(pNetif)));
}
else
{
DebugP_log("Enet IF DOWN Event\r\n");
}
return;
}
static void App_netifLinkChangeCb(struct netif *pNetif)
{
if (netif_is_link_up(pNetif))
{
DebugP_log("Network Link UP Event\r\n");
}
else
{
DebugP_log("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();
DebugP_log(" %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;
}
i am using this app_tcpclient.c file to netconn_connect other things and i attached below
/* ========================================================================== */
/* Include Files */
/* ========================================================================== */
#include <string.h>
#include <stdio.h>
#include <kernel/dpl/TaskP.h>
#include <kernel/dpl/ClockP.h>
#include "lwip/opt.h"
#include "lwip/sys.h"
#include "lwip/api.h"
#include "enet_apputils.h"
/* ========================================================================== */
/* Macros & Typedefs */
/* ========================================================================== */
#define HOST_SERVER_IP6 ("FE80::12:34FF:FE56:78AB")
#define HOST_SERVER_PORT (8888)
#define APP_MAX_RX_DATA_LEN (1024U)
#define APP_NUM_ITERATIONS (2U)
#define APP_SEND_DATA_NUM_ITERATIONS (5U)
#define MAX_IPV4_STRING_LEN (20U)
char snd_buf[APP_MAX_RX_DATA_LEN];
/* ========================================================================== */
/* Structure Declarations */
/* ========================================================================== */
struct App_hostInfo_t
{
ip_addr_t ipAddr1;
ip_addr_t ipAddr2;
uint16_t port;
};
/* ========================================================================== */
/* Function Declarations */
/* ========================================================================== */
static void AppTcp_fillHostSocketInfo(struct App_hostInfo_t* pHostInfo);
/* ========================================================================== */
/* Global Variables */
/* ========================================================================== */
static struct App_hostInfo_t gHostInfo;
static char gHostServerIp4_1[MAX_IPV4_STRING_LEN] = "";
static char gHostServerIp4_2[MAX_IPV4_STRING_LEN] = "";
/* ========================================================================== */
/* Function Definitions */
/* ========================================================================== */
static void AppTcp_fillHostSocketInfo(struct App_hostInfo_t* pHostInfo)
{
EnetAppUtils_print("[0] IP eneterd is: %s \r\n", gHostServerIp4_1);
EnetAppUtils_print("[1] IP eneterd is: %s \r\n", gHostServerIp4_2);
int32_t addr_ok;
pHostInfo->port = HOST_SERVER_PORT;
memset(&pHostInfo->ipAddr1, 0, sizeof(pHostInfo->ipAddr1));
memset(&pHostInfo->ipAddr2, 0, sizeof(pHostInfo->ipAddr2));
ip_addr_t* pAddr1 = &pHostInfo->ipAddr1;
ip_addr_t* pAddr2 = &pHostInfo->ipAddr2;
IP_SET_TYPE_VAL(*pAddr, IPADDR_TYPE_V4);
addr_ok = ip4addr_aton(gHostServerIp4_1, ip_2_ip4(pAddr1));
addr_ok = ip4addr_aton(gHostServerIp4_2, ip_2_ip4(pAddr2));
EnetAppUtils_assert(addr_ok);
return;
}
static void AppTcp_simpleclient_1(void *pArg)
{
struct netconn *pConn1 = NULL;
err_t err1 = ERR_OK, connectError1 = ERR_OK;
struct App_hostInfo_t* pHostInfo = (struct App_hostInfo_t*) pArg;
uint32_t buf_len = 0;
const enum netconn_type connType = NETCONN_TCP;
/* Create a new connection identifier. */
for (uint32_t pktIdx = 0; pktIdx < APP_NUM_ITERATIONS; pktIdx++)
{
struct netbuf *rxBbuf = NULL;
pConn1 = netconn_new(connType);
if (pConn1 != NULL)
{
/* Connect to the TCP Server */
EnetAppUtils_print("[1]<<<< ITERATION %d >>>>\r\n", (pktIdx + 1));
EnetAppUtils_print("[1] Connecting to: %s:%d \r\n", gHostServerIp4_2, HOST_SERVER_PORT);
connectError1 = netconn_bind_if(pConn1, 1);
connectError1 = netconn_connect(pConn1, &pHostInfo->ipAddr2, 8888);
if (connectError1 != ERR_OK)
{
netconn_close(pConn1);
DebugP_log("[1]Connection with the server isn't established\r\n");
continue;
}
DebugP_log("[1]Connection with the server is established\r\n");
// send the data to the server
for ( uint32_t i = 0; i < APP_SEND_DATA_NUM_ITERATIONS; i++)
{
memset(&snd_buf, 0, sizeof(snd_buf));
buf_len = snprintf(snd_buf, sizeof(snd_buf), "[1]Hello over TCP %d", i+1);
err1 = netconn_write(pConn1, snd_buf, buf_len, NETCONN_COPY);
if (err1 == ERR_OK)
{
printf("[1]\"%s\" was sent to the Server\r\n", snd_buf);
}
else
{
DebugP_log("couldn't send packet to server\r\n");
continue;
}
/* wait until the data is sent by the server */
if (netconn_recv(pConn1, &rxBbuf) == ERR_OK)
{
DebugP_log("[1]Successfully received the packet %d\r\n", i+1);
netbuf_delete(rxBbuf);
}
else
{
DebugP_log("No response from server\r\n");
}
}
netconn_close(pConn1);
netconn_delete(pConn1);
DebugP_log("[1]Connection closed\r\n");
ClockP_sleep(1);
}
}
}
static void AppTcp_simpleclient(void *pArg)
{
struct netconn *pConn = NULL;
err_t err = ERR_OK, connectError = ERR_OK;
struct App_hostInfo_t* pHostInfo = (struct App_hostInfo_t*) pArg;
uint32_t buf_len = 0;
const enum netconn_type connType = NETCONN_TCP;
/* Create a new connection identifier. */
for (uint32_t pktIdx = 0; pktIdx < APP_NUM_ITERATIONS; pktIdx++)
{
struct netbuf *rxBbuf = NULL;
pConn = netconn_new(connType);
if (pConn != NULL)
{
/* Connect to the TCP Server */
EnetAppUtils_print("[0]<<<< ITERATION %d >>>>\r\n", (pktIdx + 1));
EnetAppUtils_print("[0] Connecting to: %s:%d \r\n", gHostServerIp4_1, HOST_SERVER_PORT);
connectError = netconn_bind_if(pConn, 0);
connectError = netconn_connect(pConn, &pHostInfo->ipAddr1, 8888);
if (connectError != ERR_OK)
{
netconn_close(pConn);
DebugP_log("[0]Connection with the server isn't established\r\n");
continue;
}
DebugP_log("[0]Connection with the server is established\r\n");
// send the data to the server
for ( uint32_t i = 0; i < APP_SEND_DATA_NUM_ITERATIONS; i++)
{
memset(&snd_buf, 0, sizeof(snd_buf));
buf_len = snprintf(snd_buf, sizeof(snd_buf), "[0]Hello over TCP %d", i+1);
err = netconn_write(pConn, snd_buf, buf_len, NETCONN_COPY);
if (err == ERR_OK)
{
printf("[0]\"%s\" was sent to the Server\r\n", snd_buf);
}
else
{
DebugP_log("couldn't send packet to server\r\n");
continue;
}
/* wait until the data is sent by the server */
if (netconn_recv(pConn, &rxBbuf) == ERR_OK)
{
DebugP_log("[0]Successfully received the packet %d\r\n", i+1);
netbuf_delete(rxBbuf);
}
else
{
DebugP_log("No response from server\r\n");
}
}
netconn_close(pConn);
netconn_delete(pConn);
DebugP_log("[0]Connection closed\r\n");
ClockP_sleep(1);
}
}
}
void AppTcp_showMenu(void)
{
ip_addr_t ipAddr1;
ip_addr_t ipAddr2;
int32_t addr_ok = 0;
EnetAppUtils_print(" TCP Client Menu: \r\n");
do
{
EnetAppUtils_print(" Enter TCP server-1 IPv4 address:(example: 192.168.101.100)\r\n");
DebugP_scanf("%s", gHostServerIp4_1);
EnetAppUtils_print(" Enter TCP server-2 IPv4 address:(example: 192.168.101.100)\r\n");
DebugP_scanf("%s", gHostServerIp4_2);
addr_ok = ip4addr_aton(gHostServerIp4_1, ip_2_ip4(&ipAddr1));
addr_ok = ip4addr_aton(gHostServerIp4_2, ip_2_ip4(&ipAddr2));
TaskP_yield();
} while (addr_ok != 1);
}
void AppTcp_startClient(void)
{
AppTcp_showMenu();
AppTcp_fillHostSocketInfo(&gHostInfo);
sys_thread_new("tcpinit_thread", AppTcp_simpleclient, &gHostInfo, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
sys_thread_new("tcpinit_thread1", AppTcp_simpleclient_1, &gHostInfo, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
/* USER CODE END 5 */
}
Here if you see in this picture i could't able to ping the the ip
i saw some comments from you and i am working on the same
so can you say wat is the problem in mine. or can say any thing require i need to change??
your replay is very much helpful.