//Version 2.0

/*
 * Copyright (c) 2016, Freescale Semiconductor, Inc.
 * Copyright 2016-2020 NXP
 * All rights reserved.
 *
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

/*******************************************************************************
 * Includes
 ******************************************************************************/

#include "lwip/opt.h"

#if LWIP_IPV4 && LWIP_RAW

#include "ping.h"
#include "lwip/timeouts.h"
#include "lwip/init.h"
#include "netif/ethernet.h"
#include "enet_ethernetif.h"

#include "pin_mux.h"
#include "clock_config.h"
#include "board.h"
#include "fsl_phy.h"
#include "fsl_debug_console.h"
#include "fsl_lpi2c.h"
#include "battery_monitor.h"

#include "fsl_gpio.h"
#include "fsl_iomuxc.h"
#include "fsl_phyksz8081.h"
#include "fsl_enet_mdio.h"

#include "HHT_Parameters.h"
#include <stdio.h>
#include "string.h"
#include "stdlib.h"
#include "time.h"


#include "fsl_flexspi.h"
#include "app.h"
#include "fsl_debug_console.h"
#include "fsl_cache.h"
/* Display specific Includes
 *
 */

#include "emwin_support.h"
#ifndef APPWIZARD
#include "../emwin/emWin_header_old/DIALOG.h"
#include "Resource.h"
#else
#include "../emwin/emWin_header_old/GUI.h"
#endif
#include "fsl_gpt.h"
//#include "../AppWizard/Source/CustomCode/Application.h"
//#include "../AppWizard/Source/Generated/Resource.h"
//#include "../AppWizard/Source/Generated/ID_SCREEN_BUC_HEALTH.h"

extern int BUC_Ping_Status;


/*******************************************************************************
 * Definitions
 ******************************************************************************/
struct netif netif;
long long int UDPPktTimerCount=0;
int UDPFirstPktCounter=1;
ip4_addr_t netif_ipaddr, netif_netmask, netif_gw;

	time_t serverTime;// = time(NULL);
	struct tm tmp;// = *localtime(&serverTime);
	char timeStr[200];
	char monthStr[20];
	size_t timerstrLen;

char * pui8Data;
static struct udp_pcb *udpecho_raw_pcb;
typedef struct
{
    uint8_t byte1[16];
}stTxbuf;
stTxbuf g_txbuf;

typedef struct
{
	uint8_t byte1[13];
}stRxbuf;
stRxbuf g_Rxbuf;

int count=0;
ip_addr_t dstaddr;
void *g_udpTxSocket;
void *g_udpRxSocket;
struct pbuf * tx_pb;
struct pbuf * tx_update_pb;
struct pbuf * rx_pb;
struct pbuf * rx_update_pb;

/////* IP address configuration. */
//#define configIP_ADDR0 10
//#define configIP_ADDR1 0
//#define configIP_ADDR2 0
//#define configIP_ADDR3 10
//
///* Netmask configuration. */
//#define configNET_MASK0 255
//#define configNET_MASK1 255
//#define configNET_MASK2 255
//#define configNET_MASK3 0
//
///* Gateway address configuration. */
//#define configGW_ADDR0 10
//#define configGW_ADDR1 0
//#define configGW_ADDR2 0
//#define configGW_ADDR3 100

/* MAC address configuration. */
#define configMAC_ADDR                     \
    {                                      \
        0x02, 0x12, 0x13, 0x10, 0x15, 0x11 \
    }


/* Address of PHY interface. */
#define EXAMPLE_PHY_ADDRESS BOARD_ENET0_PHY_ADDRESS

/* MDIO operations. */
#define EXAMPLE_MDIO_OPS enet_ops

/* PHY operations. */
#define EXAMPLE_PHY_OPS phyksz8081_ops

/* ENET clock frequency. */
#define EXAMPLE_CLOCK_FREQ CLOCK_GetFreq(kCLOCK_IpgClk)

#ifndef EXAMPLE_NETIF_INIT_FN
/*! @brief Network interface initialization function. */
#define EXAMPLE_NETIF_INIT_FN ethernetif0_init
#endif /* EXAMPLE_NETIF_INIT_FN */

#define APP_PXP                PXP
#define EXAMPLE_GPT            GPT2
#define EXAMPLE_GPT_TICK_TO_MS 25


/*******************************************************************************
 * Definitions
 ******************************************************************************/
/*******************************************************************************
 * Prototypes
 ******************************************************************************/

/*******************************************************************************
 * Variables
 ******************************************************************************/
static uint8_t s_nor_program_buffer[256];
static uint8_t s_nor_read_buffer[256];

extern status_t flexspi_nor_flash_erase_sector(FLEXSPI_Type *base, uint32_t address);
extern status_t flexspi_nor_flash_page_program(FLEXSPI_Type *base, uint32_t dstAddr, const uint32_t *src);
extern status_t flexspi_nor_get_vendor_id(FLEXSPI_Type *base, uint8_t *vendorId);
extern status_t flexspi_nor_enable_quad_mode(FLEXSPI_Type *base);
extern status_t flexspi_nor_erase_chip(FLEXSPI_Type *base);
extern void flexspi_nor_flash_init(FLEXSPI_Type *base);
/*******************************************************************************
 * Code
 ******************************************************************************/
flexspi_device_config_t deviceconfig = {
    .flexspiRootClk       = 133000000,
    .flashSize            = FLASH_SIZE,
    .CSIntervalUnit       = kFLEXSPI_CsIntervalUnit1SckCycle,
    .CSInterval           = 2,
    .CSHoldTime           = 3,
    .CSSetupTime          = 3,
    .dataValidTime        = 0,
    .columnspace          = 0,
    .enableWordAddress    = 0,
    .AWRSeqIndex          = 0,
    .AWRSeqNumber         = 0,
    .ARDSeqIndex          = NOR_CMD_LUT_SEQ_IDX_READ_FAST_QUAD,
    .ARDSeqNumber         = 1,
    .AHBWriteWaitUnit     = kFLEXSPI_AhbWriteWaitUnit2AhbCycle,
    .AHBWriteWaitInterval = 0,
};

const uint32_t customLUT[CUSTOM_LUT_LENGTH] = {
    /* Normal read mode -SDR */
    [4 * NOR_CMD_LUT_SEQ_IDX_READ_NORMAL] =
        FLEXSPI_LUT_SEQ(kFLEXSPI_Command_SDR, kFLEXSPI_1PAD, 0x03, kFLEXSPI_Command_RADDR_SDR, kFLEXSPI_1PAD, 0x18),
    [4 * NOR_CMD_LUT_SEQ_IDX_READ_NORMAL + 1] =
        FLEXSPI_LUT_SEQ(kFLEXSPI_Command_READ_SDR, kFLEXSPI_1PAD, 0x04, kFLEXSPI_Command_STOP, kFLEXSPI_1PAD, 0),

    /* Fast read mode - SDR */
    [4 * NOR_CMD_LUT_SEQ_IDX_READ_FAST] =
        FLEXSPI_LUT_SEQ(kFLEXSPI_Command_SDR, kFLEXSPI_1PAD, 0x0B, kFLEXSPI_Command_RADDR_SDR, kFLEXSPI_1PAD, 0x18),
    [4 * NOR_CMD_LUT_SEQ_IDX_READ_FAST + 1] = FLEXSPI_LUT_SEQ(
        kFLEXSPI_Command_DUMMY_SDR, kFLEXSPI_1PAD, 0x08, kFLEXSPI_Command_READ_SDR, kFLEXSPI_1PAD, 0x04),

    /* Fast read quad mode - SDR */
    [4 * NOR_CMD_LUT_SEQ_IDX_READ_FAST_QUAD] =
        FLEXSPI_LUT_SEQ(kFLEXSPI_Command_SDR, kFLEXSPI_1PAD, 0xEB, kFLEXSPI_Command_RADDR_SDR, kFLEXSPI_4PAD, 0x18),
    [4 * NOR_CMD_LUT_SEQ_IDX_READ_FAST_QUAD + 1] = FLEXSPI_LUT_SEQ(
        kFLEXSPI_Command_DUMMY_SDR, kFLEXSPI_4PAD, 0x06, kFLEXSPI_Command_READ_SDR, kFLEXSPI_4PAD, 0x04),

    /* Read extend parameters */
    [4 * NOR_CMD_LUT_SEQ_IDX_READSTATUS] =
        FLEXSPI_LUT_SEQ(kFLEXSPI_Command_SDR, kFLEXSPI_1PAD, 0x81, kFLEXSPI_Command_READ_SDR, kFLEXSPI_1PAD, 0x04),

    /* Write Enable */
    [4 * NOR_CMD_LUT_SEQ_IDX_WRITEENABLE] =
        FLEXSPI_LUT_SEQ(kFLEXSPI_Command_SDR, kFLEXSPI_1PAD, 0x06, kFLEXSPI_Command_STOP, kFLEXSPI_1PAD, 0),

    /* Erase Sector  */
    [4 * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR] =
        FLEXSPI_LUT_SEQ(kFLEXSPI_Command_SDR, kFLEXSPI_1PAD, 0xD7, kFLEXSPI_Command_RADDR_SDR, kFLEXSPI_1PAD, 0x18),

    /* Page Program - single mode */
    [4 * NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM_SINGLE] =
        FLEXSPI_LUT_SEQ(kFLEXSPI_Command_SDR, kFLEXSPI_1PAD, 0x02, kFLEXSPI_Command_RADDR_SDR, kFLEXSPI_1PAD, 0x18),
    [4 * NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM_SINGLE + 1] =
        FLEXSPI_LUT_SEQ(kFLEXSPI_Command_WRITE_SDR, kFLEXSPI_1PAD, 0x04, kFLEXSPI_Command_STOP, kFLEXSPI_1PAD, 0),

    /* Page Program - quad mode */
    [4 * NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM_QUAD] =
        FLEXSPI_LUT_SEQ(kFLEXSPI_Command_SDR, kFLEXSPI_1PAD, 0x32, kFLEXSPI_Command_RADDR_SDR, kFLEXSPI_1PAD, 0x18),
    [4 * NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM_QUAD + 1] =
        FLEXSPI_LUT_SEQ(kFLEXSPI_Command_WRITE_SDR, kFLEXSPI_4PAD, 0x04, kFLEXSPI_Command_STOP, kFLEXSPI_1PAD, 0),

    /* Read ID */
    [4 * NOR_CMD_LUT_SEQ_IDX_READID] =
        FLEXSPI_LUT_SEQ(kFLEXSPI_Command_SDR, kFLEXSPI_1PAD, 0x9F, kFLEXSPI_Command_READ_SDR, kFLEXSPI_1PAD, 0x04),

    /* Enable Quad mode */
    [4 * NOR_CMD_LUT_SEQ_IDX_WRITESTATUSREG] =
        FLEXSPI_LUT_SEQ(kFLEXSPI_Command_SDR, kFLEXSPI_1PAD, 0x01, kFLEXSPI_Command_WRITE_SDR, kFLEXSPI_1PAD, 0x04),

    /* Enter QPI mode */
    [4 * NOR_CMD_LUT_SEQ_IDX_ENTERQPI] =
        FLEXSPI_LUT_SEQ(kFLEXSPI_Command_SDR, kFLEXSPI_1PAD, 0x35, kFLEXSPI_Command_STOP, kFLEXSPI_1PAD, 0),

    /* Exit QPI mode */
    [4 * NOR_CMD_LUT_SEQ_IDX_EXITQPI] =
        FLEXSPI_LUT_SEQ(kFLEXSPI_Command_SDR, kFLEXSPI_4PAD, 0xF5, kFLEXSPI_Command_STOP, kFLEXSPI_1PAD, 0),

    /* Read status register */
    [4 * NOR_CMD_LUT_SEQ_IDX_READSTATUSREG] =
        FLEXSPI_LUT_SEQ(kFLEXSPI_Command_SDR, kFLEXSPI_1PAD, 0x05, kFLEXSPI_Command_READ_SDR, kFLEXSPI_1PAD, 0x04),

    /* Erase whole chip */
    [4 * NOR_CMD_LUT_SEQ_IDX_ERASECHIP] =
        FLEXSPI_LUT_SEQ(kFLEXSPI_Command_SDR, kFLEXSPI_1PAD, 0xC7, kFLEXSPI_Command_STOP, kFLEXSPI_1PAD, 0),
};



/*******************************************************************************
 * Prototypes
 ******************************************************************************/

/*******************************************************************************
 * Variables
 ******************************************************************************/

static mdio_handle_t mdioHandle = {.ops = &EXAMPLE_MDIO_OPS};
static phy_handle_t phyHandle   = {.phyAddr = EXAMPLE_PHY_ADDRESS, .mdioHandle = &mdioHandle, .ops = &EXAMPLE_PHY_OPS};

/*******************************************************************************
 * Code
 ******************************************************************************/
void BOARD_InitModuleClock(void)
{
    const clock_enet_pll_config_t config = {.enableClkOutput = true, .enableClkOutput25M = false, .loopDivider = 1};
    CLOCK_InitEnetPll(&config);
}

void delay(void)
{
    volatile uint32_t i = 0;
    for (i = 0; i < 1000000; ++i)
    {
        __asm("NOP"); /* delay */
    }
}



/*!
 * @brief Interrupt service for SysTick timer.
 */
void SysTick_Handler(void)
{
    time_isr();
}

/* Display Functions Declation
 *
 */

/* Initialize the LCD_DISP. */
void BOARD_InitLcd(void)
{
    volatile uint32_t i = 0x1000U;

    gpio_pin_config_t config = {
        kGPIO_DigitalOutput,
        0,
        kGPIO_NoIntmode,
    };

    /* Reset the LCD. */
    GPIO_PinInit(LCD_DISP_GPIO, LCD_DISP_GPIO_PIN, &config);

    GPIO_WritePinOutput(LCD_DISP_GPIO, LCD_DISP_GPIO_PIN, 0);

    while (i--)
    {
    }

    GPIO_WritePinOutput(LCD_DISP_GPIO, LCD_DISP_GPIO_PIN, 1);

    /* Backlight. */
    config.outputLogic = 1;
    GPIO_PinInit(LCD_BL_GPIO, LCD_BL_GPIO_PIN, &config);

    /*Clock setting for LPI2C*/
    CLOCK_SetMux(kCLOCK_Lpi2cMux, LPI2C_CLOCK_SOURCE_SELECT);
    CLOCK_SetDiv(kCLOCK_Lpi2cDiv, LPI2C_CLOCK_SOURCE_DIVIDER);
}

void BOARD_InitLcdifPixelClock(void)
{
    /*
     * The desired output frame rate is 60Hz. So the pixel clock frequency is:
     * (480 + 41 + 4 + 18) * (272 + 10 + 4 + 2) * 60 = 9.2M.
     * Here set the LCDIF pixel clock to 9.3M.
     */

    /*
     * Initialize the Video PLL.
     * Video PLL output clock is OSC24M * (loopDivider + (denominator / numerator)) / postDivider = 93MHz.
     */
    clock_video_pll_config_t config = {
//        .loopDivider = 31,
//        .postDivider = 8,
		.loopDivider = 27,//31,
		.postDivider = 16,//8,
        .numerator   = 0,
        .denominator = 0,
    };

    CLOCK_InitVideoPll(&config);

    /*
     * 000 derive clock from PLL2
     * 001 derive clock from PLL3 PFD3
     * 010 derive clock from PLL5
     * 011 derive clock from PLL2 PFD0
     * 100 derive clock from PLL2 PFD1
     * 101 derive clock from PLL3 PFD1
     */
    CLOCK_SetMux(kCLOCK_LcdifPreMux, 2);

    CLOCK_SetDiv(kCLOCK_LcdifPreDiv, 4);
    CLOCK_SetDiv(kCLOCK_LcdifDiv, 1);

//    CLOCK_SetDiv(kCLOCK_LcdifPreDiv, 0);
//        CLOCK_SetDiv(kCLOCK_LcdifDiv, 0);
}

void BOARD_InitGPT(void)
{
    gpt_config_t gptConfig;

    GPT_GetDefaultConfig(&gptConfig);

    gptConfig.enableFreeRun = true;
    gptConfig.divider       = 3000;

    /* Initialize GPT module */
    GPT_Init(EXAMPLE_GPT, &gptConfig);
    GPT_StartTimer(EXAMPLE_GPT);
}
void extractIP(unsigned char * SrcString, short *ipAddr,int Ip_addr_flag)
{
    unsigned short len=0;
    unsigned char buf[5],oct[4]={0},cnt=0,cnt1=0,i;
    len = strlen(SrcString);
    for(i=0;i<len;i++)
    {
        if(SrcString[i]!='.')
        {
            buf[cnt++] = SrcString[i];
        }
        if(SrcString[i]=='.' || i==len-1)
        {
            buf[cnt]='\0';
            cnt=0;
            oct[cnt1++]=atoi(buf);
        }
    }
    switch(Ip_addr_flag)
    {
    	case 1:
					Buc_extract_ipAddr[0] = oct[0];
					Buc_extract_ipAddr[1] = oct[1];
					Buc_extract_ipAddr[2] = oct[2];
					Buc_extract_ipAddr[3] = oct[3];
					break;
    	case 2:
					Buc_extract_SubNet_Addr[0] = oct[0];
					Buc_extract_SubNet_Addr[1] = oct[1];
					Buc_extract_SubNet_Addr[2] = oct[2];
					Buc_extract_SubNet_Addr[3] = oct[3];
					break;
    	case 3:
    				Buc_extract_Gateway_Addr[0] = oct[0];
    				Buc_extract_Gateway_Addr[1] = oct[1];
    				Buc_extract_Gateway_Addr[2] = oct[2];
    				Buc_extract_Gateway_Addr[3] = oct[3];
    				break;
    	case 4:
					HHT_extract_ipAddr[0] = oct[0];
					HHT_extract_ipAddr[1] = oct[1];
					HHT_extract_ipAddr[2] = oct[2];
					HHT_extract_ipAddr[3] = oct[3];
					break;
    	case 5:
					HHT_extract_SubNet_Addr[0] = oct[0];
					HHT_extract_SubNet_Addr[1] = oct[1];
					HHT_extract_SubNet_Addr[2] = oct[2];
					HHT_extract_SubNet_Addr[3] = oct[3];
					break;
    	case 6:
					HHT_extract_Gateway_Addr[0] = oct[0];
					HHT_extract_Gateway_Addr[1] = oct[1];
					HHT_extract_Gateway_Addr[2] = oct[2];
					HHT_extract_Gateway_Addr[3] = oct[3];
					break;
    	default:	break;

    }
}

void Update_GUI_Parameters_with_Saved_Values()
{
		//Attenution Control
	if(g_Rx_ACK_from_BUC_Pkt==1)
	{
			PRINTF("\n\r Operator input values are updated");
	}
	else
	{
			PRINTF("\n\r Operator input values are Discarded since ACK not received from BUC"
					"Setting to Default Values");
			snprintf(gui_attenution_ctrl,10,"%s",Backup_gui_attenution_ctrl);
	}
}
void createBackupBuffer()
{
		strcpy(Backup_gui_BUC_ID1,gui_BUC_ID1);
		strcpy(Backup_gui_BUC_Serial_Num,gui_BUC_Serial_Num_P1);
		strcpy(Backup_gui_BUC_SW_VER_P1,gui_BUC_SW_VER_P1);
		strcpy(Backup_gui_BUC_FW_VER_P1,gui_BUC_FW_VER_P1);
		strcpy(Backup_gui_BUC_Manuf_Date,gui_BUC_Manuf_Date_P1);

		strcpy(Backup_gui_attenution_ctrl,gui_attenution_ctrl);

		strcpy(Backup_gui_RF_FWD_Power_Status_P1,gui_RF_FWD_Power_Status_P1);
		strcpy(Backup_gui_Ext_10Mhz_Src_Status,gui_Ext_10Mhz_Src_Status);

		strcpy(Backup_gui_RF_FWD_Power_Alarm_Health,gui_RF_FWD_Power_Alarm_Health);
		strcpy(Backup_gui_Input_Power_Health,gui_Input_Power_Health);
		strcpy(Backup_gui_PLO_Lock_Status_Health,gui_PLO_Lock_Status_Health);
		strcpy(Backup_gui_LO_Power_Level_Health,gui_LO_Power_Level_Health);
		strcpy(Backup_gui_L_Band_Input_OverDrive_Health,gui_L_Band_Input_OverDrive_Health);
		strcpy(Backup_gui_Fan_Health,gui_Fan_Health);
		strcpy(Backup_gui_VSWR_Alarm_Health,gui_VSWR_Alarm_Health);
		strcpy(Backup_gui_DC_24V_health,gui_DC_24V_health);
		strcpy(Backup_gui_Sequence_Health,gui_Sequence_Health);
		strcpy(Backup_gui_Temp_HPD_Health,gui_Temp_HPD_Health);

		strcpy(Backup_gui_Low_Power_Sel_Switch,gui_Low_Power_Sel_Switch);
		strcpy(Backup_gui_RF_Mute_Status,gui_RF_Mute_Status);
		strcpy(Backup_gui_BUC_Status,gui_BUC_Status);
		strcpy(Backup_gui_DC_Input_Current,gui_DC_Input_Current_P1);
		strcpy(Backup_gui_Temp_HPD,gui_Temp_HPD_P1);
		strcpy(Backup_gui_Temp_PS,gui_Temp_PS_P1);

		strcpy(Backup_gui_BUC_IP_Addr1,gui_BUC_IP_Addr1);
		strcpy(Backup_gui_BUC_Subnet_Addr1,gui_BUC_Subnet_Addr1);
		strcpy(Backup_gui_BUC_Gateway_Addr1,gui_BUC_Gateway_Addr1);

//		PRINTF("\n\r Backup_gui_BUC_ID1=%s",Backup_gui_BUC_ID1);
//		PRINTF("\n\r Backup_gui_BUC_Serial_Num=%s",Backup_gui_BUC_Serial_Num);
//		PRINTF("\n\r Backup_gui_BUC_SW_VER_P1=%s",Backup_gui_BUC_SW_VER_P1);
//		PRINTF("\n\r Backup_gui_BUC_FW_VER_P1=%s",Backup_gui_BUC_FW_VER_P1);
//		PRINTF("\n\r Backup_gui_BUC_Day=%s",Backup_gui_BUC_Manuf_Date);
}
void Flash_Data_Parsing_OnBoot()
{
		PRINTF("\n\r FLASH DATA is::\n\r");
		printf("\n%s",s_nor_read_buffer);
		char *tok;
		BC=0;
		int TokNum=0;
		tok = strtok(s_nor_read_buffer,"$");
		while(tok!=NULL)
		{
			  //PRINTF("\n\rtok0=%s",tok);
			  switch(TokNum)
			  {
					case 0:		strcpy(gui_BUC_ID1,tok);						break;
					case 1:		strcpy(gui_BUC_Serial_Num_P1,tok);				break;
					case 2:		strcpy(gui_BUC_SW_VER_P1,tok);					break;
					case 3:		strcpy(gui_BUC_FW_VER_P1,tok);					break;
					case 4:		strcpy(gui_BUC_Manuf_Date_P1,tok);				break;
					case 5:		strcpy(gui_RF_FWD_Power_Status_P1,tok);			break;
					case 6:
								if((strcmp(tok,"1")==0))				//  0->external , 1-> internal
										strcpy(gui_Ext_10Mhz_Src_Status,gui_INTERNAL_DESC);
								else
										strcpy(gui_Ext_10Mhz_Src_Status,gui_EXTERNAL_DESC);
								break;
					case 7:
								if((strcmp(tok,"1")==0))
										strcpy(gui_RF_FWD_Power_Alarm_Health,gui_HEALTHY_DESC);
								else
										strcpy(gui_RF_FWD_Power_Alarm_Health,gui_UNHEALTHY_DESC);
								break;
					case 8:
								if((strcmp(tok,"1")==0))
									strcpy(gui_Input_Power_Health,gui_HEALTHY_DESC);
								else
									strcpy(gui_Input_Power_Health,gui_UNHEALTHY_DESC);
								break;
					case 9:
								if((strcmp(tok,"1")==0))
									strcpy(gui_PLO_Lock_Status_Health,gui_HEALTHY_DESC);
								else
									strcpy(gui_PLO_Lock_Status_Health,gui_UNHEALTHY_DESC);
								break;

					case 10:
								if((strcmp(tok,"1")==0))
									strcpy(gui_LO_Power_Level_Health,gui_HEALTHY_DESC);
								else
									strcpy(gui_LO_Power_Level_Health,gui_UNHEALTHY_DESC);
								break;

					case 11:
								if((strcmp(tok,"1")==0))
									strcpy(gui_L_Band_Input_OverDrive_Health,gui_HEALTHY_DESC);
								else
									strcpy(gui_L_Band_Input_OverDrive_Health,gui_UNHEALTHY_DESC);
								break;

					case 12:
								if((strcmp(tok,"1")==0))
									strcpy(gui_Fan_Health,gui_HEALTHY_DESC);
								else
									strcpy(gui_Fan_Health,gui_UNHEALTHY_DESC);
								break;

					case 13:
								if((strcmp(tok,"1")==0))
									strcpy(gui_VSWR_Alarm_Health,gui_HEALTHY_DESC);
								else
									strcpy(gui_VSWR_Alarm_Health,gui_UNHEALTHY_DESC);
								break;

					case 14:
								if((strcmp(tok,"1")==0))
									strcpy(gui_DC_24V_health,gui_HEALTHY_DESC);
								else
									strcpy(gui_DC_24V_health,gui_UNHEALTHY_DESC);
								break;

					case 15:
								if((strcmp(tok,"1")==0))
									strcpy(gui_Sequence_Health,gui_HEALTHY_DESC);
								else
									strcpy(gui_Sequence_Health,gui_UNHEALTHY_DESC);
								break;

					case 16:
								if((strcmp(tok,"1")==0))
									strcpy(gui_Temp_HPD_Health,gui_HEALTHY_DESC);
								else
									strcpy(gui_Temp_HPD_Health,gui_UNHEALTHY_DESC);
								break;

					case 17:
								if((strcmp(tok,"1")==0))
									strcpy(gui_Low_Power_Sel_Switch,gui_ON_DESC);
								else
									strcpy(gui_Low_Power_Sel_Switch,gui_OFF_DESC);
								break;

					case 18:														// 1-OFF, 0-ON
								if((strcmp(tok,"1")==0))
									strcpy(gui_RF_Mute_Status,gui_OFF_DESC);
								else
									strcpy(gui_RF_Mute_Status,gui_ON_DESC);
								break;

					case 19:
								if((strcmp(tok,"1")==0))
									strcpy(gui_BUC_Status,gui_ACTIVE_DESC);
								else
									strcpy(gui_BUC_Status,gui_SLEEP_DESC);
								break;

					case 20:	strcpy(gui_DC_Input_Current_P1,tok);			break;
					case 21:	strcpy(gui_Temp_HPD_P1,tok);					break;
					case 22:	strcpy(gui_Temp_PS_P1,tok);						break;
					case 23:	strcpy(gui_BUC_IP_Addr1,tok);					break;
					case 24:	strcpy(gui_BUC_Subnet_Addr1,tok);				break;
					case 25:	strcpy(gui_BUC_Gateway_Addr1,tok);				break;
					//RF Attenution Control
					case 26:    strcpy(gui_attenution_ctrl,tok);				break;
					// Low Power Selection Switch Slide Bar-- Not Using
					case 27:	;												break;

					//RF Mute Control Slide Bar
					case 28:    strcpy(gui_RF_Mute_Ctrl,tok);
								udp_RF_Mute_Ctrl = atoi(gui_RF_Mute_Ctrl);
								 PRINTF("\n\r gui_RF_Mute_Ctrl=%s\t udp_RF_Mute_Ctrl=%d      ",gui_RF_Mute_Ctrl,udp_RF_Mute_Ctrl);
								if(udp_RF_Mute_Ctrl==1)
								{
									udp_RF_Mute_Ctrl=0;
								}
								else if(udp_RF_Mute_Ctrl==0)
								{
									udp_RF_Mute_Ctrl=1;
								}
								else
								{
									;
								}
								 PRINTF("\n\r AFTER gui_RF_Mute_Ctrl=%s\tudp_RF_Mute_Ctrl=%d      ",gui_RF_Mute_Ctrl,udp_RF_Mute_Ctrl);
								break;

					// Ext_10MHz_Ref_Src Slide Bar
					case 29:    strcpy(gui_Ext_10MHz_Ref_Src,tok);
								udp_Ext_10MHz_Ref_Src = atoi(gui_Ext_10MHz_Ref_Src);
								 PRINTF("\n\r gui_Ext_10MHz_Ref_Src=%s\t udp_Ext_10MHz_Ref_Src=%d      ",gui_Ext_10MHz_Ref_Src,udp_Ext_10MHz_Ref_Src);
								if(udp_Ext_10MHz_Ref_Src==1)
								{
									udp_Ext_10MHz_Ref_Src=0;
								}
								else if(udp_Ext_10MHz_Ref_Src==0)
								{
									udp_Ext_10MHz_Ref_Src=1;
								}
								else
								{
									;
								}
								 PRINTF("\n\r AFTER gui_Ext_10MHz_Ref_Src=%s\t udp_Ext_10MHz_Ref_Src=%d      ",gui_Ext_10MHz_Ref_Src,udp_Ext_10MHz_Ref_Src);
								break;

					// Sys Mode-- Not Using
					case 30:	;												break;


					//BUC Self Master/StandBy Status
					case 31:	strcpy(gui_BUC_SelfMaster,tok);
								udp_Self_Master_Enable_Disable_Status = atoi(gui_BUC_SelfMaster);
								break;

					default:	break;
			  }
			  tok=strtok(NULL,"$");
			  TokNum++;
		}
			  	PRINTF("\n\r [UDP] gui_attenution_ctrl=%s",gui_attenution_ctrl);
			  	PRINTF("\n\r [UDP] gui_Ext_10MHz_Ref_Src=%s\tudp_Ext_10MHz_Ref_Src=%d",gui_Ext_10MHz_Ref_Src,udp_Ext_10MHz_Ref_Src);
			  	PRINTF("\n\r [UDP] gui_RF_Mute_Ctrl=%s\tudp_RF_Mute_Ctrl=%d",gui_RF_Mute_Ctrl,udp_RF_Mute_Ctrl);

			  	  	PRINTF("\n\r gui_BUC_ID1=%s                          ",gui_BUC_ID1);
			  		PRINTF("\n\r gui_BUC_Serial_Num=%s                   ",gui_BUC_Serial_Num_P1);
			  		PRINTF("\n\r gui_BUC_SW_VER_P1=%s                    ",gui_BUC_SW_VER_P1);
			  		PRINTF("\n\r gui_BUC_FW_VER_P1=%s                    ",gui_BUC_FW_VER_P1);
			  		PRINTF("\n\r gui_BUC_Manufacture_Date=%s             ",gui_BUC_Manuf_Date_P1);

			  		PRINTF("\n\r gui_RF_FWD_Power_Status=%s              ",gui_RF_FWD_Power_Status_P1);
			  		PRINTF("\n\r gui_Ext_10Mhz_Src_Status=%s             ",gui_Ext_10Mhz_Src_Status);

			  		PRINTF("\n\r RF_FWD_Power_Alarm_Health=%s            ",gui_RF_FWD_Power_Alarm_Health);
			  		PRINTF("\n\r Input_Power_Health=%s                   ",gui_Input_Power_Health);
			  		PRINTF("\n\r PLO_Lock_Status_Health=%s               ",gui_PLO_Lock_Status_Health);
			  		PRINTF("\n\r LO_Power_Level_Health=%s                ",gui_LO_Power_Level_Health);
			  		PRINTF("\n\r L_Band_Input_OverDrive_Health=%s        ",gui_L_Band_Input_OverDrive_Health);
			  		PRINTF("\n\r Fan_Health=%s                           ",gui_Fan_Health);
			  		PRINTF("\n\r VSWR_Alarm_Health=%s                    ",gui_VSWR_Alarm_Health);
			  		PRINTF("\n\r DC_24V_health=%s                        ",gui_DC_24V_health);
			  		PRINTF("\n\r Sequence_Health=%s                      ",gui_Sequence_Health);
			  		PRINTF("\n\r Temp_HPD_Health=%s                      ",gui_Temp_HPD_Health);

			  		PRINTF("\n\r Low_Power_Sel_Switch=%s                 ",gui_Low_Power_Sel_Switch);
			  		PRINTF("\n\r RF_Mute_Status=%s                       ",gui_RF_Mute_Status);
			  		PRINTF("\n\r BUC_Status=%s                           ",gui_BUC_Status);
			  		PRINTF("\n\r gui_DC_Input_Current_P1=%s              ",gui_DC_Input_Current_P1);
			  		PRINTF("\n\r gui_Temp_HPD_P1=%s                      ",gui_Temp_HPD_P1);
			  		PRINTF("\n\r gui_Temp_PS=%s                          ",gui_Temp_PS_P1);

					PRINTF("\n\r gui_BUC_IP_Addr1=%s                     ",gui_BUC_IP_Addr1);
					PRINTF("\n\r gui_BUC_Subnet_Addr1=%s                 ",gui_BUC_Subnet_Addr1);
					PRINTF("\n\r gui_BUC_Gateway_Addr1=%s                ",gui_BUC_Gateway_Addr1);
			  		PRINTF("\n\r gui_BUC_Gateway_Addr1=%s                ",gui_BUC_Gateway_Addr1);
					  PRINTF("\n\r gui_RF_Mute_Ctrl=%s\tudp_RF_Mute_Ctrl=%d      ",gui_RF_Mute_Ctrl,udp_RF_Mute_Ctrl);
					  PRINTF("\n\r gui_Ext_10MHz_Ref_Src=%s\t udp_Ext_10MHz_Ref_Src=%d      ",gui_Ext_10MHz_Ref_Src,udp_Ext_10MHz_Ref_Src);
					  PRINTF("\n\r gui_BUC_SelfMaster=%s\t udp_Self_Master_Enable_Disable_Status=%d      ",gui_BUC_SelfMaster,udp_Self_Master_Enable_Disable_Status);

}

static void
udp_recv_func(void *arg, struct udp_pcb *upcb, struct pbuf *p,
                 const ip_addr_t *addr, u16_t port)
{
  g_Prev_RxPktCnt_Total = g_RxPktCnt_Total;
  g_RxPktCnt_Total++;
  PRINTF("\n\rPKT RCVD: g_RxPktCnt_Total=%d\r\n",g_RxPktCnt_Total);
  volatile u16_t u16Len;
  volatile struct pbuf *pLoc;
  pui8Data = p->payload;

  Ethernet_Link_Status=2;
//  stRxbuf *stRxBufPtr;
//  stRxBufPtr = &g_Rxbuf;
  HHT_Parameters *stRxBufPtr;
  err_t error_code;
  PRINTF("p->tot_len=%d\r\n",p->tot_len);
  PRINTF("p->len=%d\r\n",p->len);
  //PRINTF("sizeof(st_HHT_Parameters)=%d\r\n",sizeof(st_HHT_Parameters));
  int i;
//  for(i=0;i<p->tot_len;i++)
//  {
//	  //PRINTF("RcvdPkt[%d]::\t%d\t %c\n\r",i,pui8Data[i],pui8Data[i]);
//  }
  if(p->tot_len>50 &&p->tot_len<150)
  {
	  Parameter_UDP_Pkt_from_BUC_Received=1;
	  g_Rx_Param_from_BUC_Pkt_Cnt++;

	  stRxBufPtr = &st_HHT_Parameters;
	  memcpy(stRxBufPtr,pui8Data,sizeof(st_HHT_Parameters));
//	  memcpy(s_nor_program_buffer,pui8Data,sizeof(st_HHT_Parameters));
//	  printf("\ns_nor_program_buffer=%s",s_nor_program_buffer);

	  //FLASH PROGRAM START

				uint32_t i = 0;
				status_t status;
				uint8_t vendorID = 0;
	           // while(1)
	            //{
	            	count++;
	            	/* Enter quad mode. */
//	                status = flexspi_nor_enable_quad_mode(EXAMPLE_FLEXSPI);
//	                if (status != kStatus_Success)
//	                {
//	                    return status;
//	                }
//
//	                /* Erase sectors. */
//	                PRINTF("Erasing Serial NOR over FlexSPI...\r\n");
//	                status = flexspi_nor_flash_erase_sector(EXAMPLE_FLEXSPI, EXAMPLE_SECTOR * SECTOR_SIZE);
//	                if (status != kStatus_Success)
//	                {
//	                    PRINTF("Erase sector failure !\r\n");
//	                    return -1;
//	                }
//
//
//	                memset(s_nor_program_buffer, 0xFFU, sizeof(s_nor_program_buffer));
//
//	                DCACHE_InvalidateByRange(EXAMPLE_FLEXSPI_AMBA_BASE + EXAMPLE_SECTOR * SECTOR_SIZE, FLASH_PAGE_SIZE);
//
//	                memcpy(s_nor_read_buffer, (void *)(EXAMPLE_FLEXSPI_AMBA_BASE + EXAMPLE_SECTOR * SECTOR_SIZE),
//	                       sizeof(s_nor_read_buffer));
//
//	                if (memcmp(s_nor_program_buffer, s_nor_read_buffer, sizeof(s_nor_program_buffer)))
//	                {
//	                    PRINTF("Erase data -  read out data value incorrect !\r\n ");
//	                    return -1;
//	                }
//	                else
//	                {
//	                    PRINTF("Erase data - successfully. \r\n");
//	                }

//	                uint8_t sample_buffer[256] = "EVEN Time EVEN Time EVEN Time";
//
//
//	                for (i = 0; i < 0xFFU; i++)
//	                {
//	                	if(count%2==0)
//	        			{
//	        				uint8_t sample_buffer[256] = "EVEN Time EVEN Time EVEN Time";
//	        				 s_nor_program_buffer[i] = sample_buffer[i];
//	        			}
//	        			if(count%2==1)
//	        			{
//	        				uint8_t sample_buffer[256] = "ODD Time ODD Time ODD Time ODD Time";
//	        				 s_nor_program_buffer[i] = sample_buffer[i];
//	        			}
//	        			if(count%3==1)
//	        			{
//	        				uint8_t sample_buffer[256] = "DEVIDED BY THREE DEVIDED BY THREE";
//	        				s_nor_program_buffer[i] = sample_buffer[i];
//	        			}
//
//
//	                }
//	                PRINTF("\n-------------- Contents of s_nor_program_buffer Before Writing into from Flash Memory---------\n");
//	                for (i = 0; i < 0xFFU; i++)
//	                {
//
//	                	PRINTF("%c",s_nor_program_buffer[i]);
//	                }
//
//
//	                status =
//	                    flexspi_nor_flash_page_program(EXAMPLE_FLEXSPI, EXAMPLE_SECTOR * SECTOR_SIZE, (void *)s_nor_program_buffer);
//	                if (status != kStatus_Success)
//	                {
//	                    PRINTF("Page program failure !\r\n");
//	                    return -1;
//	                }
//	                else
//	                {
//	                   	PRINTF("Page program Success !\r\n");
//	                }
//
//	                DCACHE_InvalidateByRange(EXAMPLE_FLEXSPI_AMBA_BASE + EXAMPLE_SECTOR * SECTOR_SIZE, FLASH_PAGE_SIZE);
//
//	                memcpy(s_nor_read_buffer, (void *)(EXAMPLE_FLEXSPI_AMBA_BASE + EXAMPLE_SECTOR * SECTOR_SIZE),
//	                       sizeof(s_nor_read_buffer));
//
//
//	                PRINTF("\n-------------- Contents of s_nor_read_buffer After Reading from Flash Memory---------\n");
//	                for (i = 0; i < 0xFFU; i++)
//	                {
//	                        PRINTF("%c",s_nor_read_buffer[i]);
//	                }
//	                PRINTF("\n");
//
//
//	                if (memcmp(s_nor_read_buffer, s_nor_program_buffer, sizeof(s_nor_program_buffer)) != 0)
//	                {
//	                    PRINTF("Program data -  read out data value incorrect !\r\n ");
//	                    return -1;
//	                }
//	                else
//	                {
//	                    PRINTF("Program data - successfully. \r\n");
//	                }

	            //}



	        //FLASH PROGRAM END





	  //}
	  PRINTF("\n\r UDP Parameter Packet Received from BUC is::\n\r");
		char *tok;
		BC=0;
		int TokNum=0;
		tok = strtok(pui8Data,"$");
		while(tok!=NULL)
		{
			  //PRINTF("\n\rtok0=%s",tok);
			  switch(TokNum)
			  {
					case 0:		strcpy(gui_BUC_ID1,tok);						break;
					case 1:		strcpy(gui_BUC_Serial_Num_P1,tok);				break;
					case 2:		strcpy(gui_BUC_SW_VER_P1,tok);					break;
					case 3:		strcpy(gui_BUC_FW_VER_P1,tok);					break;
					case 4:		strcpy(gui_BUC_Manuf_Date_P1,tok);				break;
					case 5:		strcpy(gui_RF_FWD_Power_Status_P1,tok);			break;
					case 6:
								if((strcmp(tok,"1")==0))				//  0->external , 1-> internal
										strcpy(gui_Ext_10Mhz_Src_Status,gui_INTERNAL_DESC);
								else
										strcpy(gui_Ext_10Mhz_Src_Status,gui_EXTERNAL_DESC);
								break;
					case 7:
								if((strcmp(tok,"1")==0))
										strcpy(gui_RF_FWD_Power_Alarm_Health,gui_HEALTHY_DESC);
								else
										strcpy(gui_RF_FWD_Power_Alarm_Health,gui_UNHEALTHY_DESC);
								break;
					case 8:
								if((strcmp(tok,"1")==0))
									strcpy(gui_Input_Power_Health,gui_HEALTHY_DESC);
								else
									strcpy(gui_Input_Power_Health,gui_UNHEALTHY_DESC);
								break;
					case 9:
								if((strcmp(tok,"1")==0))
									strcpy(gui_PLO_Lock_Status_Health,gui_HEALTHY_DESC);
								else
									strcpy(gui_PLO_Lock_Status_Health,gui_UNHEALTHY_DESC);
								break;

					case 10:
								if((strcmp(tok,"1")==0))
									strcpy(gui_LO_Power_Level_Health,gui_HEALTHY_DESC);
								else
									strcpy(gui_LO_Power_Level_Health,gui_UNHEALTHY_DESC);
								break;

					case 11:
								if((strcmp(tok,"1")==0))
									strcpy(gui_L_Band_Input_OverDrive_Health,gui_HEALTHY_DESC);
								else
									strcpy(gui_L_Band_Input_OverDrive_Health,gui_UNHEALTHY_DESC);
								break;

					case 12:
								if((strcmp(tok,"1")==0))
									strcpy(gui_Fan_Health,gui_HEALTHY_DESC);
								else
									strcpy(gui_Fan_Health,gui_UNHEALTHY_DESC);
								break;

					case 13:
								if((strcmp(tok,"1")==0))
									strcpy(gui_VSWR_Alarm_Health,gui_HEALTHY_DESC);
								else
									strcpy(gui_VSWR_Alarm_Health,gui_UNHEALTHY_DESC);
								break;

					case 14:
								if((strcmp(tok,"1")==0))
									strcpy(gui_DC_24V_health,gui_HEALTHY_DESC);
								else
									strcpy(gui_DC_24V_health,gui_UNHEALTHY_DESC);
								break;

					case 15:
								if((strcmp(tok,"1")==0))
									strcpy(gui_Sequence_Health,gui_HEALTHY_DESC);
								else
									strcpy(gui_Sequence_Health,gui_UNHEALTHY_DESC);
								break;

					case 16:
								if((strcmp(tok,"1")==0))
									strcpy(gui_Temp_HPD_Health,gui_HEALTHY_DESC);
								else
									strcpy(gui_Temp_HPD_Health,gui_UNHEALTHY_DESC);
								break;

					case 17:
								if((strcmp(tok,"1")==0))
									strcpy(gui_Low_Power_Sel_Switch,gui_ON_DESC);
								else
									strcpy(gui_Low_Power_Sel_Switch,gui_OFF_DESC);
								break;

					case 18:														// 1-OFF, 0-ON
								if((strcmp(tok,"1")==0))
									strcpy(gui_RF_Mute_Status,gui_OFF_DESC);
								else
									strcpy(gui_RF_Mute_Status,gui_ON_DESC);
								break;

					case 19:
								if((strcmp(tok,"1")==0))
									strcpy(gui_BUC_Status,gui_ACTIVE_DESC);
								else
									strcpy(gui_BUC_Status,gui_SLEEP_DESC);
								break;

					case 20:	strcpy(gui_DC_Input_Current_P1,tok);			break;
					case 21:	strcpy(gui_Temp_HPD_P1,tok);					break;
					case 22:	strcpy(gui_Temp_PS_P1,tok);						break;
					case 23:	strcpy(gui_BUC_IP_Addr1,tok);					break;
					case 24:	strcpy(gui_BUC_Subnet_Addr1,tok);				break;
					case 25:	strcpy(gui_BUC_Gateway_Addr1,tok);				break;
					//RF Attenution Control
					case 26:    strcpy(gui_attenution_ctrl,tok);				break;
					// Low Power Selection Switch Slide Bar-- Not Using
					case 27:	;												break;

					//RF Mute Control Slide Bar
					case 28:    strcpy(gui_RF_Mute_Ctrl,tok);
								udp_RF_Mute_Ctrl = atoi(gui_RF_Mute_Ctrl);
								//PRINTF("\n\r gui_RF_Mute_Ctrl=%s\t udp_RF_Mute_Ctrl=%d      ",gui_RF_Mute_Ctrl,udp_RF_Mute_Ctrl);
								if(udp_RF_Mute_Ctrl==1)
								{
									udp_RF_Mute_Ctrl=0;
								}
								else if(udp_RF_Mute_Ctrl==0)
								{
									udp_RF_Mute_Ctrl=1;
								}
								else
								{
									;
								}
								// PRINTF("\n\r AFTER gui_RF_Mute_Ctrl=%s\tudp_RF_Mute_Ctrl=%d      ",gui_RF_Mute_Ctrl,udp_RF_Mute_Ctrl);
								break;

					// Ext_10MHz_Ref_Src Slide Bar
					case 29:    strcpy(gui_Ext_10MHz_Ref_Src,tok);
								udp_Ext_10MHz_Ref_Src = atoi(gui_Ext_10MHz_Ref_Src);
								// PRINTF("\n\r gui_Ext_10MHz_Ref_Src=%s\t udp_Ext_10MHz_Ref_Src=%d      ",gui_Ext_10MHz_Ref_Src,udp_Ext_10MHz_Ref_Src);
								if(udp_Ext_10MHz_Ref_Src==1)
								{
									udp_Ext_10MHz_Ref_Src=0;
								}
								else if(udp_Ext_10MHz_Ref_Src==0)
								{
									udp_Ext_10MHz_Ref_Src=1;
								}
								else
								{
									;
								}
								// PRINTF("\n\r AFTER gui_Ext_10MHz_Ref_Src=%s\t udp_Ext_10MHz_Ref_Src=%d      ",gui_Ext_10MHz_Ref_Src,udp_Ext_10MHz_Ref_Src);
								break;

					// Sys Mode-- Not Using
					case 30:	;												break;


					//BUC Self Master/StandBy Status
					case 31:	strcpy(gui_BUC_SelfMaster,tok);
								udp_Self_Master_Enable_Disable_Status = atoi(gui_BUC_SelfMaster);
								break;

					default:	break;
			  }
			  tok=strtok(NULL,"$");
			  TokNum++;
		}
		//	  	PRINTF("\n\r [UDP] gui_attenution_ctrl=%s",gui_attenution_ctrl);
		//	  	PRINTF("\n\r [UDP] gui_Ext_10MHz_Ref_Src=%s\tudp_Ext_10MHz_Ref_Src=%d",gui_Ext_10MHz_Ref_Src,udp_Ext_10MHz_Ref_Src);
		//	  	PRINTF("\n\r [UDP] gui_RF_Mute_Ctrl=%s\tudp_RF_Mute_Ctrl=%d",gui_RF_Mute_Ctrl,udp_RF_Mute_Ctrl);

		//	  	  	PRINTF("\n\r gui_BUC_ID1=%s                          ",gui_BUC_ID1);
		//	  		PRINTF("\n\r gui_BUC_Serial_Num=%s                   ",gui_BUC_Serial_Num_P1);
		//	  		PRINTF("\n\r gui_BUC_SW_VER_P1=%s                    ",gui_BUC_SW_VER_P1);
		//	  		PRINTF("\n\r gui_BUC_FW_VER_P1=%s                    ",gui_BUC_FW_VER_P1);
		//	  		PRINTF("\n\r gui_BUC_Manufacture_Date=%s             ",gui_BUC_Manuf_Date_P1);
		//
		//	  		PRINTF("\n\r gui_RF_FWD_Power_Status=%s              ",gui_RF_FWD_Power_Status_P1);
		//	  		PRINTF("\n\r gui_Ext_10Mhz_Src_Status=%s             ",gui_Ext_10Mhz_Src_Status);
		//
		//	  		PRINTF("\n\r RF_FWD_Power_Alarm_Health=%s            ",gui_RF_FWD_Power_Alarm_Health);
		//	  		PRINTF("\n\r Input_Power_Health=%s                   ",gui_Input_Power_Health);
		//	  		PRINTF("\n\r PLO_Lock_Status_Health=%s               ",gui_PLO_Lock_Status_Health);
		//	  		PRINTF("\n\r LO_Power_Level_Health=%s                ",gui_LO_Power_Level_Health);
		//	  		PRINTF("\n\r L_Band_Input_OverDrive_Health=%s        ",gui_L_Band_Input_OverDrive_Health);
		//	  		PRINTF("\n\r Fan_Health=%s                           ",gui_Fan_Health);
		//	  		PRINTF("\n\r VSWR_Alarm_Health=%s                    ",gui_VSWR_Alarm_Health);
		//	  		PRINTF("\n\r DC_24V_health=%s                        ",gui_DC_24V_health);
		//	  		PRINTF("\n\r Sequence_Health=%s                      ",gui_Sequence_Health);
		//	  		PRINTF("\n\r Temp_HPD_Health=%s                      ",gui_Temp_HPD_Health);
		//
		//	  		PRINTF("\n\r Low_Power_Sel_Switch=%s                 ",gui_Low_Power_Sel_Switch);
		//	  		PRINTF("\n\r RF_Mute_Status=%s                       ",gui_RF_Mute_Status);
		//	  		PRINTF("\n\r BUC_Status=%s                           ",gui_BUC_Status);
		//	  		PRINTF("\n\r gui_DC_Input_Current_P1=%s              ",gui_DC_Input_Current_P1);
		//	  		PRINTF("\n\r gui_Temp_HPD_P1=%s                      ",gui_Temp_HPD_P1);
		//	  		PRINTF("\n\r gui_Temp_PS=%s                          ",gui_Temp_PS_P1);
		//
		//			PRINTF("\n\r gui_BUC_IP_Addr1=%s                     ",gui_BUC_IP_Addr1);
		//			PRINTF("\n\r gui_BUC_Subnet_Addr1=%s                 ",gui_BUC_Subnet_Addr1);
		//			PRINTF("\n\r gui_BUC_Gateway_Addr1=%s                ",gui_BUC_Gateway_Addr1);
			  //			PRINTF("\n\r gui_BUC_Gateway_Addr1=%s                ",gui_BUC_Gateway_Addr1);
		//	  PRINTF("\n\r gui_RF_Mute_Ctrl=%s\tudp_RF_Mute_Ctrl=%d      ",gui_RF_Mute_Ctrl,udp_RF_Mute_Ctrl);
		//	  PRINTF("\n\r gui_Ext_10MHz_Ref_Src=%s\t udp_Ext_10MHz_Ref_Src=%d      ",gui_Ext_10MHz_Ref_Src,udp_Ext_10MHz_Ref_Src);
		//	  PRINTF("\n\r gui_BUC_SelfMaster=%s\t udp_Self_Master_Enable_Disable_Status=%d      ",gui_BUC_SelfMaster,udp_Self_Master_Enable_Disable_Status);
	  createBackupBuffer();
  }
//  if(p->tot_len>5 && p->tot_len<15)
//  {
//	  int i;
//	  g_Rx_ACK_from_BUC_Pkt=1;
//	  Update_GUI_Parameters_with_Saved_Values();
//	  PRINTF("\n\r ACK PACKET FROM BUC RECEIVED");
//	  for(i=0;i<p->tot_len;i++)
//	  {
//		  PRINTF("ACKPkt[%d]::\t%d\n\r",i,pui8Data[i]);
//	  }
//
//  }
//  if(p->tot_len == sizeof(st_HHT_Parameters))
//  {
//	  if(p->tot_len == p->len)
//	  {
//	      		//
//	      		//copy the payload into control packet structure
//	      		//
//	      		memcpy(stRxBufPtr,pui8Data,sizeof(st_HHT_Parameters));
//	      		BC=0;
//	   }
//	  else
//	      	{
//	      		pLoc = p;
//	  		   /* iterate through pbuf chain */
//	  			while(pLoc)
//	  			  {
//	  					pui8Data = pLoc->payload;
//	  					u16Len   = pLoc->len;
//	  					memcpy(stRxBufPtr,pui8Data,u16Len);
//	  					stRxBufPtr = stRxBufPtr + u16Len;
//	  					pLoc = pLoc->next;
//	  			  }; //untill we get a valid pbuf
//	      	}
//  }
    pbuf_free(p);

}
void GUI_Updated_Transmit_Packet()
{
	uint32_t error_code;
	if(BUC_Info_Buc_ID_Save_Flag==1)
	{
					st_GUI_Updated_BUC_Info_ID.ID_BUC_INFO_ID_UPDATE = BUC_INFO_ID_UPDATE;
					int i=0;
					for(i=0;i<=20;i++)
					{
						st_GUI_Updated_BUC_Info_ID.Updated_BUC_ID[i]	=  gui_BUC_Info_ID[i];
					}
					  tx_update_pb = pbuf_alloc(PBUF_TRANSPORT, sizeof(st_GUI_Updated_BUC_Info_ID), PBUF_RAM);
					  if(tx_update_pb == NULL)
					  {
						 return;
					   }
					  memcpy(tx_update_pb->payload,(const char*)&st_GUI_Updated_BUC_Info_ID,sizeof(GUI_Updated_BUC_Info_ID));
					  tx_update_pb->len = tx_update_pb->tot_len = sizeof(st_GUI_Updated_BUC_Info_ID);
					  error_code = udp_sendto(g_udpTxSocket,tx_update_pb, &dstaddr,TxPort);
					  if(error_code != ERR_OK )
					  {
						  PRINTF("\n\r Operator Updated st_GUI_Updated_BUC_Info_ID PKT on TxPort %d & IP Address %d.%d.%d.%d: Sending Failed",
						 						  	  TxPort,config_IP_BUC_ADDR0,config_IP_BUC_ADDR1,config_IP_BUC_ADDR2,config_IP_BUC_ADDR3);
					  }
					  else
					  {
						  	  //g_Tx_Updated_PktCnt++;
							  Update_Pkt_Sent_Flag++;
							  PRINTF("\n\r Operator Updated st_GUI_Updated_BUC_Info_ID PKT SENT on TxPort %d & IP Address %d.%d.%d.%d",
							 				TxPort,config_IP_BUC_ADDR0,config_IP_BUC_ADDR1,config_IP_BUC_ADDR2,config_IP_BUC_ADDR3);
					  }
					  pbuf_free(tx_update_pb);

	}
	else if(Buc_ctrl_RF_attn_ctrl_save_flag==1)
	{
		st_GUI_Updated_RF_Attn_Ctrl.ID_RF_DIGITAL_ATTN = RF_DIGITAL_ATTN;
		Buc_ctrl_RF_attn_ctrl_value = atoi(gui_attenution_ctrl);
		st_GUI_Updated_RF_Attn_Ctrl.Updated_Rf_Attn_Ctrl = Buc_ctrl_RF_attn_ctrl_value;

		  tx_update_pb = pbuf_alloc(PBUF_TRANSPORT, sizeof(st_GUI_Updated_RF_Attn_Ctrl), PBUF_RAM);
		  if(tx_update_pb == NULL)
		  {
			 return;
		   }
		  memcpy(tx_update_pb->payload,(const char*)&st_GUI_Updated_RF_Attn_Ctrl,sizeof(GUI_Updated_RF_Attn_Ctrl));
		  tx_update_pb->len = tx_update_pb->tot_len = sizeof(st_GUI_Updated_RF_Attn_Ctrl);
		  error_code = udp_sendto(g_udpTxSocket,tx_update_pb, &dstaddr,TxPort);
		  if(error_code != ERR_OK )
		  {
			  PRINTF("\n\r Operator Updated RF Attn Control PKT on TxPort %d & IP Address %d.%d.%d.%d: Sending Failed",
			 						  	  TxPort,config_IP_BUC_ADDR0,config_IP_BUC_ADDR1,config_IP_BUC_ADDR2,config_IP_BUC_ADDR3);
		  }
		  else
		  {
			  	  //g_Tx_Updated_PktCnt++;
				  Update_Pkt_Sent_Flag++;
				  PRINTF("\n\r Operator Updated RF Attn Control PKT SENT on TxPort %d & IP Address %d.%d.%d.%d",
				 				TxPort,config_IP_BUC_ADDR0,config_IP_BUC_ADDR1,config_IP_BUC_ADDR2,config_IP_BUC_ADDR3);
		  }
		  pbuf_free(tx_update_pb);
	}

	else if(Buc_ctrl_Ext_10MHz_Ref_Src_save_flag==1)
	{
		  st_GUI_Updated_Ext_10Mhz_Ref_Src_Ctrl.ID_EXT_10MHZ_REF_SRC = EXT_10MHZ_REF_SRC;
		  st_GUI_Updated_Ext_10Mhz_Ref_Src_Ctrl.Updated_Ext_10Mhz_Ref_Src_Ctrl = Buc_ctrl_Ext_10MHz_Ref_Src_switch_value_counter;
		  tx_update_pb = pbuf_alloc(PBUF_TRANSPORT, sizeof(st_GUI_Updated_Ext_10Mhz_Ref_Src_Ctrl), PBUF_RAM);
		  if(tx_update_pb == NULL)
		  {
			 return;
		   }
		  memcpy(tx_update_pb->payload,(const char*)&st_GUI_Updated_Ext_10Mhz_Ref_Src_Ctrl,sizeof(GUI_Updated_Ext_10Mhz_Ref_Src_Ctrl));
		  tx_update_pb->len = tx_update_pb->tot_len = sizeof(st_GUI_Updated_Ext_10Mhz_Ref_Src_Ctrl);
		  error_code = udp_sendto(g_udpTxSocket,tx_update_pb, &dstaddr,TxPort);
		  if(error_code != ERR_OK )
		  {
			  PRINTF("\n\r Operator Updated Ext_10Mhz_Ref_Src_Ctrl PKT on TxPort %d & IP Address %d.%d.%d.%d: Sending Failed",
										  TxPort,config_IP_BUC_ADDR0,config_IP_BUC_ADDR1,config_IP_BUC_ADDR2,config_IP_BUC_ADDR3);
		  }
		  else
		  {
				  //g_Tx_Updated_PktCnt++;
				  Update_Pkt_Sent_Flag++;
				  PRINTF("\n\r Operator Updated Ext_10Mhz_Ref_Src_Ctrl PKT SENT on TxPort %d & IP Address %d.%d.%d.%d",
								TxPort,config_IP_BUC_ADDR0,config_IP_BUC_ADDR1,config_IP_BUC_ADDR2,config_IP_BUC_ADDR3);
		  }
		  pbuf_free(tx_update_pb);

	}

	else if(Buc_ctrl_RF_Mute_save_flag==1)
	{
		  st_GUI_Updated_Rf_Mute_Ctrl.ID_RF_MUTE_CTRL_SW_STATUS = RF_MUTE_CTRL_SW_STATUS;
          st_GUI_Updated_Rf_Mute_Ctrl.Updated_Rf_Mute_Ctrl		 = 		Buc_ctrl_RF_Mute_switch_value_counter;

		  tx_update_pb = pbuf_alloc(PBUF_TRANSPORT, sizeof(st_GUI_Updated_Rf_Mute_Ctrl), PBUF_RAM);
		  if(tx_update_pb == NULL)
		  {
			 return;
		   }
		  memcpy(tx_update_pb->payload,(const char*)&st_GUI_Updated_Rf_Mute_Ctrl,sizeof(GUI_Updated_Rf_Mute_Ctrl));
		  tx_update_pb->len = tx_update_pb->tot_len = sizeof(st_GUI_Updated_Rf_Mute_Ctrl);
		  error_code = udp_sendto(g_udpTxSocket,tx_update_pb, &dstaddr,TxPort);
		  if(error_code != ERR_OK )
		  {
			  PRINTF("\n\r Operator Updated GUI_Updated_Rf_Mute_Ctrl PKT on TxPort %d & IP Address %d.%d.%d.%d: Sending Failed",
										  TxPort,config_IP_BUC_ADDR0,config_IP_BUC_ADDR1,config_IP_BUC_ADDR2,config_IP_BUC_ADDR3);
		  }
		  else
		  {
				  //g_Tx_Updated_PktCnt++;
				  Update_Pkt_Sent_Flag++;
				  PRINTF("\n\r Operator Updated GUI_Updated_Rf_Mute_Ctrl PKT SENT on TxPort %d & IP Address %d.%d.%d.%d",
								TxPort,config_IP_BUC_ADDR0,config_IP_BUC_ADDR1,config_IP_BUC_ADDR2,config_IP_BUC_ADDR3);
		  }
		  pbuf_free(tx_update_pb);

	}
	else if(BUC_Net_Sett_Save_Flag==1)
	{
		  st_GUI_Updated_Buc_IP_Sett.ID_BUC_IP_SETTINGS = BUC_IP_SETTINGS;

		  if(BUC_Net_Sett_Save_Flag==1 && BUC_Net_Validate_Flag==1)
		  {
//					PRINTF("\n\r from GUI Updated Values:");
//					PRINTF("\n\r gui_update_Buc_net_IP_Addr=%s",gui_update_Buc_net_IP_Addr);
//					PRINTF("\n\r gui_update_Buc_net_SubNet_Addr	=%s",gui_update_Buc_net_SubNet_Addr);
//					PRINTF("\n\r gui_update_Buc_net_gateway_Addr=%s",gui_update_Buc_net_gateway_Addr);

					//BUC Local IP Address
					extractIP(gui_update_Buc_net_IP_Addr,&Buc_extract_ipAddr[0],1);

					st_GUI_Updated_Buc_IP_Sett.Updated_Buc_IP_Addr[0]					= Buc_extract_ipAddr[0];
					st_GUI_Updated_Buc_IP_Sett.Updated_Buc_IP_Addr[1]					= Buc_extract_ipAddr[1];
					st_GUI_Updated_Buc_IP_Sett.Updated_Buc_IP_Addr[2]					= Buc_extract_ipAddr[2];
					st_GUI_Updated_Buc_IP_Sett.Updated_Buc_IP_Addr[3]					= Buc_extract_ipAddr[3];

					//BUC Subnet Address
					extractIP(gui_update_Buc_net_SubNet_Addr,&Buc_extract_SubNet_Addr[0],2);

					st_GUI_Updated_Buc_IP_Sett.Updated_Buc_SubNet_Addr[0]				= Buc_extract_SubNet_Addr[0];
					st_GUI_Updated_Buc_IP_Sett.Updated_Buc_SubNet_Addr[1]				= Buc_extract_SubNet_Addr[1];
					st_GUI_Updated_Buc_IP_Sett.Updated_Buc_SubNet_Addr[2]				= Buc_extract_SubNet_Addr[2];
					st_GUI_Updated_Buc_IP_Sett.Updated_Buc_SubNet_Addr[3]				= Buc_extract_SubNet_Addr[3];

					//BUC Gateway Address
					extractIP(gui_update_Buc_net_gateway_Addr,&Buc_extract_Gateway_Addr[0],3);

					st_GUI_Updated_Buc_IP_Sett.Updated_Buc_Gateway_Addr[0]				= Buc_extract_Gateway_Addr[0];
					st_GUI_Updated_Buc_IP_Sett.Updated_Buc_Gateway_Addr[1]				= Buc_extract_Gateway_Addr[1];
					st_GUI_Updated_Buc_IP_Sett.Updated_Buc_Gateway_Addr[2]				= Buc_extract_Gateway_Addr[2];
					st_GUI_Updated_Buc_IP_Sett.Updated_Buc_Gateway_Addr[3]				= Buc_extract_Gateway_Addr[3];

//					PRINTF("\n\r Data to be sent to BUC");
//					PRINTF("\n\r BUC IP ADDRESS=%d.%d.%d.%d",
//							Buc_extract_ipAddr[0],Buc_extract_ipAddr[1],Buc_extract_ipAddr[2],Buc_extract_ipAddr[3]);
//					PRINTF("\n\r BUC SUB NET ADDRESS=%d.%d.%d.%d",
//							Buc_extract_SubNet_Addr[0],Buc_extract_SubNet_Addr[1],Buc_extract_SubNet_Addr[2],Buc_extract_SubNet_Addr[3]);
//					PRINTF("\n\r BUC GATEWAY ADDRESS=%d.%d.%d.%d",
//							Buc_extract_Gateway_Addr[0],Buc_extract_Gateway_Addr[1],Buc_extract_Gateway_Addr[2],Buc_extract_Gateway_Addr[3]);
			}
		else
		{
			extractIP(gui_BUC_IP_Addr1,&Buc_extract_ipAddr[0],1);
			extractIP(gui_BUC_Subnet_Addr1,&Buc_extract_SubNet_Addr[0],2);
			extractIP(gui_BUC_Gateway_Addr1,&Buc_extract_Gateway_Addr[0],3);

			st_GUI_Updated_Buc_IP_Sett.Updated_Buc_IP_Addr[0]		 = 		Buc_extract_ipAddr[0];
			st_GUI_Updated_Buc_IP_Sett.Updated_Buc_IP_Addr[1]		 = 		Buc_extract_ipAddr[1];
			st_GUI_Updated_Buc_IP_Sett.Updated_Buc_IP_Addr[2]		 = 		Buc_extract_ipAddr[2];
			st_GUI_Updated_Buc_IP_Sett.Updated_Buc_IP_Addr[3] 		 = 		Buc_extract_ipAddr[3];

			st_GUI_Updated_Buc_IP_Sett.Updated_Buc_SubNet_Addr[0]	 = 		Buc_extract_SubNet_Addr[0];
			st_GUI_Updated_Buc_IP_Sett.Updated_Buc_SubNet_Addr[1]	 = 		Buc_extract_SubNet_Addr[1];
			st_GUI_Updated_Buc_IP_Sett.Updated_Buc_SubNet_Addr[2]	 = 		Buc_extract_SubNet_Addr[2];
			st_GUI_Updated_Buc_IP_Sett.Updated_Buc_SubNet_Addr[3]	 = 		Buc_extract_SubNet_Addr[3];

			st_GUI_Updated_Buc_IP_Sett.Updated_Buc_Gateway_Addr[0]	 = 		Buc_extract_Gateway_Addr[0];
			st_GUI_Updated_Buc_IP_Sett.Updated_Buc_Gateway_Addr[1]	 = 		Buc_extract_Gateway_Addr[1];
			st_GUI_Updated_Buc_IP_Sett.Updated_Buc_Gateway_Addr[2]	 = 		Buc_extract_Gateway_Addr[2];
			st_GUI_Updated_Buc_IP_Sett.Updated_Buc_Gateway_Addr[3]	 = 		Buc_extract_Gateway_Addr[3];

		}
		  tx_update_pb = pbuf_alloc(PBUF_TRANSPORT, sizeof(st_GUI_Updated_Buc_IP_Sett), PBUF_RAM);
		  if(tx_update_pb == NULL)
		  {
			 return;
		   }
		  memcpy(tx_update_pb->payload,(const char*)&st_GUI_Updated_Buc_IP_Sett,sizeof(GUI_Updated_Buc_IP_Sett));
		  tx_update_pb->len = tx_update_pb->tot_len = sizeof(st_GUI_Updated_Buc_IP_Sett);
		  error_code = udp_sendto(g_udpTxSocket,tx_update_pb, &dstaddr,TxPort);
		  if(error_code != ERR_OK )
		  {
			  PRINTF("\n\r Operator Updated GUI_Updated_Buc_IP_Sett PKT on TxPort %d & IP Address %d.%d.%d.%d: Sending Failed",
										  TxPort,config_IP_BUC_ADDR0,config_IP_BUC_ADDR1,config_IP_BUC_ADDR2,config_IP_BUC_ADDR3);
		  }
		  else
		  {
				  //g_Tx_Updated_PktCnt++;
				  Update_Pkt_Sent_Flag++;
				  PRINTF("\n\r Operator Updated GUI_Updated_Buc_IP_Sett PKT SENT on TxPort %d & IP Address %d.%d.%d.%d",
								TxPort,config_IP_BUC_ADDR0,config_IP_BUC_ADDR1,config_IP_BUC_ADDR2,config_IP_BUC_ADDR3);
		  }
		  pbuf_free(tx_update_pb);

	}

		else if(BUC_Sys_Self_Master_Flag==1)
		{
			  st_GUI_Updated_Buc_Self_Master.ID_BUC_SELF_MASTER = BUC_SELF_MASTER;
			  st_GUI_Updated_Buc_Self_Master.Updated_Buc_Self_Master = BUC_Sys_Self_Master_Value_counter;
			  tx_update_pb = pbuf_alloc(PBUF_TRANSPORT, sizeof(st_GUI_Updated_Buc_Self_Master), PBUF_RAM);
			  if(tx_update_pb == NULL)
			  {
				 return;
			   }
			  memcpy(tx_update_pb->payload,(const char*)&st_GUI_Updated_Buc_Self_Master,sizeof(GUI_Updated_Buc_Self_Master));
			  tx_update_pb->len = tx_update_pb->tot_len = sizeof(st_GUI_Updated_Buc_Self_Master);
			  error_code = udp_sendto(g_udpTxSocket,tx_update_pb, &dstaddr,TxPort);
			  if(error_code != ERR_OK )
			  {
				  PRINTF("\n\r Operator Updated GUI_Updated_Buc_Self_Master PKT on TxPort %d & IP Address %d.%d.%d.%d: Sending Failed",
											  TxPort,config_IP_BUC_ADDR0,config_IP_BUC_ADDR1,config_IP_BUC_ADDR2,config_IP_BUC_ADDR3);
			  }
			  else
			  {
					  //g_Tx_Updated_PktCnt++;
					  Update_Pkt_Sent_Flag++;
					  PRINTF("\n\r Operator Updated GUI_Updated_Buc_Self_Master PKT SENT on TxPort %d & IP Address %d.%d.%d.%d",
									TxPort,config_IP_BUC_ADDR0,config_IP_BUC_ADDR1,config_IP_BUC_ADDR2,config_IP_BUC_ADDR3);
			  }
			  pbuf_free(tx_update_pb);

		}

		else if(BUC_Sys_Reboot_Flag==1)
		{
			  st_GUI_Updated_Buc_Reboot.ID_BUC_REBOOT = BUC_REBOOT;

			  if(BUC_Sys_Reboot_Flag==1)
				    st_GUI_Updated_Buc_Reboot.Updated_Buc_Reboot			 =		BUC_Sys_Reboot_Value;
				else
					st_GUI_Updated_Buc_Reboot.Updated_Buc_Reboot			 =		0;

			  tx_update_pb = pbuf_alloc(PBUF_TRANSPORT, sizeof(st_GUI_Updated_Buc_Reboot), PBUF_RAM);
			  if(tx_update_pb == NULL)
			  {
				 return;
			   }
			  memcpy(tx_update_pb->payload,(const char*)&st_GUI_Updated_Buc_Reboot,sizeof(GUI_Updated_Buc_Reboot));
			  tx_update_pb->len = tx_update_pb->tot_len = sizeof(st_GUI_Updated_Buc_Reboot);
			  error_code = udp_sendto(g_udpTxSocket,tx_update_pb, &dstaddr,TxPort);
			  if(error_code != ERR_OK )
			  {
				  PRINTF("\n\r Operator Updated st_GUI_Updated_Buc_Reboot PKT on TxPort %d & IP Address %d.%d.%d.%d: Sending Failed",
											  TxPort,config_IP_BUC_ADDR0,config_IP_BUC_ADDR1,config_IP_BUC_ADDR2,config_IP_BUC_ADDR3);
			  }
			  else
			  {
					  //g_Tx_Updated_PktCnt++;
					  Update_Pkt_Sent_Flag++;
					  PRINTF("\n\r Operator Updated st_GUI_Updated_Buc_Reboot PKT SENT on TxPort %d & IP Address %d.%d.%d.%d",
									TxPort,config_IP_BUC_ADDR0,config_IP_BUC_ADDR1,config_IP_BUC_ADDR2,config_IP_BUC_ADDR3);
			  }
			  pbuf_free(tx_update_pb);

		}




//		if(Buc_ctrl_RF_attn_ctrl_save_flag==1)
//		{
//			int i=0;
//			for(i=0;i<=20;i++)
//			{
//				st_GUI_Updated_Parameters.Updated_BUC_ID[i]					 =		gui_BUC_Info_ID[i];
//			}


			if(BUC_Sys_Self_Master_Value_counter==1 && first_Sys_Master_Enable==0)
			{
				first_Sys_Master_Enable=1;
				st_GUI_Updated_Parameters.Updated_Rf_Mute_Ctrl			 	 = 		1;//1;
			}


}
void UDPSendPacket()
{
	int i;
	err_t error_code;
	//Parameter_UDP_Pkt_from_BUC_Received=0;
	Parameter_UDP_Pkt_from_BUC_Received=1;
	Parameter_UDP_Pkt_from_BUC_Stopped=1;

//	if(Ethernet_Link_Status==1)
//	{
//
//	    ethernetif_config_t enet_config = {
//	        .phyHandle  = &phyHandle,
//	        .macAddress = configMAC_ADDR,
//			#if defined(FSL_FEATURE_SOC_LPC_ENET_COUNT) && (FSL_FEATURE_SOC_LPC_ENET_COUNT > 0)
//					.non_dma_memory = non_dma_memory,
//			#endif /* FSL_FEATURE_SOC_LPC_ENET_COUNT */
//	    };
//
//		lwip_init();
//		netif_remove(&netif);
//		netif_add(&netif, &netif_ipaddr, &netif_netmask, &netif_gw, &enet_config, EXAMPLE_NETIF_INIT_FN, ethernet_input);
//		netif_set_default(&netif);
//		netif_set_up(&netif);
//		PRINTF("Ethernet_Link_Status=%d",Ethernet_Link_Status);
//	}
//	PRINTF("\n\r gui_HHT_IP_Addr1=%s",gui_HHT_IP_Addr1);
//	PRINTF("\n\r gui_HHT_Subnet_Addr1=%s",gui_HHT_Subnet_Addr1);
//	PRINTF("\n\r gui_HHT_Gateway_Addr1=%s",gui_HHT_Gateway_Addr1);
//	PRINTF("\n gui_update_Buc_net_IP_Addr=%s \t BUC_Net_Sett_Save_Flag=%d \t BUC_Net_Validate_Flag =%d",
//				BUC_Net_Sett_Save_Flag,BUC_Net_Validate_Flag,gui_update_Buc_net_IP_Addr);

	//PRINTF("\n\r ping_ok=%d",ping_ok);
//	if(BUC_Ping_Status==1)
//	{
//		PRINTF("\n\r PING STATUS PASS");
//	}
//	else
//		PRINTF("\n\r PING STATUS FAIL");
	//for(i=0;i<50;i++)
	//	    delay();
	if(BUC_Net_Validate_Flag==2)
	{
		PRINTF("\n\r gui_update_Buc_net_IP_Addr=%s",gui_update_Buc_net_IP_Addr);
		PRINTF("\n\r BUC IP ADDRESS UPDATED BY OPERATOR is NOT VALID");
		PRINTF("\n\r PLEASE UPDATE IP ADDR in format X.X.X.X, X value should be between 0-255");
		BUC_Net_Validate_Flag=0;
	}
	if(HHT_Net_Validate_Flag==2)
	{
		PRINTF("\n\r HHT IP ADDRESS UPDATED BY OPERATOR is NOT VALID");
		PRINTF("\n\r PLEASE UPDATE IP ADDR in format X.X.X.X, X value should be between 0-255");
		HHT_Net_Validate_Flag=0;
	}
//	BUC_Net_Validate_Flag=1;
//	PRINTF("\n gui_update_Buc_net_IP_Addr=%s \t BUC_Net_Sett_Save_Flag=%d \t BUC_Net_Validate_Flag =%d",
//			BUC_Net_Sett_Save_Flag,BUC_Net_Validate_Flag,gui_update_Buc_net_IP_Addr);
	//PRINTF("\n\r Main()::BUC Ping Status=%d",BUC_Ping_Status);
//	if(BUC_Sys_Self_Master_Value_counter%2==0)					{	BUC_Sys_Self_Master_Value=0;	}
//	else														{	BUC_Sys_Self_Master_Value=1;	}
//
//	if(Buc_ctrl_RF_Mute_switch_value_counter%2==0)				{	Buc_ctrl_RF_Mute_switch_value=1;	}
//	else														{	Buc_ctrl_RF_Mute_switch_value=0;	}
//
//	if(Buc_ctrl_Ext_10MHz_Ref_Src_switch_value_counter%2==0)	{	Buc_ctrl_Ext_10MHz_Ref_Src_switch_value=1;	}
//	else														{	Buc_ctrl_Ext_10MHz_Ref_Src_switch_value=0;	}

	if(HHT_Net_Sett_Save_Flag==1 && HHT_Net_Validate_Flag==1)
	{
	    ethernetif_config_t enet_config = {
	        .phyHandle  = &phyHandle,
	        .macAddress = configMAC_ADDR,};

		extractIP(gui_update_HHT_net_IP_Addr,&HHT_extract_ipAddr[0],4);							// 4 for HHT IP Addr extraction
		extractIP(gui_update_HHT_net_SubNet_Addr,&HHT_extract_SubNet_Addr[0],5);				// 5 for HHT Subnet Addr extraction
		extractIP(gui_update_HHT_net_gateway_Addr,&HHT_extract_Gateway_Addr[0],6);				// 6 for HHT Gate way Addr extraction
		IP4_ADDR(&netif_ipaddr, HHT_extract_ipAddr[0], HHT_extract_ipAddr[1], HHT_extract_ipAddr[2], HHT_extract_ipAddr[3]);
		IP4_ADDR(&netif_netmask, HHT_extract_SubNet_Addr[0], HHT_extract_SubNet_Addr[1], HHT_extract_SubNet_Addr[2], HHT_extract_SubNet_Addr[3]);
		IP4_ADDR(&netif_gw, HHT_extract_Gateway_Addr[0], HHT_extract_Gateway_Addr[1], HHT_extract_Gateway_Addr[2], HHT_extract_Gateway_Addr[3]);

		lwip_init();

		netif_remove(&netif);
//		for(i=0;i<50;i++)
//		    delay();
		netif_add(&netif, &netif_ipaddr, &netif_netmask, &netif_gw, &enet_config, EXAMPLE_NETIF_INIT_FN, ethernet_input);
		netif_set_default(&netif);
		netif_set_up(&netif);

		socket_init();

		//Assigning User updated IP Address
		configIP_ADDR0 	= HHT_extract_ipAddr[0];
		configIP_ADDR1 	= HHT_extract_ipAddr[1];
		configIP_ADDR2 	= HHT_extract_ipAddr[2];
		configIP_ADDR3 	= HHT_extract_ipAddr[3];

		configNET_MASK0 = HHT_extract_SubNet_Addr[0];
		configNET_MASK1 = HHT_extract_SubNet_Addr[1];
		configNET_MASK2 = HHT_extract_SubNet_Addr[2];
		configNET_MASK3 = HHT_extract_SubNet_Addr[3];

		configGW_ADDR0  = HHT_extract_Gateway_Addr[0];
		configGW_ADDR1  = HHT_extract_Gateway_Addr[1];
		configGW_ADDR2  = HHT_extract_Gateway_Addr[2];
		configGW_ADDR3  = HHT_extract_Gateway_Addr[3];

			PRINTF("\r\n************************************************\r\n");
		    PRINTF("************************************************\r\n");
		    PRINTF(" UPDATED IPv4 Address     : %u.%u.%u.%u\r\n", ((u8_t *)&netif_ipaddr)[0], ((u8_t *)&netif_ipaddr)[1],
		           ((u8_t *)&netif_ipaddr)[2], ((u8_t *)&netif_ipaddr)[3]);
		    PRINTF(" UPDATED IPv4 Subnet mask : %u.%u.%u.%u\r\n", ((u8_t *)&netif_netmask)[0], ((u8_t *)&netif_netmask)[1],
		           ((u8_t *)&netif_netmask)[2], ((u8_t *)&netif_netmask)[3]);
		    PRINTF(" UPDATED IPv4 Gateway     : %u.%u.%u.%u\r\n", ((u8_t *)&netif_gw)[0], ((u8_t *)&netif_gw)[1],
		           ((u8_t *)&netif_gw)[2], ((u8_t *)&netif_gw)[3]);
		    PRINTF("************************************************\r\n");

			HHT_Net_Sett_Save_Flag=0;
	}
	st_HHT_BUC_REQUEST.HHT_BUC_REQUEST_msg[0] 	= 'H';
	st_HHT_BUC_REQUEST.HHT_BUC_REQUEST_msg[1] 	= 'H';
	st_HHT_BUC_REQUEST.HHT_BUC_REQUEST_msg[2] 	= 'T';
	st_HHT_BUC_REQUEST.HHT_BUC_REQUEST_msg[3] 	= '-';
	st_HHT_BUC_REQUEST.HHT_BUC_REQUEST_msg[4] 	= 'B';
	st_HHT_BUC_REQUEST.HHT_BUC_REQUEST_msg[5] 	= 'U';
	st_HHT_BUC_REQUEST.HHT_BUC_REQUEST_msg[6] 	= 'C';
	st_HHT_BUC_REQUEST.HHT_BUC_REQUEST_msg[7] 	= '-';
	st_HHT_BUC_REQUEST.HHT_BUC_REQUEST_msg[8]	= 'R';
	st_HHT_BUC_REQUEST.HHT_BUC_REQUEST_msg[9] 	= 'E';
	st_HHT_BUC_REQUEST.HHT_BUC_REQUEST_msg[10] 	= 'Q';
	st_HHT_BUC_REQUEST.HHT_BUC_REQUEST_msg[11]	= 'U';
	st_HHT_BUC_REQUEST.HHT_BUC_REQUEST_msg[12] 	= 'E';
	st_HHT_BUC_REQUEST.HHT_BUC_REQUEST_msg[13] 	= 'S';
	st_HHT_BUC_REQUEST.HHT_BUC_REQUEST_msg[14] 	= 'T';

	if(HHT_Net_Sett_Save_Flag!=1)
	{
		snprintf(gui_HHT_IP_Addr1,10,"%d",configIP_ADDR0);
		snprintf(gui_HHT_IP_Addr2,10,"%d",configIP_ADDR1);
		snprintf(gui_HHT_IP_Addr3,10,"%d",configIP_ADDR2);
		snprintf(gui_HHT_IP_Addr4,10,"%d",configIP_ADDR3);

		strcat(gui_HHT_IP_Addr1,".");
		strcat(gui_HHT_IP_Addr1,gui_HHT_IP_Addr2);
		strcat(gui_HHT_IP_Addr1,".");
		strcat(gui_HHT_IP_Addr1,gui_HHT_IP_Addr3);
		strcat(gui_HHT_IP_Addr1,".");
		strcat(gui_HHT_IP_Addr1,gui_HHT_IP_Addr4);

		//HHT Subnet Address
		snprintf(gui_HHT_Subnet_Addr1,10,"%d",configNET_MASK0);
		snprintf(gui_HHT_Subnet_Addr2,10,"%d",configNET_MASK1);
		snprintf(gui_HHT_Subnet_Addr3,10,"%d",configNET_MASK2);
		snprintf(gui_HHT_Subnet_Addr4,10,"%d",configNET_MASK3);

		strcat(gui_HHT_Subnet_Addr1,".");
		strcat(gui_HHT_Subnet_Addr1,gui_HHT_Subnet_Addr2);
		strcat(gui_HHT_Subnet_Addr1,".");
		strcat(gui_HHT_Subnet_Addr1,gui_HHT_Subnet_Addr3);
		strcat(gui_HHT_Subnet_Addr1,".");
		strcat(gui_HHT_Subnet_Addr1,gui_HHT_Subnet_Addr4);

		//HHT Gateway Address
		snprintf(gui_HHT_Gateway_Addr1,10,"%d",configGW_ADDR0);
		snprintf(gui_HHT_Gateway_Addr2,10,"%d",configGW_ADDR1);
		snprintf(gui_HHT_Gateway_Addr3,10,"%d",configGW_ADDR2);
		snprintf(gui_HHT_Gateway_Addr4,10,"%d",configGW_ADDR3);

		strcat(gui_HHT_Gateway_Addr1,".");
		strcat(gui_HHT_Gateway_Addr1,gui_HHT_Gateway_Addr2);
		strcat(gui_HHT_Gateway_Addr1,".");
		strcat(gui_HHT_Gateway_Addr1,gui_HHT_Gateway_Addr3);
		strcat(gui_HHT_Gateway_Addr1,".");
		strcat(gui_HHT_Gateway_Addr1,gui_HHT_Gateway_Addr4);

	}
		//HHT IP ADDRESS
//		PRINTF("\n\r gui_HHT_IP_Addr1=%s",gui_HHT_IP_Addr1);
//		PRINTF("\n\r gui_HHT_Subnet_Addr1=%s",gui_HHT_Subnet_Addr1);
//		PRINTF("\n\r gui_HHT_Gateway_Addr1=%s",gui_HHT_Gateway_Addr1);
	//getDate_Time();

	//UDP_Pkt_Received=0;
	if(Update_Pkt_Sent_Flag==1)
	{
		Update_Pkt_Sent_Flag=0;
		BUC_Info_Buc_ID_Save_Flag					=0;
		Buc_ctrl_RF_attn_ctrl_save_flag				=0;
		Buc_ctrl_Ext_10MHz_Ref_Src_save_flag		=0;
		Buc_ctrl_RF_Mute_save_flag					=0;
		BUC_Status_Reset_GUI_Flag					=0;
		BUC_Status_Reset_GUI_Value					=1;
		BUC_Net_Sett_Save_Flag						=0;
		BUC_Sys_Self_Master_Flag					=0;
		BUC_Sys_Reboot_Value						=1;
		BUC_Sys_Reboot_Flag							=0;
		BUC_Sys_SaveConfig_Value					=1;
	}



	  //Buc_ctrl_RF_attn_ctrl_save_flag=1;
	  if	 (BUC_Info_Buc_ID_Save_Flag==1 || Buc_ctrl_RF_attn_ctrl_save_flag==1 || Buc_ctrl_Ext_10MHz_Ref_Src_save_flag==1 || Buc_ctrl_RF_Mute_save_flag==1 ||
			  BUC_Net_Sett_Save_Flag==1 || HHT_Net_Sett_Save_Flag==1 || BUC_Sys_Self_Master_Flag==1    || BUC_Sys_Reboot_Flag==1)
	  {
		  GUI_Updated_Transmit_Packet();
	  }
	  else
	  {
		  tx_pb = pbuf_alloc(PBUF_TRANSPORT, sizeof(st_HHT_BUC_REQUEST), PBUF_RAM);
		  if(tx_pb == NULL)
		  {
			 return;
		   }
		  memcpy(tx_pb->payload,(const char*)&st_HHT_BUC_REQUEST,sizeof(HHT_BUC_REQUEST));
		  tx_pb->len = tx_pb->tot_len = sizeof(st_HHT_BUC_REQUEST);
		  error_code = udp_sendto(g_udpTxSocket,tx_pb, &dstaddr,TxPort);
		  if(error_code != ERR_OK )
		  {
			  PRINTF("\n\r REQUEST to BUC PKT SENT on TxPort %d & IP Address %d.%d.%d.%d: Failed\n",
			 						  	  TxPort,config_IP_BUC_ADDR0,config_IP_BUC_ADDR1,config_IP_BUC_ADDR2,config_IP_BUC_ADDR3);
		  }
		  else
		  {
				  g_TxPktCnt++;
				  PRINTF("\n\r REQUEST to BUC PKT SENT on TxPort %d & IP Address %d.%d.%d.%d: g_TxPktCnt=%d\n",
						  	  TxPort,config_IP_BUC_ADDR0,config_IP_BUC_ADDR1,config_IP_BUC_ADDR2,config_IP_BUC_ADDR3,g_TxPktCnt);
		  }
	      pbuf_free(tx_pb);
	  }
      for(i=0;i<1000;i++)
   	   delay();
}



void
udpecho_raw_init(void)
{
  udpecho_raw_pcb = udp_new_ip_type(IPADDR_TYPE_ANY);
  if (udpecho_raw_pcb != NULL) {
    err_t err;

    err = udp_bind(udpecho_raw_pcb, IP_ANY_TYPE, TxPort);
    if (err == ERR_OK)
    {
    	PRINTF("NO ERROR\n");
      udp_recv(udpecho_raw_pcb, udp_recv_func, NULL);
    } else {
    	PRINTF("ERROR\n");
      /* abort? output diagnostic? */
    }
  } else {
    /* abort? output diagnostic? */
  }
}
void socket_init()
{
    IP4_ADDR(&dstaddr,config_IP_BUC_ADDR0,config_IP_BUC_ADDR1,config_IP_BUC_ADDR2,config_IP_BUC_ADDR3);
	g_udpTxSocket = udp_new();
    g_udpRxSocket = udp_new();

    udp_bind(g_udpRxSocket, IP_ADDR_ANY,RxPort);
    udp_recv(g_udpRxSocket, udp_recv_func, NULL);
}
/*!
 * @brief Main function.
 */
int main(void)
{

#if defined(FSL_FEATURE_SOC_LPC_ENET_COUNT) && (FSL_FEATURE_SOC_LPC_ENET_COUNT > 0)
    mem_range_t non_dma_memory[] = NON_DMA_MEMORY_ARRAY;
#endif /* FSL_FEATURE_SOC_LPC_ENET_COUNT */
    ethernetif_config_t enet_config = {
        .phyHandle  = &phyHandle,
        .macAddress = configMAC_ADDR,
#if defined(FSL_FEATURE_SOC_LPC_ENET_COUNT) && (FSL_FEATURE_SOC_LPC_ENET_COUNT > 0)
        .non_dma_memory = non_dma_memory,
#endif /* FSL_FEATURE_SOC_LPC_ENET_COUNT */
    };

    gpio_pin_config_t gpio_config = {kGPIO_DigitalOutput, 0, kGPIO_NoIntmode};

    BOARD_ConfigMPU();
    BOARD_InitBootPins();
    BOARD_InitBootClocks();
    BOARD_InitLcdifPixelClock();
    BOARD_InitDebugConsole();
    BOARD_InitModuleClock();
    BOARD_InitLcd();
    BOARD_InitGPT();

    //Clock setting for LPI2C Added for Battery on 13-Sep-2021
    	CLOCK_SetMux(kCLOCK_Lpi2cMux, LPI2C_CLOCK_SOURCE_SELECT);
    	CLOCK_SetDiv(kCLOCK_Lpi2cDiv, LPI2C_CLOCK_SOURCE_DIVIDER);




    IOMUXC_EnableMode(IOMUXC_GPR, kIOMUXC_GPR_ENET1TxClkOutputDir, true);

//    GPIO_PinInit(GPIO1, 9, &gpio_config);
//    GPIO_PinInit(GPIO1, 10, &gpio_config);
//    /* pull up the ENET_INT before RESET. */
//    GPIO_WritePinOutput(GPIO1, 10, 1);
//    GPIO_WritePinOutput(GPIO1, 9, 0);
//    delay();
//    GPIO_WritePinOutput(GPIO1, 9, 1);

    mdioHandle.resource.csrClock_Hz = EXAMPLE_CLOCK_FREQ;

    time_init();

    IP4_ADDR(&netif_ipaddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3);
    IP4_ADDR(&netif_netmask, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3);
    IP4_ADDR(&netif_gw, configGW_ADDR0, configGW_ADDR1, configGW_ADDR2, configGW_ADDR3);

    lwip_init();

    netif_add(&netif, &netif_ipaddr, &netif_netmask, &netif_gw, &enet_config, EXAMPLE_NETIF_INIT_FN, ethernet_input);
    netif_set_default(&netif);
    netif_set_up(&netif);

    PRINTF("\r\n************************************************\r\n");
    PRINTF(" Hand Held Controller for BUC\r\n");
    PRINTF("************************************************\r\n");
    PRINTF(" IPv4 Address     : %u.%u.%u.%u\r\n", ((u8_t *)&netif_ipaddr)[0], ((u8_t *)&netif_ipaddr)[1],
           ((u8_t *)&netif_ipaddr)[2], ((u8_t *)&netif_ipaddr)[3]);
    PRINTF(" IPv4 Subnet mask : %u.%u.%u.%u\r\n", ((u8_t *)&netif_netmask)[0], ((u8_t *)&netif_netmask)[1],
           ((u8_t *)&netif_netmask)[2], ((u8_t *)&netif_netmask)[3]);
    PRINTF(" IPv4 Gateway     : %u.%u.%u.%u\r\n", ((u8_t *)&netif_gw)[0], ((u8_t *)&netif_gw)[1],
           ((u8_t *)&netif_gw)[2], ((u8_t *)&netif_gw)[3]);
    PRINTF("************************************************\r\n");

    socket_init();

   // ping_init(&dstaddr);
    PRINTF("\n\r Ethernet_Link_Status=%d",Ethernet_Link_Status);
    if(Ethernet_Link_Status==2)
    {
    	PRINTF("\n\r Ethernet Link is UP");
    }
    if(Ethernet_Link_Status==1)
    	PRINTF("\n\r Ethernet Link is DOWN");

    PRINTF("\n\r int Ethernet_Link_Status=%d",Ethernet_Link_Status);

    //FLASH PROGRAM START

    uint32_t i = 0;
    status_t status;
    uint8_t vendorID = 0;

    flexspi_nor_flash_init(EXAMPLE_FLEXSPI);

	PRINTF("\r\nFLEXSPI example started!\r\n");

	 /* Get vendor ID. */
	 status = flexspi_nor_get_vendor_id(EXAMPLE_FLEXSPI, &vendorID);
	 if (status != kStatus_Success)
	 {
		 return status;
	 }
	 PRINTF("Vendor ID: 0x%x\r\n", vendorID);
	#if !(defined(XIP_EXTERNAL_FLASH))
	/* Erase whole chip . */
	PRINTF("Erasing whole chip over FlexSPI...\r\n");

	status = flexspi_nor_erase_chip(EXAMPLE_FLEXSPI);
	if (status != kStatus_Success)
	{
	return status;
	}
	PRINTF("Erase finished !\r\n");

	#endif
#if 1
        int count=0;
        while(1)
        {
        	count++;
        	PRINTF("\n\r count=%d",count);
        	/* Enter quad mode. */
            status = flexspi_nor_enable_quad_mode(EXAMPLE_FLEXSPI);
            if (status != kStatus_Success)
            {
                return status;
            }

            /* Erase sectors. */
            PRINTF("Erasing Serial NOR over FlexSPI...\r\n");
            status = flexspi_nor_flash_erase_sector(EXAMPLE_FLEXSPI, EXAMPLE_SECTOR * SECTOR_SIZE);
            if (status != kStatus_Success)
            {
                PRINTF("Erase sector failure !\r\n");
                return -1;
            }


            memset(s_nor_program_buffer, 0xFFU, sizeof(s_nor_program_buffer));

            DCACHE_InvalidateByRange(EXAMPLE_FLEXSPI_AMBA_BASE + EXAMPLE_SECTOR * SECTOR_SIZE, FLASH_PAGE_SIZE);

            memcpy(s_nor_read_buffer, (void *)(EXAMPLE_FLEXSPI_AMBA_BASE + EXAMPLE_SECTOR * SECTOR_SIZE),
                   sizeof(s_nor_read_buffer));

            if (memcmp(s_nor_program_buffer, s_nor_read_buffer, sizeof(s_nor_program_buffer)))
            {
                PRINTF("Erase data -  read out data value incorrect !\r\n ");
                return -1;
            }
            else
            {
                PRINTF("Erase data - successfully. \r\n");
            }

            uint8_t sample_buffer[256] = "EVEN Time EVEN Time EVEN Time";


            for (i = 0; i < 0xFFU; i++)
            {
            	if(count%2==0)
    			{
    				uint8_t sample_buffer[256] = "EVEN Time EVEN Time EVEN Time";
    				 s_nor_program_buffer[i] = sample_buffer[i];
    			}
    			if(count%2==1)
    			{
    				uint8_t sample_buffer[256] = "ODD Time ODD Time ODD Time ODD Time";
    				 s_nor_program_buffer[i] = sample_buffer[i];
    			}
    			if(count%3==1)
    			{
    				uint8_t sample_buffer[256] = "DEVIDED BY THREE DEVIDED BY THREE";
    				s_nor_program_buffer[i] = sample_buffer[i];
    			}


            }
            PRINTF("\n-------------- Contents of s_nor_program_buffer Before Writing into from Flash Memory---------\n");
            for (i = 0; i < 0xFFU; i++)
            {

            	PRINTF("%c",s_nor_program_buffer[i]);
            }


            status =
                flexspi_nor_flash_page_program(EXAMPLE_FLEXSPI, EXAMPLE_SECTOR * SECTOR_SIZE, (void *)s_nor_program_buffer);
            if (status != kStatus_Success)
            {
                PRINTF("Page program failure !\r\n");
                return -1;
            }
            else
            {
               	PRINTF("Page program Success !\r\n");
            }

            DCACHE_InvalidateByRange(EXAMPLE_FLEXSPI_AMBA_BASE + EXAMPLE_SECTOR * SECTOR_SIZE, FLASH_PAGE_SIZE);

            memcpy(s_nor_read_buffer, (void *)(EXAMPLE_FLEXSPI_AMBA_BASE + EXAMPLE_SECTOR * SECTOR_SIZE),
                   sizeof(s_nor_read_buffer));


            PRINTF("\n-------------- Contents of s_nor_read_buffer After Reading from Flash Memory---------\n");
            for (i = 0; i < 0xFFU; i++)
            {
                    PRINTF("%c",s_nor_read_buffer[i]);
            }
            PRINTF("\n");


            if (memcmp(s_nor_read_buffer, s_nor_program_buffer, sizeof(s_nor_program_buffer)) != 0)
            {
                PRINTF("Program data -  read out data value incorrect !\r\n ");
                return -1;
            }
            else
            {
                PRINTF("Program data - successfully. \r\n");
            }

        }

        //FLASH PROGRAM END
#endif
           //Flash_Data_Parsing_OnBoot();
    while (1)
    {

        /* Poll the driver, get any outstanding frames */
    	//if(UDPPktTimerCount==400)
    	//UDPSendPacket();
        //ethernetif_input(&netif);

        //UDPPktTimerCount++;
    	//MainTask();
    	//PRINTF("TTE Reg = 0x%04x\n",fuelGaugeresults.TTE);							//Added for Battery on 13-Sep-2021
       // sys_check_timeouts(); /* Handle all system timeouts for all core protocols */
    }
}
#endif
