#include "p_apps.h"
#include "p_h323.h"

#include "flash.h"

#ifdef SYS_AUVTECH
#include "auvtech.h"
#endif

void LoadIvr();
void LoadDtmfData();

void main(void)
{
	DCHAR iServiceType;

	BootIndication(10);
	Led_Off(NORMAL_LIGHT);
	
	LoadIvr();
	LoadDtmfData();
	LoadFlags();
	LoadStrings();
	MapLoadMsg();
	SdramLoadData(UPGRADE_Code, PAGE128_SDRAM_POS, UPGRADE_CODE_SIZE);

#ifdef GUI_HTTP
	HttpLoadMsg();
#endif

#ifdef CALL_H323
	H323LoadMsgs();
#endif

	SdramReadOptions();
	iServiceType = X_VAL(Sdram_pDataCache, OPTIONS_SERVICE_TYPE);

#ifdef SYS_AUVTECH
	if (iServiceType == H323_SERVICE_TYPE_AUVTECH || iServiceType == H323_SERVICE_TYPE_SOYO)
	{
		p_memcpy_mac(Local_pMacAddress, (PXCHAR)(Sdram_pDataCache+OPTIONS_MAC_ADDR));
		AuvtechMacEncrypt();
	}
#endif

	Led_On(NORMAL_LIGHT);
	BootIndication(11);

#if defined GUI_WEB 
	SwitchPage(14);		// continue to load extra ivr, web
#elif defined MT28F016
	SwitchPage(30);		// load ring
#elif defined MX29LV008B
	SwitchPage(11);		// load ring
#else
	SwitchPage(4);	// main loop in page4-5
#endif

	// to avoid warning
	IsFunctionMode();
	Led_Blink(NORMAL_LIGHT);
	p_getAsciiKey(0);
	p_IsNewLine((PXCHAR)0);
	p_IP2String((PXCHAR)0, (PXCHAR)0);
	p_Mac2String((PXCHAR)0, (PXCHAR)0);
	p_memcmp_ip((PXCHAR)0, (PXCHAR)0);
#ifndef SYS_AUVTECH
	p_memcpy_mac(Local_pMacAddress, (PXCHAR)(Sdram_pDataCache+OPTIONS_MAC_ADDR));
#endif
	p_memset_ip_0((PXCHAR)0);
	p_String2IP((PXCHAR)0, (PXCHAR)0);
	p_String2Mac((PXCHAR)0, (PXCHAR)0);
	SdramClearDataCache();
	SdramCopyData(0, (PXCHAR)0);
	SdramCopyData_0(0, (PXCHAR)0);
	SdramCopyEthernetFrame(0, (PXCHAR)0, 0);
	SdramSaveEthernetFrame(0, (PXCHAR)0, 0);
	SdramSaveData(0, (PXCHAR)0, 0);
	SdramWriteOptions();
	SdramUpdateFlagByte(0, 0);
}

