#ifndef __PROJECT_H__
#define __PROJECT_H__

#include "registers.h"
#include "adi_ad9081.h"

//#define IBERT_TESTING

// Higher values are higher priority
#define TASK_PRIORITY_MAIN			(tskIDLE_PRIORITY + 2)
#define TASK_PRIORITY_STATUS		(tskIDLE_PRIORITY + 2)
#define TASK_PRIORITY_ETH_RX		(tskIDLE_PRIORITY + 2)
#define TASK_PRIORITY_LWIP			(tskIDLE_PRIORITY + 2)

#define TICK_RATE	100.0
#define TICK_PERIOD (1 / TICK_RATE)
#define TICK_PERIOD_US (TICK_PERIOD * 1e6)

#define DEBUG_ENABLE

#ifdef DEBUG_ENABLE
    #define DEBUG_PRINT xil_printf
#else
    #define DEBUG_PRINT
#endif

int setBit(uint32_t addr, uint32_t bit);
int clearBit(uint32_t addr, uint32_t bit);
int toggleBit(uint32_t addr, uint32_t bit);
void error_print(int line_number, int err);
void setup_data_converter();

extern adi_ad9081_device_t * ad9081_dev_ptr;

  // register addresses from pg242

#define JESD_RX				  XPAR_JESD_JESD204C_0_BASEADDR
#define JESD_TX				  XPAR_JESD_JESD204C_1_BASEADDR

#define VERSION_REG           0x000
#define RESET_REG             0x020

#define RESET_ON              0x1
#define RESET_OFF             0x0

#define CTRL_ENABLE_REG       0x024
#define DISABLE_DATA_CMD      0x0
#define ENABLE_CMD            0x1
#define ENABLE_DATA           0x2
#define ENABLE_DATA_CMD       0x3

#define CTRL_MB_IN_EMB        0x30

#define CTRL_META_MODE        0x038
#define ENABLE_CRC12_MODE     0x0
#define ENABLE_CRC3_MODE      0x1
#define ENABLE_CMD_MODE       0x2
#define ENABLE_FEC_MODE       0x3

#define CTRL_RX_BUF_ADV       0x44

#define CTRL_SYSREF           0x050


#define STAT_STATUS_REG       0x060
#define STATUS_IRQ_PEND_BIT   1
#define STATUS_SYSREF_CAP_BIT 2
#define STATUS_SYSREF_ERR_BIT 4
#define STATUS_SH_LOCK_BIT    16
#define STATUS_EMB_LOCK_BIT   32
#define STATUS_BUFF_OVERR_BIT 1024
#define STAT_RX_BUF_LVL0      0x400
#define STAT_RX_BUF_LVL1      0x480
#define STAT_RX_BUF_LVL2      0x500
#define STAT_RX_BUF_LVL3      0x580
#define STAT_RX_BUF_LVL4      0x600
#define STAT_RX_BUF_LVL5      0x680
#define STAT_RX_BUF_LVL6      0x700
#define STAT_RX_BUF_LVL7      0x780

#define JESD_204B	1
#define JESD_204C	2

int32_t rf_spi_write(int dev_sel, int num_bits, int data);

#endif
