
#include "receiver_symb_func.h"

void Transform_Proc(
    uint32_t *param_ptr,
    int32_t  *temp_dm0_ptr,
    int32_t  *temp_dm1_ptr,
	int32_t  *temp_dm2_ptr,
	int32_t  *temp_dm3_ptr
)
{

    //局部变量定义
    uint32_t equ_data_ddr_ptr = CHANNELEQU_DATA_DDR_PTR; // COMPENSATED_DATA_DDR_PTR; // EQU_DATA_DDR_PTR;
   // uint32_t res_ptr = CHANNELEQU_DATA_DDR_PTR;

	v16u32 * SVRReg = (v16u32 *)temp_dm1_ptr;
    uint32_t symbol_SM_addr_in = equ_data_ddr_ptr;
    uint32_t symbol_SM_addr_out = TRANSFORMER_DATA_DDR_PTR;

    uint32_t *Cfg_DeTransform2 = receiver_symb_config_dm0_ptr + RECEIVER_SYMB_FREOFF_CFG_LENGTH + RECEIVER_SYMB_CHANNELEST_CFG_LENGTH + RECEIVER_SYMB_CHANNELEQU_CFG_LENGTH;
    uint32_t *Cfg_DeTransform4 = Cfg_DeTransform2 + RECEIVER_SYMB_DeTransform2_CFG8_LENGTH;

    uint32_t TransTemp =  (uint32_t)(temp_dm1_ptr + 0x1000) ;
    uint32_t OutputAddr_Trans = (uint32_t)temp_dm3_ptr;
    uint32_t InputAddr_Trans = (uint32_t)temp_dm3_ptr;

    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;
    }

    	get_thita(current_state,thita);
    	double* thita1, * thita2, * thita3;
    	thita1 = thita2 = thita;
    	thita3 = thita + 2;

    	for(int iBlk = 0;iBlk < 7;iBlk++){
    		 ape_csu_dma_1D_G2L_ch2ch3_transfer(
    		            (uint64_t)(equ_data_ddr_ptr + 4096*4*2*iBlk),//uint64_t addrSrc
    		            (uint64_t)DM_TO_CSU_ADDR(TransTemp),         //uint64_t addrDst
    		            4096*4*2,                                    //uint32_t dataLen
    		            DMA_TAG_G2L,                                 //uint8_t tag
    		            1                                            //uint8_t isWait
    		            );
    		 ape_csu_task_lookup(DMA_TAG_G2L, 1);
    		 TransformImpl(SVRReg, Cfg_DeTransform4,TransTemp,OutputAddr_Trans, 4, thita3, -1);

    		 ape_csu_dma_1D_L2G_ch0ch1_transfer((uint64_t)DM_TO_CSU_ADDR((uint32_t)OutputAddr_Trans),
    	    	                            (uint64_t)symbol_SM_addr_in + 4096*4*2*iBlk,
											4096*4*2,
    	    	                            DMA_TAG_L2G,
    	    	                            1);
    	 }

    	for(int iSym = 0;iSym < 8;iSym++){
    		//reading 2D data from SM
    		ape_csu_dma_3Dto1D_G2L_ch6ch2_simp_transfer(
    				symbol_SM_addr_in + 512*4*iSym,            //addrSrc
    					512*4,                                 //xNumSrc
    					14,                                    //yNumSrc
    					4096*4,                                //yStepSrc
    					0,                                     //zStepSrc
    					DM_TO_CSU_ADDR(InputAddr_Trans),       //DM_TO_CSU_ADDR(InputAddr_Trans)
    					14*512*4,                              //dataLen
    					DMA_TAG_G2L,                           //tag
    					1);
    		ape_csu_task_lookup(DMA_TAG_G2L, 1);
          	TransformImpl(SVRReg, Cfg_DeTransform2,InputAddr_Trans,TransTemp, 2, thita2, -1);

    		for(int i = 0; i<14;i++){
    			  ape_csu_dma_1D_L2G_ch0ch1_transfer(
    					  (uint64_t)DM_TO_CSU_ADDR(TransTemp + 512*4*i),           //uint64_t addrSrc
						  (uint64_t)(symbol_SM_addr_out + 4096*4*i + 512*4*iSym), //uint64_t addrDst
						  512*4,                                                  //uint32_t dataLen
						  DMA_TAG_L2G,                                            //uint8_t tag
						  1);
    		      ape_csu_task_lookup(DMA_TAG_L2G, 1);
    		  }
    	}
//    	printf("DataTranssss");

    	return ;
}








