//******************** (C) COPYRIGHT 2020 SmartLogic*******************************
// FileName           : Cpri_driver.h
// Author             : wangyanzhi, yanzhi.wang@smartlogictech.com
// Date First Issued  : 2022-05-31 09:49:26 AM
// Last Modified      : 2022-05-31 11:06:47 AM
// Description        :
// ------------------------------------------------------------
// Modification History:
// Version    Date       Author    Modification Description
//
//**********************************************************************************


#include "typedef.h"

#define CPRI_RRU_MSG_LEN        164
#define SWAP32(A)  ((((uint32_t)(A) & 0xff000000) >> 24) | (((uint32_t)(A) & 0x00ff0000) >> 8) | (((uint32_t)(A) & 0x0000ff00) << 8) | (((uint32_t)(A) & 0x000000ff) << 24))

typedef struct CpriRruMsg
{
    uint32_t msg_addr;
	uint32_t msg_len;
}CpriRruMsg_t;

void init_cpri(uint32_t cpri_speed_sel);

void Init_cpri_clk(uint32_t cpri_speed_sel);
void Init_cpri_clk(uint32_t cpri_speed_sel);
void Init_config_cpri(uint32_t cpri_speed_sel);
void Init_config_pcs(uint32_t cpri_speed_sel);

void config_cpri_pcs(uint32_t cpri_speed_sel,uint32_t cpri_rec_re_mode_sel);

void Init_jecspma(uint32_t cpri_speed_sel);
void Init_pma_commonconfig(uint32_t cpri_speed_sel);
void jecspma_recrx_eq();

void jecspma_recrx_reset(uint32_t pcs_flag);


//void config_cpri_map_directed(uint32_t cpri_speed_sel);
void config_cpri_map_directed(uint32_t option,uint32_t MappingMode);
void start_cpri_map(void);
void stop_cpri_map(void);

/***********************AUX interface**********************/
void AUX_Rx_init(uint32_t Buffer0,uint32_t Buffer1,uint32_t Len0,uint32_t Len1);
void AUX_Rx_enable(uint32_t Axi_mode);//bit17:16表示axi_mode:0x01:表示写完第一块buffer停住；0x10:写完两块buffer停住；0x11来回写两块buffer
void AUX_Rx_Disable();
void AUX_Tx_enable();
void AUX_Tx_Disable();
void AUX_Data_insert(uint32_t Num,uint8_t DATA_CNT[],uint8_t DATA_CNT_POS[],uint32_t DATA_TX[],uint32_t DATA_EN[]);
void AUX_Ctrl_insert(uint32_t Num,uint8_t CTRL_CNT[],uint8_t CTRL_CNT_POS[],uint8_t CTRL_TX[],uint8_t CTRL_EN[]);
void Int_AUX_Enable(uint32_t AUX_Int_En);
uint32_t Get_AUX_Flag();
void HeaderRam_ins_enable();
void HeaderRam_ins_disable();


//void HeaderRam_Tx(uint32_t BF_X,uint32_t BF_Ctrlword_wordnum,uint32_t Hdr_Data);
void HeaderRam_Tx(uint32_t BF_X,uint32_t BF_Ctrlword_wordnum,uint32_t Hdr_Data,uint32_t Hdr_Data_en);
uint32_t HeaderRam_Rx(uint32_t BF_X,uint32_t BF_Ctrlword_wordnum);


uint32_t UCP_API_CPRI_GetHfnsyncFlag();
uint32_t UCP_API_CPRI_GetBuffer1FullFlag();

uint32_t UCP_API_CPRI_GetTxHfnCnt();
uint32_t UCP_API_CPRI_GetTxXCnt();

uint32_t UCP_API_CPRI_GetRxHfnCnt();

int32_t set_cpri_rru_msg(CpriRruMsg_t rru_msg);

uint32_t get_cpri_rru_msg_addr();


