/**
 * \file eip_main.h
 * \brief Ethernetip Application related header file
 *
 * \copyright Copyright (c) 2012 Texas Instruments Incorporated ALL RIGHTS RESERVED
 *
*/
#ifndef EIP_MAIN_H_
#define EIP_MAIN_H_

#include <xdc/std.h>
#include "plat_utils.h"
#include "app_api.h"
#include "hal.h"
#include "device.h"
#include "eip_utils.h"
#include "app_restart.h"
#include "user_acd_ndk.h"

/**Escape Key ASCI*/
#define ESC_KEY		0x1b

#define ENTER_KEY		0x0D

#define BSPACE_KEY		0x08

/**Major Revision NUmber*/
#define APP_REVISION_MAJOR  3
/**Minor Revision NUmber*/
#define APP_REVISION_MINOR  1
/**IP where Molex EIP Trace application is runing*/
#define REMOTE_IP_EIPTRACES        0xC0A80108
/**Spiflash offset to store Device ip*/
#define SPI_EEPROM_DEVICEIP_OFFSET 0xb0000
/**Spiflash offset to store Interface speed*/
#define SPI_EEPROM_SPEED_OFFSET    0xb1000

#define SPI_EEPROM_ACD_CONFLICT_OFFSET  0xb2000

#define SPI_EEPROM_ACD_OFFSET  0xb3000

#define SPI_EEPROM_QOS_OFFSET    0xb4000

#define EIP_STARTUP_DHCP      2
#define EIP_STARTUP_STATICIP  0

#define EIP_ACD_DEFAULT  0
#define EIP_ACD_START  1
#define EIP_ACD_RESTART  2
#define EIP_ACD_STOP  3
/**
 *  \name ErasePermanentMemory
 *  \brief The function erases data from spiflash
 */
EIP_BOOL ErasePermanentMemory(unsigned int offSet);
/**
 *  \name ReadPermanentMemory
 *  \brief The function read data from spiflash
 */
EIP_BOOL ReadPermanentMemory(EIP_BYTE *varBuff,unsigned int size, unsigned int offSet );
/**
 *  \name WritePermanentMemory
 *  \brief The function writes the object attributes to spiflash
 */
EIP_BOOL WritePermanentMemory(EIP_BYTE* varBuff, unsigned int size,unsigned int offSet );
/**
 *  \name SetInterfaceSpeed
 *  \brief The function calls ndk driver ioctl to force the Interface properties
 */
EIP_VOID SetInterfaceSpeed(ST_ETH_CONTROL * pstEthControl);

/**Variable informs the IP Assign status*/
extern Uint8 finish_assign_ip;
/**Index used for getting input from Uart*/
extern int counter;
/**Flag to indicate uart input is finished*/
extern int flagFinish;
/**Ip Address used by the device*/
extern EIP_DWORD gdwIPAddress;
/**Ip mask used by the device*/
extern EIP_DWORD gdwMask;
extern DWORD ifConnfigACDStat;
extern Uint8 user_input_processing;

extern Char rxByte;

extern Semaphore_Handle SPIReadSemaphoreHandle;

extern unsigned char board_Type;
/**
 * \brief IO Data Connection Parameters
 */
typedef struct
{
/**Data size of IN data*/
	EIP_WORD wSizeIn;
/**Offset to get IN data*/
	EIP_WORD wOffsetIn;
/**Data size of Out data*/
	EIP_WORD wSizeOut;
/**Offset to get Out data*/
	EIP_WORD wOffsetOut;
}ST_CNXN_PARAMS;

typedef struct
{
	EIP_DWORD deviceIP;
	EIP_BOOL startupType;
	EIP_DWORD networkMask;
	EIP_DWORD gatewayAddress;
	EIP_DWORD serverName;
}EPROM_TCPIP;


typedef struct
{
	EPROM_TCPIP tcpipConfig;
	ST_ETH_CONTROL ethConfig[2];
	EIP_BOOL acdEnable;
	EIP_BOOL qosEnable;
	CLASS_TCP_LAST_CONFLICT_DETECTED acdConflictDetails;
}DEVICE_INIT_CONFIG;

extern ST_TCPIP_CONFIGURATION eipDevInterfaceConfig;
extern DEVICE_INIT_CONFIG eipDevInitConfig;
extern EPROM_TCPIP tcpControl;
extern unsigned int acdEIPStatus;

int EIPMain ();
void UartIsr(UArg arg);
void ConfigureDhcpClient();
void DHCPUartPrint();
EIP_BOOL EIPACDInit();
EIP_VOID EIPACDExit();
EIP_VOID EIPACDStart();
EIP_VOID EIPACDStop();
EIP_VOID EIPIPAddressChange(Uint32 ipAddress,Uint32 ipAddAssign);

#endif /* EIP_MAIN_H_ */
