
#ifndef REMOVE_MC_TEST

#include "ucp2.h"
#include "ucp2_utils.h"
#include <Transform.h>
#include <stdlib.h>
#define IDE_TEST 1

__DM0 int InputData[] = {
  //#include <Input_mod.dat>
	#include <Input_0.dat>
};
__DM0 int PilotData[] = {
	#include <Input_pilot.dat>
};
#ifdef IDE_TEST
__DM4 int TransTemp[4096*14] = {0};
__DM2 int OutData[4096*14]={};
__DM3 int DeTrans[4096*14]={};
#endif

__DM2 int PilotTrans[1024]={};
__DM3 int PilotDeTrans[1024]={};

__DM4 int RowIn[4096*2] = {};
__DM1 int RowOut[4096*2] = {};
__DM2 int ColIn[14*512] = {};
__DM1 int ColOut[14*512] = {};

//now for data transform:
//inputdata size is 2*4096
//tempdata size is 2*4096
//outdata size is 2*4096
//symbol transform one loop can process 14*512 point data
//data transform one loop can process 2*4096 point data

//for pilot transform
//inputdata size is 1*1024
//outputdata size is 1*1024
//one loop can process output

__DM3 int Config_2[] = {
 #include <TransformConfig_2.dat>
};
__DM3 int DeTransConfig_2[] = {
 #include <DeTransformConfig_2.dat>
};

__DM3 int Config_4[] = {
 #include <TransformConfig_4.dat>
};
__DM3 int DeTransConfig_4[] = {
 #include <DeTransformConfig_4.dat>
};
__DM3 int Config_8[] = {
 #include <TransformConfig_8.dat>
};
__DM3 int DeTransConfig_8[] = {
 #include <DeTransformConfig_8.dat>
};


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

int main(void)
{
  volatile int a;
  /*****************************************initial*****************************************/
   double thita[6];


   int current_state[9 + 11 + 13];
   for (int ii = 0; ii < 9 + 11 + 13; ii++)
   	{
   		int tmp = rand();
   		if(tmp>RAND_MAX/2)
   			current_state[ii] = 1;
   		else
   			current_state[ii] = 0;
   	}
   /*****************************************initial*****************************************/
   /*****************************************Transmit loop*****************************************/
   int Loop_Num = 1;
   for(int iLoop = 0;iLoop < Loop_Num;iLoop++){
	  printf("Loop[%0d] starting\n",iLoop);
     get_thita(current_state,thita);
     double* thita1, * thita2, * thita3;
     thita1 = thita2 = thita;
    	thita3 = thita + 2;


    		/******************forward tarnsform*****************************/
   	  //symbol transform, need to import data(14*512) 8 times
   	  printf("starting Data Transfrom\n");
   	  for(int iSym = 0;iSym < 8;iSym++){

#ifdef IDE_TEST
   		  ColCopy(InputData,ColIn,iSym,1);
#else
   		  //*********Important:import data 'ColIn' to DM at here
   		  //'ColIn' size is 14*512 point equals to 14*512*32bit
   		  //here need move data to DM data(ColIn)
#endif
   		Transform((int)Config_2,MPU_ADDR(ColIn),MPU_ADDR(ColOut), 2, thita2, 1);
   		  SVRReg[0] = MPU_ADDR(Config_2);
   		  Transform2Asm(SVRReg);
   		  a = __ucps2_getStatB();
   		  __ucps2_delay();
#ifdef IDE_TEST
   		   		  ColCopy(TransTemp,ColOut,iSym,-1);
#else
   		   //*********Important:transfer DM data 'ColOut' out at here
   		   //'ColOut' size is 14*512 point equals to 14*512*32bit
   		   //here need move DM data(ColOut) out
#endif

   	  }

   	  //data transform
   	  for(int iBlk = 0; iBlk < 7; iBlk++){
#ifdef IDE_TEST
   		  	  RowCopy(TransTemp,RowIn,iBlk,1);
#else
   		  	//*********Important:import data 'RowIn' to DM at here
   		  	//data block size is 2*4096 point equals to 2*4096*32bit
   		  //here need move data to DM data(RowIn)
#endif
   		 Transform((int)Config_4,MPU_ADDR(RowIn),MPU_ADDR(RowOut), 4, thita3, 1);
   		  SVRReg[0] = MPU_ADDR(Config_4);
   		  Transform4Asm(SVRReg);
   		  a = __ucps2_getStatB();
   		  __ucps2_delay();
#ifdef IDE_TEST
   		  	  RowCopy(OutData,RowOut,iBlk,-1);
#else
   		  	//*********Important:transfer data 'RowOut' to DM at here
   		  	//'RowOut' size is 2*4096 point equals to 2*4096*32bit
   		  	//here need move DM data(RowOut) out
#endif

   	  }
   	/******************forward tarnsform*****************************/

   	/*********************detarnsform********************************/
   	  //data detrans
   	  for(int iBlk = 0;iBlk < 7;iBlk++){
#ifdef IDE_TEST
   		RowCopy(OutData,RowIn,iBlk,1);
#else
   		//*********Important:import data 'RowIn' to DM at here
   		//'RowIn' size is 2*4096 point equals to 2*4096*32bit
#endif

   		Transform((int)DeTransConfig_4,MPU_ADDR(RowIn),MPU_ADDR(RowOut), 4, thita3, -1);
		  SVRReg[0] = MPU_ADDR(DeTransConfig_4);
		  Transform4Asm(SVRReg);
		  a = __ucps2_getStatB();
		  __ucps2_delay();
#ifdef IDE_TEST
		  	  RowCopy(TransTemp,RowOut,iBlk,-1);
#else
		  	//*********Important:transfer DM data 'RowOut' outside at here
		  	//'RowOut' size is 2*4096 point equals to 2*4096*32bit
#endif

   	   }
   	  //symbol detrans
   	  for(int iSym = 0;iSym < 8;iSym++){
#ifdef IDE_TEST
   		  ColCopy(TransTemp,ColIn,iSym,1);
#else
   		//*********Important:import data 'ColIn' to DM at here
   		//'ColIn' size is 14*512 point equals to 14*512*32bit
#endif
   		Transform((int)DeTransConfig_2,MPU_ADDR(ColIn),MPU_ADDR(ColOut), 2, thita2, -1);
		  SVRReg[0] = MPU_ADDR(DeTransConfig_2);
		  Transform2Asm(SVRReg);
		  a = __ucps2_getStatB();
		  __ucps2_delay();
#ifdef IDE_TEST
		  ColCopy(DeTrans,ColOut,iSym,-1);
#else
		  //*********Important:transfer DM data 'ColOut' out at here
		  //'ColOut' size is 14*512 point equals to 14*512*32bit
#endif


   	   	}

   	  for(int i = 0;i<16; i++){
   	     printf("DataTrans: Input[%0d]: %x, Detrans[%0d]: %x\n",i*16,InputData[i*16],i*16,DeTrans[i*16]);
   	    }

   	  int offset = 14*4096-16*16;
   	  for(int i = 0;i<16; i++){
   	    printf("DataTrans: Input[%0d]: %x,Detrans[%0d]: %x\n",offset+i*16,InputData[offset+i*16],offset+i*16,DeTrans[offset+i*16]);
   	    }


   	  printf("starting Pilot Transfrom\n");
   	  //pilot size is 1*1024,do not need to divide to more blocks
   	  /***************************pilot transform******************************/
   	  Transform((int)Config_8,MPU_ADDR(PilotData),MPU_ADDR(PilotTrans), 8, thita1, 1);
   	  SVRReg[0] = MPU_ADDR(Config_8);
   	  Transform8Asm(SVRReg);
   	  a = __ucps2_getStatB();
   	  __ucps2_delay();
   	  /***************************pilot transform******************************/

   	  Transform((int)DeTransConfig_8,MPU_ADDR(PilotTrans),MPU_ADDR(PilotDeTrans), 8, thita1, -1);
   	  SVRReg[0] = MPU_ADDR(DeTransConfig_8);
   	  Transform8Asm(SVRReg);
   	  a = __ucps2_getStatB();
   	  __ucps2_delay();
   	  for(int i = 0;i<16; i++){
   	   printf("PilotTrans: Input[%0d]: %x, Detrans[%0d]: %x\n",i*16,PilotData[i*16],i*16,PilotDeTrans[i*16]);
   	  	 }
   	  offset = 1024-16*16;
   	  for(int i = 0;i<16; i++){
   	    printf("PilotTrans: Input[%0d]: %x,Detrans[%0d]: %x\n",offset+i*16,PilotData[offset+i*16],offset+i*16,PilotDeTrans[offset+i*16]);
   	  	  }

   printf("Loop[%0d] finishing\n",iLoop);
   }
  return a;
}

#endif
