#ifndef _JESD_CSU_H_
#define _JESD_CSU_H_

#include "typedef.h"

#define JS_204B_CONVERTER_BITS		16	// 12
#define JS_204B_CS_BITS				0	// 2
#define JS_204B_CF_VAL				0

#define JS_204B_ORX_M				2

#define JESD_CSU_RX0_TAG			0
#define JESD_CSU_TX0_TAG			1
#define JESD_CSU_RX1_TAG			2
#define JESD_CSU_TX1_TAG			3

#define JESD_CH_NUM					2	// rx0/rx1, tx0/tx1
#define JESD_LIST_NUM				2	// double 2.5ms, 2 lists for every ch

typedef enum _tagJesdCsuCh
{
	JESD_CSU_CH0 = 0,
	JESD_CSU_CH1 = 1
}numJesdCsuCh;

typedef struct _tagJesdCsuPara
{
	uint8_t antNum;	// 天线数
	uint8_t cf;
	uint8_t cs;		// 控制字, =2
	uint8_t n;		// iq数据精度, = 12
	uint8_t m;		// 天线数*2
	uint8_t nTotal;	// n+cs+padding
	uint8_t seq;	
	uint8_t margin;
	uint8_t orxMargin;
	uint8_t tfMode;
}stJesdCsuPara;

typedef struct _tagJesdCsuNodePara
{
	uint32_t dataAddr;
	uint32_t yStep;
	uint32_t allNum;
}stJesdCsuNodePara; 

typedef struct _tagJesdListPara
{
	uint32_t listAddr;
	uint32_t listNodeNum;
}stJesdListPara;

int32_t jesd_para_init();

int32_t jesd_csu_init(uint8_t antNum, uint8_t margin, uint8_t tfMode);

int32_t jesd_orx_csu_init(uint8_t margin);

int32_t jesd_csu_rx_inlatch_thres_cfg(uint8_t ch, uint32_t send_threshold, uint32_t almostfull_threshold);

/***********************************************************************************
	 ch			  list		    RegGroup		CmdFIFO		tagId = RegGroupId
	rx0			0/1/2/3			0/4/8/12		    0			0/4/8/12
	tx0			0/1/2/3			1/5/9/13			1			1/5/9/13
	rx1			0/1/2/3			2/6/10/14			2			2/6/10/14
	tx1			0/1/2/3			3/7/11/15			3			3/7/11/15
************************************************************************************/

int32_t jesd_csu_rx_cfg(uint32_t listAddr, uint32_t nodeNum, stJesdCsuNodePara* pListNode, uint8_t nChId, uint8_t nListId);

int32_t jesd_csu_orx_cfg(uint32_t listAddr, uint32_t nodeNum, stJesdCsuNodePara* pListNode, uint8_t nListId);

int32_t jesd_csu_tx_cfg(uint32_t listAddr, uint32_t nodeNum, stJesdCsuNodePara* pListNode, uint8_t nChId, uint8_t nListId);

int32_t jesd_csu_rx_list_init(uint32_t listAddr, uint32_t nodeNum, stJesdCsuNodePara* pListNode, uint8_t nChId, uint8_t nListId, uint8_t orxFlag);

int32_t jesd_csu_tx_list_init(uint32_t listAddr, uint32_t nodeNum, stJesdCsuNodePara* pListNode, uint8_t nChId, uint8_t nListId);

int32_t jesd_csu_rx_list_desc0_flush(uint8_t nChId, uint8_t nListId);

int32_t jesd_csu_rx_dmaReg_Cfg(uint8_t nChId, uint8_t nListId);

int32_t jesd_csu_tx_dmaReg_Cfg(uint8_t nChId, uint8_t nListId);

int32_t jesd_csu_rx_start_ch(uint8_t nChId, uint8_t nListId);

int32_t jesd_csu_tx_start_ch(uint8_t nChId, uint8_t nListId);

int32_t jesd_csu_rx_start(uint8_t nListId);

int32_t jesd_csu_tx_start(uint8_t nListId);

int32_t jesd_csu_orx_start(uint8_t nListId);

int32_t jesd_csu_stat_lookup(uint8_t tag);

int32_t jesd_csu_clear_list();

#endif

