
#ifndef REMOVE_MC_TEST
#include "ucps2.h"
#include "ucp2_utils.h"
#include <LDPCEnCoding.h>


_DM0 int BG1HMatrix[] = {
  #include "CalBG1HMatrix.dat"
};

_DM0 int BG2HMatrix[] = {
  #include "CalBG2HMatrix.dat"
};

_DM5 int InputData[] = {
  #include <TestLDPCEnCodingInput.dat>
};

_DM4 int Temp0[1088] = {0};//byte Data size: max = 64 * 22 byte + 64 * 46 byte
_DM1 int PreOutputAddr0[139] = {0};//384 H_PreOut Part1
_DM2 int PreOutputAddr1[135] = {0};//384 H_PreOut Part2
_DM1 int Temp1[70] = {0};//64 H_PreOut Part1
_DM2 int Temp2[70] = {0};//64 H_PreOut Part2


_DM3 int Config64BG1[] = {
  #include "Config64BG1.dat"
};
_DM3 int Config64BG2[] = {
  #include "Config64BG2.dat"
};
_DM3 int Config384Pre[] = {
  #include "Config384Pre.dat"
};
_DM3 int Config384BG1[] = {
  #include "Config384BG1.dat"
};
_DM3 int Config384BG2[] = {
  #include "Config384BG2.dat"
};

v16u32 KI = {2,4,6};

_DM3 v16s32 SVRReg  = {
		0, 0, 0, 0,
		0x40, 0, 0, 0,
		0xff00ff, 0, 0, 0x0000,
		0xffff, 0x6, 0, 0
};

int main()
{
	volatile int a = 1;
	int Basegraph = 1;
	int ZcLen = 384;
	int index =0;

	if(ZcLen==2 ||ZcLen==4 ||ZcLen==8||ZcLen==16||ZcLen==32||ZcLen==64||ZcLen==128||ZcLen==256)
		index = 0;
	else if(ZcLen==3||ZcLen==6||ZcLen==12||ZcLen==24||ZcLen==48||ZcLen==96||ZcLen==192||ZcLen==384)
		index=1;
	else if(ZcLen==5||ZcLen==10||ZcLen==20||ZcLen==40||ZcLen==80||ZcLen==160||ZcLen==320)
		index=2;
	else if(ZcLen==7||ZcLen==14||ZcLen==28||ZcLen==56||ZcLen==112||ZcLen==224)
		index=3;
	else if(ZcLen==9||ZcLen==18||ZcLen==36||ZcLen==72||ZcLen==144||ZcLen==288)
		index=4;
	else if(ZcLen==11||ZcLen==22||ZcLen==44||ZcLen==88||ZcLen==176||ZcLen==352)
		index=5;
	else if(ZcLen==13||ZcLen==26||ZcLen==52||ZcLen==104||ZcLen==208)
		index=6;
	else if(ZcLen==15||ZcLen==30||ZcLen==60||ZcLen==120||ZcLen==240)
		index=7;

	if (Basegraph == 1) {//BG1
		if(ZcLen < 64) {
			Ldpc64BG1(Config64BG1, MPU_ADDR(InputData), ZcLen, MPU_ADDR(BG1HMatrix)+index*274*2, MPU_ADDR(Temp0), MPU_ADDR(Temp1), MPU_ADDR(Temp2));
			SVRReg[0] = MPU_ADDR(Config64BG1);
			LDPCEnCoding64BG1Asm(SVRReg);
			a = __ucps2_getStatB();
			__ucps2_delay();

		} else {
			Ldpc384Pre(Config384Pre, MPU_ADDR(BG1HMatrix)+index*274*2, ZcLen, Basegraph, MPU_ADDR(PreOutputAddr0), MPU_ADDR(PreOutputAddr1));
			SVRReg[0] = MPU_ADDR(Config384Pre);
			LDPCEnCoding384PreAsm(SVRReg);
			a = __ucps2_getStatB();
			__ucps2_delay();

			Ldpc384BG1(Config384BG1, MPU_ADDR(InputData), MPU_ADDR(PreOutputAddr0), MPU_ADDR(PreOutputAddr1), ZcLen);
			SVRReg[0] = MPU_ADDR(Config384BG1);
			LDPCEnCoding384BG1Asm(SVRReg);
			a = __ucps2_getStatB();
			__ucps2_delay();
		}
	} else {//BG2
		if(ZcLen < 64) {
			Ldpc64BG2(Config64BG2, MPU_ADDR(InputData), ZcLen, MPU_ADDR(BG2HMatrix)+index*150*2, MPU_ADDR(Temp0), MPU_ADDR(Temp1), MPU_ADDR(Temp2));
			SVRReg[0] = MPU_ADDR(Config64BG2);
			LDPCEnCoding64BG2Asm(SVRReg);
			a = __ucps2_getStatB();
			__ucps2_delay();

		} else {
			Ldpc384Pre(Config384Pre, MPU_ADDR(BG2HMatrix)+index*150*2, ZcLen, Basegraph, MPU_ADDR(PreOutputAddr0), MPU_ADDR(PreOutputAddr1));
			SVRReg[0] = MPU_ADDR(Config384Pre);
			LDPCEnCoding384PreAsm(SVRReg);
			a = __ucps2_getStatB();
			__ucps2_delay();

			Ldpc384BG2(Config384BG2, MPU_ADDR(InputData), MPU_ADDR(PreOutputAddr0), MPU_ADDR(PreOutputAddr1), ZcLen);
			SVRReg[0] = MPU_ADDR(Config384BG2);
			LDPCEnCoding384BG2Asm(SVRReg);
			a = __ucps2_getStatB();
			__ucps2_delay();

		}
	}

	return 0;
}

#endif //DEBUG_MC
