#ifndef _JESD_TIMER_H_
#define _JESD_TIMER_H_

#include "typedef.h"
#include "phy_para.h"

#define JESD_TXRX_CHANGE_GAP		13000 // ns
#define JESD_RF_ON_GAP              8000
#define JESD_RF_OFF_GAP             2000
//#define JESD_TX_ADVANCE_SAMPLE		0		// 500		// sample
//#define JESD_RX_ADVANCE_SAMPLE		1600	// sample
//#define JESD_RRU_TD					0		// 480		// sample
#define JESD_TX_ADVANCE_NS			0		
#define JESD_RX_ADVANCE_NS			13000	
#define JESD_RRU_TD					0		// ns

typedef enum _tagJesdSndRcvMode
{
	JESD_IO_CTRL		= 0,
	JESD_CSU_CTRL		= 1
}numJesdSndRcvMode;

typedef enum _tagJesdTestMode
{
	JESD_NORMAL_MODE	= 0,
	JESD_NORMAL_TO_TEST	= 1,
	JESD_TEST_MODE		= 2,
	JESD_TEST_TO_NORMAL	= 3
}numJesdTestMode;

typedef enum _tagJesdInitStep
{
    JESD_NO_INIT        = 0,
	JESD_CLK_INIT       = 1,
	JESD_TRANS_INIT		= 2,
	JESD_INIT_STEP_MAX  = 3
}numJesdInitStep;

typedef struct _tagJesdDelay
{
	uint32_t	txOffset;
	uint32_t	rxOffset;
	uint32_t	tddOffset;
}stJesdDelay;


void jesd_init(uint8_t option);

int32_t jesd_mtimer_init(int32_t nTmrId, int32_t nScsId, int32_t nTddSlotNum);

int32_t jesd_timer_init(int32_t nTmrId, int32_t nScsId, int32_t nTddSlotNum);

// 协议规定的接收提前量，NR提前13us，LTE不提前，LTE模式下，需在建小区之前，调用该接口，修改协议提前量
void jesd_set_protocol_rx_advance(uint32_t rxAdvance);

int32_t jesd_timer_reconfig(int32_t nTmrId, phy_timer_config_ind_t *my_jesdtmr);

int32_t jesd_timer_clear_cell(int32_t nTmrId, uint8_t scsId);

void jesd_timer_rcfg_act(int32_t nTmrId);

int32_t jesd_pin_ctrl(int32_t nTmrId);

void set_jesd_tmr_period(int32_t nTmrId);

void jesd_1pps_src_init(uint8_t srcId);

void set_jesd_1pps_scratch(int32_t nTmrId);

void set_jesd_sfn_offset(int32_t nTmrId);

void set_jesd_tdd_offset(int32_t nTmrId);

void clear_jesd_tdd_offset(int32_t nTmrId);

void set_jesd_tx_slot_offset(int32_t nTmrId);

void clear_jesd_tx_slot_offset(int32_t nTmrId);

void set_jesd_rx_slot_offset(int32_t nTmrId);

void clear_jesd_rx_slot_offset(int32_t nTmrId);

//void set_jesd_lte_fapi_offset(void);

//void clear_jesd_lte_fapi_offset(void);

int32_t set_jesd_ape_slot_offset(int32_t nTmrId, uint32_t apeCoreId);

int32_t clear_jesd_ape_slot_offset(int32_t nTmrId, uint32_t apeCoreId);

//int32_t set_jesd_csu_point(int32_t nTmrId, uint8_t nPointId);
int32_t set_jesd_csuon_point(int32_t nTmrId, uint8_t nPointId);
int32_t set_jesd_csuoff_point(int32_t nTmrId, uint8_t nPointId);

void set_jesd_txon_point(int32_t nTmrId, uint8_t nPointId);

void clear_jesd_txon_point(int32_t nTmrId);

void set_jesd_txoff_point(int32_t nTmrId, uint8_t nPointId);

void clear_jesd_txoff_point(int32_t nTmrId);

void set_jesd_rxon_point(int32_t nTmrId, uint8_t nPointId);

void clear_jesd_rxon_point(int32_t nTmrId);

void set_jesd_rxoff_point(int32_t nTmrId, uint8_t nPointId);

void clear_jesd_rxoff_point(int32_t nTmrId);

void start_jesd_timer(int32_t nTmrId);

void stop_jesd_timer(int32_t nTmrId);

uint64_t get_jesd_scr_value(int32_t nTmrId);

int32_t set_jesd_timer_int(int32_t nTmrId);

void isr_jesd_10ms_rx0(void);

void isr_jesd_10ms_rx1(void);

void isr_jesd_tdd_offset_rx0(void);

void isr_jesd_slot_rx0(void);

void isr_jesd_slot_rx1(void);

//void jesd_1pps_resync();

//void jesd_1pps_sfn_cal();

//void jesd_tdd_start_csu();

#endif

