/******************************************************************
 * @file  Receiver_Sync_First_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_sync_first_func.h"


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

    //DM0
    g_receiver_sync_first_table_param.ConfigByteCopy_CFG1_Offset = 0;
    g_receiver_sync_first_table_param.ConfigSlidingCorrelation_CFG2_Offset = g_receiver_sync_first_table_param.ConfigByteCopy_CFG1_Offset + RECEIVER_SYNC_FIRST_ConfigByteCopy_CFG1_LENGTH;
    g_receiver_sync_first_table_param.ConfigSlidingCorrelationSecond_CFG3_Offset = g_receiver_sync_first_table_param.ConfigSlidingCorrelation_CFG2_Offset + RECEIVER_SYNC_FIRST_ConfigSlidingCorrelation_CFG2_LENGTH;
    g_receiver_sync_first_table_param.ConfigSyncVer_CFG4_Offset = g_receiver_sync_first_table_param.ConfigSlidingCorrelationSecond_CFG3_Offset + RECEIVER_SYNC_FIRST_ConfigSlidingCorrelationSecond_CFG3_LENGTH;
    //DM1

    //DM2

    //DM3

    //SM


    // //7. SPU查找表dma 搬移到ShareMemory，共257544Byte 包括：
    // //   1). 置信度表uint16_t Q_W_Lut[2016] (n-5)
    // //   2). 置信度最高的K'个置0的比特掩码表uint32_t I_BitMask_Lut[61056] (K-18,n-5)
    // //   3). 解三角交织边长T表 uint8_t T_Lut[8192] (E-1)
    // //   4). CRC6校验查找表uint8_t CRC6_Lut[256] (crc6check())
    // //   5). 长度≥36的ZC序列q值查找表 uint8_t Zc_q_Lut[840] (nPrbs-3,u,v)
    // //获取地址
    //     ret = osp_get_cfgfile("nr_puxch_lut_sm.dat",
    //                       (uint32_t *)&lutDdrAddr, 
    //                       (int32_t *)&(g_receiver_sync_first_table_param.pucch_lut_length));
    // g_receiver_sync_first_table_param.pucch_lut_sm_ptr = SM0_BASE;
    // ape_csu_dma_1D_G2L_ch0ch1_transfer((uint64_t)lutDdrAddr, 
    //                                    (uint64_t)g_receiver_sync_first_table_param.pucch_lut_sm_ptr, 
    //                                    g_receiver_sync_first_table_param.pucch_lut_length, 
    //                                    DMA_TAG_G2G, 
    //                                    1);
    // LOG_ERROR_S("test init\n");
    //9. 微码配置文件ddr地址初始化

    //!!!配置文件是同一个!!!
    ret = osp_get_cfgfile("Receiver_Sync_First_cfg_dm0.dat",
                          (uint32_t *)&(g_receiver_sync_first_table_param.receiver_sync_first_config0_ddr_ptr),
                          (int32_t *)&(g_receiver_sync_first_table_param.receiver_sync_first_config0_length));
    if(-1 == ret)
    {
        LOG_ERROR_S("Receiver_Sync_First_cfg_dm0.dat not found!\n");
    }  
    // ret = osp_get_cfgfile("Receiver_Sync_First_cfg_dm1.dat",
    //                       (uint32_t *)&(g_receiver_sync_first_table_param.receiver_sync_config1_ddr_ptr),
    //                       (int32_t *)&(g_receiver_sync_first_table_param.receiver_sync_config1_length));

    // ret = osp_get_cfgfile("Receiver_Sync_First_cfg_dm2.dat",
    //                       (uint32_t *)&(g_receiver_sync_first_table_param.receiver_sync_config2_ddr_ptr),
    //                       (int32_t *)&(g_receiver_sync_first_table_param.receiver_sync_config2_length));
    // ret = osp_get_cfgfile("Receiver_Sync_First_cfg_dm3.dat",
    //                       (uint32_t *)&(g_receiver_sync_first_table_param.receiver_sync_config3_ddr_ptr),
    //                       (int32_t *)&(g_receiver_sync_first_table_param.receiver_sync_config3_length));

    // LOG_ERROR_S("init %d 0x%08x %d\n", ret, g_receiver_sync_first_table_param.receiver_sync_config0_ddr_ptr, g_receiver_sync_first_table_param.receiver_sync_config0_length);
    g_receiver_sync_status_SM_ptr = (uint32_t)RECEIVER_SYNC2SYNC_FIRST_INF_ADDR;

    
}
