no-OS
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
adf4156.h
Go to the documentation of this file.
1/***************************************************************************/
33#ifndef _ADF4156_H_
34#define _ADF4156_H_
35
36#include <stdint.h>
37#include "no_os_gpio.h"
38#include "no_os_spi.h"
39
40/* FRAC/INT Register R0 */
41/* MUXOUT Control */
42#define ADF4156_MUXOUT_Z (0x00 << 27)
43#define ADF4156_MUXOUT_DVdd (0x01 << 27)
44#define ADF4156_MUXOUT_DGND (0x02 << 27)
45#define ADF4156_MUXOUT_RDIV (0x03 << 27)
46#define ADF4156_MUXOUT_NDIV (0x04 << 27)
47#define ADF4156_MUXOUT_ALOCK (0x05 << 27)
48#define ADF4156_MUXOUT_DLOCK (0x06 << 27)
49#define ADF4156_MUXOUT_SDO (0x07 << 27)
50#define ADF4156_MUXOUT_CLKDIV (0x0A << 27)
51#define ADF4156_MUXOUT_FLS (0x0C << 27)
52#define ADF4156_MUXOUT_RDIV2 (0x0D << 27)
53#define ADF4156_MUXOUT_NDIV2 (0x0E << 27)
54#define ADF4156_MUXOUT_RESERVED (0x0F << 27)
55/* 12-Bit Integer Value INT */
56#define ADF4156_INT_VAL(x) ((x & 0xFFF) << 15)
57/* 12-Bit Fractional Value FRAC */
58#define ADF4156_FRAC_VAL(x) ((x & 0xFFF) << 3)
59/* Control bits */
60#define ADF4156_R0_CTRL 0x00
61
62/* PHASE Register R1 */
63#define ADF4156_PHASE_VAL(x) ((x & 0xFFF) << 3)
64#define ADF4156_R1_CTRL 0x01
65
66/* MOD/R Register R2 */
67/* Noise Mode */
68#define ADF4156_LOW_NOISE (0x00 << 29)
69#define ADF4156_LOW_SPUR (0x03 << 29)
70/* CSR EN */
71#define ADF4156_CSR_EN(x) ((x & 0x1) << 28)
72/* Current setting */
73#define ADF4156_CURR_SET(x) ((x & 0xF) << 24)
74/* Prescaler */
75#define ADF4156_PRESCALER(x) ((x & 0x1) << 22)
76/* RDIV2 */
77#define ADF4156_RDIV2(x) ((x & 0x1) << 21)
78/* Reference Doubler */
79#define ADF4156_REF_DBL(x) ((x & 0x1) << 20)
80/* 5-Bit R-Counter */
81#define ADF4156_R_CNT(x) ((x & 0x1F) << 15)
82/* 12-Bit Modulus Word */
83#define ADF4156_MOD_WORD(x) ((x & 0xFFF) << 3)
84/* Control bits */
85#define ADF4156_R2_CTRL 0x02
86
87/* Function Register R3 */
88/* Sigma Delta Reset */
89#define ADF4156_SIG_DEL_RST(x) ((x & 0x1) << 14)
90/* LDP */
91#define ADF4156_LDP(x) ((x & 0x1) << 7)
92/* PD Polarity */
93#define ADF4156_PD_POL(x) ((x & 0x1) << 6)
94/* Power down */
95#define ADF4156_PD ((x & 0x1) << 5)
96/* CP Three State */
97#define ADF4156_CP_Z(x) ((x & 0x1) << 4)
98/* Counter Reset */
99#define ADF4156_CNT_RST(x) ((x & 0x1) << 3)
100/* Control bits */
101#define ADF4156_R3_CTRL 0x03
102
103/* CLK DIV Register R4 */
104/* CLK DIV Mode */
105#define ADF4156_CLK_DIV_OFF (0x00 << 19)
106#define ADF4156_CLK_FAST_LOCK (0x01 << 19)
107#define ADF4156_CLK_RESYNC_EN (0x02 << 19)
108/* CLK DIV VALUE */
109#define ADF4156_CLK_DIV_VAL(x) ((x & 0xFFF) << 7)
110/* Control bits */
111#define ADF4156_R4_CTRL 0x04
112
113/* GPIO */
114#define ADF4156_LE_OUT no_os_gpio_direction_output(dev->gpio_le, \
115 NO_OS_GPIO_HIGH);
116#define ADF4156_LE_LOW no_os_gpio_set_value(dev->gpio_le, \
117 NO_OS_GPIO_LOW)
118#define ADF4156_LE_HIGH no_os_gpio_set_value(dev->gpio_le, \
119 NO_OS_GPIO_HIGH)
120
121#define ADF4156_MUX_OUT no_os_gpio_direction_output(dev->gpio_mux, \
122 NO_OS_GPIO_HIGH);
123#define ADF4156_MUX_LOW no_os_gpio_set_value(dev->gpio_mux, \
124 NO_OS_GPIO_LOW)
125#define ADF4156_MUX_HIGH no_os_gpio_set_value(dev->gpio_mux, \
126 NO_OS_GPIO_HIGH)
127
128#define ADF4156_CE_OUT no_os_gpio_direction_output(dev->gpio_ce, \
129 NO_OS_GPIO_HIGH);
130#define ADF4156_CE_LOW no_os_gpio_set_value(dev->gpio_ce, \
131 NO_OS_GPIO_LOW)
132#define ADF4156_CE_HIGH no_os_gpio_set_value(dev->gpio_ce, \
133 NO_OS_GPIO_HIGH)
134
135#define ADF4156_LE2_OUT no_os_gpio_direction_output(dev->gpio_le2, \
136 NO_OS_GPIO_HIGH);
137#define ADF4156_LE2_LOW no_os_gpio_set_value(dev->gpio_le2, \
138 NO_OS_GPIO_LOW)
139#define ADF4156_LE2_HIGH no_os_gpio_set_value(dev->gpio_le2, \
140 NO_OS_GPIO_HIGH)
141
142#define ADF4156_CE2_OUT no_os_gpio_direction_output(dev->gpio_ce2, \
143 NO_OS_GPIO_HIGH);
144#define ADF4156_CE2_LOW no_os_gpio_set_value(dev->gpio_ce2, \
145 NO_OS_GPIO_LOW)
146#define ADF4156_CE2_HIGH no_os_gpio_set_value(dev->gpio_ce2, \
147 NO_OS_GPIO_HIGH)
148
149/* Specifications */
150#define ADF4156_MAX_OUT_FREQ 6200 /* MHz */
151#define ADF4156_MIN_OUT_FREQ 500 /* MHz */
152#define ADF4156_MAX_FREQ_45_PRESC 3000 /* MHz */
153#define ADF4156_MAX_FREQ_PFD 32000000 /* Hz */
154#define ADF4156_MAX_FREQ_REFIN 250000000 /* Hz */
155#define ADF4156_MIN_FREQ_REFIN 10000000 /* Hz */
156#define ADF4156_MAX_MODULUS 4095 /* (2^12)-1 */
157#define ADF4156_MAX_R_CNT 32
158#define ADF4156_MAX_REG_VAL 0x1FFFFFFF
159
160/* Registers */
161#define ADF4156_REG0 0
162#define ADF4156_REG1 1
163#define ADF4156_REG2 2
164#define ADF4156_REG3 3
165#define ADF4156_REG4 4
166
167/* Supported devices */
168/*typedef enum {
169 ID_ADF4156,
170 ID_ADF4157,
171} ADF4156_type;
172*/
183
186 uint32_t fpfd; /* Phase Frequency Detector */
187 uint16_t r_cnt; /* R-counter */
188 uint32_t r0_fract; /* Fractional value */
189 uint32_t r0_int; /* Integer value */
190 uint32_t r2_mod; /* Modulus value */
191 uint32_t reg_val[5]; /* Actual register value */
192};
193
195 /* SPI */
197 /* GPIO */
200 /* Device Settings */
202};
203
211
212/* Initialize the SPI communication with the device. */
213int8_t adf4156_init(struct adf4156_dev **device,
215
216/* Free the resources allocated by adf4156_init(). */
217int32_t adf4156_remove(struct adf4156_dev *dev);
218
219/* Transmits 32 bits on SPI. */
220int8_t adf4156_set(struct adf4156_dev *dev,
221 uint32_t value);
222
223/* Increases the R counter value until the PFD frequency is smaller than
224ADF4351_MAX_FREQ_PFD. */
225int32_t adf4156_tune_r_cnt(struct adf4156_dev *dev,
226 int32_t r_cnt);
227
228/* Computes the greatest common divider of two numbers. */
229uint32_t gcd(uint32_t x, uint32_t y);
230
231/* Sets the ADF4156 output frequency. */
232double adf4156_set_freq(struct adf4156_dev *dev,
233 double freq);
234
235#endif /* _ADF4156_H_ */
struct ad7616_init_param init_param
Definition ad7616_sdz.c:107
int8_t adf4156_set(struct adf4156_dev *dev, uint32_t value)
Transmits 32 bits on SPI.
Definition adf4156.c:151
int8_t adf4156_init(struct adf4156_dev **device, struct adf4156_init_param init_param)
Initialize the SPI communication with the device.
Definition adf4156.c:50
double adf4156_set_freq(struct adf4156_dev *dev, double freq)
Sets the ADF4156 output frequency.
Definition adf4156.c:225
int32_t adf4156_tune_r_cnt(struct adf4156_dev *dev, int32_t r_cnt)
Increases the R counter value until the PFD frequency is smaller than ADF4351_MAX_FREQ_PFD.
Definition adf4156.c:184
uint32_t gcd(uint32_t x, uint32_t y)
Computes the greatest common divider of two numbers.
Definition adf4156.c:204
int32_t adf4156_remove(struct adf4156_dev *dev)
Free the resources allocated by adf4156_init().
Definition adf4156.c:130
Header file of GPIO Interface.
Header file of SPI Interface.
Definition adf4156.h:194
struct adf4156_state adf4156_st
Definition adf4156.h:201
struct no_os_spi_desc * spi_desc
Definition adf4156.h:196
struct no_os_gpio_desc * gpio_le
Definition adf4156.h:198
struct no_os_gpio_desc * gpio_ce
Definition adf4156.h:199
Definition adf4156.h:204
struct no_os_gpio_init_param gpio_ce
Definition adf4156.h:209
struct no_os_gpio_init_param gpio_le
Definition adf4156.h:208
struct no_os_spi_init_param spi_init
Definition adf4156.h:206
Definition adf4156.h:173
uint32_t r2_user_settings
Definition adf4156.h:179
uint32_t clkin
Definition adf4156.h:174
uint32_t r4_user_settings
Definition adf4156.h:181
uint32_t r3_user_settings
Definition adf4156.h:180
uint32_t r0_user_settings
Definition adf4156.h:178
uint8_t ref_div2_en
Definition adf4156.h:177
uint32_t channel_spacing
Definition adf4156.h:175
uint8_t ref_doubler_en
Definition adf4156.h:176
Definition adf4156.h:184
struct adf4156_platform_data * pdata
Definition adf4156.h:185
uint32_t reg_val[5]
Definition adf4156.h:191
uint32_t r0_fract
Definition adf4156.h:188
uint32_t r2_mod
Definition adf4156.h:190
uint32_t r0_int
Definition adf4156.h:189
uint16_t r_cnt
Definition adf4156.h:187
uint32_t fpfd
Definition adf4156.h:186
Definition ad9361_util.h:63
Structure holding the GPIO descriptor.
Definition no_os_gpio.h:84
Structure holding the parameters for GPIO initialization.
Definition no_os_gpio.h:67
Structure holding SPI descriptor.
Definition no_os_spi.h:180
Structure holding the parameters for SPI initialization.
Definition no_os_spi.h:128