no-OS
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
adf4382.c File Reference

Implementation of adf4382 Driver. More...

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

Functions

int adf4382_spi_write (struct adf4382_dev *dev, uint16_t reg_addr, uint8_t data)
 Writes data to ADF4382 over SPI.
 
int adf4382_spi_read (struct adf4382_dev *dev, uint16_t reg_addr, uint8_t *data)
 Reads data from ADF4382 over SPI.
 
int adf4382_spi_update_bits (struct adf4382_dev *dev, uint16_t reg_addr, uint8_t mask, uint8_t data)
 Updates the values of the ADF4382 register.
 
int adf4382_reg_dump (struct adf4382_dev *dev)
 Will output on the terminal the values of all the ADF4382 registers.
 
int adf4382_set_ref_clk (struct adf4382_dev *dev, uint64_t val)
 Set the desired reference frequency and reset everything over to maximum supported value of 5GHz to the max. value and everything under the minimum supported value of 10MHz to the min. value.
 
int adf4382_get_ref_clk (struct adf4382_dev *dev, uint64_t *val)
 Gets the user proposed reference frequency.
 
int adf4382_set_en_ref_doubler (struct adf4382_dev *dev, bool en)
 Set the reference doubler to enable or disable based on the passed parameter. If the parameter is different then 0 it will set the doubler to enable.
 
int adf4382_get_en_ref_doubler (struct adf4382_dev *dev, bool *en)
 Gets the value the doubler if it is enabled or disable and stores it it the dev structure.
 
int adf4382_set_ref_div (struct adf4382_dev *dev, int32_t div)
 Set the reference divider value and reset everything over to maximum supported value of 63 to the max. value.
 
int adf4382_get_ref_div (struct adf4382_dev *dev, int32_t *div)
 Gets the value the reference divider.
 
int adf4382_set_cp_i (struct adf4382_dev *dev, int32_t reg_val)
 Set the charge pump value which will be written to the register. The value will be between 0 and 15 on 8 bits. For more information please consult the Datasheet.
 
int adf4382_get_cp_i (struct adf4382_dev *dev, int32_t *reg_val)
 Gets the charge pump value from the register. The value will be between 0 and 15 on 8 bits. For more information please consult the Datasheet.
 
int adf4382_set_bleed_word (struct adf4382_dev *dev, int32_t word)
 Set the bleed word, which represents the value of the bleed current written to the register space.
 
int adf4382_get_bleed_word (struct adf4382_dev *dev, int32_t *word)
 Gets the value of the set bleed word.
 
int adf4382_set_out_power (struct adf4382_dev *dev, uint8_t ch, int32_t pwr)
 Set the output power register value of a channel and reset everything over to maximum supported value of 15 to the max. value.
 
int adf4382_get_out_power (struct adf4382_dev *dev, uint8_t ch, int32_t *pwr)
 Gets the output power register value.
 
int adf4382_set_en_chan (struct adf4382_dev *dev, uint8_t ch, bool en)
 Set the output channel to enable or disable based on the passed parameter. If the parameter is different then 0 it will set the doubler to enable.
 
int adf4382_get_en_chan (struct adf4382_dev *dev, uint8_t ch, bool *en)
 Gets the value the output channel if it is enabled or disable.
 
int adf4382_set_rfout (struct adf4382_dev *dev, uint64_t val)
 Set the desired output frequency and reset everything over to maximum supported value of 22GHz (21GHz for ADF4382A) to the max. value and everything under the minimum supported value of 687.5MHz (2.875GHz for ADF4382A) to the min. value.
 
int adf4382_get_rfout (struct adf4382_dev *dev, uint64_t *val)
 Gets the user proposed output frequency.
 
int adf4382_set_en_fast_calibration (struct adf4382_dev *dev, bool en_fast_cal)
 Fast calibration function. Computes Minimum VCO frequency (fmin), uses the minimum NDIV value to generate fastcal Lookup table (LUT), and finally enables LUT Calibration.
 
int adf4382_get_en_lut_calibration (struct adf4382_dev *dev, bool *en)
 Gets Fast calibration LUT Calibration status.
 
int adf4382_set_en_lut_calibration (struct adf4382_dev *dev, bool en_lut_cal)
 Sets Fast calibration LUT Calibration. Refer to en_fastcal function to first generate fastcal Lookup Table (LUT).
 
int adf4382_get_change_rfout (struct adf4382_dev *dev, uint64_t *val)
 Gets the user proposed output frequency from the device tree without reading from the device. This is to enable and accurate reading of device lock-time.
 
int adf4382_set_change_rfout (struct adf4382_dev *dev, uint64_t val)
 Set the desired output frequency and reset everything over to maximum supported value of 22GHz (21GHz for ADF4382A) to the max without starting autocalibration. value and everything under the minimum supported value of 687.5MHz (2.875GHz for ADF4382A) to the min. value.
 
int adf4382_set_change_freq (struct adf4382_dev *dev)
 Set the output frequency. This will set the required registers to device but skip NDIV value, to be written separately. This Function will not start autocalibration until REG0010 is written.
 
int adf4382_get_start_calibration (struct adf4382_dev *dev, bool *start_cal)
 Get the status of start calibration. Will always return zero to allow users set it multiple times to trigger autocalibration.
 
int adf4382_set_start_calibration (struct adf4382_dev *dev)
 Set REG0010 value in device structure to the device to start autocal.
 
int adf4382_set_freq (struct adf4382_dev *dev)
 Set the output frequency.
 
int adf4382_set_phase_adjust (struct adf4382_dev *dev, uint32_t phase_ps)
 Set the phase adjustment in pico-seconds. The phase adjust will enable the Bleed current option as well as delay mode to 0.
 
int adf4382_set_phase_pol (struct adf4382_dev *dev, bool polarity)
 Set the phase polarity. If pol = 0 then it will add the phase value otherwise it will subtract the phase value.
 
int adf4382_get_phase_pol (struct adf4382_dev *dev, bool *polarity)
 Gets the polarity of the phase adjust.
 
int adf4382_set_ezsync_setup (struct adf4382_dev *dev, bool sync)
 Set the EZSYNC features' initial state. Awaits the SW_SYNC toggle.
 
int adf4382_set_timed_sync_setup (struct adf4382_dev *dev, bool sync)
 Set Timed SYNC features' initial state. Uses SYNC pin.
 
int adf4382_get_phase_sync_setup (struct adf4382_dev *dev, bool *en)
 Gets the value of the SYNC powerdown bit.
 
int adf4382_set_sw_sync (struct adf4382_dev *dev, bool sw_sync)
 Set Software SYNC Request. Setting SW_SYNC resets the RF block. Clearing SW_SYNC makes ready for a new reference clock.
 
int adf4382_get_sw_sync (struct adf4382_dev *dev, bool *sw_sync)
 Gets the value of the SW_SYNC bit.
 
int adf4382_init (struct adf4382_dev **dev, struct adf4382_init_param *init_param)
 Initializes the ADF4382.
 
int adf4382_remove (struct adf4382_dev *dev)
 Free resources allocated for ADF4382.
 

Detailed Description

Implementation of adf4382 Driver.

Authors
Ciprian Hegbeli (cipri.nosp@m.an.h.nosp@m.egbel.nosp@m.i@an.nosp@m.alog..nosp@m.com) Jude Osemene (jude..nosp@m.osem.nosp@m.ene@a.nosp@m.nalo.nosp@m.g.com)

Copyright 2024(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

◆ adf4382_get_bleed_word()

int adf4382_get_bleed_word ( struct adf4382_dev * dev,
int32_t * word )

Gets the value of the set bleed word.

Parameters
dev- The device structure.
word- The read bleed current register value.
Returns
- Result of the reading procedure, error code otherwise.

◆ adf4382_get_change_rfout()

int adf4382_get_change_rfout ( struct adf4382_dev * dev,
uint64_t * val )

Gets the user proposed output frequency from the device tree without reading from the device. This is to enable and accurate reading of device lock-time.

Parameters
dev- The device structure.
val- Holds the software value of RFOUT Frequency set.
Returns
- Output frequency in KHz.

◆ adf4382_get_cp_i()

int adf4382_get_cp_i ( struct adf4382_dev * dev,
int32_t * reg_val )

Gets the charge pump value from the register. The value will be between 0 and 15 on 8 bits. For more information please consult the Datasheet.

Parameters
dev- The device structure.
reg_val- The read charge pump register value.
Returns
- 0 in case of success or negative error code.

◆ adf4382_get_en_chan()

int adf4382_get_en_chan ( struct adf4382_dev * dev,
uint8_t ch,
bool * en )

Gets the value the output channel if it is enabled or disable.

Parameters
dev- The device structure.
ch- The channel to get state.
en- The status of the output channel.
Returns
- 0 in case of success or negative error code.

◆ adf4382_get_en_lut_calibration()

int adf4382_get_en_lut_calibration ( struct adf4382_dev * dev,
bool * en )

Gets Fast calibration LUT Calibration status.

Parameters
dev- The device structure.
en- The set value of LUT Calibration.
Returns
- 0 in case of success, negative error code otherwise.

◆ adf4382_get_en_ref_doubler()

int adf4382_get_en_ref_doubler ( struct adf4382_dev * dev,
bool * en )

Gets the value the doubler if it is enabled or disable and stores it it the dev structure.

Parameters
dev- The device structure.
en- The read value of the reference doubler.
Returns
- 0 in case of success or negative error code.

◆ adf4382_get_out_power()

int adf4382_get_out_power ( struct adf4382_dev * dev,
uint8_t ch,
int32_t * pwr )

Gets the output power register value.

Parameters
dev- The device structure.
ch- The channel to get the power off.
pwr- The output power register value.
Returns
- Result of the reading procedure, error code otherwise.

◆ adf4382_get_phase_pol()

int adf4382_get_phase_pol ( struct adf4382_dev * dev,
bool * polarity )

Gets the polarity of the phase adjust.

uint8_t pol;

Parameters
dev- The device structure.
polarity- The read polarity of the phase.
Returns
- Result of the tesint procedure, negative error code otherwise.

◆ adf4382_get_phase_sync_setup()

int adf4382_get_phase_sync_setup ( struct adf4382_dev * dev,
bool * en )

Gets the value of the SYNC powerdown bit.

Parameters
dev- The device structure.
en- The read status of the sync enable.
Returns
- 0 in case of success or negative error code.

◆ adf4382_get_ref_clk()

int adf4382_get_ref_clk ( struct adf4382_dev * dev,
uint64_t * val )

Gets the user proposed reference frequency.

Parameters
dev- The device structure.
val- The set value of the reference frequency in Hz.
Returns
- Reference frequency in KHz.

◆ adf4382_get_ref_div()

int adf4382_get_ref_div ( struct adf4382_dev * dev,
int32_t * div )

Gets the value the reference divider.

Parameters
dev- The device structure.
div- The read reference divider value.
Returns
- Result of the reading procedure, error code otherwise.

◆ adf4382_get_rfout()

int adf4382_get_rfout ( struct adf4382_dev * dev,
uint64_t * val )

Gets the user proposed output frequency.

Parameters
dev- The device structure.
val- The set value of the output frequency in Hz.
Returns
- 0 in case of success or negative error code.

◆ adf4382_get_start_calibration()

int adf4382_get_start_calibration ( struct adf4382_dev * dev,
bool * start_cal )

Get the status of start calibration. Will always return zero to allow users set it multiple times to trigger autocalibration.

Parameters
dev- The device structure.
start_cal- Overwrites start calibration attribute to 0.
Returns
- 0 in case of success, negative error code otherwise.

◆ adf4382_get_sw_sync()

int adf4382_get_sw_sync ( struct adf4382_dev * dev,
bool * sw_sync )

Gets the value of the SW_SYNC bit.

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

◆ adf4382_init()

int adf4382_init ( struct adf4382_dev ** dev,
struct adf4382_init_param * init_param )

Initializes the ADF4382.

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:

◆ adf4382_reg_dump()

int adf4382_reg_dump ( struct adf4382_dev * dev)

Will output on the terminal the values of all the ADF4382 registers.

Parameters
dev- The device structure.
Returns
- 0 in case of success or negative error code.

◆ adf4382_remove()

int adf4382_remove ( struct adf4382_dev * dev)

Free resources allocated for ADF4382.

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

◆ adf4382_set_bleed_word()

int adf4382_set_bleed_word ( struct adf4382_dev * dev,
int32_t word )

Set the bleed word, which represents the value of the bleed current written to the register space.

Parameters
dev- The device structure.
word- The bleed current register value.
Returns
- 0 in case of success or negative error code.

◆ adf4382_set_change_freq()

int adf4382_set_change_freq ( struct adf4382_dev * dev)

Set the output frequency. This will set the required registers to device but skip NDIV value, to be written separately. This Function will not start autocalibration until REG0010 is written.

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

◆ adf4382_set_change_rfout()

int adf4382_set_change_rfout ( struct adf4382_dev * dev,
uint64_t val )

Set the desired output frequency and reset everything over to maximum supported value of 22GHz (21GHz for ADF4382A) to the max without starting autocalibration. value and everything under the minimum supported value of 687.5MHz (2.875GHz for ADF4382A) to the min. value.

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

◆ adf4382_set_cp_i()

int adf4382_set_cp_i ( struct adf4382_dev * dev,
int32_t reg_val )

Set the charge pump value which will be written to the register. The value will be between 0 and 15 on 8 bits. For more information please consult the Datasheet.

Parameters
dev- The device structure.
reg_val- The desired charge pump register value.
Returns
- 0 in case of success or negative error code.

◆ adf4382_set_en_chan()

int adf4382_set_en_chan ( struct adf4382_dev * dev,
uint8_t ch,
bool en )

Set the output channel to enable or disable based on the passed parameter. If the parameter is different then 0 it will set the doubler to enable.

Parameters
dev- The device structure.
ch- The channel to set state.
en- The enable or disable value of the output channel.
Returns
- Result of the writing procedure, error code otherwise.

◆ adf4382_set_en_fast_calibration()

int adf4382_set_en_fast_calibration ( struct adf4382_dev * dev,
bool en_fast_cal )

Fast calibration function. Computes Minimum VCO frequency (fmin), uses the minimum NDIV value to generate fastcal Lookup table (LUT), and finally enables LUT Calibration.

Parameters
dev- The device structure.
en_fast_cal- Enables the fast calibration routine.
Returns
- N_INT value corresponding to minimum VCO frequency for fast calibration LUT generation.

◆ adf4382_set_en_lut_calibration()

int adf4382_set_en_lut_calibration ( struct adf4382_dev * dev,
bool en_lut_cal )

Sets Fast calibration LUT Calibration. Refer to en_fastcal function to first generate fastcal Lookup Table (LUT).

Parameters
dev- The device structure.
en_lut_cal- Enable/Disable LUT Calibration.
Returns
- 0 in case of success, negative error code otherwise.

◆ adf4382_set_en_ref_doubler()

int adf4382_set_en_ref_doubler ( struct adf4382_dev * dev,
bool en )

Set the reference doubler to enable or disable based on the passed parameter. If the parameter is different then 0 it will set the doubler to enable.

Parameters
dev- The device structure.
en- The enable or disable value of the reference doubler.
Returns
- 0 in case of success or negative error code.

◆ adf4382_set_ezsync_setup()

int adf4382_set_ezsync_setup ( struct adf4382_dev * dev,
bool sync )

Set the EZSYNC features' initial state. Awaits the SW_SYNC toggle.

Parameters
dev- The device structure.
sync- The enable or disable sync.
Returns
- Result of the writing procedure, error code otherwise.

◆ adf4382_set_freq()

int adf4382_set_freq ( struct adf4382_dev * dev)

Set the output frequency.

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

◆ adf4382_set_out_power()

int adf4382_set_out_power ( struct adf4382_dev * dev,
uint8_t ch,
int32_t pwr )

Set the output power register value of a channel and reset everything over to maximum supported value of 15 to the max. value.

Parameters
dev- The device structure.
ch- The channel to set the power off.
pwr- The output power register value.
Returns
- Result of the writing procedure, error code otherwise.
Here is the caller graph for this function:

◆ adf4382_set_phase_adjust()

int adf4382_set_phase_adjust ( struct adf4382_dev * dev,
uint32_t phase_ps )

Set the phase adjustment in pico-seconds. The phase adjust will enable the Bleed current option as well as delay mode to 0.

Parameters
dev- The device structure.
phase_ps- The phase adjustment in pico-seconds.
Returns
- 0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ adf4382_set_phase_pol()

int adf4382_set_phase_pol ( struct adf4382_dev * dev,
bool polarity )

Set the phase polarity. If pol = 0 then it will add the phase value otherwise it will subtract the phase value.

Parameters
dev- The device structure.
polarity- The polarity to be set.
Returns
- Result of the writing procedure, error code otherwise.

◆ adf4382_set_ref_clk()

int adf4382_set_ref_clk ( struct adf4382_dev * dev,
uint64_t val )

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

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

◆ adf4382_set_ref_div()

int adf4382_set_ref_div ( struct adf4382_dev * dev,
int32_t div )

Set the reference divider value and reset everything over to maximum supported value of 63 to the max. value.

Parameters
dev- The device structure.
div- The reference divider value.
Returns
- 0 in case of success or negative error code.

◆ adf4382_set_rfout()

int adf4382_set_rfout ( struct adf4382_dev * dev,
uint64_t val )

Set the desired output frequency and reset everything over to maximum supported value of 22GHz (21GHz for ADF4382A) to the max. value and everything under the minimum supported value of 687.5MHz (2.875GHz for ADF4382A) to the min. value.

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

◆ adf4382_set_start_calibration()

int adf4382_set_start_calibration ( struct adf4382_dev * dev)

Set REG0010 value in device structure to the device to start autocal.

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

◆ adf4382_set_sw_sync()

int adf4382_set_sw_sync ( struct adf4382_dev * dev,
bool sw_sync )

Set Software SYNC Request. Setting SW_SYNC resets the RF block. Clearing SW_SYNC makes ready for a new reference clock.

Parameters
dev- The device structure.
sw_sync- Set send SW_SYNC request
Returns
- 0 in case of success or negative error code.

◆ adf4382_set_timed_sync_setup()

int adf4382_set_timed_sync_setup ( struct adf4382_dev * dev,
bool sync )

Set Timed SYNC features' initial state. Uses SYNC pin.

Parameters
dev- The device structure.
sync- The enable or disable sync.
Returns
- Result of the writing procedure, error code otherwise.

◆ adf4382_spi_read()

int adf4382_spi_read ( struct adf4382_dev * dev,
uint16_t reg_addr,
uint8_t * data )

Reads data from ADF4382 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:

◆ adf4382_spi_update_bits()

int adf4382_spi_update_bits ( struct adf4382_dev * dev,
uint16_t reg_addr,
uint8_t mask,
uint8_t data )

Updates the values of the ADF4382 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:

◆ adf4382_spi_write()

int adf4382_spi_write ( struct adf4382_dev * dev,
uint16_t reg_addr,
uint8_t data )

Writes data to ADF4382 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: