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