/* AD9528 data structure initialization file */
#include <stdint.h>
#include "dev_profile.h"
#include "../app_config.h"

static spi_init_param ad9528_spi_init = {
	.device_id = SPI_DEVICE_ID,
    .max_speed_hz = SPI_ENGINE_MAX_SPEED,
	.mode = SPI_MODE_0,
	.chip_select = SPI_CS_AD9528,
	.platform_ops = SPI_OPS,
	.extra = SPI_PARAM
};

static gpio_init_param ad9528_gpio_resetb_init = {
	.number = AD9528_RESETB,
	.platform_ops = GPIO_OPS,
	.extra = GPIO_PARAM
};

static gpio_init_param ad9528_gpio_sysref_req_init = {
	.number = AD9528_SYSREF_REQ,
	.platform_ops = GPIO_OPS,
	.extra = GPIO_PARAM
};

static ad9528pll1Settings_t clockPll1Settings = {
    .refA_Frequency_Hz  = 50000000,
    .refA_Divider       = 1,
    .refA_bufferCtrl    = SINGLE_ENDED,
    .refB_Frequency_Hz  = 0,
    .refB_Divider       = 1,
    .refB_bufferCtrl    = DISABLED,
    .vcxo_Frequency_Hz  = 50000000,
    .vcxoBufferCtrl     = SINGLE_ENDED,
    .nDivider           = 1
};

static ad9528pll2Settings_t clockPll2Settings = {
    .rfDivider = 4,
    .n2Divider = 20,
    .totalNdiv = 80
};

/*******************************************************************
 * Output Distribution Settings
 * 9369CE02A uses the following clock outputs
 * OUT 1: FPGA REFCLK
 * OUT 3: FPGA SYSREF
 * OUT 12: DUT SYSREF
 * OUT 13: DUT REFCLK
 *******************************************************************
 */
static ad9528outputSettings_t clockOutputSettings = {
    .outPowerDown = 0,//0x0FF5,
    .outSource = {
            CHANNEL_DIV, CHANNEL_DIV, CHANNEL_DIV, CHANNEL_DIV, CHANNEL_DIV,
            CHANNEL_DIV, CHANNEL_DIV, CHANNEL_DIV, CHANNEL_DIV, CHANNEL_DIV,
            CHANNEL_DIV, CHANNEL_DIV, CHANNEL_DIV, CHANNEL_DIV
    },
    .outBufferCtrl = {
    		0,0,0,0,0,
    		0,0,0,0,0,
			0,0,0,0
    },
    .outAnalogDelay = {
    		0,0,0,0,0,
    		0,0,0,0,0,
			0,0,0,0
    },
    .outDigitalDelay = {
    		0,0,0,0,0,
    		0,0,0,0,0,
			0,0,0,0
    },
    .outChannelDiv = {
    		5,5,5,5,5,
			5,5,5,5,5,
			5,40,40,5
    },
    .outFrequency_Hz    = {
            200e6, 200e6, 200e6, 200e6, 200e6,
			200e6, 200e6, 200e6, 200e6, 200e6,
			200e6, 25e6, 25e6, 200e6
    }
};

static ad9528sysrefSettings_t clockSysrefSettings = {
    .sysrefRequestMethod    = PIN,
    .sysrefSource           = INTERNAL,
    .sysrefPinEdgeMode      = LEVEL_ACTIVE_HIGH,
    .sysrefPinBufferMode    = DISABLED,
    .sysrefPatternMode      = CONTINUOUS,
    .sysrefNshotMode        = FOUR_PULSES,
    .sysrefDivide           = 256
};

static ad9528spiSettings_t clockSpiSettings = {
    .chipSelectIndex        = SPI_CS_AD9528, //chip select Index, not used
    .writeBitPolarity       = 0, //Write bit polarity
    .longInstructionWord    = 1, //16bit instruction word
    .MSBFirst               = 1, //MSB first
    .CPHA                   = 0, //Clock phase
    .CPOL                   = 0, //Clock polarity
    .enSpiStreaming         = 0, //uint8_t enSpiStreaming;
    .autoIncAddrUp          = 1, //uint8_t autoIncAddrUp;
    .fourWireMode           = 1  //uint8_t fourWireMode;
};

ad9528Init_t ad9528_default_init_param = {
	/* SPI */
	.spi_init = &ad9528_spi_init,
	.gpio_init_resetb = &ad9528_gpio_resetb_init,
	.gpio_init_sysref_req = &ad9528_gpio_sysref_req_init,
    .spiSettings = &clockSpiSettings,
    .pll1Settings = &clockPll1Settings,
    .pll2Settings = &clockPll2Settings,
    .outputSettings = &clockOutputSettings,
    .sysrefSettings = &clockSysrefSettings
};
