/******************************************************************
 * @file  receiver_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 "receiver_symb_func.h"

 /*!   
 * @brief:  Receiver_sync链路处理
 * @author:  HUOHUO
 * @Date:  2024年10月30日
 */
void Receiver_Symb_Proc(
    receiver_sync2symb_t *param_ptr,
    int32_t  *temp_dm0_ptr,
    int32_t  *temp_dm1_ptr,
    int32_t  *temp_dm2_ptr,
    int32_t  *temp_dm3_ptr
)
{
    //局部变量定义
    int32_t  *cfg_addr;
    uint32_t time_data_length;
    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 time_data_dm0_ptr = ((((uint32_t)&temp_dm0_ptr[0] + 4095)>>12)<<12);
    uint32_t time0, time1;

    //data读入
    //获取源数据地址
    receiver_sync2symb_t* para_dm_ptr = param_ptr;

    uint32_t cur_sfn = get_rx_nr_sfn();
    uint32_t cur_slot = get_rx_nr_slot();
    uint32_t cur_time = TIME_NS();
    LOG_ERROR_S("%d %d %d %d %d %d %d 0x%08x 0x%08x %d %d\n", cur_sfn, cur_slot, cur_time, para_dm_ptr->sfn, para_dm_ptr->slot, para_dm_ptr->num_data_section,
      para_dm_ptr->proc_id, para_dm_ptr->data_section0_ptr, para_dm_ptr->data_section1_ptr, para_dm_ptr->data_section0_length, para_dm_ptr->data_section1_length);

    // if(1 == para_dm_ptr->num_data_section)
    // {
    //     ape_csu_dma_1D_G2L_ch0ch1_transfer((uint64_t)(para_dm_ptr->data_section0_ptr),
    //                         (uint64_t)DM_TO_CSU_ADDR(temp_dm0_ptr),
    //                         (para_dm_ptr->data_section0_length)<<2,
    //                         DMA_TAG_G2L,
    //                         1);
    // }
    // else
    // {
    //     ape_csu_dma_1D_G2L_ch0ch1_transfer((uint64_t)(para_dm_ptr->data_section0_ptr),
    //                 (uint64_t)DM_TO_CSU_ADDR(temp_dm0_ptr),
    //                 (para_dm_ptr->data_section0_length)<<2,
    //                 DMA_TAG_G2L,
    //                 0);
    //     ape_csu_dma_1D_G2L_ch2ch3_transfer((uint64_t)(para_dm_ptr->data_section1_ptr),
    //                 (uint64_t)DM_TO_CSU_ADDR(temp_dm0_ptr + (para_dm_ptr->data_section0_length)),
    //                 (para_dm_ptr->data_section1_length)<<2,
    //                 DMA_TAG_G2L,
    //                 1);   
    // }



    return ;

    // //计算结果搬移到外存
    // temp_u32 = 1000;//计算byte数
    // WAIT_MPU_STOP;
    // ape_csu_task_lookup(DMA_TAG_G2L, 1);
    TRACE(TRACE_RECEIVER_SYMB_ADDR, 3, 2);
    time0 = Time_offset(0);
    TRACE_MAX(TRACE_RECEIVER_SYMB_ADDR, 4, time0);

	FreOff_Proc((uint32_t*)para_dm_ptr->data_section0_ptr, temp_dm0_ptr, temp_dm1_ptr, temp_dm2_ptr, temp_dm3_ptr);
    TRACE(TRACE_RECEIVER_SYMB_ADDR, 3, 3);
    time1 = Time_offset(0);
    TRACE_MAX(TRACE_RECEIVER_SYMB_ADDR, 5, time1 -time0);
    time0 = time1;

	ChannelEst_Proc(param_ptr,temp_dm0_ptr,temp_dm1_ptr);
    TRACE(TRACE_RECEIVER_SYMB_ADDR, 3, 4);
    time1 = Time_offset(0);
    TRACE_MAX(TRACE_RECEIVER_SYMB_ADDR, 6, time1 -time0);
    time0 = time1;
	
    ChannelEqu_Proc(param_ptr, temp_dm0_ptr, temp_dm1_ptr, temp_dm2_ptr, temp_dm3_ptr);
    TRACE(TRACE_RECEIVER_SYMB_ADDR, 3, 5);
    time1 = Time_offset(0);
    TRACE_MAX(TRACE_RECEIVER_SYMB_ADDR, 7, time1 -time0);
    time0 = time1;
	
    Transform_Proc(param_ptr, temp_dm0_ptr, temp_dm1_ptr, temp_dm2_ptr, temp_dm3_ptr);
    TRACE(TRACE_RECEIVER_SYMB_ADDR, 3, 6);
    time1 = Time_offset(0);
    TRACE_MAX(TRACE_RECEIVER_SYMB_ADDR, 8, time1 -time0);
    time0 = time1;

#ifdef IDE_TEST
    printf("DataTrans");
#endif

    return ;
    //7.核间消息to APE2
    //需要定义结构体
    receiver_symb2bit_t data_send2bit_task;
    phy_et_msg_send((uint32_t)(&data_send2bit_task),
					     sizeof(receiver_symb2bit_t),
					     UCP4008_KERNEL_INTER,
					     APE5_CORE_ID,
					     APE6_CORE_ID,
					     PHY_TASK_RECIEVER_SYMB,
					     PHY_TASK_RECIEVER_BIT);

    return;
}
