/******************************************************************
 * @file  transmitter_Proc.s.c
 * @brief:    [file description] 
 * @author: HUOHUO
 * @Date 2024年4月20日
 * COPYRIGHT NOTICE: ITTC
 * Change_date         Owner         Change_content
 * 2024年4月20日        HUOHUO       create file

*****************************************************************/
#include "transmitter_func.h"
#include "mem_def.h"
//#include "log_interface.h"

 /*!   
 * @brief:  Transmitter链路处理
 * @author:  HUOHUO
 * @Date:  2024年4月20日
 */
void Transmitter_Proc(
    uint32_t *param_ptr,//for inputdata
    int32_t  *temp_dm0_ptr,
    int32_t  *temp_dm1_ptr,
    int32_t  *temp_dm2_ptr,
    int32_t  *temp_dm3_ptr,
    uint32_t cur_slot, 
    uint32_t cur_sfn   
)
{
    //局部变量定义
    int32_t  *cfg_addr;// 配置地址指针
    uint32_t source_bit_ddr_ptr;// 配置地址指针
    uint32_t source_bit_length;// 源比特数据的长度（单位：bytes）
    int32_t  *output_data_ptr;// 最终输出数据地址(dm)
    uint32_t output_data_ptr_ddr_even = JESD_NRFDD_TX_SLOT_EVEN_DATA_ADDR;// 最终输出数据地址(ddr)
    uint32_t output_data_ptr_ddr_odd = JESD_NRFDD_TX_SLOT_ODD_DATA_ADDR;// 最终输出数据地址(ddr)
    uint32_t output_data_ptr_ddr;
    uint32_t mpu_temp_dm0_ptr;
    uint32_t mpu_temp_dm1_ptr;
    uint32_t mpu_temp_dm2_ptr;
    uint32_t mpu_temp_dm3_ptr;
    uint32_t temp_u32;
    uint32_t source_bit_dm0_ptr = ((((uint32_t)&temp_dm0_ptr[0] + 4095)>>12)<<12);
    uint32_t res_ptr = TRANSMITTER_OUT;

    mpu_temp_dm0_ptr = (uint32_t)(temp_dm0_ptr);
    mpu_temp_dm1_ptr = (uint32_t)(temp_dm1_ptr);
    mpu_temp_dm2_ptr = (uint32_t)(temp_dm2_ptr);
    mpu_temp_dm3_ptr = (uint32_t)(temp_dm3_ptr);

    //source_bit读入
    //获取源数据地址
/*
    //**********************************for test begin**********************************
    source_bit_ddr_ptr = (uint32_t)*param_ptr;
    source_bit_length = (uint32_t)((*(param_ptr + 1) +7)>>3);//计算byte数

    //等待 DMA 通道可用
    ape_csu_task_lookup(DMA_TAG_G2L, 1);
    //执行 DMA 传输：从 DDR（全局内存）到本地内存（DM）
    ape_csu_dma_1D_G2L_ch0ch1_transfer((uint64_t)source_bit_ddr_ptr,
                             (uint64_t)DM_TO_CSU_ADDR(source_bit_dm0_ptr),
                             source_bit_length*2*4,
                             DMA_TAG_G2L,
                             0);
                             
    //**********************************for test end**********************************
*/

    //**********************************for board begin**********************************
   source_bit_ddr_ptr = (SOURCE_DATA_DDR_ADDR + 16016 * cur_slot);  // 0-19 帧数循环
   // source_bit_ddr_ptr = (SOURCE_DATA_DDR_ADDR);  //固定读第一帧数据
    //等待 DMA 通道可用
    ape_csu_task_lookup(DMA_TAG_G2L, 1);
    //执行 DMA 传输：从 DDR（全局内存）到本地内存（DM）
    ape_csu_dma_1D_G2L_ch0ch1_transfer((uint64_t)source_bit_ddr_ptr,
                             (uint64_t)DM_TO_CSU_ADDR(source_bit_dm0_ptr),
                             SOURCE_DATA_BYTE_LENGTH,
                             DMA_TAG_G2L,
                             0);
    //**********************************for board end**********************************

    /*
    //数据附加CRC24A-------------------------------------------------------------------------------------------------
    //获取配置和临时数据的地址
    cfg_addr = (int32_t *)transmitter_config_dm1_ptr + g_transmitter_table_param.CRC24BCFGOffset;
    source_bit_length = (uint32_t)*(param_ptr + 1);//取bit数
    mpu_temp_dm2_ptr = (uint32_t)(transmitter_config_dm2_ptr + g_transmitter_table_param.CRC24BLUT1Offset);
    mpu_temp_dm3_ptr = (uint32_t)(transmitter_config_dm1_ptr + g_transmitter_table_param.CRC24BLUT2Offset);
    //等待之前的 DMA 传输完成
    ape_csu_task_lookup(DMA_TAG_G2L, 1);//保证source_bit_dm0_ptr搬移完成
    //调用 CRC24 函数，计算并附加 CRC 校验码
    CRC24((int)(cfg_addr),
        source_bit_length,
        MPU_ADDR(source_bit_dm0_ptr),
        MPU_ADDR(mpu_temp_dm2_ptr),//0x4000对齐
        MPU_ADDR(mpu_temp_dm3_ptr)//0x4000对齐
        );
    //等待 MPU 执行完成
    WAIT_MPU_STOP;

    //设置 SVR 寄存器并调用汇编函数执行 CRC24 操作
    SVRReg[0] = MPU_ADDR(cfg_addr);
    CRC24Asm(SVRReg);
    */
    //defination----------------------------------------------------------------------------------------------
    //LDPCCBSegment------------------------------------------------------------------------------------------------------------
    volatile int NumCB = 28;	//number of CB
    volatile int K1 = 4576;   //length of every CB(bits)
    volatile int K = 14144;// length of every CB after Segment(bits)
    volatile int L = 0;       //without crc,L=0
    volatile int NullLen_LDPCCBSegment,CBSize;
    uint32_t InputAddr_LDPCCBSegment,OutputAddr_LDPCCBSegment;
    int i;
    NullLen_LDPCCBSegment = K-K1;//留出空余地址存放结果
    CBSize = K1-L;

	//LDPCEncoding(everyCB in:4567bits out:14144bits)------------------------------------------------------------------------------------------------------------
    uint32_t InputAddr_LDPCEncoding,OutputAddr_LDPCEncoding;
    uint32_t BG1HMatrixAddr;
    int Basegraph = 1;
    int ZcLen = K1/22;//码块长度 ; zclen=208
    int index = 6;

	//RMLDPC------------------------------------------------------------------------------------------------------------
    int encoded_nullen = ZcLen*2/8;
    int bitsel_nullen = 173*4;
    int encoded_len = 14144/8;
    int rm_efect_len = 8192/8;
    volatile int EkLength = 8192;//单个CB块RM处理后的比特数目;
    uint32_t rm_datain_ptr;
    uint32_t rm_dataout_ptr;
    
    //Final Frame Combination(DM2)------------------------------------------------------------------------------------------------------------
    int PILOT_TRANS_LEN = 1024*4;          // PilotTrans 数据
	int DATA_BLOCK_LEN = 4096*4;			//数据块长度(word)
    int CP_LEN_1024 = 1024*4;               // 循环前缀长度 (用于 PilotTrans)
    int CP_LEN_68 = 68*4;                   // 循环前缀长度 (用于 OutputAddr_Trans)
    int CP_LEN_72 = 72*4;                   // 循环前缀长度 (特殊的 72 字节 CP)
 /*
    uint32_t InputAddr_RMLDPC,OutputAddr_RMBitSelLDPC,OutputAddr_RMLDPC;
    volatile int k0 = 11648;//0 17Zc 33Zc 56Zc
    volatile int EncodedCBSizes = (68-2)*ZcLen;//(68-2)*ZcLen 单码块LDPC编码输出长度 Ncb
    volatile int EkLength = 8192;//单个CB块RM处理后的比特数目;
    volatile int Qm_RMLDPC = 4;
    volatile int NullPos = K1-2*ZcLen;//Nullbit的起始位置 K'-2ZC
    volatile int NullLen = 22*ZcLen-K1;//K - K' K：CB分块大小(编码前长度)   K'值=(B+C*L)/C
*/
    for(i=0;i<NumCB;i++)
    {
        //LDPCCBSegment----------------------------------------------------------------------------------------------------------------------------------------------------------
        //获取配置和临时数据的地址
        
        cfg_addr = (int32_t *)(transmitter_config_dm1_ptr + g_transmitter_table_param.ConfigCBSegment_CFG1_Offset);
        InputAddr_LDPCCBSegment = MPU_ADDR(source_bit_dm0_ptr) + i*(CBSize>>3);//DM0
        OutputAddr_LDPCCBSegment = MPU_ADDR(mpu_temp_dm1_ptr) + i*((K>>3)); //DM1
        //等待之前的 DMA 传输完成
        ape_csu_task_lookup(DMA_TAG_G2L, 1);
        //int CBSegment(int *InputAddr,int *OutputAddr,int TmpCBLen,int NullLen,int *ConfigBaseAddr)
        CBSegment(
            (int *)InputAddr_LDPCCBSegment,//MPU DM0
            (int *)OutputAddr_LDPCCBSegment,//MPU DM1
            CBSize,
            NullLen_LDPCCBSegment,
            cfg_addr//SPU
            );

        SVRReg[0] = MPU_ADDR(cfg_addr);
        LDPCCBSegmentAsm(SVRReg);
        //等待 MPU 执行完成
        WAIT_MPU_STOP;
       
        TRACE(TRACE_TRANSMITTER_ADDR, 3, 100+i); 
        //LDPCEncoding(BG1)----------------------------------------------------------------------------------------------------------------------------------------------------------
        //获取配置和临时数据的地址
        
        cfg_addr = (int32_t *)transmitter_config_dm1_ptr + g_transmitter_table_param.Config384Pre_CFG4_Offset;
        BG1HMatrixAddr = (uint32_t)(transmitter_config_dm1_ptr + g_transmitter_table_param.CalBG1HMatrix_LUT1_Offset);//BG1HMatrix

        InputAddr_LDPCEncoding = OutputAddr_LDPCCBSegment;//DM1
        OutputAddr_LDPCEncoding = InputAddr_LDPCEncoding;
        
        //WAIT_MPU_STOP;
        Ldpc384Pre(
            (int *)cfg_addr,//SPU
            MPU_ADDR(BG1HMatrixAddr)+index*274*2,//MPU
            ZcLen,
            Basegraph,
            MPU_ADDR(mpu_temp_dm2_ptr),//MPU
            MPU_ADDR(mpu_temp_dm3_ptr)//MPU
            );
        SVRReg[0] = MPU_ADDR(cfg_addr);
        LDPCEnCoding384PreAsm(SVRReg);
        WAIT_MPU_STOP;
        TRACE(TRACE_TRANSMITTER_ADDR, 3, 200+i); 
        //获取配置和临时数据的地址
        cfg_addr = (int32_t *)transmitter_config_dm1_ptr + g_transmitter_table_param.Config384BG1_CFG5_Offset;
        //Ldpc384BG1(cfg_addr, MPU_ADDR(OutputData_LDPCCBSegment), MPU_ADDR(mpu_temp_dm2_ptr), MPU_ADDR(mpu_temp_dm3_ptr), ZcLen);
        Ldpc384BG1(
            (int *)cfg_addr,//SPU
            InputAddr_LDPCEncoding,//MPU
            MPU_ADDR(mpu_temp_dm2_ptr),//MPU
            MPU_ADDR(mpu_temp_dm3_ptr),//MPU
            ZcLen
            );
        SVRReg[0] = MPU_ADDR(cfg_addr);
        LDPCEnCoding384BG1Asm(SVRReg);
        WAIT_MPU_STOP;
        TRACE(TRACE_TRANSMITTER_ADDR, 3, 300+i); 
        //RMLDPC----------------------------------------------------------------------------------------------------------------------------------------------------------
        /*
        //获取配置和临时数据的地址
        cfg_addr = (int32_t *)transmitter_config_dm1_ptr + g_transmitter_table_param.ConfigRMBitSelLDPC_CFG7_Offset;
        mpu_temp_dm2_ptr = (uint32_t)(temp_dm2_ptr);//TempAddr2
        mpu_temp_dm3_ptr = (uint32_t)(temp_dm3_ptr);//TempAddr1
        mpu_temp_dm0_ptr = (uint32_t)(temp_dm0_ptr);//outputRMBitSelLDPCADDR DM1
        mpu_temp_dm1_ptr = (uint32_t)(temp_dm1_ptr);//OutputAddr_RMLDPC
        InputAddr_RMLDPC = OutputAddr_LDPCEncoding;
        OutputAddr_RMBitSelLDPC = MPU_ADDR(mpu_temp_dm0_ptr + 8);
        OutputAddr_RMLDPC = MPU_ADDR(mpu_temp_dm1_ptr + i*(EkLength>>3));
        RMBitSelLDPC(
            (int)cfg_addr,//SPU
            EkLength,
            NullPos,
            NullLen,
            k0,
            EncodedCBSizes,
            //MPU_ADDR(OutputData_LDPCCBSegment+ZcLen*2),//inputdataAddr
            InputAddr_RMLDPC+(ZcLen*2/32),//MPU
            MPU_ADDR(mpu_temp_dm2_ptr),//MPU
            MPU_ADDR(mpu_temp_dm3_ptr),//MPU
            //MPU_ADDR(Temp2OutputData+8)
            OutputAddr_RMBitSelLDPC//MPU
            );
        SVRReg[0] = MPU_ADDR(cfg_addr);
        RMBitSelLDPCAsm(SVRReg);
        WAIT_MPU_STOP;

        //获取配置和临时数据的地址
        cfg_addr = (int32_t *)transmitter_config_dm1_ptr + g_transmitter_table_param.ConfigRMBitILLDPC_CFG8_Offset;
        RMBitILLDPC(
            (int)cfg_addr,//SPU
            EkLength,
            Qm_RMLDPC,
            //MPU_ADDR(Temp2OutputData+8),//MPU
            OutputAddr_RMBitSelLDPC,
            //MPU_ADDR(OutputData_RMLDPC+i*(EkLength>>3))//MPU
            OutputAddr_RMLDPC
            );
        SVRReg[0] = MPU_ADDR(cfg_addr);
        RMBitILLDPCAsm(SVRReg);
        WAIT_MPU_STOP;
        */
    }
    /*
    for(i=0;i<NumCB;i++){
		//RMLDPC----------------------------------------------------------------------------------------------------------------------------------------------------------
		mpu_temp_dm0_ptr = (uint32_t)(temp_dm0_ptr);
		mpu_temp_dm1_ptr = (uint32_t)(temp_dm1_ptr);
		rm_datain_ptr = mpu_temp_dm1_ptr + encoded_nullen + encoded_len*i;
		rm_dataout_ptr = mpu_temp_dm0_ptr + rm_efect_len*i;

		memcpy((int32_t *)rm_dataout_ptr, (int32_t *)rm_datain_ptr, rm_efect_len); //442个word中舍去前13个与后173个
    }*/
    cfg_addr = (int32_t *)transmitter_config_dm1_ptr + g_transmitter_table_param.ConfigByteCopy_CFG1_Offset;
    for(i=0;i<NumCB;i++){
        rm_datain_ptr = mpu_temp_dm1_ptr + encoded_nullen + encoded_len*i;
		rm_dataout_ptr = mpu_temp_dm0_ptr + rm_efect_len*i;

               ByteCopy((int)cfg_addr, MPU_ADDR(rm_datain_ptr),MPU_ADDR(rm_dataout_ptr),rm_efect_len);
        SVRReg[0] = MPU_ADDR(cfg_addr);
        ByteCopyAsm(SVRReg);
        WAIT_MPU_STOP;
        TRACE(TRACE_TRANSMITTER_ADDR, 3, 400+i); 
    }
    
    // 16QAM--------------------------------------------------------------------------------------------------------------------------------------------------------------
    uint32_t InputAddr_16QAM,OutputAddr_16QAM;
    uint32_t temp_16QAMOUT_SM_addr = TRANSMITTER_OUT;
    int BitLen = EkLength*2;//这里分成14块进行
    int Qm_16QAM = 4;
    int after_16QAM_bit_len = 4096*32;//这里分成14块进行,every segment has 4096*32 bits

    //获取配置和临时数据的地址
    cfg_addr = (int32_t *)transmitter_config_dm1_ptr + g_transmitter_table_param.ConfigModuQAM16_CFG10_Offset;
    InputAddr_16QAM = mpu_temp_dm0_ptr;
    OutputAddr_16QAM = mpu_temp_dm2_ptr;//57344*32 bits

    for(i=0;i<NumCB/2;i++){//这里分成14块进行
        InputAddr_16QAM = mpu_temp_dm0_ptr + BitLen/8*i;
        Mudulation(
        (int)cfg_addr,
        MPU_ADDR(InputAddr_16QAM),
        MPU_ADDR(OutputAddr_16QAM),
        BitLen,
        Qm_16QAM
        );
        SVRReg[0] = MPU_ADDR(cfg_addr);
        ModulationAsm(SVRReg);
        WAIT_MPU_STOP;
        TRACE(TRACE_TRANSMITTER_ADDR, 3, 500+i); 
        ape_csu_dma_1D_L2G_ch0ch1_transfer(
            (uint64_t)DM_TO_CSU_ADDR(OutputAddr_16QAM),//Source address of the data
			(uint64_t)temp_16QAMOUT_SM_addr,//Destination address where the data will be copied
            after_16QAM_bit_len/8,//Length of data to be copied (in bytes)
            DMA_TAG_L2G,//A tag, possibly to track the transfer or associate it with a specific task
            1//A flag indicating whether the function should wait for the transfer to complete
            );
        temp_16QAMOUT_SM_addr = temp_16QAMOUT_SM_addr + after_16QAM_bit_len/8;
    }
    
  
    // Transform--------------------------------------------------------------------------------------------------------------------------------------------------------------
    uint32_t InputAddr_Trans,OutputAddr_Trans;
    uint32_t TransTemp,PilotData,PilotTrans;
    uint32_t TRANSMOUT_symbol_SM_addr_in = TRANSMITTER_OUT;//SM
    uint32_t TRANSMOUT_symbol_SM_addr_out = TRANSMITTER_OUT + 14*4096*4 + 4*1024;
    uint32_t TRANSMOUT_DATA_SM_addr_out = TRANSMOUT_symbol_SM_addr_out + 14*4096*4 + 4*1024;
    double thita[6] = {0.435,2.784,1.864,1.211,2.546,2.011};




	double* thita1, * thita2, * thita3;
	thita1 = thita2 = thita;
	thita3 = thita + 2;

    cfg_addr = (int32_t *)transmitter_config_dm1_ptr + g_transmitter_table_param.TransformConfig_8_CFG3_Offset;
    PilotData =transmitter_config_dm1_ptr + g_transmitter_table_param.Pilot_Data_Offset;
    PilotTrans = mpu_temp_dm3_ptr;
    Transform((int)cfg_addr,MPU_ADDR(PilotData),MPU_ADDR(PilotTrans), 8, thita1, 1);
    SVRReg[0] = MPU_ADDR(cfg_addr);
    Transform8Asm(SVRReg);
    WAIT_MPU_STOP;
    // TODO 03
    if(cur_slot % 2 == 0)
        output_data_ptr_ddr = output_data_ptr_ddr_even;  // output_data_ptr_ddr = output_data_ptr_ddr_odd;
    else
        output_data_ptr_ddr = output_data_ptr_ddr_odd;   // output_data_ptr_ddr = output_data_ptr_ddr_even;
    ape_csu_dma_1D_L2G_ch0ch1_transfer(
            (uint64_t)DM_TO_CSU_ADDR(mpu_temp_dm3_ptr),//uint64_t addrSrc
            (uint64_t)(output_data_ptr_ddr),//uint64_t addrDst
            1024*4,//uint32_t dataLen 
            DMA_TAG_L2G,//uint8_t tag
            1//uint8_t isWait
            );
    ape_csu_dma_1D_L2G_ch2ch3_transfer(
            (uint64_t)DM_TO_CSU_ADDR(mpu_temp_dm3_ptr),//uint64_t addrSrc
            (uint64_t)(output_data_ptr_ddr + CP_LEN_1024),//uint64_t addrDst
            1024*4,//uint32_t dataLen 
            DMA_TAG_L2G,//uint8_t tag
            1//uint8_t isWait
            );
        ape_csu_dma_1D_L2G_ch0ch1_transfer(
            (uint64_t)DM_TO_CSU_ADDR(mpu_temp_dm3_ptr + PILOT_TRANS_LEN - CP_LEN_72),//uint64_t addrSrc
            (uint64_t)(output_data_ptr_ddr + CP_LEN_1024 + PILOT_TRANS_LEN + (CP_LEN_68 + DATA_BLOCK_LEN)*7),//uint64_t addrDst
            72*4,//uint32_t dataLen 
            DMA_TAG_L2G,//uint8_t tag
            1//uint8_t isWait
            );
        ape_csu_dma_1D_L2G_ch2ch3_transfer(
            (uint64_t)DM_TO_CSU_ADDR(mpu_temp_dm3_ptr),//uint64_t addrSrc
            (uint64_t)(output_data_ptr_ddr + CP_LEN_1024 + PILOT_TRANS_LEN + (CP_LEN_68 + DATA_BLOCK_LEN)*7 + CP_LEN_72),//uint64_t addrDst
            1024*4,//uint32_t dataLen 
            DMA_TAG_L2G,//uint8_t tag
            1//uint8_t isWait
            );

	//symbol transform
	cfg_addr = (int32_t *)transmitter_config_dm1_ptr + g_transmitter_table_param.TransformConfig_2_CFG1_Offset;
	InputAddr_Trans = mpu_temp_dm2_ptr;//DM2
	TransTemp = mpu_temp_dm3_ptr;//DM3

   for(int iSym = 0;iSym < 8;iSym++){
    //reading 2D data from SM

        ape_csu_dma_2Dto2D_transfer(
        TRANSMOUT_symbol_SM_addr_in + 512*4*iSym,//源地址 
        512*4, //源第一维度搬移字节数 
        4096*4,  //源第二维度搬移步进字节数
        DM_TO_CSU_ADDR(InputAddr_Trans), //目的地址
        2048, //目的第一维度搬移字节数
        2048,//目的第二维度搬移步进字节数
        28672,//搬移总字节数
        DMA_TAG_G2L, //Tag
        1, //iswait
        DMA_REG_GROUP2, //reggroup
        DMA_DIR_G2L);//G2L

 
    //*********Important:import data 'InputData' to DM at here
        //'InputData' size is 14*512 point equals to 14*512*32bit
        //WAIT_MPU_STOP;
      
        Transform((int)cfg_addr,MPU_ADDR(InputAddr_Trans),MPU_ADDR(TransTemp), 2, thita2, 1);
        SVRReg[0] = MPU_ADDR(cfg_addr);
        Transform2Asm(SVRReg);
        WAIT_MPU_STOP;
      
        TRACE(TRACE_TRANSMITTER_ADDR, 3, 600+iSym); 
    //*********Important:transfer SM data 'TransTemp' out at here
        ape_csu_dma_2Dto2D_transfer(
        DM_TO_CSU_ADDR(TransTemp),
        //DM_TO_CSU_ADDR(InputAddr_Trans),
        2048,
        2048,
        TRANSMOUT_symbol_SM_addr_out + 2048*iSym,//源地址 
        512*4, //源第一维度搬移字节数 
        4096*4,  //源第二维度搬移步进字节数
        28672,//搬移总字节数14*512*4
        DMA_TAG_L2G, //Tag
        1, //iswait
        DMA_REG_GROUP2, //reggroup
        DMA_DIR_L2G);//L2G    
    //'TransTemp' size is 14*512 point equals to 14*512*32bit
    }
  
	//data transform
	cfg_addr = (int32_t *)transmitter_config_dm1_ptr + g_transmitter_table_param.TransformConfig_4_CFG2_Offset;
	TransTemp = mpu_temp_dm3_ptr;//DM3
	OutputAddr_Trans = mpu_temp_dm2_ptr;//DM2

    for(int iBlk = 0; iBlk < 7; iBlk++){
    //read data from SM
    //*********Important:import data 'TransTemp' to DM at here
        ape_csu_dma_1D_G2L_ch2ch3_transfer(
            (uint64_t)(TRANSMOUT_symbol_SM_addr_out + 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
            );

        //data block size is 2*4096 point equals to 2*4096*32bit
        Transform((int)cfg_addr,MPU_ADDR(TransTemp),MPU_ADDR(OutputAddr_Trans), 4, thita3, 1);
        SVRReg[0] = MPU_ADDR(cfg_addr);
        Transform4Asm(SVRReg);
        WAIT_MPU_STOP;
        TRACE(TRACE_TRANSMITTER_ADDR, 3, 700+iBlk); 

    //*********Important:import data 'OutData' to RM-DDR at here 直接先搬到射频模块DDR预定位置
    //由于OutputAddr_Trans每次有两组4096，因此按照下面方式传输

      if(iBlk < 3)
      {
            ape_csu_dma_1D_L2G_ch0ch1_transfer( 
                    (uint64_t)DM_TO_CSU_ADDR(OutputAddr_Trans + DATA_BLOCK_LEN - CP_LEN_68),//uint64_t addrSrc
                    (uint64_t)(output_data_ptr_ddr + CP_LEN_1024 + PILOT_TRANS_LEN + (DATA_BLOCK_LEN + CP_LEN_68)*2*iBlk),//uint64_t addrDst
                    68*4,//uint32_t dataLen 
                    DMA_TAG_L2G,//uint8_t tag
                    1//uint8_t isWait
                    );
                //Add 2ed 68 CP
                ape_csu_dma_1D_L2G_ch0ch1_transfer(
                    (uint64_t)DM_TO_CSU_ADDR(OutputAddr_Trans + DATA_BLOCK_LEN*2 - CP_LEN_68),//uint64_t addrSrc
                    (uint64_t)(output_data_ptr_ddr + CP_LEN_1024 + PILOT_TRANS_LEN + (DATA_BLOCK_LEN + CP_LEN_68)*(2*iBlk + 1)),//uint64_t addrDst
                    68*4,//uint32_t dataLen 
                    DMA_TAG_L2G,//uint8_t tag
                    1//uint8_t isWait
                    );    
                //Add 1st 4096 DATA
                ape_csu_dma_1D_L2G_ch2ch3_transfer(
                    (uint64_t)DM_TO_CSU_ADDR(OutputAddr_Trans),//uint64_t addrSrc
                    (uint64_t)(output_data_ptr_ddr + CP_LEN_1024 + PILOT_TRANS_LEN + (DATA_BLOCK_LEN + CP_LEN_68)*2*iBlk + CP_LEN_68),//uint64_t addrDst
                    4096*4,//uint32_t dataLen 
                    DMA_TAG_L2G,//uint8_t tag
                    1//uint8_t isWait
                    );
                //Add 2ed 4096 DATA
                ape_csu_dma_1D_L2G_ch2ch3_transfer(
                    (uint64_t)DM_TO_CSU_ADDR(OutputAddr_Trans + DATA_BLOCK_LEN),//uint64_t addrSrc
                    (uint64_t)(output_data_ptr_ddr + CP_LEN_1024 + PILOT_TRANS_LEN + (DATA_BLOCK_LEN + CP_LEN_68)*(2*iBlk + 1) + CP_LEN_68),//uint64_t addrDst
                    4096*4,//uint32_t dataLen 
                    DMA_TAG_L2G,//uint8_t tag
                    1//uint8_t isWait
                    );
            }else if(iBlk == 3){//第7，8个4096特殊处理
                //Add 1st 68 CP 第7个4096
                ape_csu_dma_1D_L2G_ch0ch1_transfer(
                    (uint64_t)DM_TO_CSU_ADDR(OutputAddr_Trans + DATA_BLOCK_LEN - CP_LEN_68),//uint64_t addrSrc
                    (uint64_t)(output_data_ptr_ddr + CP_LEN_1024 + PILOT_TRANS_LEN + (DATA_BLOCK_LEN + CP_LEN_68)*2*iBlk),//uint64_t addrDst
                    68*4,//uint32_t dataLen 
                    DMA_TAG_L2G,//uint8_t tag
                    1//uint8_t isWait
                    );
                //Add 2ed 68 CP 第8个4096
                ape_csu_dma_1D_L2G_ch0ch1_transfer(
                    (uint64_t)DM_TO_CSU_ADDR(OutputAddr_Trans + DATA_BLOCK_LEN*2 - CP_LEN_68),//uint64_t addrSrc
                    (uint64_t)(output_data_ptr_ddr + CP_LEN_1024 + PILOT_TRANS_LEN + (DATA_BLOCK_LEN + CP_LEN_68)*(2*iBlk + 1) + CP_LEN_72 + PILOT_TRANS_LEN),//uint64_t addrDst
                    68*4,//uint32_t dataLen 
                    DMA_TAG_L2G,//uint8_t tag
                    1//uint8_t isWait
                    );    
                //Add 1st 4096 DATA 第7个4096
                ape_csu_dma_1D_L2G_ch2ch3_transfer(
                    (uint64_t)DM_TO_CSU_ADDR(OutputAddr_Trans),//uint64_t addrSrc
                    (uint64_t)(output_data_ptr_ddr + CP_LEN_1024 + PILOT_TRANS_LEN + (DATA_BLOCK_LEN + CP_LEN_68)*2*iBlk + CP_LEN_68),//uint64_t addrDst
                    4096*4,//uint32_t dataLen 
                    DMA_TAG_L2G,//uint8_t tag
                    1//uint8_t isWait
                    );
                //Add 2ed 4096 DATA 第8个4096
                ape_csu_dma_1D_L2G_ch2ch3_transfer(
                    (uint64_t)DM_TO_CSU_ADDR(OutputAddr_Trans + DATA_BLOCK_LEN),//uint64_t addrSrc
                    (uint64_t)(output_data_ptr_ddr + CP_LEN_1024 + PILOT_TRANS_LEN + (DATA_BLOCK_LEN + CP_LEN_68)*(2*iBlk + 1) + CP_LEN_68 + CP_LEN_72 + PILOT_TRANS_LEN),//uint64_t addrDst
                    4096*4,//uint32_t dataLen 
                    DMA_TAG_L2G,//uint8_t tag
                    1//uint8_t isWait
                    );
            }else{
                ape_csu_dma_1D_L2G_ch0ch1_transfer(
                    (uint64_t)DM_TO_CSU_ADDR(OutputAddr_Trans + DATA_BLOCK_LEN - CP_LEN_68),//uint64_t addrSrc
                    (uint64_t)(output_data_ptr_ddr + CP_LEN_1024 + PILOT_TRANS_LEN + (DATA_BLOCK_LEN + CP_LEN_68)*2*iBlk + CP_LEN_72 + PILOT_TRANS_LEN),//uint64_t addrDst
                    68*4,//uint32_t dataLen 
                    DMA_TAG_L2G,//uint8_t tag
                    1//uint8_t isWait
                    );
                ape_csu_dma_1D_L2G_ch0ch1_transfer(
                    (uint64_t)DM_TO_CSU_ADDR(OutputAddr_Trans + DATA_BLOCK_LEN*2 - CP_LEN_68),//uint64_t addrSrc
                    (uint64_t)(output_data_ptr_ddr + CP_LEN_1024 + PILOT_TRANS_LEN + (DATA_BLOCK_LEN + CP_LEN_68)*(2*iBlk + 1) + CP_LEN_72 + PILOT_TRANS_LEN),//uint64_t addrDst
                    68*4,//uint32_t dataLen 
                    DMA_TAG_L2G,//uint8_t tag
                    1//uint8_t isWait
                    );
                ape_csu_dma_1D_L2G_ch2ch3_transfer(
                    (uint64_t)DM_TO_CSU_ADDR(OutputAddr_Trans),//uint64_t addrSrc
                    (uint64_t)(output_data_ptr_ddr + CP_LEN_1024 + PILOT_TRANS_LEN + (DATA_BLOCK_LEN + CP_LEN_68)*2*iBlk + CP_LEN_68 + CP_LEN_72 + PILOT_TRANS_LEN),//uint64_t addrDst
                    4096*4,//uint32_t dataLen 
                    DMA_TAG_L2G,//uint8_t tag
                    1//uint8_t isWait
                    );
                ape_csu_dma_1D_L2G_ch2ch3_transfer(
                    (uint64_t)DM_TO_CSU_ADDR(OutputAddr_Trans + DATA_BLOCK_LEN),//uint64_t addrSrc
                    (uint64_t)(output_data_ptr_ddr + CP_LEN_1024 + PILOT_TRANS_LEN + (DATA_BLOCK_LEN + CP_LEN_68)*(2*iBlk + 1) + CP_LEN_68 + CP_LEN_72 + PILOT_TRANS_LEN),//uint64_t addrDst
                    4096*4,//uint32_t dataLen 
                    DMA_TAG_L2G,//uint8_t tag
                    1//uint8_t isWait
                    );
            }
        
   
        //测试TRANS输出结果是否正常
        //ape_csu_dma_1D_L2G_ch0ch1_transfer(
        //    (uint64_t)DM_TO_CSU_ADDR(OutputAddr_Trans),//uint64_t addrSrc
        //    (uint64_t)(TRANSMOUT_DATA_SM_addr_out + 4096*4*2*iBlk),//uint64_t addrDst
        //    4096*4*2,//uint32_t dataLen 
        //    DMA_TAG_L2G,//uint8_t tag
        //    1//uint8_t isWait
        //    );
        
        //'OutData' size is 2*4096 point equals to 2*4096*32bit
    }
    //**********************pilot trans**********************




    return;
}
