no-OS
adf4350.h
Go to the documentation of this file.
1 /***************************************************************************/
34 #ifndef __ADF4350_H__
35 #define __ADF4350_H__
36 
37 /******************************************************************************/
38 /***************************** Include Files **********************************/
39 /******************************************************************************/
40 #include <stdint.h>
41 #include "no_os_spi.h"
42 
43 /******************************************************************************/
44 /********************** Macros and Constants Definitions **********************/
45 /******************************************************************************/
46 
47 /* Channels */
48 #define ADF4350_RX_CHANNEL 0
49 #define ADF4350_TX_CHANNEL 1
50 
51 /* Registers */
52 #define ADF4350_REG0 0
53 #define ADF4350_REG1 1
54 #define ADF4350_REG2 2
55 #define ADF4350_REG3 3
56 #define ADF4350_REG4 4
57 #define ADF4350_REG5 5
58 
59 /* REG0 Bit Definitions */
60 #define ADF4350_REG0_FRACT(x) (((x) & 0xFFF) << 3)
61 #define ADF4350_REG0_INT(x) (((x) & 0xFFFF) << 15)
62 
63 /* REG1 Bit Definitions */
64 #define ADF4350_REG1_MOD(x) (((x) & 0xFFF) << 3)
65 #define ADF4350_REG1_PHASE(x) (((x) & 0xFFF) << 15)
66 #define ADF4350_REG1_PRESCALER (1 << 27)
67 
68 /* REG2 Bit Definitions */
69 #define ADF4350_REG2_COUNTER_RESET_EN (1 << 3)
70 #define ADF4350_REG2_CP_THREESTATE_EN (1 << 4)
71 #define ADF4350_REG2_POWER_DOWN_EN (1 << 5)
72 #define ADF4350_REG2_PD_POLARITY_POS (1 << 6)
73 #define ADF4350_REG2_LDP_6ns (1 << 7)
74 #define ADF4350_REG2_LDP_10ns (0 << 7)
75 #define ADF4350_REG2_LDF_FRACT_N (0 << 8)
76 #define ADF4350_REG2_LDF_INT_N (1 << 8)
77 #define ADF4350_REG2_CHARGE_PUMP_CURR_uA(x) (((((x)-312) / 312) & 0xF) << 9)
78 #define ADF4350_REG2_DOUBLE_BUFF_EN (1 << 13)
79 #define ADF4350_REG2_10BIT_R_CNT(x) ((x) << 14)
80 #define ADF4350_REG2_RDIV2_EN (1 << 24)
81 #define ADF4350_REG2_RMULT2_EN (1 << 25)
82 #define ADF4350_REG2_MUXOUT(x) ((x) << 26)
83 #define ADF4350_REG2_NOISE_MODE(x) (((x) & 0x3) << 29)
84 
85 /* REG3 Bit Definitions */
86 #define ADF4350_REG3_12BIT_CLKDIV(x) ((x) << 3)
87 #define ADF4350_REG3_12BIT_CLKDIV_MODE(x) ((x) << 16)
88 #define ADF4350_REG3_12BIT_CSR_EN (1 << 18)
89 #define ADF4351_REG3_CHARGE_CANCELLATION_EN (1 << 21)
90 #define ADF4351_REG3_ANTI_BACKLASH_3ns_EN (1 << 22)
91 #define ADF4351_REG3_BAND_SEL_CLOCK_MODE_HIGH (1 << 23)
92 
93 /* REG4 Bit Definitions */
94 #define ADF4350_REG4_OUTPUT_PWR(x) ((x) << 3)
95 #define ADF4350_REG4_RF_OUT_EN (1 << 5)
96 #define ADF4350_REG4_AUX_OUTPUT_PWR(x) ((x) << 6)
97 #define ADF4350_REG4_AUX_OUTPUT_EN (1 << 8)
98 #define ADF4350_REG4_AUX_OUTPUT_FUND (1 << 9)
99 #define ADF4350_REG4_AUX_OUTPUT_DIV (0 << 9)
100 #define ADF4350_REG4_MUTE_TILL_LOCK_EN (1 << 10)
101 #define ADF4350_REG4_VCO_PWRDOWN_EN (1 << 11)
102 #define ADF4350_REG4_8BIT_BAND_SEL_CLKDIV(x) ((x) << 12)
103 #define ADF4350_REG4_RF_DIV_SEL(x) ((x) << 20)
104 #define ADF4350_REG4_FEEDBACK_DIVIDED (0 << 23)
105 #define ADF4350_REG4_FEEDBACK_FUND (1 << 23)
106 
107 /* REG5 Bit Definitions */
108 #define ADF4350_REG5_LD_PIN_MODE_LOW (0 << 22)
109 #define ADF4350_REG5_LD_PIN_MODE_DIGITAL (1 << 22)
110 #define ADF4350_REG5_LD_PIN_MODE_HIGH (3 << 22)
111 
112 /* Specifications */
113 #define ADF4350_MAX_OUT_FREQ 4400000000ULL /* Hz */
114 #define ADF4350_MIN_OUT_FREQ 34375000 /* Hz */
115 #define ADF4350_MIN_VCO_FREQ 2200000000ULL /* Hz */
116 #define ADF4350_MAX_FREQ_45_PRESC 3000000000ULL /* Hz */
117 #define ADF4350_MAX_FREQ_PFD 32000000 /* Hz */
118 #define ADF4350_MAX_BANDSEL_CLK 125000 /* Hz */
119 #define ADF4350_MAX_FREQ_REFIN 250000000 /* Hz */
120 #define ADF4350_MAX_MODULUS 4095
121 #define ADF4350_MAX_R_CNT 1023
122 
123 /******************************************************************************/
124 /************************ Types Definitions ***********************************/
125 /******************************************************************************/
127  uint32_t clkin;
128  uint32_t channel_spacing;
130 
131  uint16_t ref_div_factor; /* 10-bit R counter */
132  uint8_t ref_doubler_en;
133  uint8_t ref_div2_en;
134 
139 };
140 
141 typedef struct {
142  /* SPI */
144 
145  /* Device settings */
146  uint32_t clkin;
147  uint32_t channel_spacing;
152 
153  /* r2_user_settings */
158  uint32_t muxout_select;
160 
161  /* r3_user_settings */
168 
169  /* r4_user_settings */
173  uint32_t output_power;
176 
177 typedef struct {
180  uint32_t clkin;
181  uint32_t chspc; /* Channel Spacing */
182  uint32_t fpfd; /* Phase Frequency Detector */
183  uint32_t min_out_freq;
184  uint32_t r0_fract;
185  uint32_t r0_int;
186  uint32_t r1_mod;
187  uint32_t r4_rf_div_sel;
188  uint32_t regs[6];
189  uint32_t regs_hw[6];
190  uint32_t val;
191 } adf4350_dev;
192 
193 /******************************************************************************/
194 /************************ Functions Declarations ******************************/
195 /******************************************************************************/
200 int32_t adf4350_write(adf4350_dev *dev,
201  uint32_t data);
204  int64_t Hz);
207  int32_t Hz);
210  int64_t Hz);
213  int32_t pwd);
214 
215 #endif // __ADF4350_H__
adf4350_platform_data::gpio_lock_detect
int32_t gpio_lock_detect
Definition: adf4350.h:138
no_os_alloc.h
ADF4350_MAX_BANDSEL_CLK
#define ADF4350_MAX_BANDSEL_CLK
Definition: adf4350.h:118
adf4350_init_param::reference_div_factor
uint32_t reference_div_factor
Definition: adf4350.h:149
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
adf4350_init_param::muxout_select
uint32_t muxout_select
Definition: adf4350.h:158
adf4350_dev::regs
uint32_t regs[6]
Definition: adf4350.h:188
no_os_spi.h
Header file of SPI Interface.
ADF4350_MIN_OUT_FREQ
#define ADF4350_MIN_OUT_FREQ
Definition: adf4350.h:114
ADF4350_REG2_RDIV2_EN
#define ADF4350_REG2_RDIV2_EN
Definition: adf4350.h:80
ADF4351_REG3_ANTI_BACKLASH_3ns_EN
#define ADF4351_REG3_ANTI_BACKLASH_3ns_EN
Definition: adf4350.h:90
adf4350_out_altvoltage0_refin_frequency
int64_t adf4350_out_altvoltage0_refin_frequency(adf4350_dev *dev, int64_t Hz)
Sets PLL 0 REFin frequency in Hz.
Definition: adf4350.c:399
adf4350_init_param::lock_detect_precision_6ns_enable
uint8_t lock_detect_precision_6ns_enable
Definition: adf4350.h:155
ADF4350_REG2_10BIT_R_CNT
#define ADF4350_REG2_10BIT_R_CNT(x)
Definition: adf4350.h:79
ADF4350_REG2_PD_POLARITY_POS
#define ADF4350_REG2_PD_POLARITY_POS
Definition: adf4350.h:72
adf4350_init_param::aux_output_enable
uint8_t aux_output_enable
Definition: adf4350.h:170
adf4350_set_freq
int64_t adf4350_set_freq(adf4350_dev *dev, uint64_t freq)
Sets the ADF4350 frequency.
Definition: adf4350.c:143
ADF4350_REG2
#define ADF4350_REG2
Definition: adf4350.h:54
ADF4350_MAX_FREQ_PFD
#define ADF4350_MAX_FREQ_PFD
Definition: adf4350.h:117
adf4350_write
int32_t adf4350_write(adf4350_dev *dev, uint32_t data)
Writes 4 bytes of data to ADF4350.
Definition: adf4350.c:51
adf4350_dev::r0_int
uint32_t r0_int
Definition: adf4350.h:185
device
Definition: ad9361_util.h:69
ADF4350_REG3_12BIT_CSR_EN
#define ADF4350_REG3_12BIT_CSR_EN
Definition: adf4350.h:88
ADF4350_REG4_RF_DIV_SEL
#define ADF4350_REG4_RF_DIV_SEL(x)
Definition: adf4350.h:103
adf4350_out_altvoltage0_refin_frequency
int64_t adf4350_out_altvoltage0_refin_frequency(adf4350_dev *dev, int64_t Hz)
Sets PLL 0 REFin frequency in Hz.
Definition: adf4350.c:399
ADF4350_REG4_8BIT_BAND_SEL_CLKDIV
#define ADF4350_REG4_8BIT_BAND_SEL_CLKDIV(x)
Definition: adf4350.h:102
adf4350_out_altvoltage0_frequency
int64_t adf4350_out_altvoltage0_frequency(adf4350_dev *dev, int64_t Hz)
Stores PLL 0 frequency in Hz.
Definition: adf4350.c:367
ADF4350_REG1_MOD
#define ADF4350_REG1_MOD(x)
Definition: adf4350.h:64
adf4350_platform_data::ref_doubler_en
uint8_t ref_doubler_en
Definition: adf4350.h:132
adf4350_init_param::phase_detector_polarity_positive_enable
uint8_t phase_detector_polarity_positive_enable
Definition: adf4350.h:154
adf4350_platform_data::r4_user_settings
uint32_t r4_user_settings
Definition: adf4350.h:137
ADF4350_REG4_AUX_OUTPUT_FUND
#define ADF4350_REG4_AUX_OUTPUT_FUND
Definition: adf4350.h:98
ADF4350_REG1_PRESCALER
#define ADF4350_REG1_PRESCALER
Definition: adf4350.h:66
adf4350_platform_data::ref_div2_en
uint8_t ref_div2_en
Definition: adf4350.h:133
ADF4350_MAX_R_CNT
#define ADF4350_MAX_R_CNT
Definition: adf4350.h:121
adf4350_init_param::band_select_clock_mode_high_enable
uint8_t band_select_clock_mode_high_enable
Definition: adf4350.h:165
adf4350_sync_config
int32_t adf4350_sync_config(adf4350_dev *dev)
Updates the registers values.
Definition: adf4350.c:71
adf4350_init_param::anti_backlash_3ns_enable
uint8_t anti_backlash_3ns_enable
Definition: adf4350.h:164
adf4350_init_param::lock_detect_function_integer_n_enable
uint8_t lock_detect_function_integer_n_enable
Definition: adf4350.h:156
adf4350_tune_r_cnt
int32_t adf4350_tune_r_cnt(adf4350_dev *dev, uint16_t r_cnt)
Increases the R counter value until the ADF4350_MAX_FREQ_PFD is greater than PFD frequency.
Definition: adf4350.c:105
ADF4350_REG3_12BIT_CLKDIV
#define ADF4350_REG3_12BIT_CLKDIV(x)
Definition: adf4350.h:86
adf4350_init_param::aux_output_power
uint32_t aux_output_power
Definition: adf4350.h:174
adf4350_dev::r0_fract
uint32_t r0_fract
Definition: adf4350.h:184
ADF4350_REG2_DOUBLE_BUFF_EN
#define ADF4350_REG2_DOUBLE_BUFF_EN
Definition: adf4350.h:78
adf4350_init_param
Definition: adf4350.h:141
adf4350_dev::clkin
uint32_t clkin
Definition: adf4350.h:180
adf4350_dev::r1_mod
uint32_t r1_mod
Definition: adf4350.h:186
adf4350_init_param::output_power
uint32_t output_power
Definition: adf4350.h:173
ADF4351_REG3_CHARGE_CANCELLATION_EN
#define ADF4351_REG3_CHARGE_CANCELLATION_EN
Definition: adf4350.h:89
ADF4350_REG2_NOISE_MODE
#define ADF4350_REG2_NOISE_MODE(x)
Definition: adf4350.h:83
adf4350_out_altvoltage0_frequency_resolution
int32_t adf4350_out_altvoltage0_frequency_resolution(adf4350_dev *dev, int32_t Hz)
Stores PLL 0 frequency resolution/channel spacing in Hz.
Definition: adf4350.c:381
adf4350_init_param::cycle_slip_reduction_enable
uint8_t cycle_slip_reduction_enable
Definition: adf4350.h:162
ADF4350_REG4_FEEDBACK_FUND
#define ADF4350_REG4_FEEDBACK_FUND
Definition: adf4350.h:105
adf4350_write
int32_t adf4350_write(adf4350_dev *dev, uint32_t data)
Writes 4 bytes of data to ADF4350.
Definition: adf4350.c:51
ADF4350_REG0_INT
#define ADF4350_REG0_INT(x)
Definition: adf4350.h:61
adf4350.h
Header file of ADF4350 Driver.
ADF4350_REG2_LDP_6ns
#define ADF4350_REG2_LDP_6ns
Definition: adf4350.h:73
ADF4350_MAX_OUT_FREQ
#define ADF4350_MAX_OUT_FREQ
Definition: adf4350.h:113
adf4350_platform_data::r2_user_settings
uint32_t r2_user_settings
Definition: adf4350.h:135
ADF4350_REG0_FRACT
#define ADF4350_REG0_FRACT(x)
Definition: adf4350.h:60
adf4350_platform_data::clkin
uint32_t clkin
Definition: adf4350.h:127
adf4350_init_param::aux_output_fundamental_enable
uint8_t aux_output_fundamental_enable
Definition: adf4350.h:171
adf4350_init_param::clkin
uint32_t clkin
Definition: adf4350.h:146
ADF4350_REG2_LDF_INT_N
#define ADF4350_REG2_LDF_INT_N
Definition: adf4350.h:76
adf4350_dev
Definition: adf4350.h:177
no_os_spi_desc
Structure holding SPI descriptor.
Definition: no_os_spi.h:192
ADF4350_MIN_VCO_FREQ
#define ADF4350_MIN_VCO_FREQ
Definition: adf4350.h:115
spi_init
struct no_os_spi_init_param spi_init
Definition: common_data.c:120
adf4350_platform_data::power_up_frequency
uint64_t power_up_frequency
Definition: adf4350.h:129
gcd
uint32_t gcd(uint32_t x, uint32_t y)
Computes the greatest common divider of two numbers.
Definition: adf4350.c:122
adf4350_platform_data::r3_user_settings
uint32_t r3_user_settings
Definition: adf4350.h:136
adf4350_init_param::charge_cancellation_enable
uint8_t charge_cancellation_enable
Definition: adf4350.h:163
ADF4350_REG2_CHARGE_PUMP_CURR_uA
#define ADF4350_REG2_CHARGE_PUMP_CURR_uA(x)
Definition: adf4350.h:77
adf4350_out_altvoltage0_frequency_resolution
int32_t adf4350_out_altvoltage0_frequency_resolution(adf4350_dev *dev, int32_t Hz)
Stores PLL 0 frequency resolution/channel spacing in Hz.
Definition: adf4350.c:381
ADF4350_REG4_AUX_OUTPUT_PWR
#define ADF4350_REG4_AUX_OUTPUT_PWR(x)
Definition: adf4350.h:96
ADF4350_MAX_FREQ_45_PRESC
#define ADF4350_MAX_FREQ_45_PRESC
Definition: adf4350.h:116
adf4350_platform_data::ref_div_factor
uint16_t ref_div_factor
Definition: adf4350.h:131
adf4350_setup
int32_t adf4350_setup(adf4350_dev **device, adf4350_init_param init_param)
Initializes the ADF4350.
Definition: adf4350.c:273
adf4350_out_altvoltage0_frequency
int64_t adf4350_out_altvoltage0_frequency(adf4350_dev *dev, int64_t Hz)
Stores PLL 0 frequency in Hz.
Definition: adf4350.c:367
no_os_malloc
void * no_os_malloc(size_t size)
Allocate memory and return a pointer to it.
Definition: chibios_alloc.c:43
adf4350_dev::regs_hw
uint32_t regs_hw[6]
Definition: adf4350.h:189
ADF4350_REG4
#define ADF4350_REG4
Definition: adf4350.h:56
adf4350_init_param::reference_doubler_enable
uint8_t reference_doubler_enable
Definition: adf4350.h:150
ADF4350_REG1_PHASE
#define ADF4350_REG1_PHASE(x)
Definition: adf4350.h:65
ADF4350_REG2_RMULT2_EN
#define ADF4350_REG2_RMULT2_EN
Definition: adf4350.h:81
ADF4350_REG5
#define ADF4350_REG5
Definition: adf4350.h:57
adf4350_init_param::low_spur_mode_enable
uint8_t low_spur_mode_enable
Definition: adf4350.h:159
adf4350_dev::spi_desc
struct no_os_spi_desc * spi_desc
Definition: adf4350.h:178
adf4350_init_param::mute_till_lock_enable
uint8_t mute_till_lock_enable
Definition: adf4350.h:172
adf4350_init_param::charge_pump_current
uint32_t charge_pump_current
Definition: adf4350.h:157
adf4350_platform_data
Definition: adf4350.h:126
ADF4350_MAX_MODULUS
#define ADF4350_MAX_MODULUS
Definition: adf4350.h:120
adf4350_dev::r4_rf_div_sel
uint32_t r4_rf_div_sel
Definition: adf4350.h:187
adf4350_init_param::channel_spacing
uint32_t channel_spacing
Definition: adf4350.h:147
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:113
ADF4350_REG0
#define ADF4350_REG0
Definition: adf4350.h:52
ADF4350_REG4_MUTE_TILL_LOCK_EN
#define ADF4350_REG4_MUTE_TILL_LOCK_EN
Definition: adf4350.h:100
ADF4350_REG2_MUXOUT
#define ADF4350_REG2_MUXOUT(x)
Definition: adf4350.h:82
adf4350_init_param::clk_divider_mode
uint32_t clk_divider_mode
Definition: adf4350.h:167
adf4350_init_param::reference_div2_enable
uint8_t reference_div2_enable
Definition: adf4350.h:151
ADF4350_REG3
#define ADF4350_REG3
Definition: adf4350.h:55
adf4350_out_altvoltage0_powerdown
int32_t adf4350_out_altvoltage0_powerdown(adf4350_dev *dev, int32_t pwd)
Powers down the PLL.
Definition: adf4350.c:419
adf4350_dev::pdata
struct adf4350_platform_data * pdata
Definition: adf4350.h:179
ADF4350_REG2_POWER_DOWN_EN
#define ADF4350_REG2_POWER_DOWN_EN
Definition: adf4350.h:71
ADF4350_REG4_RF_OUT_EN
#define ADF4350_REG4_RF_OUT_EN
Definition: adf4350.h:95
adf4350_dev::min_out_freq
uint32_t min_out_freq
Definition: adf4350.h:183
adf4350_platform_data::channel_spacing
uint32_t channel_spacing
Definition: adf4350.h:128
ADF4350_REG3_12BIT_CLKDIV_MODE
#define ADF4350_REG3_12BIT_CLKDIV_MODE(x)
Definition: adf4350.h:87
ADF4350_REG1
#define ADF4350_REG1
Definition: adf4350.h:53
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
adf4350_dev::val
uint32_t val
Definition: adf4350.h:190
ADF4350_REG4_OUTPUT_PWR
#define ADF4350_REG4_OUTPUT_PWR(x)
Definition: adf4350.h:94
adf4350_setup
int32_t adf4350_setup(adf4350_dev **device, adf4350_init_param init_param)
Initializes the ADF4350.
Definition: adf4350.c:273
ADF4350_REG5_LD_PIN_MODE_DIGITAL
#define ADF4350_REG5_LD_PIN_MODE_DIGITAL
Definition: adf4350.h:109
adf4350_init_param::power_up_frequency
uint32_t power_up_frequency
Definition: adf4350.h:148
adf4350_init_param::clk_divider_12bit
uint32_t clk_divider_12bit
Definition: adf4350.h:166
adf4350_dev::chspc
uint32_t chspc
Definition: adf4350.h:181
ADF4351_REG3_BAND_SEL_CLOCK_MODE_HIGH
#define ADF4351_REG3_BAND_SEL_CLOCK_MODE_HIGH
Definition: adf4350.h:91
adf4350_dev::fpfd
uint32_t fpfd
Definition: adf4350.h:182
adf4350_out_altvoltage0_powerdown
int32_t adf4350_out_altvoltage0_powerdown(adf4350_dev *dev, int32_t pwd)
Powers down the PLL.
Definition: adf4350.c:419
ADF4350_REG4_AUX_OUTPUT_EN
#define ADF4350_REG4_AUX_OUTPUT_EN
Definition: adf4350.h:97
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:140