#include "p_apps.h"

#define __LOAD_SDRAM

#include "dsp\ILBCMAIN.h"

#include "dsp\ILBCENIN.h"
#include "dsp\ILBCEnc1.h"
#include "dsp\ILBCEnc2.h"
#include "dsp\ILBCEnc3.h"
#include "dsp\ILBCEnc4.h"
#include "dsp\ILBCEnc5.h"
#include "dsp\ILBCEnc6.h"

#include "dsp\ILBCDEIN.h"
#include "dsp\ILBCDec1.h"
#include "dsp\ILBCDec2.h"
#include "dsp\ILBCDec3.h"
#include "dsp\ILBCDec4.h"
#include "dsp\ILBCDec5.h"
#include "dsp\ILBCDec6.h"

#include "dsp\iLBCEncTbl.h"
#include "dsp\iLBCDecTbl.h"

#include "dsp\GSM.H"
#include "dsp\GSMENC.H"
#include "dsp\GSMDEC.H"
#include "dsp\GSMDATA.h"

#include "dsp\G711.h"
#include "dsp\PCM.h"
#include "dsp\G711CNG.h"
#include "dsp\G711PLC.h"

void LoadMiscDsp();

void main(void)
{
	BootIndication(6);
	Led_Off(NORMAL_LIGHT);

	sdram_read(SDRAM_CHECK_HI, SDRAM_CHECK_LO, SRAM_DMA_HALF_DWORD);
	if (XBYTE[Sdram_pDataCache+SDRAM_CHECK_POS] & SDRAM_CHECK_ILBC_OK)	goto End;

	SdramLoadCompressedCode(ILBCMAIN_CODE, 0x1500, ILBCMAIN_COMPRESSED_SIZE);

	SdramLoadCompressedCode(ILBCENIN_CODE, 0x1510, ILBCENIN_COMPRESSED_SIZE);
	SdramLoadCompressedCode(ILBCENC1_CODE, 0x1520, ILBCENC1_COMPRESSED_SIZE);
	SdramLoadCompressedCode(ILBCENC2_CODE, 0x1530, ILBCENC2_COMPRESSED_SIZE);
	SdramLoadCompressedCode(ILBCENC3_CODE, 0x1540, ILBCENC3_COMPRESSED_SIZE);
	SdramLoadCompressedCode(ILBCENC4_CODE, 0x1550, ILBCENC4_COMPRESSED_SIZE);
	SdramLoadCompressedCode(ILBCENC5_CODE, 0x1560, ILBCENC5_COMPRESSED_SIZE);
	SdramLoadCompressedCode(ILBCENC6_CODE, 0x1570, ILBCENC6_COMPRESSED_SIZE);

	SdramLoadCompressedCode(ILBCDEIN_CODE, 0x1580, ILBCDEIN_COMPRESSED_SIZE);
	SdramLoadCompressedCode(ILBCDEC1_CODE, 0x1590, ILBCDEC1_COMPRESSED_SIZE);
	SdramLoadCompressedCode(ILBCDEC2_CODE, 0x15a0, ILBCDEC2_COMPRESSED_SIZE);
	SdramLoadCompressedCode(ILBCDEC3_CODE, 0x15b0, ILBCDEC3_COMPRESSED_SIZE);
	SdramLoadCompressedCode(ILBCDEC4_CODE, 0x15c0, ILBCDEC4_COMPRESSED_SIZE);
	SdramLoadCompressedCode(ILBCDEC5_CODE, 0x15d0, ILBCDEC5_COMPRESSED_SIZE);
	SdramLoadCompressedCode(ILBCDEC6_CODE, 0x15e0, ILBCDEC6_COMPRESSED_SIZE);

	SdramLoadData((PCCHAR)iLBCEnc_Table, 0x0700, iLBCENCTBL_SIZE*2);
	SdramLoadData((PCCHAR)iLBCDec_Table, 0x0715, iLBCDECTBL_SIZE*2);

	SdramLoadCompressedCode(GSM_CODE, 0x0500+GSM_SDRAM_LO, GSM_COMPRESSED_SIZE);
	SdramLoadCompressedCode(GSMENC_CODE, 0x0500+GSMENC_SDRAM_LO, GSMENC_COMPRESSED_SIZE);
	SdramLoadCompressedCode(GSMDEC_CODE, 0x0500+GSMDEC_SDRAM_LO, GSMDEC_COMPRESSED_SIZE);
	SdramLoadData((PCCHAR)GSM_DATA, 0x0500+GSM_DATA_SDRAM_LO, GSM_DATA_SIZE*2);		

	SdramLoadCompressedCode(G711_CODE, 0x0500+G711_SDRAM_LO, G711_COMPRESSED_SIZE);
	SdramLoadCompressedCode(PCM_CODE, 0x0500+PCM_SDRAM_LO, PCM_COMPRESSED_SIZE);			
	SdramLoadCompressedCode(G711CNG_CODE, 0x0500+G711_CNG_SDRAM_LO, G711CNG_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G711PLC_CODE, 0x0500+G711_PLC_SDRAM_LO, G711PLC_COMPRESSED_SIZE);

	LoadMiscDsp();

End:
	Led_On(NORMAL_LIGHT);
	BootIndication(7);

#ifdef AUTO_PROVISIONING
	SwitchPage(13);	// continue to do auto provisioning
#else
	SwitchPage(6);	// continue to load g.729
#endif

	// to avoid warning
	Led_Blink(Sys_cFlags[0]);
}
