Debian Codegraph @

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

raw symbols SCIP
1 /***************************************************************************//**
2 * @file ADF4157.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 _ADF4157_H_
42 #define _ADF4157_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 ADF4157_MUXOUT_Z (0x00 << 27)
55 #define ADF4157_MUXOUT_DVdd (0x01 << 27)
56 #define ADF4157_MUXOUT_DGND (0x02 << 27)
57 #define ADF4157_MUXOUT_RDIV (0x03 << 27)
58 #define ADF4157_MUXOUT_NDIV (0x04 << 27)
59 #define ADF4157_MUXOUT_ALOCK (0x05 << 27)
60 #define ADF4157_MUXOUT_DLOCK (0x06 << 27)
61 #define ADF4157_MUXOUT_SDO (0x07 << 27)
62 #define ADF4157_MUXOUT_CLKDIV (0x0A << 27)
63 #define ADF4157_MUXOUT_FLS (0x0C << 27)
64 #define ADF4157_MUXOUT_RDIV2 (0x0D << 27)
65 #define ADF4157_MUXOUT_NDIV2 (0x0E << 27)
66 #define ADF4157_MUXOUT_RESERVED (0x0F << 27)
67 /* 12-Bit Integer Value INT */
68 #define ADF4157_INT_VAL(x) ((x & 0xFFF) << 15)
69 /* 12-Bit Fractional Value FRAC */
70 #define ADF4157_FRAC_VAL_MSB(x) ((x & 0x1FFE000) >> 10)
71 /* Control bits */
72 #define ADF4157_R0_CTRL 0x00
73
74 /* LSB FRAC Register R1 */
75 #define ADF4157_FRAC_VAL_LSB(x) ((x & 0x1FFF) << 15)
76 #define ADF4157_R1_CTRL 0x01
77
78 /* MOD/R Register R2 */
79 /* Noise Mode */
80 #define ADF4157_LOW_NOISE (0x00 << 29)
81 #define ADF4157_LOW_SPUR (0x03 << 29)
82 /* CSR EN */
83 #define ADF4157_CSR_EN(x) ((x & 0x1) << 28)
84 /* Current setting */
85 #define ADF4157_CURR_SET(x) ((x & 0xF) << 24)
86 /* Prescaler */
87 #define ADF4157_PRESCALER(x) ((x & 0x1) << 22)
88 /* RDIV2 */
89 #define ADF4157_RDIV2(x) ((x & 0x1) << 21)
90 /* Reference Doubler */
91 #define ADF4157_REF_DBL(x) ((x & 0x1) << 20)
92 /* 5-Bit R-Counter */
93 #define ADF4157_R_CNT(x) ((x & 0x1F) << 15)
94 /* Control bits */
95 #define ADF4157_R2_CTRL 0x02
96
97 /* Function Register R3 */
98 /* Sigma Delta Reset */
99 #define ADF4157_SIG_DEL_RST(x) ((x & 0x1) << 14)
100 /* LDP */
101 #define ADF4157_LDP(x) ((x & 0x1) << 7)
102 /* PD Polarity */
103 #define ADF4157_PD_POL(x) ((x & 0x1) << 6)
104 /* Power down */
105 #define ADF4157_PD ((x & 0x1) << 5)
106 /* CP Three State */
107 #define ADF4157_CP_Z(x) ((x & 0x1) << 4)
108 /* Counter Reset */
109 #define ADF4157_CNT_RST(x) ((x & 0x1) << 3)
110 /* Control bits */
111 #define ADF4157_R3_CTRL 0x03
112
113 /* CLK DIV Register R4 */
114 /* NEG BLEED Current*/
115 #define ADF4157_NEG_BLEED_CUR(x) ((x && 0x3) << 23)
116 /* CLK DIV Mode */
117 #define ADF4157_CLK_DIV_OFF (0x00 << 19)
118 #define ADF4157_CLK_FAST_LOCK (0x01 << 19)
119 #define ADF4157_CLK_RESYNC_EN (0x02 << 19)
120 /* CLK DIV VALUE */
121 #define ADF4157_CLK_DIV_VAL(x) ((x & 0xFFF) << 7)
122 /* Control bits */
123 #define ADF4157_R4_CTRL 0x04
124
125 /* GPIO */
126 #define ADF4157_LE_OUT GPIO0_PIN_OUT
127 #define ADF4157_LE_LOW GPIO0_LOW
128 #define ADF4157_LE_HIGH GPIO0_HIGH
129
130 #define ADF4157_MUX_OUT GPIO1_PIN_OUT
131 #define ADF4157_MUX_LOW GPIO1_LOW
132 #define ADF4157_MUX_HIGH GPIO1_HIGH
133
134 #define ADF4157_CE_OUT GPIO2_PIN_OUT
135 #define ADF4157_CE_LOW GPIO2_LOW
136 #define ADF4157_CE_HIGH GPIO2_HIGH
137
138 #define ADF4157_LE2_OUT GPIO6_PIN_OUT
139 #define ADF4157_LE2_LOW GPIO6_LOW
140 #define ADF4157_LE2_HIGH GPIO6_HIGH
141
142 #define ADF4157_CE2_OUT GPIO7_PIN_OUT
143 #define ADF4157_CE2_LOW GPIO7_LOW
144 #define ADF4157_CE2_HIGH GPIO7_HIGH
145
146 /* Specifications */
147 #define ADF4157_MAX_OUT_FREQ 6000 /* MHz */
148 #define ADF4157_MIN_OUT_FREQ 500 /* MHz */
149 #define ADF4157_MAX_FREQ_45_PRESC 3000 /* MHz */
150 #define ADF4157_MAX_FREQ_PFD 32000000 /* Hz */
151 #define ADF4157_MAX_FREQ_REFIN 300000000 /* Hz */
152 #define ADF4157_MIN_FREQ_REFIN 10000000 /* Hz */
153 #define ADF4157_FIXED_MODULUS 33554432 /* 2^25 */
154 #define ADF4157_MAX_R_CNT 32
155 #define ADF4157_MAX_REG_VAL 0x1FFFFFFF
156
157 /* Registers */
158 #define ADF4157_REG0 0
159 #define ADF4157_REG1 1
160 #define ADF4157_REG2 2
161 #define ADF4157_REG3 3
162 #define ADF4157_REG4 4
163
164 #define ADF4157_SLAVE_ID 1
165
166 /******************************************************************************/
167 /**************************** Types Declarations ******************************/
168 /******************************************************************************/
169 typedef struct
170 {
171 unsigned long clkin;
172 unsigned char ref_doubler_en;
173 unsigned char ref_div2_en;
174 unsigned long r0_user_settings;
175 unsigned long r2_user_settings;
176 unsigned long r3_user_settings;
177 unsigned long r4_user_settings;
178 }ADF4157_platform_data;
179
180 typedef struct
181 {
182 ADF4157_platform_data *pdata;
183 unsigned long fpfd; /* Phase Frequency Detector */
184 unsigned short r_cnt; /* R-counter */
185 unsigned long r0_fract; /* Fractional value */
186 unsigned long r0_int; /* Integer value */
187 unsigned long r2_mod; /* Modulus value */
188 float channel_spacing; /* Channel spacing */
189 unsigned long reg_val[5]; /* Actual register value */
190 }ADF4157_state;
191
192 /******************************************************************************/
193 /************************** Functions Declarations ****************************/
194 /******************************************************************************/
195 /* Initialize the SPI communication with the device. */
196 char ADF4157_Init();
197
198 /* Transmits 32 bits on SPI. */
199 char ADF4157_Set(unsigned long value);
200
201 /* Increases the R counter value until the PFD frequency is smaller than
202 ADF4157_MAX_FREQ_PFD. */
203 long ADF4157_tune_r_cnt(ADF4157_state *st, long r_cnt);
204
205 /* Computes the greatest common divider of two numbers. */
206 unsigned long gcd(unsigned long x, unsigned long y);
207
208 /* Sets the ADF4157 output frequency. */
209 double adf4157_set_freq(ADF4157_state *st, double freq);
210
211 #endif /* _ADF4157_H_ */