
#include "receiver_symb_func.h"


void ChannelEst_Proc(
    uint32_t *param_ptr,
    int32_t  *temp_dm0_ptr,
    int32_t  *temp_dm1_ptr

)
{
    //局部变量定义
    int32_t  *cfg_addr;
    uint32_t time_data_ddr_ptr;
    uint32_t time_data_length;
    uint32_t time_data_dm0_ptr = ((((uint32_t)&temp_dm0_ptr[0] + 4095)>>12)<<12);
    uint32_t res_ptr = CHANNELEST_DATA_DDR_PTR;


	v16u32 * SVRReg = (v16u32 *)temp_dm1_ptr;
	SVRReg[0] = (v16u32){0, 0, 0, 0,
					0x40, 0, 0, 0,
					0xff00ff, 0, 0, 0x0000,
					0xffff, 0x6, 0, 0};
	int numSub = 2;
	int sliceIndex[2] = {1024,31268}; // position of pilot
    for(int subIndex=0;subIndex<numSub;subIndex++){

    	time_data_ddr_ptr = COMPENSATED_DATA_DDR_PTR + sliceIndex[subIndex];
    	time_data_length = 1024;
    	ape_csu_task_lookup(DMA_TAG_G2L, 1);
    	ape_csu_dma_1D_G2L_ch0ch1_transfer((uint64_t)time_data_ddr_ptr,
                             (uint64_t)DM_TO_CSU_ADDR(time_data_dm0_ptr),
                             time_data_length*4,
                             DMA_TAG_G2L,
                             0);


    	// Get Configuration and LUT
    	uint32_t *ConfigAddr_channelEst = receiver_symb_config_dm0_ptr + RECEIVER_SYMB_FreOffEst_CFG1_LENGTH + RECEIVER_SYMB_FreOffComp_CFG2_LENGTH + RECEIVER_SYMB_FreOffCordic_CFG3_LENGTH;
    	uint32_t *Pilot_orig_LUT = receiver_symb_config_dm2_ptr;
    	uint32_t *InputPilotAddr = (uint32_t *)time_data_dm0_ptr;
    	uint32_t *channelEstOutAddr = (uint32_t *)(temp_dm1_ptr + 0x0080);

    	ChannelEstImpl(SVRReg,ConfigAddr_channelEst, Pilot_orig_LUT, InputPilotAddr, channelEstOutAddr);

    	WAIT_MPU_STOP;
    	ape_csu_dma_1D_L2G_ch0ch1_transfer((uint64_t)DM_TO_CSU_ADDR((uint32_t)channelEstOutAddr),
    	                            (uint64_t)res_ptr,
									4096*4 ,
    	                            DMA_TAG_L2G,
    	                            1);
    	res_ptr += 0x4000;
    }



}

