no-OS
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
adf4157.h
Go to the documentation of this file.
1/***************************************************************************/
33#ifndef _ADF4157_H_
34#define _ADF4157_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 ADF4157_MUXOUT_Z (0x00 << 27)
43#define ADF4157_MUXOUT_DVdd (0x01 << 27)
44#define ADF4157_MUXOUT_DGND (0x02 << 27)
45#define ADF4157_MUXOUT_RDIV (0x03 << 27)
46#define ADF4157_MUXOUT_NDIV (0x04 << 27)
47#define ADF4157_MUXOUT_ALOCK (0x05 << 27)
48#define ADF4157_MUXOUT_DLOCK (0x06 << 27)
49#define ADF4157_MUXOUT_SDO (0x07 << 27)
50#define ADF4157_MUXOUT_CLKDIV (0x0A << 27)
51#define ADF4157_MUXOUT_FLS (0x0C << 27)
52#define ADF4157_MUXOUT_RDIV2 (0x0D << 27)
53#define ADF4157_MUXOUT_NDIV2 (0x0E << 27)
54#define ADF4157_MUXOUT_RESERVED (0x0F << 27)
55/* 12-Bit Integer Value INT */
56#define ADF4157_INT_VAL(x) ((x & 0xFFF) << 15)
57/* 12-Bit Fractional Value FRAC */
58#define ADF4157_FRAC_VAL_MSB(x) ((x & 0x1FFE000) >> 10)
59/* Control bits */
60#define ADF4157_R0_CTRL 0x00
61
62/* LSB FRAC Register R1 */
63#define ADF4157_FRAC_VAL_LSB(x) ((x & 0x1FFF) << 15)
64#define ADF4157_R1_CTRL 0x01
65
66/* MOD/R Register R2 */
67/* Noise Mode */
68#define ADF4157_LOW_NOISE (0x00 << 29)
69#define ADF4157_LOW_SPUR (0x03 << 29)
70/* CSR EN */
71#define ADF4157_CSR_EN(x) ((x & 0x1) << 28)
72/* Current setting */
73#define ADF4157_CURR_SET(x) ((x & 0xF) << 24)
74/* Prescaler */
75#define ADF4157_PRESCALER(x) ((x & 0x1) << 22)
76/* RDIV2 */
77#define ADF4157_RDIV2(x) ((x & 0x1) << 21)
78/* Reference Doubler */
79#define ADF4157_REF_DBL(x) ((x & 0x1) << 20)
80/* 5-Bit R-Counter */
81#define ADF4157_R_CNT(x) ((x & 0x1F) << 15)
82/* Control bits */
83#define ADF4157_R2_CTRL 0x02
84
85/* Function Register R3 */
86/* Sigma Delta Reset */
87#define ADF4157_SIG_DEL_RST(x) ((x & 0x1) << 14)
88/* LDP */
89#define ADF4157_LDP(x) ((x & 0x1) << 7)
90/* PD Polarity */
91#define ADF4157_PD_POL(x) ((x & 0x1) << 6)
92/* Power down */
93#define ADF4157_PD ((x & 0x1) << 5)
94/* CP Three State */
95#define ADF4157_CP_Z(x) ((x & 0x1) << 4)
96/* Counter Reset */
97#define ADF4157_CNT_RST(x) ((x & 0x1) << 3)
98/* Control bits */
99#define ADF4157_R3_CTRL 0x03
100
101/* CLK DIV Register R4 */
102/* NEG BLEED Current*/
103#define ADF4157_NEG_BLEED_CUR(x) ((x && 0x3) << 23)
104/* CLK DIV Mode */
105#define ADF4157_CLK_DIV_OFF (0x00 << 19)
106#define ADF4157_CLK_FAST_LOCK (0x01 << 19)
107#define ADF4157_CLK_RESYNC_EN (0x02 << 19)
108/* CLK DIV VALUE */
109#define ADF4157_CLK_DIV_VAL(x) ((x & 0xFFF) << 7)
110/* Control bits */
111#define ADF4157_R4_CTRL 0x04
112
113/* GPIO */
114#define ADF4157_LE_OUT no_os_gpio_direction_output(dev->gpio_le, \
115 NO_OS_GPIO_HIGH);
116#define ADF4157_LE_LOW no_os_gpio_set_value(dev->gpio_le, \
117 NO_OS_GPIO_LOW)
118#define ADF4157_LE_HIGH no_os_gpio_set_value(dev->gpio_le, \
119 NO_OS_GPIO_HIGH)
120
121#define ADF4157_MUX_OUT no_os_gpio_direction_output(dev->gpio_mux, \
122 NO_OS_GPIO_HIGH);
123#define ADF4157_MUX_LOW no_os_gpio_set_value(dev->gpio_mux, \
124 NO_OS_GPIO_LOW)
125#define ADF4157_MUX_HIGH no_os_gpio_set_value(dev->gpio_mux, \
126 NO_OS_GPIO_HIGH)
127
128#define ADF4157_CE_OUT no_os_gpio_direction_output(dev->gpio_ce, \
129 NO_OS_GPIO_HIGH);
130#define ADF4157_CE_LOW no_os_gpio_set_value(dev->gpio_ce, \
131 NO_OS_GPIO_LOW)
132#define ADF4157_CE_HIGH no_os_gpio_set_value(dev->gpio_ce, \
133 NO_OS_GPIO_HIGH)
134
135#define ADF4157_LE2_OUT no_os_gpio_direction_output(dev->gpio_le2, \
136 NO_OS_GPIO_HIGH);
137#define ADF4157_LE2_LOW no_os_gpio_set_value(dev->gpio_le2, \
138 NO_OS_GPIO_LOW)
139#define ADF4157_LE2_HIGH no_os_gpio_set_value(dev->gpio_le2, \
140 NO_OS_GPIO_HIGH)
141
142#define ADF4157_CE2_OUT no_os_gpio_direction_output(dev->gpio_ce2, \
143 NO_OS_GPIO_HIGH);
144#define ADF4157_CE2_LOW no_os_gpio_set_value(dev->gpio_ce2, \
145 NO_OS_GPIO_LOW)
146#define ADF4157_CE2_HIGH no_os_gpio_set_value(dev->gpio_ce2, \
147 NO_OS_GPIO_HIGH)
148
149/* Specifications */
150#define ADF4157_MAX_OUT_FREQ 6000 /* MHz */
151#define ADF4157_MIN_OUT_FREQ 500 /* MHz */
152#define ADF4157_MAX_FREQ_45_PRESC 3000 /* MHz */
153#define ADF4157_MAX_FREQ_PFD 32000000 /* Hz */
154#define ADF4157_MAX_FREQ_REFIN 300000000 /* Hz */
155#define ADF4157_MIN_FREQ_REFIN 10000000 /* Hz */
156#define ADF4157_FIXED_MODULUS 33554432 /* 2^25 */
157#define ADF4157_MAX_R_CNT 32
158#define ADF4157_MAX_REG_VAL 0x1FFFFFFF
159
160/* Registers */
161#define ADF4157_REG0 0
162#define ADF4157_REG1 1
163#define ADF4157_REG2 2
164#define ADF4157_REG3 3
165#define ADF4157_REG4 4
166
176
179 uint32_t fpfd; /* Phase Frequency Detector */
180 uint16_t r_cnt; /* R-counter */
181 uint32_t r0_fract; /* Fractional value */
182 uint32_t r0_int; /* Integer value */
183 uint32_t r2_mod; /* Modulus value */
184 float channel_spacing; /* Channel spacing */
185 uint32_t reg_val[5]; /* Actual register value */
186};
187
189 /* SPI */
191 /* GPIO */
194 /* Device Settings */
196};
197
205
206/* Initialize the SPI communication with the device. */
207int8_t adf4157_init(struct adf4157_dev **device,
209
210/* Free the resources allocated by adf4157_init(). */
211int32_t adf4157_remove(struct adf4157_dev *dev);
212
213/* Transmits 32 bits on SPI. */
214int8_t adf4157_set(struct adf4157_dev *dev,
215 uint32_t value);
216
217/* Increases the R counter value until the PFD frequency is smaller than
218ADF4157_MAX_FREQ_PFD. */
219int32_t adf4157_tune_r_cnt(struct adf4157_dev *dev,
220 int32_t r_cnt);
221
222/* Computes the greatest common divider of two numbers. */
223uint32_t gcd(uint32_t x, uint32_t y);
224
225/* Sets the ADF4157 output frequency. */
226double adf4157_set_freq(struct adf4157_dev *dev,
227 double freq);
228
229#endif /* _ADF4157_H_ */
struct ad7616_init_param init_param
Definition ad7616_sdz.c:107
int32_t adf4157_remove(struct adf4157_dev *dev)
Free the resources allocated by adf4157_init().
Definition adf4157.c:128
int32_t adf4157_tune_r_cnt(struct adf4157_dev *dev, int32_t r_cnt)
Increases the R counter value until the PFD frequency is smaller than ADF4351_MAX_FREQ_PFD.
Definition adf4157.c:182
int8_t adf4157_set(struct adf4157_dev *dev, uint32_t value)
Transmits 32 bits on SPI.
Definition adf4157.c:149
uint32_t gcd(uint32_t x, uint32_t y)
Computes the greatest common divider of two numbers.
Definition adf4156.c:204
int8_t adf4157_init(struct adf4157_dev **device, struct adf4157_init_param init_param)
Initialize the SPI communication with the device.
Definition adf4157.c:49
double adf4157_set_freq(struct adf4157_dev *dev, double freq)
Sets the ADF4157 output frequency.
Definition adf4157.c:222
Header file of GPIO Interface.
Header file of SPI Interface.
Definition adf4157.h:188
struct no_os_gpio_desc * gpio_ce
Definition adf4157.h:193
struct no_os_gpio_desc * gpio_le
Definition adf4157.h:192
struct no_os_spi_desc * spi_desc
Definition adf4157.h:190
struct adf4157_state adf4157_st
Definition adf4157.h:195
Definition adf4157.h:198
struct no_os_spi_init_param spi_init
Definition adf4157.h:200
struct no_os_gpio_init_param gpio_ce
Definition adf4157.h:203
struct no_os_gpio_init_param gpio_le
Definition adf4157.h:202
Definition adf4157.h:167
uint32_t clkin
Definition adf4157.h:168
uint32_t r3_user_settings
Definition adf4157.h:173
uint8_t ref_doubler_en
Definition adf4157.h:169
uint32_t r0_user_settings
Definition adf4157.h:171
uint32_t r4_user_settings
Definition adf4157.h:174
uint8_t ref_div2_en
Definition adf4157.h:170
uint32_t r2_user_settings
Definition adf4157.h:172
Definition adf4157.h:177
uint16_t r_cnt
Definition adf4157.h:180
float channel_spacing
Definition adf4157.h:184
uint32_t r2_mod
Definition adf4157.h:183
uint32_t reg_val[5]
Definition adf4157.h:185
struct adf4157_platform_data * pdata
Definition adf4157.h:178
uint32_t r0_fract
Definition adf4157.h:181
uint32_t fpfd
Definition adf4157.h:179
uint32_t r0_int
Definition adf4157.h:182
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