/******************************************************************
 * @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"

receiver_symb2bit_t data_send2bit_task;
 /*!   
 * @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;
    //计算完成结果需要存到下面两个buffer地址中的一个
    uint32_t cur_out_ddr_ptr = (0 == g_symb2bit_buffer_sel) ? ((uint32_t)RECEIVER_SYMB2BIT_BUFFER0_ADDR) : ((uint32_t)RECEIVER_SYMB2BIT_BUFFER1_ADDR);
    //更新buffer
    g_symb2bit_buffer_sel = (g_symb2bit_buffer_sel + 1) & 0x1;


    // 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,temp_dm2_ptr,temp_dm3_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;
    // __ucps2_synch(0);
    // __ucps2_synch(0);
    // __ucps2_synch(0);
    // __ucps2_synch(0);
    // __ucps2_synch(0);
    // __ucps2_dbgbreak();

    Transform_Proc(param_ptr, temp_dm0_ptr, temp_dm1_ptr, temp_dm2_ptr, temp_dm3_ptr, cur_out_ddr_ptr);
    
    TRACE(TRACE_RECEIVER_SYMB_ADDR, 3, 6);
    time1 = Time_offset(0);
    TRACE_MAX(TRACE_RECEIVER_SYMB_ADDR, 8, time1 -time0);
    time0 = time1;
    //7.核间消息to APE3/5
    data_send2bit_task.proc_id = para_dm_ptr->proc_id;
    data_send2bit_task.sfn = para_dm_ptr->sfn;
    data_send2bit_task.slot = para_dm_ptr->slot;
    data_send2bit_task.data_ptr = cur_out_ddr_ptr;
    data_send2bit_task.data_length = 57344;//TODO:待确认，单位WORD
    //LOG_ERROR_S("%d 0x%08x %d\n",data_send2bit_task.proc_id,  data_send2bit_task.data_ptr, g_symb2bit_buffer_sel);
#ifdef CORE_ODD
    uint8_t cur_core_id =  APE3_CORE_ID;
#else
    uint8_t cur_core_id =  APE5_CORE_ID;
#endif
    phy_et_msg_send((uint32_t)(&data_send2bit_task),
					     sizeof(receiver_symb2bit_t),
					     UCP4008_KERNEL_INTER,
					     cur_core_id,
					     APE6_CORE_ID,
					     PHY_TASK_RECEIVER_SYMB,
					     PHY_TASK_RECEIVER_BIT);

    return;
}
