Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/device_drivers/ADF4106/adf4106.h

raw symbols SCIP
1 /**************************************************************************//**
2 * @file adf4106.h
3 * @brief Header file of ADF4106 driver. This driver supporting the following
4 * devices : ADF4001, ADF4002, ADF4106
5 * @author Istvan Csomortani ([email protected])
6 *
7 *******************************************************************************
8 * Copyright 2013(c) Analog Devices, Inc.
9 *
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without modification,
13 * are permitted provided that the following conditions are met:
14 * - Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * - Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 * - Neither the name of Analog Devices, Inc. nor the names of its
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
23 * - The use of this software may or may not infringe the patent rights
24 * of one or more patent holders. This license does not release you
25 * from the requirement that you obtain separate licenses from these
26 * patent holders to use this software.
27 * - Use of the software either in source or binary form, must be run
28 * on or directly connected to an Analog Devices Inc. component.
29 *
30 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED
31 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY
32 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
33 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
35 * INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
37 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 ******************************************************************************/
42 #ifndef __ADF4106_H__
43 #define __ADF4106_H__
44
45 #include "Communication.h"
46
47 /* Supported devices */
48 typedef enum _ADF4106_type_t
49 {
50 ID_ADF4001,
51 ID_ADF4002,
52 ID_ADF4106
53 } ADF4106_type_t;
54
55 /* Initialization methods */
56 typedef enum _ADF4106_init_t
57 {
58 INIT_LATCH,
59 INIT_CEPIN,
60 INIT_COUNTER_RESET
61 } ADF4106_init_t;
62
63 /*****************************************************************************/
64 /* Device specific MACROs */
65 /*****************************************************************************/
66 /* GPIOs */
67 #define ADF4106_LE_OUT GPIO0_PIN_OUT
68 #define ADF4106_LE_LOW GPIO0_LOW
69 #define ADF4106_LE_HIGH GPIO0_HIGH
70
71 #define ADF4106_CE_OUT GPIO2_PIN_OUT
72 #define ADF4106_CE_LOW GPIO2_LOW
73 #define ADF4106_CE_HIGH GPIO2_HIGH
74
75 #define ADF4106_LE2_OUT GPIO6_PIN_OUT
76 #define ADF4106_LE2_LOW GPIO6_LOW
77 #define ADF4106_LE2_HIGH GPIO6_HIGH
78
79 #define ADF4106_CE2_OUT GPIO7_PIN_OUT
80 #define ADF4106_CE2_LOW GPIO7_LOW
81 #define ADF4106_CE2_HIGH GPIO7_HIGH
82
83 /* Control Bits */
84 #define ADF4106_CTRL_MASK 0x3
85
86 #define ADF4106_CTRL_R_COUNTER 0 /* Reference Counter */
87 #define ADF4106_CTRL_N_COUNTER 1 /* N Counter */
88 #define ADF4106_CTRL_FUNCTION_LATCH 2 /* Function Latch*/
89 #define ADF4106_CTRL_INIT_LATCH 3 /* Initialization Latch*/
90
91 /* Reference Counter Latch */
92
93 #define ADF4106_R_COUNTER_OFFSET 2
94 #define ADF4106_R_COUNTER_MASK 0x3FFF
95 #define ADF4106_R_COUNTER(x) ((x) & ADF4106_R_COUNTER_MASK) \
96 << ADF4106_R_COUNTER_OFFSET
97 /* Anti-backlash Pulse Width options */
98 #define ADF4106_R_ABP_OFFSET 16
99 #define ADF4106_R_ABP_MASK 0x3
100 #define ADF4106_R_ABP(x) ((x) & ADF4106_R_ABP_MASK) \
101 << ADF4106_R_ABP_OFFSET
102 #define ADF4106_R_ABP_2_9NS 0
103 #define ADF4106_R_ABP_1_3NS 1
104 #define ADF4106_R_ABP_6_0NS 2
105
106 /* Test Mode Bits */
107 #define ADF4106_R_TMB_OFFSET 18
108 #define ADF4106_R_TMB_MASK 0x1
109 #define ADF4106_R_TMB(x) ((x) & ADF4106_R_TMB_MASK) \
110 << ADF4106_R_TMB_OFFSET
111 #define ADF4106_R_TMB_NORMAL 0
112 /* Lock Detect Precision */
113 #define ADF4106_R_LDP_OFFSET 20
114 #define ADF4106_R_LDP_MASK 0x1
115 #define ADF4106_R_LDP(x) ((x) & ADF4106_R_LDP_MASK) \
116 << ADF4106_R_LDP_OFFSET
117 #define ADF4106_R_LDP_3 0
118 #define ADF4106_R_LDP_5 1
119
120 /* N Counter Latch */
121 #define ADF4106_N_COUNTER_A_OFFSET 2
122 #define ADF4106_N_COUNTER_A_MASK 0x3F
123 #define ADF4106_N_COUNTER_A(x) ((x) & ADF4106_N_COUNTER_A_MASK) \
124 << ADF4106_N_COUNTER_A_OFFSET
125 #define ADF4106_N_COUNTER_B_OFFSET 8
126 #define ADF4106_N_COUNTER_B_MASK 0x1FFF
127 #define ADF4106_N_COUNTER_B(x) ((x) & ADF4106_N_COUNTER_B_MASK) \
128 << ADF4106_N_COUNTER_B_OFFSET
129 /* Charge Pump Gain Settings */
130 #define ADF4106_N_CP_OFFSET 21
131 #define ADF4106_N_CP_MASK 0x1
132 #define ADF4106_N_CP(x) ((x) & ADF4106_N_CP_MASK) \
133 << ADF4106_N_CP_OFFSET
134 #define ADF4106_N_CP_GAIN_1 0
135 #define ADF4106_N_CP_GAIN_2 1
136
137 /********* Function and Initialization register offsets and masks ************/
138 /* Counter Reset Bit */
139 #define ADF4106_CR_OFFSET 2
140 #define ADF4106_CR_MASK 0x1
141 #define ADF4106_CR(x) ((x) & ADF4106_CR_MASK) \
142 << ADF4106_CR_OFFSET
143 /* Power Down Bit 1 */
144 #define ADF4106_PD1_OFFSET 3
145 #define ADF4106_PD1_MASK 0x1
146 #define ADF4106_PD1(x) ((x) & ADF4106_PD1_MASK) \
147 << ADF4106_PD1_OFFSET
148 /* Muxout Control */
149 #define ADF4106_MUXOUT_OFFSET 4
150 #define ADF4106_MUXOUT_MASK 0x7
151 #define ADF4106_MUXOUT(x) ((x) & ADF4106_MUXOUT_MASK) \
152 << ADF4106_MUXOUT_OFFSET
153 /* Phase Detector Polarity */
154 #define ADF4106_PDPOL_OFFSET 7
155 #define ADF4106_PDPOL_MASK 0x1
156 #define ADF4106_PDPOL(x) ((x) & ADF4106_PDPOL_MASK) \
157 << ADF4106_PDPOL_OFFSET
158 /* Charge Pump Output*/
159 #define ADF4106_CP_OFFSET 8
160 #define ADF4106_CP_MASK 0x1
161 #define ADF4106_CP(x) ((x) & ADF4106_CP_MASK) \
162 << ADF4106_CP_OFFSET
163 /* Fast-lock Mode */
164 #define ADF4106_FASTLOCK_OFFSET 9
165 #define ADF4106_FASTLOCK_MASK 0x3
166 #define ADF4106_FASTLOCK(x) ((x) & ADF4106_FASTLOCK_MASK) \
167 << ADF4106_FASTLOCK_OFFSET
168 /* Timer Counter Control */
169 #define ADF4106_TCC_OFFSET 11
170 #define ADF4106_TCC_MASK 0xF
171 #define ADF4106_TCC(x) ((x) & ADF4106_TCC_MASK) \
172 << ADF4106_TCC_OFFSET
173 /* Current Setting Position */
174 #define ADF4106_CS1_OFFSET 15
175 #define ADF4106_CS1_MASK 0x7
176 #define ADF4106_CS1(x) ((x) << ADF4106_CS1_OFFSET)
177 #define ADF4106_CS2_OFFSET 18
178 #define ADF4106_CS2_MASK 0x7
179 #define ADF4106_CS2(x) ((x) << ADF4106_CS2_OFFSET)
180
181 /* Synchronous or asynchronous power down*/
182 #define ADF4106_PD2_OFFSET 21
183 #define ADF4106_PD2_MASK 0x1
184 #define ADF4106_PD2(x) ((x) & ADF4106_PD2_MASK) \
185 << ADF4106_PD2_OFFSET
186 /* Prescaler value */
187 #define ADF4106_PS_OFFSET 22
188 #define ADF4106_PS_MASK 0x3
189 #define ADF4106_PS(x) ((x) & ADF4106_PS_MASK) \
190 << ADF4106_PS_OFFSET
191
192 /* Counter Reset Bit Definition */
193 #define ADF4106_CR_NORMAL 0
194 #define ADF4106_CR_RESET 1
195 /* Power Down Bit 1 Definition */
196 #define ADF4106_PD1_NORMAL 0
197 #define ADF4106_PD1_POWER_DOWN 1
198 /* Muxout Control Definition */
199 #define ADF4106_MUXOUT_3STATE 0
200 #define ADF4106_MUXOUT_DLOCK_DETECT 1
201 #define ADF4106_MUXOUT_NDIV_OUTPUT 2
202 #define ADF4106_MUXOUT_AVDD 3
203 #define ADF4106_MUXOUT_RDIV_OUTPUT 4
204 #define ADF4106_MUXOUT_NCH_OPENDRAIN 5
205 #define ADF4106_MUXOUT_SERIAL_OUTPUT 6
206 #define ADF4106_MUXOUT_DGND 7
207 /* Phase Detector Polarity Definition */
208 #define ADF4106_PDPOL_NEGATIVE 0
209 #define ADF4106_PDPOL_POSITIVE 1
210 /* Charge Pump Output Definition */
211 #define ADF4106_CP_NORMAL 0
212 #define ADF4106_CP_THREE_STATE 1
213 /* Fast-lock Mode Definition */
214 #define ADF4106_FASTLOCK_DISABLE 0
215 #define ADF4106_FASTLOCK_MODE1 1
216 #define ADF4106_FASTLOCK_MODE2 3
217 /* Timer Counter Control Definition */
218 #define ADF4106_TCC_3 0
219 #define ADF4106_TCC_7 1
220 #define ADF4106_TCC_11 2
221 #define ADF4106_TCC_15 3
222 #define ADF4106_TCC_19 4
223 #define ADF4106_TCC_23 5
224 #define ADF4106_TCC_27 6
225 #define ADF4106_TCC_31 7
226 #define ADF4106_TCC_35 8
227 #define ADF4106_TCC_39 9
228 #define ADF4106_TCC_43 10
229 #define ADF4106_TCC_47 11
230 #define ADF4106_TCC_51 12
231 #define ADF4106_TCC_55 13
232 #define ADF4106_TCC_59 14
233 #define ADF4106_TCC_63 15
234 /* Current Settings Definitions */
235 #define ADF4106_CS_0_62 0
236 #define ADF4106_CS_1_25 1
237 #define ADF4106_CS_1_87 2
238 #define ADF4106_CS_2_5 3
239 #define ADF4106_CS_3_12 4
240 #define ADF4106_CS_3_75 5
241 #define ADF4106_CS_4_37 6
242 #define ADF4106_CS_5_0 7
243 /* Synchronous or asynchronous power down Definition */
244 #define ADF4106_ASYNC_PWD 0
245 #define ADF4106_SYNC_PWD 1
246 /* Prescaler value Definition */
247 #define ADF4106_PS_8_9 0
248 #define ADF4106_PS_16_17 1
249 #define ADF4106_PS_32_33 2
250 #define ADF4106_PS_64_65 3
251
252 /* The default slave ID for SPI interface */
253 #define ADF4106_SLAVE_ID 1
254
255 /* Default prescaler for ADF4001 and ADF4002 */
256 #define ADF4106_PRESCALE(x) (8 << (x))
257
258 /*****************************************************************************/
259 /************************** Types Declarations *******************************/
260 /*****************************************************************************/
261
262 /**
263 * struct ADF4106_settings_t - store the value of all the latch and the input
264 * reference frequency
265 * @refIn - the input reference frequency
266 * Reference Latch
267 * @refCounter - the initial value of the 14 bit Reference Counter register
268 * @antiBacklashWidth - the width of the anti-backlash pulse, this pulse
269 * ensures that no dead zone is in the PFD transfer function and minimizes
270 * phase noise and reference spurs.
271 * @testModeBits - Should be set to zero for Normal operation
272 * @lockDetectPrecision - determines the number of consecutive cycles of phase
273 * delay, that must occur before lock detect is set
274 * N Latch
275 * @aNCounter - a 6 bits counter is supported at ADF4106
276 * @bNCounter - a 13 bits counter
277 * @cpGain - determines which charge pump current settings is used
278 * Function/Initialization Latch
279 * @counterReset - resets the R and N counters
280 * @powerDown1 - activate power down mode
281 * @muxoutControl - the type of the MUXOUT output
282 * @phaseDetectorPol - the polarity of the Phase Detector
283 * @cpType - the type of the Charge Pump output
284 * @fastLockMode - set the desired Fast Lock Mode
285 * @timerCounterControl - how long will be the secondary charge pump current
286 * active, before reverting to the primary current
287 * @currentSetting1 - is used when the RF output is stable and the system is
288 * in static state
289 * @currentSetting2 - is meant to be used when the system is dynamic and in a
290 * state of change (i.e., when a new output frequency is programmed)
291 * @powerDown2 - define the type of the power down: asynchronous or
292 */
293
294 typedef struct _ADF4106_settings_t {
295
296 /* Reference Input Frequency*/
297 unsigned long refIn;
298
299 /* PFD max frequency */
300 unsigned long pfdMax;
301
302 /* Reference latch */
303 unsigned short refCounter : 14;
304 unsigned char antiBacklashWidth : 2;
305 unsigned char testModeBits : 1;
306 unsigned char lockDetectPrecision : 1;
307
308 /* N Latch */
309 unsigned char aNCounter : 6;
310 unsigned short bNCounter : 13;
311 unsigned char cpGain : 1;
312
313 /* Functional/Initialization latch */
314 unsigned char counterReset : 1;
315 unsigned char powerDown1 : 1;
316 unsigned char muxoutControl : 3;
317 unsigned char phaseDetectorPol : 1;
318 unsigned char cpType : 1;
319 unsigned char fastLockMode : 2;
320 unsigned char timerCounterControl : 4;
321 unsigned char currentSetting1 : 3;
322 unsigned char currentSetting2 : 3;
323 unsigned char powerDown2 : 1;
324 unsigned char prescalerValue : 2;
325
326 } ADF4106_settings_t;
327
328 /*****************************************************************************/
329 /* Functions Prototypes */
330 /*****************************************************************************/
331 /* Initialize the communication with the device */
332 char ADF4106_Init(ADF4106_type_t device,
333 ADF4106_init_t initMethod,
334 ADF4106_settings_t ADF4106_st);
335
336 /* Update register function */
337 void ADF4106_UpdateLatch(unsigned long latchData);
338
339 /* Return the value of a desired latch */
340 unsigned long ADF4106_ReadLatch(unsigned char latchType);
341
342 /* PLL initialization functions */
343 void ADF4106_InitLatchMethod(ADF4106_settings_t ADF4106_st);
344 void ADF4106_InitCEPinMethod(ADF4106_settings_t ADF4106_st);
345 void ADF4106_InitCounteResetMethod(ADF4106_settings_t ADF4106_st);
346
347 /* Set the frequency to a desired value */
348 unsigned long long ADF4106_SetFrequency(unsigned long long frequency);
349
350 #endif // __ADF4106_H__