// +FHDR------------------------------------------------------------
//                 Copyright (c) 2022 SmartLogic.
//                       ALL RIGHTS RESERVED
// -----------------------------------------------------------------
// Filename      : cpri_test_case0.c
// Author        : xianfeng.du
// Created On    : 2022-10-19s
// Last Modified :
// -----------------------------------------------------------------
// Description:
//
//
// -FHDR------------------------------------------------------------

#include "typedef.h"

#include "phy_para.h"
#include "cpri_test.h"
#include "cpri_csu.h"
#include "ape_csu.h"
#include "hw_cpri.h"
#include "cpri_driver.h"
#include "ucp_utility.h"
#include "ucp_printf.h"
#include "cpri_timer.h"
#include "HeaderRam.h"


extern stMtimerIntStat 		gMtimerIntCnt[SCS_MAX_NUM];
extern uint32_t           Tdd_Offset_Int_Falg;
extern uint32_t           CPRI_OPTION;







#define HeaderTestCnt   10


#define Ping_Flag   0
#define Pong_Flag   1

#define RF_NUM   1//2



//uint32_t pSrcData[16*1024] = {0};
//uint32_t *addrSrc =(uint32_t *)pSrcData;


uint32_t cpri_ape_csu_cnt = 0;

uint32_t cpri_AxC_test_cnt =0;

uint32_t cpri_AxC_test_cnt0 =0;
uint32_t cpri_AxC_test_cnt1 =0;


extern uint32_t gCpriTestMode;


#if 1
void Axc_data_init()

{

   uint32_t i,j,k,t,m,n =0;
	
	 for(i=0;i<RF_NUM;i=i+1)//2 frame
	 {
		 for(j=0;j<2;j=j+1)//0-74HF/75-149HF
		 {
			for(k=0;k<ID_NUM;k=k+1)//ID
			{
				//bit31:28为RFN,bit27:20为HFN,bit19:12为BasicFN,bit11:8为AXC ID,bit7:0为AXC data
				if(0==k || 5==k)
				{
					for(t=0;t<75;t=t+1)//HF
				   {	
				  		for(m=0;m<256;m=m+1)//bfn
			  			{
			  				for(n=0;n<ID0_SIZE;n=n+1)//
		  					{		  	
					   			//STORE_EX_W(((uint32_t *)(CSU_TX_AXC_ADDR +ID_NUM*2*ID_DATA_STEP+ i*ID_DATA_STEP*ID_NUM*2 + j*ID_DATA_STEP*ID_NUM + k*ID_DATA_STEP + t*256*ID0_SIZE*4 + m*ID0_SIZE*4 + n*4)), (i<<28)+((j*75+t)<<20)+(m<<12)+(k<<8)+0x1);
								do_write(((uint32_t *)(CSU_TX_AXC_ADDR + i*ID_DATA_STEP*ID_NUM*2 + j*ID_DATA_STEP*ID_NUM + k*ID_DATA_STEP + t*256*ID0_SIZE*4 + m*ID0_SIZE*4 + n*4)), (i<<28)+((j*75+t)<<20)+(m<<12)+(k<<8)+0x1);

							}
				  		}

				   }

				}
				else//ID1~ID4
				{
					for(t=0;t<75;t=t+1)//HF
					{
						 for(m=0;m<256;m=m+1)//bfn
						 {
							 for(n=0;n<ID1_SIZE*8/4;n=n+1)//
							 {
								// STORE_EX_W(((uint32_t *)(CSU_TX_AXC_ADDR +ID_NUM*2*ID_DATA_STEP+ i*ID_DATA_STEP*ID_NUM*2 + j*ID_DATA_STEP*ID_NUM + k*ID_DATA_STEP + t*256*ID1_SIZE*8 + m*(ID1_SIZE*8) + n*4)), (i<<28)+((j*75+t)<<20)+(m<<12)+(k<<8)+n);
								 do_write(((uint32_t *)(CSU_TX_AXC_ADDR + i*ID_DATA_STEP*ID_NUM*2 + j*ID_DATA_STEP*ID_NUM + k*ID_DATA_STEP + t*256*ID1_SIZE*8 + m*(ID1_SIZE*8) + n*4)), (i<<28)+((j*75+t)<<20)+(m<<12)+(k<<8)+n);
					
							 }
					
							 
						 }
					
					}


				}
			}
		 }
		 
	 }

}

#endif


void CtrlAxc_data_init()
{
	uint32_t bf_ctrlaxc_byte = 16;

	for(uint32_t HFid=0;HFid<150;HFid++)
	{
		for(uint32_t BFid=0;BFid<16;BFid++)//4~7,68~71,132~135,196~199
		{
			for(uint32_t idvalue=0;idvalue<(bf_ctrlaxc_byte>>2);idvalue++)
			{

				do_write((uint32_t *)(CSU_TX_CTRL_ADDR+(idvalue<<2)+(BFid*16)+(HFid*256)),  ((HFid<<24) | (BFid<<8) | idvalue));
			}
		
		}

	}


}

void HeaderTxRam_data_init()
{

	for(int i=0;i<16*HeaderTestCnt;i++)
	{
		do_write(((uint32_t *)HeaderTxDataAddr0 +i),0x12345678+i);
	}
#if 0
	for(int i=0;i<16*HeaderTestCnt;i++)
	{
		do_write(((uint32_t *)HeaderTxDataAddr1 +i),0x87654321+i);
	}
#endif
}

#if 0
void HeaderTxRam_init()
{
	uint32_t i,j;

	HeaderRam_ins_disable();
	for(i=0;i<64;i++)//Ns
	{
		for(j=0;j<4;j++)//
		{
			HeaderRam_Tx(i+64*j,0,0,0);//vendor
			HeaderRam_Tx(i+64*j,1,0,0);//vendor
			HeaderRam_Tx(i+64*j,2,0,0);//vendor
			HeaderRam_Tx(i+64*j,3,0,0);//vendor
		}
	}
	//HeaderRam_ins_enable();
	do_write(&CPRI_FRAME_RX_HDR_ADDR,0);
}
#endif

uint32_t CtrlAxCDataErrorCnt= 0;
uint32_t CtrlAxCDataCheckCnt= 0;
uint32_t CtrlAxCDataCheckCycle= 0;
void AxC_data_check(uint32_t times)
{

#if 1	
	
	uint32_t bf_ctrlaxc_byte = 16;
	uint32_t TxData , RxData= 0;
	CtrlAxCDataCheckCnt++;
	if(pMtimerInt->tddOffsetIntCnt  >= 64)
	{

		for(uint32_t HFid=0;HFid<150;HFid++)
		{
			for(uint32_t BFid=0;BFid<16;BFid++)//4~7,68~71,132~135,196~199
			{
				for(uint32_t idvalue=0;idvalue<(bf_ctrlaxc_byte>>2);idvalue++)
				{
				    TxData = ((HFid<<24) | (BFid<<8) | idvalue);
					RxData = do_read_volatile((CSU_RX_CTRL_ADDR+(idvalue<<2)+(BFid*16)+(HFid*256)));
					if(TxData != RxData)
					{
					    CtrlAxCDataErrorCnt++;
						
						debug_write((DBG_DDR_IDX_CPRI_BASE+8+ ((CtrlAxCDataErrorCnt<<2)&0xff)), TxData); // 0xb7e28020 
						debug_write((DBG_DDR_IDX_CPRI_BASE+9+ ((CtrlAxCDataErrorCnt<<2)&0xff)), RxData); // 
						debug_write((DBG_DDR_IDX_CPRI_BASE+10+((CtrlAxCDataErrorCnt<<2)&0xff)),((HFid<<24) | (BFid<<8) | idvalue)); // 
					}
				}
			
			}
	
		}
		
		debug_write((DBG_DDR_IDX_CPRI_BASE+4), CtrlAxCDataCheckCnt); // 0xb7e28010
		debug_write((DBG_DDR_IDX_CPRI_BASE+5), CtrlAxCDataCheckCycle);
		debug_write((DBG_DDR_IDX_CPRI_BASE+6), CtrlAxCDataErrorCnt); // 
		if(CtrlAxCDataCheckCnt == 0xffffffff)
		{
			CtrlAxCDataCheckCycle++;
			CtrlAxCDataCheckCnt =0;
		}
	}
#endif
	return;

}

void cpri_csu_test_init()
{
	stCpriCsuCmdFifoInfo		txTestCmdFifo;
	stCpriCsuCmdFifoInfo		rxTestCmdFifo;
	
	cpri_csu_axc_init_nr_7ds2u(CPRI_DUMMY_USE_DDR_ADDR, &txTestCmdFifo, &rxTestCmdFifo);
	cpri_csu_axcctrl_init_timing();
	UCP_API_CPRI_CSU_Get_CmdFIFO(&txTestCmdFifo, &rxTestCmdFifo);
}


void Get_Cpri_OptionId()
{
	CPRI_OPTION = CPRI_OPTION_8;
    return;
}

void Cpri_data_init()
{
	gCpriTestMode = CPRI_TEST_MODE;
	debug_write((DBG_DDR_IDX_DRV_BASE+192), gCpriTestMode); // 0x300
	Get_Cpri_OptionId();//get cpri option value
	UCP_PRINT_EMPTY("Get Cpri Option Id.\r\n");
		
	Axc_data_init();//init axc data
	CtrlAxc_data_init();
	//AUX_Rx_init(0x50000000,0x60000000,0x10000,0x10000);
	HeaderTxRam_data_init();
	//HeaderTxRam_init();			
	UCP_PRINT_EMPTY("Axc data init.\r\n");

}

#if 0
void Cpri_AxC_test(uint32_t Ping_Pong_Flag,uint32_t times)
{

   uint32_t i=0;
   uint32_t j=0;

   uint32_t test_axc_error0 =0;
   uint32_t test_axc_error1 =0;
	
	//uint32_t memcpy_len = 32*1024;
	uint32_t memcpy_len = 2*256*75;//ID0前75帧数据;
	uint32_t mem_cycle = ID_NUM*ID_DATA_STEP/memcpy_len;

	
	//uint32_t memcpy_len = 512*1024;
	//uint32_t mem_cycle = 14;

	if(Ping_Pong_Flag == 0)
	{

		/**************test ping addr*************/
		uint32_t startTick0 = GET_STC_CNT();

		#if 0	

		uint32_t CSU_Rx_AxC_Data =0;
  		uint32_t CSU_Tx_AxC_Data =0;
		uint32_t cycle = ID_NUM*ID_DATA_STEP/4;
		for(i=0;i<cycle;i=i+1)
		{		
			CSU_Rx_AxC_Data = do_read((uint32_t *)(CSU_RX_AXC_ADDR + i*4));
			CSU_Tx_AxC_Data = do_read((uint32_t *)(CSU_TX_AXC_ADDR + i*4));
			if((CSU_Rx_AxC_Data ^ CSU_Tx_AxC_Data) !=0)
			{
			  test_axc_error0++;
			}
		}
		#endif

		#if 0
		for(i=0;i<mem_cycle;i=i+1)
		{
			memcpy_ucp((void*)pSrcData,(void*)(CSU_TX_AXC_ADDR + i*memcpy_len), memcpy_len);
			memcpy_ucp((void*)(pSrcData + memcpy_len),(void*)(CSU_RX_AXC_ADDR + i*memcpy_len), memcpy_len);
			for(j=0;j<(memcpy_len>>2);j=j+1)
			{
				if((pSrcData[j]  ^ pSrcData[(memcpy_len>>2) + j] ) !=0)
				{
				  test_axc_error0++;
				}
			}
		}
		#endif

		 #if 0
		 {
			 memcpy_ucp((void*)pSrcData,(void*)(CSU_TX_AXC_ADDR + (mem_cycle -1)*memcpy_len), memcpy_len);
			 memcpy_ucp((void*)(pSrcData + memcpy_len),(void*)(CSU_RX_AXC_ADDR +  (mem_cycle -1)*memcpy_len), memcpy_len);
			 for(j=0;j<(memcpy_len>>2);j=j+1)
			 {
				 if((pSrcData[j]  ^ pSrcData[(memcpy_len>>2) + j] ) !=0)
				 {
				   test_axc_error0++;
				 }
			 }
		 }
		#endif

		
		for(i=0;i<mem_cycle;i=i+1)
		{
			memcpy_ucp((void*)pSrcData,(void*)(CSU_TX_AXC_ADDR + i*memcpy_len), memcpy_len);
			memcpy_ucp((void*)(pSrcData + memcpy_len),(void*)(CSU_RX_AXC_ADDR + i*memcpy_len), memcpy_len);
			#if 0

			if ((memcmp((void*)pSrcData,(void*)(pSrcData + memcpy_len),memcpy_len)) != 0)
			{
			 	test_axc_error0++;
			}
			#endif		
			for(j=0;j<(memcpy_len>>2);j=j+1)
			{
				if((pSrcData[j]  ^ pSrcData[(memcpy_len>>2) + j] ) !=0)
				{
				  test_axc_error0++;
				}
			}
			
		}
		
#if 0

		 for(i=0;i<mem_cycle;i=i+1)
		 {
			 //memcpy_ucp((void*)pSrcData,(void*)(CSU_TX_AXC_ADDR + i*memcpy_len), memcpy_len);
			 //memcpy_ucp((void*)(pSrcData + memcpy_len),(void*)(CSU_RX_AXC_ADDR + i*memcpy_len), memcpy_len);
			 //if ((memcmp((void*)pSrcData,(void*)(pSrcData + memcpy_len),memcpy_len)) != 0)

			
			 if ((memcmp((void*)(CSU_TX_AXC_ADDR + i*memcpy_len),(void*)(CSU_RX_AXC_ADDR + i*memcpy_len),memcpy_len)) != 0)//512k
			 {
				 test_axc_error0++;
			 }
		 }
#endif


		
		 uint32_t cost0 = GET_STC_CNT() - startTick0;
		 debug_write((DBG_DDR_IDX_CPRI_BASE+210+times),cost0);
		 debug_write((DBG_DDR_IDX_CPRI_BASE+220+times),test_axc_error0);

		 if(test_axc_error0 == 0) 
		{
			UCP_PRINT_LOG("Test axc data pass.\r\n");
		}
		else
		{
			UCP_PRINT_LOG("Test axc data error!!!!!!!!!!!!!!!!!\r\n");
		}

	}
	if(Ping_Pong_Flag == 1)
	{
		 /**************test pong addr**********/
		 uint32_t startTick1 = GET_STC_CNT();
		 #if 0
		 for(i=0;i<cycle;i=i+1)//pong
		{		
			CSU_Rx_AxC_Data = do_read((uint32_t *)(CSU_RX_AXC_ADDR +ID_NUM*ID_DATA_STEP + i*4));
			CSU_Tx_AxC_Data = do_read((uint32_t *)(CSU_TX_AXC_ADDR +ID_NUM*ID_DATA_STEP+ i*4));
			if((CSU_Rx_AxC_Data ^ CSU_Tx_AxC_Data) !=0)
			{
			  test_axc_error1++;
			}
		}
		#endif

		#if 0
		 for(i=0;i<mem_cycle;i=i+1)
		 {
			 memcpy_ucp((void*)pSrcData,(void*)(CSU_TX_AXC_ADDR +ID_NUM*ID_DATA_STEP+i*memcpy_len), memcpy_len);
			 memcpy_ucp((void*)(pSrcData + memcpy_len),(void*)(CSU_RX_AXC_ADDR +ID_NUM*ID_DATA_STEP+ i*memcpy_len), memcpy_len);
			 for(j=0;j<(memcpy_len>>2);j=j+1)
			 {
				 if((pSrcData[j]  ^ pSrcData[(memcpy_len>>2) + j] ) !=0)
				 {
				   test_axc_error1++;
				 }
			 }
		 }
		#endif

#if 0
		 //for(i=0;i<mem_cycle;i=i+1)
		 {
			 memcpy_ucp((void*)pSrcData,(void*)(CSU_TX_AXC_ADDR +ID_NUM*ID_DATA_STEP+(mem_cycle -1)*memcpy_len), memcpy_len);
			 memcpy_ucp((void*)(pSrcData + memcpy_len),(void*)(CSU_RX_AXC_ADDR +ID_NUM*ID_DATA_STEP+ (mem_cycle -1)*memcpy_len), memcpy_len);
			 for(j=0;j<(memcpy_len>>2);j=j+1)
			 {
				 if((pSrcData[j]  ^ pSrcData[(memcpy_len>>2) + j] ) !=0)
				 {
				   test_axc_error1++;
				 }
			 }
		 }
#endif


		 for(i=0;i<mem_cycle;i=i+1)
		 {
			 memcpy_ucp((void*)pSrcData,(void*)(CSU_TX_AXC_ADDR +ID_NUM*ID_DATA_STEP+ i*memcpy_len), memcpy_len);
			 memcpy_ucp((void*)(pSrcData + memcpy_len),(void*)(CSU_RX_AXC_ADDR +ID_NUM*ID_DATA_STEP+ i*memcpy_len), memcpy_len);

			#if 0

			 if ((memcmp((void*)pSrcData,(void*)(pSrcData + memcpy_len),memcpy_len) )!= 0)
			 {
				 test_axc_error1++;
			 }
			#endif
			 for(j=0;j<(memcpy_len>>2);j=j+1)
			 {
				 if((pSrcData[j]  ^ pSrcData[(memcpy_len>>2) + j] ) !=0)
				 {
				   test_axc_error0++;
				 }
			 }
	
		 }

		#if 0

		 for(i=0;i<mem_cycle;i=i+1)
		  {
			  memcpy_ucp((void*)pSrcData,(void*)(CSU_TX_AXC_ADDR + i*memcpy_len), memcpy_len);
			  memcpy_ucp((void*)(pSrcData + memcpy_len),(void*)(CSU_RX_AXC_ADDR + i*memcpy_len), memcpy_len);
			  if ((memcmp((void*)pSrcData,(void*)(pSrcData + memcpy_len),memcpy_len)) != 0)
 
			 
			  //if ((memcmp((void*)(CSU_TX_AXC_ADDR +ID_NUM*ID_DATA_STEP+ i*memcpy_len),(void*)(CSU_RX_AXC_ADDR+ID_NUM*ID_DATA_STEP + i*memcpy_len),memcpy_len)) != 0)//512k
			  {
				  test_axc_error1++;
			  }
		  }

		#endif

		 
		 uint32_t cost1 = GET_STC_CNT() - startTick1;
		 debug_write((DBG_DDR_IDX_CPRI_BASE+230+times),cost1);
		debug_write((DBG_DDR_IDX_CPRI_BASE+240+times),test_axc_error1);

		if(test_axc_error1 == 0) 
		{
			UCP_PRINT_LOG("Test axc data pass.\r\n");
		}
		else
		{
			UCP_PRINT_LOG("Test axc data error!!!!!!!!!!!!!!!!!\r\n");
		}

	}
		

}

#endif

#if 0
uint32_t Header_error0=0;
uint32_t Header_error1 = 0;

uint32_t HeaderTxtimes = 0;

void Cpri_Header_test(void)
{
	
	//uint32_t Header_error0=0;
	//uint32_t Header_error1 = 0;
	//uint32_t Get_Rx_HFN = 0;
	uint32_t j= 0;

//	if ((2 <= gCpriTimerPara.tddOffsetIntCnt) && (20 >= gCpriTimerPara.tddOffsetIntCnt))
	if (2 <= gCpriTimerPara.tddOffsetIntCnt) 
	{
		if (1 == (gCpriTimerPara.tddOffsetIntCnt & 0x1))
		{	
						
			HeaderTxtimes++;
			#if 0
			if(HeaderTxtimes == 1 )
			{
				AUX_Rx_init(0x50000000,0x60000000,0x10000,0x10000);
				AUX_Rx_enable(0x2);
				//Get_Rx_HFN = HeaderRam_Rx(64,0);//get Rx HFN
				//debug_write((DBG_DDR_IDX_DRV_BASE+394 + ), Get_Rx_HFN); // 0x628
			}
			#endif
			//Get_Rx_HFN = HeaderRam_Rx(64,0);//get Rx HFN
			//Get_Rx_HFN = UCP_API_CPRI_GetRxHfnCnt();
			//debug_write((DBG_DDR_IDX_CPRI_BASE+ HeaderTxtimes), Get_Rx_HFN); // 0xb7e28000				
			UCP_PRINT_LOG("Header insert start.\r\n");

			/*********************1st HyperFrame*********************/
			//when BFN=111,header Tx insert
		//	uint32_t startTick = GET_STC_CNT();
		 //if(HeaderTxtimes == 1 )
		 {

			
			while(1)
			{
				if((UCP_API_CPRI_GetTxHfnCnt() ==HeaderTxHFN0) && ( UCP_API_CPRI_GetTxXCnt() <10))
				//if((UCP_API_CPRI_GetTxHfnCnt() ==HeaderTxHFN0))
				{
					HeaderRam_ins_disable();
					break;
				}
			}
		 }
			//uint32_t startTick0 = GET_STC_CNT();
			//Get_Rx_HFN = HeaderRam_Rx(64,0);//get Rx HFN
			//Get_Rx_HFN = UCP_API_CPRI_GetRxHfnCnt();
			//debug_write((DBG_DDR_IDX_CPRI_BASE+20+HeaderTxtimes), Get_Rx_HFN); // 
#if 1
		 //if(HeaderTxtimes == 1 )
		 {

			//uint32_t startTick0 = GET_STC_CNT();
			//memcpy_ucp((uint32_t*)Txdata,(uint32_t*)(HeaderTxDataAddr0 + ((HeaderTxtimes-1)*64)), 64);
			memcpy_ucp((uint32_t*)Txdata,(uint32_t*)(HeaderTxDataAddr0 + ((HeaderTxtimes%2)*64)), 64);
			for(j=0;j<4;j++)
			{
				HeaderRam_Tx(3+64*j,0,Txdata[j*4],0xF);//vendor
				HeaderRam_Tx(3+64*j,1,Txdata[1+j*4],0xF);//vendor
				HeaderRam_Tx(3+64*j,2,Txdata[2+j*4],0xF);//vendor
				HeaderRam_Tx(3+64*j,3,Txdata[3+j*4],0xF);//vendor

			}
			//uint32_t cost0 = GET_STC_CNT() - startTick0;
			//debug_write((DBG_DDR_IDX_CPRI_BASE+170+gCpriTimerPara.tddOffsetIntCnt),cost0);//17us左右
#endif

			
			HeaderRam_ins_enable();
			debug_write((DBG_DDR_IDX_CPRI_BASE+141), do_read_volatile(&AUX_CNT0));

			
			//delay_us(10);

		 }
#if 0
			//when BFN=112,header Tx insert enable
			while(1)
			{
				if((UCP_API_CPRI_GetTxHfnCnt() ==  (HeaderTxHFN0+1)) && ( UCP_API_CPRI_GetTxXCnt() <2))
				{
					HeaderRam_ins_enable();
					break;
				}
			}
			//Get_Rx_HFN = HeaderRam_Rx(64,0);//get Rx HFN
			//debug_write((DBG_DDR_IDX_CPRI_BASE+40+HeaderTxtimes), Get_Rx_HFN); // 

#endif
#if 1
			//when BFN=113,header Rx
			while(1)
			{
				//if((UCP_API_CPRI_GetTxHfnCnt() ==(HeaderTxHFN0+2)) && ( UCP_API_CPRI_GetTxXCnt() ==0))
				//if(UCP_API_CPRI_GetTxHfnCnt() ==(HeaderTxHFN0+3))
				//if((UCP_API_CPRI_GetTxHfnCnt() ==(HeaderTxHFN0+1)) && ( UCP_API_CPRI_GetTxXCnt() >=200))//BFN=112
				if((UCP_API_CPRI_GetRxHfnCnt() == (HeaderTxHFN0+2)))//BFN=112
				{
					//HeaderRam_ins_disable();
					break;
				}
			}
			debug_write((DBG_DDR_IDX_CPRI_BASE+142), do_read_volatile(&AUX_CNT0));
			debug_write((DBG_DDR_IDX_CPRI_BASE+143), do_read_volatile(&AUX_CNT2));

			//Get_Rx_HFN = HeaderRam_Rx(64,0);//get Rx HFN
			//Get_Rx_HFN = UCP_API_CPRI_GetRxHfnCnt();
			///debug_write((DBG_DDR_IDX_CPRI_BASE+60+HeaderTxtimes), Get_Rx_HFN); // 
			for(j=0;j<4;j++)
			{
				//Rxdata0[3+j*4] = HeaderRam_Rx(3+64*j,3);//vendor	
				Rxdata0[j*4] = HeaderRam_Rx(3+64*j,0);//vendor
				Rxdata0[1+j*4] = HeaderRam_Rx(3+64*j,1);//vendor
				Rxdata0[2+j*4] = HeaderRam_Rx(3+64*j,2);//vendor			
				Rxdata0[3+j*4] = HeaderRam_Rx(3+64*j,3);//vendor
			
			}
			//do_write(&CPRI_FRAME_RX_HDR_ADDR,0);
			//memcpy_ucp((uint32_t*)(HeaderRxDataAddr0 +((HeaderTxtimes-1)*64)),(uint32_t*)Rxdata0, 64);
			memcpy_ucp((uint32_t*)HeaderRxDataAddr0,(uint32_t*)Rxdata0, 64);
#endif	

			#if 1
			for(j=0;j<16;j++)
			{
				if (Rxdata0[j] != Txdata[j])//vendor
				{
					Header_error0++;
					Header_error1++;
				}
			
			}
			#endif
			if(Header_error1!=0)
			{
			
				memcpy_ucp((uint32_t*)HeaderRxDataAddr1,(uint32_t*)Rxdata0, 64);
				Header_error1 =0;
			}

#if 0

				for(j=0;j<16;j++)
			{
				if(j%4 == 3)
				{
					continue;
				}
				if (Rxdata0[j] != Txdata[j])//vendor
				{
					Header_error0++;
				}
			
			}
#endif
			//if(memcmp((uint32_t*)HeaderTxDataAddr0 ,(uint32_t*)(HeaderRxDataAddr0 + (HeaderTxtimes*64)),64) != 0)
			//{
			//	Header_error0++;
			//}
	

			/*********************2nd HyperFrame*********************/

#if 0
			//when BFN=114,header Tx insert
			while(1)
			{
				if((UCP_API_CPRI_GetTxHfnCnt() == HeaderTxHFN1) && ( UCP_API_CPRI_GetTxXCnt() < 10))
				//if(UCP_API_CPRI_GetTxHfnCnt() == HeaderTxHFN1)
				{
					HeaderRam_ins_disable();
					break;
				}
			}
			//Get_Rx_HFN = HeaderRam_Rx(64,0);//get Rx HFN
			Get_Rx_HFN = UCP_API_CPRI_GetRxHfnCnt();
			debug_write((DBG_DDR_IDX_CPRI_BASE+80+HeaderTxtimes), Get_Rx_HFN); // 
			
			memcpy_ucp((uint32_t*)Txdata,(uint32_t*)(HeaderTxDataAddr1+ ((HeaderTxtimes-1)*64)), 64);			
			for(j=0;j<4;j++)
			{
				HeaderRam_Tx(3+64*j,0,Txdata[j*4]);//vendor
				HeaderRam_Tx(3+64*j,1,Txdata[1+j*4]);//vendor
				HeaderRam_Tx(3+64*j,2,Txdata[2+j*4]);//vendor
				HeaderRam_Tx(3+64*j,3,Txdata[3+j*4]);//vendor

			}
			HeaderRam_ins_enable();
			
	#if 0
			//when BFN=115,header Tx insert enable
			while(1)
			{
				if((UCP_API_CPRI_GetTxHfnCnt() ==(HeaderTxHFN1+1)) && ( UCP_API_CPRI_GetTxXCnt() ==0))
				{
					HeaderRam_ins_enable();
					break;
				}
			}
	#endif
			//Get_Rx_HFN = HeaderRam_Rx(64,0);//get Rx HFN
			//debug_write((DBG_DDR_IDX_CPRI_BASE+100+HeaderTxtimes), Get_Rx_HFN); // 

			//when BFN=116,header Rx
			while(1)
			{
				//if((UCP_API_CPRI_GetTxHfnCnt() ==(HeaderTxHFN1+2)) && ( UCP_API_CPRI_GetTxXCnt() ==0))
				//if(UCP_API_CPRI_GetTxHfnCnt() ==(HeaderTxHFN1+2))
				if((UCP_API_CPRI_GetTxHfnCnt() ==(HeaderTxHFN1+1)) && ( UCP_API_CPRI_GetTxXCnt() >=200))//
				{
					//HeaderRam_ins_disable();
					break;
				}
			}
			//Get_Rx_HFN = HeaderRam_Rx(64,0);//get Rx HFN
			Get_Rx_HFN = UCP_API_CPRI_GetRxHfnCnt();
			debug_write((DBG_DDR_IDX_CPRI_BASE+120+HeaderTxtimes), Get_Rx_HFN); // 
			
			for(j=0;j<4;j++)
			{
				Rxdata1[j*4] = HeaderRam_Rx(3+64*j,0);//vendor
				Rxdata1[1+j*4] = HeaderRam_Rx(3+64*j,1);//vendor
				Rxdata1[2+j*4] = HeaderRam_Rx(3+64*j,2);//vendor
				Rxdata1[3+j*4] = HeaderRam_Rx(3+64*j,3);//vendor	
			
			}
			memcpy_ucp((uint32_t*)(HeaderRxDataAddr1 +((HeaderTxtimes-1)*64)),(uint32_t*)Rxdata1, 64);

			//if(memcmp((uint32_t*)HeaderTxDataAddr1 ,(uint32_t*)(HeaderRxDataAddr1 + (HeaderTxtimes*64)),64) != 0)
			//{
			//	Header_error1++;
			//}
#if 0
			for(j=0;j<16;j++)
			{
				if (Rxdata[j] != Txdata[j])//vendor
				{
					Header_error1++;
				}
			
			}
#endif
#endif
			//uint32_t cost0 = GET_STC_CNT() - startTick0;
			//debug_write((DBG_DDR_IDX_CPRI_BASE+160+gCpriTimerPara.tddOffsetIntCnt),cost0);

			//debug_write((DBG_DDR_IDX_CPRI_BASE+140+(HeaderTxtimes*2)), Header_error0); 
			debug_write((DBG_DDR_IDX_CPRI_BASE+140), Header_error0);
			//debug_write((DBG_DDR_IDX_CPRI_BASE+140+(HeaderTxtimes*2+1)), Header_error1); 

#if 0
			if(Header_error0 !=0)
			{
				UCP_PRINT_LOG("1st HF Header fail.\r\n");
				
			}
			if(Header_error1 !=0)
			{
				UCP_PRINT_LOG("2nd HF Header fail.\r\n");
			}
#endif


		//uint32_t cost = GET_STC_CNT() - startTick;
		//debug_write((DBG_DDR_IDX_CPRI_BASE+180+gCpriTimerPara.tddOffsetIntCnt),cost);

		}
	}
	
}
#endif

void cpri_AxCData_test(void)
{				
		stMtimerIntStat* pMtimerInt = &gMtimerIntCnt[MTIMER_CPRI_ID];
		if ((2 < pMtimerInt->tddOffsetIntCnt) &&(pMtimerInt->tddOffsetIntCnt < 7))//2 RF
		{				
			if (pMtimerInt->tddOffsetIntCnt&0x1)//ping
			{
			
				uint32_t startTick0 = GET_STC_CNT();
				
				ape_csu_dma_1D_G2L_ch2ch3_transfer(CSU_RX_AXC_ADDR,
												   CSU_RX_AXC_ADDR+ID_NUM*2*ID_DATA_STEP+(pMtimerInt->tddOffsetIntCnt-3)*ID_DATA_STEP*ID_NUM,
												   ID_DATA_STEP*ID_NUM, 0,1);										
					
				uint32_t cost0 = GET_STC_CNT() - startTick0;
				debug_write((DBG_DDR_IDX_CPRI_BASE+pMtimerInt->tddOffsetIntCnt),cost0);
							   
			}
			else//pong
			{
				uint32_t startTick1 = GET_STC_CNT();
				
				ape_csu_dma_1D_G2L_ch2ch3_transfer(CSU_RX_AXC_ADDR+ID_NUM*ID_DATA_STEP ,
												   CSU_RX_AXC_ADDR+ID_NUM*2*ID_DATA_STEP+(pMtimerInt->tddOffsetIntCnt-3)*ID_DATA_STEP*ID_NUM,
												   ID_DATA_STEP*ID_NUM, 1, 1);	
				
				uint32_t cost1 = GET_STC_CNT() - startTick1;
				debug_write((DBG_DDR_IDX_CPRI_BASE+pMtimerInt->tddOffsetIntCnt),cost1);
				
			}
		}
	

}


void cpri_test_case(void)
{
#if 0
#if 1
	//if (6 <= gCpriTimerPara.tddOffsetIntCnt)
	if (4 <= gCpriTimerPara.tddOffsetIntCnt)
	//if (2 == gCpriTimerPara.tddOffsetIntCnt)
	{
	
		if (0 == (gCpriTimerPara.tddOffsetIntCnt & 0x3))
		//if ((0x94 <= UCP_API_CPRI_GetTxHfnCnt()	) && (UCP_API_CPRI_GetTxHfnCnt() <= 0x95))
		//if (0x95 == UCP_API_CPRI_GetTxHfnCnt() )
		{
#ifdef CPRI_TIMING_TEST
//						UINT32 startTick = GET_STC_CNT();
			
		    cpri_csu_start_timing();
//						UINT32 cost = GET_STC_CNT() - startTick;
//						do_write(DDR_ADDR_90, cost);
#endif
#ifdef CPRI_NOTIMING_TEST
			cpri_csu_start_notiming();
#endif
			#if 0	
			if (20 >= gCpriTimerPara.tddOffsetIntCnt)
			{

				debug_write((DBG_DDR_IDX_CPRI_BASE+280 + gCpriTimerPara.tddOffsetIntCnt), UCP_API_CPRI_GetRxHfnCnt()); // 0x628
				//debug_write((DBG_DDR_IDX_CPRI_BASE+280), UCP_API_CPRI_GetRxHfnCnt()); 
			}
			#endif
		}
	}
#endif
//	cpri_AxCData_test();

	Cpri_Header_test();
#endif
	stMtimerIntStat* pMtimerInt = &gMtimerIntCnt[MTIMER_CPRI_ID];
	//if(gCpriTimerPara.tddOffsetIntCnt <= 8)
	if(pMtimerInt->csuEnCnt > 4 )
	{
		if((pMtimerInt->csuEnCnt  &  0x3) == 0)
		{
			debug_write((DBG_DDR_IDX_CPRI_BASE+7), pMtimerInt->tddOffsetIntCnt); // 
			cpri_csu_start_timing();
		}
	}
			
}

void cpri_test_move_data()
{
}

void Cpri_Header_Rx(void)
{
}
