#include "p_apps.h"

#define __LOAD_SDRAM

#include "dsp\G723Main.h"
#include "dsp\G723Init.h"
#include "dsp\G723Enc1.h"
#include "dsp\G723Enc2.h"
#include "dsp\G723Enc3.h"
#include "dsp\G723Enc4.h"
#include "dsp\G723Enc5.h"
#include "dsp\G723Enc6.h"
#include "dsp\G723Enc7.h"
#include "dsp\G723Enc8.h"
#include "dsp\G723Enc9.h"
#include "dsp\G723En10.h"
#include "dsp\G723En11.h"
#include "dsp\G723En12.h"
#include "dsp\G723En13.h"
#include "dsp\G723En14.h"

#include "dsp\G723Dec1.h"
#include "dsp\G723Dec2.h"
#include "dsp\G723Dec3.h"
#include "dsp\G723Dec4.h"
#include "dsp\G723Dec5.h"
#include "dsp\G723Dec6.h"
#include "dsp\G723Dec7.h"

#include "dsp\Epg1tab.h"
#include "dsp\Epg2tab.h"
#include "dsp\band0tb8.h"
#include "dsp\band1tb8.h"
#include "dsp\band2tb8.h"
#include "dsp\Epg3tab.h"
#include "dsp\Epg4tab.h"
#include "dsp\Epg5tab.h"
#include "dsp\acbk085.h"
#include "dsp\acbk170.h"
#include "dsp\Epg7tab.h"
#include "dsp\Epg11tab.h"
#include "dsp\Epg12tab.h"
#include "dsp\Epg13tab.h"
#include "dsp\Epg14tab.h"
#include "dsp\dpg1tab.h"
#include "dsp\dpg4tab.h"
#include "dsp\dpg5tab.h"
//#include "dsp\combin.h"
//#include "dsp\dpg7tab.h"

void main(void)
{
#if defined AM29F040 || defined MT28F016
	BootIndication(2);
	BootIndication(3);
#endif
	BootIndication(4);

	Led_On(SECOND_LIGHT);

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

	SdramLoadCompressedCode(G723MAIN_CODE, 0x0800, G723MAIN_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G723INIT_CODE, 0x0810, G723INIT_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G723ENC1_CODE, 0x0820, G723ENC1_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G723ENC2_CODE, 0x0830, G723ENC2_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G723ENC3_CODE, 0x0840, G723ENC3_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G723ENC4_CODE, 0x0850, G723ENC4_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G723ENC5_CODE, 0x0860, G723ENC5_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G723ENC6_CODE, 0x0870, G723ENC6_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G723ENC7_CODE, 0x0880, G723ENC7_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G723ENC8_CODE, 0x0890, G723ENC8_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G723ENC9_CODE, 0x08a0, G723ENC9_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G723EN10_CODE, 0x08b0, G723EN10_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G723EN11_CODE, 0x08c0, G723EN11_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G723EN12_CODE, 0x08d0, G723EN12_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G723EN13_CODE, 0x08e0, G723EN13_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G723EN14_CODE, 0x08f0, G723EN14_COMPRESSED_SIZE);

	SdramLoadCompressedCode(G723DEC1_CODE, 0x0900, G723DEC1_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G723DEC2_CODE, 0x0910, G723DEC2_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G723DEC3_CODE, 0x0920, G723DEC3_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G723DEC4_CODE, 0x0930, G723DEC4_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G723DEC5_CODE, 0x0940, G723DEC5_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G723DEC6_CODE, 0x0950, G723DEC6_COMPRESSED_SIZE);
	SdramLoadCompressedCode(G723DEC7_CODE, 0x0960, G723DEC7_COMPRESSED_SIZE);

	SdramLoadData((PCCHAR)G723_ENC_TABLE1, 0x0980, G723_ENC_TABLE1_SIZE*2);
	SdramLoadData((PCCHAR)G723_ENC_TABLE2, 0x0986, G723_ENC_TABLE2_SIZE*2);
	SdramLoadData((PCCHAR)G723_band0tb8, 0x0987, G723_band0tb8_SIZE*2);
	SdramLoadData((PCCHAR)G723_band1tb8, 0x098d, G723_band1tb8_SIZE*2);
	SdramLoadData((PCCHAR)G723_band2tb8, 0x0993, G723_band2tb8_SIZE*2);
	SdramLoadData((PCCHAR)G723_ENC_TABLE3, 0x099b, G723_ENC_TABLE3_SIZE*2);
	SdramLoadData((PCCHAR)G723_ENC_TABLE4, 0x099c, G723_ENC_TABLE4_SIZE*2);
	SdramLoadData((PCCHAR)G723_ENC_TABLE5, 0x09a1, G723_ENC_TABLE5_SIZE*2);

	SdramLoadData((PCCHAR)G723_acbk085, 0x09a2, G723_acbk085_SIZE*2);
	SdramLoadData((PCCHAR)G723_acbk170, 0x09b2, G723_acbk170_SIZE*2);

	SdramLoadData((PCCHAR)G723_ENC_TABLE7, 0x09d2, G723_ENC_TABLE7_SIZE*2);
	SdramLoadData((PCCHAR)G723_ENC_TABLE11, 0x09d5, G723_ENC_TABLE11_SIZE*2);
	SdramLoadData((PCCHAR)G723_ENC_TABLE12, 0x09d9, G723_ENC_TABLE12_SIZE*2);
	SdramLoadData((PCCHAR)G723_ENC_TABLE13, 0x09dc, G723_ENC_TABLE13_SIZE*2);
	SdramLoadData((PCCHAR)G723_ENC_TABLE14, 0x09dd, G723_ENC_TABLE14_SIZE*2);
	SdramLoadData((PCCHAR)G723_DEC_TABLE1, 0x09df, G723_DEC_TABLE1_SIZE*2);
	SdramLoadData((PCCHAR)G723_DEC_TABLE4, 0x09e0, G723_DEC_TABLE4_SIZE*2);
	SdramLoadData((PCCHAR)G723_DEC_TABLE5, 0x09e1, G723_DEC_TABLE5_SIZE*2);
//	SdramLoadData((PCCHAR)G723_combinatorialtable, 0x09e2, G723_combinatorialtable_SIZE*2);
//	SdramLoadData((PCCHAR)G723_DEC_TABLE7, 0x09e5, G723_DEC_TABLE7_SIZE*2);

	// Continue init ne2000 here because it need "sleep" between step1, 2, 3
	// Need about 1 second from Step1 to Step2
	Ne2000Initialize_Step2();

End:
	Led_Off(SECOND_LIGHT);
	BootIndication(5);

	SwitchPage(3);	// continue to load iLBC

	// to avoid warning
	Led_Blink(SECOND_LIGHT);
}
