no-OS
Loading...
Searching...
No Matches
adf4030.c File Reference

Implementation of ADF4030 Driver. More...

#include "adf4030.h"
#include "no_os_alloc.h"
#include "no_os_delay.h"
#include "no_os_error.h"
#include "no_os_print_log.h"
Include dependency graph for adf4030.c:

Classes

struct  adf4030_reg_sequence
 ADF4030 register format structure for default values.
 

Functions

int adf4030_spi_write (struct adf4030_dev *dev, uint16_t reg_addr, uint8_t data)
 Writes data to ADF4030 over SPI.
 
int adf4030_spi_read (struct adf4030_dev *dev, uint16_t reg_addr, uint8_t *data)
 Reads data from ADF4030 over SPI.
 
int adf4030_spi_update_bits (struct adf4030_dev *dev, uint16_t reg_addr, uint8_t mask, uint8_t data)
 Updates the values of the ADF4030 register.
 
int adf4030_set_default_regs (struct adf4030_dev *dev, bool spi_4wire)
 Applys a softreset, sets the SPI 4 wire mode and writes the default registers.
 
int adf4030_set_temperature (struct adf4030_dev *dev, bool en)
 Set Temperature Readback feature's initial state. This function should be called before reading temperature to trigger measurement.
 
int adf4030_get_temperature (struct adf4030_dev *dev, int16_t *temperature)
 Gets the value of the approximate die temperature.
 
int adf4030_set_chip_address (struct adf4030_dev *dev, uint8_t addr)
 Set the chip address value.
 
int adf4030_set_ref_clk (struct adf4030_dev *dev, uint32_t val)
 Set the desired reference frequency and reset everything over to maximum supported value of 250MHz to the max. value and everything under the minimum supported value of 10MHz to the min.
 
int adf4030_set_vco_freq (struct adf4030_dev *dev, uint32_t vco_freq)
 Set the desired VCO frequency.
 
int adf4030_get_vco_freq (struct adf4030_dev *dev, uint32_t *vco_freq)
 Get the VCO frequency in Hz.
 
int adf4030_set_bsync_freq (struct adf4030_dev *dev, uint32_t bsync_freq, bool odivb_sel)
 Set the BSYNC frequency in Hz. Output divider will be choose according to odiv sel argument.
 
int adf4030_get_bsync_freq (struct adf4030_dev *dev, uint32_t *bsync_freq, bool odivb_sel)
 Get the BSYNC frequency in Hz.
 
int adf4030_set_tdc_source (struct adf4030_dev *dev, uint8_t tdc_source)
 Set the TDC source.
 
int adf4030_get_tdc_source (struct adf4030_dev *dev, uint8_t *tdc_source)
 Get the TDC source.
 
int adf4030_set_tdc_measurement (struct adf4030_dev *dev, uint8_t tdc_target)
 Set the TDC measurement target and start the measurement. Before calling this function, please set tdc_source to the desired bsync channel.
 
int adf4030_get_tdc_measurement (struct adf4030_dev *dev, int64_t *tdc_result_fs)
 Get the TDC measurement result. Reads bitfileds and calculates the TDC result with period of the BSYNC signal.
 
int adf4030_set_alignment_iter (struct adf4030_dev *dev, uint8_t iter_number)
 Set the iteration number of alignment.
 
int adf4030_get_alignment_iter (struct adf4030_dev *dev, uint8_t *iter_number)
 Get the iteration number of alignment.
 
int adf4030_set_alignment_threshold (struct adf4030_dev *dev, uint32_t threshold_fs)
 Set the alignment threshold in femtoseconds.
 
int adf4030_get_alignment_threshold (struct adf4030_dev *dev, uint32_t *threshold_fs)
 Get the alignment threshold in femtoseconds.
 
int adf4030_set_single_ch_alignment (struct adf4030_dev *dev, uint8_t tdc_target_ch)
 Perform single-channel alignment. Before calling this function, please set tdc_source to the desired bsync channel.
 
int adf4030_set_serial_alignment (struct adf4030_dev *dev, uint16_t channel_flags)
 Set serial alignment for multiple BSYNC channels.
 
int adf4030_get_serial_alignment (struct adf4030_dev *dev, uint16_t *channel_flags)
 Get the serial alignment channel flags for multiple BSYNC channels.
 
int adf4030_set_background_serial_alignment (struct adf4030_dev *dev, uint16_t channel_flags)
 Set background serial alignment for multiple BSYNC channels.
 
int adf4030_get_background_serial_alignment (struct adf4030_dev *dev, uint16_t *channel_flags)
 Get the background serial alignment channel flags for multiple BSYNC channels.
 
int adf4030_set_channel_delay (struct adf4030_dev *dev, uint8_t channel, int64_t delay_fs)
 Set the delay for a specific BSYNC channel. This Delay will show up between TDC_SOURCE and channel.
 
int adf4030_get_channel_delay (struct adf4030_dev *dev, uint8_t channel, int64_t *delay_fs)
 Get the delay for a specific channel.
 
int adf4030_set_channel_direction (struct adf4030_dev *dev, uint8_t channel, bool tx_en)
 Set the TX-RX direction of a specific channel.
 
int adf4030_get_channel_direction (struct adf4030_dev *dev, uint8_t channel, bool *tx_en)
 Get the TX direction (TX/RX) of a specific channel.
 
int adf4030_set_channel_termination (struct adf4030_dev *dev, uint8_t channel, enum adf4030_terminations_e termination)
 Set the termination type for a specific channel.
 
int adf4030_get_channel_termination (struct adf4030_dev *dev, uint8_t channel, enum adf4030_terminations_e *termination)
 Get the termination type for a specific channel.
 
int adf4030_set_channel_prbs (struct adf4030_dev *dev, uint8_t channel, bool prbs_en)
 Set the PRBS (Pseudo-Random Binary Sequence) state for a specific channel.
 
int adf4030_get_channel_prbs (struct adf4030_dev *dev, uint8_t channel, bool *prbs_en)
 Get the PRBS (Pseudo-Random Binary Sequence) state for a specific channel.
 
int adf4030_set_channel_odivb (struct adf4030_dev *dev, uint8_t channel, bool odivb_en)
 Set the output divider selection for a specific channel. If odivb_en is enabled, the output divider b will be used for the channel. Otherwise, the output divider a will be used.
 
int adf4030_get_channel_odivb (struct adf4030_dev *dev, uint8_t channel, bool *odivb_en)
 Get the output divider selection for a specific channel. If odivb_en is enabled, the output divider b will be used for the channel. Otherwise, the output divider a will be used.
 
int adf4030_set_channel_invert (struct adf4030_dev *dev, uint8_t channel, bool invert_en)
 Set the inversion state for the BSYNC channel.
 
int adf4030_get_channel_invert (struct adf4030_dev *dev, uint8_t channel, bool *invert_en)
 Get the inversion state for a specific channel.
 
int adf4030_set_channel_voltage (struct adf4030_dev *dev, uint8_t channel, uint32_t voltage_mv)
 Set the voltage level for the BSYNC channel.
 
int adf4030_get_channel_voltage (struct adf4030_dev *dev, uint8_t channel, uint32_t *voltage_mv)
 Get the voltage level for a specific channel.
 
int adf4030_init (struct adf4030_dev **dev, struct adf4030_init_param *init_param)
 Initializes the adf4030.
 
int adf4030_remove (struct adf4030_dev *dev)
 Free resources allocated for adf4030.
 

Detailed Description

Implementation of ADF4030 Driver.

Author
Sirac Kucukarabacioglu (sirac.nosp@m..kuc.nosp@m.ukara.nosp@m.baci.nosp@m.oglu@.nosp@m.anal.nosp@m.og.co.nosp@m.m)

Copyright 2025(c) Analog Devices, Inc.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of Analog Devices, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Function Documentation

◆ adf4030_get_alignment_iter()

int adf4030_get_alignment_iter ( struct adf4030_dev * dev,
uint8_t * iter_number )

Get the iteration number of alignment.

Parameters
dev- The device structure.
iter_number- Read value of number of iterations in one alignment.
Returns
- 0 in case of success or negative error code otherwise.

◆ adf4030_get_alignment_threshold()

int adf4030_get_alignment_threshold ( struct adf4030_dev * dev,
uint32_t * threshold_fs )

Get the alignment threshold in femtoseconds.

Parameters
dev- The device structure.
threshold_fs- Read value of alignment threshold in femtoseconds.
Returns
- 0 in case of success or negative error code otherwise.

◆ adf4030_get_background_serial_alignment()

int adf4030_get_background_serial_alignment ( struct adf4030_dev * dev,
uint16_t * channel_flags )

Get the background serial alignment channel flags for multiple BSYNC channels.

Parameters
dev- The device structure.
channel_flags- Read value of the channel alignment flags.
Returns
- 0 in case of success or negative error code otherwise.

◆ adf4030_get_bsync_freq()

int adf4030_get_bsync_freq ( struct adf4030_dev * dev,
uint32_t * bsync_freq,
bool odivb_sel )

Get the BSYNC frequency in Hz.

Parameters
dev- The device structure.
bsync_freq- The read BSYNC frequency in Hz.
odivb_sel- Selects the output divider to read.
Returns
- 0 in case of success or negative error code otherwise.

◆ adf4030_get_channel_delay()

int adf4030_get_channel_delay ( struct adf4030_dev * dev,
uint8_t channel,
int64_t * delay_fs )

Get the delay for a specific channel.

Parameters
dev- The device structure.
channel- The channel to get the delay for.
delay_fs- Read value of the delay in femtoseconds.
Returns
- 0 in case of success or negative error code otherwise.

◆ adf4030_get_channel_direction()

int adf4030_get_channel_direction ( struct adf4030_dev * dev,
uint8_t channel,
bool * tx_en )

Get the TX direction (TX/RX) of a specific channel.

Parameters
dev- The device structure.
channel- The channel to get the direction for.
tx_en- Read the channel's TX direction status.
Returns
- 0 in case of success or negative error code otherwise.
Here is the caller graph for this function:

◆ adf4030_get_channel_invert()

int adf4030_get_channel_invert ( struct adf4030_dev * dev,
uint8_t channel,
bool * invert_en )

Get the inversion state for a specific channel.

Parameters
dev- The device structure.
channel- The channel to get the inversion state for.
invert_en- Pointer to store the inversion state.
Returns
- 0 in case of success or negative error code otherwise.

◆ adf4030_get_channel_odivb()

int adf4030_get_channel_odivb ( struct adf4030_dev * dev,
uint8_t channel,
bool * odivb_en )

Get the output divider selection for a specific channel. If odivb_en is enabled, the output divider b will be used for the channel. Otherwise, the output divider a will be used.

Parameters
dev- The device structure.
channel- The channel to get the output divider for.
odivb_en- Pointer to store the output divider state.
Returns
- 0 in case of success or negative error code otherwise.

◆ adf4030_get_channel_prbs()

int adf4030_get_channel_prbs ( struct adf4030_dev * dev,
uint8_t channel,
bool * prbs_en )

Get the PRBS (Pseudo-Random Binary Sequence) state for a specific channel.

Parameters
dev- The device structure.
channel- The channel to get the PRBS state for.
prbs_en- Pointer to store the PRBS state.
Returns
- 0 in case of success or negative error code otherwise.

◆ adf4030_get_channel_termination()

int adf4030_get_channel_termination ( struct adf4030_dev * dev,
uint8_t channel,
enum adf4030_terminations_e * termination )

Get the termination type for a specific channel.

Parameters
dev- The device structure.
channel- The channel to get the termination for.
termination- Read value of the termination type.
Returns
- 0 in case of success or negative error code otherwise.

◆ adf4030_get_channel_voltage()

int adf4030_get_channel_voltage ( struct adf4030_dev * dev,
uint8_t channel,
uint32_t * voltage_mv )

Get the voltage level for a specific channel.

Parameters
dev- The device structure.
channel- The channel to get the voltage level for.
voltage_mv- Read value of the voltage level in millivolts.
Returns
- 0 in case of success or negative error code otherwise.

◆ adf4030_get_serial_alignment()

int adf4030_get_serial_alignment ( struct adf4030_dev * dev,
uint16_t * channel_flags )

Get the serial alignment channel flags for multiple BSYNC channels.

Parameters
dev- The device structure.
channel_flags- Read value of the channel alignment flags.
Returns
- 0 in case of success or negative error code otherwise.

◆ adf4030_get_tdc_measurement()

int adf4030_get_tdc_measurement ( struct adf4030_dev * dev,
int64_t * tdc_result_fs )

Get the TDC measurement result. Reads bitfileds and calculates the TDC result with period of the BSYNC signal.

Parameters
dev- The device structure.
tdc_result_fs- Read TDC measurement result in femtoseconds.
Returns
- 0 in case of success or negative error code otherwise.
Here is the caller graph for this function:

◆ adf4030_get_tdc_source()

int adf4030_get_tdc_source ( struct adf4030_dev * dev,
uint8_t * tdc_source )

Get the TDC source.

Parameters
dev- The device structure.
tdc_source- Read TDC source value.
Returns
- 0 in case of success or negative error code otherwise.

◆ adf4030_get_temperature()

int adf4030_get_temperature ( struct adf4030_dev * dev,
int16_t * temperature )

Gets the value of the approximate die temperature.

Parameters
dev- The device structure.
temperature- The read value of the Temperature Readback.
Returns
- 0 in case of success or negative error code.

◆ adf4030_get_vco_freq()

int adf4030_get_vco_freq ( struct adf4030_dev * dev,
uint32_t * vco_freq )

Get the VCO frequency in Hz.

Parameters
dev- The device structure.
vco_freq- The VCO frequency in Hz.
Returns
- 0 in case of success, negative error code otherwise.

◆ adf4030_init()

int adf4030_init ( struct adf4030_dev ** dev,
struct adf4030_init_param * init_param )

Initializes the adf4030.

Parameters
dev- The device structure.
init_param- The structure containing the device initial parameters.
Returns
- 0 in case of success or negative error code.
Here is the caller graph for this function:

◆ adf4030_remove()

int adf4030_remove ( struct adf4030_dev * dev)

Free resources allocated for adf4030.

Parameters
dev- The device structure.
Returns
- 0 in case of success or negative error code.
Here is the caller graph for this function:

◆ adf4030_set_alignment_iter()

int adf4030_set_alignment_iter ( struct adf4030_dev * dev,
uint8_t iter_number )

Set the iteration number of alignment.

Parameters
dev- The device structure.
iter_number- The number of iterations for the alignment.
Returns
- 0 in case of success or negative error code otherwise.

◆ adf4030_set_alignment_threshold()

int adf4030_set_alignment_threshold ( struct adf4030_dev * dev,
uint32_t threshold_fs )

Set the alignment threshold in femtoseconds.

Parameters
dev- The device structure.
threshold_fs- The alignment threshold in femtoseconds.
Returns
- 0 in case of success or negative error code otherwise.

◆ adf4030_set_background_serial_alignment()

int adf4030_set_background_serial_alignment ( struct adf4030_dev * dev,
uint16_t channel_flags )

Set background serial alignment for multiple BSYNC channels.

Parameters
dev- The device structure.
channel_flags- Flags indicating the channels to align.
Returns
- 0 in case of success or negative error code otherwise.

◆ adf4030_set_bsync_freq()

int adf4030_set_bsync_freq ( struct adf4030_dev * dev,
uint32_t bsync_freq,
bool odivb_sel )

Set the BSYNC frequency in Hz. Output divider will be choose according to odiv sel argument.

Parameters
dev- The device structure.
bsync_freq- The VCO frequency in Hz.
odivb_sel- Selects the output divider which will be set.
Returns
- 0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ adf4030_set_channel_delay()

int adf4030_set_channel_delay ( struct adf4030_dev * dev,
uint8_t channel,
int64_t delay_fs )

Set the delay for a specific BSYNC channel. This Delay will show up between TDC_SOURCE and channel.

Parameters
dev- The device structure.
channel- The channel to set the delay for.
delay_fs- The delay in femtoseconds.
Returns
- 0 in case of success or negative error code otherwise.
Here is the caller graph for this function:

◆ adf4030_set_channel_direction()

int adf4030_set_channel_direction ( struct adf4030_dev * dev,
uint8_t channel,
bool tx_en )

Set the TX-RX direction of a specific channel.

Parameters
dev- The device structure.
channel- The channel to set the direction for.
tx_en- Enable or disable the channel.
Returns
- 0 in case of success or negative error code otherwise.
Here is the caller graph for this function:

◆ adf4030_set_channel_invert()

int adf4030_set_channel_invert ( struct adf4030_dev * dev,
uint8_t channel,
bool invert_en )

Set the inversion state for the BSYNC channel.

Parameters
dev- The device structure.
channel- The channel to set the inversion state for.
invert_en- Enable or disable inversion.
Returns
- 0 in case of success or negative error code otherwise.

◆ adf4030_set_channel_odivb()

int adf4030_set_channel_odivb ( struct adf4030_dev * dev,
uint8_t channel,
bool odivb_en )

Set the output divider selection for a specific channel. If odivb_en is enabled, the output divider b will be used for the channel. Otherwise, the output divider a will be used.

Parameters
dev- The device structure.
channel- The channel to set the output divider for.
odivb_en- Enable or disable the output divider b for the channel.
Returns
- 0 in case of success or negative error code otherwise.

◆ adf4030_set_channel_prbs()

int adf4030_set_channel_prbs ( struct adf4030_dev * dev,
uint8_t channel,
bool prbs_en )

Set the PRBS (Pseudo-Random Binary Sequence) state for a specific channel.

Parameters
dev- The device structure.
channel- The channel to set the PRBS state for.
prbs_en- Enable or disable PRBS.
Returns
- 0 in case of success or negative error code otherwise.

◆ adf4030_set_channel_termination()

int adf4030_set_channel_termination ( struct adf4030_dev * dev,
uint8_t channel,
enum adf4030_terminations_e termination )

Set the termination type for a specific channel.

Parameters
dev- The device structure.
channel- The channel to set the termination for.
termination- The termination type.
Returns
- 0 in case of success or negative error code otherwise.

◆ adf4030_set_channel_voltage()

int adf4030_set_channel_voltage ( struct adf4030_dev * dev,
uint8_t channel,
uint32_t voltage_mv )

Set the voltage level for the BSYNC channel.

Parameters
dev- The device structure.
channel- The channel to set the voltage level for.
voltage_mv- The desired voltage level in millivolts.
Returns
- 0 in case of success or negative error code otherwise.

◆ adf4030_set_chip_address()

int adf4030_set_chip_address ( struct adf4030_dev * dev,
uint8_t addr )

Set the chip address value.

Parameters
dev- The device structure.
addr- The desired chip address value.
Returns
- 0 in case of success or negative error code.

◆ adf4030_set_default_regs()

int adf4030_set_default_regs ( struct adf4030_dev * dev,
bool spi_4wire )

Applys a softreset, sets the SPI 4 wire mode and writes the default registers.

Parameters
dev- The device structure
spi_4wire- SPI 4 wire feature enable input
Returns
- 0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ adf4030_set_ref_clk()

int adf4030_set_ref_clk ( struct adf4030_dev * dev,
uint32_t val )

Set the desired reference frequency and reset everything over to maximum supported value of 250MHz to the max. value and everything under the minimum supported value of 10MHz to the min.

Parameters
dev- The device structure.
val- The desired reference frequency in Hz.
Returns
- 0 in case of success or negative error code.

◆ adf4030_set_serial_alignment()

int adf4030_set_serial_alignment ( struct adf4030_dev * dev,
uint16_t channel_flags )

Set serial alignment for multiple BSYNC channels.

Parameters
dev- The device structure.
channel_flags- Flags indicating the channels to align.
Returns
- 0 in case of success or negative error code otherwise.

◆ adf4030_set_single_ch_alignment()

int adf4030_set_single_ch_alignment ( struct adf4030_dev * dev,
uint8_t tdc_target_ch )

Perform single-channel alignment. Before calling this function, please set tdc_source to the desired bsync channel.

Parameters
dev- The device structure.
tdc_target_ch- The TDC Target channel for alignment.
Returns
- 0 in case of success or negative error code otherwise.
Here is the caller graph for this function:

◆ adf4030_set_tdc_measurement()

int adf4030_set_tdc_measurement ( struct adf4030_dev * dev,
uint8_t tdc_target )

Set the TDC measurement target and start the measurement. Before calling this function, please set tdc_source to the desired bsync channel.

Parameters
dev- The device structure.
tdc_target- TDC measurement target.
Returns
- 0 in case of success or negative error code otherwise.
Here is the caller graph for this function:

◆ adf4030_set_tdc_source()

int adf4030_set_tdc_source ( struct adf4030_dev * dev,
uint8_t tdc_source )

Set the TDC source.

Parameters
dev- The device structure.
tdc_source- The desired TDC source value.
Returns
- 0 in case of success or negative error code otherwise.
Here is the caller graph for this function:

◆ adf4030_set_temperature()

int adf4030_set_temperature ( struct adf4030_dev * dev,
bool en )

Set Temperature Readback feature's initial state. This function should be called before reading temperature to trigger measurement.

Parameters
dev- The device structure.
en- The enable or disable Temperature readback feature.
Returns
- 0 in case of success or negative error code.
Here is the caller graph for this function:

◆ adf4030_set_vco_freq()

int adf4030_set_vco_freq ( struct adf4030_dev * dev,
uint32_t vco_freq )

Set the desired VCO frequency.

Parameters
dev- The device structure.
vco_freq- The desired reference frequency in Hz.
Returns
- 0 in case of success or negative error code.
Here is the caller graph for this function:

◆ adf4030_spi_read()

int adf4030_spi_read ( struct adf4030_dev * dev,
uint16_t reg_addr,
uint8_t * data )

Reads data from ADF4030 over SPI.

Parameters
dev- The device structure.
reg_addr- The register address.
data- Data read from the device.
Returns
- 0 in case of success or negative error code otherwise.
Here is the caller graph for this function:

◆ adf4030_spi_update_bits()

int adf4030_spi_update_bits ( struct adf4030_dev * dev,
uint16_t reg_addr,
uint8_t mask,
uint8_t data )

Updates the values of the ADF4030 register.

Parameters
dev- The device structure.
reg_addr- The register address.
mask- Bits to be updated.
data- Update value for the mask.
Returns
- 0 in case of success or negative error code otherwise.
Here is the caller graph for this function:

◆ adf4030_spi_write()

int adf4030_spi_write ( struct adf4030_dev * dev,
uint16_t reg_addr,
uint8_t data )

Writes data to ADF4030 over SPI.

Parameters
dev- The device structure.
reg_addr- The register address.
data- Data value to write.
Returns
- 0 in case of success or negative error code otherwise.
Here is the caller graph for this function: