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


 /*!   
 * @brief:  Transmitter任务启动前的初始化工作
 *          初始化全局参数，ddr查找表搬入SM
 * @author:  HUOHUO
 * @Date:  2024年4月20日
 */
void Transmitter_Init()
{
    int32_t  ret;
    uint32_t lutDdrAddr,idx;
    //STORE_EX_W((void*)addr, 0);addr in ddr
    //DM0

    //DM1
    g_transmitter_table_param.ConfigCBSegment_CFG1_Offset = 0;
    g_transmitter_table_param.Config64BG1_CFG2_Offset = g_transmitter_table_param.ConfigCBSegment_CFG1_Offset + TRANSMITTER_ConfigCBSegment_CFG1_LENGTH;
    g_transmitter_table_param.Config64BG2_CFG3_Offset = g_transmitter_table_param.Config64BG1_CFG2_Offset + TRANSMITTER_Config64BG1_CFG2_LENGTH ;
    g_transmitter_table_param.Config384Pre_CFG4_Offset = g_transmitter_table_param.Config64BG2_CFG3_Offset + TRANSMITTER_Config64BG2_CFG3_LENGTH;
    g_transmitter_table_param.Config384BG1_CFG5_Offset = g_transmitter_table_param.Config384Pre_CFG4_Offset + TRANSMITTER_Config384Pre_CFG4_LENGTH;
    g_transmitter_table_param.Config384BG2_CFG6_Offset = g_transmitter_table_param.Config384BG1_CFG5_Offset + TRANSMITTER_Config384BG1_CFG5_LENGTH;
    g_transmitter_table_param.ConfigRMBitSelLDPC_CFG7_Offset = g_transmitter_table_param.Config384BG2_CFG6_Offset + TRANSMITTER_Config384BG2_CFG6_LENGTH;
    g_transmitter_table_param.ConfigRMBitILLDPC_CFG8_Offset = g_transmitter_table_param.ConfigRMBitSelLDPC_CFG7_Offset + TRANSMITTER_ConfigRMBitSelLDPC_CFG7_LENGTH;
    g_transmitter_table_param.ConfigModuQPSK_CFG9_Offset = g_transmitter_table_param.ConfigRMBitILLDPC_CFG8_Offset + TRANSMITTER_ConfigRMBitILLDPC_CFG8_LENGTH;
    g_transmitter_table_param.ConfigModuQAM16_CFG10_Offset = g_transmitter_table_param.ConfigModuQPSK_CFG9_Offset + TRANSMITTER_ConfigModuQPSK_CFG9_LENGTH;
    g_transmitter_table_param.ConfigModuQAM64_CFG11_Offset = g_transmitter_table_param.ConfigModuQAM16_CFG10_Offset + TRANSMITTER_ConfigModuQAM16_CFG10_LENGTH;
    g_transmitter_table_param.ConfigModuQAM256_CFG12_Offset = g_transmitter_table_param.ConfigModuQAM64_CFG11_Offset + TRANSMITTER_ConfigModuQAM64_CFG11_LENGTH;
    
    g_transmitter_table_param.CalBG1HMatrix_LUT1_Offset = g_transmitter_table_param.ConfigModuQAM256_CFG12_Offset + TRANSMITTER_ConfigModuQAM256_CFG12_LENGTH;
    g_transmitter_table_param.CalBG2HMatrix_LUT2_Offset = g_transmitter_table_param.CalBG1HMatrix_LUT1_Offset + TRANSMITTER_CalBG1HMatrix_LUT1_LENGTH;

    g_transmitter_table_param.TransformConfig_2_CFG1_Offset = g_transmitter_table_param.CalBG2HMatrix_LUT2_Offset + TRANSMITTER_CalBG2HMatrix_LUT2_LENGTH;
    g_transmitter_table_param.TransformConfig_4_CFG2_Offset = g_transmitter_table_param.TransformConfig_2_CFG1_Offset + TRANSMITTER_TransformConfig_2_CFG1_LENGTH;
    g_transmitter_table_param.TransformConfig_8_CFG3_Offset = g_transmitter_table_param.TransformConfig_4_CFG2_Offset + TRANSMITTER_TransformConfig_4_CFG2_LENGTH;

    g_transmitter_table_param.Pilot_Data_Offset = g_transmitter_table_param.TransformConfig_8_CFG3_Offset + TRANSMITTER_TransformConfig_8_CFG3_LENGTH;
    g_transmitter_table_param.ConfigByteCopy_CFG1_Offset = g_transmitter_table_param.Pilot_Data_Offset + TRANSMITTER_Pilot_Data_LENGTH;
    //DM2

    //DM3

    //SM

    


    //9. 微码配置文件ddr地址初始化
    //ret = osp_get_cfgfile("Transmitter_cfg_dm0.dat",
    //                      (uint32_t *)&(g_transmitter_table_param.transmitter_config0_ddr_ptr),
    //                      (int32_t *)&(g_transmitter_table_param.transmitter_config0_length));
    ret = osp_get_cfgfile("Transmitter_cfg_dm1.dat",
                          (uint32_t *)&(g_transmitter_table_param.transmitter_config1_ddr_ptr),
                          (int32_t *)&(g_transmitter_table_param.transmitter_config1_length));
    if(-1 == ret)
    {
        LOG_ERROR_S("Transmitter_cfg_dm1.dat not found!\n");
    }  
    //ret = osp_get_cfgfile("Transmitter_cfg_dm2.dat",
    //                      (uint32_t *)&(g_transmitter_table_param.transmitter_config2_ddr_ptr),
    //                      (int32_t *)&(g_transmitter_table_param.transmitter_config2_length));
    //ret = osp_get_cfgfile("Transmitter_cfg_dm3.dat",
    //                      (uint32_t *)&(g_transmitter_table_param.transmitter_config3_ddr_ptr),
    //                      (int32_t *)&(g_transmitter_table_param.transmitter_config3_length));
    LOG_ERROR_S("Transmitter_INIT finish\n");
}
