Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/fmcomms1/Common/xcomm.c

raw symbols SCIP
1 /**************************************************************************//**
2 * @file xcomm.c
3 * @brief XCOMM interface functions implementation.
4 * @author acozma ([email protected])
5 *
6 *******************************************************************************
7 * Copyright 2011(c) Analog Devices, Inc.
8 *
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without modification,
12 * are permitted provided that the following conditions are met:
13 * - Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 * - Neither the name of Analog Devices, Inc. nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 * - The use of this software may or may not infringe the patent rights
23 * of one or more patent holders. This license does not release you
24 * from the requirement that you obtain separate licenses from these
25 * patent holders to use this software.
26 * - Use of the software either in source or binary form, must be run
27 * on or directly connected to an Analog Devices Inc. component.
28 *
29 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED
30 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY
31 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
32 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34 * INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
36 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 *******************************************************************************
41 * SVN Revision: $WCREV$
42 ******************************************************************************/
43
44 /*****************************************************************************/
45 /***************************** Include Files *********************************/
46 /*****************************************************************************/
47 #include <stdint.h>
48 #include "AD9548.h"
49 #include "AD9523.h"
50 #include "ADF4351.h"
51 #include "AD9122.h"
52 #include "AD9643.h"
53 #include "AD8366.h"
54 #include "eeprom.h"
55 #include "spi_interface.h"
56 #include "adc_core.h"
57 #include "dac_core.h"
58 #include "mmcm.h"
59 #include "xcomm.h"
60
61 /****** Global variables ******/
62 struct fmcomms1_calib_data XCOMM_calData[16];
63 struct fmcomms1_calib_data_v1 XCOMM_calData_v1[16];
64 uint8_t XCOMM_calDataSize;
65 XCOMM_FmcPort XCOMM_boardFmcPort;
66
67 /****** XCOMM state structure ******/
68 struct stXCOMM_State
69 {
70 /* Rx state variables */
71 int64_t rxFreq;
72 int8_t rxFreqValid;
73 int32_t rxResolution;
74 int8_t rxResolutionValid;
75 int32_t rxGain;
76 int8_t rxGainValid;
77 XCOMM_RxIQCorrection rxIqCorrection;
78 int8_t rxIqCorrectionValid;
79
80 /* Tx state variables */
81 int64_t txFreq;
82 int8_t txFreqValid;
83 int32_t txResolution;
84 int8_t txResolutionValid;
85 XCOMM_TxIQCorrection txIqCorrection;
86 int8_t txIqCorrectionValid;
87
88 /* ADC state variables */
89 int64_t adcSampleRate;
90 int8_t adcSampleRateValid;
91 XCOMM_AdcTestMode adcTestMode;
92 int8_t adcTestModeValid;
93
94 /* DAC state variables */
95 int64_t dacSampleRate;
96 int8_t dacSampleRateValid;
97 XCOMM_DacIQCorrection dacIQCorrection;
98 int8_t dacIqCorrectionValid;
99
100 /* FRU state variables */
101 uint8_t fruData[256];
102 uint8_t fruDataValid;
103
104 }XCOMM_State;
105
106 /**************************************************************************//**
107 * @brief Initializes the I2C peripheral.
108 *
109 * @param pDefInit - pointer to initialization structure
110 *
111 * @return Returns -1 in case of error, 0 for success
112 ******************************************************************************/
113 int32_t XCOMM_InitI2C(XCOMM_DefaultInit* pDefInit)
114 {
115 /* Local variables */
116 uint32_t enableCommMux;
117 uint32_t ps7Interface = 0;
118 int32_t ret;
119
120 /* Initialize the SPI communication */
121 switch(pDefInit->carrierBoard)
122 {
123 case XILINX_ZC702:
124 case XILINX_ZC706:
125 case XILINX_AC701:
126 case XILINX_KC705:
127 case XILINX_VC707:
128 enableCommMux = 1;
129 break;
130 case DIGILENT_ZED:
131 pDefInit->fmcPort = FMC_HPC;
132 case XILINX_ML605:
133 default:
134 enableCommMux = 0;
135 break;
136 }
137 XCOMM_boardFmcPort = enableCommMux ? FMC_HPC : pDefInit->fmcPort;
138 ret = SPI_Init(pDefInit->fmcPort, enableCommMux, ps7Interface,
139 pDefInit->carrierBoard);
140
141 return ret;
142 }
143 /**************************************************************************//**
144 * @brief Initializes the XCOMM board. The Rx and Tx path are disabled.
145 *
146 * @param pDefInit - pointer to initialization structure
147 *
148 * @return If success, return 0
149 * if error, return -1
150 ******************************************************************************/
151 int32_t XCOMM_Init(XCOMM_DefaultInit* pDefInit)
152 {
153 /* Local variables */
154 uint32_t enableCommMux;
155 uint32_t ps7Interface = 0;
156
157 /* Reset the XCOMM state variables */
158 int32_t i = 0;
159 int8_t* pData = (int8_t*)&XCOMM_State;
160 for(i = 0; i < sizeof(XCOMM_State); i++)
161 {
162 pData[i] = 0;
163 }
164
165 /* Initialize the SPI communication */
166 switch(pDefInit->carrierBoard)
167 {
168 case XILINX_ZC702:
169 case XILINX_ZC706:
170 case XILINX_AC701:
171 case XILINX_KC705:
172 case XILINX_VC707:
173 enableCommMux = 1;
174 break;
175 case DIGILENT_ZED:
176 pDefInit->fmcPort = FMC_HPC;
177 case XILINX_ML605:
178 default:
179 enableCommMux = 0;
180 break;
181 }
182
183 XCOMM_boardFmcPort = enableCommMux ? FMC_HPC : pDefInit->fmcPort;
184 if(SPI_Init(pDefInit->fmcPort, enableCommMux, ps7Interface,
185 pDefInit->carrierBoard) < 0)
186 return -1;
187
188 /* Initialize the AD9548 */
189 if(ad9548_setup() < 0)
190 return -1;
191
192 /* Initialize the AD9523 */
193 if(ad9523_setup() < 0)
194 return -1;
195
196 /* Initialize the Rx ADF4351 */
197 if(adf4351_setup(ADF4351_RX_CHANNEL) < 0)
198 return -1;
199
200 /* Initialize the Tx ADF4351 */
201 if(adf4351_setup(ADF4351_TX_CHANNEL) < 0)
202 return -1;
203
204 /* Read the calibration data from the EEPROM */
205 if(EEPROM_GetCalData((uint8_t*)XCOMM_calData, &XCOMM_calDataSize, XCOMM_boardFmcPort) < 0)
206 return -1;
207 if(EEPROM_GetCalData((uint8_t*)XCOMM_calData_v1, &XCOMM_calDataSize, XCOMM_boardFmcPort) < 0)
208 return -1;
209 if(XCOMM_calData[0].version == ADI_VERSION(1))
210 XCOMM_calDataSize = XCOMM_calData_v1[0].num_entries;
211
212 return 0;
213 }
214
215 /**************************************************************************//**
216 * @brief Initializes the Rx path
217 *
218 * @param pDefInit - pointer to initialization structure
219 *
220 * @return If success, return 0
221 * if error, return -1
222 ******************************************************************************/
223 int32_t XCOMM_InitRx(XCOMM_DefaultInit* pDefInit)
224 {
225 /* Power up all the Rx clocks */
226 if(ad9523_out_altvoltage_ADC_CLK_raw(1) < 0)
227 return -1;
228 if(ad9523_out_altvoltage_ADC_SYNC_CLK_raw(1) < 0)
229 return -1;
230 if(ad9523_out_altvoltage_RX_LO_REF_CLK_raw(1) < 0)
231 return -1;
232
233 /* Power Up the Rx ADF4351 */
234 if(adf4351_out_altvoltage0_powerdown(0, ADF4351_RX_CHANNEL) < 0)
235 return -1;
236
237 /* Set the default Rx frequency */
238 if(XCOMM_SetRxFrequency(pDefInit->rxFrequency) < 0)
239 return -1;
240
241 /* Set the AD9643 sampling rate */
242 if(XCOMM_SetAdcSamplingRate(pDefInit->adcSamplingRate) < 0)
243 return -1;
244
245 /* Initialize the AD9643 */
246 ADC_Core_Init(pDefInit->fmcPort);
247 if(ad9643_setup() < 0)
248 return -1;
249
250 /* Initialize the AD8366 */
251 if(ad8366_setup() < 0)
252 return -1;
253
254 /* Set the default Rx gain */
255 if(XCOMM_SetRxGain(pDefInit->rxGain1000) < 0)
256 return -1;
257
258 return 0;
259 }
260
261 /**************************************************************************//**
262 * @brief Initializes the Tx path
263 *
264 * @param pDefInit - pointer to initialization structure
265 *
266 * @return If success, return 0
267 * if error, return -1
268 ******************************************************************************/
269 int32_t XCOMM_InitTx(XCOMM_DefaultInit* pDefInit)
270 {
271 /* Initialize MMCM */
272 mmcm_init(pDefInit->fmcPort);
273
274 /* Power up all the Tx clocks */
275 if(ad9523_out_altvoltage_DAC_CLK_raw(1) < 0)
276 return -1;
277 if(ad9523_out_altvoltage_DAC_DCO_CLK_raw(1) < 0)
278 return -1;
279 if(ad9523_out_altvoltage_DAC_REF_CLK_raw(1) < 0)
280 return -1;
281 if(ad9523_out_altvoltage_TX_LO_REF_CLK_raw(1) < 0)
282 return -1;
283
284 /* Power Up the Tx ADF4351 */
285 if(adf4351_out_altvoltage0_powerdown(0, ADF4351_TX_CHANNEL) < 0)
286 return -1;
287
288 /* Set the default Tx frequency */
289 if(XCOMM_SetTxFrequency(pDefInit->txFrequency) < 0)
290 return -1;
291
292 /* Initialize the AD9122 */
293 DAC_Core_Init(pDefInit->fmcPort);
294 if(ad9122_setup(ad9523_out_altvoltage_DAC_DCO_CLK_frequency,
295 ad9523_out_altvoltage_DAC_CLK_frequency,
296 ad9523_out_altvoltage_DAC_REF_CLK_frequency,
297 ad9523_clk_round_rate_DAC_DCO_CLK,
298 ad9523_clk_round_rate_DAC_CLK,
299 ad9523_clk_round_rate_DAC_REF_CLK) < 0)
300 return -1;
301
302 /* Set the AD9122 sampling rate */
303 if(XCOMM_SetDacSamplingRate(pDefInit->dacSamplingRate) < 0)
304 return -1;
305
306 return 0;
307 }
308
309 /**************************************************************************//**
310 * @brief Stops the Rx path
311 *
312 * @param pDefInit - pointer to initialization structure
313 *
314 * @return If success, return 0
315 * if error, return -1
316 ******************************************************************************/
317 int32_t XCOMM_StopRx(void)
318 {
319 /* Power down all the Rx clocks */
320 if(ad9523_out_altvoltage_ADC_CLK_raw(0) < 0)
321 return -1;
322 if(ad9523_out_altvoltage_ADC_SYNC_CLK_raw(0) < 0)
323 return -1;
324 if(ad9523_out_altvoltage_RX_LO_REF_CLK_raw(0) < 0)
325 return -1;
326
327 /* Power Down the Rx ADF4351 */
328 if(adf4351_out_altvoltage0_powerdown(1, ADF4351_RX_CHANNEL) < 0)
329 return -1;
330
331 return 0;
332 }
333
334 /**************************************************************************//**
335 * @brief Stops the Tx path
336 *
337 * @param pDefInit - pointer to initialization structure
338 *
339 * @return If success, return 0
340 * if error, return -1
341 ******************************************************************************/
342 int32_t XCOMM_StopTx(void)
343 {
344 /* Power down all the Tx clocks */
345 if(ad9523_out_altvoltage_DAC_CLK_raw(0) < 0)
346 return -1;
347 if(ad9523_out_altvoltage_DAC_DCO_CLK_raw(0) < 0)
348 return -1;
349 if(ad9523_out_altvoltage_DAC_REF_CLK_raw(0) < 0)
350 return -1;
351 if(ad9523_out_altvoltage_TX_LO_REF_CLK_raw(0) < 0)
352 return -1;
353
354 /* Power Down the Tx ADF4351 */
355 if(adf4351_out_altvoltage0_powerdown(1, ADF4351_TX_CHANNEL) < 0)
356 return -1;
357
358 return 0;
359 }
360
361 /**************************************************************************//**
362 * @brief Resync driver cached values by reading the XCOMM board
363 *
364 * @return Returns 0 in case of success or -1 if error
365 ******************************************************************************/
366 int32_t XCOMM_Sync(void)
367 {
368 /* Resync Rx state variables */
369 XCOMM_GetRxResolution(XCOMM_ReadMode_FromHW);
370 XCOMM_GetRxGain(XCOMM_ReadMode_FromHW);
371 XCOMM_GetRxIqCorrection(0, XCOMM_ReadMode_FromHW);
372
373 /* Resync Tx state variables */
374 XCOMM_GetTxResolution(XCOMM_ReadMode_FromHW);
375 XCOMM_GetTxIqCorrection(0, XCOMM_ReadMode_FromHW);
376
377 /* Resync ADC state variables */
378 XCOMM_GetAdcSamplingRate(XCOMM_ReadMode_FromHW);
379 XCOMM_GetAdcTestMode(XCOMM_ReadMode_FromHW);
380
381 /* Resync DAC state variables */
382 XCOMM_GetDacSamplingRate(XCOMM_ReadMode_FromHW);
383 XCOMM_GetDacIqCorrection(XCOMM_ReadMode_FromHW);
384
385 return 0;
386 }
387
388 /**************************************************************************//**
389 * @brief Gets the XCOMM board version string
390 *
391 * @param readMode - Read version from driver or HW
392 *
393 * @return If success, return version struct with version string and error set to 0
394 If error, return version struct with error set to -1
395 ******************************************************************************/
396 XCOMM_Version XCOMM_GetBoardVersion(XCOMM_ReadMode readMode)
397 {
398 int32_t ret;
399 uint8_t len;
400 int32_t i;
401 uint8_t idx = 0;
402 uint8_t* ptr = XCOMM_State.fruData;
403 XCOMM_Version ver;
404
405 ver.error = -1;
406
407 /* Read the FRU data */
408 if((!XCOMM_State.fruDataValid) || (readMode == XCOMM_ReadMode_FromHW))
409 {
410 for(i = 0; i < 255; i += 16)
411 {
412 ret = EEPROM_Read(XCOMM_boardFmcPort == FMC_LPC ?
413 IICSEL_FRU_LPC : IICSEL_FRU_HPC,
414 i, &XCOMM_State.fruData[i],
415 ((255 - i) > 16) ? 16 : (255 - i));
416 if((ret < 0) || (XCOMM_State.fruData[0] != 0x01))
417 return ver;
418 }
419 XCOMM_State.fruDataValid = 1;
420 }
421
422 /* Move to the Board Area offset from the FRU */
423 ptr += ptr[3] * 8 + 6;
424
425 /* Read the Board Manufacturer */
426 len = *ptr & 0x3F;
427 ptr++;
428 while(len--)
429 {
430 ver.value[idx++] = *ptr;
431 ptr++;
432 if(!len)
433 {
434 ver.value[idx++] = ',';
435 ver.value[idx++] = ' ';
436 }
437 }
438
439 /* Read the Board Product Name */
440 len = *ptr & 0x3F;
441 ptr++;
442 while(len--)
443 {
444 ver.value[idx++] = *ptr;
445 ptr++;
446 if(!len)
447 {
448 ver.value[idx++] = ',';
449 ver.value[idx++] = ' ';
450 }
451 }
452
453 /* Read the Board Serial Number */
454 len = *ptr & 0x3F;
455 ptr++;
456 while(len--)
457 {
458 ver.value[idx++] = *ptr;
459 ptr++;
460 if(!len)
461 {
462 ver.value[idx++] = ',';
463 ver.value[idx++] = ' ';
464 }
465 }
466
467 /* Read the Board Part Number */
468 len = *ptr & 0x3F;
469 ptr++;
470 while(len--)
471 {
472 ver.value[idx++] = *ptr;
473 ptr++;
474 if(!len)
475 {
476 ver.value[idx++] = ',';
477 ver.value[idx++] = ' ';
478 }
479 }
480
481 /* Read the PCB Revision */
482 len = *ptr & 0x3F;
483 ptr += 1 + len;
484 len = *ptr & 0x3F;
485 ptr++;
486 if(*ptr == 0)
487 {
488 ptr++;
489 len--;
490 if(len)
491 {
492 ver.value[idx++] = 'P';
493 ver.value[idx++] = 'C';
494 ver.value[idx++] = 'B';
495 ver.value[idx++] = ' ';
496 ver.value[idx++] = 'R';
497 ver.value[idx++] = 'e';
498 ver.value[idx++] = 'v';
499 ver.value[idx++] = '.';
500 }
501 while(len--)
502 {
503 ver.value[idx++] = *ptr;
504 ptr++;
505 if(!len)
506 {
507 ver.value[idx++] = ',';
508 ver.value[idx++] = ' ';
509 }
510 }
511 }
512
513 /* Read the BOM Revision */
514 len = *ptr & 0x3F;
515 ptr++;
516 if(*ptr == 2)
517 {
518 ptr++;
519 len--;
520 if(len)
521 {
522 ver.value[idx++] = 'B';
523 ver.value[idx++] = 'O';
524 ver.value[idx++] = 'M';
525 ver.value[idx++] = ' ';
526 ver.value[idx++] = 'R';
527 ver.value[idx++] = 'e';
528 ver.value[idx++] = 'v';
529 ver.value[idx++] = '.';
530 }
531 while(len--)
532 {
533 ver.value[idx++] = *ptr;
534 ptr++;
535 }
536 }
537
538 ver.value[idx] = 0;
539 ver.error = 0;
540
541 return ver;
542 }
543
544 /**************************************************************************//**
545 * @brief Gets the PIC firmware version
546 *
547 * @return If success, returns the PIC firmware version number - 0 to 100
548 * If error returns -1
549 ******************************************************************************/
550 int32_t XCOMM_GetPicFwVersion()
551 {
552 return PIC_ReadFwVersion();
553 }
554
555 /************************ Rx Functions ***************************************/
556
557
558 /**************************************************************************//**
559 * @brief Sets the Rx center frequency
560 *
561 * @param frequency - desired frequency value in Hz
562 *
563 * @return If success, return exact calculated frequency in Hz
564 * if error, return -1
565 ******************************************************************************/
566 int64_t XCOMM_SetRxFrequency(uint64_t frequency)
567 {
568 int64_t freq = adf4351_out_altvoltage0_frequency(frequency, ADF4351_RX_CHANNEL);
569 if(freq < 0)
570 return -1;
571
572 XCOMM_State.rxFreq = freq;
573 XCOMM_State.rxFreqValid = 1;
574
575 return XCOMM_State.rxFreq;
576 }
577
578 /**************************************************************************//**
579 * @brief Gets the Rx center frequency
580 *
581 * @return If success, return frequency in Hz stored in driver,
582 * if error, return -1
583 ******************************************************************************/
584 int64_t XCOMM_GetRxFrequency(void)
585 {
586 return XCOMM_State.rxFreqValid ? XCOMM_State.rxFreq : -1;
587 }
588
589 /**************************************************************************//**
590 * @brief Sets the Rx center frequency resolution
591 *
592 * @param resolution: desired frequency resolution in Hz
593 *
594 * @return If success, return exact calculated resolution in Hz,
595 * if error, return -1
596 ******************************************************************************/
597 int32_t XCOMM_SetRxResolution(uint32_t resolution)
598 {
599 int32_t res = adf4351_out_altvoltage0_frequency_resolution(resolution,
600 ADF4351_RX_CHANNEL);
601 if(res < 0)
602 return -1;
603
604 XCOMM_State.rxResolution = res;
605 XCOMM_State.rxResolutionValid = 1;
606
607 return XCOMM_State.rxResolution;
608 }
609
610 /**************************************************************************//**
611 * @brief Gets the Rx center frequency resolution
612 *
613 * @param readMode: read frequency resolution from driver or HW
614 *
615 * @return If success, return frequency resolution in Hz,
616 * if error, return -1
617 ******************************************************************************/
618 int32_t XCOMM_GetRxResolution(XCOMM_ReadMode readMode)
619 {
620 int32_t res;
621
622 if(readMode == XCOMM_ReadMode_FromHW)
623 {
624 res = adf4351_out_altvoltage0_frequency_resolution(INT32_MAX,
625 ADF4351_RX_CHANNEL);
626 if(res < 0)
627 return -1;
628
629 XCOMM_State.rxResolution = res;
630 XCOMM_State.rxResolutionValid = 1;
631 }
632
633 return XCOMM_State.rxResolutionValid ? XCOMM_State.rxResolution : -1;
634 }
635
636 /**************************************************************************//**
637 * @brief Sets the Rx gain
638 *
639 * @param gain1000: desired gain (x1000) in dB
640 *
641 * @return If success, return calculated gain (x1000) in dB,
642 * if error, return -1
643 ******************************************************************************/
644 int32_t XCOMM_SetRxGain(int32_t gain1000)
645 {
646 int32_t retGain = 0;
647
648 retGain = ad8366_out_voltage0_hardwaregain(gain1000);
649 retGain = ad8366_out_voltage1_hardwaregain(gain1000);
650 if(retGain < 0)
651 return -1;
652
653 XCOMM_State.rxGain = retGain;
654 XCOMM_State.rxGainValid = 1;
655
656 return XCOMM_State.rxGain;
657 }
658
659 /**************************************************************************//**
660 * @brief Gets the Rx gain
661 *
662 * @param readMode: read gain from driver or HW
663 *
664 * @return If success, return gain (x1000) in dB
665 * if error, return -1
666 ******************************************************************************/
667 int32_t XCOMM_GetRxGain(XCOMM_ReadMode readMode)
668 {
669 int32_t gain;
670
671 if(readMode == XCOMM_ReadMode_FromHW)
672 {
673 gain = ad8366_out_voltage0_hardwaregain(2 * (int32_t)AD8366_MAX_GAIN * 1000);
674 if(gain < 0)
675 return -1;
676 XCOMM_State.rxGain = gain;
677 XCOMM_State.rxGainValid = 1;
678 }
679
680 return XCOMM_State.rxGainValid ? XCOMM_State.rxGain : -1;
681 }
682
683 /**************************************************************************//**
684 * @brief Gets the Rx gain and phase correction for I and Q
685 *
686 * @param frequency: center frequency used for the correction in Hz
687 * @param readMode: read gain and phase correction from driver or HW
688 *
689 * @return If success, return RxIQCorrection struct with error set to 0
690 * If error, return RxIQCorrection struct with error set to -1
691 ******************************************************************************/
692 XCOMM_RxIQCorrection XCOMM_GetRxIqCorrection(uint64_t frequency, XCOMM_ReadMode readMode)
693 {
694 uint8_t idx = 0;
695 uint8_t calIdx = 0;
696 uint32_t delta = 0;
697 int32_t signeddelta = 0;
698 uint32_t minDelta = UINT32_MAX;
699
700 if(readMode == XCOMM_ReadMode_FromHW)
701 {
702 EEPROM_GetCalData((uint8_t*)XCOMM_calData, &XCOMM_calDataSize, XCOMM_boardFmcPort);
703 EEPROM_GetCalData((uint8_t*)XCOMM_calData_v1, &XCOMM_calDataSize, XCOMM_boardFmcPort);
704 }
705
706 if(!XCOMM_calDataSize)
707 {
708 XCOMM_State.rxIqCorrection.error = -1;
709 }
710 else
711 {
712 if(XCOMM_calData[0].version == ADI_VERSION(0))
713 {
714 /* Version 0 */
715 frequency /= 1000000;
716 while(idx < XCOMM_calDataSize)
717 {
718 signeddelta = (int32_t)(frequency - XCOMM_calData[idx].cal_frequency_MHz);
719 delta = (uint32_t)(signeddelta>0?signeddelta:-signeddelta);
720 if(delta < minDelta)
721 {
722 minDelta = delta;
723 calIdx = idx;
724 }
725 idx++;
726 }
727 if ((XCOMM_calData[calIdx].adi_magic0 != ADI_MAGIC_0) ||
728 (XCOMM_calData[calIdx].adi_magic1 != ADI_MAGIC_1))
729 {
730 XCOMM_State.rxIqCorrection.error = -1;
731 }
732 else
733 {
734 XCOMM_State.rxIqCorrection.gainI = XCOMM_calData[calIdx].i_adc_gain_adj;
735 XCOMM_State.rxIqCorrection.offsetI = XCOMM_calData[calIdx].i_adc_offset_adj;
736 XCOMM_State.rxIqCorrection.gainQ = XCOMM_calData[calIdx].q_adc_gain_adj;
737 XCOMM_State.rxIqCorrection.offsetQ = XCOMM_calData[calIdx].q_adc_offset_adj;
738 XCOMM_State.rxIqCorrection.error = 0;
739 }
740 }
741 else
742 {
743 if(XCOMM_calData[0].version == ADI_VERSION(1))
744 {
745 /* Version 1 */
746 XCOMM_calDataSize = XCOMM_calData_v1[0].num_entries;
747 frequency /= 1000000;
748 while(idx < XCOMM_calDataSize)
749 {
750 signeddelta = (int32_t)(frequency - XCOMM_calData_v1[idx].cal_frequency_MHz);
751 delta = (uint32_t)(signeddelta>0?signeddelta:-signeddelta);
752 if(delta < minDelta)
753 {
754 minDelta = delta;
755 calIdx = idx;
756 }
757 idx++;
758 }
759 if ((XCOMM_calData_v1[calIdx].adi_magic0 != ADI_MAGIC_0) ||
760 (XCOMM_calData_v1[calIdx].adi_magic1 != ADI_MAGIC_1))
761 {
762 XCOMM_State.rxIqCorrection.error = -1;
763 }
764 else
765 {
766 XCOMM_State.rxIqCorrection.gainI = XCOMM_calData_v1[calIdx].i_adc_gain_adj;
767 XCOMM_State.rxIqCorrection.offsetI = XCOMM_calData_v1[calIdx].i_adc_offset_adj;
768 XCOMM_State.rxIqCorrection.gainQ = XCOMM_calData_v1[calIdx].q_adc_gain_adj;
769 XCOMM_State.rxIqCorrection.offsetQ = XCOMM_calData_v1[calIdx].q_adc_offset_adj;
770 XCOMM_State.rxIqCorrection.error = 0;
771 }
772 }
773 else
774 {
775 /* Unknown version */
776 XCOMM_State.rxIqCorrection.error = -1;
777 }
778 }
779 }
780
781 return XCOMM_State.rxIqCorrection;
782 }
783
784 /************************ Tx Functions ***************************************/
785
786
787 /**************************************************************************//**
788 * @brief Sets the Tx center frequency
789 *
790 * @param frequency: desired frequency in Hz
791 *
792 * @return If success, return calculated frequency in Hz
793 * if error, return -1
794 ******************************************************************************/
795 int64_t XCOMM_SetTxFrequency(uint64_t frequency)
796 {
797 int64_t freq = adf4351_out_altvoltage0_frequency(frequency, ADF4351_TX_CHANNEL);
798
799 if(freq < 0)
800 return -1;
801
802 XCOMM_State.txFreq = freq;
803 XCOMM_State.txFreqValid = 1;
804
805 return XCOMM_State.txFreq;
806 }
807
808 /**************************************************************************//**
809 * @brief Gets the Tx center frequency
810 *
811 * @return If success, return frequency in Hz stored in driver,
812 * if error, return -1
813 ******************************************************************************/
814 int64_t XCOMM_GetTxFrequency(void)
815 {
816 return XCOMM_State.txFreqValid ? XCOMM_State.txFreq : -1;
817 }
818
819 /**************************************************************************//**
820 * @brief Sets the Tx center frequency resolution
821 *
822 * @param resolution: desired frequency resolution in Hz
823 *
824 * @return If success, return exact calculated resolution in Hz,
825 * if error, return -1
826 ******************************************************************************/
827 int32_t XCOMM_SetTxResolution(uint32_t resolution)
828 {
829 int32_t res = adf4351_out_altvoltage0_frequency_resolution(resolution,
830 ADF4351_TX_CHANNEL);
831 if(res < 0)
832 return -1;
833
834 XCOMM_State.txResolution = res;
835 XCOMM_State.txResolutionValid = 1;
836
837 return XCOMM_State.txResolution;
838 }
839
840 /**************************************************************************//**
841 * @brief Gets the Tx center frequency resolution
842 *
843 * @param readMode: read frequency resolution from driver or HW
844 *
845 * @return If success, return frequency resolution in Hz,
846 * if error, return -1
847 ******************************************************************************/
848 int32_t XCOMM_GetTxResolution(XCOMM_ReadMode readMode)
849 {
850 int32_t res;
851
852 if(readMode == XCOMM_ReadMode_FromHW)
853 {
854 res = adf4351_out_altvoltage0_frequency_resolution(INT32_MAX,
855 ADF4351_TX_CHANNEL);
856 if(res < 0)
857 return -1;
858
859 XCOMM_State.txResolution = res;
860 XCOMM_State.txResolutionValid = 1;
861 }
862
863 return XCOMM_State.txResolutionValid ? XCOMM_State.txResolution : -1;
864 }
865
866 /**************************************************************************//**
867 * @brief Gets the Tx gain and phase correction for I and Q
868 *
869 * @param frequency: center frequency used for the correction in Hz
870 * @param readMode: read gain and phase correction from driver or HW
871 *
872 * @return If success, return TxIQCorrection struct with error set to 0
873 * If error, return TxIQCorrection struct with error set to -1
874 ******************************************************************************/
875 XCOMM_TxIQCorrection XCOMM_GetTxIqCorrection(uint64_t frequency, XCOMM_ReadMode readMode)
876 {
877 uint8_t idx = 0;
878 uint8_t calIdx = 0;
879 uint32_t delta = 0;
880 int32_t signeddelta = 0;
881 uint32_t minDelta = UINT32_MAX;
882
883 if(readMode == XCOMM_ReadMode_FromHW)
884 {
885 EEPROM_GetCalData((uint8_t*)XCOMM_calData, &XCOMM_calDataSize, XCOMM_boardFmcPort);
886 EEPROM_GetCalData((uint8_t*)XCOMM_calData_v1, &XCOMM_calDataSize, XCOMM_boardFmcPort);
887 }
888
889 if(!XCOMM_calDataSize)
890 {
891 XCOMM_State.txIqCorrection.error = -1;
892 }
893 else
894 {
895 if(XCOMM_calData[0].version == ADI_VERSION(0))
896 {
897 /* Version 0 */
898 frequency /= 1000000;
899 while(idx < XCOMM_calDataSize)
900 {
901 signeddelta = (int32_t)(frequency - XCOMM_calData[idx].cal_frequency_MHz);
902 delta = (uint32_t)(signeddelta>0?signeddelta:-signeddelta);
903 if(delta < minDelta)
904 {
905 minDelta = delta;
906 calIdx = idx;
907 }
908 idx++;
909 }
910 if ((XCOMM_calData[calIdx].adi_magic0 != ADI_MAGIC_0) ||
911 (XCOMM_calData[calIdx].adi_magic1 != ADI_MAGIC_1))
912 {
913 XCOMM_State.txIqCorrection.error = -1;
914 }
915 else
916 {
917 XCOMM_State.txIqCorrection.phaseAdjI = XCOMM_calData[calIdx].i_phase_adj;
918 XCOMM_State.txIqCorrection.offsetI = XCOMM_calData[calIdx].i_dac_offset;
919 XCOMM_State.txIqCorrection.fsAdjI = XCOMM_calData[calIdx].i_dac_fs_adj;
920
921 XCOMM_State.txIqCorrection.phaseAdjQ = XCOMM_calData[calIdx].q_phase_adj;
922 XCOMM_State.txIqCorrection.offsetQ = XCOMM_calData[calIdx].q_dac_offset;
923 XCOMM_State.txIqCorrection.fsAdjQ = XCOMM_calData[calIdx].q_dac_fs_adj;
924
925 XCOMM_State.txIqCorrection.error = 0;
926 }
927 }
928 else
929 {
930 if(XCOMM_calData[0].version == ADI_VERSION(1))
931 {
932 /* Version 1 */
933 XCOMM_calDataSize = XCOMM_calData_v1[0].num_entries;
934 frequency /= 1000000;
935 while(idx < XCOMM_calDataSize)
936 {
937 signeddelta = (int32_t)(frequency - XCOMM_calData_v1[idx].cal_frequency_MHz);
938 delta = (uint32_t)(signeddelta>0?signeddelta:-signeddelta);
939 if(delta < minDelta)
940 {
941 minDelta = delta;
942 calIdx = idx;
943 }
944 idx++;
945 }
946 if ((XCOMM_calData_v1[calIdx].adi_magic0 != ADI_MAGIC_0) ||
947 (XCOMM_calData_v1[calIdx].adi_magic1 != ADI_MAGIC_1))
948 {
949 XCOMM_State.txIqCorrection.error = -1;
950 }
951 else
952 {
953 XCOMM_State.txIqCorrection.phaseAdjI = XCOMM_calData_v1[calIdx].i_phase_adj;
954 XCOMM_State.txIqCorrection.offsetI = XCOMM_calData_v1[calIdx].i_dac_offset;
955 XCOMM_State.txIqCorrection.fsAdjI = XCOMM_calData_v1[calIdx].i_dac_fs_adj;
956
957 XCOMM_State.txIqCorrection.phaseAdjQ = XCOMM_calData_v1[calIdx].q_phase_adj;
958 XCOMM_State.txIqCorrection.offsetQ = XCOMM_calData_v1[calIdx].q_dac_offset;
959 XCOMM_State.txIqCorrection.fsAdjQ = XCOMM_calData_v1[calIdx].q_dac_fs_adj;
960
961 XCOMM_State.txIqCorrection.error = 0;
962 }
963 }
964 else
965 {
966 /* Unknown version */
967 XCOMM_State.rxIqCorrection.error = -1;
968 }
969 }
970 }
971
972 return XCOMM_State.txIqCorrection;
973 }
974
975 /************************ ADC Functions ***************************************/
976
977
978 /**************************************************************************//**
979 * @brief Sets the sampling rate of the ADC
980 *
981 * @param rate: desired rate in Hz
982 *
983 * @return If success, return exact calculated rate in Hz
984 * if error, return -1
985 ******************************************************************************/
986 int64_t XCOMM_SetAdcSamplingRate(uint64_t rate)
987 {
988 int64_t sampleRate = ad9523_out_altvoltage_ADC_CLK_frequency(rate);
989
990 if(sampleRate < 0)
991 return -1;
992
993 XCOMM_State.adcSampleRate = sampleRate;
994 XCOMM_State.adcSampleRateValid = 1;
995
996 return XCOMM_State.adcSampleRate;
997 }
998
999 /**************************************************************************//**
1000 * @brief Gets the sampling rate of the ADC
1001 *
1002 * @param readMode: read rate from driver or HW
1003 *
1004 * @return If success, return rate in Hz
1005 * if error, return -1
1006 ******************************************************************************/
1007 int64_t XCOMM_GetAdcSamplingRate(XCOMM_ReadMode readMode)
1008 {
1009 int64_t sampleRate;
1010
1011 if(readMode == XCOMM_ReadMode_FromHW)
1012 {
1013 sampleRate = ad9523_out_altvoltage_ADC_CLK_frequency(INT64_MAX);
1014 if(sampleRate < 0)
1015 return -1;
1016
1017 XCOMM_State.adcSampleRate = sampleRate;
1018 XCOMM_State.adcSampleRateValid = 1;
1019 }
1020
1021 return XCOMM_State.adcSampleRateValid ? XCOMM_State.adcSampleRate : -1;
1022 }
1023
1024 /**************************************************************************//**
1025 * @brief Sets the test mode of the ADC
1026 *
1027 * @param testMode - desired ADC test mode
1028 *
1029 * @param channel - ADC channel to set the test mode for
1030 *
1031 * @return If success, return new ADC test mode if success
1032 * if error, return -1
1033 ******************************************************************************/
1034 XCOMM_AdcTestMode XCOMM_SetAdcTestMode(XCOMM_AdcTestMode testMode, XCOMM_AdcChannel channel)
1035 {
1036 int32_t mode = ad9643_test_mode(testMode, channel);
1037
1038 if(mode < 0)
1039 return (XCOMM_AdcTestMode)-1;
1040
1041 XCOMM_State.adcTestMode = (XCOMM_AdcTestMode)mode;
1042 XCOMM_State.adcTestModeValid = 1;
1043
1044 return XCOMM_State.adcTestMode;
1045 }
1046
1047 /**************************************************************************//**
1048 * @brief Gets the test mode of the ADC
1049 *
1050 * @param readMode: read ADC test mode from driver or HW
1051 *
1052 * @return If success, return ADC test mode
1053 * if error,return -1
1054 ******************************************************************************/
1055 XCOMM_AdcTestMode XCOMM_GetAdcTestMode(XCOMM_ReadMode readMode)
1056 {
1057 int32_t mode;
1058
1059 if(readMode == XCOMM_ReadMode_FromHW)
1060 {
1061 mode = ad9643_test_mode(XCOMM_AdcTestMode_Ramp + 1, XCOMM_AdcChannel_All);
1062 if(mode < 0)
1063 return (XCOMM_AdcTestMode)-1;
1064
1065 XCOMM_State.adcTestMode = (XCOMM_AdcTestMode)mode;
1066 XCOMM_State.adcTestModeValid = 1;
1067 }
1068
1069 return XCOMM_State.adcTestModeValid ? XCOMM_State.adcTestMode : (XCOMM_AdcTestMode)-1;
1070 }
1071
1072 /**************************************************************************//**
1073 * @brief Sets the user test pattern of the ADC
1074 *
1075 * @param pattern: Buffer containing the test pattern (8 bytes)
1076 *
1077 * @return If success, returns 0
1078 * if error, returns -1
1079 ******************************************************************************/
1080 int32_t XCOMM_SetAdcUserTestPattern(uint8_t* pattern)
1081 {
1082 int32_t ret;
1083
1084 ret = ad9643_user_test_pattern(pattern);
1085
1086 return ret;
1087 }
1088
1089 /**************************************************************************//**
1090 * @brief Calibrates the ADC DCO clock delay
1091 *
1092 * @return If success, returns DCO clock delay code. If the DCO clock is
1093 * inverted 0x100 is added to the returned DCO value
1094 * if error,return -1
1095 ******************************************************************************/
1096 int32_t XCOMM_CalibrateAdcDco(void)
1097 {
1098 int32_t ret;
1099
1100 ret = ad9643_dco_calibrate();
1101
1102 return ret;
1103 }
1104
1105 /**************************************************************************//**
1106 * @brief Checks if the ADC DCO is locked
1107 *
1108 * @return If the DCO is locked returns 1
1109 * if the DCO is not locked returns 0
1110 ******************************************************************************/
1111 int32_t XCOMM_IsAdcDcoLocked(void)
1112 {
1113 return ad9643_is_dco_locked();
1114 }
1115
1116 /************************ DAC Functions **************************************/
1117
1118 /**************************************************************************//**
1119 * @brief Gets the available interpolation frequencies
1120 *
1121 * @param valArray: Array to store the return values.
1122 * The size of the array must be 5, the last valid value
1123 * in the array is followed by a 0.
1124 *
1125 * @return If success, return 0 if error, return -1
1126 ******************************************************************************/
1127 int32_t XCOMM_GetDacAvailableInterpolationFreq(int32_t* valArray)
1128 {
1129 return out_altvoltage_interpolation_frequency_available(valArray);
1130 }
1131
1132 /**************************************************************************//**
1133 * @brief Sets the DAC interpolation frequency
1134 *
1135 * @param interp: Interpolation frequency in Hz
1136 *
1137 * @return If success, return the set value if error, return -1
1138 ******************************************************************************/
1139 int32_t XCOMM_SetDacInterpolationFreq(int32_t interp)
1140 {
1141 return ad9122_out_altvoltage_interpolation_frequency(interp);
1142 }
1143
1144 /**************************************************************************//**
1145 * @brief Gets the available center shift frequencies
1146 *
1147 * @param valArray: Array to store the return values.
1148 * The size of the array must be 17, the last valid value
1149 * in the array is followed by a -1.
1150 *
1151 * @return If success, return 0 if error, return -1
1152 ******************************************************************************/
1153 int32_t XCOMM_GetDacAvailableCenterShiftFreq(int32_t* valArray)
1154 {
1155 return out_altvoltage_interpolation_center_shift_frequency_available(valArray);
1156 }
1157
1158 /**************************************************************************//**
1159 * @brief Sets the DAC center frequency shift
1160 *
1161 * @param shift: Center frequency shift in Hz
1162 *
1163 * @return If success, return the set value if error, return -1
1164 ******************************************************************************/
1165 int32_t XCOMM_SetDacCenterShiftFreq(int32_t shift)
1166 {
1167 return ad9122_out_altvoltage_interpolation_center_shift_frequency(shift);
1168 }
1169
1170 /**************************************************************************//**
1171 * @brief Sets the sampling rate of the DAC
1172 *
1173 * @param rate: desired rate in Hz
1174 *
1175 * @return If success, return exact calculated rate in Hz
1176 * if error, return -1
1177 ******************************************************************************/
1178 int64_t XCOMM_SetDacSamplingRate(uint64_t rate)
1179 {
1180 int32_t sampleRate;
1181
1182 sampleRate = ad9122_set_data_rate((uint32_t)rate);
1183
1184 if(sampleRate < 0)
1185 return -1;
1186
1187 XCOMM_State.dacSampleRate = sampleRate;
1188 XCOMM_State.dacSampleRateValid = 1;
1189
1190 return XCOMM_State.dacSampleRate;
1191 }
1192
1193 /**************************************************************************//**
1194 * @brief Gets the sampling rate of the DAC
1195 *
1196 * @param readMode: read rate from driver or HW
1197 *
1198 * @return If success, return rate in Hz
1199 * if error, return -1
1200 ******************************************************************************/
1201 int64_t XCOMM_GetDacSamplingRate(XCOMM_ReadMode readMode)
1202 {
1203 int64_t sampleRate;
1204
1205 if(readMode == XCOMM_ReadMode_FromHW)
1206 {
1207 sampleRate = ad9523_out_altvoltage_DAC_DCO_CLK_frequency(INT64_MAX);
1208 if(sampleRate < 0)
1209 return -1;
1210
1211 XCOMM_State.dacSampleRate = sampleRate;
1212 XCOMM_State.dacSampleRateValid = 1;
1213 }
1214
1215 return XCOMM_State.dacSampleRateValid ? XCOMM_State.dacSampleRate : -1;
1216 }
1217
1218 /**************************************************************************//**
1219 * @brief Sets offset and phase correction for I and Q in DAC
1220 *
1221 * @param iqCorrection: desired correction
1222 *
1223 * @return If success, return IQCorrection struct with error set to 0
1224 * if error, return IQCorrection struct with error set to -1
1225 ******************************************************************************/
1226 XCOMM_DacIQCorrection XCOMM_SetDacIqCorrection(XCOMM_DacIQCorrection daciqCorrection)
1227 {
1228
1229 XCOMM_State.dacIQCorrection.fsAdjI = ad9122_fs_adj_I_DAC(daciqCorrection.fsAdjI);
1230 XCOMM_State.dacIQCorrection.fsAdjQ = ad9122_fs_adj_Q_DAC(daciqCorrection.fsAdjQ);
1231
1232 XCOMM_State.dacIQCorrection.offsetI = ad9122_offset_I_DAC(daciqCorrection.offsetI);
1233 XCOMM_State.dacIQCorrection.offsetQ = ad9122_offset_Q_DAC(daciqCorrection.offsetQ);
1234
1235 XCOMM_State.dacIQCorrection.phaseAdjI = ad9122_phaseAdj_I_DAC(daciqCorrection.phaseAdjI);
1236 XCOMM_State.dacIQCorrection.phaseAdjQ = ad9122_phaseAdj_Q_DAC(daciqCorrection.phaseAdjQ);
1237
1238 XCOMM_State.dacIQCorrection.error = 0;
1239 XCOMM_State.dacIqCorrectionValid = 1;
1240
1241 return XCOMM_State.dacIQCorrection;
1242 }
1243
1244 /**************************************************************************//**
1245 * @brief Gets offset and phase correction for I and Q from DAC
1246 *
1247 * @param readMode: read rate from driver or HW
1248 *
1249 * @return If success, return IQCorrection struct with error set to 0
1250 * if error, return IQCorrection struct with error set to -1
1251 ******************************************************************************/
1252 XCOMM_DacIQCorrection XCOMM_GetDacIqCorrection(XCOMM_ReadMode readMode)
1253 {
1254 if(readMode == XCOMM_ReadMode_FromHW)
1255 {
1256 XCOMM_State.dacIQCorrection.fsAdjI = ad9122_fs_adj_I_DAC(INT32_MAX);
1257 XCOMM_State.dacIQCorrection.fsAdjQ = ad9122_fs_adj_Q_DAC(INT32_MAX);
1258
1259 XCOMM_State.dacIQCorrection.offsetI = ad9122_offset_I_DAC(INT32_MAX);
1260 XCOMM_State.dacIQCorrection.offsetQ = ad9122_offset_Q_DAC(INT32_MAX);
1261
1262 XCOMM_State.dacIQCorrection.phaseAdjI = ad9122_phaseAdj_I_DAC(INT32_MAX);
1263 XCOMM_State.dacIQCorrection.phaseAdjQ = ad9122_phaseAdj_Q_DAC(INT32_MAX);
1264
1265 XCOMM_State.dacIQCorrection.error = 0;
1266 XCOMM_State.dacIqCorrectionValid = 1;
1267 }
1268
1269 return XCOMM_State.dacIQCorrection;
1270 }
1271
1272 /**************************************************************************//**
1273 * @brief Calibrates the DAC DCI
1274 *
1275 * @return If success, returns 0
1276 * if error,returns -1
1277 ******************************************************************************/
1278 int32_t XCOMM_CalibrateDacDci(void)
1279 {
1280 return ad9122_dci_calibrate();
1281 }
1282
1283 /**************************************************************************//**
1284 * @brief Gets the DAC FIFO Status.
1285 *
1286 * @return If success, return XCOMM_DacFifoStatus struct with error set to 0
1287 * If error, return XCOMM_DacFifoStatus struct with error set to -1
1288 ******************************************************************************/
1289 XCOMM_DacFifoStatus XCOMM_GetDacFifoStatus(void)
1290 {
1291 XCOMM_DacFifoStatus status;
1292 int32_t ret = 0;
1293 uint8_t status1 = 0;
1294 uint8_t status2 = 0;
1295
1296 ret = ad9122_get_fifo_status_regs(&status1, &status2);
1297 if(ret < 0)
1298 {
1299 status.error = -1;
1300 }
1301 else
1302 {
1303 status.error = 0;
1304 }
1305 status.warning1 = ((status1 & 0x80) >> 7);
1306 status.warning2 = ((status1 & 0x40) >> 6);
1307 status.softAlignAck = ((status1 & 0x04) >> 2);
1308 status.softAlignReq = ((status1 & 0x02) >> 1);
1309 status.level = status2;
1310
1311 return status;
1312 }
1313
1314 /**************************************************************************//**
1315 * @brief Sets the DAC input data format.
1316 *
1317 * @param format - The input data format.
1318 * Example: TWOS_COMPLEMENT_FORMAT - input data is in twos complement format.
1319 * BINARY_FORMAT - input data is in binary format.
1320 *
1321 * @return Returns negative error code in case of error or the set
1322 * input data format.
1323 ******************************************************************************/
1324 int32_t XCOMM_SetDacDataFormat(uint8_t dataFormat)
1325 {
1326 return ad9122_set_data_format(dataFormat);
1327 }
1328
1329 /***************************************************************************//**
1330 * @brief Gets the DAC die temperature code.
1331 *
1332 * @return Returns negative error code in case of error or the
1333 * die temperature code.
1334 *******************************************************************************/
1335 int32_t XCOMM_GetDacTemperatureCode(void)
1336 {
1337 return ad9122_get_temperature_code();
1338 }
1339
1340 /***************************************************************************//**
1341 * @brief Gets the DAC die temperature.
1342 *
1343 * @param calibTemp: The known temperature in milli degrees Celsius.
1344 * @param calibTempCode: The readback code for the known temperature.
1345 *
1346 * @return Returns negative error code in case of error or the die temperature
1347 * in milli degrees Celsius.
1348 *******************************************************************************/
1349 int32_t XCOMM_GetDacTemperature(int32_t calibTemp, int32_t calibTempCode)
1350 {
1351 int32_t tempCode;
1352 int32_t temp;
1353
1354 tempCode = ad9122_get_temperature_code();
1355 if(tempCode < 0)
1356 return -1;
1357
1358 temp = ((tempCode - calibTempCode) * 77 + calibTemp * 10 + 10000) / 10;
1359
1360 return temp;
1361 }