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