/******************************************************************
 * @file  nr_common.h
 * @brief:    [file description] 
 * @author: xuekun.zhang
 * @Date 2022年1月10日
 * COPYRIGHT NOTICE: (c) smartlogictech. All rights reserved. 
 * Change_date         Owner         Change_content
 * 2022年1月10日        xuekun.zhang       create file

*****************************************************************/

#ifndef     COMMON_VARS_H
#define     COMMON_VARS_H

/**************************include******************************/
#include "type_define.h"
#include "mem_def.h"
#include "ucps2.h"
#include "ucps2-intrin.h"
#include "interface_fapi_tasks.h"
#include "phy_msg_func.h"


#define APE0_CORE_ID     0
#define APE1_CORE_ID     1
#define APE2_CORE_ID     2
#define APE3_CORE_ID     3
#define APE4_CORE_ID     4
#define APE5_CORE_ID     5
#define APE6_CORE_ID     6
#define APE7_CORE_ID     7
#define PT_RFM0_CORE_ID  8
#define PT_RFM1_CORE_ID  9
#define ECS_RFM0_CORE_ID 10
#define ECS_RFM1_CORE_ID 11
#define ARM_CORE_ID      12
#define MAX_CORE_ID      13

#define MAX_APE_CORE_ID 8

#define DMA_DIR_L2G		0
#define DMA_DIR_G2L 	1
#define DMA_DIR_G2G 	1


#define DMA_REG_GROUP0  0
#define DMA_REG_GROUP1 	1
#define DMA_REG_GROUP2 	2
#define DMA_REG_GROUP3 	3


//PUCCH & PUSCH公用PUCCH SM查找表内部结构偏移宏定义


/**************************define******************************/
#define LOAD_EX_W(ptr) __ucps2_load_ext_mem((char*)ptr, f_W)
#define LOAD_EX_S(ptr) __ucps2_load_ext_mem((char*)ptr, f_S)
#define LOAD_EX_B(ptr) __ucps2_load_ext_mem((char*)ptr, f_B)

#define STORE_EX_W(ptr, value) __ucps2_store_ext_mem((char*)ptr, value, f_W)
#define STORE_EX_S(ptr, value) __ucps2_store_ext_mem((char*)ptr, value, f_S)
#define STORE_EX_B(ptr, value) __ucps2_store_ext_mem((char*)ptr, value, f_B)

#define LOAD_EX_V_W(ptr) __ucps2_load_ext_mem_v((char*)ptr, f_W)
#define LOAD_EX_V_S(ptr) __ucps2_load_ext_mem_v((char*)ptr, f_S)
#define LOAD_EX_V_B(ptr) __ucps2_load_ext_mem_v((char*)ptr, f_B)

#define WAIT_MPU_STOP __ucps2_getStatB(); __ucps2_delay()

//38.214 Table 5.1.3.1-2: MCS index table 1 for PDSCH/PUSCH
extern uint16_t g_mcs_table_1[32][3];
//38.214 Table 5.1.3.1-2: MCS index table 2 for PDSCH/PUSCH
extern uint16_t g_mcs_table_2[32][3];
//38.214 Table 5.1.3.1-3: MCS index table 3 for PDSCH/PUSCH
extern uint16_t g_mcs_table_3[32][3];


// extern uint16_t g_zc_table[8][8];
extern uint16_t g_zc_table[50];
extern uint8_t g_ils_table[51];


extern uint16_t g_nprb_lbrm_table[7];
extern uint32_t g_tbsize_lbrm_256qam_table[7];
extern uint32_t g_tbsize_lbrm_64qam_table[7];

extern uint8_t g_dmrstype1_delta_table[8];//{1000,1001,...,1007}
extern uint8_t g_dmrstype2_delta_table[12];//{1000,1001,...,1011}
extern int8_t  g_dmrstype1_wf_pk_table[8][2];
extern int8_t  g_dmrstype2_wf_pk_table[12][2];
extern int8_t  g_dmrstype1_wt_pl_table[8][2];
extern int8_t  g_dmrstype2_wt_pl_table[12][2];
extern uint16_t g_zc_lift_sizearray[51];
extern uint8_t g_zc_iLs[51];

extern uint32_t  g_dm_malloc_count[4];
extern uint32_t  g_dm_malloc_err_count[4];
extern uint32_t  g_dm_free_count[4] ;

extern phy_com_param_t* g_phy_com_param;
extern phy_tasks_mgr_reg_t* g_phy_tasks_mgr_ptr;
extern msg_ring_buffer_t* g_phy_msg_buffer;

//求10log10查找表静态变量声明，上行信道公用
extern const int16_t c_tb_dB[32][3];
extern const int16_t c_dBcal_value_comp_table[70];

/**************************function******************************/
//extern void wait_mpu_stop();
extern  uint64_t ceil_long_fix(uint64_t a_numerator, uint64_t a_denominator);
extern  int64_t floor_long_fix(int64_t a_numerator, int64_t a_denominator);
extern int ceil_fix(int a_numerator, int a_denominator);
extern int floor_fix(int a_numerator, int a_denominator);
extern  int round_fix(int a_numerator, int a_denominator);
extern int * dmalloc_unit(uint32_t len, uint8_t dm_index);
extern int * dmemalign_unit(uint32_t align_addr, uint32_t len, uint8_t dm_index); 
extern void dfree_unit(int *val_ptr, uint8_t dm_index);
int phase_compensation(uint32_t a_f0, uint32_t *phase, uint32_t dl);
//求10log10函数声明，上行信道公用
int16_t Calc_10Log10(int32_t real_value, uint8_t Q_in, uint8_t Q_out);
extern char *osp_heap_malloc(uint32_t size);
extern uint8_t CRC6Check(uint32_t *dataIn, uint8_t *crc6Lut, uint8_t bitLen, uint32_t **dataOut);
#endif
