| 1 | /***************************************************************************//** |
| 2 | * @file AD9643.h |
| 3 | * @brief Header file of AD9643 Driver. |
| 4 | * @author DBogdan ([email protected]) |
| 5 | ******************************************************************************** |
| 6 | * Copyright 2012(c) Analog Devices, Inc. |
| 7 | * |
| 8 | * All rights reserved. |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or without |
| 11 | * modification, are permitted provided that the following conditions are met: |
| 12 | * - Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * - Redistributions in binary form must reproduce the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer in |
| 16 | * the documentation and/or other materials provided with the |
| 17 | * distribution. |
| 18 | * - Neither the name of Analog Devices, Inc. nor the names of its |
| 19 | * contributors may be used to endorse or promote products derived |
| 20 | * from this software without specific prior written permission. |
| 21 | * - The use of this software may or may not infringe the patent rights |
| 22 | * of one or more patent holders. This license does not release you |
| 23 | * from the requirement that you obtain separate licenses from these |
| 24 | * patent holders to use this software. |
| 25 | * - Use of the software either in source or binary form, must be run |
| 26 | * on or directly connected to an Analog Devices Inc. component. |
| 27 | * |
| 28 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR |
| 29 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
| 30 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 31 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 33 | * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 34 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 36 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 38 | * |
| 39 | ******************************************************************************** |
| 40 | * SVN Revision: $WCREV$ |
| 41 | *******************************************************************************/ |
| 42 | #ifndef _AD9643_H_ |
| 43 | #define _AD9643_H_ |
| 44 | |
| 45 | /*****************************************************************************/ |
| 46 | /***************************** Include Files *********************************/ |
| 47 | /*****************************************************************************/ |
| 48 | #include <stdint.h> |
| 49 | |
| 50 | /******************************************************************************/ |
| 51 | /***************************** AD9643 *****************************************/ |
| 52 | /******************************************************************************/ |
| 53 | /* Chip configuration registers */ |
| 54 | #define AD9643_REG_SPI_CONFIG 0x00 |
| 55 | #define AD9643_REG_CHIP_ID 0x01 |
| 56 | #define AD9643_REG_CHIP_GRADE 0x02 |
| 57 | |
| 58 | /* Channel index and transfer registers */ |
| 59 | #define AD9643_REG_CHANNEL_IDX 0x05 |
| 60 | #define AD9643_REG_TRANSFER 0xFF |
| 61 | |
| 62 | /* ADC functions registers */ |
| 63 | #define AD9643_REG_PWR_MODES 0x08 |
| 64 | #define AD9643_REG_GLOBAL_CLK 0x09 |
| 65 | #define AD9643_REG_CLK_DIV 0x0B |
| 66 | #define AD9643_REG_TEST_MODE 0x0D |
| 67 | #define AD9643_REG_BIST_EN 0x0E |
| 68 | #define AD9643_REG_OFFSET_ADJ 0x10 |
| 69 | #define AD9643_REG_OUTPUT_MODE 0x14 |
| 70 | #define AD9643_REG_OUTPUT_ADJ 0x15 |
| 71 | #define AD9643_REG_CLK_PHASE_CTRL 0x16 |
| 72 | #define AD9643_REG_DCO_OUTPUT_DELAY 0x17 |
| 73 | #define AD9643_REG_INPUT_SPAN_SEL 0x18 |
| 74 | #define AD9643_REG_USER_TEST_PATTERN_1LSB 0x19 |
| 75 | #define AD9643_REG_USER_TEST_PATTERN_1MSB 0x1A |
| 76 | #define AD9643_REG_USER_TEST_PATTERN_2LSB 0x1B |
| 77 | #define AD9643_REG_USER_TEST_PATTERN_2MSB 0x1C |
| 78 | #define AD9643_REG_USER_TEST_PATTERN_3LSB 0x1D |
| 79 | #define AD9643_REG_USER_TEST_PATTERN_3MSB 0x1E |
| 80 | #define AD9643_REG_USER_TEST_PATTERN_4LSB 0x1F |
| 81 | #define AD9643_REG_USER_TEST_PATTERN_4MSB 0x20 |
| 82 | #define AD9643_REG_BIST_SIGNATURE_LSB 0x24 |
| 83 | #define AD9643_REG_BIST_SIGNATURE_MSB 0x25 |
| 84 | #define AD9643_REG_SYNC_CONTROL 0x3A |
| 85 | |
| 86 | /* SPI_CONFIG Bit Definitions */ |
| 87 | #define AD9643_SPI_CONFIG_LSB_FIRST ((1 << 1) | (1 << 6)) |
| 88 | #define AD9643_SPI_CONFIG_SOFT_RESET ((1 << 2) | (1 << 5)) |
| 89 | |
| 90 | /* CHIP_GRADE Bit Definitions */ |
| 91 | #define AD9643_CHIP_GRADE_SPEED_GRADE_ID(x) ((x) & (0x03 << 4)) |
| 92 | |
| 93 | /* CHANNEL_IDX Bit Definitions */ |
| 94 | #define AD9643_CHANNEL_IDX_ADC_A (1 << 0) |
| 95 | #define AD9643_CHANNEL_IDX_ADC_B (1 << 1) |
| 96 | #define AD9643_CHANNEL_IDX_ADC_AB (0x03) |
| 97 | |
| 98 | /* REG_TRANSFER Bit Definitions */ |
| 99 | #define AD9643_TRANSFER_EN (1 << 0) |
| 100 | |
| 101 | /* REG_PWR_MODES Bit Definitions */ |
| 102 | #define AD9643_PWR_MODES_INT_PWR_DOWN_MODE(x) ((x) & 0x03) |
| 103 | #define AD9643_PWR_MODES_EXT_PWR_DOWN_PIN_FNC (1 << 5) |
| 104 | |
| 105 | /* GLOBAL_CLK Bit Definitions */ |
| 106 | #define AD9643_GLOBAL_CLK_DUTY_CYCLE_STABILIZER_EN (1 << 0) |
| 107 | |
| 108 | /* CLK_DIV Bit Definitions */ |
| 109 | #define AD9643_CLK_DIV_RATIO(x) ((x) & 0x07) |
| 110 | #define AD9643_CLK_IN_CLK_DIV_PHASE_ADJ(x) (((x) & 0x07) << 3) |
| 111 | |
| 112 | /* TEST_MODE Bit Definitions */ |
| 113 | #define AD9643_TEST_MODE_OUTPUT_MODE(x) ((x) & 0x0F) |
| 114 | #define AD9643_TEST_MODE_RESET_PN_SHORT_GEN (1 << 4) |
| 115 | #define AD9643_TEST_MODE_RESET_PN_LONG_GEN (1 << 5) |
| 116 | #define AD9643_TEST_MODE_CTRL (1 << 7) |
| 117 | |
| 118 | /* Test Modes Definitions */ |
| 119 | #define AD9643_TEST_MODE_OFF 0x00 |
| 120 | #define AD9643_TEST_MODE_MIDSCALE_SHORT 0x01 |
| 121 | #define AD9643_TEST_MODE_POSITIVE_FS 0x02 |
| 122 | #define AD9643_TEST_MODE_NEGATIVE_FS 0x03 |
| 123 | #define AD9643_TEST_MODE_ALTERNATING_CHECKERBOARD 0x04 |
| 124 | #define AD9643_TEST_MODE_PN23_SEQ 0x05 |
| 125 | #define AD9643_TEST_MODE_PN9_SEQ 0x06 |
| 126 | #define AD9643_TEST_MODE_ONE_ZERO_TOGGLE 0x07 |
| 127 | #define AD9643_TEST_MODE_USER_MODE 0x08 |
| 128 | #define AD9643_TEST_MODE_RAMP 0x0F |
| 129 | |
| 130 | /* BIST_EN Bit Definitions */ |
| 131 | #define AD9643_BIST_EN (1 << 0) |
| 132 | #define AD9643_BIST_EN_RESET_BISRT_SEQ (1 << 1) |
| 133 | |
| 134 | /* OFFSET_ADJ Bit Definitions */ |
| 135 | #define AD9643_OFFSET_ADJ(x) ((x) & 0x3F) |
| 136 | |
| 137 | /* OUTPUT_MODE Bit Definitions */ |
| 138 | #define AD9643_OUTPUT_MODE_DEF 0x00 |
| 139 | #define AD9643_OUTPUT_MODE_OFFSET_BINARY 0x0 |
| 140 | #define AD9643_OUTPUT_MODE_TWOS_COMPLEMENT 0x1 |
| 141 | #define AD9643_OUTPUT_MODE_GRAY_CODE 0x2 |
| 142 | #define AD9643_OUTPUT_MODE_OUTPUT_FORMAT(x) ((x) & 0x03) |
| 143 | #define AD9643_OUTPUT_MODE_OUTPUT_INVERT (1 << 2) |
| 144 | #define AD9643_OUTPUT_MODE_OUTPUT_EN (1 << 4) |
| 145 | |
| 146 | /* OUTPUT_ADJ Bit Definitions */ |
| 147 | #define AD9643_REG_OUTPUT_ADJ_VAL(x) ((x) & 0x0F) |
| 148 | |
| 149 | /* CLK_PHASE_CTRL Bit Definitions */ |
| 150 | #define AD9643_CLK_PHASE_CTRL_EVEN_ODD_MODE_EN 0x20 |
| 151 | #define AD9643_CLK_PHASE_CTRL_MODE (1 << 5) |
| 152 | #define AD9643_CLK_PHASE_CTRL_INVERT_DCO_CLK (1 << 7) |
| 153 | |
| 154 | /* DCO_OUTPUT_DELAY Bit Definitions */ |
| 155 | #define AD9643_DCO_OUTPUT_DELAY_DCO_CLK_DELAY(x) ((x) & 0x1F) |
| 156 | #define AD9643_DCO_OUTPUT_DELAY_EN_DCO_CLK_DELAY (1 << 7) |
| 157 | |
| 158 | /* INPUT_SPAN_SEL Bit Definitions */ |
| 159 | #define AD9643_INPUT_SPAN_SEL_FULL_SCALE_VOLTAGE(x) ((x) & 0x1F) |
| 160 | |
| 161 | /* SYNC_CONTROL Bit Definitions */ |
| 162 | #define AD9643_SYNC_CONTROL_MASTER_SYNC_BUF_EN (1 << 0) |
| 163 | #define AD9643_SYNC_CONTROL_CLK_DIV_SYNC_EN (1 << 1) |
| 164 | #define AD9643_SYNC_CONTROL_CLK_DIV_NEXT_SYNC_ONLY (1 << 2) |
| 165 | |
| 166 | /******************************************************************************/ |
| 167 | /************************ Functions Declarations ******************************/ |
| 168 | /******************************************************************************/ |
| 169 | /** Initializes the AD9643. */ |
| 170 | int32_t ad9643_setup(); |
| 171 | /** Resets the device. */ |
| 172 | int32_t ad9643_reset(); |
| 173 | /** Configures the external power-down pin function. */ |
| 174 | int32_t ad9643_ext_pwd_pin_fnc(int32_t fnc); |
| 175 | /** Configures the power mode. */ |
| 176 | int32_t ad9643_pwd_mode(int32_t mode); |
| 177 | /** Enables (0) or disables (1) the duty cycle stabilizer. */ |
| 178 | int32_t ad9643_clock_duty_cycle_stabilizer(int32_t en); |
| 179 | /** Configures the input clock divide ratio and returns the set divide ratio. */ |
| 180 | int32_t ad9643_clock_divide_ratio(int32_t ratio); |
| 181 | /** Configures the phase adjustment in clock cycles delay and returns the set phase adjustment. */ |
| 182 | int32_t ad9643_clock_phase_adj(int32_t adj); |
| 183 | /** Sets the offset adjustment. Returns the set offset adjustment. */ |
| 184 | int32_t ad9643_offset_adj(int32_t adj); |
| 185 | /** Enables (1) or disables (0) the data output. Returns output enable state. */ |
| 186 | int32_t ad9643_output_enable(int32_t en); |
| 187 | /** Activates the normal (1) or inverted output mode. Returns the set output mode. */ |
| 188 | int32_t ad9643_output_invert(int32_t invert); |
| 189 | /** Specifies the output formatReturns the set output format. */ |
| 190 | int32_t ad9643_output_format(int32_t format); |
| 191 | /** Sets the output current adjustment. Returns the set current adjustment. */ |
| 192 | int32_t ad9643_output_current_adj(int32_t adj); |
| 193 | /** Activates the normal (0) or inverted (1) DCO clock. Returns the DCO clock inversion status. */ |
| 194 | int32_t ad9643_dco_clock_invert(int32_t invert); |
| 195 | /** Enables (0) or disables (1) the even/odd mode output. Returns the set clock mode. */ |
| 196 | int32_t ad9643_dco_clock_mode(int32_t mode); |
| 197 | /** Configures the clock delay setting. Returns the set clock delay. */ |
| 198 | int32_t ad9643_dco_output_clock_delay(int32_t delay); |
| 199 | /** Configures the full-scale input voltage selection. Returns the set input voltage selection. */ |
| 200 | int32_t ad9643_input_span(int32_t span); |
| 201 | /** Sets the ADC's test mode. Returns the set test mode. */ |
| 202 | int32_t ad9643_test_mode(int32_t mode, int32_t chan_mask); |
| 203 | /** Sets the ADC's user test pattern. */ |
| 204 | int32_t ad9643_user_test_pattern(uint8_t* pattern); |
| 205 | /** Calibrates the DCO clock delay. */ |
| 206 | int32_t ad9643_dco_calibrate(); |
| 207 | /** Checks if the DCO is locked. */ |
| 208 | int32_t ad9643_is_dco_locked(); |
| 209 | |
| 210 | #endif /* __AD9643_H__ */ |