Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/device_drivers/ADF4156/ADF4156.h

raw symbols SCIP
1 /***************************************************************************//**
2 * @file adf4156.h
3 * @brief Header file of AD9833 Driver for Microblaze processor.
4 * @author Lucian Sin ([email protected])
5 *
6 ********************************************************************************
7 * Copyright 2013(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 #ifndef _ADF4156_H_
42 #define _ADF4156_H_
43
44 /******************************************************************************/
45 /******************************* Include Files ********************************/
46 /******************************************************************************/
47 #include "Communication.h"
48
49 /******************************************************************************/
50 /********************* Macros and Constants Definitions ***********************/
51 /******************************************************************************/
52 /* FRAC/INT Register R0 */
53 /* MUXOUT Control */
54 #define ADF4156_MUXOUT_Z (0x00 << 27)
55 #define ADF4156_MUXOUT_DVdd (0x01 << 27)
56 #define ADF4156_MUXOUT_DGND (0x02 << 27)
57 #define ADF4156_MUXOUT_RDIV (0x03 << 27)
58 #define ADF4156_MUXOUT_NDIV (0x04 << 27)
59 #define ADF4156_MUXOUT_ALOCK (0x05 << 27)
60 #define ADF4156_MUXOUT_DLOCK (0x06 << 27)
61 #define ADF4156_MUXOUT_SDO (0x07 << 27)
62 #define ADF4156_MUXOUT_CLKDIV (0x0A << 27)
63 #define ADF4156_MUXOUT_FLS (0x0C << 27)
64 #define ADF4156_MUXOUT_RDIV2 (0x0D << 27)
65 #define ADF4156_MUXOUT_NDIV2 (0x0E << 27)
66 #define ADF4156_MUXOUT_RESERVED (0x0F << 27)
67 /* 12-Bit Integer Value INT */
68 #define ADF4156_INT_VAL(x) ((x & 0xFFF) << 15)
69 /* 12-Bit Fractional Value FRAC */
70 #define ADF4156_FRAC_VAL(x) ((x & 0xFFF) << 3)
71 /* Control bits */
72 #define ADF4156_R0_CTRL 0x00
73
74 /* PHASE Register R1 */
75 #define ADF4156_PHASE_VAL(x) ((x & 0xFFF) << 3)
76 #define ADF4156_R1_CTRL 0x01
77
78 /* MOD/R Register R2 */
79 /* Noise Mode */
80 #define ADF4156_LOW_NOISE (0x00 << 29)
81 #define ADF4156_LOW_SPUR (0x03 << 29)
82 /* CSR EN */
83 #define ADF4156_CSR_EN(x) ((x & 0x1) << 28)
84 /* Current setting */
85 #define ADF4156_CURR_SET(x) ((x & 0xF) << 24)
86 /* Prescaler */
87 #define ADF4156_PRESCALER(x) ((x & 0x1) << 22)
88 /* RDIV2 */
89 #define ADF4156_RDIV2(x) ((x & 0x1) << 21)
90 /* Reference Doubler */
91 #define ADF4156_REF_DBL(x) ((x & 0x1) << 20)
92 /* 5-Bit R-Counter */
93 #define ADF4156_R_CNT(x) ((x & 0x1F) << 15)
94 /* 12-Bit Modulus Word */
95 #define ADF4156_MOD_WORD(x) ((x & 0xFFF) << 3)
96 /* Control bits */
97 #define ADF4156_R2_CTRL 0x02
98
99 /* Function Register R3 */
100 /* Sigma Delta Reset */
101 #define ADF4156_SIG_DEL_RST(x) ((x & 0x1) << 14)
102 /* LDP */
103 #define ADF4156_LDP(x) ((x & 0x1) << 7)
104 /* PD Polarity */
105 #define ADF4156_PD_POL(x) ((x & 0x1) << 6)
106 /* Power down */
107 #define ADF4156_PD ((x & 0x1) << 5)
108 /* CP Three State */
109 #define ADF4156_CP_Z(x) ((x & 0x1) << 4)
110 /* Counter Reset */
111 #define ADF4156_CNT_RST(x) ((x & 0x1) << 3)
112 /* Control bits */
113 #define ADF4156_R3_CTRL 0x03
114
115 /* CLK DIV Register R4 */
116 /* CLK DIV Mode */
117 #define ADF4156_CLK_DIV_OFF (0x00 << 19)
118 #define ADF4156_CLK_FAST_LOCK (0x01 << 19)
119 #define ADF4156_CLK_RESYNC_EN (0x02 << 19)
120 /* CLK DIV VALUE */
121 #define ADF4156_CLK_DIV_VAL(x) ((x & 0xFFF) << 7)
122 /* Control bits */
123 #define ADF4156_R4_CTRL 0x04
124
125 /* GPIO */
126 #define ADF4156_LE_OUT GPIO0_PIN_OUT
127 #define ADF4156_LE_LOW GPIO0_LOW
128 #define ADF4156_LE_HIGH GPIO0_HIGH
129
130 #define ADF4156_MUX_OUT GPIO1_PIN_OUT
131 #define ADF4156_MUX_LOW GPIO1_LOW
132 #define ADF4156_MUX_HIGH GPIO1_HIGH
133
134 #define ADF4156_CE_OUT GPIO2_PIN_OUT
135 #define ADF4156_CE_LOW GPIO2_LOW
136 #define ADF4156_CE_HIGH GPIO2_HIGH
137
138 #define ADF4156_LE2_OUT GPIO6_PIN_OUT
139 #define ADF4156_LE2_LOW GPIO6_LOW
140 #define ADF4156_LE2_HIGH GPIO6_HIGH
141
142 #define ADF4156_CE2_OUT GPIO7_PIN_OUT
143 #define ADF4156_CE2_LOW GPIO7_LOW
144 #define ADF4156_CE2_HIGH GPIO7_HIGH
145
146 /* Specifications */
147 #define ADF4156_MAX_OUT_FREQ 6200 /* MHz */
148 #define ADF4156_MIN_OUT_FREQ 500 /* MHz */
149 #define ADF4156_MAX_FREQ_45_PRESC 3000 /* MHz */
150 #define ADF4156_MAX_FREQ_PFD 32000000 /* Hz */
151 #define ADF4156_MAX_FREQ_REFIN 250000000 /* Hz */
152 #define ADF4156_MIN_FREQ_REFIN 10000000 /* Hz */
153 #define ADF4156_MAX_MODULUS 4095 /* (2^12)-1 */
154 #define ADF4156_MAX_R_CNT 32
155 #define ADF4156_MAX_REG_VAL 0x1FFFFFFF
156
157 /* Registers */
158 #define ADF4156_REG0 0
159 #define ADF4156_REG1 1
160 #define ADF4156_REG2 2
161 #define ADF4156_REG3 3
162 #define ADF4156_REG4 4
163
164 #define ADF4156_SLAVE_ID 1
165
166 /******************************************************************************/
167 /**************************** Types Declarations ******************************/
168 /******************************************************************************/
169 /* Supported devices */
170 /*typedef enum {
171 ID_ADF4156,
172 ID_ADF4157,
173 } ADF4156_type;
174 */
175 typedef struct
176 {
177 unsigned long clkin;
178 unsigned long channel_spacing;
179 unsigned char ref_doubler_en;
180 unsigned char ref_div2_en;
181 unsigned long r0_user_settings;
182 unsigned long r2_user_settings;
183 unsigned long r3_user_settings;
184 unsigned long r4_user_settings;
185 }adf4156_platform_data;
186
187 typedef struct
188 {
189 adf4156_platform_data *pdata;
190 unsigned long fpfd; /* Phase Frequency Detector */
191 unsigned short r_cnt; /* R-counter */
192 unsigned long r0_fract; /* Fractional value */
193 unsigned long r0_int; /* Integer value */
194 unsigned long r2_mod; /* Modulus value */
195 unsigned long reg_val[5]; /* Actual register value */
196 }adf4156_state;
197
198 /******************************************************************************/
199 /************************** Functions Declarations ****************************/
200 /******************************************************************************/
201 /* Initialize the SPI communication with the device. */
202 char ADF4156_Init(void);
203
204 /* Transmits 32 bits on SPI. */
205 char ADF4156_Set(unsigned long value);
206
207 /* Increases the R counter value until the PFD frequency is smaller than
208 ADF4351_MAX_FREQ_PFD. */
209 long adf4156_tune_r_cnt(adf4156_state *st, long r_cnt);
210
211 /* Computes the greatest common divider of two numbers. */
212 unsigned long gcd(unsigned long x, unsigned long y);
213
214 /* Sets the ADF4156 output frequency. */
215 double adf4156_set_freq(adf4156_state *st, double freq);
216
217 #endif /* _ADF4156_H_ */