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