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

*****************************************************************/
#include "receiver_symb_func.h"

 /*!   
 * @brief:  Receiver任务启动前的初始化工作
 *          初始化全局参数，ddr查找表搬入SM
 * @author:  HUOHUO
 * @Date:  2024年10月30日
 */
void Receiver_Symb_Init()
{
    int32_t  ret;
    uint32_t lutDdrAddr,idx;

    //DM0
    g_receiver_symb_table_param.FreOffEst_CFG1_Offset = 0;
    g_receiver_symb_table_param.FreOffComp_CFG2_Offset = g_receiver_symb_table_param.FreOffEst_CFG1_Offset + RECEIVER_SYMB_FreOffEst_CFG1_LENGTH;
    g_receiver_symb_table_param.FreOffCordic_CFG3_Offset =  g_receiver_symb_table_param.FreOffComp_CFG2_Offset + RECEIVER_SYMB_FreOffComp_CFG2_LENGTH;
    g_receiver_symb_table_param.ChannelEst_CFG4_Offset = g_receiver_symb_table_param.FreOffCordic_CFG3_Offset + RECEIVER_SYMB_FreOffCordic_CFG3_LENGTH;
    g_receiver_symb_table_param.Fft4096Int32_CFG5_Offset = g_receiver_symb_table_param.ChannelEst_CFG4_Offset + RECEIVER_SYMB_ChannelEst_CFG4_LENGTH;
    g_receiver_symb_table_param.EQ21Part1_CFG6_Offset = g_receiver_symb_table_param.Fft4096Int32_CFG5_Offset + RECEIVER_SYMB_Fft4096Int32_CFG5_LENGTH;
    g_receiver_symb_table_param.EQ1Part2_CFG7_Offset  = g_receiver_symb_table_param.EQ21Part1_CFG6_Offset  +  RECEIVER_SYMB_EQ21Part1_CFG6_LENGTH;
    g_receiver_symb_table_param.IFFT4096_CFG8_Offset = g_receiver_symb_table_param.EQ1Part2_CFG7_Offset + RECEIVER_SYMB_EQ1Part2_CFG7_LENGTH;
    g_receiver_symb_table_param.IFFTDatTurn_CFG9_Offset = g_receiver_symb_table_param.IFFT4096_CFG8_Offset + RECEIVER_SYMB_IFFT4096_CFG8_LENGTH;
    g_receiver_symb_table_param.Agcshift_CFG10_Offset = g_receiver_symb_table_param.IFFTDatTurn_CFG9_Offset + RECEIVER_SYMB_IFFT4096_TURN_CFG9_LENGTH;
    g_receiver_symb_table_param.AddCP_CFG11_Offset = g_receiver_symb_table_param.Agcshift_CFG10_Offset + RECEIVER_SYMB_AgcShiftFft_CFG10_LENGTH;
    g_receiver_symb_table_param.DeTransform2_CFG12_Offset = g_receiver_symb_table_param.AddCP_CFG11_Offset + RECEIVER_SYMB_AddCP_CFG11_LENGTH;
    g_receiver_symb_table_param.DeTransform4_CFG13_Offset = g_receiver_symb_table_param.DeTransform2_CFG12_Offset + RECEIVER_SYMB_DeTransform2_CFG12_LENGTH;
    g_receiver_symb_table_param.Transform8_CFG14_Offset = g_receiver_symb_table_param.DeTransform4_CFG13_Offset + RECEIVER_SYMB_DeTransform4_CFG13_LENGTH;
    g_receiver_symb_table_param.ByteSet_CFG15_Offset = g_receiver_symb_table_param.Transform8_CFG14_Offset + RECEIVER_SYMB_Transform8_CFG14_LENGTH;
    g_receiver_symb_table_param.ByteCopy_CFG16_Offset = g_receiver_symb_table_param.ByteSet_CFG15_Offset + RECEIVER_SYMB_ByteSet_CFG15_LENGTH;
    g_receiver_symb_table_param.AgcMultiSym_CFG17_Offset = g_receiver_symb_table_param.ByteCopy_CFG16_Offset + RECEIVER_SYMB_ByteCopy_CFG16_LENGTH;
    //DM1
    g_receiver_symb_table_param.EqFactor_LUT5_Offset = 0;
    //DM2
    g_receiver_symb_table_param.PilotOrig_LUT1_Offset = 0;
    g_receiver_symb_table_param.EqW4096_LUT2_Offset = g_receiver_symb_table_param.PilotOrig_LUT1_Offset + RECEIVER_SYMB_PilotOrig_LUT1_LENGTH;
    g_receiver_symb_table_param.EqFactor0_LUT3_Offset = g_receiver_symb_table_param.EqW4096_LUT2_Offset + RECEIVER_SYMB_EqW4096_LUT2_LENGTH;
    //TODO:遗留问题
    g_receiver_symb_table_param.EqCpPhase_LUT6_Offset = g_receiver_symb_table_param.EqFactor0_LUT3_Offset + RECEIVER_SYMB_EqFactor0_LUT3_LENGTH + \
                                                            RECEIVER_SYMB_EqFactor1_LUT4_LENGTH + RECEIVER_SYMB_EqFactor_LUT5_LENGTH ;
    g_receiver_symb_table_param.AgcShiftFft_LUT7_Offset = g_receiver_symb_table_param.EqCpPhase_LUT6_Offset + RECEIVER_SYMB_EqCpPhase_LUT6_LENGTH;
    g_receiver_symb_table_param.AgcMultiSymFactor_LUT8_Offset = g_receiver_symb_table_param.AgcShiftFft_LUT7_Offset + RECEIVER_SYMB_AgcShiftFft_LUT7_LENGTH;

    //DM3
    g_receiver_symb_table_param.EqFactor1_LUT4_Offset = 0;
   
    //SM

    g_symb2bit_buffer_sel = 0;

    //9. 微码配置文件ddr地址初始化
    ret = osp_get_cfgfile("Receiver_Symb_cfg_dm0.dat",
                          (uint32_t *)&(g_receiver_symb_table_param.receiver_symb_config0_ddr_ptr),
                          (int32_t *)&(g_receiver_symb_table_param.receiver_symb_config0_length));
    if(0 != ret)
    {
        //LOG_ERROR_S("Receiver_Symb_cfg_dm0.dat not found!\n");
    } 
    ret = osp_get_cfgfile("Receiver_Symb_cfg_dm1.dat",
                          (uint32_t *)&(g_receiver_symb_table_param.receiver_symb_config1_ddr_ptr),
                          (int32_t *)&(g_receiver_symb_table_param.receiver_symb_config1_length));
    if(0 != ret)
    {
        //LOG_ERROR_S("Receiver_Symb_cfg_dm1.dat not found!\n");
    } 
    ret = osp_get_cfgfile("Receiver_Symb_cfg_dm2.dat",
                          (uint32_t *)&(g_receiver_symb_table_param.receiver_symb_config2_ddr_ptr),
                          (int32_t *)&(g_receiver_symb_table_param.receiver_symb_config2_length));
    if(0 != ret)
    {
        //LOG_ERROR_S("Receiver_Symb_cfg_dm2.dat not found!\n");
    }                           
    ret = osp_get_cfgfile("Receiver_Symb_cfg_dm3.dat",
                          (uint32_t *)&(g_receiver_symb_table_param.receiver_symb_config3_ddr_ptr),
                          (int32_t *)&(g_receiver_symb_table_param.receiver_symb_config3_length));
    if(0 != ret)
    {
        //LOG_ERROR_S("Receiver_Symb_cfg_dm3.dat not found!\n");
    }  

#ifdef RECV_SYMB_DBG_DATA_TEST
    uint32_t timedata_ptr;
    int32_t timedata_len;
    ret = osp_get_cfgfile("timedatasym.dat",
                              (uint32_t *)&(timedata_ptr),
                           (int32_t *)&(timedata_len));
             
     if(-1 == ret)
     {
         LOG_ERROR_S("timedatasym.dat not found!\n");
     } 
 
    //  int* param_ptr = (int *)RECEIVER_SYMB_CFG_BASE;
    //  STORE_EX_W(param_ptr, timedata_ptr);
    //  STORE_EX_W((param_ptr+1), timedata_len);
    ape_csu_dma_1D_G2L_ch2ch3_transfer((uint64_t)(timedata_ptr),
    (uint64_t)JESD_NRFDD_RX_SLOT_EVEN_DATA_DOWN_SAMP_ADDR,//第一次固定搬移到dm0
    timedata_len,
    DMA_TAG_G2G,
    1);
    ape_csu_dma_1D_G2L_ch2ch3_transfer((uint64_t)(timedata_ptr),
    (uint64_t)JESD_NRFDD_RX_SLOT_ODD_DATA_DOWN_SAMP_ADDR,//第一次固定搬移到dm0
    timedata_len,
    DMA_TAG_G2G,
    1);  

#endif
    // uint32_t ptr1,ptr2,len1,len2;
    // ret = osp_get_cfgfile("channel_est_1_Quan.dat",
    //                           (uint32_t *)&(ptr1),
    //                        (int32_t *)&(len1));
             
    //  if(-1 == ret)
    //  {
    //      LOG_ERROR_S("channel_est_1_Quan not found!\n");
    //  } 
    //  ape_csu_dma_1D_G2L_ch2ch3_transfer((uint64_t)(ptr1),
    //  (uint64_t)CHANNELEST_DATA_DDR_PTR,//第一次固定搬移到dm0
    //  len1,
    //  DMA_TAG_G2G,
    //  1); 
    //  ret = osp_get_cfgfile("EquIn_Quan.dat",
    //     (uint32_t *)&(ptr2),
    //  (int32_t *)&(len2));

    // if(-1 == ret)
    // {
    // LOG_ERROR_S("timedatasym.dat not found!\n");
    // } 
    // ape_csu_dma_1D_G2L_ch2ch3_transfer((uint64_t)(ptr2),
    // (uint64_t)COMPENSATED_DATA_DDR_PTR,//第一次固定搬移到dm0
    // len2,
    // DMA_TAG_G2G,
    // 1); 


}
