| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
#include <xparameters.h> |
| 44 |
#include <xil_io.h> |
| 45 |
#include "platform_drivers.h" |
| 46 |
#include "ad9625.h" |
| 47 |
#include "adc_core.h" |
| 48 |
#include "jesd204b_gt.h" |
| 49 |
#include "jesd204b_v51.h" |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
#define AD9625_CORE_0_BASEADDR XPAR_AXI_AD9625_0_CORE_BASEADDR |
| 55 |
#define AD9625_CORE_1_BASEADDR XPAR_AXI_AD9625_1_CORE_BASEADDR |
| 56 |
#define AD9625_DMA_BASEADDR XPAR_AXI_AD9625_DMA_BASEADDR |
| 57 |
#define AD9625_JESD_0_BASEADDR XPAR_AXI_AD9625_0_JESD_BASEADDR |
| 58 |
#define AD9625_JESD_1_BASEADDR XPAR_AXI_AD9625_1_JESD_BASEADDR |
| 59 |
#define FMCADC5_GT_0_BASEADDR XPAR_AXI_FMCADC5_0_GT_BASEADDR |
| 60 |
#define FMCADC5_GT_1_BASEADDR XPAR_AXI_FMCADC5_1_GT_BASEADDR |
| 61 |
#define SPI_DEVICE_ID XPAR_SPI_0_DEVICE_ID |
| 62 |
#define SPI_AD9625_0_SS 0 |
| 63 |
#define SPI_AD9625_1_SS 1 |
| 64 |
#define GPIO_DEVICE_ID XPAR_AXI_GPIO_DEVICE_ID |
| 65 |
#define GPIO_OFFSET 32 |
| 66 |
#define GPIO_RST_0 GPIO_OFFSET + 2 |
| 67 |
#define GPIO_PWDN_0 GPIO_OFFSET + 3 |
| 68 |
#define GPIO_RST_1 GPIO_OFFSET + 6 |
| 69 |
#define GPIO_PWDN_1 GPIO_OFFSET + 7 |
| 70 |
#define GPIO_IRQ_0 GPIO_OFFSET + 8 |
| 71 |
#define GPIO_FD_0 GPIO_OFFSET + 9 |
| 72 |
#define GPIO_IRQ_1 GPIO_OFFSET + 10 |
| 73 |
#define GPIO_FD_1 GPIO_OFFSET + 11 |
| 74 |
#define GPIO_PWR_GOOD GPIO_OFFSET + 12 |
| 75 |
|
| 76 |
#define ADC_DDR_BASEADDR XPAR_AXI_DDR_CNTRL_BASEADDR + 0x800000 |
| 77 |
|
| 78 |
jesd204b_state jesd204b_st = { |
| 79 |
1, |
| 80 |
1, |
| 81 |
0, |
| 82 |
32, |
| 83 |
1, |
| 84 |
1, |
| 85 |
}; |
| 86 |
|
| 87 |
jesd204b_gt_link gt_0_link = { |
| 88 |
FMCADC5_GT_0_BASEADDR, |
| 89 |
JESD204B_GT_RX, |
| 90 |
0, |
| 91 |
7, |
| 92 |
JESD204B_GT_QPLL, |
| 93 |
JESD204B_GT_DFE, |
| 94 |
625, |
| 95 |
6250, |
| 96 |
JESD204B_GT_SYSREF_INT, |
| 97 |
0, |
| 98 |
2, |
| 99 |
0, |
| 100 |
}; |
| 101 |
|
| 102 |
jesd204b_gt_link gt_1_link = { |
| 103 |
FMCADC5_GT_1_BASEADDR, |
| 104 |
JESD204B_GT_RX, |
| 105 |
0, |
| 106 |
7, |
| 107 |
JESD204B_GT_QPLL, |
| 108 |
JESD204B_GT_DFE, |
| 109 |
625, |
| 110 |
6250, |
| 111 |
JESD204B_GT_SYSREF_INT, |
| 112 |
0, |
| 113 |
2, |
| 114 |
0, |
| 115 |
}; |
| 116 |
|
| 117 |
ad9625_init_param default_ad9625_init_param = { |
| 118 |
0, |
| 119 |
SPI_MODE_3, |
| 120 |
#ifdef _XPARAMETERS_PS_H_ |
| 121 |
PS7_SPI, |
| 122 |
#else |
| 123 |
AXI_SPI, |
| 124 |
#endif |
| 125 |
SPI_DEVICE_ID, |
| 126 |
}; |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
int32_t adc5_gpio_ctl(void) |
| 132 |
{ |
| 133 |
gpio_device dev; |
| 134 |
uint8_t pwr_good; |
| 135 |
|
| 136 |
#ifdef _XPARAMETERS_PS_H_ |
| 137 |
dev.type = PS7_GPIO; |
| 138 |
#else |
| 139 |
dev.type = AXI_GPIO; |
| 140 |
#endif |
| 141 |
dev.device_id = GPIO_DEVICE_ID; |
| 142 |
|
| 143 |
gpio_init(&dev); |
| 144 |
|
| 145 |
gpio_set_direction(&dev, GPIO_RST_0, GPIO_OUT); |
| 146 |
gpio_set_direction(&dev, GPIO_PWDN_0, GPIO_OUT); |
| 147 |
gpio_set_direction(&dev, GPIO_RST_1, GPIO_OUT); |
| 148 |
gpio_set_direction(&dev, GPIO_PWDN_1, GPIO_OUT); |
| 149 |
gpio_set_direction(&dev, GPIO_IRQ_0, GPIO_IN); |
| 150 |
gpio_set_direction(&dev, GPIO_FD_0, GPIO_IN); |
| 151 |
gpio_set_direction(&dev, GPIO_IRQ_1, GPIO_IN); |
| 152 |
gpio_set_direction(&dev, GPIO_FD_1, GPIO_IN); |
| 153 |
gpio_set_direction(&dev, GPIO_PWR_GOOD, GPIO_IN); |
| 154 |
gpio_set_value(&dev, GPIO_RST_0, 0); |
| 155 |
gpio_set_value(&dev, GPIO_PWDN_0, 0); |
| 156 |
gpio_set_value(&dev, GPIO_RST_1, 0); |
| 157 |
gpio_set_value(&dev, GPIO_PWDN_1, 0); |
| 158 |
mdelay(10); |
| 159 |
|
| 160 |
gpio_get_value(&dev, GPIO_PWR_GOOD, &pwr_good); |
| 161 |
if (!pwr_good) { |
| 162 |
xil_printf("Error: GPIO Power Good NOT set.\n\r"); |
| 163 |
return -1; |
| 164 |
} |
| 165 |
|
| 166 |
gpio_set_value(&dev, GPIO_RST_0, 1); |
| 167 |
gpio_set_value(&dev, GPIO_RST_1, 1); |
| 168 |
mdelay(100); |
| 169 |
|
| 170 |
return 0; |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
int32_t adc5_gtlink_control(uint32_t data) |
| 177 |
{ |
| 178 |
int32_t n; |
| 179 |
|
| 180 |
for (n = 7; n >= 0; n--) { |
| 181 |
jesd204b_gt_txrx_write(gt_0_link, JESD204B_GT_REG_RSTN(n), data); |
| 182 |
jesd204b_gt_txrx_write(gt_0_link, JESD204B_GT_REG_SYNC_CTL(n), data); |
| 183 |
jesd204b_gt_txrx_write(gt_1_link, JESD204B_GT_REG_RSTN(n), data); |
| 184 |
jesd204b_gt_txrx_write(gt_1_link, JESD204B_GT_REG_SYNC_CTL(n), data); |
| 185 |
} |
| 186 |
return(0); |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
int32_t adc5_gtlink_sysref(uint32_t data, |
| 193 |
uint32_t status) |
| 194 |
{ |
| 195 |
uint32_t n; |
| 196 |
uint32_t rdata; |
| 197 |
int32_t rstatus = 0; |
| 198 |
|
| 199 |
jesd204b_gt_txrx_write(gt_0_link, JESD204B_GT_REG_SYSREF_CTL(0), 0x0); |
| 200 |
jesd204b_gt_txrx_write(gt_0_link, JESD204B_GT_REG_SYSREF_CTL(0), data); |
| 201 |
jesd204b_gt_txrx_write(gt_0_link, JESD204B_GT_REG_SYSREF_CTL(0), 0x0); |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
for (n = 0; n < 8; n++) { |
| 206 |
jesd204b_gt_read(gt_0_link, JESD204B_GT_REG_STATUS(n), &rdata); |
| 207 |
if (rdata != status) { |
| 208 |
rstatus = -1; |
| 209 |
xil_printf("JESD204B-GT[%d,%d]: Invalid status, received(0x%05x), " |
| 210 |
"expected(0x%05x)!\n", 0, n, rdata, status); |
| 211 |
} |
| 212 |
jesd204b_gt_read(gt_1_link, JESD204B_GT_REG_STATUS(n), &rdata); |
| 213 |
if (rdata != status) { |
| 214 |
rstatus = -1; |
| 215 |
xil_printf("JESD204B-GT[%d,%d]: Invalid status, received(0x%05x), " |
| 216 |
"expected(0x%05x)!\n", 1, n, rdata, status); |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
return rstatus; |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
int32_t adc5_sysref_sw_calibrate(ad9625_dev *dev_0, ad9625_dev *dev_1) |
| 227 |
{ |
| 228 |
uint32_t n; |
| 229 |
uint32_t rgpio; |
| 230 |
uint32_t rdata; |
| 231 |
uint32_t rstatus = 0; |
| 232 |
uint8_t rdata8_0; |
| 233 |
uint8_t rdata8_1; |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
ad9625_spi_write(dev_0, 0x072, 0x8b); |
| 238 |
ad9625_spi_write(dev_0, 0x03a, 0x02); |
| 239 |
ad9625_spi_write(dev_0, 0x0ff, 0x01); |
| 240 |
ad9625_spi_write(dev_1, 0x072, 0x8b); |
| 241 |
ad9625_spi_write(dev_1, 0x03a, 0x02); |
| 242 |
ad9625_spi_write(dev_1, 0x0ff, 0x01); |
| 243 |
|
| 244 |
rgpio = Xil_In32(XPAR_GPIO_0_BASEADDR + 0x8) & 0x00ffffff; |
| 245 |
Xil_Out32((XPAR_GPIO_0_BASEADDR + 0x8), (rgpio | (31<<24))); |
| 246 |
|
| 247 |
ad9625_spi_write(dev_0, 0x13c, 0x60); |
| 248 |
ad9625_spi_write(dev_0, 0x0ff, 0x01); |
| 249 |
|
| 250 |
for (n = 0; n < 32; n++) { |
| 251 |
adc5_gtlink_control(0); |
| 252 |
if (adc5_gtlink_sysref(0, 0xffff) != 0) { |
| 253 |
xil_printf("[%05d]: Interleaving Synchronization Failed, " |
| 254 |
"Exiting!!\n", __LINE__); |
| 255 |
return -1; |
| 256 |
} |
| 257 |
|
| 258 |
ad9625_spi_write(dev_0, 0x03a, 0x42); |
| 259 |
ad9625_spi_write(dev_0, 0x0ff, 0x01); |
| 260 |
ad9625_spi_write(dev_0, 0x03a, 0x02); |
| 261 |
ad9625_spi_write(dev_0, 0x0ff, 0x01); |
| 262 |
|
| 263 |
ad9625_spi_write(dev_1, 0x03a, 0x42); |
| 264 |
ad9625_spi_write(dev_1, 0x0ff, 0x01); |
| 265 |
ad9625_spi_write(dev_1, 0x03a, 0x02); |
| 266 |
ad9625_spi_write(dev_1, 0x0ff, 0x01); |
| 267 |
|
| 268 |
Xil_Out32((XPAR_GPIO_0_BASEADDR + 0x8), (rgpio | (n<<24))); |
| 269 |
rdata = Xil_In32(XPAR_GPIO_0_BASEADDR + 0x8); |
| 270 |
if ((rdata & 0xff000000) != ((n<<24) | 0x20000000)) { |
| 271 |
xil_printf("[%05d]: SYSREF Delay Control Failed(%d, 0x%08x), Exiting!!\n", __LINE__, n, rdata); |
| 272 |
return(-1); |
| 273 |
} |
| 274 |
|
| 275 |
ad9625_spi_read(dev_0, 0x100, &rdata8_0); |
| 276 |
ad9625_spi_read(dev_1, 0x100, &rdata8_1); |
| 277 |
if (((rdata8_0 & 0x04) != 0x00) || ((rdata8_1 & 0x04) != 0x00)) { |
| 278 |
xil_printf("[%05d]: SYSREF Clear Status Failed(%d, 0x%02x, 0x%02x), Exiting!!\n", __LINE__, n, rdata8_0, rdata8_1); |
| 279 |
return(-1); |
| 280 |
} |
| 281 |
|
| 282 |
adc5_gtlink_control(1); |
| 283 |
if (adc5_gtlink_sysref(1, 0x1ffff) != 0) { |
| 284 |
xil_printf("[%05d]: Interleaving Synchronization Failed, Exiting!!\n", __LINE__); |
| 285 |
return(-1); |
| 286 |
} |
| 287 |
|
| 288 |
ad9625_spi_read(dev_0, 0x100, &rdata8_0); |
| 289 |
ad9625_spi_read(dev_1, 0x100, &rdata8_1); |
| 290 |
|
| 291 |
if ((rstatus == 1) && ((rdata8_0 & 0x04) == 0x04) && ((rdata8_1 & 0x04) == 0x00)) { |
| 292 |
rstatus = 2; |
| 293 |
xil_printf("SYSREF Calibration Successful[%d]\n", n); |
| 294 |
break; |
| 295 |
} |
| 296 |
|
| 297 |
rstatus = 0; |
| 298 |
if (((rdata8_0 & 0x04) == 0x00) && ((rdata8_1 & 0x04) == 0x00)) { |
| 299 |
rstatus = 1; |
| 300 |
} |
| 301 |
} |
| 302 |
|
| 303 |
if (rstatus != 2) { |
| 304 |
xil_printf("SYSREF Calibration Failed!!\n"); |
| 305 |
return -1; |
| 306 |
} |
| 307 |
|
| 308 |
return 0; |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
int main(void) |
| 315 |
{ |
| 316 |
ad9625_dev *ad9625_0_device; |
| 317 |
ad9625_dev *ad9625_1_device; |
| 318 |
adc_core ad9625_0_core; |
| 319 |
adc_core ad9625_1_core; |
| 320 |
|
| 321 |
if (adc5_gpio_ctl()) |
| 322 |
return -1; |
| 323 |
|
| 324 |
default_ad9625_init_param.spi_chip_select = SPI_AD9625_0_SS; |
| 325 |
ad9625_setup(&ad9625_0_device, default_ad9625_init_param); |
| 326 |
|
| 327 |
default_ad9625_init_param.spi_chip_select = SPI_AD9625_1_SS; |
| 328 |
ad9625_setup(&ad9625_1_device, default_ad9625_init_param); |
| 329 |
|
| 330 |
jesd204b_gt_initialize(gt_0_link); |
| 331 |
jesd204b_setup(XPAR_AXI_AD9625_0_JESD_BASEADDR, jesd204b_st); |
| 332 |
jesd204b_gt_setup(gt_0_link); |
| 333 |
|
| 334 |
jesd204b_gt_initialize(gt_1_link); |
| 335 |
jesd204b_setup(XPAR_AXI_AD9625_1_JESD_BASEADDR, jesd204b_st); |
| 336 |
jesd204b_gt_setup(gt_1_link); |
| 337 |
|
| 338 |
ad9625_0_core.adc_baseaddr = AD9625_CORE_0_BASEADDR; |
| 339 |
ad9625_0_core.dmac_baseaddr = AD9625_DMA_BASEADDR; |
| 340 |
ad9625_0_core.no_of_channels = 1; |
| 341 |
ad9625_0_core.resolution = 12; |
| 342 |
|
| 343 |
ad9625_1_core.adc_baseaddr = AD9625_CORE_1_BASEADDR; |
| 344 |
ad9625_1_core.dmac_baseaddr = 0; |
| 345 |
ad9625_1_core.no_of_channels = 1; |
| 346 |
ad9625_0_core.resolution = 12; |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
adc5_sysref_sw_calibrate(ad9625_0_device, ad9625_1_device); |
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
adc_setup(ad9625_0_core); |
| 357 |
adc_setup(ad9625_1_core); |
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
ad9625_spi_write(ad9625_0_device, AD9625_REG_TEST_CNTRL, 0x5); |
| 362 |
ad9625_spi_write(ad9625_0_device, AD9625_REG_OUTPUT_MODE, 0x0); |
| 363 |
ad9625_spi_write(ad9625_0_device, AD9625_REG_TRANSFER, 0x1); |
| 364 |
|
| 365 |
ad9625_spi_write(ad9625_1_device, AD9625_REG_TEST_CNTRL, 0x5); |
| 366 |
ad9625_spi_write(ad9625_1_device, AD9625_REG_OUTPUT_MODE, 0x0); |
| 367 |
ad9625_spi_write(ad9625_1_device, AD9625_REG_TRANSFER, 0x1); |
| 368 |
|
| 369 |
if (adc_pn_mon(ad9625_0_core, ADC_PN23A) != 0) |
| 370 |
return -1; |
| 371 |
if (adc_pn_mon(ad9625_1_core, ADC_PN23A) != 0) |
| 372 |
return -1; |
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
ad9625_spi_write(ad9625_0_device, AD9625_REG_TEST_CNTRL, 0x0); |
| 377 |
ad9625_spi_write(ad9625_0_device, AD9625_REG_OUTPUT_MODE, 0x1); |
| 378 |
ad9625_spi_write(ad9625_0_device, AD9625_REG_TRANSFER, 0x1); |
| 379 |
adc_write(ad9625_0_core, ADC_REG_CHAN_CNTRL(0), 0x51); |
| 380 |
|
| 381 |
ad9625_spi_write(ad9625_1_device, AD9625_REG_TEST_CNTRL, 0x0); |
| 382 |
ad9625_spi_write(ad9625_1_device, AD9625_REG_OUTPUT_MODE, 0x1); |
| 383 |
ad9625_spi_write(ad9625_1_device, AD9625_REG_TRANSFER, 0x1); |
| 384 |
adc_write(ad9625_1_core, ADC_REG_CHAN_CNTRL(0), 0x51); |
| 385 |
|
| 386 |
xil_printf("Initialization done.\n"); |
| 387 |
|
| 388 |
adc_capture(ad9625_0_core, 32768, ADC_DDR_BASEADDR); |
| 389 |
|
| 390 |
xil_printf("Capture done.\n"); |
| 391 |
|
| 392 |
return 0; |
| 393 |
} |