
#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 res_ptr
)
{
	receiver_sync2symb_t *proc_info = param_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;

    uint32_t symbol_SM_addr_in = equ_data_ddr_ptr;
    uint32_t symbol_SM_addr_out = res_ptr;

    uint32_t *Cfg_DeTransform2 = receiver_symb_config_dm0_ptr + g_receiver_symb_table_param.DeTransform2_CFG12_Offset;
    uint32_t *Cfg_DeTransform4 = receiver_symb_config_dm0_ptr + g_receiver_symb_table_param.DeTransform4_CFG13_Offset;

    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;

    /*****************************************initial*****************************************/
	// double *db_imag = proc_info->transform_para_real;
	// double *db_real = proc_info->transform_para_imag;



	double db_real[4] = {-0.3827, 0.8660, -0.7071, 0.5};
    double db_imag[4] = {0.9239, 0.5,    -0.7071, 0.8660};
 

    for(int iBlk = 0;iBlk < 7;iBlk++){
		ape_csu_task_lookup(DMA_TAG_G2L, 1);
    	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
    		            );

		Transform((int)Cfg_DeTransform4,MPU_ADDR(TransTemp),MPU_ADDR(OutputAddr_Trans), 4,  db_real, db_imag, -1);
	 	SVRReg[0]= MPU_ADDR(Cfg_DeTransform4);
		Transform4Asm(SVRReg);
		WAIT_MPU_STOP;
	 
    	ape_csu_dma_1D_L2G_ch0ch1_transfer((uint64_t)DM_TO_CSU_ADDR((uint32_t)OutputAddr_Trans),
    	    	                            (uint64_t)symbol_SM_addr_out + 4096*4*2*iBlk,
											4096*4*2,
    	    	                            DMA_TAG_L2G,
    	    	                            1);
    }


	 for(int iSym = 0;iSym < 8;iSym++){
		ape_csu_task_lookup(DMA_TAG_G2L, 1);
		ape_csu_dma_2Dto2D_transfer(
				symbol_SM_addr_out + 512*4*iSym,//源地址
				512*4, //源第一维度搬移字节数
				4096*4,  //源第二维度搬移步进字节数
				DM_TO_CSU_ADDR(InputAddr_Trans), //目的地址
				2048, //目的第一维度搬移字节数
				2048,//目的第二维度搬移步进字节数
				28672,//搬移总字节数
				DMA_TAG_G2L, //Tag
				1, //iswait
				2, //reggroup
				DMA_DIR_G2L);

		//TODO:待确认地址合理性，db_real指针指向DM空间，自动变量是IM, 后续可以查表节约时间 20250528
		double db_real_tmp[4];// = *db_real *1.375;
		double db_imag_tmp[4];// = *db_imag *1.375;
		uint32_t loop_idx;
		for (loop_idx = 0; loop_idx < 4; loop_idx++)
		{
			db_real_tmp[loop_idx] = *(db_real + loop_idx) * 1.414;
			db_imag_tmp[loop_idx] = *(db_imag + loop_idx) * 1.414;
		}
    	Transform((int)Cfg_DeTransform2,MPU_ADDR(InputAddr_Trans),MPU_ADDR(TransTemp), 2, &db_real_tmp[0], &db_imag_tmp[0], -1);
    	SVRReg[0] = MPU_ADDR(Cfg_DeTransform2);
    	Transform2Asm(SVRReg);
    	WAIT_MPU_STOP;

		ape_csu_dma_2Dto2D_transfer(
				DM_TO_CSU_ADDR(TransTemp),
				//DM_TO_CSU_ADDR(InputAddr_Trans),
				2048,
				2048,
				symbol_SM_addr_out + 2048*iSym,//源地址
				512*4, //源第一维度搬移字节数
				4096*4,  //源第二维度搬移步进字节数
				28672,//搬移总字节数14*512*4
				DMA_TAG_L2G, //Tag
				1, //iswait
				2, //reggroup
				DMA_DIR_L2G);

    }



    return ;
}








