#ifndef _TRANSFORM_PARA_FUNC_H
#define _TRANSFORM_PARA_FUNC_H


#include "type_define.h"
#include "log_interface.h"
#include "phy_macro.h"
#define THITA1_LEN  (511)
#define THITA2_LEN  (2047)
#define THITA34_LEN (8191)


extern volatile uint32_t g_thita1_val;
extern volatile uint32_t g_thita2_val;
extern volatile uint32_t g_thita34_val;
extern uint32_t g_thita1_addr;
extern uint32_t g_thita2_addr;
extern uint32_t g_thita3_addr;
extern uint32_t g_thita4_addr;
extern double thita2real[4][4];
extern double thita2imag[4][4];




#define transform_get_thita1_2bit()     (LOAD_EX_W(g_thita1_addr + (g_thita1_val<<2)))
#define transform_get_thita2_2bit()     (LOAD_EX_W(g_thita2_addr + (g_thita2_val<<2)))
#define transform_get_thita3_2bit()     (LOAD_EX_W(g_thita3_addr + (g_thita34_val<<2)))
#define transform_get_thita4_2bit()     (LOAD_EX_W(g_thita4_addr + (g_thita34_val<<2)))

#define transform_get_thita1_real()     (thita2real[0][LOAD_EX_W(g_thita1_addr + (g_thita1_val<<2))])
#define transform_get_thita2_real()     (thita2real[1][LOAD_EX_W(g_thita2_addr + (g_thita2_val<<2))])
#define transform_get_thita3_real()     (thita2real[2][LOAD_EX_W(g_thita3_addr + (g_thita34_val<<2))])
#define transform_get_thita4_real()     (thita2real[3][LOAD_EX_W(g_thita4_addr + (g_thita34_val<<2))])

#define transform_get_thita1_imag()     (thita2imag[0][LOAD_EX_W(g_thita1_addr + (g_thita1_val<<2))])
#define transform_get_thita2_imag()     (thita2imag[1][LOAD_EX_W(g_thita2_addr + (g_thita2_val<<2))])
#define transform_get_thita3_imag()     (thita2imag[2][LOAD_EX_W(g_thita3_addr + (g_thita34_val<<2))])
#define transform_get_thita4_imag()     (thita2imag[3][LOAD_EX_W(g_thita4_addr + (g_thita34_val<<2))])

//获得当前8bit随机数值
#define get_transform_8bit()         (uint8_t)(transform_get_thita1_2bit()     | (transform_get_thita2_2bit() << 2) | \
                                                 (transform_get_thita3_2bit()<<4) | (transform_get_thita4_2bit() << 6))
   
/*初始化transform_para操作相关的变量，发送和接收使用同一个全局标量 note：发送和接受任务不能部署在同一个核上，否则维护的变量会冲突
*设置存储寄存器序号
*param: thita1_init：查表的序号，范围0~510
*param: thita2_init：查表的序号，范围0~2047
*param: thita34_init：查表的序号，范围0~8191
*/
int transform_para_init(uint32_t thita1_init, uint32_t thita2_init, uint32_t thita34_init);

/*设置存储寄存器序号
*param: thita1_init：查表的序号，范围0~510
*param: thita2_init：查表的序号，范围0~2047
*param: thita34_init：查表的序号，范围0~8191
*/
int transform_set_para(uint32_t thita1_init, uint32_t thita2_init, uint32_t thita34_init);

//向后递推n次
int transform_para_update(uint32_t n);

/*根据pcie返回的结果计算当前状态，并更新寄存器参数
*param: thita1_para:pcie提供的对应全部bit
*param: thita2_para:pcie提供的对应全部bit
*param: thita3_para:pcie提供的对应全部bit
*/
int transform_decode_para(uint32_t thita1_para, uint32_t thita2_para, uint32_t thita34_para);


/*根据pcie返回的结果计算当前状态，并更新寄存器参数
*param: thita1_para:pcie提供的对应全部bit
*param: thita2_para:pcie提供的对应全部bit
*param: thita3_para:pcie提供的对应全部bit
*/
int transform_decode_para_check(uint32_t thita1_para, uint32_t thita2_para, uint32_t thita34_para);


/*根据时序偏差更新寄存器参数
*param: cur_sfn：当前sfn号
*param: cur_slot：当前slot号
*param: ref_sfn：rk3588解算输入使用的sfn号
*param: ref_slot：rk3588解算输入使用的slot号
*/
int transform_update_cur_para(uint32_t cur_sfn, uint32_t cur_slot, uint32_t ref_sfn, uint32_t ref_slot);

#endif /*_TRANSFORM_PARA_FUNC_H*/