
#ifndef REMOVE_MC_TEST

#include "ucp2.h"
#include "ucp2_utils.h"
#include <Transform.h>
#include <stdlib.h>
//_DM2 int InputData000[10028] = {0};

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

//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 = 4;
   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;


   	  //data test
   	  //symbol transform, need to import data(14*512) 8 times
   	  printf("starting Data Transfrom\n");
   	  for(int iSym = 0;iSym < 8;iSym++){
   	  //*********Important:import data 'InputData' to DM at here
   		  //'InputData' size is 14*512 point equals to 14*512*32bit
   		  Transform((int)Config_2,MPU_ADDR(InputData),MPU_ADDR(TransTemp), 2, thita2, 1);
   		  SVRReg[0] = MPU_ADDR(Config_2);
   		  Transform2Asm(SVRReg);
   		  a = __ucps2_getStatB();
   		  __ucps2_delay();

     //*********Important:transfer DM data 'TransTemp' out at here
   		//'TransTemp' size is 14*512 point equals to 14*512*32bit
   	  }

   	  //data transform
   	  for(int iBlk = 0; iBlk < 7; iBlk++){
     //*********Important:import data 'TransTemp' to DM at here
   		  //data block size is 2*4096 point equals to 2*4096*32bit
   		  Transform((int)Config_4,MPU_ADDR(TransTemp),MPU_ADDR(OutData), 4, thita3, 1);
   		  SVRReg[0] = MPU_ADDR(Config_4);
   		  Transform4Asm(SVRReg);
   		  a = __ucps2_getStatB();
   		  __ucps2_delay();


   	 //*********Important:import data 'OutData' to DM at here
   		 //'OutData' size is 2*4096 point equals to 2*4096*32bit
   	  }


   	  //data detrans
   	  for(int iBlk = 0;iBlk < 7;iBlk++){
   	  //*********Important:import data 'OutData' to DM at here
   	   		  //'OutData' size is 2*4096 point equals to 2*4096*32bit
		  Transform((int)DeTransConfig_4,MPU_ADDR(OutData),MPU_ADDR(TransTemp), 4, thita3, -1);
		  SVRReg[0] = MPU_ADDR(DeTransConfig_4);
		  Transform4Asm(SVRReg);
		  a = __ucps2_getStatB();
		  __ucps2_delay();
   	  //*********Important:import data 'TransTemp' to DM at here
   	   		 //'TransTemp' size is 2*4096 point equals to 2*4096*32bit
   	   }
   	  //symbol detrans
   	  for(int iSym = 0;iSym < 8;iSym++){
   	   	  //*********Important:import data 'TransTemp' to DM at here
   	   		  //'TransTemp' size is 14*512 point equals to 14*512*32bit
		  Transform((int)DeTransConfig_2,MPU_ADDR(TransTemp),MPU_ADDR(DeTrans), 2, thita2, -1);
		  SVRReg[0] = MPU_ADDR(DeTransConfig_2);
		  Transform2Asm(SVRReg);
		  a = __ucps2_getStatB();
		  __ucps2_delay();
   	  //*********Important:transfer DM data 'DeTrans' out at here
   	   		//'DeTrans' size is 14*512 point equals to 14*512*32bit
   	   	}

   	  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
   	  Transform((int)Config_8,MPU_ADDR(PilotData),MPU_ADDR(PilotTrans), 8, thita1, 1);
   	  SVRReg[0] = MPU_ADDR(Config_8);
   	  a = __ucps2_getStatB();
   	  __ucps2_delay();

   	  Transform8Asm(SVRReg);

   	  a = __ucps2_getStatB();
   	  __ucps2_delay();


   	  Transform((int)DeTransConfig_8,MPU_ADDR(PilotTrans),MPU_ADDR(PilotDeTrans), 8, thita1, -1);
   	  SVRReg[0] = MPU_ADDR(DeTransConfig_8);
   	  a = __ucps2_getStatB();
   	  __ucps2_delay();

   	  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);
   }
     /*****************************************Transmit loop*****************************************/
/*
//data test
  //symbol transform
  N = 2;
  Transform((int)Config_2,MPU_ADDR(InputData),MPU_ADDR(TransTemp), N, cs, 1);
  SVRReg[0] = MPU_ADDR(Config_2);
  Transform2Asm(SVRReg);
  a = __ucps2_getStatB();
   __ucps2_delay();

  //data transform
  N = 4;
  Transform((int)Config_4,MPU_ADDR(TransTemp),MPU_ADDR(OutData), N, cs, 1);
  SVRReg[0] = MPU_ADDR(Config_4);
  Transform4Asm(SVRReg);
  a = __ucps2_getStatB();
  __ucps2_delay();

  //data detrans
  Transform((int)DeTransConfig_4,MPU_ADDR(OutData),MPU_ADDR(TransTemp), N, cs, -1);
  SVRReg[0] = MPU_ADDR(DeTransConfig_4);
  Transform4Asm(SVRReg);
  a = __ucps2_getStatB();
  __ucps2_delay();

  //symbol detrans
  N = 2;
  Transform((int)DeTransConfig_2,MPU_ADDR(TransTemp),MPU_ADDR(DeTrans), N, cs, -1);
  SVRReg[0] = MPU_ADDR(DeTransConfig_2);
  Transform2Asm(SVRReg);
  a = __ucps2_getStatB();
  __ucps2_delay();

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

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


/*
//case 2
  N = 2;
  Transform((int)Config_2,MPU_ADDR(InputData),MPU_ADDR(OutData), N, cs, 1);
  SVRReg[0] = MPU_ADDR(Config_2);
  Transform2Asm(SVRReg);
  a = __ucps2_getStatB();
  __ucps2_delay();

  Transform((int)DeTransConfig_2,MPU_ADDR(OutData),MPU_ADDR(DeTrans), N, cs, -1);
  SVRReg[0] = MPU_ADDR(DeTransConfig_2);
  Transform2Asm(SVRReg);
  a = __ucps2_getStatB();

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


//case 4
  N = 4;
  Transform((int)Config_4,MPU_ADDR(InputData),MPU_ADDR(OutData), N, cs, 1);
  SVRReg[0] = MPU_ADDR(Config_4);
  a = __ucps2_getStatB();
  __ucps2_delay();

  Transform4Asm(SVRReg);

  a = __ucps2_getStatB();
  __ucps2_delay();


  Transform((int)DeTransConfig_4,MPU_ADDR(OutData),MPU_ADDR(DeTrans), N, cs, -1);
  SVRReg[0] = MPU_ADDR(DeTransConfig_4);
  a = __ucps2_getStatB();
  __ucps2_delay();

  Transform4Asm(SVRReg);

  a = __ucps2_getStatB();
  __ucps2_delay();
  for(int i = 0;i<16; i++){
	  printf("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("Input[%0d]: %x,Detrans[%0d]: %x\n",offset+i*16,InputData[offset+i*16],offset+i*16,DeTrans[offset+i*16]);
   }


  //case 8
  N = 8;
  Transform((int)Config_8,MPU_ADDR(PilotData),MPU_ADDR(PilotTrans), N, cs, 1);
  SVRReg[0] = MPU_ADDR(Config_8);
  a = __ucps2_getStatB();
  __ucps2_delay();

  Transform8Asm(SVRReg);

  a = __ucps2_getStatB();
  __ucps2_delay();


  Transform((int)DeTransConfig_8,MPU_ADDR(PilotTrans),MPU_ADDR(PilotDeTrans), N, cs, -1);
  SVRReg[0] = MPU_ADDR(DeTransConfig_8);
  a = __ucps2_getStatB();
  __ucps2_delay();

  Transform8Asm(SVRReg);

  a = __ucps2_getStatB();
  __ucps2_delay();

  for(int i = 0;i<1024; i=i+16){
   printf("Input[%0d]: %x, Detrans[%0d]: %x\n",i,PilotData[i],i,PilotDeTrans[i]);
  }
*/

  return a;
}

#endif
