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