| 1 | /**************************************************************************//** |
| 2 | * @file xcomm.h |
| 3 | * @brief XCOMM interface header file. |
| 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 | #ifndef __XCOMM_H__ |
| 45 | #define __XCOMM_H__ |
| 46 | |
| 47 | /*****************************************************************************/ |
| 48 | /***************************** Include Files *********************************/ |
| 49 | /*****************************************************************************/ |
| 50 | #include <stdint.h> |
| 51 | |
| 52 | /******************************************************************************/ |
| 53 | /***************************** XCOMM *****************************************/ |
| 54 | /******************************************************************************/ |
| 55 | |
| 56 | /** ADC Test Modes Definitions */ |
| 57 | typedef enum |
| 58 | { |
| 59 | XCOMM_AdcTestMode_Off = 0x00, |
| 60 | XCOMM_AdcTestMode_MidscaleShort = 0x01, |
| 61 | XCOMM_AdcTestMode_PositiveFs = 0x02, |
| 62 | XCOMM_AdcTestMode_NegativeFs = 0x03, |
| 63 | XCOMM_AdcTestMode_AlternatingCheckerboard = 0x04, |
| 64 | XCOMM_AdcTestMode_Pn23Seq = 0x05, |
| 65 | XCOMM_AdcTestMode_Pn9Seq = 0x06, |
| 66 | XCOMM_AdcTestMode_OneZeroToggle = 0x07, |
| 67 | XCOMM_AdcTestMode_UserMode = 0x08, |
| 68 | XCOMM_AdcTestMode_Ramp = 0x0F, |
| 69 | }XCOMM_AdcTestMode; |
| 70 | |
| 71 | /** ADC Channels */ |
| 72 | typedef enum |
| 73 | { |
| 74 | XCOMM_AdcChannel_A = 0x01, |
| 75 | XCOMM_AdcChannel_B = 0x02, |
| 76 | XCOMM_AdcChannel_All = 0x03 |
| 77 | }XCOMM_AdcChannel; |
| 78 | |
| 79 | /** Read Modes Definitions */ |
| 80 | typedef enum |
| 81 | { |
| 82 | XCOMM_ReadMode_FromDriver = 0, |
| 83 | XCOMM_ReadMode_FromHW = 1, |
| 84 | }XCOMM_ReadMode; |
| 85 | |
| 86 | /** FMC Ports Definitions */ |
| 87 | typedef enum |
| 88 | { |
| 89 | FMC_LPC = 0, |
| 90 | FMC_HPC |
| 91 | }XCOMM_FmcPort; |
| 92 | |
| 93 | /** Carrier Boards Definitions */ |
| 94 | typedef enum |
| 95 | { |
| 96 | XILINX_ML605 = 0, |
| 97 | XILINX_AC701, |
| 98 | XILINX_KC705, |
| 99 | XILINX_VC707, |
| 100 | XILINX_ZC702, |
| 101 | XILINX_ZC706, |
| 102 | DIGILENT_ZED, |
| 103 | }XCOMM_CarrierBoard; |
| 104 | |
| 105 | /** Version Buffer Definitions */ |
| 106 | typedef struct |
| 107 | { |
| 108 | int8_t value[128]; |
| 109 | int32_t error; |
| 110 | }XCOMM_Version; |
| 111 | |
| 112 | /** Tx IQ Correction Definitions */ |
| 113 | typedef struct |
| 114 | { |
| 115 | int16_t offsetI; |
| 116 | int16_t phaseAdjI; |
| 117 | int32_t fsAdjI; |
| 118 | int16_t offsetQ; |
| 119 | int16_t phaseAdjQ; |
| 120 | int32_t fsAdjQ; |
| 121 | int32_t error; |
| 122 | }XCOMM_TxIQCorrection; |
| 123 | |
| 124 | |
| 125 | /** Rx IQ Correction Definitions */ |
| 126 | typedef struct |
| 127 | { |
| 128 | int16_t gainI; |
| 129 | int16_t offsetI; |
| 130 | int16_t gainQ; |
| 131 | int16_t offsetQ; |
| 132 | int32_t error; |
| 133 | }XCOMM_RxIQCorrection; |
| 134 | |
| 135 | typedef XCOMM_TxIQCorrection XCOMM_DacIQCorrection; |
| 136 | |
| 137 | /* DAC FIFO Status Definitions */ |
| 138 | typedef struct |
| 139 | { |
| 140 | int8_t warning1; |
| 141 | int8_t warning2; |
| 142 | int8_t softAlignAck; |
| 143 | int8_t softAlignReq; |
| 144 | int8_t level; |
| 145 | int8_t error; |
| 146 | }XCOMM_DacFifoStatus; |
| 147 | |
| 148 | /* DAC input data format definitions */ |
| 149 | #define TWOS_COMPLEMENT_FORMAT 0 |
| 150 | #define BINARY_FORMAT 1 |
| 151 | |
| 152 | /** XCOMM Default Initialization Structure */ |
| 153 | typedef struct |
| 154 | { |
| 155 | XCOMM_FmcPort fmcPort; |
| 156 | XCOMM_CarrierBoard carrierBoard; |
| 157 | uint64_t adcSamplingRate; |
| 158 | uint64_t dacSamplingRate; |
| 159 | int32_t rxGain1000; |
| 160 | uint64_t rxFrequency; |
| 161 | uint64_t txFrequency; |
| 162 | }XCOMM_DefaultInit; |
| 163 | |
| 164 | /*****************************************************************************/ |
| 165 | /************************ Functions Declarations *****************************/ |
| 166 | /*****************************************************************************/ |
| 167 | |
| 168 | /** Initializes the I2C peripheral */ |
| 169 | /* ** if success, return 0 */ |
| 170 | /* ** if error, return -1 */ |
| 171 | int32_t XCOMM_InitI2C(XCOMM_DefaultInit* pDefInit); |
| 172 | |
| 173 | /** Initializes the XCOMM board */ |
| 174 | /* ** if success, return 0 */ |
| 175 | /* ** if error, return -1 */ |
| 176 | int32_t XCOMM_Init(XCOMM_DefaultInit* pDefInit); |
| 177 | |
| 178 | /** Initializes the Rx path */ |
| 179 | /* ** if success, return 0 */ |
| 180 | /* ** if error, return -1 */ |
| 181 | int32_t XCOMM_InitRx(XCOMM_DefaultInit* pDefInit); |
| 182 | |
| 183 | /** Initializes the Tx path */ |
| 184 | /* ** if success, return 0 */ |
| 185 | /* ** if error, return -1 */ |
| 186 | int32_t XCOMM_InitTx(XCOMM_DefaultInit* pDefInit); |
| 187 | |
| 188 | /** Stops the Rx path */ |
| 189 | /* ** if success, return 0 */ |
| 190 | /* ** if error, return -1 */ |
| 191 | int32_t XCOMM_StopRx(void); |
| 192 | |
| 193 | /** Stops the Tx path */ |
| 194 | /* ** if success, return 0 */ |
| 195 | /* ** if error, return -1 */ |
| 196 | int32_t XCOMM_StopTx(void); |
| 197 | |
| 198 | /** Resync driver cached values by reading the XCOMM board */ |
| 199 | /* ** if success, return 0 */ |
| 200 | /* ** if error, return -1 */ |
| 201 | int32_t XCOMM_Sync(void); |
| 202 | |
| 203 | /** Gets the XCOMM board version string*/ |
| 204 | /* ** readMode: read version from driver or HW */ |
| 205 | /* ** if success, return version struct with version string and error set to 0 */ |
| 206 | /* ** if error, return version struct with error set to -1 */ |
| 207 | XCOMM_Version XCOMM_GetBoardVersion(XCOMM_ReadMode readMode); |
| 208 | |
| 209 | /** Gets the PIC firmware version*/ |
| 210 | /* ** if success, returns the PIC firmware version number - 0 to 100 */ |
| 211 | /* ** if error returns -1 */ |
| 212 | int32_t XCOMM_GetPicFwVersion(); |
| 213 | |
| 214 | /************************ Rx Functions *****************************/ |
| 215 | |
| 216 | /** Sets the Rx center frequency */ |
| 217 | /* ** frequency: desired frequency in Hz */ |
| 218 | /* ** if success, return exact calculated frequency in Hz */ |
| 219 | /* ** if error, return -1 */ |
| 220 | int64_t XCOMM_SetRxFrequency(uint64_t frequency); |
| 221 | |
| 222 | /** Gets the Rx center frequency */ |
| 223 | /* ** if success, return frequency in Hz stored in driver */ |
| 224 | /* ** if error, return -1 */ |
| 225 | int64_t XCOMM_GetRxFrequency(void); |
| 226 | |
| 227 | /** Sets the Rx center frequency resolution */ |
| 228 | /* ** resolution: desired frequency resolution in Hz */ |
| 229 | /* ** if success, return exact calculated resolution in Hz */ |
| 230 | /* ** if error, return -1 */ |
| 231 | int32_t XCOMM_SetRxResolution(uint32_t resolution); |
| 232 | |
| 233 | /** Gets the Rx center frequency resolution */ |
| 234 | /* ** readMode: read frequency resolution from driver or HW */ |
| 235 | /* ** if success, return frequency resolution in Hz */ |
| 236 | /* ** if error, return -1 */ |
| 237 | int32_t XCOMM_GetRxResolution(XCOMM_ReadMode readMode); |
| 238 | |
| 239 | /** Sets the Rx gain */ |
| 240 | /* ** gain1000: desired gain (x1000) in dB */ |
| 241 | /* ** if success, return calculated gain (x1000) in dB */ |
| 242 | /* ** if error, return -1 */ |
| 243 | int32_t XCOMM_SetRxGain(int32_t gain1000); |
| 244 | |
| 245 | /** Gets the Rx gain */ |
| 246 | /* ** readMode: read gain from driver or HW */ |
| 247 | /* ** if success, return gain (x1000) in dB */ |
| 248 | /* ** if error, return -1 */ |
| 249 | int32_t XCOMM_GetRxGain(XCOMM_ReadMode readMode); |
| 250 | |
| 251 | /** Gets the Rx gain and phase correction for I and Q */ |
| 252 | /* ** frequency: center frequency used for the correction in Hz */ |
| 253 | /* ** readMode: read gain and phase correction from driver or HW */ |
| 254 | /* ** if success, return IQCorrection struct with gain and phase correction for the frequency and error set to 0 */ |
| 255 | /* ** if error, return IQCorrection struct with error set to -1 */ |
| 256 | XCOMM_RxIQCorrection XCOMM_GetRxIqCorrection(uint64_t frequency, XCOMM_ReadMode readMode); |
| 257 | |
| 258 | /************************ Tx Functions *****************************/ |
| 259 | |
| 260 | /** Sets the Tx center frequency */ |
| 261 | /* ** frequency: desired frequency in Hz */ |
| 262 | /* ** if success, return calculated frequency in Hz */ |
| 263 | /* ** if error, return -1 */ |
| 264 | int64_t XCOMM_SetTxFrequency(uint64_t frequency); |
| 265 | |
| 266 | /** Gets the Tx center frequency */ |
| 267 | /* ** if success, return frequency in Hz stored in driver */ |
| 268 | /* ** if error, return -1 */ |
| 269 | int64_t XCOMM_GetTxFrequency(void); |
| 270 | |
| 271 | /** Sets the Tx center frequency resolution */ |
| 272 | /* ** resolution: desired frequency resolution in Hz */ |
| 273 | /* ** if success, return exact calculated resolution in Hz */ |
| 274 | /* ** if error, return -1 */ |
| 275 | int32_t XCOMM_SetTxResolution(uint32_t resolution); |
| 276 | |
| 277 | /** Gets the Tx center frequency resolution */ |
| 278 | /* ** readMode: read frequency resolution from driver or HW */ |
| 279 | /* ** if success, return frequency resolution in Hz */ |
| 280 | /* ** if error, return -1 */ |
| 281 | int32_t XCOMM_GetTxResolution(XCOMM_ReadMode readMode); |
| 282 | |
| 283 | /** Gets the Tx gain and phase correction for I and Q */ |
| 284 | /* ** frequency: center frequency used for the correction in Hz*/ |
| 285 | /* ** readMode: read gain and phase correction from driver or HW */ |
| 286 | /* ** if success, return IQCorrection struct with gain and phase correction for the frequency and error set to 0 */ |
| 287 | /* ** if error, return IQCorrection struct with error set to -1 */ |
| 288 | XCOMM_TxIQCorrection XCOMM_GetTxIqCorrection(uint64_t frequency, XCOMM_ReadMode readMode); |
| 289 | |
| 290 | /************************ ADC Functions *****************************/ |
| 291 | |
| 292 | /** Sets the sampling rate of the ADC */ |
| 293 | /* ** rate: desired rate in Hz */ |
| 294 | /* ** if success, return exact calculated rate in Hz */ |
| 295 | /* ** if error, return -1 */ |
| 296 | int64_t XCOMM_SetAdcSamplingRate(uint64_t rate); |
| 297 | |
| 298 | /** Gets the sampling rate of the ADC */ |
| 299 | /* ** readMode: read rate from driver or HW */ |
| 300 | /* ** if success, return rate in Hz */ |
| 301 | /* ** if error, return -1 */ |
| 302 | int64_t XCOMM_GetAdcSamplingRate(XCOMM_ReadMode); |
| 303 | |
| 304 | /** Sets the test mode of the ADC */ |
| 305 | /* ** testMode: desired ADC test mode */ |
| 306 | /* ** channel: ADC channel to set the test mode for */ |
| 307 | /* ** if success, return new ADC test mode if success */ |
| 308 | /* ** if error, return -1 */ |
| 309 | XCOMM_AdcTestMode XCOMM_SetAdcTestMode(XCOMM_AdcTestMode testMode, XCOMM_AdcChannel channel); |
| 310 | |
| 311 | /** Gets the test mode of the ADC */ |
| 312 | /* ** readMode: read ADC test mode from driver or HW */ |
| 313 | /* ** if success, return ADC test mode */ |
| 314 | /* ** if error,return -1 */ |
| 315 | XCOMM_AdcTestMode XCOMM_GetAdcTestMode(XCOMM_ReadMode readMode); |
| 316 | |
| 317 | /** Sets the user test pattern of the ADC */ |
| 318 | /* ** pattern: buffer containing the test pattern (8 bytes) */ |
| 319 | /* ** if success, returns 0 */ |
| 320 | /* ** if error,return -1 */ |
| 321 | int32_t XCOMM_SetAdcUserTestPattern(uint8_t* pattern); |
| 322 | |
| 323 | /** Calibrates the ADC DCO clock delay */ |
| 324 | /* ** if success, returns DCO clock delay code */ |
| 325 | /* ** if error,return -1 */ |
| 326 | int32_t XCOMM_CalibrateAdcDco(void); |
| 327 | |
| 328 | /** Checks if the ADC DCO is locked */ |
| 329 | /* ** if the DCO is locked returns 1 */ |
| 330 | /* ** if the DCO is not locked returns 0 */ |
| 331 | int32_t XCOMM_IsAdcDcoLocked(void); |
| 332 | |
| 333 | /************************ DAC Functions *****************************/ |
| 334 | |
| 335 | /** Gets the available interpolation frequencies */ |
| 336 | /* ** valArray: Array to store the return values. */ |
| 337 | /* ** if success, return 0 */ |
| 338 | /* ** if error, return -1 */ |
| 339 | int32_t XCOMM_GetDacAvailableInterpolationFreq(int32_t* valArray); |
| 340 | |
| 341 | /** Sets the DAC interpolation frequency */ |
| 342 | /* ** interp: Interpolation frequency in Hz */ |
| 343 | /* ** if success, return the set value */ |
| 344 | /* ** if error, return -1 */ |
| 345 | int32_t XCOMM_SetDacInterpolationFreq(int32_t interp); |
| 346 | |
| 347 | /** Gets the available center shift frequencies */ |
| 348 | /* ** valArray: Array to store the return values. */ |
| 349 | /* ** if success, return 0 */ |
| 350 | /* ** if error, return -1 */ |
| 351 | int32_t XCOMM_GetDacAvailableCenterShiftFreq(int32_t* valArray); |
| 352 | |
| 353 | /** Sets the DAC center frequency shift */ |
| 354 | /* ** shift: Center frequency shift in Hz*/ |
| 355 | /* ** if success, return the set value */ |
| 356 | /* ** if error, return -1 */ |
| 357 | int32_t XCOMM_SetDacCenterShiftFreq(int32_t shift); |
| 358 | |
| 359 | /** Sets the sampling rate of the DAC */ |
| 360 | /* ** rate: desired rate in Hz */ |
| 361 | /* ** if success, return exact calculated rate in Hz */ |
| 362 | /* ** if error, return -1 */ |
| 363 | int64_t XCOMM_SetDacSamplingRate(uint64_t rate); |
| 364 | |
| 365 | /** Gets the sampling rate of the DAC */ |
| 366 | /* ** readMode: read rate from driver or HW */ |
| 367 | /* ** if success, return rate in Hz */ |
| 368 | /* ** if error, return -1 */ |
| 369 | int64_t XCOMM_GetDacSamplingRate(XCOMM_ReadMode readMode); |
| 370 | |
| 371 | /** Sets offset and phase correction for I and Q in DAC*/ |
| 372 | /* ** daciqCorrection: desired correction*/ |
| 373 | /* ** if success, return IQCorrection struct with offset and phase correction and error set to 0 */ |
| 374 | /* ** if error, return IQCorrection struct with error set to -1 */ |
| 375 | XCOMM_DacIQCorrection XCOMM_SetDacIqCorrection(XCOMM_DacIQCorrection daciqCorrection); |
| 376 | |
| 377 | /** Gets offset and phase correction for I and Q from DAC*/ |
| 378 | /* ** readMode: read DAC correction from driver or HW */ |
| 379 | /* ** if success, return IQCorrection struct with offset and phase correction and error set to 0 */ |
| 380 | /* ** if error, return IQCorrection struct with error set to -1 */ |
| 381 | XCOMM_DacIQCorrection XCOMM_GetDacIqCorrection(XCOMM_ReadMode readMode); |
| 382 | |
| 383 | /** Calibrates the DAC DCI */ |
| 384 | /* ** if success, returns 0 */ |
| 385 | /* ** if error,return -1 */ |
| 386 | int32_t XCOMM_CalibrateDacDci(void); |
| 387 | |
| 388 | /** Gets the DAC FIFO Status. */ |
| 389 | /* ** if success, return XCOMM_DacFifoStatus with error set to 0*/ |
| 390 | /* ** if error, return XCOMM_DacFifoStatus with error set to -1 */ |
| 391 | XCOMM_DacFifoStatus XCOMM_GetDacFifoStatus(void); |
| 392 | |
| 393 | /** Sets the DAC input data format. */ |
| 394 | /* if success, return the set input data format.*/ |
| 395 | /* if error, return -1 */ |
| 396 | int32_t XCOMM_SetDacDataFormat(uint8_t dataFormat); |
| 397 | |
| 398 | /** Gets the DAC die temperature code. */ |
| 399 | /* ** if success, return the die temperature code */ |
| 400 | /* ** if error, return -1 */ |
| 401 | int32_t XCOMM_GetDacTemperatureCode(void); |
| 402 | |
| 403 | /** Gets the DAC die temperature. */ |
| 404 | /* ** calibTemp: the known temperature in milli degrees Celsius */ |
| 405 | /* ** calibTempCode: the readback code for the known temperature */ |
| 406 | /* ** if success, return the die temperature in milli degrees Celsius */ |
| 407 | /* ** if error, return -1 */ |
| 408 | int32_t XCOMM_GetDacTemperature(int32_t calibTemp, int32_t calibTempCode); |
| 409 | |
| 410 | #endif /* __XCOMM_H__ */ |